Skip to content

Commit d90bf11

Browse files
committed
feat(pill): message here
1 parent bdab894 commit d90bf11

19 files changed

+14395
-58
lines changed

example/src/App.tsx

+7-26
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
1-
import * as React from 'react';
2-
3-
import { StyleSheet, View, Text } from 'react-native';
4-
import { multiply } from 'react-native-components';
5-
6-
export default function App() {
7-
const [result, setResult] = React.useState<number | undefined>();
8-
9-
React.useEffect(() => {
10-
multiply(3, 7).then(setResult);
11-
}, []);
1+
import { View, Text } from 'react-native';
2+
import React from 'react';
123

4+
const App = () => {
135
return (
14-
<View style={styles.container}>
15-
<Text>Result: {result}</Text>
6+
<View>
7+
<Text>App</Text>
168
</View>
179
);
18-
}
10+
};
1911

20-
const styles = StyleSheet.create({
21-
container: {
22-
flex: 1,
23-
alignItems: 'center',
24-
justifyContent: 'center',
25-
},
26-
box: {
27-
width: 60,
28-
height: 60,
29-
marginVertical: 20,
30-
},
31-
});
12+
export default App;

package.json

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "react-native-components",
3-
"version": "0.1.0",
2+
"name": "@bsdaoquang/rncomponent",
3+
"version": "0.0.1",
44
"description": "UI library for react native",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
@@ -26,13 +26,14 @@
2626
"!**/.*"
2727
],
2828
"scripts": {
29-
"example": "yarn workspace react-native-components-example",
29+
"example": "yarn workspace rncomponents-example",
3030
"test": "jest",
3131
"typecheck": "tsc --noEmit",
3232
"lint": "eslint \"**/*.{js,ts,tsx}\"",
3333
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
3434
"prepare": "bob build",
35-
"release": "release-it"
35+
"release": "release-it",
36+
"start": "npx react-native start"
3637
},
3738
"keywords": [
3839
"react-native",
@@ -161,5 +162,10 @@
161162
"name": "RNComponentsSpec",
162163
"type": "modules",
163164
"jsSrcsDir": "src"
165+
},
166+
"dependencies": {
167+
"@react-native-community/checkbox": "^0.5.17",
168+
"iconsax-react-native": "^0.0.8",
169+
"react-native-svg": "^15.3.0"
164170
}
165171
}

src/colors/colors.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export const colors = {
2+
black: '#000',
3+
white: '#fff',
4+
blue100: '#cfe2ff',
5+
blue200: '#9ec5fe',
6+
blue300: '#6ea8fe',
7+
blue400: '#3d8bfd',
8+
blue500: '#0d6efd',
9+
blue600: '#0a58ca',
10+
blue700: '#084298',
11+
blue800: '#052c65',
12+
blue900: '#031633',
13+
gray100: '#f8f9fa',
14+
gray200: '#e9ecef',
15+
gray300: '#dee2e6',
16+
gray400: '#ced4da',
17+
gray500: '#adb5bd',
18+
gray600: '#6c757d',
19+
gray700: '#495057',
20+
gray800: '#343a40',
21+
gray900: '#212529',
22+
red100: '#f8d7da',
23+
red200: '#f1aeb5',
24+
red300: '#ea868f',
25+
red400: '#e35d6a',
26+
red500: '#dc3545',
27+
red600: '#b02a37',
28+
red700: '#842029',
29+
red800: '',
30+
red900: '',
31+
};

src/components/Badge.tsx

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import React, { type ReactNode } from 'react';
2+
import { StyleSheet, View, type StyleProp, type ViewStyle } from 'react-native';
3+
import { colors } from '../colors/colors';
4+
import Label from './Label';
5+
import Row from './Row';
6+
7+
type Props = {
8+
children: ReactNode;
9+
renderDot?: ReactNode;
10+
dotColor?: string;
11+
dotStylesProps?: StyleProp<ViewStyle>;
12+
count?: number;
13+
show?: boolean;
14+
overflowCount?: number;
15+
};
16+
17+
const Badge = (props: Props) => {
18+
const {
19+
children,
20+
renderDot,
21+
dotColor,
22+
dotStylesProps,
23+
count,
24+
show,
25+
overflowCount,
26+
} = props;
27+
const dotProps = (
28+
<View
29+
style={[
30+
{
31+
position: 'absolute',
32+
top: -5,
33+
right: -5,
34+
},
35+
dotStylesProps,
36+
]}
37+
>
38+
{renderDot ? (
39+
renderDot
40+
) : (
41+
<View
42+
style={[
43+
localStyles.dot,
44+
{
45+
backgroundColor: dotColor ?? colors.red500,
46+
},
47+
dotStylesProps,
48+
]}
49+
/>
50+
)}
51+
</View>
52+
);
53+
54+
const renderCount = (
55+
<View style={[localStyles.count]}>
56+
<Label
57+
size={12}
58+
color="white"
59+
text={`${
60+
count
61+
? overflowCount
62+
? count >= overflowCount
63+
? `${overflowCount - 1}+`
64+
: count
65+
: count
66+
: ''
67+
}`}
68+
/>
69+
</View>
70+
);
71+
72+
return (
73+
<Row>
74+
<View>
75+
{children}
76+
77+
{count ? (
78+
count > 0 ? (
79+
renderCount
80+
) : null
81+
) : show === false || count === 0 ? (
82+
<></>
83+
) : (
84+
dotProps
85+
)}
86+
</View>
87+
</Row>
88+
);
89+
};
90+
91+
export default Badge;
92+
93+
const localStyles = StyleSheet.create({
94+
dot: {
95+
width: 14,
96+
height: 14,
97+
borderRadius: 10,
98+
borderWidth: 2,
99+
borderColor: 'white',
100+
},
101+
count: {
102+
backgroundColor: colors.red500,
103+
position: 'absolute',
104+
top: -8,
105+
// left: '70%',
106+
right: -14,
107+
paddingVertical: 2,
108+
paddingHorizontal: 7,
109+
borderRadius: 100,
110+
borderWidth: 1,
111+
borderColor: colors.white,
112+
},
113+
});

src/components/Card.tsx

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React, { type ReactNode } from 'react';
2+
import {
3+
type StyleProp,
4+
TouchableOpacity,
5+
View,
6+
type ViewStyle,
7+
} from 'react-native';
8+
import { globalStyles } from '../styles/globalStyles';
9+
10+
interface Props {
11+
children: ReactNode;
12+
color?: string;
13+
onPress?: () => void;
14+
styles?: StyleProp<ViewStyle>;
15+
shadowed?: boolean;
16+
}
17+
const Card = (props: Props) => {
18+
const { children, color, onPress, styles, shadowed } = props;
19+
20+
const localStyles: StyleProp<ViewStyle> = {
21+
paddingVertical: 12,
22+
marginBottom: 20,
23+
marginHorizontal: 16,
24+
paddingHorizontal: 16,
25+
backgroundColor: color ?? 'white',
26+
borderRadius: 4,
27+
};
28+
29+
return onPress ? (
30+
<TouchableOpacity
31+
onPress={onPress}
32+
style={[
33+
localStyles,
34+
shadowed === false ? undefined : globalStyles.shadow,
35+
styles,
36+
]}
37+
>
38+
{children}
39+
</TouchableOpacity>
40+
) : (
41+
<View
42+
style={[
43+
localStyles,
44+
shadowed === false ? undefined : globalStyles.shadow,
45+
styles,
46+
]}
47+
>
48+
{children}
49+
</View>
50+
);
51+
};
52+
53+
export default Card;

0 commit comments

Comments
 (0)