@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
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# getting started
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npx create-expo-app --template expo-template-storybook AwesomeStorybook
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
or
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
yarn create expo-app --template expo-template-storybook AwesomeStorybook
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
# app
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
yarn start
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
# RN Storybook (ondevice)
|
|
22
|
+
|
|
23
|
+
In this template you can now run `yarn storybook` to start ondevice storybook or `yarn start` to start your expo app.
|
|
24
|
+
This works via env variables and expo constants.
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
# either
|
|
28
|
+
yarn storybook
|
|
29
|
+
|
|
30
|
+
# ios
|
|
31
|
+
yarn storybook:ios
|
|
32
|
+
|
|
33
|
+
# android
|
|
34
|
+
yarn storybook:android
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
If you add new stories on the native (ondevice version) you either need to have the watcher running or run the stories loader
|
|
38
|
+
|
|
39
|
+
To update the stories one time
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
yarn storybook-generate
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
# Web
|
|
46
|
+
|
|
47
|
+
Start react native web storybook:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
yarn storybook:web
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
build react native web storybook:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
yarn build-storybook
|
|
57
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import type { UXForegroundColor, UXRadius } from '@particle-network/ui-shared';
|
|
4
|
+
import { type FlexProps } from '..';
|
|
5
|
+
export interface ProgressWrapperProps extends Omit<FlexProps, 'radius' | 'width' | 'height' | 'w' | 'h'> {
|
|
6
|
+
/**
|
|
7
|
+
* 进度 (%)
|
|
8
|
+
*/
|
|
9
|
+
value?: number;
|
|
10
|
+
/**
|
|
11
|
+
* 宽度
|
|
12
|
+
*/
|
|
13
|
+
width?: number;
|
|
14
|
+
/**
|
|
15
|
+
* 高度
|
|
16
|
+
*/
|
|
17
|
+
height?: number;
|
|
18
|
+
/**
|
|
19
|
+
* 进度条宽度
|
|
20
|
+
*/
|
|
21
|
+
strokeWidth?: number;
|
|
22
|
+
/**
|
|
23
|
+
* 圆角
|
|
24
|
+
*/
|
|
25
|
+
radius?: UXRadius | number;
|
|
26
|
+
/**
|
|
27
|
+
* 进度条颜色
|
|
28
|
+
*/
|
|
29
|
+
color?: UXForegroundColor | 'transparent';
|
|
30
|
+
/**
|
|
31
|
+
* SVG 样式
|
|
32
|
+
*/
|
|
33
|
+
svgStyle?: StyleProp<ViewStyle>;
|
|
34
|
+
}
|
|
35
|
+
export declare const ProgressWrapper: React.FC<ProgressWrapperProps>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useState } from "react";
|
|
3
|
+
import { StyleSheet, View } from "react-native";
|
|
4
|
+
import react_native_svg, { Path } from "react-native-svg";
|
|
5
|
+
import { Flex } from "../index.js";
|
|
6
|
+
import { useColors, useRadius } from "../../hooks/index.js";
|
|
7
|
+
const ProgressWrapper = ({ style, svgStyle, value = 0, width, height, radius = 'sm', strokeWidth = 1, color = 'primary', children, ...restProps })=>{
|
|
8
|
+
const { getColor } = useColors();
|
|
9
|
+
const { getRadius } = useRadius();
|
|
10
|
+
const autoLayout = !width && !height;
|
|
11
|
+
const [childWidth, setChildWidth] = useState(0);
|
|
12
|
+
const [childHeight, setChildHeight] = useState(0);
|
|
13
|
+
const widthValue = useMemo(()=>{
|
|
14
|
+
if (width) return width;
|
|
15
|
+
return childWidth + 2 * strokeWidth;
|
|
16
|
+
}, [
|
|
17
|
+
childWidth,
|
|
18
|
+
strokeWidth,
|
|
19
|
+
width
|
|
20
|
+
]);
|
|
21
|
+
const heightValue = useMemo(()=>{
|
|
22
|
+
if (height) return height;
|
|
23
|
+
return childHeight + 2 * strokeWidth;
|
|
24
|
+
}, [
|
|
25
|
+
childHeight,
|
|
26
|
+
strokeWidth,
|
|
27
|
+
height
|
|
28
|
+
]);
|
|
29
|
+
const clampedProgress = Math.max(0, Math.min(100, value));
|
|
30
|
+
const rectWidth = widthValue - strokeWidth;
|
|
31
|
+
const rectHeight = heightValue - strokeWidth;
|
|
32
|
+
const rectXY = strokeWidth / 2;
|
|
33
|
+
const perimeter = 2 * (rectWidth + rectHeight);
|
|
34
|
+
const strokeDashoffset = perimeter * (1 - clampedProgress / 100);
|
|
35
|
+
const colorValue = 'transparent' === color ? 'transparent' : getColor(color);
|
|
36
|
+
const trackColor = 'transparent' === color ? 'transparent' : `${colorValue}40`;
|
|
37
|
+
const radiusValue = getRadius(radius);
|
|
38
|
+
const createPathData = (x, y, w, h, r)=>{
|
|
39
|
+
if (0 === r) return `
|
|
40
|
+
M ${x + w} ${y + h}
|
|
41
|
+
L ${x} ${y + h}
|
|
42
|
+
L ${x} ${y}
|
|
43
|
+
L ${x + w} ${y}
|
|
44
|
+
Z
|
|
45
|
+
`;
|
|
46
|
+
return `
|
|
47
|
+
M ${x + w - r} ${y + h}
|
|
48
|
+
L ${x + r} ${y + h}
|
|
49
|
+
Q ${x} ${y + h} ${x} ${y + h - r}
|
|
50
|
+
L ${x} ${y + r}
|
|
51
|
+
Q ${x} ${y} ${x + r} ${y}
|
|
52
|
+
L ${x + w - r} ${y}
|
|
53
|
+
Q ${x + w} ${y} ${x + w} ${y + r}
|
|
54
|
+
L ${x + w} ${y + h - r}
|
|
55
|
+
Q ${x + w} ${y + h} ${x + w - r} ${y + h}
|
|
56
|
+
Z
|
|
57
|
+
`;
|
|
58
|
+
};
|
|
59
|
+
const pathData = createPathData(rectXY, rectXY, rectWidth, rectHeight, radiusValue);
|
|
60
|
+
const styles = StyleSheet.create({
|
|
61
|
+
container: {
|
|
62
|
+
width: widthValue,
|
|
63
|
+
height: heightValue
|
|
64
|
+
},
|
|
65
|
+
svg: {
|
|
66
|
+
position: 'absolute',
|
|
67
|
+
left: 0,
|
|
68
|
+
top: 0
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
const handleLayout = (event)=>{
|
|
72
|
+
const { width, height } = event.nativeEvent.layout;
|
|
73
|
+
setChildWidth(width);
|
|
74
|
+
setChildHeight(height);
|
|
75
|
+
};
|
|
76
|
+
return /*#__PURE__*/ jsxs(Flex, {
|
|
77
|
+
center: true,
|
|
78
|
+
h: heightValue,
|
|
79
|
+
style: [
|
|
80
|
+
styles.container,
|
|
81
|
+
style
|
|
82
|
+
],
|
|
83
|
+
w: widthValue,
|
|
84
|
+
...restProps,
|
|
85
|
+
children: [
|
|
86
|
+
/*#__PURE__*/ jsxs(react_native_svg, {
|
|
87
|
+
height: heightValue,
|
|
88
|
+
style: [
|
|
89
|
+
styles.svg,
|
|
90
|
+
svgStyle
|
|
91
|
+
],
|
|
92
|
+
width: widthValue,
|
|
93
|
+
children: [
|
|
94
|
+
/*#__PURE__*/ jsx(Path, {
|
|
95
|
+
d: pathData,
|
|
96
|
+
fill: "none",
|
|
97
|
+
stroke: trackColor,
|
|
98
|
+
strokeWidth: strokeWidth
|
|
99
|
+
}),
|
|
100
|
+
/*#__PURE__*/ jsx(Path, {
|
|
101
|
+
d: pathData,
|
|
102
|
+
fill: "none",
|
|
103
|
+
stroke: colorValue,
|
|
104
|
+
strokeDasharray: perimeter,
|
|
105
|
+
strokeDashoffset: strokeDashoffset,
|
|
106
|
+
strokeLinecap: "round",
|
|
107
|
+
strokeLinejoin: "round",
|
|
108
|
+
strokeWidth: strokeWidth
|
|
109
|
+
})
|
|
110
|
+
]
|
|
111
|
+
}),
|
|
112
|
+
autoLayout ? /*#__PURE__*/ jsx(View, {
|
|
113
|
+
onLayout: handleLayout,
|
|
114
|
+
children: children
|
|
115
|
+
}) : children
|
|
116
|
+
]
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
ProgressWrapper.displayName = 'UXProgressWrapper';
|
|
120
|
+
export { ProgressWrapper };
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useMemo, useState } from "react";
|
|
3
|
+
import { StyleSheet, Text, View } from "react-native";
|
|
4
|
+
import { Box, HStack, useBoxStyle } from "../index.js";
|
|
5
|
+
import { useColors } from "../../hooks/index.js";
|
|
6
|
+
import { textStyles } from "./text.types.js";
|
|
7
|
+
const text_Text = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
8
|
+
const { variant = 'body2Bold', fontWeight, color = 'default', lineHeight, align, style, h1, h2, h3, body1, body1Bold, body2, body2Bold, body3, body3Bold, caption1, caption1Bold, underlineStyle, fullWidth, fullHeight, h, minH, maxH, w, minW, maxW, m, mt, mr, mb, ml, ms, me, mh, mv, p, pt, pr, pb, pl, ps, pe, ph, pv, borderStyle, border, borderTop, borderRight, borderBottom, borderLeft, borderStart, borderEnd, borderColor, borderTopColor, borderRightColor, borderBottomColor, borderLeftColor, borderStartColor, borderEndColor, radius, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius, topStartRadius, topEndRadius, bottomStartRadius, bottomEndRadius, position, top, right, bottom, left, start, end, bg, bgOpacity, opacity, zIndex, overflow, ...restProps } = props;
|
|
9
|
+
const [textWidth, setTextWidth] = useState(0);
|
|
10
|
+
const { getColor } = useColors();
|
|
11
|
+
const boxStyle = useBoxStyle({
|
|
12
|
+
fullWidth,
|
|
13
|
+
fullHeight,
|
|
14
|
+
h,
|
|
15
|
+
minH,
|
|
16
|
+
maxH,
|
|
17
|
+
w,
|
|
18
|
+
minW,
|
|
19
|
+
maxW,
|
|
20
|
+
m,
|
|
21
|
+
mt,
|
|
22
|
+
mr,
|
|
23
|
+
mb,
|
|
24
|
+
ml,
|
|
25
|
+
ms,
|
|
26
|
+
me,
|
|
27
|
+
mh,
|
|
28
|
+
mv,
|
|
29
|
+
p,
|
|
30
|
+
pt,
|
|
31
|
+
pr,
|
|
32
|
+
pb,
|
|
33
|
+
pl,
|
|
34
|
+
ps,
|
|
35
|
+
pe,
|
|
36
|
+
ph,
|
|
37
|
+
pv,
|
|
38
|
+
borderStyle,
|
|
39
|
+
border,
|
|
40
|
+
borderTop,
|
|
41
|
+
borderRight,
|
|
42
|
+
borderBottom,
|
|
43
|
+
borderLeft,
|
|
44
|
+
borderStart,
|
|
45
|
+
borderEnd,
|
|
46
|
+
borderColor,
|
|
47
|
+
borderTopColor,
|
|
48
|
+
borderRightColor,
|
|
49
|
+
borderBottomColor,
|
|
50
|
+
borderLeftColor,
|
|
51
|
+
borderStartColor,
|
|
52
|
+
borderEndColor,
|
|
53
|
+
radius,
|
|
54
|
+
topLeftRadius,
|
|
55
|
+
topRightRadius,
|
|
56
|
+
bottomLeftRadius,
|
|
57
|
+
bottomRightRadius,
|
|
58
|
+
topStartRadius,
|
|
59
|
+
topEndRadius,
|
|
60
|
+
bottomStartRadius,
|
|
61
|
+
bottomEndRadius,
|
|
62
|
+
position,
|
|
63
|
+
top,
|
|
64
|
+
right,
|
|
65
|
+
bottom,
|
|
66
|
+
left,
|
|
67
|
+
start,
|
|
68
|
+
end,
|
|
69
|
+
bg,
|
|
70
|
+
bgOpacity,
|
|
71
|
+
opacity,
|
|
72
|
+
zIndex,
|
|
73
|
+
overflow
|
|
74
|
+
});
|
|
75
|
+
const variantStyle = useMemo(()=>{
|
|
76
|
+
if (h1) return textStyles.variant.h1;
|
|
77
|
+
if (h2) return textStyles.variant.h2;
|
|
78
|
+
if (h3) return textStyles.variant.h3;
|
|
79
|
+
if (body1) return textStyles.variant.body1;
|
|
80
|
+
if (body1Bold) return textStyles.variant.body1Bold;
|
|
81
|
+
if (body2) return textStyles.variant.body2;
|
|
82
|
+
if (body2Bold) return textStyles.variant.body2Bold;
|
|
83
|
+
if (body3) return textStyles.variant.body3;
|
|
84
|
+
if (body3Bold) return textStyles.variant.body3Bold;
|
|
85
|
+
if (caption1) return textStyles.variant.caption1;
|
|
86
|
+
if (caption1Bold) return textStyles.variant.caption1Bold;
|
|
87
|
+
return textStyles.variant[variant];
|
|
88
|
+
}, [
|
|
89
|
+
h1,
|
|
90
|
+
h2,
|
|
91
|
+
h3,
|
|
92
|
+
body1,
|
|
93
|
+
body1Bold,
|
|
94
|
+
body2,
|
|
95
|
+
body2Bold,
|
|
96
|
+
body3,
|
|
97
|
+
body3Bold,
|
|
98
|
+
caption1,
|
|
99
|
+
caption1Bold,
|
|
100
|
+
variant
|
|
101
|
+
]);
|
|
102
|
+
const textStyle = useMemo(()=>({
|
|
103
|
+
...variantStyle,
|
|
104
|
+
...fontWeight && {
|
|
105
|
+
fontWeight: textStyles.fontWeight[fontWeight]
|
|
106
|
+
},
|
|
107
|
+
...lineHeight && {
|
|
108
|
+
lineHeight: textStyles.lineHeight[lineHeight] * variantStyle.fontSize
|
|
109
|
+
},
|
|
110
|
+
textAlign: textStyles.align[align],
|
|
111
|
+
color: getColor(color)
|
|
112
|
+
}), [
|
|
113
|
+
variantStyle,
|
|
114
|
+
fontWeight,
|
|
115
|
+
lineHeight,
|
|
116
|
+
align,
|
|
117
|
+
color,
|
|
118
|
+
getColor
|
|
119
|
+
]);
|
|
120
|
+
if ([
|
|
121
|
+
'dotted',
|
|
122
|
+
'dashed'
|
|
123
|
+
].includes(underlineStyle ?? '')) {
|
|
124
|
+
const dotCount = Math.max(1, Math.floor(textWidth / 3));
|
|
125
|
+
const dashCount = Math.max(1, Math.floor(textWidth / 6));
|
|
126
|
+
const dotStyle = StyleSheet.create({
|
|
127
|
+
position: {
|
|
128
|
+
position: 'absolute',
|
|
129
|
+
bottom: 0,
|
|
130
|
+
left: 0,
|
|
131
|
+
right: 0,
|
|
132
|
+
height: 1,
|
|
133
|
+
paddingHorizontal: 1,
|
|
134
|
+
width: textWidth
|
|
135
|
+
},
|
|
136
|
+
dot: {
|
|
137
|
+
width: 1,
|
|
138
|
+
height: 1,
|
|
139
|
+
backgroundColor: getColor(color),
|
|
140
|
+
borderRadius: 0.5
|
|
141
|
+
},
|
|
142
|
+
dash: {
|
|
143
|
+
width: 3,
|
|
144
|
+
height: 1,
|
|
145
|
+
backgroundColor: getColor(color)
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return /*#__PURE__*/ jsxs(Box, {
|
|
149
|
+
position: "relative",
|
|
150
|
+
children: [
|
|
151
|
+
/*#__PURE__*/ jsx(Text, {
|
|
152
|
+
style: [
|
|
153
|
+
boxStyle,
|
|
154
|
+
textStyle,
|
|
155
|
+
style
|
|
156
|
+
],
|
|
157
|
+
onLayout: (e)=>{
|
|
158
|
+
setTextWidth(e.nativeEvent.layout.width);
|
|
159
|
+
},
|
|
160
|
+
...restProps
|
|
161
|
+
}),
|
|
162
|
+
/*#__PURE__*/ jsxs(HStack, {
|
|
163
|
+
justify: "between",
|
|
164
|
+
style: dotStyle.position,
|
|
165
|
+
children: [
|
|
166
|
+
'dotted' === underlineStyle && Array.from({
|
|
167
|
+
length: dotCount
|
|
168
|
+
}).map((_, index)=>/*#__PURE__*/ jsx(View, {
|
|
169
|
+
style: dotStyle.dot
|
|
170
|
+
}, index)),
|
|
171
|
+
'dashed' === underlineStyle && Array.from({
|
|
172
|
+
length: dashCount
|
|
173
|
+
}).map((_, index)=>/*#__PURE__*/ jsx(View, {
|
|
174
|
+
style: dotStyle.dash
|
|
175
|
+
}, index))
|
|
176
|
+
]
|
|
177
|
+
})
|
|
178
|
+
]
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return /*#__PURE__*/ jsx(Text, {
|
|
182
|
+
ref: ref,
|
|
183
|
+
style: [
|
|
184
|
+
boxStyle,
|
|
185
|
+
textStyle,
|
|
186
|
+
underlineStyle && {
|
|
187
|
+
textDecorationLine: 'underline',
|
|
188
|
+
textDecorationStyle: underlineStyle
|
|
189
|
+
},
|
|
190
|
+
style
|
|
191
|
+
],
|
|
192
|
+
...restProps
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
text_Text.displayName = 'UXText';
|
|
196
|
+
export { text_Text as Text };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { TextProps as RNTextProps, TextStyle } from 'react-native';
|
|
2
|
+
import type { UXForegroundColor } from '@particle-network/ui-shared';
|
|
3
|
+
import type { UseBoxProps } from '..';
|
|
4
|
+
type TextVariant = 'h1' | 'h2' | 'h3' | 'body1' | 'body1Bold' | 'body2' | 'body2Bold' | 'body3' | 'body3Bold' | 'caption1' | 'caption1Bold';
|
|
5
|
+
type TextWeight = 'normal' | 'medium' | 'semibold' | 'bold' | 'extrabold';
|
|
6
|
+
type TextLineHeight = '1' | '1.4';
|
|
7
|
+
type TextAlign = 'left' | 'center' | 'right';
|
|
8
|
+
export interface TextProps extends RNTextProps, UseBoxProps {
|
|
9
|
+
/**
|
|
10
|
+
* | variant | font-size | font-weight |
|
|
11
|
+
* | :----------- | :-------- | :---------- |
|
|
12
|
+
* | h1 | 24px | 600 |
|
|
13
|
+
* | h2 | 20px | 600 |
|
|
14
|
+
* | h3 | 16px | 600 |
|
|
15
|
+
* | body1 | 14px | 400 |
|
|
16
|
+
* | body1Bold | 14px | 500 |
|
|
17
|
+
* | body2 | 12px | 400 |
|
|
18
|
+
* | body2Bold | 12px | 500 |
|
|
19
|
+
* | body3 | 10px | 400 |
|
|
20
|
+
* | body3Bold | 10px | 500 |
|
|
21
|
+
* | caption1 | 8px | 400 |
|
|
22
|
+
* | caption1Bold | 8px | 500 |
|
|
23
|
+
*/
|
|
24
|
+
variant?: TextVariant;
|
|
25
|
+
/**
|
|
26
|
+
* `24px 600`
|
|
27
|
+
*/
|
|
28
|
+
h1?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* `20px 600`
|
|
31
|
+
*/
|
|
32
|
+
h2?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* `16px 600`
|
|
35
|
+
*/
|
|
36
|
+
h3?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* `14px 400`
|
|
39
|
+
*/
|
|
40
|
+
body1?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* `14px 500`
|
|
43
|
+
*/
|
|
44
|
+
body1Bold?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* `12px 400`
|
|
47
|
+
*/
|
|
48
|
+
body2?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* `12px 500`
|
|
51
|
+
*/
|
|
52
|
+
body2Bold?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* `11px 400`
|
|
55
|
+
*/
|
|
56
|
+
body3?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* `11px 500`
|
|
59
|
+
*/
|
|
60
|
+
body3Bold?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* `10px 400`
|
|
63
|
+
*/
|
|
64
|
+
caption1?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* `10px 500`
|
|
67
|
+
*/
|
|
68
|
+
caption1Bold?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* | weight | font-weight |
|
|
71
|
+
* | :-------- | :---------: |
|
|
72
|
+
* | normal | 400 |
|
|
73
|
+
* | medium | 500 |
|
|
74
|
+
* | semibold | 600 |
|
|
75
|
+
* | bold | 700 |
|
|
76
|
+
* | extrabold | 800 |
|
|
77
|
+
*/
|
|
78
|
+
fontWeight?: TextWeight;
|
|
79
|
+
/**
|
|
80
|
+
* | color | dark | light |
|
|
81
|
+
* | :--------- | :-------- | :-------- |
|
|
82
|
+
* | default | #FFFFFF | #000000 |
|
|
83
|
+
* | foreground | #FFFFFF | #000000 |
|
|
84
|
+
* | white | #FFFFFF | #FFFFFF |
|
|
85
|
+
* | secondary | #A1A1AA | #767A80 |
|
|
86
|
+
* | tertiary | #4E4E56 | #C0C0C9 |
|
|
87
|
+
* | primary | #D745FF | #000000 |
|
|
88
|
+
* | success | #45B167 | #2E9F4A |
|
|
89
|
+
* | danger | #E84A5A | #DE4A40 |
|
|
90
|
+
* | alert | #F57733 | #E65E16 |
|
|
91
|
+
* | warning | #FF9821 | #FF9821 |
|
|
92
|
+
* | gold | #FFB800 | #F38300 |
|
|
93
|
+
*/
|
|
94
|
+
color?: UXForegroundColor;
|
|
95
|
+
lineHeight?: TextLineHeight;
|
|
96
|
+
align?: TextAlign;
|
|
97
|
+
underlineStyle?: TextStyle['textDecorationStyle'];
|
|
98
|
+
}
|
|
99
|
+
export declare const textStyles: {
|
|
100
|
+
variant: Record<TextVariant, {
|
|
101
|
+
fontSize: number;
|
|
102
|
+
lineHeight: number;
|
|
103
|
+
fontWeight: TextStyle['fontWeight'];
|
|
104
|
+
}>;
|
|
105
|
+
fontWeight: Record<TextWeight, TextStyle['fontWeight']>;
|
|
106
|
+
lineHeight: Record<TextLineHeight, number>;
|
|
107
|
+
align: Record<TextAlign, TextStyle['textAlign']>;
|
|
108
|
+
};
|
|
109
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ms } from "react-native-size-matters";
|
|
2
|
+
const textStyles = {
|
|
3
|
+
variant: {
|
|
4
|
+
h1: {
|
|
5
|
+
fontSize: ms(24),
|
|
6
|
+
lineHeight: ms(28),
|
|
7
|
+
fontWeight: '600'
|
|
8
|
+
},
|
|
9
|
+
h2: {
|
|
10
|
+
fontSize: ms(20),
|
|
11
|
+
lineHeight: ms(24),
|
|
12
|
+
fontWeight: '600'
|
|
13
|
+
},
|
|
14
|
+
h3: {
|
|
15
|
+
fontSize: ms(16),
|
|
16
|
+
lineHeight: ms(20),
|
|
17
|
+
fontWeight: '600'
|
|
18
|
+
},
|
|
19
|
+
body1Bold: {
|
|
20
|
+
fontSize: ms(14),
|
|
21
|
+
lineHeight: ms(18),
|
|
22
|
+
fontWeight: '500'
|
|
23
|
+
},
|
|
24
|
+
body1: {
|
|
25
|
+
fontSize: ms(14),
|
|
26
|
+
lineHeight: ms(18),
|
|
27
|
+
fontWeight: '400'
|
|
28
|
+
},
|
|
29
|
+
body2Bold: {
|
|
30
|
+
fontSize: ms(12),
|
|
31
|
+
lineHeight: ms(16),
|
|
32
|
+
fontWeight: '500'
|
|
33
|
+
},
|
|
34
|
+
body2: {
|
|
35
|
+
fontSize: ms(12),
|
|
36
|
+
lineHeight: ms(16),
|
|
37
|
+
fontWeight: '400'
|
|
38
|
+
},
|
|
39
|
+
body3Bold: {
|
|
40
|
+
fontSize: ms(11),
|
|
41
|
+
lineHeight: ms(16),
|
|
42
|
+
fontWeight: '500'
|
|
43
|
+
},
|
|
44
|
+
body3: {
|
|
45
|
+
fontSize: ms(11),
|
|
46
|
+
lineHeight: ms(16),
|
|
47
|
+
fontWeight: '400'
|
|
48
|
+
},
|
|
49
|
+
caption1Bold: {
|
|
50
|
+
fontSize: ms(10),
|
|
51
|
+
lineHeight: ms(14),
|
|
52
|
+
fontWeight: '500'
|
|
53
|
+
},
|
|
54
|
+
caption1: {
|
|
55
|
+
fontSize: ms(10),
|
|
56
|
+
lineHeight: ms(14),
|
|
57
|
+
fontWeight: '400'
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
fontWeight: {
|
|
61
|
+
normal: '400',
|
|
62
|
+
medium: '500',
|
|
63
|
+
semibold: '600',
|
|
64
|
+
bold: '700',
|
|
65
|
+
extrabold: '800'
|
|
66
|
+
},
|
|
67
|
+
lineHeight: {
|
|
68
|
+
1: 1,
|
|
69
|
+
'1.4': 1.4
|
|
70
|
+
},
|
|
71
|
+
align: {
|
|
72
|
+
left: 'left',
|
|
73
|
+
center: 'center',
|
|
74
|
+
right: 'right'
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
export { textStyles };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useMemo } from "react";
|
|
3
|
+
import { ActivityIndicator, Keyboard } from "react-native";
|
|
4
|
+
import { Text, UXPressable } from "../index.js";
|
|
5
|
+
import { triggerHapticFeedback } from "../../utils/triggerHapticFeedback.js";
|
|
6
|
+
import { useStyles } from "./button.styles.js";
|
|
7
|
+
const UXButton = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
8
|
+
const { style, size, radius, color, variant, onPress, isDisabled, isLoading, startContent, endContent, fullWidth, fill, width, isIconOnly, children, ...restProps } = props;
|
|
9
|
+
const handlePress = (e)=>{
|
|
10
|
+
Keyboard.dismiss();
|
|
11
|
+
triggerHapticFeedback();
|
|
12
|
+
onPress?.(e);
|
|
13
|
+
};
|
|
14
|
+
const { styles, textColor } = useStyles({
|
|
15
|
+
size,
|
|
16
|
+
radius,
|
|
17
|
+
color,
|
|
18
|
+
variant,
|
|
19
|
+
isDisabled,
|
|
20
|
+
isLoading,
|
|
21
|
+
fullWidth,
|
|
22
|
+
isIconOnly,
|
|
23
|
+
width,
|
|
24
|
+
fill
|
|
25
|
+
});
|
|
26
|
+
const content = useMemo(async ()=>{
|
|
27
|
+
if ('string' == typeof children || 'number' == typeof children) return /*#__PURE__*/ jsx(Text, {
|
|
28
|
+
style: styles.title,
|
|
29
|
+
children: children.toString()
|
|
30
|
+
});
|
|
31
|
+
return children;
|
|
32
|
+
}, [
|
|
33
|
+
children,
|
|
34
|
+
styles.title
|
|
35
|
+
]);
|
|
36
|
+
const renderChildren = useMemo(()=>{
|
|
37
|
+
if (isLoading && isIconOnly) return /*#__PURE__*/ jsx(ActivityIndicator, {
|
|
38
|
+
color: textColor,
|
|
39
|
+
size: "small"
|
|
40
|
+
});
|
|
41
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
42
|
+
children: [
|
|
43
|
+
isLoading ? /*#__PURE__*/ jsx(ActivityIndicator, {
|
|
44
|
+
color: textColor,
|
|
45
|
+
size: "small"
|
|
46
|
+
}) : null,
|
|
47
|
+
startContent,
|
|
48
|
+
content,
|
|
49
|
+
endContent
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
}, [
|
|
53
|
+
isLoading,
|
|
54
|
+
content,
|
|
55
|
+
textColor,
|
|
56
|
+
startContent,
|
|
57
|
+
endContent,
|
|
58
|
+
isIconOnly
|
|
59
|
+
]);
|
|
60
|
+
return /*#__PURE__*/ jsx(UXPressable, {
|
|
61
|
+
ref: ref,
|
|
62
|
+
disabled: isDisabled || isLoading,
|
|
63
|
+
style: ({ pressed })=>[
|
|
64
|
+
styles.button,
|
|
65
|
+
pressed && styles.buttonPressed,
|
|
66
|
+
style
|
|
67
|
+
],
|
|
68
|
+
onPress: handlePress,
|
|
69
|
+
...restProps,
|
|
70
|
+
children: renderChildren
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
UXButton.displayName = 'UXButton';
|
|
74
|
+
export { UXButton };
|