@particle-network/ui-native 0.1.4-beta.0 → 0.1.4-beta.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/dist/components/UXButton/button.types.d.ts +2 -2
- package/dist/components/UXCheckbox/checkbox.js +29 -14
- package/dist/components/UXCheckbox/icons.d.ts +14 -0
- package/dist/{icons/CheckboxOnIcon.js → components/UXCheckbox/icons.js} +23 -8
- package/dist/components/UXCheckbox/types.d.ts +2 -2
- package/dist/components/UXHint/index.js +3 -2
- package/dist/components/UXListBox/UXListBoxItem.js +3 -2
- package/dist/components/UXRadio/radio.js +5 -4
- package/dist/components/UXTabs/tab.js +3 -2
- package/dist/components/UXTabs/types.d.ts +1 -1
- package/dist/components/UXToast/ToastView.js +3 -2
- package/dist/components/date-picker/date-button.d.ts +8 -0
- package/dist/components/date-picker/date-button.js +21 -0
- package/dist/components/date-picker/date-picker.d.ts +3 -0
- package/dist/components/date-picker/date-picker.js +117 -0
- package/dist/components/date-picker/date-range-picker.d.ts +3 -0
- package/dist/components/date-picker/date-range-picker.js +195 -0
- package/dist/components/date-picker/date-wheel-picker.d.ts +3 -0
- package/dist/components/date-picker/date-wheel-picker.js +121 -0
- package/dist/components/date-picker/index.d.ts +3 -0
- package/dist/components/date-picker/index.js +2 -0
- package/dist/components/date-picker/time-wheel-picker.d.ts +7 -0
- package/dist/components/date-picker/time-wheel-picker.js +64 -0
- package/dist/components/date-picker/types.d.ts +93 -0
- package/dist/components/date-picker/types.js +0 -0
- package/dist/components/date-picker/utils.d.ts +6 -0
- package/dist/components/date-picker/utils.js +2 -0
- package/dist/components/date-picker/wheel-column.d.ts +12 -0
- package/dist/components/date-picker/wheel-column.js +152 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/input/input.js +3 -2
- package/dist/components/input/number-input.js +3 -2
- package/dist/config/config.street.d.ts +2 -0
- package/dist/config/{config.ux.js → config.street.js} +2 -2
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +2 -2
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/useI18n.d.ts +5 -0
- package/dist/hooks/useI18n.js +7 -0
- package/dist/hooks/useLocale.d.ts +8 -0
- package/dist/hooks/useLocale.js +9 -0
- package/dist/icons/{DotIcon.d.ts → index.d.ts} +1 -2
- package/dist/icons/index.js +121 -0
- package/dist/icons/types.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/locales/en.d.ts +35 -0
- package/dist/locales/en.js +35 -0
- package/dist/locales/index.d.ts +107 -0
- package/dist/locales/index.js +12 -0
- package/dist/locales/zh.d.ts +2 -0
- package/dist/locales/zh.js +35 -0
- package/dist/provider/ThemeContext.js +2 -0
- package/dist/provider/ThemeProvider.d.ts +4 -2
- package/dist/provider/ThemeProvider.js +9 -3
- package/dist/types/theme.d.ts +4 -0
- package/package.json +6 -4
- package/dist/config/config.ux.d.ts +0 -2
- package/dist/icons/CheckIcon.d.ts +0 -4
- package/dist/icons/CheckIcon.js +0 -20
- package/dist/icons/CheckboxOffIcon.d.ts +0 -4
- package/dist/icons/CheckboxOffIcon.js +0 -21
- package/dist/icons/CheckboxOnIcon.d.ts +0 -4
- package/dist/icons/CloseIcon.d.ts +0 -4
- package/dist/icons/CloseIcon.js +0 -21
- package/dist/icons/DotIcon.js +0 -23
- package/dist/icons/QuestionIcon.d.ts +0 -4
- package/dist/icons/QuestionIcon.js +0 -21
- package/dist/icons/RadioOffIcon.d.ts +0 -4
- package/dist/icons/RadioOffIcon.js +0 -22
- package/dist/icons/RadioOnIcon.d.ts +0 -4
- package/dist/icons/RadioOnIcon.js +0 -42
|
@@ -8,7 +8,7 @@ export interface UXButtonProps extends Omit<UXPressableProps, 'style' | 'disable
|
|
|
8
8
|
/**
|
|
9
9
|
* 按钮尺寸
|
|
10
10
|
* @default 'md'
|
|
11
|
-
* | size | ux
|
|
11
|
+
* | size | ux | street |
|
|
12
12
|
* | :----- | :----- | :----- |
|
|
13
13
|
* | xs | 20 | 36 |
|
|
14
14
|
* | sm | 24 | 40 |
|
|
@@ -16,7 +16,7 @@ export interface UXButtonProps extends Omit<UXPressableProps, 'style' | 'disable
|
|
|
16
16
|
* | lg | 44 | 48 |
|
|
17
17
|
*
|
|
18
18
|
* fontSize
|
|
19
|
-
* | size | ux
|
|
19
|
+
* | size | ux | street |
|
|
20
20
|
* | :----- | :----- | :----- |
|
|
21
21
|
* | xs | 11 | 12 |
|
|
22
22
|
* | sm | 10 | 14 |
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useMemo, useState } from "react";
|
|
3
3
|
import { useMs } from "../../hooks/index.js";
|
|
4
|
-
import CheckboxOffIcon from "../../icons/CheckboxOffIcon.js";
|
|
5
|
-
import CheckboxOnIcon from "../../icons/CheckboxOnIcon.js";
|
|
6
4
|
import { disabledOpacity } from "../../theme/index.js";
|
|
7
5
|
import { Flex } from "../layout/Flex/index.js";
|
|
8
6
|
import { Text } from "../Text/index.js";
|
|
9
7
|
import { UXPressable } from "../UXPressable/index.js";
|
|
10
8
|
import { useCheckboxGroup } from "./context.js";
|
|
11
|
-
|
|
9
|
+
import { CheckboxOffIcon, CheckboxOnIcon } from "./icons.js";
|
|
10
|
+
const UXCheckbox = ({ size, color, defaultSelected = false, isSelected, children, value, onValueChange, isDisabled, labelPlacement = 'right', ...props })=>{
|
|
12
11
|
const { ms } = useMs();
|
|
13
12
|
const [internalSelected, setInternalSelected] = useState(defaultSelected ?? isSelected);
|
|
14
13
|
const groupContext = useCheckboxGroup();
|
|
@@ -22,6 +21,19 @@ const UXCheckbox = ({ size, color, defaultSelected = false, isSelected, children
|
|
|
22
21
|
defaultSelected
|
|
23
22
|
]);
|
|
24
23
|
const checkboxColor = color || groupContext?.color || 'primary';
|
|
24
|
+
const displayLabelPlacement = labelPlacement || groupContext?.labelPlacement || 'right';
|
|
25
|
+
const bgColor = useMemo(()=>{
|
|
26
|
+
if ('secondary' === checkboxColor) return 'tertiary';
|
|
27
|
+
return checkboxColor;
|
|
28
|
+
}, [
|
|
29
|
+
checkboxColor
|
|
30
|
+
]);
|
|
31
|
+
const foregroundColor = useMemo(()=>{
|
|
32
|
+
if ('secondary' === checkboxColor) return 'foreground';
|
|
33
|
+
return 'white';
|
|
34
|
+
}, [
|
|
35
|
+
checkboxColor
|
|
36
|
+
]);
|
|
25
37
|
const checkboxIsDisabled = isDisabled || groupContext?.isDisabled;
|
|
26
38
|
const checkboxSize = size || groupContext?.size || 'md';
|
|
27
39
|
const handleSelectChange = ()=>{
|
|
@@ -33,23 +45,24 @@ const UXCheckbox = ({ size, color, defaultSelected = false, isSelected, children
|
|
|
33
45
|
};
|
|
34
46
|
const iconSize = useMemo(()=>{
|
|
35
47
|
if ('sm' === checkboxSize) return ms(14);
|
|
36
|
-
if ('lg' === checkboxSize) return ms(
|
|
48
|
+
if ('lg' === checkboxSize) return ms(18);
|
|
37
49
|
return ms(16);
|
|
38
50
|
}, [
|
|
39
|
-
checkboxSize
|
|
51
|
+
checkboxSize,
|
|
52
|
+
ms
|
|
40
53
|
]);
|
|
41
54
|
const labelVariant = useMemo(()=>{
|
|
42
|
-
if ('sm' === checkboxSize) return '
|
|
43
|
-
if ('lg' === checkboxSize) return '
|
|
44
|
-
return '
|
|
55
|
+
if ('sm' === checkboxSize) return 'body3';
|
|
56
|
+
if ('lg' === checkboxSize) return 'body1';
|
|
57
|
+
return 'body2';
|
|
45
58
|
}, [
|
|
46
59
|
checkboxSize
|
|
47
60
|
]);
|
|
48
|
-
const
|
|
49
|
-
if ('
|
|
50
|
-
return
|
|
61
|
+
const flexDirection = useMemo(()=>{
|
|
62
|
+
if ('left' === displayLabelPlacement) return 'row-reverse';
|
|
63
|
+
return 'row';
|
|
51
64
|
}, [
|
|
52
|
-
|
|
65
|
+
displayLabelPlacement
|
|
53
66
|
]);
|
|
54
67
|
return /*#__PURE__*/ jsx(UXPressable, {
|
|
55
68
|
disabled: checkboxIsDisabled,
|
|
@@ -58,12 +71,14 @@ const UXCheckbox = ({ size, color, defaultSelected = false, isSelected, children
|
|
|
58
71
|
},
|
|
59
72
|
onPress: handleSelectChange,
|
|
60
73
|
children: /*#__PURE__*/ jsxs(Flex, {
|
|
61
|
-
|
|
74
|
+
direction: flexDirection,
|
|
75
|
+
gap: 8,
|
|
62
76
|
items: "center",
|
|
63
77
|
...props,
|
|
64
78
|
children: [
|
|
65
79
|
internalSelected ? /*#__PURE__*/ jsx(CheckboxOnIcon, {
|
|
66
|
-
|
|
80
|
+
color1: bgColor,
|
|
81
|
+
color2: foregroundColor,
|
|
67
82
|
size: iconSize
|
|
68
83
|
}) : /*#__PURE__*/ jsx(CheckboxOffIcon, {
|
|
69
84
|
color: "secondary",
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { UXColor } from '@particle-network/ui-shared';
|
|
3
|
+
interface CheckboxOnIconProps {
|
|
4
|
+
size?: number;
|
|
5
|
+
color1?: UXColor;
|
|
6
|
+
color2?: UXColor;
|
|
7
|
+
}
|
|
8
|
+
interface CheckboxOffIconProps {
|
|
9
|
+
size?: number;
|
|
10
|
+
color?: UXColor;
|
|
11
|
+
}
|
|
12
|
+
export declare const CheckboxOnIcon: ({ size, color1, color2 }: CheckboxOnIconProps) => React.JSX.Element;
|
|
13
|
+
export declare const CheckboxOffIcon: ({ size, color }: CheckboxOffIconProps) => React.JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -1,26 +1,41 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
3
|
import react_native_svg, { Path } from "react-native-svg";
|
|
4
|
-
import { useColors } from "
|
|
5
|
-
const
|
|
4
|
+
import { useColors } from "../../hooks/index.js";
|
|
5
|
+
const CheckboxOnIcon = ({ size = 16, color1 = 'default', color2 = 'white' })=>{
|
|
6
6
|
const { getColor } = useColors();
|
|
7
|
+
const color1Value = getColor(color1);
|
|
8
|
+
const color2Value = getColor(color2);
|
|
7
9
|
return /*#__PURE__*/ jsxs(react_native_svg, {
|
|
8
10
|
fill: "none",
|
|
9
|
-
height: size,
|
|
10
11
|
viewBox: "0 0 16 16",
|
|
11
12
|
width: size,
|
|
12
|
-
|
|
13
|
+
height: size,
|
|
13
14
|
children: [
|
|
14
15
|
/*#__PURE__*/ jsx(Path, {
|
|
15
16
|
d: "M2.46154 16H13.5385C14.8979 16 16 14.8979 16 13.5385V2.46154C16 1.10207 14.8979 0 13.5385 0H2.46154C1.10207 0 0 1.10207 0 2.46154V13.5385C0 14.8979 1.10207 16 2.46154 16Z",
|
|
16
|
-
fill:
|
|
17
|
+
fill: color1Value
|
|
17
18
|
}),
|
|
18
19
|
/*#__PURE__*/ jsx(Path, {
|
|
19
20
|
d: "M6.75547 9.24601L4.84436 7.3349C4.68139 7.17193 4.47399 7.09045 4.22214 7.09045C3.97028 7.09045 3.76288 7.17193 3.59991 7.3349C3.43695 7.49786 3.35547 7.70527 3.35547 7.95712C3.35547 8.20897 3.43695 8.41638 3.59991 8.57934L6.13325 11.1127C6.31102 11.2905 6.51843 11.3793 6.75547 11.3793C6.99251 11.3793 7.19991 11.2905 7.37769 11.1127L12.3999 6.09045C12.5629 5.92749 12.6444 5.72008 12.6444 5.46823C12.6444 5.21638 12.5629 5.00897 12.3999 4.84601C12.237 4.68304 12.0295 4.60156 11.7777 4.60156C11.5258 4.60156 11.3184 4.68304 11.1555 4.84601L6.75547 9.24601Z",
|
|
20
|
-
fill:
|
|
21
|
+
fill: color2Value
|
|
21
22
|
})
|
|
22
23
|
]
|
|
23
24
|
});
|
|
24
25
|
};
|
|
25
|
-
const
|
|
26
|
-
|
|
26
|
+
const CheckboxOffIcon = ({ size = 16, color = 'default' })=>{
|
|
27
|
+
const { getColor } = useColors();
|
|
28
|
+
const colorValue = getColor(color);
|
|
29
|
+
return /*#__PURE__*/ jsx(react_native_svg, {
|
|
30
|
+
fill: "none",
|
|
31
|
+
viewBox: "0 0 16 16",
|
|
32
|
+
width: size,
|
|
33
|
+
height: size,
|
|
34
|
+
children: /*#__PURE__*/ jsx(Path, {
|
|
35
|
+
d: "M2.46191 0.615234H13.5381C14.5577 0.615234 15.3848 1.44231 15.3848 2.46191V13.5381C15.3848 14.5577 14.5577 15.3848 13.5381 15.3848H2.46191C1.44231 15.3848 0.615234 14.5577 0.615234 13.5381V2.46191C0.615234 1.44231 1.44231 0.615234 2.46191 0.615234Z",
|
|
36
|
+
stroke: colorValue,
|
|
37
|
+
strokeWidth: 1.23077
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
export { CheckboxOffIcon, CheckboxOnIcon };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { UXForegroundColor } from '@particle-network/ui-shared';
|
|
2
1
|
export interface UXCheckboxCommonProps {
|
|
3
|
-
color?:
|
|
2
|
+
color?: 'secondary' | 'primary' | 'success' | 'danger' | 'alert' | 'warning' | 'gold' | 'bullish' | 'bearish';
|
|
4
3
|
size?: 'sm' | 'md' | 'lg';
|
|
5
4
|
isDisabled?: boolean;
|
|
5
|
+
labelPlacement?: 'left' | 'right';
|
|
6
6
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
3
|
import { useMs } from "../../hooks/index.js";
|
|
4
|
-
import
|
|
4
|
+
import { Icon } from "../../icons/index.js";
|
|
5
5
|
import { Square } from "../layout/Square.js";
|
|
6
6
|
import { UXTooltip } from "../UXTooltip/index.js";
|
|
7
7
|
const UXHint = (props)=>{
|
|
@@ -14,7 +14,8 @@ const UXHint = (props)=>{
|
|
|
14
14
|
center: true,
|
|
15
15
|
size: 20,
|
|
16
16
|
style: style,
|
|
17
|
-
children: /*#__PURE__*/ jsx(
|
|
17
|
+
children: /*#__PURE__*/ jsx(Icon, {
|
|
18
|
+
name: "question",
|
|
18
19
|
color: "secondary",
|
|
19
20
|
size: ms(14),
|
|
20
21
|
style: iconStyle
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { useMs } from "../../hooks/index.js";
|
|
4
|
-
import
|
|
4
|
+
import { Icon } from "../../icons/index.js";
|
|
5
5
|
import { HStack } from "../layout/HStack.js";
|
|
6
6
|
import { Text } from "../Text/index.js";
|
|
7
7
|
import { UXTouchableOpacity } from "../UXTouchableOpacity/index.js";
|
|
@@ -47,7 +47,8 @@ const UXListBoxItem = ({ value = '', startContent, isDisabled = false, onPress,
|
|
|
47
47
|
})
|
|
48
48
|
]
|
|
49
49
|
}),
|
|
50
|
-
selectionMode && isSelected ? /*#__PURE__*/ jsx(
|
|
50
|
+
selectionMode && isSelected ? /*#__PURE__*/ jsx(Icon, {
|
|
51
|
+
name: "check",
|
|
51
52
|
size: ms(16),
|
|
52
53
|
color: "foreground"
|
|
53
54
|
}) : null
|
|
@@ -2,8 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { Pressable } from "react-native";
|
|
4
4
|
import { useMs } from "../../hooks/index.js";
|
|
5
|
-
import
|
|
6
|
-
import RadioOnIcon from "../../icons/RadioOnIcon.js";
|
|
5
|
+
import { Icon } from "../../icons/index.js";
|
|
7
6
|
import { disabledOpacity } from "../../theme/index.js";
|
|
8
7
|
import { Flex } from "../layout/Flex/index.js";
|
|
9
8
|
import { Text } from "../Text/index.js";
|
|
@@ -50,10 +49,12 @@ const UXRadio = ({ size, color, children, value, isDisabled, ...props })=>{
|
|
|
50
49
|
items: "center",
|
|
51
50
|
...props,
|
|
52
51
|
children: [
|
|
53
|
-
isSelected ? /*#__PURE__*/ jsx(
|
|
52
|
+
isSelected ? /*#__PURE__*/ jsx(Icon, {
|
|
53
|
+
name: "radioOn",
|
|
54
54
|
color: radioColor,
|
|
55
55
|
size: iconSize
|
|
56
|
-
}) : /*#__PURE__*/ jsx(
|
|
56
|
+
}) : /*#__PURE__*/ jsx(Icon, {
|
|
57
|
+
name: "radioOff",
|
|
57
58
|
color: "secondary",
|
|
58
59
|
size: iconSize
|
|
59
60
|
}),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback } from "react";
|
|
3
|
-
import
|
|
3
|
+
import { Icon } from "../../icons/index.js";
|
|
4
4
|
import { Box } from "../layout/Box/index.js";
|
|
5
5
|
import { HStack } from "../layout/HStack.js";
|
|
6
6
|
import { Text } from "../Text/index.js";
|
|
@@ -42,7 +42,8 @@ const UXTab = ({ tabKey = '', title, icon, style, notification })=>{
|
|
|
42
42
|
style: styles.tabText,
|
|
43
43
|
children: title
|
|
44
44
|
}),
|
|
45
|
-
notification ? /*#__PURE__*/ jsx(
|
|
45
|
+
notification ? /*#__PURE__*/ jsx(Icon, {
|
|
46
|
+
name: "dot",
|
|
46
47
|
color: "danger",
|
|
47
48
|
size: 5,
|
|
48
49
|
style: {
|
|
@@ -6,7 +6,7 @@ import { HStack } from "../layout/HStack.js";
|
|
|
6
6
|
import { Text } from "../Text/index.js";
|
|
7
7
|
import { UXButton } from "../UXButton/index.js";
|
|
8
8
|
import { useComponentConfig, useTheme } from "../../hooks/index.js";
|
|
9
|
-
import
|
|
9
|
+
import { Icon } from "../../icons/index.js";
|
|
10
10
|
import { ToastIcon } from "./ToastIcon.js";
|
|
11
11
|
const ToastView = ({ type, text, props: toastProps })=>{
|
|
12
12
|
const { btnText, numberOfLines = 4, colorBg, onPress = ()=>null } = toastProps ?? {};
|
|
@@ -63,7 +63,8 @@ const ToastView = ({ type, text, props: toastProps })=>{
|
|
|
63
63
|
/*#__PURE__*/ jsx(UXButton, {
|
|
64
64
|
variant: "text",
|
|
65
65
|
onPress: ()=>react_native_toast_message.hide(),
|
|
66
|
-
children: /*#__PURE__*/ jsx(
|
|
66
|
+
children: /*#__PURE__*/ jsx(Icon, {
|
|
67
|
+
name: "close",
|
|
67
68
|
color: colorBg ? 'white' : 'foreground',
|
|
68
69
|
size: 18
|
|
69
70
|
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type UXPressableProps } from '../UXPressable';
|
|
3
|
+
interface DateButtonProps extends UXPressableProps {
|
|
4
|
+
isSelected?: boolean;
|
|
5
|
+
text: string;
|
|
6
|
+
}
|
|
7
|
+
declare const DateButton: React.FC<DateButtonProps>;
|
|
8
|
+
export default DateButton;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import { Text } from "../Text/index.js";
|
|
4
|
+
import { UXPressable } from "../UXPressable/index.js";
|
|
5
|
+
const DateButton = ({ isSelected, text, ...props })=>/*#__PURE__*/ jsx(UXPressable, {
|
|
6
|
+
fill: true,
|
|
7
|
+
center: true,
|
|
8
|
+
border: 1,
|
|
9
|
+
h: 30,
|
|
10
|
+
radius: "xs",
|
|
11
|
+
borderColor: isSelected ? 'primary' : 'bg-200',
|
|
12
|
+
bg: "bg-200",
|
|
13
|
+
...props,
|
|
14
|
+
children: /*#__PURE__*/ jsx(Text, {
|
|
15
|
+
body3Bold: true,
|
|
16
|
+
color: isSelected ? 'foreground' : 'secondary',
|
|
17
|
+
children: text
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
const date_button = DateButton;
|
|
21
|
+
export { date_button as default };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useState } from "react";
|
|
3
|
+
import dayjs from "dayjs";
|
|
4
|
+
import { useI18n } from "../../hooks/index.js";
|
|
5
|
+
import { UXInput } from "../input/index.js";
|
|
6
|
+
import { HStack } from "../layout/HStack.js";
|
|
7
|
+
import { VStack } from "../layout/VStack.js";
|
|
8
|
+
import { UXButton } from "../UXButton/index.js";
|
|
9
|
+
import { UXModal } from "../UXModal/index.js";
|
|
10
|
+
import { UXPressable } from "../UXPressable/index.js";
|
|
11
|
+
import date_button from "./date-button.js";
|
|
12
|
+
import { DateWheelPicker } from "./date-wheel-picker.js";
|
|
13
|
+
import { TimeWheelPicker } from "./time-wheel-picker.js";
|
|
14
|
+
import { hasTimeInFormat } from "./utils.js";
|
|
15
|
+
const UXDatePicker = ({ value, defaultValue, onConfirm = ()=>null, format = 'YYYY/MM/DD', minDate, maxDate, placeholder, isDisabled = false, isReadOnly = false, ...uxPressableProps })=>{
|
|
16
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
17
|
+
const [pickerType, setPickerType] = useState('date');
|
|
18
|
+
const [internalValue, setInternalValue] = useState(value || defaultValue || new Date());
|
|
19
|
+
const i18n = useI18n();
|
|
20
|
+
const [dateFormat, timeFormat] = format.split(' ');
|
|
21
|
+
const showTimePicker = hasTimeInFormat(format);
|
|
22
|
+
const displayPlaceholder = placeholder ?? format;
|
|
23
|
+
useEffect(()=>{
|
|
24
|
+
if (void 0 !== value) setInternalValue(value);
|
|
25
|
+
}, [
|
|
26
|
+
value
|
|
27
|
+
]);
|
|
28
|
+
const handleOpenModal = useCallback((picker)=>{
|
|
29
|
+
if (isDisabled || isReadOnly) return;
|
|
30
|
+
setPickerType(picker);
|
|
31
|
+
setIsOpen(true);
|
|
32
|
+
}, [
|
|
33
|
+
isDisabled,
|
|
34
|
+
isReadOnly
|
|
35
|
+
]);
|
|
36
|
+
const handleConfirm = useCallback(()=>{
|
|
37
|
+
onConfirm(internalValue);
|
|
38
|
+
setIsOpen(false);
|
|
39
|
+
}, [
|
|
40
|
+
internalValue,
|
|
41
|
+
onConfirm
|
|
42
|
+
]);
|
|
43
|
+
const handleClose = useCallback(()=>{
|
|
44
|
+
setIsOpen(false);
|
|
45
|
+
}, []);
|
|
46
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
47
|
+
children: [
|
|
48
|
+
/*#__PURE__*/ jsx(UXPressable, {
|
|
49
|
+
onPress: ()=>handleOpenModal('date'),
|
|
50
|
+
...uxPressableProps,
|
|
51
|
+
children: /*#__PURE__*/ jsx(UXInput, {
|
|
52
|
+
containerStyle: {
|
|
53
|
+
flex: 1
|
|
54
|
+
},
|
|
55
|
+
editable: false,
|
|
56
|
+
isDisabled: isDisabled,
|
|
57
|
+
isReadOnly: isReadOnly,
|
|
58
|
+
placeholder: displayPlaceholder,
|
|
59
|
+
pointerEvents: "none",
|
|
60
|
+
value: value ? dayjs(value).format(format) : format
|
|
61
|
+
})
|
|
62
|
+
}),
|
|
63
|
+
/*#__PURE__*/ jsx(UXModal, {
|
|
64
|
+
disableCloseBySwipe: true,
|
|
65
|
+
wrapPortal: true,
|
|
66
|
+
footer: /*#__PURE__*/ jsx(UXButton, {
|
|
67
|
+
fullWidth: true,
|
|
68
|
+
color: "primary",
|
|
69
|
+
size: "lg",
|
|
70
|
+
onPress: handleConfirm,
|
|
71
|
+
children: i18n.datePicker.confirm
|
|
72
|
+
}),
|
|
73
|
+
isOpen: isOpen,
|
|
74
|
+
scrollViewProps: {
|
|
75
|
+
scrollEnabled: false
|
|
76
|
+
},
|
|
77
|
+
title: i18n.datePicker.confirm,
|
|
78
|
+
onClose: handleClose,
|
|
79
|
+
children: /*#__PURE__*/ jsxs(VStack, {
|
|
80
|
+
fullWidth: true,
|
|
81
|
+
gap: "lg",
|
|
82
|
+
children: [
|
|
83
|
+
/*#__PURE__*/ jsxs(HStack, {
|
|
84
|
+
fullWidth: true,
|
|
85
|
+
items: "center",
|
|
86
|
+
gap: 8,
|
|
87
|
+
children: [
|
|
88
|
+
/*#__PURE__*/ jsx(date_button, {
|
|
89
|
+
isSelected: 'date' === pickerType,
|
|
90
|
+
text: dayjs(internalValue).format(dateFormat),
|
|
91
|
+
onPress: ()=>setPickerType('date')
|
|
92
|
+
}),
|
|
93
|
+
showTimePicker && /*#__PURE__*/ jsx(date_button, {
|
|
94
|
+
isSelected: 'time' === pickerType,
|
|
95
|
+
text: dayjs(internalValue).format(timeFormat),
|
|
96
|
+
onPress: ()=>setPickerType('time')
|
|
97
|
+
})
|
|
98
|
+
]
|
|
99
|
+
}),
|
|
100
|
+
'date' === pickerType && /*#__PURE__*/ jsx(DateWheelPicker, {
|
|
101
|
+
maxDate: maxDate,
|
|
102
|
+
minDate: minDate,
|
|
103
|
+
selectedDate: internalValue,
|
|
104
|
+
onDateChange: setInternalValue
|
|
105
|
+
}),
|
|
106
|
+
'time' === pickerType && /*#__PURE__*/ jsx(TimeWheelPicker, {
|
|
107
|
+
selectedDate: internalValue,
|
|
108
|
+
onDateChange: setInternalValue
|
|
109
|
+
})
|
|
110
|
+
]
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
]
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
UXDatePicker.displayName = 'UXDatePicker';
|
|
117
|
+
export { UXDatePicker };
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useState } from "react";
|
|
3
|
+
import dayjs from "dayjs";
|
|
4
|
+
import { useI18n } from "../../hooks/index.js";
|
|
5
|
+
import { Icon } from "../../icons/index.js";
|
|
6
|
+
import { UXInput } from "../input/index.js";
|
|
7
|
+
import { HStack } from "../layout/HStack.js";
|
|
8
|
+
import { VStack } from "../layout/VStack.js";
|
|
9
|
+
import { Text } from "../Text/index.js";
|
|
10
|
+
import { UXButton } from "../UXButton/index.js";
|
|
11
|
+
import { UXModal } from "../UXModal/index.js";
|
|
12
|
+
import { UXPressable } from "../UXPressable/index.js";
|
|
13
|
+
import date_button from "./date-button.js";
|
|
14
|
+
import { DateWheelPicker } from "./date-wheel-picker.js";
|
|
15
|
+
import { TimeWheelPicker } from "./time-wheel-picker.js";
|
|
16
|
+
import { hasTimeInFormat } from "./utils.js";
|
|
17
|
+
const UXDateRangePicker = ({ value, defaultValue, onConfirm = ()=>null, format = 'YYYY/MM/DD', minDate, maxDate, startPlaceholder, endPlaceholder, isDisabled = false, isReadOnly = false, ...hStackProps })=>{
|
|
18
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
19
|
+
const [currentEditType, setCurrentEditType] = useState('start');
|
|
20
|
+
const [pickerType, setPickerType] = useState('date');
|
|
21
|
+
const [internalStart, setInternalStart] = useState(value?.start || defaultValue?.start || new Date());
|
|
22
|
+
const [internalEnd, setInternalEnd] = useState(value?.end || defaultValue?.end || new Date());
|
|
23
|
+
const [error, setError] = useState('');
|
|
24
|
+
const i18n = useI18n();
|
|
25
|
+
const [dateFormat, timeFormat] = format.split(' ');
|
|
26
|
+
const showTimePicker = hasTimeInFormat(format);
|
|
27
|
+
const displayStartPlaceholder = startPlaceholder ?? format;
|
|
28
|
+
const displayEndPlaceholder = endPlaceholder ?? format;
|
|
29
|
+
useEffect(()=>{
|
|
30
|
+
if (value?.start !== void 0) setInternalStart(value?.start);
|
|
31
|
+
if (value?.end !== void 0) setInternalEnd(value?.end);
|
|
32
|
+
}, [
|
|
33
|
+
value
|
|
34
|
+
]);
|
|
35
|
+
const handleOpenModal = useCallback((type, picker)=>{
|
|
36
|
+
if (isDisabled || isReadOnly) return;
|
|
37
|
+
setCurrentEditType(type);
|
|
38
|
+
setPickerType(picker);
|
|
39
|
+
setError('');
|
|
40
|
+
setIsOpen(true);
|
|
41
|
+
}, [
|
|
42
|
+
isDisabled,
|
|
43
|
+
isReadOnly
|
|
44
|
+
]);
|
|
45
|
+
const handleConfirm = useCallback(()=>{
|
|
46
|
+
if (!internalStart || !internalEnd) return void setError(i18n.datePicker.errorBothRequired);
|
|
47
|
+
if (internalStart > internalEnd) return void setError(i18n.datePicker.errorStartBeforeEnd);
|
|
48
|
+
setError('');
|
|
49
|
+
onConfirm({
|
|
50
|
+
start: internalStart,
|
|
51
|
+
end: internalEnd
|
|
52
|
+
});
|
|
53
|
+
setIsOpen(false);
|
|
54
|
+
}, [
|
|
55
|
+
internalStart,
|
|
56
|
+
internalEnd,
|
|
57
|
+
onConfirm,
|
|
58
|
+
i18n
|
|
59
|
+
]);
|
|
60
|
+
const handleClose = useCallback(()=>{
|
|
61
|
+
setIsOpen(false);
|
|
62
|
+
}, []);
|
|
63
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
64
|
+
children: [
|
|
65
|
+
/*#__PURE__*/ jsxs(HStack, {
|
|
66
|
+
gap: 8,
|
|
67
|
+
...hStackProps,
|
|
68
|
+
children: [
|
|
69
|
+
/*#__PURE__*/ jsx(UXPressable, {
|
|
70
|
+
fill: true,
|
|
71
|
+
onPress: ()=>handleOpenModal('start', 'date'),
|
|
72
|
+
children: /*#__PURE__*/ jsx(UXInput, {
|
|
73
|
+
containerStyle: {
|
|
74
|
+
flex: 1
|
|
75
|
+
},
|
|
76
|
+
editable: false,
|
|
77
|
+
isDisabled: isDisabled,
|
|
78
|
+
isReadOnly: isReadOnly,
|
|
79
|
+
placeholder: displayStartPlaceholder,
|
|
80
|
+
pointerEvents: "none",
|
|
81
|
+
value: value?.start ? dayjs(value?.start).format(format) : format
|
|
82
|
+
})
|
|
83
|
+
}),
|
|
84
|
+
/*#__PURE__*/ jsx(Icon, {
|
|
85
|
+
name: "arrow-right",
|
|
86
|
+
color: "tertiary",
|
|
87
|
+
size: 16
|
|
88
|
+
}),
|
|
89
|
+
/*#__PURE__*/ jsx(UXPressable, {
|
|
90
|
+
fill: true,
|
|
91
|
+
onPress: ()=>handleOpenModal('end', 'date'),
|
|
92
|
+
children: /*#__PURE__*/ jsx(UXInput, {
|
|
93
|
+
containerStyle: {
|
|
94
|
+
flex: 1
|
|
95
|
+
},
|
|
96
|
+
editable: false,
|
|
97
|
+
isDisabled: isDisabled,
|
|
98
|
+
isReadOnly: isReadOnly,
|
|
99
|
+
placeholder: displayEndPlaceholder,
|
|
100
|
+
pointerEvents: "none",
|
|
101
|
+
value: value?.end ? dayjs(value?.end).format(format) : format
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
]
|
|
105
|
+
}),
|
|
106
|
+
/*#__PURE__*/ jsx(UXModal, {
|
|
107
|
+
disableCloseBySwipe: true,
|
|
108
|
+
wrapPortal: true,
|
|
109
|
+
footer: /*#__PURE__*/ jsxs(VStack, {
|
|
110
|
+
fullWidth: true,
|
|
111
|
+
gap: 8,
|
|
112
|
+
children: [
|
|
113
|
+
error && /*#__PURE__*/ jsx(Text, {
|
|
114
|
+
color: "danger",
|
|
115
|
+
children: error
|
|
116
|
+
}),
|
|
117
|
+
/*#__PURE__*/ jsx(UXButton, {
|
|
118
|
+
fullWidth: true,
|
|
119
|
+
color: "primary",
|
|
120
|
+
size: "lg",
|
|
121
|
+
onPress: handleConfirm,
|
|
122
|
+
children: i18n.datePicker.confirm
|
|
123
|
+
})
|
|
124
|
+
]
|
|
125
|
+
}),
|
|
126
|
+
isOpen: isOpen,
|
|
127
|
+
scrollViewProps: {
|
|
128
|
+
scrollEnabled: false
|
|
129
|
+
},
|
|
130
|
+
title: "Time Range",
|
|
131
|
+
onClose: handleClose,
|
|
132
|
+
children: /*#__PURE__*/ jsxs(VStack, {
|
|
133
|
+
fullWidth: true,
|
|
134
|
+
gap: "lg",
|
|
135
|
+
children: [
|
|
136
|
+
/*#__PURE__*/ jsxs(HStack, {
|
|
137
|
+
fullWidth: true,
|
|
138
|
+
items: "center",
|
|
139
|
+
gap: 8,
|
|
140
|
+
children: [
|
|
141
|
+
/*#__PURE__*/ jsx(date_button, {
|
|
142
|
+
isSelected: 'start' === currentEditType && 'date' === pickerType,
|
|
143
|
+
text: dayjs(internalStart).format(dateFormat),
|
|
144
|
+
onPress: ()=>handleOpenModal('start', 'date')
|
|
145
|
+
}),
|
|
146
|
+
showTimePicker && /*#__PURE__*/ jsx(date_button, {
|
|
147
|
+
isSelected: 'start' === currentEditType && 'time' === pickerType,
|
|
148
|
+
text: dayjs(internalStart).format(timeFormat),
|
|
149
|
+
onPress: ()=>handleOpenModal('start', 'time')
|
|
150
|
+
}),
|
|
151
|
+
/*#__PURE__*/ jsx(Icon, {
|
|
152
|
+
name: "arrow-right",
|
|
153
|
+
color: "tertiary",
|
|
154
|
+
size: 16
|
|
155
|
+
}),
|
|
156
|
+
/*#__PURE__*/ jsx(date_button, {
|
|
157
|
+
isSelected: 'end' === currentEditType && 'date' === pickerType,
|
|
158
|
+
text: dayjs(internalEnd).format(dateFormat),
|
|
159
|
+
onPress: ()=>handleOpenModal('end', 'date')
|
|
160
|
+
}),
|
|
161
|
+
showTimePicker && /*#__PURE__*/ jsx(date_button, {
|
|
162
|
+
isSelected: 'end' === currentEditType && 'time' === pickerType,
|
|
163
|
+
text: dayjs(internalEnd).format(timeFormat),
|
|
164
|
+
onPress: ()=>handleOpenModal('end', 'time')
|
|
165
|
+
})
|
|
166
|
+
]
|
|
167
|
+
}),
|
|
168
|
+
'start' === currentEditType && 'date' === pickerType && /*#__PURE__*/ jsx(DateWheelPicker, {
|
|
169
|
+
maxDate: maxDate,
|
|
170
|
+
minDate: minDate,
|
|
171
|
+
selectedDate: internalStart,
|
|
172
|
+
onDateChange: setInternalStart
|
|
173
|
+
}),
|
|
174
|
+
'start' === currentEditType && 'time' === pickerType && /*#__PURE__*/ jsx(TimeWheelPicker, {
|
|
175
|
+
selectedDate: internalStart,
|
|
176
|
+
onDateChange: setInternalStart
|
|
177
|
+
}),
|
|
178
|
+
'end' === currentEditType && 'date' === pickerType && /*#__PURE__*/ jsx(DateWheelPicker, {
|
|
179
|
+
maxDate: maxDate,
|
|
180
|
+
minDate: minDate,
|
|
181
|
+
selectedDate: internalEnd,
|
|
182
|
+
onDateChange: setInternalEnd
|
|
183
|
+
}),
|
|
184
|
+
'end' === currentEditType && 'time' === pickerType && /*#__PURE__*/ jsx(TimeWheelPicker, {
|
|
185
|
+
selectedDate: internalEnd,
|
|
186
|
+
onDateChange: setInternalEnd
|
|
187
|
+
})
|
|
188
|
+
]
|
|
189
|
+
})
|
|
190
|
+
})
|
|
191
|
+
]
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
UXDateRangePicker.displayName = 'UXDateRangePicker';
|
|
195
|
+
export { UXDateRangePicker };
|