jp-composter 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/dist/index.d.mts +997 -0
  2. package/dist/index.d.ts +997 -0
  3. package/dist/index.js +36837 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +36778 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +66 -0
  8. package/src/SliceUI/IconMoon.tsx +33 -0
  9. package/src/SliceUI/assets/Anatomy diagram copy.svg +19 -0
  10. package/src/SliceUI/assets/Anatomy diagram.svg +19 -0
  11. package/src/SliceUI/assets/Anatomycheck.svg +15 -0
  12. package/src/SliceUI/assets/Anatomyinput.svg +32 -0
  13. package/src/SliceUI/assets/Checkbox.jpg +0 -0
  14. package/src/SliceUI/assets/Diagram copy.svg +15 -0
  15. package/src/SliceUI/assets/Diagram.jpg +0 -0
  16. package/src/SliceUI/assets/Diagram.svg +15 -0
  17. package/src/SliceUI/assets/Frame 5 copy.png +0 -0
  18. package/src/SliceUI/assets/Frame 5.png +0 -0
  19. package/src/SliceUI/assets/Frame 65.png +0 -0
  20. package/src/SliceUI/assets/Frame_65.png +0 -0
  21. package/src/SliceUI/assets/Icon copy.svg +3 -0
  22. package/src/SliceUI/assets/Icon.svg +3 -0
  23. package/src/SliceUI/assets/Icon_Bridging copy.svg +39 -0
  24. package/src/SliceUI/assets/Icon_Bridging.svg +39 -0
  25. package/src/SliceUI/assets/Icon_Consistent copy.svg +39 -0
  26. package/src/SliceUI/assets/Icon_Consistent.svg +39 -0
  27. package/src/SliceUI/assets/Icon_Plug copy.svg +38 -0
  28. package/src/SliceUI/assets/Icon_Plug.svg +38 -0
  29. package/src/SliceUI/assets/Icon_Reusable copy.svg +39 -0
  30. package/src/SliceUI/assets/Icon_Reusable.svg +39 -0
  31. package/src/SliceUI/assets/Layer_1.png +0 -0
  32. package/src/SliceUI/assets/accessibility.png +0 -0
  33. package/src/SliceUI/assets/accessibility.svg +1 -0
  34. package/src/SliceUI/assets/addon-library.png +0 -0
  35. package/src/SliceUI/assets/assets.png +0 -0
  36. package/src/SliceUI/assets/avif-test-image.avif +0 -0
  37. package/src/SliceUI/assets/bridging.svg +13 -0
  38. package/src/SliceUI/assets/consistent.svg +11 -0
  39. package/src/SliceUI/assets/context.png +0 -0
  40. package/src/SliceUI/assets/discord.svg +1 -0
  41. package/src/SliceUI/assets/docs.png +0 -0
  42. package/src/SliceUI/assets/figma-plugin.png +0 -0
  43. package/src/SliceUI/assets/github.svg +1 -0
  44. package/src/SliceUI/assets/resources/Anatomy diagram.svg +19 -0
  45. package/src/SliceUI/assets/resources/Anatomycheck.svg +15 -0
  46. package/src/SliceUI/assets/resources/Anatomyinput.svg +32 -0
  47. package/src/SliceUI/assets/resources/Diagram.svg +15 -0
  48. package/src/SliceUI/assets/resources/Frame 5.png +0 -0
  49. package/src/SliceUI/assets/resources/Frame 65.png +0 -0
  50. package/src/SliceUI/assets/resources/Icon.svg +3 -0
  51. package/src/SliceUI/assets/resources/Icon_Bridging.svg +39 -0
  52. package/src/SliceUI/assets/resources/Icon_Consistent.svg +39 -0
  53. package/src/SliceUI/assets/resources/Icon_Plug.svg +38 -0
  54. package/src/SliceUI/assets/resources/Icon_Reusable.svg +39 -0
  55. package/src/SliceUI/assets/resources/fonts/FontIcon.json +150 -0
  56. package/src/SliceUI/assets/resources/fonts/Lato-Black.ttf +0 -0
  57. package/src/SliceUI/assets/resources/fonts/Lato-Bold.ttf +0 -0
  58. package/src/SliceUI/assets/resources/fonts/Lato-Heavy.ttf +0 -0
  59. package/src/SliceUI/assets/resources/fonts/Lato-Medium.ttf +0 -0
  60. package/src/SliceUI/assets/resources/fonts/Lato-Regular.ttf +0 -0
  61. package/src/SliceUI/assets/resources/fonts/Lato.woff2 +0 -0
  62. package/src/SliceUI/assets/resources/fonts/icomoon.eot +0 -0
  63. package/src/SliceUI/assets/resources/fonts/icomoon.svg +601 -0
  64. package/src/SliceUI/assets/resources/fonts/icomoon.ttf +0 -0
  65. package/src/SliceUI/assets/resources/fonts/icomoon.woff +0 -0
  66. package/src/SliceUI/assets/resources/fonts/selection.json +1 -0
  67. package/src/SliceUI/assets/share.png +0 -0
  68. package/src/SliceUI/assets/styling.png +0 -0
  69. package/src/SliceUI/assets/testing.png +0 -0
  70. package/src/SliceUI/assets/theming.png +0 -0
  71. package/src/SliceUI/assets/tutorials.svg +1 -0
  72. package/src/SliceUI/assets/youtube.svg +1 -0
  73. package/src/SliceUI/automation/helper.ts +29 -0
  74. package/src/SliceUI/avatar/Avatar.tsx +237 -0
  75. package/src/SliceUI/avatar/Token.ts +116 -0
  76. package/src/SliceUI/avatar/Type.ts +36 -0
  77. package/src/SliceUI/avatar/helper.ts +53 -0
  78. package/src/SliceUI/badge/Badge.tsx +308 -0
  79. package/src/SliceUI/badge/Token.ts +202 -0
  80. package/src/SliceUI/badge/Type.ts +46 -0
  81. package/src/SliceUI/badge/helper.ts +39 -0
  82. package/src/SliceUI/button/Button.tsx +243 -0
  83. package/src/SliceUI/button/Token.ts +138 -0
  84. package/src/SliceUI/button/Type.ts +34 -0
  85. package/src/SliceUI/button/helper.ts +125 -0
  86. package/src/SliceUI/checkbox/Checkbox.tsx +176 -0
  87. package/src/SliceUI/checkbox/Token.ts +128 -0
  88. package/src/SliceUI/checkbox/Type.ts +35 -0
  89. package/src/SliceUI/chip/Chip.tsx +290 -0
  90. package/src/SliceUI/chip/Token.ts +151 -0
  91. package/src/SliceUI/chip/Type.ts +43 -0
  92. package/src/SliceUI/chip/helper.ts +40 -0
  93. package/src/SliceUI/colors/Pallete.ts +151 -0
  94. package/src/SliceUI/colors/Token.ts +110 -0
  95. package/src/SliceUI/colors/Type.ts +56 -0
  96. package/src/SliceUI/contextProvider/context.tsx +108 -0
  97. package/src/SliceUI/divider/Divider.tsx +109 -0
  98. package/src/SliceUI/divider/Token.ts +18 -0
  99. package/src/SliceUI/divider/Type.ts +26 -0
  100. package/src/SliceUI/icon/CustomIcon.ts +4 -0
  101. package/src/SliceUI/icon/IcoMoonIcon.tsx +11 -0
  102. package/src/SliceUI/icon/Icon.tsx +38 -0
  103. package/src/SliceUI/icon/Token.ts +14 -0
  104. package/src/SliceUI/icon/Type.ts +13 -0
  105. package/src/SliceUI/icon/selection.json +1 -0
  106. package/src/SliceUI/input/Input.tsx +573 -0
  107. package/src/SliceUI/input/ToDo.md +99 -0
  108. package/src/SliceUI/input/Token.ts +372 -0
  109. package/src/SliceUI/input/Type.ts +109 -0
  110. package/src/SliceUI/input/components/InputPortal.tsx +211 -0
  111. package/src/SliceUI/input/components/NativeBottomSheet.tsx +296 -0
  112. package/src/SliceUI/input/components/SelectChip.tsx +185 -0
  113. package/src/SliceUI/input/components/SelectList.tsx +173 -0
  114. package/src/SliceUI/input/components/SelectListItem.tsx +377 -0
  115. package/src/SliceUI/input/components/SelectScrollbarStyle.ts +44 -0
  116. package/src/SliceUI/input/hooks/useCustomScrollbar.ts +17 -0
  117. package/src/SliceUI/input/hooks/useInputState.ts +41 -0
  118. package/src/SliceUI/input/hooks/useLabelAnimation.ts +132 -0
  119. package/src/SliceUI/input/hooks/useOutsideClick.ts +38 -0
  120. package/src/SliceUI/input/hooks/useSelectLogic.ts +338 -0
  121. package/src/SliceUI/input/utils/inputUtils.ts +120 -0
  122. package/src/SliceUI/input/utils/selectUtils.ts +85 -0
  123. package/src/SliceUI/input/utils/styleUtils.ts +50 -0
  124. package/src/SliceUI/input/variants/CurrencyInput/CurrencyInput.tsx +16 -0
  125. package/src/SliceUI/input/variants/CurrencyInput/NativeCurrencyInput.tsx +181 -0
  126. package/src/SliceUI/input/variants/CurrencyInput/WebCurrencyInput.tsx +163 -0
  127. package/src/SliceUI/input/variants/CurrencyInput/types.ts +17 -0
  128. package/src/SliceUI/input/variants/PhoneInput/NativePhoneInput.tsx +189 -0
  129. package/src/SliceUI/input/variants/PhoneInput/PhoneInput.tsx +16 -0
  130. package/src/SliceUI/input/variants/PhoneInput/WebPhoneInput.tsx +291 -0
  131. package/src/SliceUI/input/variants/PhoneInput/types.ts +22 -0
  132. package/src/SliceUI/input/variants/SelectInput/SelectInput.tsx +407 -0
  133. package/src/SliceUI/input/variants/SelectInput/types.ts +34 -0
  134. package/src/SliceUI/input/variants/TextInput.tsx +68 -0
  135. package/src/SliceUI/layout/Box.tsx +38 -0
  136. package/src/SliceUI/layout/Center.tsx +38 -0
  137. package/src/SliceUI/layout/Divider.tsx +37 -0
  138. package/src/SliceUI/layout/Grid.tsx +75 -0
  139. package/src/SliceUI/layout/PageContainer.tsx +60 -0
  140. package/src/SliceUI/layout/ScrollContainer.tsx +72 -0
  141. package/src/SliceUI/layout/Spacer.tsx +54 -0
  142. package/src/SliceUI/layout/Stack.tsx +97 -0
  143. package/src/SliceUI/layout/StickyHeader.tsx +71 -0
  144. package/src/SliceUI/radio/RadioButton.tsx +130 -0
  145. package/src/SliceUI/radio/Token.ts +197 -0
  146. package/src/SliceUI/radio/Type.ts +35 -0
  147. package/src/SliceUI/react-native.config.js +3 -0
  148. package/src/SliceUI/responsive/Type.ts +7 -0
  149. package/src/SliceUI/responsive/helper.ts +53 -0
  150. package/src/SliceUI/switch/Switch.tsx +119 -0
  151. package/src/SliceUI/switch/Token.ts +205 -0
  152. package/src/SliceUI/switch/Type.ts +26 -0
  153. package/src/SliceUI/tab/TabItem.tsx +204 -0
  154. package/src/SliceUI/tab/Tabs.tsx +110 -0
  155. package/src/SliceUI/tab/Token.ts +282 -0
  156. package/src/SliceUI/tab/Type.ts +66 -0
  157. package/src/SliceUI/tab/helper.ts +53 -0
  158. package/src/SliceUI/table/Table.tsx +388 -0
  159. package/src/SliceUI/table/TableCell.tsx +158 -0
  160. package/src/SliceUI/table/TableFooter.tsx +353 -0
  161. package/src/SliceUI/table/TableHeader.tsx +247 -0
  162. package/src/SliceUI/table/TableRow.tsx +218 -0
  163. package/src/SliceUI/table/Token.ts +252 -0
  164. package/src/SliceUI/table/Type.ts +213 -0
  165. package/src/SliceUI/table/helper.ts +376 -0
  166. package/src/SliceUI/table/index.ts +53 -0
  167. package/src/SliceUI/theme/dummyColors.tsx +7 -0
  168. package/src/SliceUI/theme/theme.ts +107 -0
  169. package/src/SliceUI/typography/BaseTypographyToken.ts +62 -0
  170. package/src/SliceUI/typography/FoundationToken.ts +48 -0
  171. package/src/SliceUI/typography/Token.ts +228 -0
  172. package/src/SliceUI/typography/Type.ts +20 -0
  173. package/src/SliceUI/typography/Typography.tsx +99 -0
  174. package/src/SliceUI/values/BorderRadius.ts +17 -0
  175. package/src/SliceUI/values/BorderWidth.ts +7 -0
  176. package/src/SliceUI/values/Dimension.ts +35 -0
  177. package/src/SliceUI/values/IconSizes.ts +13 -0
  178. package/src/SliceUI/values/Spacing.ts +22 -0
  179. package/src/declarations.d.ts +8 -0
  180. package/src/index.tsx +119 -0
  181. package/src/stories/Colors.mdx +1418 -0
  182. package/src/stories/Dimensions.mdx +60 -0
  183. package/src/stories/GetStarted.mdx +90 -0
  184. package/src/stories/Introduction.mdx +136 -0
  185. package/src/stories/Shape.mdx +126 -0
  186. package/src/stories/Spacing.mdx +104 -0
  187. package/src/stories/Typography.mdx +454 -0
  188. package/src/stories/Utils.mdx +277 -0
  189. package/src/stories/story-components/AddIcon.js +13 -0
  190. package/src/stories/story-components/RectangleWithBox.jsx +51 -0
  191. package/src/stories/story-components/RoundedRectangle.jsx +18 -0
  192. package/src/stories/story-components/RoundedWithWhiteInside.jsx +33 -0
  193. package/src/stories/story-components/WhiteRoundedRectangle.jsx +107 -0
  194. package/src/stories/story-components/svgPaths.js +126 -0
