Skip to content

Commit 7ef6a97

Browse files
committed
feat: button
1 parent 5987ec0 commit 7ef6a97

File tree

7 files changed

+162
-141
lines changed

7 files changed

+162
-141
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ pod install
4545
return (
4646
<View>
4747
<Card>
48-
4948
<Text>Hello world</Text>
5049
</Card>
5150
</View>
5251
);
53-
};
52+
};
5453

5554
export default App;
5655

example/src/App.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
import { View } from 'react-native';
21
import React from 'react';
3-
import Card from '../../src/components/Card';
2+
import { View } from 'react-native';
3+
import Button from '../../src/components/Button';
4+
import Section from '../../src/components/Section';
45
import Text from '../../src/components/Text';
56

67
const App = () => {
78
return (
8-
<View>
9-
<Card>
10-
<Text text="Hello world!!!" size={32} />
11-
</Card>
9+
<View style={{ flex: 1, paddingVertical: 20 }}>
10+
<Section>
11+
<Button
12+
title="Button Default"
13+
iconPosition="right"
14+
onPress={() => console.log('dada')}
15+
/>
16+
<Button
17+
icon={<Text text="a" />}
18+
iconExtra
19+
title="Button Default"
20+
onPress={() => console.log('dada')}
21+
/>
22+
</Section>
1223
</View>
1324
);
1425
};

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@
170170
"jsSrcsDir": "src"
171171
},
172172
"dependencies": {
173-
"@react-native-community/checkbox": "^0.5.17",
174-
"iconsax-react-native": "^0.0.8",
175-
"react-native-svg": "^15.3.0"
173+
"@react-native-community/checkbox": "^0.5.17"
176174
}
177175
}

src/components/Button.tsx

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import React, { type ReactNode } from 'react';
2+
import {
3+
TouchableOpacity,
4+
View,
5+
type StyleProp,
6+
type TextStyle,
7+
type ViewStyle,
8+
} from 'react-native';
9+
import { colors } from '../colors/colors';
10+
import { globalStyles } from '../styles/globalStyles';
11+
import Text from './Text';
12+
13+
interface Props {
14+
title?: string;
15+
icon?: ReactNode;
16+
outline?: boolean;
17+
color?: string;
18+
styles?: StyleProp<ViewStyle>;
19+
onPress: () => void;
20+
type?: 'primary' | 'text' | 'link' | 'dashed';
21+
textStyleProps?: StyleProp<TextStyle>;
22+
size?: 'large' | 'default' | 'small';
23+
onLongPress?: () => void;
24+
inline?: boolean;
25+
isShadow?: boolean;
26+
iconPosition?: 'left' | 'right';
27+
textLine?: number;
28+
iconExtra?: boolean;
29+
}
30+
31+
const Button = (props: Props) => {
32+
const {
33+
title,
34+
icon,
35+
outline,
36+
color,
37+
styles,
38+
onPress,
39+
type,
40+
textStyleProps,
41+
size,
42+
onLongPress,
43+
inline,
44+
isShadow,
45+
iconPosition,
46+
textLine,
47+
iconExtra,
48+
} = props;
49+
50+
const localstyles: StyleProp<ViewStyle> =
51+
type === 'text' || type === 'link'
52+
? {}
53+
: {
54+
paddingVertical: size === 'large' ? 14 : size === 'small' ? 6 : 12,
55+
paddingHorizontal: size === 'large' ? 30 : size === 'small' ? 12 : 20,
56+
backgroundColor: outline
57+
? colors.white
58+
: color
59+
? color
60+
: type === 'primary'
61+
? colors.blue400
62+
: colors.white,
63+
borderWidth: 1,
64+
borderColor: outline
65+
? color
66+
? color
67+
: colors.blue400
68+
: type === 'primary'
69+
? colors.blue400
70+
: color
71+
? color
72+
: colors.gray400,
73+
borderStyle: type === 'dashed' ? 'dashed' : 'solid',
74+
borderRadius: 100,
75+
minHeight: size === 'small' ? 38 : 42,
76+
};
77+
78+
return (
79+
<TouchableOpacity
80+
activeOpacity={0.6}
81+
onLongPress={onLongPress}
82+
style={[
83+
localstyles,
84+
globalStyles.row,
85+
globalStyles.center,
86+
isShadow !== false ? globalStyles.shadow : undefined,
87+
{
88+
marginBottom: inline ? 0 : 16,
89+
},
90+
styles,
91+
]}
92+
onPress={onPress}
93+
>
94+
{icon && (iconPosition === 'left' || !iconPosition) && icon}
95+
{title && (
96+
<View
97+
style={{
98+
flex: iconExtra ? 1 : 0,
99+
marginLeft:
100+
icon && (!iconPosition || iconPosition === 'left') && !iconExtra
101+
? 12
102+
: 0,
103+
marginRight:
104+
icon && iconPosition === 'right' && !iconExtra ? 12 : 0,
105+
}}
106+
>
107+
<Text
108+
numberOfLine={textLine ?? 1}
109+
textAlign="center"
110+
text={title}
111+
size={size === 'small' ? 12 : 14}
112+
weight={!type || type === 'text' || type === 'link' ? '400' : '600'}
113+
color={
114+
outline
115+
? color
116+
? color
117+
: colors.blue400
118+
: type === 'primary'
119+
? colors.white
120+
: !type || type === 'text' || type === 'link'
121+
? type === 'link'
122+
? colors.blue500
123+
: color && color !== '#ffffff' && color !== 'white'
124+
? colors.white
125+
: colors.black
126+
: colors.black
127+
}
128+
styles={[{}, textStyleProps]}
129+
/>
130+
</View>
131+
)}
132+
{icon && iconPosition === 'right' && icon}
133+
</TouchableOpacity>
134+
);
135+
};
136+
137+
export default Button;

src/components/CheckboxItem.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import CheckBox from '@react-native-community/checkbox';
2-
import { ArrowDown2, ArrowRight2 } from 'iconsax-react-native';
32
import React, { useState, type ReactNode } from 'react';
43
import {
54
Text,
@@ -127,12 +126,12 @@ const CheckboxItem = (props: Props) => {
127126
expandedIcon ? (
128127
expandedIcon
129128
) : (
130-
<ArrowDown2 size={16} color="#212121" />
129+
<></>
131130
)
132131
) : unExpandedIcon ? (
133132
unExpandedIcon
134133
) : (
135-
<ArrowRight2 size={16} color="#212121" />
134+
<></>
136135
)}
137136
</TouchableOpacity>
138137
) : (

src/components/Text.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ interface Props {
5858
textTransform?: 'none' | 'capitalize' | 'uppercase' | 'lowercase' | undefined;
5959
userSelect?: 'auto' | 'none' | 'text' | 'contain' | 'all' | undefined;
6060
letterSpacing?: number | undefined;
61+
flex?: number;
6162
}
6263

6364
const Text = (props: Props) => {
@@ -71,6 +72,7 @@ const Text = (props: Props) => {
7172
numberOfLine,
7273
styles,
7374
textAlign,
75+
flex,
7476
transform,
7577
letterSpacing,
7678
textDecorationColor,
@@ -104,6 +106,7 @@ const Text = (props: Props) => {
104106
textShadowRadius,
105107
textShadowColor,
106108
userSelect,
109+
flex: flex ?? 0,
107110
},
108111
styles,
109112
]}

0 commit comments

Comments
 (0)