1+ import React , { useRef , useState , useEffect } from 'react' ;
2+ import { View , ViewStyle , StyleSheet , Text , TouchableOpacity , Modal , ModalProps , Animated } from 'react-native' ;
3+ import Icon from '../Icon'
4+ import Button from '../Button'
5+ import { size } from './index'
6+
7+ export enum containerSize {
8+ small = 30 ,
9+ default = 36 ,
10+ large = 44 ,
11+ }
12+ export enum contentSize {
13+ small = 12 ,
14+ default = 18 ,
15+ large = 26 ,
16+ }
17+ export interface DirTextProps {
18+ size : size ,
19+ direction : 'left' | 'right' ,
20+ disabled : boolean ,
21+ icon : boolean ,
22+ onPageChange : ( type : 'prev' | 'next' ) => void
23+ }
24+
25+ const DirText = ( props : DirTextProps ) => {
26+ const { size, direction, disabled, icon, onPageChange } = props ;
27+ const dirText : '上一页' | '下一页' = useRef < '上一页' | '下一页' > ( direction === 'left' ? '上一页' : '下一页' ) . current
28+ const [ disabledStyle , setDisabledStyle ] = useState < '#d9d9d9' | '#3d3d3d' > ( '#3d3d3d' )
29+ useEffect ( ( ) => {
30+ setDisabledStyle ( disabled ? '#d9d9d9' : '#3d3d3d' )
31+ } , [ disabled ] )
32+
33+
34+ return (
35+ < View style = { [ styles . containerStyle , { minWidth : containerSize [ size ] , height : containerSize [ size ] , paddingHorizontal : icon ? 0 : 5 } ] } >
36+ < Button bordered = { false } disabled = { disabled } onPress = { ( ) => {
37+ onPageChange ( direction === 'left' ?'prev' :'next' )
38+ } } >
39+ { icon ? < Icon name = { direction } size = { contentSize [ size ] } color = { disabledStyle } /> : < Text style = { { fontSize : contentSize [ size ] , color : disabledStyle } } >
40+ { dirText }
41+ </ Text > }
42+ </ Button >
43+ </ View >
44+ ) ;
45+ }
46+
47+ export const containerStyle : ViewStyle = {
48+ borderStyle : 'solid' ,
49+ borderWidth : 1 ,
50+ borderColor : '#d9d9d9' ,
51+ borderRadius : 2 ,
52+ display : 'flex' ,
53+ flexDirection : 'row' ,
54+ justifyContent : 'center' ,
55+ alignItems : 'center' ,
56+ }
57+ const styles = StyleSheet . create ( {
58+ containerStyle,
59+ } ) ;
60+ export default DirText
0 commit comments