@@ -0,0 +1,130 @@
1
+ import React from 'react';
2
+ import {TouchableOpacity, View, StyleSheet} from 'react-native';
3
+ import {useSliceTheme} from '../contextProvider/context';
4
+ // import {useGetColors} from '../theme/dummyColors';
5
+ import Typography from '../typography/Typography';
6
+ import FONT_ICOMOON from '../assets/resources/fonts/FontIcon.json';
7
+ import type {RadioButtonProps} from './Type';
8
+ import IconMoon from '../IconMoon';
9
+ import {spacing} from '../values/Spacing';
10
+
11
+ export const RadioButton: React.FC<RadioButtonProps> = ({
12
+ checked,
13
+ onPress,
14
+ label,
15
+ size = 'medium',
16
+ disabled = false,
17
+ style,
18
+ labelStyle,
19
+ description,
20
+ descriptionStyle,
21
+ prefixIcon,
22
+ suffixIcon,
23
+ }) => {
24
+ const {theme} = useSliceTheme();
25
+
26
+ const colors = theme.colors;
27
+
28
+ // Sizing tokens
29
+ const outerSize =
30
+ size === 'large'
31
+ ? theme.dimensions.dimension16
32
+ : size === 'small'
33
+ ? theme.dimensions.dimension10
34
+ : theme.dimensions.dimension14; // 48, 20, 32
35
+ const spacingHorizontal = spacing.space100; // 12
36
+ const spacingVertical = theme.dimensions.dimension04; // 8
37
+
38
+ // Color tokens
39
+ const iconColor = disabled
40
+ ? colors.colorStatePrimaryDisabled
41
+ : checked
42
+ ? colors.colorBorderAccent
43
+ : colors.colorBorderMedium;
44
+
45
+ return (
46
+ <TouchableOpacity
47
+ style={[
48
+ styles.container,
49
+ {
50
+ paddingVertical: spacingVertical,
51
+ paddingHorizontal: spacingHorizontal,
52
+ opacity: disabled ? 0.5 : 1,
53
+ },
54
+ style,
55
+ ]}
56
+ onPress={onPress}
57
+ activeOpacity={0.7}
58
+ disabled={disabled}
59
+ accessibilityRole="radio"
60
+ accessibilityState={{checked, disabled}}>
61
+ {prefixIcon && <View style={styles.icon}>{prefixIcon}</View>}
62
+ <IconMoon
63
+ icon={
64
+ checked
65
+ ? FONT_ICOMOON.RADIO_BUTTON_SELECTED
66
+ : FONT_ICOMOON.RADIO_BUTTON_UNSELECTED
67
+ }
68
+ size={outerSize}
69
+ color={iconColor}
70
+ />
71
+ <View
72
+ style={{
73
+ flex: 1,
74
+ marginLeft: spacingHorizontal,
75
+ flexDirection: 'column',
76
+ height: outerSize,
77
+ justifyContent: description ? 'flex-start' : 'center',
78
+ }}>
79
+ <Typography
80
+ variant={
81
+ size === 'medium'
82
+ ? checked
83
+ ? 'body1Bold'
84
+ : 'body1Medium'
85
+ : checked
86
+ ? 'heading5Bold'
87
+ : 'heading5Medium'
88
+ }
89
+ style={StyleSheet.flatten([
90
+ {
91
+ color: disabled
92
+ ? colors.colorStatePrimaryDisabled
93
+ : colors.colorForegroundPrimary,
94
+ },
95
+ labelStyle,
96
+ ])}>
97
+ {label}
98
+ </Typography>
99
+ {description ? (
100
+ <Typography
101
+ variant="body2Regular"
102
+ style={StyleSheet.flatten([
103
+ {
104
+ color: disabled
105
+ ? colors.colorStatePrimaryDisabled
106
+ : colors.colorForegroundSecondary,
107
+ marginTop: theme.dimensions.dimension01,
108
+ },
109
+ descriptionStyle,
110
+ ])}>
111
+ {description}
112
+ </Typography>
113
+ ) : null}
114
+ </View>
115
+ {suffixIcon && <View style={styles.icon}>{suffixIcon}</View>}
116
+ </TouchableOpacity>
117
+ );
118
+ };
119
+
120
+ const styles = StyleSheet.create({
121
+ container: {
122
+ flexDirection: 'row',
123
+ alignItems: 'center',
124
+ },
125
+ icon: {
126
+ marginHorizontal: 4,
127
+ alignItems: 'center',
128
+ justifyContent: 'center',
129
+ },
130
+ });
@@ -0,0 +1,197 @@
1
+ import {dimensions} from '../values/Dimension';
2
+ import type {RadioButtonThemeSize} from './Type';
3
+
4
+ export const RADIO_BUTTON_THEME: RadioButtonThemeSize = {
5
+ small: {
6
+ default: {
7
+ container: {
8
+ flexDirection: 'row',
9
+ alignItems: 'center',
10
+ minHeight: dimensions.dimension17,
11
+ },
12
+ radio: {
13
+ width: dimensions.dimension07,
14
+ height: dimensions.dimension07,
15
+ borderRadius: dimensions.dimension07 / 2,
16
+ borderWidth: 2,
17
+ borderColor: '#888',
18
+ justifyContent: 'center',
19
+ alignItems: 'center',
20
+ marginRight: dimensions.dimension04,
21
+ },
22
+ dot: {
23
+ width: dimensions.dimension05,
24
+ height: dimensions.dimension05,
25
+ borderRadius: dimensions.dimension05 / 2,
26
+ backgroundColor: '#888',
27
+ },
28
+ label: {
29
+ fontSize: dimensions.dimension06,
30
+ color: '#222',
31
+ },
32
+ description: {
33
+ fontSize: dimensions.dimension05,
34
+ color: '#666',
35
+ },
36
+ },
37
+ error: {
38
+ container: {},
39
+ radio: {
40
+ borderColor: '#E53935',
41
+ },
42
+ dot: {
43
+ backgroundColor: '#E53935',
44
+ },
45
+ label: {
46
+ color: '#E53935',
47
+ },
48
+ description: {
49
+ color: '#E53935',
50
+ },
51
+ },
52
+ disabled: {
53
+ container: {},
54
+ radio: {
55
+ borderColor: '#CCC',
56
+ backgroundColor: '#F5F5F5',
57
+ },
58
+ dot: {
59
+ backgroundColor: '#CCC',
60
+ },
61
+ label: {
62
+ color: '#CCC',
63
+ },
64
+ description: {
65
+ color: '#CCC',
66
+ },
67
+ },
68
+ },
69
+ medium: {
70
+ default: {
71
+ container: {
72
+ flexDirection: 'row',
73
+ alignItems: 'center',
74
+ minHeight: dimensions.dimension18,
75
+ },
76
+ radio: {
77
+ width: dimensions.dimension08,
78
+ height: dimensions.dimension08,
79
+ borderRadius: dimensions.dimension08 / 2,
80
+ borderWidth: 2,
81
+ borderColor: '#888',
82
+ justifyContent: 'center',
83
+ alignItems: 'center',
84
+ marginRight: dimensions.dimension05,
85
+ },
86
+ dot: {
87
+ width: dimensions.dimension06,
88
+ height: dimensions.dimension06,
89
+ borderRadius: dimensions.dimension06 / 2,
90
+ backgroundColor: '#888',
91
+ },
92
+ label: {
93
+ fontSize: dimensions.dimension07,
94
+ color: '#222',
95
+ },
96
+ description: {
97
+ fontSize: dimensions.dimension06,
98
+ color: '#666',
99
+ },
100
+ },
101
+ error: {
102
+ container: {},
103
+ radio: {
104
+ borderColor: '#E53935',
105
+ },
106
+ dot: {
107
+ backgroundColor: '#E53935',
108
+ },
109
+ label: {
110
+ color: '#E53935',
111
+ },
112
+ description: {
113
+ color: '#E53935',
114
+ },
115
+ },
116
+ disabled: {
117
+ container: {},
118
+ radio: {
119
+ borderColor: '#CCC',
120
+ backgroundColor: '#F5F5F5',
121
+ },
122
+ dot: {
123
+ backgroundColor: '#CCC',
124
+ },
125
+ label: {
126
+ color: '#CCC',
127
+ },
128
+ description: {
129
+ color: '#CCC',
130
+ },
131
+ },
132
+ },
133
+ large: {
134
+ default: {
135
+ container: {
136
+ flexDirection: 'row',
137
+ alignItems: 'center',
138
+ minHeight: dimensions.dimension19,
139
+ },
140
+ radio: {
141
+ width: dimensions.dimension09,
142
+ height: dimensions.dimension09,
143
+ borderRadius: dimensions.dimension09 / 2,
144
+ borderWidth: 2,
145
+ borderColor: '#888',
146
+ justifyContent: 'center',
147
+ alignItems: 'center',
148
+ marginRight: dimensions.dimension06,
149
+ },
150
+ dot: {
151
+ width: dimensions.dimension07,
152
+ height: dimensions.dimension07,
153
+ borderRadius: dimensions.dimension07 / 2,
154
+ backgroundColor: '#888',
155
+ },
156
+ label: {
157
+ fontSize: dimensions.dimension08,
158
+ color: '#222',
159
+ },
160
+ description: {
161
+ fontSize: dimensions.dimension07,
162
+ color: '#666',
163
+ },
164
+ },
165
+ error: {
166
+ container: {},
167
+ radio: {
168
+ borderColor: '#E53935',
169
+ },
170
+ dot: {
171
+ backgroundColor: '#E53935',
172
+ },
173
+ label: {
174
+ color: '#E53935',
175
+ },
176
+ description: {
177
+ color: '#E53935',
178
+ },
179
+ },
180
+ disabled: {
181
+ container: {},
182
+ radio: {
183
+ borderColor: '#CCC',
184
+ backgroundColor: '#F5F5F5',
185
+ },
186
+ dot: {
187
+ backgroundColor: '#CCC',
188
+ },
189
+ label: {
190
+ color: '#CCC',
191
+ },
192
+ description: {
193
+ color: '#CCC',
194
+ },
195
+ },
196
+ },
197
+ };
@@ -0,0 +1,35 @@
1
+ import {ViewStyle, TextStyle} from 'react-native';
2
+
3
+ export type RadioButtonSize = 'small' | 'medium' | 'large';
4
+ export type RadioButtonVariant = 'default' | 'error' | 'disabled';
5
+
6
+ export interface RadioButtonProps {
7
+ checked: boolean;
8
+ onPress: () => void;
9
+ label: string;
10
+ size?: RadioButtonSize;
11
+ variant?: RadioButtonVariant;
12
+ disabled?: boolean;
13
+ style?: ViewStyle;
14
+ labelStyle?: TextStyle;
15
+ description?: string;
16
+ descriptionStyle?: TextStyle;
17
+ prefixIcon?: React.ReactNode;
18
+ suffixIcon?: React.ReactNode;
19
+ }
20
+
21
+ export interface RadioButtonTheme {
22
+ container: ViewStyle;
23
+ radio: ViewStyle;
24
+ dot: ViewStyle;
25
+ label: TextStyle;
26
+ description: TextStyle;
27
+ }
28
+
29
+ export type RadioButtonThemeVariant = {
30
+ [key in RadioButtonVariant]: RadioButtonTheme;
31
+ };
32
+
33
+ export type RadioButtonThemeSize = {
34
+ [key in RadioButtonSize]: RadioButtonThemeVariant;
35
+ };
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ assets: ['./assets/resources/fonts'],
3
+ };
@@ -0,0 +1,7 @@
1
+ import { Breakpoints } from './helper';
2
+
3
+ export type VariantBreakPoints = {
4
+ [Key in keyof typeof Breakpoints]: string;
5
+ } & {
6
+ default: string; // Adding a default property
7
+ };
@@ -0,0 +1,53 @@
1
+ import {PixelRatio} from 'react-native';
2
+
3
+ import {Dimensions} from 'react-native';
4
+ import type {VariantBreakPoints} from './Type';
5
+
6
+ export const Breakpoints = {
7
+ xs: 0, // Extra small
8
+ sm: 576, // Small
9
+ md: 768, // Medium
10
+ lg: 992, // Large
11
+ xl: 1200, // Extra large
12
+ xxl: 1400, // Extra extra large
13
+ };
14
+
15
+ export const getDeviceBreakpoint = (): keyof typeof Breakpoints => {
16
+ const {width} = Dimensions.get('window');
17
+
18
+ if (width >= Breakpoints.xxl) return 'xxl';
19
+ if (width >= Breakpoints.xl) return 'xl';
20
+ if (width >= Breakpoints.lg) return 'lg';
21
+ if (width >= Breakpoints.md) return 'md';
22
+ if (width >= Breakpoints.sm) return 'sm';
23
+ return 'xs';
24
+ };
25
+
26
+ // Helper function to scale font based on system settings
27
+ export const scaleFont = (size: string | number | undefined) => {
28
+ if (typeof size === 'number') {
29
+ return size / PixelRatio.getFontScale();
30
+ }
31
+ return size; // Return string or undefined as is
32
+ };
33
+
34
+ export const getDeviceVariantByBreakPoint = (
35
+ variantBreakPoints: VariantBreakPoints | string,
36
+ ) => {
37
+ if (typeof variantBreakPoints === 'string') {
38
+ return variantBreakPoints;
39
+ }
40
+ const deviceSize = getDeviceBreakpoint();
41
+ return variantBreakPoints[deviceSize];
42
+ };
43
+
44
+ //this is important to resolve the variant based on the breakpoint
45
+
46
+ export const resolveVariant = (
47
+ variant: string | VariantBreakPoints,
48
+ breakpoint: keyof VariantBreakPoints,
49
+ ): string => {
50
+ return typeof variant === 'string'
51
+ ? variant
52
+ : variant[breakpoint] || variant.default;
53
+ };
@@ -0,0 +1,119 @@
1
+ import React, {useRef, useEffect} from 'react';
2
+ import {Pressable, StyleSheet, Animated, Easing} from 'react-native';
3
+ import {useSliceTheme} from '../contextProvider/context';
4
+ import type {ViewStyle} from 'react-native';
5
+ import type {SwitchSize, SwitchBrand} from './Type';
6
+ import {SWITCH_THEME} from './Token';
7
+
8
+ interface SwitchProps {
9
+ checked: boolean;
10
+ onChange: (checked: boolean) => void;
11
+ size?: SwitchSize;
12
+ disabled?: boolean;
13
+ brand?: SwitchBrand;
14
+ style?: ViewStyle;
15
+ id?: string;
16
+ }
17
+
18
+ const ANIMATION_DURATION = 200;
19
+
20
+ const Switch: React.FC<SwitchProps> = ({
21
+ checked,
22
+ onChange,
23
+ size = 'medium',
24
+ disabled = false,
25
+ brand = 'CO',
26
+ style,
27
+ id,
28
+ }) => {
29
+ const {theme} = useSliceTheme();
30
+ const switchTheme = SWITCH_THEME[size];
31
+ const state = disabled ? 'disabled' : checked ? 'checked' : 'default';
32
+ const stylesObj =
33
+ state === 'checked'
34
+ ? switchTheme.checked(theme, brand)
35
+ : state === 'disabled'
36
+ ? switchTheme.disabled(theme)
37
+ : switchTheme.default(theme);
38
+
39
+ // Calculate track and thumb sizes
40
+ const trackWidth = Number(stylesObj.track.width) || 0;
41
+ const trackHeight = Number(stylesObj.track.height) || 0;
42
+ const thumbWidth = Number(stylesObj.thumb.width) || 0;
43
+ const thumbHeight = Number(stylesObj.thumb.height) || 0;
44
+ const paddingLeft = Number(stylesObj.track.paddingLeft) || 0;
45
+ const paddingRight = Number(stylesObj.track.paddingRight) || 0;
46
+ const thumbTop = (trackHeight - thumbHeight) / 2;
47
+
48
+ // Thumb: left for OFF, right for ON
49
+ const thumbRest = paddingLeft; // left end (OFF)
50
+ const thumbActive = trackWidth - thumbWidth - paddingRight; // right end (ON)
51
+
52
+ // Animated values
53
+ const anim = useRef(new Animated.Value(checked ? 1 : 0)).current;
54
+
55
+ useEffect(() => {
56
+ Animated.timing(anim, {
57
+ toValue: checked ? 1 : 0,
58
+ duration: ANIMATION_DURATION,
59
+ easing: Easing.out(Easing.ease),
60
+ useNativeDriver: false,
61
+ }).start();
62
+ }, [checked, anim]);
63
+
64
+ // Interpolate thumb position and scale
65
+ const thumbTranslate = anim.interpolate({
66
+ inputRange: [0, 1],
67
+ outputRange: [thumbRest, thumbActive],
68
+ });
69
+ const thumbScale = anim.interpolate({
70
+ inputRange: [0, 1],
71
+ outputRange: [0.8, 1], // scale up when toggled on
72
+ });
73
+ const thumbBgColor = anim.interpolate({
74
+ inputRange: [0, 1],
75
+ outputRange: [
76
+ String(stylesObj.thumb.backgroundColor),
77
+ String(switchTheme.checked(theme, brand).thumb.backgroundColor),
78
+ ],
79
+ });
80
+
81
+ return (
82
+ <Pressable
83
+ onPress={() => !disabled && onChange(!checked)}
84
+ accessibilityRole="switch"
85
+ accessibilityState={{checked, disabled}}
86
+ disabled={disabled}
87
+ style={[styles.track, stylesObj.track, style]}
88
+ testID={id}>
89
+ <Animated.View
90
+ style={[
91
+ styles.thumb,
92
+ stylesObj.thumb,
93
+ {
94
+ transform: [{translateX: thumbTranslate}, {scale: thumbScale}],
95
+ top: thumbTop,
96
+ backgroundColor: thumbBgColor,
97
+ },
98
+ ]}
99
+ />
100
+ </Pressable>
101
+ );
102
+ };
103
+
104
+ const styles = StyleSheet.create({
105
+ track: {
106
+ flexDirection: 'row',
107
+ alignItems: 'center',
108
+ justifyContent: 'flex-start',
109
+ position: 'relative',
110
+ overflow: 'hidden',
111
+ },
112
+ thumb: {
113
+ position: 'absolute',
114
+ left: 0,
115
+ top: 0,
116
+ },
117
+ });
118
+
119
+ export default Switch;