Skip to content

Commit 43f71c9

Browse files
committed
refactor: move reusable component styles to separate file
1 parent 4aea181 commit 43f71c9

4 files changed

Lines changed: 62 additions & 58 deletions

File tree

src/ui-components/Notification.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,10 @@ import {
1111
type StyleProp,
1212
} from 'react-native';
1313
import type { NotifierComponentProps } from '../types';
14+
import { commonStyles } from './common';
1415

1516
const s = StyleSheet.create({
1617
container: {
17-
shadowColor: '#000000',
18-
shadowOffset: {
19-
width: 0,
20-
height: 2,
21-
},
22-
shadowOpacity: 0.25,
23-
shadowRadius: 4,
24-
25-
elevation: 10,
26-
2718
backgroundColor: '#ffffff',
2819
borderRadius: 5,
2920
margin: 10,
@@ -70,7 +61,7 @@ export interface NotificationComponentProps extends NotifierComponentProps {
7061
maxDescriptionLines?: number;
7162

7263
/** A container of the component. Set it in case you use different SafeAreaView than the custom `ViewWithOffsets`
73-
* @default SafeAreaView */
64+
* @default ViewWithOffsets */
7465
ContainerComponent?: React.ElementType;
7566

7667
/** The style to use for rendering title
@@ -107,7 +98,7 @@ export const NotificationComponent = ({
10798
const Container = ContainerComponent ?? ViewWithOffsets;
10899
return (
109100
<Container>
110-
<View style={[s.container, containerStyle]}>
101+
<View style={[s.container, commonStyles.shadow, containerStyle]}>
111102
{!!imageSource && (
112103
<Image style={[s.image, imageStyle]} source={imageSource} />
113104
)}

src/ui-components/SimpleToast.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface SimpleToastProps extends NotifierComponentProps {
3535
maxTitleLines?: number;
3636

3737
/** A container of the component. Set it in case you use different SafeAreaView than the custom `ViewWithOffsets`
38-
* @default SafeAreaView */
38+
* @default ViewWithOffsets */
3939
ContainerComponent?: React.ElementType;
4040

4141
/** The style to use for rendering title

src/ui-components/Toast.tsx

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,13 @@ import {
1111
type ImageStyle,
1212
} from 'react-native';
1313
import type { NotifierComponentProps } from '../types';
14-
15-
type Types =
16-
| 'error'
17-
| 'warn'
18-
| 'info'
19-
| 'success'
20-
| 'connected'
21-
| 'disconnected';
22-
23-
const iconColors: Record<Types, string> = {
24-
warn: '#FD9F02',
25-
error: '#F34F4E',
26-
info: '#3150EC',
27-
success: '#24BF60',
28-
connected: '#24BF60',
29-
disconnected: '#CCCCCC',
30-
};
31-
32-
const backgroundColors: Record<Types, string> = {
33-
warn: '#FFF6E5',
34-
error: '#FFF2F2',
35-
info: '#F3F3FF',
36-
success: '#E7F8F0',
37-
connected: '#E7F8F0',
38-
disconnected: '#F2F2F2',
39-
};
40-
41-
const icons: Record<Types, ImageSourcePropType> = {
42-
warn: require('./icons/warn.png'),
43-
error: require('./icons/error.png'),
44-
success: require('./icons/success.png'),
45-
info: require('./icons/info.png'),
46-
connected: require('./icons/connected.png'),
47-
disconnected: require('./icons/disconnected.png'),
48-
};
14+
import {
15+
backgroundColors,
16+
commonStyles,
17+
iconColors,
18+
icons,
19+
type Types,
20+
} from './common';
4921

5022
const s = StyleSheet.create({
5123
container: {
@@ -61,16 +33,6 @@ const s = StyleSheet.create({
6133
flexDirection: 'row',
6234
alignItems: 'center',
6335
gap: 8,
64-
65-
shadowColor: '#000000',
66-
shadowOffset: {
67-
width: 0,
68-
height: 2,
69-
},
70-
shadowOpacity: 0.25,
71-
shadowRadius: 4,
72-
73-
elevation: 10,
7436
},
7537
contentContainerNoIcon: {
7638
paddingLeft: 20,
@@ -193,6 +155,7 @@ export const ToastComponent = ({
193155
<View
194156
style={[
195157
s.contentContainer,
158+
commonStyles.shadow,
196159
!type && !iconSource && s.contentContainerNoIcon,
197160
contentContainerStyle,
198161
]}

src/ui-components/common.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { StyleSheet, type ImageSourcePropType } from 'react-native';
2+
3+
export type Types =
4+
| 'error'
5+
| 'warn'
6+
| 'info'
7+
| 'success'
8+
| 'connected'
9+
| 'disconnected';
10+
11+
export const iconColors: Record<Types, string> = {
12+
warn: '#FD9F02',
13+
error: '#F34F4E',
14+
info: '#3150EC',
15+
success: '#24BF60',
16+
connected: '#24BF60',
17+
disconnected: '#CCCCCC',
18+
};
19+
20+
export const backgroundColors: Record<Types, string> = {
21+
warn: '#FFF6E5',
22+
error: '#FFF2F2',
23+
info: '#F3F3FF',
24+
success: '#E7F8F0',
25+
connected: '#E7F8F0',
26+
disconnected: '#F2F2F2',
27+
};
28+
29+
export const icons: Record<Types, ImageSourcePropType> = {
30+
warn: require('./icons/warn.png'),
31+
error: require('./icons/error.png'),
32+
success: require('./icons/success.png'),
33+
info: require('./icons/info.png'),
34+
connected: require('./icons/connected.png'),
35+
disconnected: require('./icons/disconnected.png'),
36+
};
37+
38+
export const commonStyles = StyleSheet.create({
39+
shadow: {
40+
shadowColor: '#000000',
41+
shadowOffset: {
42+
width: 0,
43+
height: 2,
44+
},
45+
shadowOpacity: 0.25,
46+
shadowRadius: 4,
47+
48+
elevation: 10,
49+
},
50+
});

0 commit comments

Comments
 (0)