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.
- package/dist/index.d.mts +997 -0
- package/dist/index.d.ts +997 -0
- package/dist/index.js +36837 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +36778 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +66 -0
- package/src/SliceUI/IconMoon.tsx +33 -0
- package/src/SliceUI/assets/Anatomy diagram copy.svg +19 -0
- package/src/SliceUI/assets/Anatomy diagram.svg +19 -0
- package/src/SliceUI/assets/Anatomycheck.svg +15 -0
- package/src/SliceUI/assets/Anatomyinput.svg +32 -0
- package/src/SliceUI/assets/Checkbox.jpg +0 -0
- package/src/SliceUI/assets/Diagram copy.svg +15 -0
- package/src/SliceUI/assets/Diagram.jpg +0 -0
- package/src/SliceUI/assets/Diagram.svg +15 -0
- package/src/SliceUI/assets/Frame 5 copy.png +0 -0
- package/src/SliceUI/assets/Frame 5.png +0 -0
- package/src/SliceUI/assets/Frame 65.png +0 -0
- package/src/SliceUI/assets/Frame_65.png +0 -0
- package/src/SliceUI/assets/Icon copy.svg +3 -0
- package/src/SliceUI/assets/Icon.svg +3 -0
- package/src/SliceUI/assets/Icon_Bridging copy.svg +39 -0
- package/src/SliceUI/assets/Icon_Bridging.svg +39 -0
- package/src/SliceUI/assets/Icon_Consistent copy.svg +39 -0
- package/src/SliceUI/assets/Icon_Consistent.svg +39 -0
- package/src/SliceUI/assets/Icon_Plug copy.svg +38 -0
- package/src/SliceUI/assets/Icon_Plug.svg +38 -0
- package/src/SliceUI/assets/Icon_Reusable copy.svg +39 -0
- package/src/SliceUI/assets/Icon_Reusable.svg +39 -0
- package/src/SliceUI/assets/Layer_1.png +0 -0
- package/src/SliceUI/assets/accessibility.png +0 -0
- package/src/SliceUI/assets/accessibility.svg +1 -0
- package/src/SliceUI/assets/addon-library.png +0 -0
- package/src/SliceUI/assets/assets.png +0 -0
- package/src/SliceUI/assets/avif-test-image.avif +0 -0
- package/src/SliceUI/assets/bridging.svg +13 -0
- package/src/SliceUI/assets/consistent.svg +11 -0
- package/src/SliceUI/assets/context.png +0 -0
- package/src/SliceUI/assets/discord.svg +1 -0
- package/src/SliceUI/assets/docs.png +0 -0
- package/src/SliceUI/assets/figma-plugin.png +0 -0
- package/src/SliceUI/assets/github.svg +1 -0
- package/src/SliceUI/assets/resources/Anatomy diagram.svg +19 -0
- package/src/SliceUI/assets/resources/Anatomycheck.svg +15 -0
- package/src/SliceUI/assets/resources/Anatomyinput.svg +32 -0
- package/src/SliceUI/assets/resources/Diagram.svg +15 -0
- package/src/SliceUI/assets/resources/Frame 5.png +0 -0
- package/src/SliceUI/assets/resources/Frame 65.png +0 -0
- package/src/SliceUI/assets/resources/Icon.svg +3 -0
- package/src/SliceUI/assets/resources/Icon_Bridging.svg +39 -0
- package/src/SliceUI/assets/resources/Icon_Consistent.svg +39 -0
- package/src/SliceUI/assets/resources/Icon_Plug.svg +38 -0
- package/src/SliceUI/assets/resources/Icon_Reusable.svg +39 -0
- package/src/SliceUI/assets/resources/fonts/FontIcon.json +150 -0
- package/src/SliceUI/assets/resources/fonts/Lato-Black.ttf +0 -0
- package/src/SliceUI/assets/resources/fonts/Lato-Bold.ttf +0 -0
- package/src/SliceUI/assets/resources/fonts/Lato-Heavy.ttf +0 -0
- package/src/SliceUI/assets/resources/fonts/Lato-Medium.ttf +0 -0
- package/src/SliceUI/assets/resources/fonts/Lato-Regular.ttf +0 -0
- package/src/SliceUI/assets/resources/fonts/Lato.woff2 +0 -0
- package/src/SliceUI/assets/resources/fonts/icomoon.eot +0 -0
- package/src/SliceUI/assets/resources/fonts/icomoon.svg +601 -0
- package/src/SliceUI/assets/resources/fonts/icomoon.ttf +0 -0
- package/src/SliceUI/assets/resources/fonts/icomoon.woff +0 -0
- package/src/SliceUI/assets/resources/fonts/selection.json +1 -0
- package/src/SliceUI/assets/share.png +0 -0
- package/src/SliceUI/assets/styling.png +0 -0
- package/src/SliceUI/assets/testing.png +0 -0
- package/src/SliceUI/assets/theming.png +0 -0
- package/src/SliceUI/assets/tutorials.svg +1 -0
- package/src/SliceUI/assets/youtube.svg +1 -0
- package/src/SliceUI/automation/helper.ts +29 -0
- package/src/SliceUI/avatar/Avatar.tsx +237 -0
- package/src/SliceUI/avatar/Token.ts +116 -0
- package/src/SliceUI/avatar/Type.ts +36 -0
- package/src/SliceUI/avatar/helper.ts +53 -0
- package/src/SliceUI/badge/Badge.tsx +308 -0
- package/src/SliceUI/badge/Token.ts +202 -0
- package/src/SliceUI/badge/Type.ts +46 -0
- package/src/SliceUI/badge/helper.ts +39 -0
- package/src/SliceUI/button/Button.tsx +243 -0
- package/src/SliceUI/button/Token.ts +138 -0
- package/src/SliceUI/button/Type.ts +34 -0
- package/src/SliceUI/button/helper.ts +125 -0
- package/src/SliceUI/checkbox/Checkbox.tsx +176 -0
- package/src/SliceUI/checkbox/Token.ts +128 -0
- package/src/SliceUI/checkbox/Type.ts +35 -0
- package/src/SliceUI/chip/Chip.tsx +290 -0
- package/src/SliceUI/chip/Token.ts +151 -0
- package/src/SliceUI/chip/Type.ts +43 -0
- package/src/SliceUI/chip/helper.ts +40 -0
- package/src/SliceUI/colors/Pallete.ts +151 -0
- package/src/SliceUI/colors/Token.ts +110 -0
- package/src/SliceUI/colors/Type.ts +56 -0
- package/src/SliceUI/contextProvider/context.tsx +108 -0
- package/src/SliceUI/divider/Divider.tsx +109 -0
- package/src/SliceUI/divider/Token.ts +18 -0
- package/src/SliceUI/divider/Type.ts +26 -0
- package/src/SliceUI/icon/CustomIcon.ts +4 -0
- package/src/SliceUI/icon/IcoMoonIcon.tsx +11 -0
- package/src/SliceUI/icon/Icon.tsx +38 -0
- package/src/SliceUI/icon/Token.ts +14 -0
- package/src/SliceUI/icon/Type.ts +13 -0
- package/src/SliceUI/icon/selection.json +1 -0
- package/src/SliceUI/input/Input.tsx +573 -0
- package/src/SliceUI/input/ToDo.md +99 -0
- package/src/SliceUI/input/Token.ts +372 -0
- package/src/SliceUI/input/Type.ts +109 -0
- package/src/SliceUI/input/components/InputPortal.tsx +211 -0
- package/src/SliceUI/input/components/NativeBottomSheet.tsx +296 -0
- package/src/SliceUI/input/components/SelectChip.tsx +185 -0
- package/src/SliceUI/input/components/SelectList.tsx +173 -0
- package/src/SliceUI/input/components/SelectListItem.tsx +377 -0
- package/src/SliceUI/input/components/SelectScrollbarStyle.ts +44 -0
- package/src/SliceUI/input/hooks/useCustomScrollbar.ts +17 -0
- package/src/SliceUI/input/hooks/useInputState.ts +41 -0
- package/src/SliceUI/input/hooks/useLabelAnimation.ts +132 -0
- package/src/SliceUI/input/hooks/useOutsideClick.ts +38 -0
- package/src/SliceUI/input/hooks/useSelectLogic.ts +338 -0
- package/src/SliceUI/input/utils/inputUtils.ts +120 -0
- package/src/SliceUI/input/utils/selectUtils.ts +85 -0
- package/src/SliceUI/input/utils/styleUtils.ts +50 -0
- package/src/SliceUI/input/variants/CurrencyInput/CurrencyInput.tsx +16 -0
- package/src/SliceUI/input/variants/CurrencyInput/NativeCurrencyInput.tsx +181 -0
- package/src/SliceUI/input/variants/CurrencyInput/WebCurrencyInput.tsx +163 -0
- package/src/SliceUI/input/variants/CurrencyInput/types.ts +17 -0
- package/src/SliceUI/input/variants/PhoneInput/NativePhoneInput.tsx +189 -0
- package/src/SliceUI/input/variants/PhoneInput/PhoneInput.tsx +16 -0
- package/src/SliceUI/input/variants/PhoneInput/WebPhoneInput.tsx +291 -0
- package/src/SliceUI/input/variants/PhoneInput/types.ts +22 -0
- package/src/SliceUI/input/variants/SelectInput/SelectInput.tsx +407 -0
- package/src/SliceUI/input/variants/SelectInput/types.ts +34 -0
- package/src/SliceUI/input/variants/TextInput.tsx +68 -0
- package/src/SliceUI/layout/Box.tsx +38 -0
- package/src/SliceUI/layout/Center.tsx +38 -0
- package/src/SliceUI/layout/Divider.tsx +37 -0
- package/src/SliceUI/layout/Grid.tsx +75 -0
- package/src/SliceUI/layout/PageContainer.tsx +60 -0
- package/src/SliceUI/layout/ScrollContainer.tsx +72 -0
- package/src/SliceUI/layout/Spacer.tsx +54 -0
- package/src/SliceUI/layout/Stack.tsx +97 -0
- package/src/SliceUI/layout/StickyHeader.tsx +71 -0
- package/src/SliceUI/radio/RadioButton.tsx +130 -0
- package/src/SliceUI/radio/Token.ts +197 -0
- package/src/SliceUI/radio/Type.ts +35 -0
- package/src/SliceUI/react-native.config.js +3 -0
- package/src/SliceUI/responsive/Type.ts +7 -0
- package/src/SliceUI/responsive/helper.ts +53 -0
- package/src/SliceUI/switch/Switch.tsx +119 -0
- package/src/SliceUI/switch/Token.ts +205 -0
- package/src/SliceUI/switch/Type.ts +26 -0
- package/src/SliceUI/tab/TabItem.tsx +204 -0
- package/src/SliceUI/tab/Tabs.tsx +110 -0
- package/src/SliceUI/tab/Token.ts +282 -0
- package/src/SliceUI/tab/Type.ts +66 -0
- package/src/SliceUI/tab/helper.ts +53 -0
- package/src/SliceUI/table/Table.tsx +388 -0
- package/src/SliceUI/table/TableCell.tsx +158 -0
- package/src/SliceUI/table/TableFooter.tsx +353 -0
- package/src/SliceUI/table/TableHeader.tsx +247 -0
- package/src/SliceUI/table/TableRow.tsx +218 -0
- package/src/SliceUI/table/Token.ts +252 -0
- package/src/SliceUI/table/Type.ts +213 -0
- package/src/SliceUI/table/helper.ts +376 -0
- package/src/SliceUI/table/index.ts +53 -0
- package/src/SliceUI/theme/dummyColors.tsx +7 -0
- package/src/SliceUI/theme/theme.ts +107 -0
- package/src/SliceUI/typography/BaseTypographyToken.ts +62 -0
- package/src/SliceUI/typography/FoundationToken.ts +48 -0
- package/src/SliceUI/typography/Token.ts +228 -0
- package/src/SliceUI/typography/Type.ts +20 -0
- package/src/SliceUI/typography/Typography.tsx +99 -0
- package/src/SliceUI/values/BorderRadius.ts +17 -0
- package/src/SliceUI/values/BorderWidth.ts +7 -0
- package/src/SliceUI/values/Dimension.ts +35 -0
- package/src/SliceUI/values/IconSizes.ts +13 -0
- package/src/SliceUI/values/Spacing.ts +22 -0
- package/src/declarations.d.ts +8 -0
- package/src/index.tsx +119 -0
- package/src/stories/Colors.mdx +1418 -0
- package/src/stories/Dimensions.mdx +60 -0
- package/src/stories/GetStarted.mdx +90 -0
- package/src/stories/Introduction.mdx +136 -0
- package/src/stories/Shape.mdx +126 -0
- package/src/stories/Spacing.mdx +104 -0
- package/src/stories/Typography.mdx +454 -0
- package/src/stories/Utils.mdx +277 -0
- package/src/stories/story-components/AddIcon.js +13 -0
- package/src/stories/story-components/RectangleWithBox.jsx +51 -0
- package/src/stories/story-components/RoundedRectangle.jsx +18 -0
- package/src/stories/story-components/RoundedWithWhiteInside.jsx +33 -0
- package/src/stories/story-components/WhiteRoundedRectangle.jsx +107 -0
- package/src/stories/story-components/svgPaths.js +126 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import React, {useState, useMemo, useCallback, type ReactNode} from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Text,
|
|
4
|
+
Pressable,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
Platform,
|
|
7
|
+
type ViewStyle,
|
|
8
|
+
type TextStyle,
|
|
9
|
+
View,
|
|
10
|
+
} from 'react-native';
|
|
11
|
+
import {useSliceTheme} from '../contextProvider/context';
|
|
12
|
+
import {getBackgroundColor, getBorderColor, getTextColor} from './helper';
|
|
13
|
+
import {resolveVariant, scaleFont} from '../responsive/helper';
|
|
14
|
+
import type {SizeType, VariantsType} from './Type';
|
|
15
|
+
import type {BADGE_COLOR_TOKENS} from './Token';
|
|
16
|
+
import {setTestId} from '../automation/helper';
|
|
17
|
+
import type {ExtendedTheme} from '../colors/Type';
|
|
18
|
+
import Typography from '../typography/Typography';
|
|
19
|
+
import {dimensions} from '../values/Dimension';
|
|
20
|
+
import {spacing} from '../values/Spacing';
|
|
21
|
+
import IconMoon from '../IconMoon';
|
|
22
|
+
|
|
23
|
+
interface BadgeProps {
|
|
24
|
+
screenName?: string;
|
|
25
|
+
id?: number | string;
|
|
26
|
+
text: string | string[];
|
|
27
|
+
onPress?: () => void;
|
|
28
|
+
overridedTheme?: any;
|
|
29
|
+
variant?: BadgeVariantType;
|
|
30
|
+
size?: string;
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
rounded?: boolean;
|
|
33
|
+
badgeStyle?: ViewStyle;
|
|
34
|
+
textStyle?: TextStyle;
|
|
35
|
+
showSuffixIcon?: boolean;
|
|
36
|
+
iconName?: string;
|
|
37
|
+
badgeSelected?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const BADGE_VARIANTS = {
|
|
41
|
+
CO: 'co',
|
|
42
|
+
CM: 'cm',
|
|
43
|
+
NEGATIVE: 'negative',
|
|
44
|
+
POSITIVE: 'positive',
|
|
45
|
+
POSTIVE: 'postive',
|
|
46
|
+
} as const;
|
|
47
|
+
|
|
48
|
+
export type BadgeVariantType =
|
|
49
|
+
(typeof BADGE_VARIANTS)[keyof typeof BADGE_VARIANTS];
|
|
50
|
+
|
|
51
|
+
const isWeb = Platform.OS === 'web';
|
|
52
|
+
|
|
53
|
+
const Badge: React.FC<BadgeProps> = ({
|
|
54
|
+
screenName = 'default',
|
|
55
|
+
id = 'default',
|
|
56
|
+
text,
|
|
57
|
+
onPress,
|
|
58
|
+
variant = BADGE_VARIANTS.CO,
|
|
59
|
+
size = 'medium',
|
|
60
|
+
disabled = false,
|
|
61
|
+
rounded = false,
|
|
62
|
+
showSuffixIcon = false,
|
|
63
|
+
iconName,
|
|
64
|
+
badgeStyle,
|
|
65
|
+
badgeSelected,
|
|
66
|
+
textStyle,
|
|
67
|
+
}) => {
|
|
68
|
+
const {theme, deviceBreakpoint} = useSliceTheme();
|
|
69
|
+
const {isDebugBuildType, automationBaseid} = theme;
|
|
70
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
71
|
+
const [isSelected, setIsSelected] = useState(badgeSelected);
|
|
72
|
+
|
|
73
|
+
const onPressBadge = () => {
|
|
74
|
+
setIsSelected(!isSelected);
|
|
75
|
+
onPress?.();
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const responsiveSize = useMemo(
|
|
79
|
+
() => resolveVariant(size, deviceBreakpoint),
|
|
80
|
+
[size, deviceBreakpoint],
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const badgeTheme = useMemo(() => {
|
|
84
|
+
const badgeType = 'solid';
|
|
85
|
+
const styleKey = rounded ? `${badgeType}Rounded` : badgeType;
|
|
86
|
+
|
|
87
|
+
return theme.badgeStyles[responsiveSize as SizeType][
|
|
88
|
+
styleKey as VariantsType
|
|
89
|
+
];
|
|
90
|
+
}, [responsiveSize, rounded, theme]);
|
|
91
|
+
|
|
92
|
+
const textTheme = useMemo(
|
|
93
|
+
() => theme.badgeTextStyles[responsiveSize as SizeType],
|
|
94
|
+
[responsiveSize, theme.badgeTextStyles],
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const defaultBgColor = useMemo(
|
|
98
|
+
() =>
|
|
99
|
+
getBackgroundColor(
|
|
100
|
+
variant as keyof typeof BADGE_COLOR_TOKENS,
|
|
101
|
+
'default',
|
|
102
|
+
theme as ExtendedTheme,
|
|
103
|
+
),
|
|
104
|
+
[variant, theme],
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const hoverBgColor = useMemo(
|
|
108
|
+
() =>
|
|
109
|
+
getBackgroundColor(
|
|
110
|
+
variant as keyof typeof BADGE_COLOR_TOKENS,
|
|
111
|
+
'hover',
|
|
112
|
+
theme as ExtendedTheme,
|
|
113
|
+
),
|
|
114
|
+
[variant, theme],
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const disabledBgColor = useMemo(
|
|
118
|
+
() =>
|
|
119
|
+
getBackgroundColor(
|
|
120
|
+
variant as keyof typeof BADGE_COLOR_TOKENS,
|
|
121
|
+
'disabled',
|
|
122
|
+
theme as ExtendedTheme,
|
|
123
|
+
),
|
|
124
|
+
[variant, theme],
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const pressedBgColor = useMemo(
|
|
128
|
+
() =>
|
|
129
|
+
getBackgroundColor(
|
|
130
|
+
variant as keyof typeof BADGE_COLOR_TOKENS,
|
|
131
|
+
'pressed',
|
|
132
|
+
theme as ExtendedTheme,
|
|
133
|
+
),
|
|
134
|
+
[variant, theme],
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const selectedBgColor = useMemo(
|
|
138
|
+
() =>
|
|
139
|
+
getBackgroundColor(
|
|
140
|
+
variant as keyof typeof BADGE_COLOR_TOKENS,
|
|
141
|
+
'selected',
|
|
142
|
+
theme as ExtendedTheme,
|
|
143
|
+
),
|
|
144
|
+
[variant, theme],
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
const borderColor = useMemo(
|
|
148
|
+
() =>
|
|
149
|
+
getBorderColor(
|
|
150
|
+
variant as keyof typeof BADGE_COLOR_TOKENS,
|
|
151
|
+
isSelected ? 'selected' : 'default',
|
|
152
|
+
theme as ExtendedTheme,
|
|
153
|
+
),
|
|
154
|
+
[variant, isSelected, theme],
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const textColor = useMemo(
|
|
158
|
+
() =>
|
|
159
|
+
getTextColor(
|
|
160
|
+
variant as keyof typeof BADGE_COLOR_TOKENS,
|
|
161
|
+
isSelected ? 'selected' : 'default',
|
|
162
|
+
theme as ExtendedTheme,
|
|
163
|
+
),
|
|
164
|
+
[variant, isSelected, theme],
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
const opacity = useMemo(() => (disabled ? 0.3 : 1), [disabled]);
|
|
168
|
+
|
|
169
|
+
const iconStyleMemo = useMemo(() => {
|
|
170
|
+
const iconSize = scaleFont(
|
|
171
|
+
theme?.badgeIconStyles?.[responsiveSize as SizeType]?.size,
|
|
172
|
+
);
|
|
173
|
+
return {
|
|
174
|
+
size: iconSize,
|
|
175
|
+
color: textColor,
|
|
176
|
+
paddingRight: spacing.space100,
|
|
177
|
+
paddingLeft: spacing.space100,
|
|
178
|
+
};
|
|
179
|
+
}, [responsiveSize, textColor, theme.badgeIconStyles]);
|
|
180
|
+
|
|
181
|
+
const applyIconStyle = useCallback(
|
|
182
|
+
(icon: ReactNode) =>
|
|
183
|
+
icon
|
|
184
|
+
? React.cloneElement(icon as React.ReactElement, iconStyleMemo)
|
|
185
|
+
: null,
|
|
186
|
+
[iconStyleMemo],
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
const combinedButtonStyle = useMemo(
|
|
190
|
+
() =>
|
|
191
|
+
StyleSheet.flatten([
|
|
192
|
+
styles.baseBadge,
|
|
193
|
+
badgeTheme,
|
|
194
|
+
{
|
|
195
|
+
backgroundColor: disabled
|
|
196
|
+
? disabledBgColor
|
|
197
|
+
: isHovered
|
|
198
|
+
? hoverBgColor
|
|
199
|
+
: defaultBgColor,
|
|
200
|
+
borderColor,
|
|
201
|
+
opacity,
|
|
202
|
+
},
|
|
203
|
+
badgeStyle,
|
|
204
|
+
]),
|
|
205
|
+
[
|
|
206
|
+
disabled,
|
|
207
|
+
disabledBgColor,
|
|
208
|
+
badgeTheme,
|
|
209
|
+
isHovered,
|
|
210
|
+
hoverBgColor,
|
|
211
|
+
defaultBgColor,
|
|
212
|
+
borderColor,
|
|
213
|
+
opacity,
|
|
214
|
+
badgeStyle,
|
|
215
|
+
],
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
const pressedBadgeStyle = useMemo(
|
|
219
|
+
() =>
|
|
220
|
+
StyleSheet.flatten([
|
|
221
|
+
combinedButtonStyle,
|
|
222
|
+
{backgroundColor: pressedBgColor},
|
|
223
|
+
]),
|
|
224
|
+
[combinedButtonStyle, pressedBgColor],
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
const selectedBadgeStyle = useMemo(
|
|
228
|
+
() =>
|
|
229
|
+
StyleSheet.flatten([
|
|
230
|
+
combinedButtonStyle,
|
|
231
|
+
{backgroundColor: selectedBgColor},
|
|
232
|
+
]),
|
|
233
|
+
[combinedButtonStyle, selectedBgColor],
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
const typographyVariant = useMemo(() => {
|
|
237
|
+
switch (responsiveSize) {
|
|
238
|
+
case 'small':
|
|
239
|
+
return 'captionBold';
|
|
240
|
+
case 'medium':
|
|
241
|
+
return 'body2Bold';
|
|
242
|
+
case 'large':
|
|
243
|
+
return 'body1Bold';
|
|
244
|
+
case 'xLarge':
|
|
245
|
+
return 'heading5Bold';
|
|
246
|
+
case 'xxLarge':
|
|
247
|
+
return 'heading4Bold';
|
|
248
|
+
default:
|
|
249
|
+
return 'body2Bold';
|
|
250
|
+
}
|
|
251
|
+
}, [responsiveSize]);
|
|
252
|
+
|
|
253
|
+
const combinedTextStyle = useMemo(
|
|
254
|
+
() =>
|
|
255
|
+
StyleSheet.flatten([
|
|
256
|
+
styles.baseText,
|
|
257
|
+
{color: textColor},
|
|
258
|
+
textStyle,
|
|
259
|
+
]) as TextStyle,
|
|
260
|
+
[textColor, textStyle],
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
return (
|
|
264
|
+
<Pressable
|
|
265
|
+
onPress={onPressBadge}
|
|
266
|
+
disabled={disabled}
|
|
267
|
+
style={({pressed}) =>
|
|
268
|
+
isSelected
|
|
269
|
+
? selectedBadgeStyle
|
|
270
|
+
: pressed
|
|
271
|
+
? pressedBadgeStyle
|
|
272
|
+
: combinedButtonStyle
|
|
273
|
+
}
|
|
274
|
+
{...(isWeb && {
|
|
275
|
+
onMouseEnter: () => setIsHovered(true),
|
|
276
|
+
onMouseLeave: () => setIsHovered(false),
|
|
277
|
+
})}
|
|
278
|
+
{...(isDebugBuildType && automationBaseid
|
|
279
|
+
? setTestId(automationBaseid, screenName, id)
|
|
280
|
+
: {})}>
|
|
281
|
+
<Typography style={combinedTextStyle} variant={typographyVariant}>
|
|
282
|
+
{text}
|
|
283
|
+
</Typography>
|
|
284
|
+
{isSelected && showSuffixIcon && iconName && (
|
|
285
|
+
<View style={{paddingLeft: spacing.space50}}>
|
|
286
|
+
<IconMoon
|
|
287
|
+
icon={iconName}
|
|
288
|
+
color={textColor}
|
|
289
|
+
size={iconStyleMemo.size}
|
|
290
|
+
/>
|
|
291
|
+
</View>
|
|
292
|
+
)}
|
|
293
|
+
</Pressable>
|
|
294
|
+
);
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const styles = StyleSheet.create({
|
|
298
|
+
baseBadge: {
|
|
299
|
+
alignItems: 'center',
|
|
300
|
+
justifyContent: 'center',
|
|
301
|
+
flexDirection: 'row',
|
|
302
|
+
},
|
|
303
|
+
baseText: {
|
|
304
|
+
textAlign: 'center',
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
export default Badge;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import {spacing} from '../values/Spacing';
|
|
2
|
+
import {borderRadius} from '../values/BorderRadius';
|
|
3
|
+
import type {
|
|
4
|
+
BadgeIconSizeType,
|
|
5
|
+
BadgeSizeType,
|
|
6
|
+
BadgeTextSizeType,
|
|
7
|
+
SizePadding,
|
|
8
|
+
} from './Type';
|
|
9
|
+
import {TYPOGRAPHY_STYLES} from '../typography/Token';
|
|
10
|
+
import type {TextStyle} from 'react-native';
|
|
11
|
+
import {ICON_SIZES} from '../icon/Token';
|
|
12
|
+
import type {ExtendedTheme} from '../colors/Type';
|
|
13
|
+
|
|
14
|
+
// Variant styles (shared across sizes)
|
|
15
|
+
const variantStyles = {
|
|
16
|
+
solid: {borderRadius: borderRadius.borderRadius40},
|
|
17
|
+
solidRounded: {borderRadius: borderRadius.borderRadiusFull},
|
|
18
|
+
outline: {borderRadius: borderRadius.borderRadius40, borderWidth: 1},
|
|
19
|
+
outlineRounded: {
|
|
20
|
+
borderRadius: borderRadius.borderRadiusFull,
|
|
21
|
+
borderWidth: 1,
|
|
22
|
+
},
|
|
23
|
+
} as const;
|
|
24
|
+
|
|
25
|
+
// Size-specific padding - Badge typically has smaller padding than Chip
|
|
26
|
+
const sizePaddings = {
|
|
27
|
+
small: {
|
|
28
|
+
paddingVertical: spacing.space100,
|
|
29
|
+
paddingHorizontal: spacing.space200,
|
|
30
|
+
},
|
|
31
|
+
medium: {
|
|
32
|
+
paddingVertical: spacing.space150,
|
|
33
|
+
paddingHorizontal: spacing.space250,
|
|
34
|
+
},
|
|
35
|
+
large: {
|
|
36
|
+
paddingVertical: spacing.space200,
|
|
37
|
+
paddingHorizontal: spacing.space300,
|
|
38
|
+
},
|
|
39
|
+
xLarge: {
|
|
40
|
+
paddingVertical: spacing.space250,
|
|
41
|
+
paddingHorizontal: spacing.space350,
|
|
42
|
+
},
|
|
43
|
+
xxLarge: {
|
|
44
|
+
paddingVertical: spacing.space300,
|
|
45
|
+
paddingHorizontal: spacing.space400,
|
|
46
|
+
},
|
|
47
|
+
} as const;
|
|
48
|
+
|
|
49
|
+
// Helper function to create styles for a given size
|
|
50
|
+
const createStylesForSize = (sizePadding: SizePadding) => ({
|
|
51
|
+
solid: {...variantStyles.solid, ...sizePadding},
|
|
52
|
+
solidRounded: {
|
|
53
|
+
...variantStyles.solidRounded,
|
|
54
|
+
...sizePadding,
|
|
55
|
+
},
|
|
56
|
+
outline: {
|
|
57
|
+
...variantStyles.outline,
|
|
58
|
+
...sizePadding,
|
|
59
|
+
},
|
|
60
|
+
outlineRounded: {
|
|
61
|
+
...variantStyles.outlineRounded,
|
|
62
|
+
...sizePadding,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Export the badge styles
|
|
67
|
+
export const BADGE_STYLE: BadgeSizeType = {
|
|
68
|
+
small: createStylesForSize(sizePaddings.small),
|
|
69
|
+
medium: createStylesForSize(sizePaddings.medium),
|
|
70
|
+
large: createStylesForSize(sizePaddings.large),
|
|
71
|
+
xLarge: createStylesForSize(sizePaddings.xLarge),
|
|
72
|
+
xxLarge: createStylesForSize(sizePaddings.xxLarge),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export function textViewWrapperStyle(
|
|
76
|
+
textStyle: TextStyle,
|
|
77
|
+
marginRight?: TextStyle['marginHorizontal'],
|
|
78
|
+
): TextStyle {
|
|
79
|
+
return {...textStyle, lineHeight: undefined, marginRight};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const BADGE_TXT_STYLE: BadgeTextSizeType = {
|
|
83
|
+
small: textViewWrapperStyle(
|
|
84
|
+
TYPOGRAPHY_STYLES.captionBold as TextStyle,
|
|
85
|
+
spacing.space50,
|
|
86
|
+
),
|
|
87
|
+
medium: textViewWrapperStyle(
|
|
88
|
+
TYPOGRAPHY_STYLES.body2Bold as TextStyle,
|
|
89
|
+
spacing.space50,
|
|
90
|
+
),
|
|
91
|
+
large: textViewWrapperStyle(
|
|
92
|
+
TYPOGRAPHY_STYLES.body1Bold as TextStyle,
|
|
93
|
+
spacing.space50,
|
|
94
|
+
),
|
|
95
|
+
xLarge: textViewWrapperStyle(
|
|
96
|
+
TYPOGRAPHY_STYLES.heading5Bold as TextStyle,
|
|
97
|
+
spacing.space50,
|
|
98
|
+
),
|
|
99
|
+
xxLarge: textViewWrapperStyle(
|
|
100
|
+
TYPOGRAPHY_STYLES.heading4Bold as TextStyle,
|
|
101
|
+
spacing.space50,
|
|
102
|
+
),
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const BADGE_ICON_STYLE: BadgeIconSizeType = {
|
|
106
|
+
xxLarge: ICON_SIZES.medium,
|
|
107
|
+
xLarge: ICON_SIZES.small,
|
|
108
|
+
large: ICON_SIZES.xSmall,
|
|
109
|
+
medium: ICON_SIZES.xxSmall,
|
|
110
|
+
small: ICON_SIZES.xxSmall,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const BADGE_ROUNDED_BORDER_RADIUS = borderRadius.borderRadiusFull;
|
|
114
|
+
|
|
115
|
+
// Color tokens based on the design spec
|
|
116
|
+
export const BADGE_COLOR_TOKENS = {
|
|
117
|
+
co: {
|
|
118
|
+
background: {
|
|
119
|
+
default: (theme: ExtendedTheme) => theme.colors.colorBackgroundNegative, // Red background
|
|
120
|
+
pressed: (theme: ExtendedTheme) => theme.colors.colorBackgroundNegative,
|
|
121
|
+
hover: (theme: ExtendedTheme) => theme.colors.colorBackgroundNegative,
|
|
122
|
+
selected: (theme: ExtendedTheme) => theme.colors.colorBackgroundNegative,
|
|
123
|
+
disabled: (theme: ExtendedTheme) => theme.colors.colorBackgroundSecondary,
|
|
124
|
+
},
|
|
125
|
+
border: {
|
|
126
|
+
default: (theme: ExtendedTheme) => theme.colors.colorBorderNegative,
|
|
127
|
+
selected: (theme: ExtendedTheme) => theme.colors.colorBorderNegative,
|
|
128
|
+
},
|
|
129
|
+
text: {
|
|
130
|
+
default: () => '#FFFFFF', // White text on red background
|
|
131
|
+
selected: () => '#FFFFFF',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
cm: {
|
|
135
|
+
background: {
|
|
136
|
+
default: (theme: ExtendedTheme) => theme.colors.colorBackgroundPositive, // Green background
|
|
137
|
+
pressed: (theme: ExtendedTheme) => theme.colors.colorBackgroundPositive,
|
|
138
|
+
hover: (theme: ExtendedTheme) => theme.colors.colorBackgroundPositive,
|
|
139
|
+
selected: (theme: ExtendedTheme) => theme.colors.colorBackgroundPositive,
|
|
140
|
+
disabled: (theme: ExtendedTheme) => theme.colors.colorBackgroundSecondary,
|
|
141
|
+
},
|
|
142
|
+
border: {
|
|
143
|
+
default: (theme: ExtendedTheme) => theme.colors.colorBorderPositive,
|
|
144
|
+
selected: (theme: ExtendedTheme) => theme.colors.colorBorderPositive,
|
|
145
|
+
},
|
|
146
|
+
text: {
|
|
147
|
+
default: () => '#FFFFFF', // White text on green background
|
|
148
|
+
selected: () => '#FFFFFF',
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
negative: {
|
|
152
|
+
background: {
|
|
153
|
+
default: (theme: ExtendedTheme) => theme.colors.colorBackgroundNegative, // Red background
|
|
154
|
+
pressed: (theme: ExtendedTheme) => theme.colors.colorBackgroundNegative,
|
|
155
|
+
hover: (theme: ExtendedTheme) => theme.colors.colorBackgroundNegative,
|
|
156
|
+
selected: (theme: ExtendedTheme) => theme.colors.colorBackgroundNegative,
|
|
157
|
+
disabled: (theme: ExtendedTheme) => theme.colors.colorBackgroundSecondary,
|
|
158
|
+
},
|
|
159
|
+
border: {
|
|
160
|
+
default: (theme: ExtendedTheme) => theme.colors.colorBorderNegative,
|
|
161
|
+
selected: (theme: ExtendedTheme) => theme.colors.colorBorderNegative,
|
|
162
|
+
},
|
|
163
|
+
text: {
|
|
164
|
+
default: () => '#FFFFFF', // White text on red background
|
|
165
|
+
selected: () => '#FFFFFF',
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
positive: {
|
|
169
|
+
background: {
|
|
170
|
+
default: (theme: ExtendedTheme) => theme.colors.colorBackgroundPositive, // Green background
|
|
171
|
+
pressed: (theme: ExtendedTheme) => theme.colors.colorBackgroundPositive,
|
|
172
|
+
hover: (theme: ExtendedTheme) => theme.colors.colorBackgroundPositive,
|
|
173
|
+
selected: (theme: ExtendedTheme) => theme.colors.colorBackgroundPositive,
|
|
174
|
+
disabled: (theme: ExtendedTheme) => theme.colors.colorBackgroundSecondary,
|
|
175
|
+
},
|
|
176
|
+
border: {
|
|
177
|
+
default: (theme: ExtendedTheme) => theme.colors.colorBorderPositive,
|
|
178
|
+
selected: (theme: ExtendedTheme) => theme.colors.colorBorderPositive,
|
|
179
|
+
},
|
|
180
|
+
text: {
|
|
181
|
+
default: () => '#FFFFFF', // White text on green background
|
|
182
|
+
selected: () => '#FFFFFF',
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
postive: {
|
|
186
|
+
background: {
|
|
187
|
+
default: (theme: ExtendedTheme) => theme.colors.colorForegroundPrimary, // Black background
|
|
188
|
+
pressed: (theme: ExtendedTheme) => theme.colors.colorForegroundSecondary,
|
|
189
|
+
hover: (theme: ExtendedTheme) => theme.colors.colorForegroundSecondary,
|
|
190
|
+
selected: (theme: ExtendedTheme) => theme.colors.colorForegroundPrimary,
|
|
191
|
+
disabled: (theme: ExtendedTheme) => theme.colors.colorBackgroundSecondary,
|
|
192
|
+
},
|
|
193
|
+
border: {
|
|
194
|
+
default: (theme: ExtendedTheme) => theme.colors.colorForegroundPrimary,
|
|
195
|
+
selected: (theme: ExtendedTheme) => theme.colors.colorForegroundPrimary,
|
|
196
|
+
},
|
|
197
|
+
text: {
|
|
198
|
+
default: () => '#FFFFFF', // White text on black background
|
|
199
|
+
selected: () => '#FFFFFF',
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
} as const;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import type {TextStyle, ViewStyle} from 'react-native';
|
|
3
|
+
|
|
4
|
+
export type SizeType = 'small' | 'medium' | 'large' | 'xLarge' | 'xxLarge';
|
|
5
|
+
|
|
6
|
+
export type VariantsType =
|
|
7
|
+
| 'solid'
|
|
8
|
+
| 'outline'
|
|
9
|
+
| 'solidRounded'
|
|
10
|
+
| 'outlineRounded';
|
|
11
|
+
|
|
12
|
+
export type BadgeSizeType = {
|
|
13
|
+
[key in SizeType]: BadgeVariantType;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type BadgeVariantType = {
|
|
17
|
+
[key in VariantsType]: ViewStyle;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type BadgeVariants = {
|
|
21
|
+
[key in SizeType]: TextStyle;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type BadgeTextSizeType = {
|
|
25
|
+
[key in SizeType]: TextStyle;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type BadgeIconSizeType = {
|
|
29
|
+
[key in SizeType]: any;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type BadgeState =
|
|
33
|
+
| 'default'
|
|
34
|
+
| 'pressed'
|
|
35
|
+
| 'hover'
|
|
36
|
+
| 'disabled'
|
|
37
|
+
| 'selected';
|
|
38
|
+
|
|
39
|
+
// Badge variants based on the design spec
|
|
40
|
+
export type BadgeVariant = 'co' | 'cm' | 'negative' | 'positive' | 'postive';
|
|
41
|
+
|
|
42
|
+
export type SizePadding = {
|
|
43
|
+
paddingVertical: ViewStyle['paddingVertical'];
|
|
44
|
+
paddingHorizontal: ViewStyle['paddingHorizontal'];
|
|
45
|
+
};
|
|
46
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type {ExtendedTheme} from '../colors/Type';
|
|
2
|
+
import {BADGE_COLOR_TOKENS} from './Token';
|
|
3
|
+
import type {BadgeState} from './Type';
|
|
4
|
+
|
|
5
|
+
export const getBackgroundColor = (
|
|
6
|
+
badgeType: keyof typeof BADGE_COLOR_TOKENS,
|
|
7
|
+
state: BadgeState,
|
|
8
|
+
theme: ExtendedTheme,
|
|
9
|
+
) => {
|
|
10
|
+
const variant = BADGE_COLOR_TOKENS[badgeType] || BADGE_COLOR_TOKENS.co;
|
|
11
|
+
const bg =
|
|
12
|
+
variant.background[state as keyof typeof variant.background] ||
|
|
13
|
+
variant.background.default;
|
|
14
|
+
return bg(theme);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const getBorderColor = (
|
|
18
|
+
badgeType: keyof typeof BADGE_COLOR_TOKENS,
|
|
19
|
+
state: BadgeState,
|
|
20
|
+
theme: ExtendedTheme,
|
|
21
|
+
) => {
|
|
22
|
+
const variant = BADGE_COLOR_TOKENS[badgeType] || BADGE_COLOR_TOKENS.co;
|
|
23
|
+
const border =
|
|
24
|
+
variant.border[state as keyof typeof variant.border] ||
|
|
25
|
+
variant.border.default;
|
|
26
|
+
return border(theme);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const getTextColor = (
|
|
30
|
+
badgeType: keyof typeof BADGE_COLOR_TOKENS,
|
|
31
|
+
state: BadgeState,
|
|
32
|
+
theme: ExtendedTheme,
|
|
33
|
+
) => {
|
|
34
|
+
const variant = BADGE_COLOR_TOKENS[badgeType] || BADGE_COLOR_TOKENS.co;
|
|
35
|
+
const text =
|
|
36
|
+
variant.text[state as keyof typeof variant.text] || variant.text.default;
|
|
37
|
+
return text(theme);
|
|
38
|
+
};
|
|
39
|
+
|