@particle-network/ui-native 0.0.2
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/README.md +57 -0
- package/dist/components/ProgressWrapper/index.d.ts +35 -0
- package/dist/components/ProgressWrapper/index.js +120 -0
- package/dist/components/Text/index.d.ts +2 -0
- package/dist/components/Text/index.js +2 -0
- package/dist/components/Text/text.d.ts +4 -0
- package/dist/components/Text/text.js +196 -0
- package/dist/components/Text/text.types.d.ts +109 -0
- package/dist/components/Text/text.types.js +77 -0
- package/dist/components/UXButton/button.d.ts +3 -0
- package/dist/components/UXButton/button.js +74 -0
- package/dist/components/UXButton/button.styles.d.ts +53 -0
- package/dist/components/UXButton/button.styles.js +157 -0
- package/dist/components/UXButton/button.types.d.ts +18 -0
- package/dist/components/UXButton/button.types.js +0 -0
- package/dist/components/UXButton/index.d.ts +2 -0
- package/dist/components/UXButton/index.js +1 -0
- package/dist/components/UXCheckbox/checkbox-group.d.ts +8 -0
- package/dist/components/UXCheckbox/checkbox-group.js +30 -0
- package/dist/components/UXCheckbox/checkbox.d.ts +10 -0
- package/dist/components/UXCheckbox/checkbox.js +78 -0
- package/dist/components/UXCheckbox/context.d.ts +8 -0
- package/dist/components/UXCheckbox/context.js +8 -0
- package/dist/components/UXCheckbox/index.d.ts +4 -0
- package/dist/components/UXCheckbox/index.js +3 -0
- package/dist/components/UXCheckbox/types.d.ts +6 -0
- package/dist/components/UXCheckbox/types.js +0 -0
- package/dist/components/UXChip/chip.d.ts +3 -0
- package/dist/components/UXChip/chip.js +48 -0
- package/dist/components/UXChip/index.d.ts +2 -0
- package/dist/components/UXChip/index.js +1 -0
- package/dist/components/UXChip/styles.d.ts +24 -0
- package/dist/components/UXChip/styles.js +70 -0
- package/dist/components/UXChip/types.d.ts +11 -0
- package/dist/components/UXChip/types.js +0 -0
- package/dist/components/UXDivider/index.d.ts +8 -0
- package/dist/components/UXDivider/index.js +34 -0
- package/dist/components/UXHint/index.d.ts +7 -0
- package/dist/components/UXHint/index.js +19 -0
- package/dist/components/UXModal/index.d.ts +24 -0
- package/dist/components/UXModal/index.js +271 -0
- package/dist/components/UXPressable/index.d.ts +4 -0
- package/dist/components/UXPressable/index.js +36 -0
- package/dist/components/UXRadio/context.d.ts +7 -0
- package/dist/components/UXRadio/context.js +10 -0
- package/dist/components/UXRadio/index.d.ts +2 -0
- package/dist/components/UXRadio/index.js +2 -0
- package/dist/components/UXRadio/radio-group.d.ts +5 -0
- package/dist/components/UXRadio/radio-group.js +21 -0
- package/dist/components/UXRadio/radio.d.ts +5 -0
- package/dist/components/UXRadio/radio.js +67 -0
- package/dist/components/UXRadio/types.d.ts +10 -0
- package/dist/components/UXRadio/types.js +0 -0
- package/dist/components/UXSwitch/index.d.ts +2 -0
- package/dist/components/UXSwitch/index.js +1 -0
- package/dist/components/UXSwitch/styles.d.ts +16 -0
- package/dist/components/UXSwitch/styles.js +58 -0
- package/dist/components/UXSwitch/switch.d.ts +3 -0
- package/dist/components/UXSwitch/switch.js +103 -0
- package/dist/components/UXSwitch/types.d.ts +11 -0
- package/dist/components/UXSwitch/types.js +0 -0
- package/dist/components/UXTabs/context.d.ts +5 -0
- package/dist/components/UXTabs/context.js +8 -0
- package/dist/components/UXTabs/index.d.ts +4 -0
- package/dist/components/UXTabs/index.js +3 -0
- package/dist/components/UXTabs/styles.d.ts +30 -0
- package/dist/components/UXTabs/styles.js +191 -0
- package/dist/components/UXTabs/tab.d.ts +3 -0
- package/dist/components/UXTabs/tab.js +55 -0
- package/dist/components/UXTabs/tabs.d.ts +3 -0
- package/dist/components/UXTabs/tabs.js +66 -0
- package/dist/components/UXTabs/types.d.ts +23 -0
- package/dist/components/UXTabs/types.js +0 -0
- package/dist/components/UXTooltip/index.d.ts +6 -0
- package/dist/components/UXTooltip/index.js +32 -0
- package/dist/components/UXTouchableOpacity/index.d.ts +4 -0
- package/dist/components/UXTouchableOpacity/index.js +24 -0
- package/dist/components/index.d.ts +22 -0
- package/dist/components/index.js +22 -0
- package/dist/components/input/index.d.ts +3 -0
- package/dist/components/input/index.js +2 -0
- package/dist/components/input/input.d.ts +3 -0
- package/dist/components/input/input.js +138 -0
- package/dist/components/input/number-input.d.ts +3 -0
- package/dist/components/input/number-input.js +231 -0
- package/dist/components/input/styles.d.ts +31 -0
- package/dist/components/input/styles.js +102 -0
- package/dist/components/input/types.d.ts +61 -0
- package/dist/components/input/types.js +0 -0
- package/dist/components/layout/Box/box.d.ts +12 -0
- package/dist/components/layout/Box/box.js +89 -0
- package/dist/components/layout/Box/index.d.ts +3 -0
- package/dist/components/layout/Box/index.js +2 -0
- package/dist/components/layout/Box/useBox.style.d.ts +3 -0
- package/dist/components/layout/Box/useBox.style.js +141 -0
- package/dist/components/layout/Box/useBox.type.d.ts +292 -0
- package/dist/components/layout/Box/useBox.type.js +0 -0
- package/dist/components/layout/Center.d.ts +5 -0
- package/dist/components/layout/Center.js +10 -0
- package/dist/components/layout/Circle.d.ts +7 -0
- package/dist/components/layout/Circle.js +14 -0
- package/dist/components/layout/Flex/flex.d.ts +6 -0
- package/dist/components/layout/Flex/flex.js +33 -0
- package/dist/components/layout/Flex/index.d.ts +4 -0
- package/dist/components/layout/Flex/index.js +3 -0
- package/dist/components/layout/Flex/useFlex.style.d.ts +3 -0
- package/dist/components/layout/Flex/useFlex.style.js +122 -0
- package/dist/components/layout/Flex/useFlex.type.d.ts +65 -0
- package/dist/components/layout/Flex/useFlex.type.js +0 -0
- package/dist/components/layout/Flex/useFlexBox.style.d.ts +134 -0
- package/dist/components/layout/Flex/useFlexBox.style.js +26 -0
- package/dist/components/layout/HStack.d.ts +5 -0
- package/dist/components/layout/HStack.js +11 -0
- package/dist/components/layout/Square.d.ts +9 -0
- package/dist/components/layout/Square.js +14 -0
- package/dist/components/layout/VStack.d.ts +5 -0
- package/dist/components/layout/VStack.js +14 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/useColors.d.ts +7 -0
- package/dist/hooks/useColors.js +18 -0
- package/dist/hooks/useKeyboard.d.ts +4 -0
- package/dist/hooks/useKeyboard.js +29 -0
- package/dist/hooks/useRadius.d.ts +7 -0
- package/dist/hooks/useRadius.js +16 -0
- package/dist/hooks/useSpacing.d.ts +7 -0
- package/dist/hooks/useSpacing.js +16 -0
- package/dist/hooks/useTheme.d.ts +5 -0
- package/dist/hooks/useTheme.js +6 -0
- package/dist/icons/CheckboxOffIcon.d.ts +4 -0
- package/dist/icons/CheckboxOffIcon.js +21 -0
- package/dist/icons/CheckboxOnIcon.d.ts +4 -0
- package/dist/icons/CheckboxOnIcon.js +26 -0
- package/dist/icons/DotIcon.d.ts +4 -0
- package/dist/icons/DotIcon.js +23 -0
- package/dist/icons/QuestionIcon.d.ts +4 -0
- package/dist/icons/QuestionIcon.js +30 -0
- package/dist/icons/RadioOffIcon.d.ts +4 -0
- package/dist/icons/RadioOffIcon.js +22 -0
- package/dist/icons/RadioOnIcon.d.ts +4 -0
- package/dist/icons/RadioOnIcon.js +42 -0
- package/dist/icons/types.d.ts +6 -0
- package/dist/icons/types.js +0 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/provider/ThemeContext.d.ts +3 -0
- package/dist/provider/ThemeContext.js +15 -0
- package/dist/provider/ThemeProvider.d.ts +10 -0
- package/dist/provider/ThemeProvider.js +31 -0
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +2 -0
- package/dist/theme/colors.d.ts +6 -0
- package/dist/theme/colors.js +17 -0
- package/dist/theme/index.d.ts +7 -0
- package/dist/theme/index.js +16 -0
- package/dist/theme/opacity.d.ts +2 -0
- package/dist/theme/opacity.js +3 -0
- package/dist/theme/radius.d.ts +3 -0
- package/dist/theme/radius.js +10 -0
- package/dist/theme/spacing.d.ts +3 -0
- package/dist/theme/spacing.js +10 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +0 -0
- package/dist/types/theme.d.ts +17 -0
- package/dist/types/theme.js +0 -0
- package/dist/utils/triggerHapticFeedback.d.ts +5 -0
- package/dist/utils/triggerHapticFeedback.js +16 -0
- package/package.json +110 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { UXButtonProps } from './button.types';
|
|
2
|
+
export declare const sizeMap: {
|
|
3
|
+
readonly sm: number;
|
|
4
|
+
readonly md: number;
|
|
5
|
+
readonly lg: number;
|
|
6
|
+
readonly auto: undefined;
|
|
7
|
+
};
|
|
8
|
+
export declare const fontSizeMap: {
|
|
9
|
+
readonly sm: number;
|
|
10
|
+
readonly md: number;
|
|
11
|
+
readonly lg: number;
|
|
12
|
+
readonly auto: number;
|
|
13
|
+
};
|
|
14
|
+
export declare const radiusMap: {
|
|
15
|
+
readonly sm: "sm";
|
|
16
|
+
readonly md: "sm";
|
|
17
|
+
readonly lg: "md";
|
|
18
|
+
readonly auto: "sm";
|
|
19
|
+
};
|
|
20
|
+
export declare const useStyles: ({ size, radius, color, variant, isDisabled, isLoading, width, fullWidth, fill, isIconOnly, }: UXButtonProps) => {
|
|
21
|
+
styles: {
|
|
22
|
+
button: {
|
|
23
|
+
flexDirection: "row";
|
|
24
|
+
alignItems: "center";
|
|
25
|
+
justifyContent: "center";
|
|
26
|
+
gap: number;
|
|
27
|
+
paddingVertical: number;
|
|
28
|
+
height: number | undefined;
|
|
29
|
+
width: number | "100%" | undefined;
|
|
30
|
+
flexGrow: number | undefined;
|
|
31
|
+
paddingHorizontal: number;
|
|
32
|
+
backgroundColor: string | undefined;
|
|
33
|
+
borderRadius: number | undefined;
|
|
34
|
+
borderWidth: number;
|
|
35
|
+
borderStyle: "solid";
|
|
36
|
+
borderColor: string | undefined;
|
|
37
|
+
opacity: number;
|
|
38
|
+
};
|
|
39
|
+
buttonPressed: {
|
|
40
|
+
opacity: number;
|
|
41
|
+
transform: {
|
|
42
|
+
scale: number;
|
|
43
|
+
}[];
|
|
44
|
+
};
|
|
45
|
+
title: {
|
|
46
|
+
fontWeight: "500" | "600";
|
|
47
|
+
fontSize: number;
|
|
48
|
+
lineHeight: number;
|
|
49
|
+
color: string | undefined;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
textColor: string | undefined;
|
|
53
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { StyleSheet } from "react-native";
|
|
3
|
+
import { ms } from "react-native-size-matters";
|
|
4
|
+
import { useColors, useRadius } from "../../hooks/index.js";
|
|
5
|
+
import { disabledOpacity } from "../../theme/index.js";
|
|
6
|
+
const sizeMap = {
|
|
7
|
+
sm: ms(24),
|
|
8
|
+
md: ms(30),
|
|
9
|
+
lg: ms(44),
|
|
10
|
+
auto: void 0
|
|
11
|
+
};
|
|
12
|
+
const fontSizeMap = {
|
|
13
|
+
sm: ms(10),
|
|
14
|
+
md: ms(12),
|
|
15
|
+
lg: ms(16),
|
|
16
|
+
auto: ms(12)
|
|
17
|
+
};
|
|
18
|
+
const radiusMap = {
|
|
19
|
+
sm: 'sm',
|
|
20
|
+
md: 'sm',
|
|
21
|
+
lg: 'md',
|
|
22
|
+
auto: 'sm'
|
|
23
|
+
};
|
|
24
|
+
const paddingMap = {
|
|
25
|
+
sm: ms(2),
|
|
26
|
+
md: ms(2),
|
|
27
|
+
lg: ms(4)
|
|
28
|
+
};
|
|
29
|
+
const useStyles = ({ size = 'md', radius, color = 'default', variant = 'solid', isDisabled, isLoading, width, fullWidth, fill, isIconOnly })=>{
|
|
30
|
+
const { getColor } = useColors();
|
|
31
|
+
const { getRadius } = useRadius();
|
|
32
|
+
const height = useMemo(()=>{
|
|
33
|
+
if ('text' === variant || 'auto' === size) return;
|
|
34
|
+
return sizeMap[size];
|
|
35
|
+
}, [
|
|
36
|
+
size,
|
|
37
|
+
variant
|
|
38
|
+
]);
|
|
39
|
+
const widthStyle = useMemo(()=>{
|
|
40
|
+
if (isIconOnly) return height;
|
|
41
|
+
if (fullWidth) return '100%';
|
|
42
|
+
return width;
|
|
43
|
+
}, [
|
|
44
|
+
fullWidth,
|
|
45
|
+
height,
|
|
46
|
+
isIconOnly,
|
|
47
|
+
width
|
|
48
|
+
]);
|
|
49
|
+
const fontSize = useMemo(()=>fontSizeMap[size], [
|
|
50
|
+
size
|
|
51
|
+
]);
|
|
52
|
+
const borderRadius = useMemo(()=>getRadius(radius ?? radiusMap[size]), [
|
|
53
|
+
radius,
|
|
54
|
+
size
|
|
55
|
+
]);
|
|
56
|
+
const paddingHorizontal = useMemo(()=>{
|
|
57
|
+
if (isIconOnly || 'auto' === size || 'text' === variant) return 0;
|
|
58
|
+
return paddingMap[size];
|
|
59
|
+
}, [
|
|
60
|
+
size,
|
|
61
|
+
isIconOnly,
|
|
62
|
+
variant
|
|
63
|
+
]);
|
|
64
|
+
const textColor = useMemo(()=>{
|
|
65
|
+
if ('default' === color) return getColor('default');
|
|
66
|
+
if ('secondary' === color) return getColor('secondary');
|
|
67
|
+
if ('contrast' === color) return getColor('bg-default');
|
|
68
|
+
if ('solid' === variant) return getColor('white');
|
|
69
|
+
return getColor(color);
|
|
70
|
+
}, [
|
|
71
|
+
color,
|
|
72
|
+
getColor,
|
|
73
|
+
variant
|
|
74
|
+
]);
|
|
75
|
+
const backgroundColor = useMemo(()=>{
|
|
76
|
+
if ('solid' === variant) {
|
|
77
|
+
if ([
|
|
78
|
+
'default',
|
|
79
|
+
'secondary'
|
|
80
|
+
].includes(color)) return getColor('bg-300');
|
|
81
|
+
if ('contrast' === color) return getColor('foreground');
|
|
82
|
+
return getColor(color);
|
|
83
|
+
}
|
|
84
|
+
if ('flat' === variant) {
|
|
85
|
+
if ([
|
|
86
|
+
'default',
|
|
87
|
+
'secondary'
|
|
88
|
+
].includes(color)) return `${getColor('bg-300')}40`;
|
|
89
|
+
if ('contrast' === color) return `${getColor('foreground')}40`;
|
|
90
|
+
return `${getColor(color)}20`;
|
|
91
|
+
}
|
|
92
|
+
return 'transparent';
|
|
93
|
+
}, [
|
|
94
|
+
color,
|
|
95
|
+
getColor,
|
|
96
|
+
variant
|
|
97
|
+
]);
|
|
98
|
+
const borderColor = useMemo(()=>{
|
|
99
|
+
if ('bordered' === variant) {
|
|
100
|
+
if ([
|
|
101
|
+
'default',
|
|
102
|
+
'secondary'
|
|
103
|
+
].includes(color)) return getColor('secondary');
|
|
104
|
+
if ('contrast' === color) return getColor('bg-default');
|
|
105
|
+
return getColor(color);
|
|
106
|
+
}
|
|
107
|
+
return 'transparent';
|
|
108
|
+
}, [
|
|
109
|
+
color,
|
|
110
|
+
getColor,
|
|
111
|
+
variant
|
|
112
|
+
]);
|
|
113
|
+
const fontWeight = useMemo(()=>{
|
|
114
|
+
if ('lg' === size) return '600';
|
|
115
|
+
return '500';
|
|
116
|
+
}, [
|
|
117
|
+
size
|
|
118
|
+
]);
|
|
119
|
+
const styles = StyleSheet.create({
|
|
120
|
+
button: {
|
|
121
|
+
flexDirection: 'row',
|
|
122
|
+
alignItems: 'center',
|
|
123
|
+
justifyContent: 'center',
|
|
124
|
+
gap: ms(8),
|
|
125
|
+
paddingVertical: 0,
|
|
126
|
+
height,
|
|
127
|
+
width: widthStyle,
|
|
128
|
+
flexGrow: fill ? 1 : void 0,
|
|
129
|
+
paddingHorizontal,
|
|
130
|
+
backgroundColor,
|
|
131
|
+
borderRadius,
|
|
132
|
+
borderWidth: 'bordered' === variant ? 1 : 0,
|
|
133
|
+
borderStyle: 'solid',
|
|
134
|
+
borderColor,
|
|
135
|
+
opacity: isDisabled || isLoading ? disabledOpacity : 1
|
|
136
|
+
},
|
|
137
|
+
buttonPressed: {
|
|
138
|
+
opacity: 0.8,
|
|
139
|
+
transform: [
|
|
140
|
+
{
|
|
141
|
+
scale: 0.98
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
},
|
|
145
|
+
title: {
|
|
146
|
+
fontWeight,
|
|
147
|
+
fontSize,
|
|
148
|
+
lineHeight: fontSize + ms(4),
|
|
149
|
+
color: textColor
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
return {
|
|
153
|
+
styles,
|
|
154
|
+
textColor
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
export { fontSizeMap, radiusMap, sizeMap, useStyles };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { PressableProps, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import type { UXRadius } from '@particle-network/ui-shared';
|
|
4
|
+
export interface UXButtonProps extends Omit<PressableProps, 'style'> {
|
|
5
|
+
style?: StyleProp<ViewStyle>;
|
|
6
|
+
color?: 'default' | 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'bullish' | 'bearish' | 'contrast';
|
|
7
|
+
size?: 'sm' | 'md' | 'lg' | 'auto';
|
|
8
|
+
variant?: 'solid' | 'bordered' | 'light' | 'flat' | 'text';
|
|
9
|
+
radius?: UXRadius;
|
|
10
|
+
isDisabled?: boolean;
|
|
11
|
+
isLoading?: boolean;
|
|
12
|
+
startContent?: React.ReactNode;
|
|
13
|
+
endContent?: React.ReactNode;
|
|
14
|
+
isIconOnly?: boolean;
|
|
15
|
+
fullWidth?: boolean;
|
|
16
|
+
width?: number;
|
|
17
|
+
fill?: boolean;
|
|
18
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./button.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type FlexProps } from '..';
|
|
3
|
+
import type { UXCheckboxCommonProps } from './types';
|
|
4
|
+
export type UXCheckboxGroupProps = UXCheckboxCommonProps & FlexProps & {
|
|
5
|
+
value?: string[];
|
|
6
|
+
onValueChange?: (value: string[]) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const UXCheckboxGroup: React.FC<UXCheckboxGroupProps>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import { Flex } from "../index.js";
|
|
4
|
+
import { CheckboxGroupContext } from "./context.js";
|
|
5
|
+
const UXCheckboxGroup = ({ size, isDisabled, color, children, gap = 8, value = [], onValueChange, ...props })=>{
|
|
6
|
+
const handleValueChange = (checkboxValue, selected)=>{
|
|
7
|
+
if (selected) onValueChange?.([
|
|
8
|
+
...value,
|
|
9
|
+
checkboxValue
|
|
10
|
+
]);
|
|
11
|
+
else onValueChange?.(value.filter((v)=>v !== checkboxValue));
|
|
12
|
+
};
|
|
13
|
+
return /*#__PURE__*/ jsx(CheckboxGroupContext.Provider, {
|
|
14
|
+
value: {
|
|
15
|
+
size,
|
|
16
|
+
isDisabled,
|
|
17
|
+
color,
|
|
18
|
+
selectedValues: value,
|
|
19
|
+
onValueChange: handleValueChange
|
|
20
|
+
},
|
|
21
|
+
children: /*#__PURE__*/ jsx(Flex, {
|
|
22
|
+
direction: "col",
|
|
23
|
+
gap: gap,
|
|
24
|
+
...props,
|
|
25
|
+
children: children
|
|
26
|
+
})
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
UXCheckboxGroup.displayName = 'UXCheckboxGroup';
|
|
30
|
+
export { UXCheckboxGroup };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type FlexProps } from '..';
|
|
3
|
+
import type { UXCheckboxCommonProps } from './types';
|
|
4
|
+
export type UXCheckboxProps = UXCheckboxCommonProps & FlexProps & {
|
|
5
|
+
defaultSelected?: boolean;
|
|
6
|
+
isSelected?: boolean;
|
|
7
|
+
value?: string;
|
|
8
|
+
onValueChange?: (selected: boolean) => void;
|
|
9
|
+
};
|
|
10
|
+
export declare const UXCheckbox: React.FC<UXCheckboxProps>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { ms } from "react-native-size-matters";
|
|
4
|
+
import { Flex, Text, UXPressable } from "../index.js";
|
|
5
|
+
import CheckboxOffIcon from "../../icons/CheckboxOffIcon.js";
|
|
6
|
+
import CheckboxOnIcon from "../../icons/CheckboxOnIcon.js";
|
|
7
|
+
import { disabledOpacity } from "../../theme/index.js";
|
|
8
|
+
import { useCheckboxGroup } from "./context.js";
|
|
9
|
+
const UXCheckbox = ({ size, color, defaultSelected = false, isSelected, children, value, onValueChange, isDisabled, ...props })=>{
|
|
10
|
+
const [internalSelected, setInternalSelected] = useState(defaultSelected ?? isSelected);
|
|
11
|
+
const groupContext = useCheckboxGroup();
|
|
12
|
+
const isInGroup = null !== groupContext;
|
|
13
|
+
useEffect(()=>{
|
|
14
|
+
if (isInGroup) setInternalSelected(groupContext.selectedValues.includes(value));
|
|
15
|
+
else void 0 !== isSelected ? setInternalSelected(isSelected) : setInternalSelected(defaultSelected);
|
|
16
|
+
}, [
|
|
17
|
+
isSelected,
|
|
18
|
+
groupContext,
|
|
19
|
+
defaultSelected
|
|
20
|
+
]);
|
|
21
|
+
const checkboxColor = color || groupContext?.color || 'primary';
|
|
22
|
+
const checkboxIsDisabled = isDisabled || groupContext?.isDisabled;
|
|
23
|
+
const checkboxSize = size || groupContext?.size || 'md';
|
|
24
|
+
const handleSelectChange = ()=>{
|
|
25
|
+
if (isInGroup) groupContext.onValueChange(value, !internalSelected);
|
|
26
|
+
else {
|
|
27
|
+
onValueChange?.(!internalSelected);
|
|
28
|
+
setInternalSelected(!internalSelected);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const iconSize = useMemo(()=>{
|
|
32
|
+
if ('sm' === checkboxSize) return ms(14);
|
|
33
|
+
if ('lg' === checkboxSize) return ms(20);
|
|
34
|
+
return ms(16);
|
|
35
|
+
}, [
|
|
36
|
+
checkboxSize
|
|
37
|
+
]);
|
|
38
|
+
const labelVariant = useMemo(()=>{
|
|
39
|
+
if ('sm' === checkboxSize) return 'body3Bold';
|
|
40
|
+
if ('lg' === checkboxSize) return 'body1Bold';
|
|
41
|
+
return 'body2Bold';
|
|
42
|
+
}, [
|
|
43
|
+
checkboxSize
|
|
44
|
+
]);
|
|
45
|
+
const gap = useMemo(()=>{
|
|
46
|
+
if ('sm' === checkboxSize) return 6;
|
|
47
|
+
return 8;
|
|
48
|
+
}, [
|
|
49
|
+
checkboxSize
|
|
50
|
+
]);
|
|
51
|
+
return /*#__PURE__*/ jsx(UXPressable, {
|
|
52
|
+
disabled: checkboxIsDisabled,
|
|
53
|
+
style: {
|
|
54
|
+
opacity: checkboxIsDisabled ? disabledOpacity : 1
|
|
55
|
+
},
|
|
56
|
+
onPress: handleSelectChange,
|
|
57
|
+
children: /*#__PURE__*/ jsxs(Flex, {
|
|
58
|
+
gap: gap,
|
|
59
|
+
items: "center",
|
|
60
|
+
...props,
|
|
61
|
+
children: [
|
|
62
|
+
internalSelected ? /*#__PURE__*/ jsx(CheckboxOnIcon, {
|
|
63
|
+
color: checkboxColor,
|
|
64
|
+
size: iconSize
|
|
65
|
+
}) : /*#__PURE__*/ jsx(CheckboxOffIcon, {
|
|
66
|
+
color: "secondary",
|
|
67
|
+
size: iconSize
|
|
68
|
+
}),
|
|
69
|
+
'string' == typeof children ? /*#__PURE__*/ jsx(Text, {
|
|
70
|
+
variant: labelVariant,
|
|
71
|
+
children: children
|
|
72
|
+
}) : children
|
|
73
|
+
]
|
|
74
|
+
})
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
UXCheckbox.displayName = 'UXCheckbox';
|
|
78
|
+
export { UXCheckbox };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UXCheckboxCommonProps } from './types';
|
|
2
|
+
type CheckboxGroupContextType = UXCheckboxCommonProps & {
|
|
3
|
+
selectedValues: string[];
|
|
4
|
+
onValueChange: (value: string, selected: boolean) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare const CheckboxGroupContext: import("react").Context<CheckboxGroupContextType | null>;
|
|
7
|
+
export declare const useCheckboxGroup: () => CheckboxGroupContextType | null;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
const CheckboxGroupContext = createContext(null);
|
|
3
|
+
const useCheckboxGroup = ()=>{
|
|
4
|
+
const context = useContext(CheckboxGroupContext);
|
|
5
|
+
if (!context) return null;
|
|
6
|
+
return context;
|
|
7
|
+
};
|
|
8
|
+
export { CheckboxGroupContext, useCheckboxGroup };
|
|
File without changes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useMemo } from "react";
|
|
3
|
+
import { HStack, Text } from "../index.js";
|
|
4
|
+
import { useStyles } from "./styles.js";
|
|
5
|
+
const UXChip = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
6
|
+
const { style, size, gap = 2, radius = 4, color, variant, isDisabled, startContent, endContent, children, ...restProps } = props;
|
|
7
|
+
const styles = useStyles({
|
|
8
|
+
size,
|
|
9
|
+
color,
|
|
10
|
+
variant,
|
|
11
|
+
isDisabled
|
|
12
|
+
});
|
|
13
|
+
const content = useMemo(async ()=>{
|
|
14
|
+
if ('string' == typeof children || 'number' == typeof children) return /*#__PURE__*/ jsx(Text, {
|
|
15
|
+
style: styles.title,
|
|
16
|
+
children: children.toString()
|
|
17
|
+
});
|
|
18
|
+
return children;
|
|
19
|
+
}, [
|
|
20
|
+
children,
|
|
21
|
+
styles.title
|
|
22
|
+
]);
|
|
23
|
+
const renderChildren = useMemo(()=>/*#__PURE__*/ jsxs(Fragment, {
|
|
24
|
+
children: [
|
|
25
|
+
startContent,
|
|
26
|
+
content,
|
|
27
|
+
endContent
|
|
28
|
+
]
|
|
29
|
+
}), [
|
|
30
|
+
content,
|
|
31
|
+
startContent,
|
|
32
|
+
endContent
|
|
33
|
+
]);
|
|
34
|
+
return /*#__PURE__*/ jsx(HStack, {
|
|
35
|
+
ref: ref,
|
|
36
|
+
gap: gap,
|
|
37
|
+
ph: 4,
|
|
38
|
+
radius: radius,
|
|
39
|
+
style: [
|
|
40
|
+
styles.button,
|
|
41
|
+
style
|
|
42
|
+
],
|
|
43
|
+
...restProps,
|
|
44
|
+
children: renderChildren
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
UXChip.displayName = 'UXChip';
|
|
48
|
+
export { UXChip };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./chip.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { UXChipProps } from './types';
|
|
2
|
+
export declare const sizeMap: {
|
|
3
|
+
readonly sm: number;
|
|
4
|
+
readonly md: number;
|
|
5
|
+
readonly lg: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const fontSizeMap: {
|
|
8
|
+
readonly sm: number;
|
|
9
|
+
readonly md: number;
|
|
10
|
+
readonly lg: number;
|
|
11
|
+
};
|
|
12
|
+
export declare const useStyles: ({ size, color, variant, isDisabled }: UXChipProps) => {
|
|
13
|
+
button: {
|
|
14
|
+
height: number;
|
|
15
|
+
backgroundColor: string | undefined;
|
|
16
|
+
opacity: number;
|
|
17
|
+
};
|
|
18
|
+
title: {
|
|
19
|
+
fontWeight: 400;
|
|
20
|
+
fontSize: number;
|
|
21
|
+
lineHeight: number;
|
|
22
|
+
color: string | undefined;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { StyleSheet } from "react-native";
|
|
3
|
+
import { ms } from "react-native-size-matters";
|
|
4
|
+
import { useColors } from "../../hooks/index.js";
|
|
5
|
+
import { disabledOpacity } from "../../theme/index.js";
|
|
6
|
+
const sizeMap = {
|
|
7
|
+
sm: ms(14),
|
|
8
|
+
md: ms(16),
|
|
9
|
+
lg: ms(18)
|
|
10
|
+
};
|
|
11
|
+
const fontSizeMap = {
|
|
12
|
+
sm: ms(11),
|
|
13
|
+
md: ms(12),
|
|
14
|
+
lg: ms(14)
|
|
15
|
+
};
|
|
16
|
+
const useStyles = ({ size = 'md', color = 'default', variant = 'flat', isDisabled })=>{
|
|
17
|
+
const { getColor } = useColors();
|
|
18
|
+
const height = useMemo(()=>sizeMap[size], [
|
|
19
|
+
size
|
|
20
|
+
]);
|
|
21
|
+
const fontSize = useMemo(()=>fontSizeMap[size], [
|
|
22
|
+
size
|
|
23
|
+
]);
|
|
24
|
+
const textColor = useMemo(()=>{
|
|
25
|
+
if ('default' === color) return getColor('default');
|
|
26
|
+
if ('secondary' === color) return getColor('secondary');
|
|
27
|
+
if ('solid' === variant) return getColor('white');
|
|
28
|
+
return getColor(color);
|
|
29
|
+
}, [
|
|
30
|
+
color,
|
|
31
|
+
getColor,
|
|
32
|
+
variant
|
|
33
|
+
]);
|
|
34
|
+
const backgroundColor = useMemo(()=>{
|
|
35
|
+
if ('solid' === variant) {
|
|
36
|
+
if ([
|
|
37
|
+
'default',
|
|
38
|
+
'secondary'
|
|
39
|
+
].includes(color)) return getColor('bg-300');
|
|
40
|
+
return getColor(color);
|
|
41
|
+
}
|
|
42
|
+
if ('flat' === variant) {
|
|
43
|
+
if ([
|
|
44
|
+
'default',
|
|
45
|
+
'secondary'
|
|
46
|
+
].includes(color)) return getColor('bg-300');
|
|
47
|
+
return `${getColor(color)}20`;
|
|
48
|
+
}
|
|
49
|
+
return 'transparent';
|
|
50
|
+
}, [
|
|
51
|
+
color,
|
|
52
|
+
getColor,
|
|
53
|
+
variant
|
|
54
|
+
]);
|
|
55
|
+
const styles = StyleSheet.create({
|
|
56
|
+
button: {
|
|
57
|
+
height,
|
|
58
|
+
backgroundColor,
|
|
59
|
+
opacity: isDisabled ? disabledOpacity : 1
|
|
60
|
+
},
|
|
61
|
+
title: {
|
|
62
|
+
fontWeight: 400,
|
|
63
|
+
fontSize,
|
|
64
|
+
lineHeight: fontSize + 2,
|
|
65
|
+
color: textColor
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return styles;
|
|
69
|
+
};
|
|
70
|
+
export { fontSizeMap, sizeMap, useStyles };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { UXForegroundColor } from '@particle-network/ui-shared';
|
|
3
|
+
import type { HStackProps } from '..';
|
|
4
|
+
export interface UXChipProps extends HStackProps {
|
|
5
|
+
color?: UXForegroundColor;
|
|
6
|
+
size?: 'sm' | 'md' | 'lg';
|
|
7
|
+
variant?: 'solid' | 'flat';
|
|
8
|
+
isDisabled?: boolean;
|
|
9
|
+
startContent?: React.ReactNode;
|
|
10
|
+
endContent?: React.ReactNode;
|
|
11
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { View } from 'react-native';
|
|
2
|
+
import { type BoxProps } from '..';
|
|
3
|
+
export interface UXDividerProps extends Omit<BoxProps, 'w' | 'h'> {
|
|
4
|
+
w?: number;
|
|
5
|
+
h?: number;
|
|
6
|
+
orientation?: 'horizontal' | 'vertical';
|
|
7
|
+
}
|
|
8
|
+
export declare const UXDivider: import("react").ForwardRefExoticComponent<UXDividerProps & import("react").RefAttributes<View>>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useMemo } from "react";
|
|
3
|
+
import { Box } from "../index.js";
|
|
4
|
+
const UXDivider = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
5
|
+
const { w, h, orientation = 'horizontal', style, ...restProps } = props;
|
|
6
|
+
const width = useMemo(()=>{
|
|
7
|
+
if (w) return w;
|
|
8
|
+
return 'vertical' === orientation ? 1 : '100%';
|
|
9
|
+
}, [
|
|
10
|
+
w,
|
|
11
|
+
orientation
|
|
12
|
+
]);
|
|
13
|
+
const height = useMemo(()=>{
|
|
14
|
+
if (h) return h;
|
|
15
|
+
return 'horizontal' === orientation ? 1 : '100%';
|
|
16
|
+
}, [
|
|
17
|
+
h,
|
|
18
|
+
orientation
|
|
19
|
+
]);
|
|
20
|
+
return /*#__PURE__*/ jsx(Box, {
|
|
21
|
+
ref: ref,
|
|
22
|
+
bg: "divider",
|
|
23
|
+
style: [
|
|
24
|
+
{
|
|
25
|
+
width,
|
|
26
|
+
height
|
|
27
|
+
},
|
|
28
|
+
style
|
|
29
|
+
],
|
|
30
|
+
...restProps
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
UXDivider.displayName = 'UXDivider';
|
|
34
|
+
export { UXDivider };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import { ms } from "react-native-size-matters";
|
|
4
|
+
import { UXTooltip } from "../index.js";
|
|
5
|
+
import QuestionIcon from "../../icons/QuestionIcon.js";
|
|
6
|
+
const UXHint = (props)=>{
|
|
7
|
+
const { content, children, iconStyle, ...restProps } = props;
|
|
8
|
+
return /*#__PURE__*/ jsx(UXTooltip, {
|
|
9
|
+
content: content || children,
|
|
10
|
+
...restProps,
|
|
11
|
+
children: /*#__PURE__*/ jsx(QuestionIcon, {
|
|
12
|
+
color: "secondary",
|
|
13
|
+
size: ms(12),
|
|
14
|
+
style: iconStyle
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
UXHint.displayName = 'UXHint';
|
|
19
|
+
export { UXHint };
|