rn-inputforge 0.3.0 → 0.4.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/README.md +224 -19
- package/lib/commonjs/components/FieldFlowCheckbox/FieldFlowCheckbox.js +131 -0
- package/lib/commonjs/components/FieldFlowCheckbox/FieldFlowCheckbox.js.map +1 -0
- package/lib/commonjs/components/FieldFlowCheckbox/index.js +13 -0
- package/lib/commonjs/components/FieldFlowCheckbox/index.js.map +1 -0
- package/lib/commonjs/components/FieldFlowDateTimePicker/FieldFlowDateTimePicker.js +536 -0
- package/lib/commonjs/components/FieldFlowDateTimePicker/FieldFlowDateTimePicker.js.map +1 -0
- package/lib/commonjs/components/FieldFlowDateTimePicker/index.js +13 -0
- package/lib/commonjs/components/FieldFlowDateTimePicker/index.js.map +1 -0
- package/lib/commonjs/components/FieldFlowDateTimePicker/types.js +6 -0
- package/lib/commonjs/components/FieldFlowDateTimePicker/types.js.map +1 -0
- package/lib/commonjs/components/FieldFlowDropdown/FieldFlowDropdown.js +24 -9
- package/lib/commonjs/components/FieldFlowDropdown/FieldFlowDropdown.js.map +1 -1
- package/lib/commonjs/components/FieldFlowInput/FieldFlowInput.js +55 -24
- package/lib/commonjs/components/FieldFlowInput/FieldFlowInput.js.map +1 -1
- package/lib/commonjs/components/FieldFlowInput/styles.js +32 -11
- package/lib/commonjs/components/FieldFlowInput/styles.js.map +1 -1
- package/lib/commonjs/components/FieldFlowMaskedInput/FieldFlowMaskedInput.js +66 -0
- package/lib/commonjs/components/FieldFlowMaskedInput/FieldFlowMaskedInput.js.map +1 -0
- package/lib/commonjs/components/FieldFlowMaskedInput/index.js +13 -0
- package/lib/commonjs/components/FieldFlowMaskedInput/index.js.map +1 -0
- package/lib/commonjs/components/FieldFlowMaskedInput/types.js +6 -0
- package/lib/commonjs/components/FieldFlowMaskedInput/types.js.map +1 -0
- package/lib/commonjs/components/FieldFlowOTP/FieldFlowOTP.js +255 -0
- package/lib/commonjs/components/FieldFlowOTP/FieldFlowOTP.js.map +1 -0
- package/lib/commonjs/components/FieldFlowOTP/index.js +13 -0
- package/lib/commonjs/components/FieldFlowOTP/index.js.map +1 -0
- package/lib/commonjs/components/FieldFlowOTP/types.js +6 -0
- package/lib/commonjs/components/FieldFlowOTP/types.js.map +1 -0
- package/lib/commonjs/components/FieldFlowRadio/FieldFlowRadio.js +164 -0
- package/lib/commonjs/components/FieldFlowRadio/FieldFlowRadio.js.map +1 -0
- package/lib/commonjs/components/FieldFlowRadio/index.js +13 -0
- package/lib/commonjs/components/FieldFlowRadio/index.js.map +1 -0
- package/lib/commonjs/components/FieldFlowSwitch/FieldFlowSwitch.js +152 -0
- package/lib/commonjs/components/FieldFlowSwitch/FieldFlowSwitch.js.map +1 -0
- package/lib/commonjs/components/FieldFlowSwitch/index.js +13 -0
- package/lib/commonjs/components/FieldFlowSwitch/index.js.map +1 -0
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useFieldFlowForm.js +146 -31
- package/lib/commonjs/hooks/useFieldFlowForm.js.map +1 -1
- package/lib/commonjs/icons/Icon.js +719 -30
- package/lib/commonjs/icons/Icon.js.map +1 -1
- package/lib/commonjs/icons/index.js +7 -0
- package/lib/commonjs/icons/index.js.map +1 -1
- package/lib/commonjs/icons/renderIcon.js +24 -0
- package/lib/commonjs/icons/renderIcon.js.map +1 -0
- package/lib/commonjs/index.js +127 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/masks.js +130 -0
- package/lib/commonjs/utils/masks.js.map +1 -0
- package/lib/commonjs/validation/index.js +25 -0
- package/lib/commonjs/validation/index.js.map +1 -1
- package/lib/commonjs/validation/zodAdapter.js +91 -0
- package/lib/commonjs/validation/zodAdapter.js.map +1 -0
- package/lib/module/components/FieldFlowCheckbox/FieldFlowCheckbox.js +126 -0
- package/lib/module/components/FieldFlowCheckbox/FieldFlowCheckbox.js.map +1 -0
- package/lib/module/components/FieldFlowCheckbox/index.js +4 -0
- package/lib/module/components/FieldFlowCheckbox/index.js.map +1 -0
- package/lib/module/components/FieldFlowDateTimePicker/FieldFlowDateTimePicker.js +531 -0
- package/lib/module/components/FieldFlowDateTimePicker/FieldFlowDateTimePicker.js.map +1 -0
- package/lib/module/components/FieldFlowDateTimePicker/index.js +4 -0
- package/lib/module/components/FieldFlowDateTimePicker/index.js.map +1 -0
- package/lib/module/components/FieldFlowDateTimePicker/types.js +4 -0
- package/lib/module/components/FieldFlowDateTimePicker/types.js.map +1 -0
- package/lib/module/components/FieldFlowDropdown/FieldFlowDropdown.js +24 -9
- package/lib/module/components/FieldFlowDropdown/FieldFlowDropdown.js.map +1 -1
- package/lib/module/components/FieldFlowInput/FieldFlowInput.js +59 -28
- package/lib/module/components/FieldFlowInput/FieldFlowInput.js.map +1 -1
- package/lib/module/components/FieldFlowInput/styles.js +32 -11
- package/lib/module/components/FieldFlowInput/styles.js.map +1 -1
- package/lib/module/components/FieldFlowMaskedInput/FieldFlowMaskedInput.js +61 -0
- package/lib/module/components/FieldFlowMaskedInput/FieldFlowMaskedInput.js.map +1 -0
- package/lib/module/components/FieldFlowMaskedInput/index.js +4 -0
- package/lib/module/components/FieldFlowMaskedInput/index.js.map +1 -0
- package/lib/module/components/FieldFlowMaskedInput/types.js +4 -0
- package/lib/module/components/FieldFlowMaskedInput/types.js.map +1 -0
- package/lib/module/components/FieldFlowOTP/FieldFlowOTP.js +250 -0
- package/lib/module/components/FieldFlowOTP/FieldFlowOTP.js.map +1 -0
- package/lib/module/components/FieldFlowOTP/index.js +4 -0
- package/lib/module/components/FieldFlowOTP/index.js.map +1 -0
- package/lib/module/components/FieldFlowOTP/types.js +4 -0
- package/lib/module/components/FieldFlowOTP/types.js.map +1 -0
- package/lib/module/components/FieldFlowRadio/FieldFlowRadio.js +159 -0
- package/lib/module/components/FieldFlowRadio/FieldFlowRadio.js.map +1 -0
- package/lib/module/components/FieldFlowRadio/index.js +4 -0
- package/lib/module/components/FieldFlowRadio/index.js.map +1 -0
- package/lib/module/components/FieldFlowSwitch/FieldFlowSwitch.js +147 -0
- package/lib/module/components/FieldFlowSwitch/FieldFlowSwitch.js.map +1 -0
- package/lib/module/components/FieldFlowSwitch/index.js +4 -0
- package/lib/module/components/FieldFlowSwitch/index.js.map +1 -0
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useFieldFlowForm.js +147 -32
- package/lib/module/hooks/useFieldFlowForm.js.map +1 -1
- package/lib/module/icons/Icon.js +720 -31
- package/lib/module/icons/Icon.js.map +1 -1
- package/lib/module/icons/index.js +1 -0
- package/lib/module/icons/index.js.map +1 -1
- package/lib/module/icons/renderIcon.js +19 -0
- package/lib/module/icons/renderIcon.js.map +1 -0
- package/lib/module/index.js +11 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/masks.js +118 -0
- package/lib/module/utils/masks.js.map +1 -0
- package/lib/module/validation/index.js +1 -0
- package/lib/module/validation/index.js.map +1 -1
- package/lib/module/validation/zodAdapter.js +84 -0
- package/lib/module/validation/zodAdapter.js.map +1 -0
- package/lib/typescript/components/FieldFlowCheckbox/FieldFlowCheckbox.d.ts +36 -0
- package/lib/typescript/components/FieldFlowCheckbox/FieldFlowCheckbox.d.ts.map +1 -0
- package/lib/typescript/components/FieldFlowCheckbox/index.d.ts +3 -0
- package/lib/typescript/components/FieldFlowCheckbox/index.d.ts.map +1 -0
- package/lib/typescript/components/FieldFlowDateTimePicker/FieldFlowDateTimePicker.d.ts +4 -0
- package/lib/typescript/components/FieldFlowDateTimePicker/FieldFlowDateTimePicker.d.ts.map +1 -0
- package/lib/typescript/components/FieldFlowDateTimePicker/index.d.ts +3 -0
- package/lib/typescript/components/FieldFlowDateTimePicker/index.d.ts.map +1 -0
- package/lib/typescript/components/FieldFlowDateTimePicker/types.d.ts +55 -0
- package/lib/typescript/components/FieldFlowDateTimePicker/types.d.ts.map +1 -0
- package/lib/typescript/components/FieldFlowDropdown/FieldFlowDropdown.d.ts.map +1 -1
- package/lib/typescript/components/FieldFlowDropdown/types.d.ts +7 -1
- package/lib/typescript/components/FieldFlowDropdown/types.d.ts.map +1 -1
- package/lib/typescript/components/FieldFlowInput/FieldFlowInput.d.ts.map +1 -1
- package/lib/typescript/components/FieldFlowInput/styles.d.ts +19 -2
- package/lib/typescript/components/FieldFlowInput/styles.d.ts.map +1 -1
- package/lib/typescript/components/FieldFlowInput/types.d.ts +24 -5
- package/lib/typescript/components/FieldFlowInput/types.d.ts.map +1 -1
- package/lib/typescript/components/FieldFlowMaskedInput/FieldFlowMaskedInput.d.ts +5 -0
- package/lib/typescript/components/FieldFlowMaskedInput/FieldFlowMaskedInput.d.ts.map +1 -0
- package/lib/typescript/components/FieldFlowMaskedInput/index.d.ts +3 -0
- package/lib/typescript/components/FieldFlowMaskedInput/index.d.ts.map +1 -0
- package/lib/typescript/components/FieldFlowMaskedInput/types.d.ts +20 -0
- package/lib/typescript/components/FieldFlowMaskedInput/types.d.ts.map +1 -0
- package/lib/typescript/components/FieldFlowOTP/FieldFlowOTP.d.ts +4 -0
- package/lib/typescript/components/FieldFlowOTP/FieldFlowOTP.d.ts.map +1 -0
- package/lib/typescript/components/FieldFlowOTP/index.d.ts +3 -0
- package/lib/typescript/components/FieldFlowOTP/index.d.ts.map +1 -0
- package/lib/typescript/components/FieldFlowOTP/types.d.ts +52 -0
- package/lib/typescript/components/FieldFlowOTP/types.d.ts.map +1 -0
- package/lib/typescript/components/FieldFlowRadio/FieldFlowRadio.d.ts +39 -0
- package/lib/typescript/components/FieldFlowRadio/FieldFlowRadio.d.ts.map +1 -0
- package/lib/typescript/components/FieldFlowRadio/index.d.ts +3 -0
- package/lib/typescript/components/FieldFlowRadio/index.d.ts.map +1 -0
- package/lib/typescript/components/FieldFlowSwitch/FieldFlowSwitch.d.ts +31 -0
- package/lib/typescript/components/FieldFlowSwitch/FieldFlowSwitch.d.ts.map +1 -0
- package/lib/typescript/components/FieldFlowSwitch/index.d.ts +3 -0
- package/lib/typescript/components/FieldFlowSwitch/index.d.ts.map +1 -0
- package/lib/typescript/hooks/index.d.ts +1 -1
- package/lib/typescript/hooks/index.d.ts.map +1 -1
- package/lib/typescript/hooks/useFieldFlowForm.d.ts +46 -7
- package/lib/typescript/hooks/useFieldFlowForm.d.ts.map +1 -1
- package/lib/typescript/icons/Icon.d.ts +2 -2
- package/lib/typescript/icons/Icon.d.ts.map +1 -1
- package/lib/typescript/icons/index.d.ts +2 -0
- package/lib/typescript/icons/index.d.ts.map +1 -1
- package/lib/typescript/icons/renderIcon.d.ts +6 -0
- package/lib/typescript/icons/renderIcon.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +20 -6
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/types/index.d.ts +4 -0
- package/lib/typescript/types/index.d.ts.map +1 -1
- package/lib/typescript/utils/masks.d.ts +37 -0
- package/lib/typescript/utils/masks.d.ts.map +1 -0
- package/lib/typescript/validation/index.d.ts +2 -0
- package/lib/typescript/validation/index.d.ts.map +1 -1
- package/lib/typescript/validation/zodAdapter.d.ts +53 -0
- package/lib/typescript/validation/zodAdapter.d.ts.map +1 -0
- package/package.json +27 -5
- package/src/components/FieldFlowCheckbox/FieldFlowCheckbox.tsx +174 -0
- package/src/components/FieldFlowCheckbox/index.ts +2 -0
- package/src/components/FieldFlowDateTimePicker/FieldFlowDateTimePicker.tsx +585 -0
- package/src/components/FieldFlowDateTimePicker/index.ts +2 -0
- package/src/components/FieldFlowDateTimePicker/types.ts +57 -0
- package/src/components/FieldFlowDropdown/FieldFlowDropdown.tsx +17 -7
- package/src/components/FieldFlowDropdown/types.ts +8 -1
- package/src/components/FieldFlowInput/FieldFlowInput.tsx +69 -26
- package/src/components/FieldFlowInput/styles.ts +41 -6
- package/src/components/FieldFlowInput/types.ts +24 -5
- package/src/components/FieldFlowMaskedInput/FieldFlowMaskedInput.tsx +76 -0
- package/src/components/FieldFlowMaskedInput/index.ts +2 -0
- package/src/components/FieldFlowMaskedInput/types.ts +22 -0
- package/src/components/FieldFlowOTP/FieldFlowOTP.tsx +305 -0
- package/src/components/FieldFlowOTP/index.ts +2 -0
- package/src/components/FieldFlowOTP/types.ts +57 -0
- package/src/components/FieldFlowRadio/FieldFlowRadio.tsx +215 -0
- package/src/components/FieldFlowRadio/index.ts +2 -0
- package/src/components/FieldFlowSwitch/FieldFlowSwitch.tsx +172 -0
- package/src/components/FieldFlowSwitch/index.ts +2 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useFieldFlowForm.ts +209 -33
- package/src/icons/Icon.tsx +451 -5
- package/src/icons/index.ts +2 -0
- package/src/icons/renderIcon.tsx +17 -0
- package/src/index.ts +47 -4
- package/src/types/index.ts +5 -0
- package/src/utils/masks.ts +137 -0
- package/src/validation/index.ts +7 -0
- package/src/validation/zodAdapter.ts +103 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React, { useMemo } from 'react';
|
|
4
|
+
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
|
5
|
+
import { useFieldFlowTheme, mergeDeep } from '../../theme/ThemeProvider';
|
|
6
|
+
import { defaultTheme } from '../../theme/defaultTheme';
|
|
7
|
+
import { renderFieldFlowIcon } from '../../icons';
|
|
8
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
export function FieldFlowCheckbox({
|
|
10
|
+
value,
|
|
11
|
+
onChange,
|
|
12
|
+
label,
|
|
13
|
+
helperText,
|
|
14
|
+
errorText,
|
|
15
|
+
disabled,
|
|
16
|
+
required,
|
|
17
|
+
labelPosition = 'right',
|
|
18
|
+
checkedIcon = 'check',
|
|
19
|
+
uncheckedIcon,
|
|
20
|
+
leftIcon,
|
|
21
|
+
iconSize = 14,
|
|
22
|
+
checkedColor,
|
|
23
|
+
uncheckedColor,
|
|
24
|
+
boxSize = 22,
|
|
25
|
+
boxStyle,
|
|
26
|
+
containerStyle,
|
|
27
|
+
labelStyle,
|
|
28
|
+
helperStyle,
|
|
29
|
+
errorStyle,
|
|
30
|
+
theme: themeOverride,
|
|
31
|
+
testID
|
|
32
|
+
}) {
|
|
33
|
+
const contextTheme = useFieldFlowTheme();
|
|
34
|
+
const theme = useMemo(() => themeOverride ? mergeDeep(contextTheme ?? defaultTheme, themeOverride) : contextTheme ?? defaultTheme, [contextTheme, themeOverride]);
|
|
35
|
+
const styles = useMemo(() => createStyles(theme, Boolean(errorText), Boolean(disabled), boxSize), [theme, errorText, disabled, boxSize]);
|
|
36
|
+
const checked = Boolean(value);
|
|
37
|
+
const activeColor = checkedColor ?? theme.colors.borderFocused;
|
|
38
|
+
const idleColor = uncheckedColor ?? (errorText ? theme.colors.borderError : theme.colors.border);
|
|
39
|
+
const box = /*#__PURE__*/_jsx(View, {
|
|
40
|
+
style: [styles.box, checked && {
|
|
41
|
+
backgroundColor: activeColor,
|
|
42
|
+
borderColor: activeColor
|
|
43
|
+
}, !checked && {
|
|
44
|
+
borderColor: idleColor
|
|
45
|
+
}, disabled ? styles.boxDisabled : null, boxStyle],
|
|
46
|
+
children: checked ? renderFieldFlowIcon(checkedIcon, '#FFFFFF', iconSize) : uncheckedIcon ? renderFieldFlowIcon(uncheckedIcon, idleColor, iconSize) : null
|
|
47
|
+
});
|
|
48
|
+
const labelNode = label ? /*#__PURE__*/_jsxs(Text, {
|
|
49
|
+
style: [styles.label, labelStyle],
|
|
50
|
+
children: [label, required ? ' *' : '']
|
|
51
|
+
}) : null;
|
|
52
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
53
|
+
style: [styles.wrapper, containerStyle],
|
|
54
|
+
testID: testID,
|
|
55
|
+
children: [/*#__PURE__*/_jsxs(Pressable, {
|
|
56
|
+
onPress: () => !disabled && onChange(!checked),
|
|
57
|
+
disabled: disabled,
|
|
58
|
+
style: styles.row,
|
|
59
|
+
accessibilityRole: "checkbox",
|
|
60
|
+
accessibilityState: {
|
|
61
|
+
checked,
|
|
62
|
+
disabled: Boolean(disabled)
|
|
63
|
+
},
|
|
64
|
+
accessibilityLabel: label,
|
|
65
|
+
hitSlop: 6,
|
|
66
|
+
children: [leftIcon ? /*#__PURE__*/_jsx(View, {
|
|
67
|
+
style: styles.leftIcon,
|
|
68
|
+
children: renderFieldFlowIcon(leftIcon, theme.colors.icon, 18)
|
|
69
|
+
}) : null, labelPosition === 'left' ? labelNode : null, box, labelPosition === 'right' ? labelNode : null]
|
|
70
|
+
}), errorText ? /*#__PURE__*/_jsx(Text, {
|
|
71
|
+
style: [styles.errorText, errorStyle, helperStyle],
|
|
72
|
+
children: errorText
|
|
73
|
+
}) : helperText ? /*#__PURE__*/_jsx(Text, {
|
|
74
|
+
style: [styles.helperText, helperStyle],
|
|
75
|
+
children: helperText
|
|
76
|
+
}) : null]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function createStyles(theme, _hasError, disabled, boxSize) {
|
|
80
|
+
return StyleSheet.create({
|
|
81
|
+
wrapper: {
|
|
82
|
+
marginBottom: theme.spacing.gap * 2,
|
|
83
|
+
opacity: disabled ? 0.6 : 1
|
|
84
|
+
},
|
|
85
|
+
row: {
|
|
86
|
+
flexDirection: 'row',
|
|
87
|
+
alignItems: 'center',
|
|
88
|
+
gap: theme.spacing.gap
|
|
89
|
+
},
|
|
90
|
+
leftIcon: {
|
|
91
|
+
marginRight: 2
|
|
92
|
+
},
|
|
93
|
+
box: {
|
|
94
|
+
width: boxSize,
|
|
95
|
+
height: boxSize,
|
|
96
|
+
borderRadius: 6,
|
|
97
|
+
borderWidth: theme.spacing.borderWidthFocused,
|
|
98
|
+
backgroundColor: theme.colors.background,
|
|
99
|
+
alignItems: 'center',
|
|
100
|
+
justifyContent: 'center'
|
|
101
|
+
},
|
|
102
|
+
boxDisabled: {
|
|
103
|
+
backgroundColor: theme.colors.backgroundDisabled
|
|
104
|
+
},
|
|
105
|
+
label: {
|
|
106
|
+
flex: 1,
|
|
107
|
+
fontSize: theme.typography.fontSize,
|
|
108
|
+
color: theme.colors.text,
|
|
109
|
+
fontWeight: '400',
|
|
110
|
+
fontFamily: theme.typography.fontFamily
|
|
111
|
+
},
|
|
112
|
+
helperText: {
|
|
113
|
+
marginTop: theme.spacing.gap / 1.5,
|
|
114
|
+
marginLeft: boxSize + theme.spacing.gap,
|
|
115
|
+
fontSize: theme.typography.helperFontSize,
|
|
116
|
+
color: theme.colors.label
|
|
117
|
+
},
|
|
118
|
+
errorText: {
|
|
119
|
+
marginTop: theme.spacing.gap / 1.5,
|
|
120
|
+
marginLeft: boxSize + theme.spacing.gap,
|
|
121
|
+
fontSize: theme.typography.helperFontSize,
|
|
122
|
+
color: theme.colors.error
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=FieldFlowCheckbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useMemo","Pressable","StyleSheet","Text","View","useFieldFlowTheme","mergeDeep","defaultTheme","renderFieldFlowIcon","jsx","_jsx","jsxs","_jsxs","FieldFlowCheckbox","value","onChange","label","helperText","errorText","disabled","required","labelPosition","checkedIcon","uncheckedIcon","leftIcon","iconSize","checkedColor","uncheckedColor","boxSize","boxStyle","containerStyle","labelStyle","helperStyle","errorStyle","theme","themeOverride","testID","contextTheme","styles","createStyles","Boolean","checked","activeColor","colors","borderFocused","idleColor","borderError","border","box","style","backgroundColor","borderColor","boxDisabled","children","labelNode","wrapper","onPress","row","accessibilityRole","accessibilityState","accessibilityLabel","hitSlop","icon","_hasError","create","marginBottom","spacing","gap","opacity","flexDirection","alignItems","marginRight","width","height","borderRadius","borderWidth","borderWidthFocused","background","justifyContent","backgroundDisabled","flex","fontSize","typography","color","text","fontWeight","fontFamily","marginTop","marginLeft","helperFontSize","error"],"sourceRoot":"../../../../src","sources":["components/FieldFlowCheckbox/FieldFlowCheckbox.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SAASC,SAAS,EAAEC,UAAU,EAAEC,IAAI,EAAEC,IAAI,Q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MAAM,EAAE7C,OAAO;MACf8C,YAAY,EAAE,CAAC;MACfC,WAAW,EAAEzC,KAAK,CAACgC,OAAO,CAACU,kBAAkB;MAC7C1B,eAAe,EAAEhB,KAAK,CAACS,MAAM,CAACkC,UAAU;MACxCP,UAAU,EAAE,QAAQ;MACpBQ,cAAc,EAAE;IAClB,CAAC;IACD1B,WAAW,EAAE;MACXF,eAAe,EAAEhB,KAAK,CAACS,MAAM,CAACoC;IAChC,CAAC;IACD/D,KAAK,EAAE;MACLgE,IAAI,EAAE,CAAC;MACPC,QAAQ,EAAE/C,KAAK,CAACgD,UAAU,CAACD,QAAQ;MACnCE,KAAK,EAAEjD,KAAK,CAACS,MAAM,CAACyC,IAAI;MACxBC,UAAU,EAAE,KAAK;MACjBC,UAAU,EAAEpD,KAAK,CAACgD,UAAU,CAACI;IAC/B,CAAC;IACDrE,UAAU,EAAE;MACVsE,SAAS,EAAErD,KAAK,CAACgC,OAAO,CAACC,GAAG,GAAG,GAAG;MAClCqB,UAAU,EAAE5D,OAAO,GAAGM,KAAK,CAACgC,OAAO,CAACC,GAAG;MACvCc,QAAQ,EAAE/C,KAAK,CAACgD,UAAU,CAACO,cAAc;MACzCN,KAAK,EAAEjD,KAAK,CAACS,MAAM,CAAC3B;IACtB,CAAC;IACDE,SAAS,EAAE;MACTqE,SAAS,EAAErD,KAAK,CAACgC,OAAO,CAACC,GAAG,GAAG,GAAG;MAClCqB,UAAU,EAAE5D,OAAO,GAAGM,KAAK,CAACgC,OAAO,CAACC,GAAG;MACvCc,QAAQ,EAAE/C,KAAK,CAACgD,UAAU,CAACO,cAAc;MACzCN,KAAK,EAAEjD,KAAK,CAACS,MAAM,CAAC+C;IACtB;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FieldFlowCheckbox"],"sourceRoot":"../../../../src","sources":["components/FieldFlowCheckbox/index.ts"],"mappings":";;AAAA,SAASA,iBAAiB,QAAQ,qBAAqB","ignoreList":[]}
|
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
4
|
+
import { Modal, Pressable, ScrollView, StyleSheet, Text, View } from 'react-native';
|
|
5
|
+
import { useFieldFlowTheme, mergeDeep } from '../../theme/ThemeProvider';
|
|
6
|
+
import { defaultTheme } from '../../theme/defaultTheme';
|
|
7
|
+
import { useFieldState } from '../../hooks/useFieldState';
|
|
8
|
+
import { createStyles as createInputStyles, iconColorFor } from '../FieldFlowInput/styles';
|
|
9
|
+
import { renderFieldFlowIcon } from '../../icons/renderIcon';
|
|
10
|
+
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
|
+
const WEEKDAYS = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
|
|
12
|
+
const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
13
|
+
function pad(n) {
|
|
14
|
+
return n < 10 ? `0${n}` : String(n);
|
|
15
|
+
}
|
|
16
|
+
function parseValue(value, mode) {
|
|
17
|
+
const now = new Date();
|
|
18
|
+
if (!value) return now;
|
|
19
|
+
if (mode === 'time') {
|
|
20
|
+
const [h, m] = value.split(':').map(Number);
|
|
21
|
+
const d = new Date(now);
|
|
22
|
+
d.setHours(h || 0, m || 0, 0, 0);
|
|
23
|
+
return d;
|
|
24
|
+
}
|
|
25
|
+
if (mode === 'datetime' && value.includes('T')) {
|
|
26
|
+
const [datePart, timePart] = value.split('T');
|
|
27
|
+
const [y, mo, day] = datePart.split('-').map(Number);
|
|
28
|
+
const [h, m] = (timePart || '00:00').split(':').map(Number);
|
|
29
|
+
return new Date(y, (mo || 1) - 1, day || 1, h || 0, m || 0);
|
|
30
|
+
}
|
|
31
|
+
const [y, mo, day] = value.split('-').map(Number);
|
|
32
|
+
if (!y) return now;
|
|
33
|
+
return new Date(y, (mo || 1) - 1, day || 1);
|
|
34
|
+
}
|
|
35
|
+
function toOutput(date, mode) {
|
|
36
|
+
const y = date.getFullYear();
|
|
37
|
+
const mo = pad(date.getMonth() + 1);
|
|
38
|
+
const d = pad(date.getDate());
|
|
39
|
+
const h = pad(date.getHours());
|
|
40
|
+
const mi = pad(date.getMinutes());
|
|
41
|
+
if (mode === 'time') return `${h}:${mi}`;
|
|
42
|
+
if (mode === 'datetime') return `${y}-${mo}-${d}T${h}:${mi}`;
|
|
43
|
+
return `${y}-${mo}-${d}`;
|
|
44
|
+
}
|
|
45
|
+
function formatTime(date, hourCycle) {
|
|
46
|
+
if (hourCycle === 12) {
|
|
47
|
+
const h = date.getHours();
|
|
48
|
+
const ampm = h >= 12 ? 'PM' : 'AM';
|
|
49
|
+
const h12 = h % 12 || 12;
|
|
50
|
+
return `${h12}:${pad(date.getMinutes())} ${ampm}`;
|
|
51
|
+
}
|
|
52
|
+
return `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
53
|
+
}
|
|
54
|
+
function defaultFormat(date, mode, hourCycle) {
|
|
55
|
+
if (mode === 'time') return formatTime(date, hourCycle);
|
|
56
|
+
const dateStr = `${MONTHS[date.getMonth()].slice(0, 3)} ${date.getDate()}, ${date.getFullYear()}`;
|
|
57
|
+
if (mode === 'date') return dateStr;
|
|
58
|
+
return `${dateStr} · ${formatTime(date, hourCycle)}`;
|
|
59
|
+
}
|
|
60
|
+
function daysInMonth(year, month) {
|
|
61
|
+
return new Date(year, month + 1, 0).getDate();
|
|
62
|
+
}
|
|
63
|
+
function startWeekday(year, month) {
|
|
64
|
+
return new Date(year, month, 1).getDay();
|
|
65
|
+
}
|
|
66
|
+
export function FieldFlowDateTimePicker({
|
|
67
|
+
mode = 'date',
|
|
68
|
+
value,
|
|
69
|
+
onChange,
|
|
70
|
+
label,
|
|
71
|
+
placeholder = 'Select',
|
|
72
|
+
helperText,
|
|
73
|
+
errorText,
|
|
74
|
+
hasError,
|
|
75
|
+
successText,
|
|
76
|
+
isSuccess,
|
|
77
|
+
disabled,
|
|
78
|
+
required,
|
|
79
|
+
clearable,
|
|
80
|
+
variant = 'outlined',
|
|
81
|
+
minimumDate,
|
|
82
|
+
maximumDate,
|
|
83
|
+
hourCycle = 24,
|
|
84
|
+
confirmLabel = 'Done',
|
|
85
|
+
cancelLabel = 'Cancel',
|
|
86
|
+
title,
|
|
87
|
+
leftIcon,
|
|
88
|
+
rightIcon,
|
|
89
|
+
iconSize = 18,
|
|
90
|
+
onLeftIconPress,
|
|
91
|
+
onRightIconPress,
|
|
92
|
+
formatDisplay,
|
|
93
|
+
renderTrigger,
|
|
94
|
+
containerStyle,
|
|
95
|
+
triggerStyle,
|
|
96
|
+
labelStyle,
|
|
97
|
+
helperStyle,
|
|
98
|
+
modalStyle,
|
|
99
|
+
theme: themeOverride,
|
|
100
|
+
testID
|
|
101
|
+
}) {
|
|
102
|
+
const contextTheme = useFieldFlowTheme();
|
|
103
|
+
const theme = useMemo(() => themeOverride ? mergeDeep(contextTheme ?? defaultTheme, themeOverride) : contextTheme ?? defaultTheme, [contextTheme, themeOverride]);
|
|
104
|
+
const [open, setOpen] = useState(false);
|
|
105
|
+
const [draft, setDraft] = useState(() => parseValue(value, mode));
|
|
106
|
+
const [viewYear, setViewYear] = useState(draft.getFullYear());
|
|
107
|
+
const [viewMonth, setViewMonth] = useState(draft.getMonth());
|
|
108
|
+
const state = useFieldState({
|
|
109
|
+
isFocused: open,
|
|
110
|
+
hasError: Boolean(hasError || errorText),
|
|
111
|
+
isSuccess,
|
|
112
|
+
disabled
|
|
113
|
+
});
|
|
114
|
+
const inputStyles = useMemo(() => createInputStyles(theme, state, false, variant), [theme, state, variant]);
|
|
115
|
+
const styles = useMemo(() => createModalStyles(theme), [theme]);
|
|
116
|
+
const iconColor = iconColorFor(theme, state);
|
|
117
|
+
const display = useMemo(() => {
|
|
118
|
+
if (!value) return '';
|
|
119
|
+
const d = parseValue(value, mode);
|
|
120
|
+
return formatDisplay ? formatDisplay(d, mode) : defaultFormat(d, mode, hourCycle);
|
|
121
|
+
}, [value, mode, formatDisplay, hourCycle]);
|
|
122
|
+
const resolvedLeft = leftIcon !== undefined ? leftIcon : mode === 'time' ? 'clock' : 'calendar';
|
|
123
|
+
const resolvedRight = rightIcon !== undefined ? rightIcon : 'chevronDown';
|
|
124
|
+
const min = minimumDate ? parseValue(minimumDate, 'date') : undefined;
|
|
125
|
+
const max = maximumDate ? parseValue(maximumDate, 'date') : undefined;
|
|
126
|
+
const openPicker = useCallback(() => {
|
|
127
|
+
if (disabled) return;
|
|
128
|
+
const d = parseValue(value, mode);
|
|
129
|
+
setDraft(d);
|
|
130
|
+
setViewYear(d.getFullYear());
|
|
131
|
+
setViewMonth(d.getMonth());
|
|
132
|
+
setOpen(true);
|
|
133
|
+
}, [disabled, value, mode]);
|
|
134
|
+
const confirm = useCallback(() => {
|
|
135
|
+
onChange(toOutput(draft, mode));
|
|
136
|
+
setOpen(false);
|
|
137
|
+
}, [draft, mode, onChange]);
|
|
138
|
+
const isDayDisabled = day => {
|
|
139
|
+
const d = new Date(viewYear, viewMonth, day);
|
|
140
|
+
if (min && d < new Date(min.getFullYear(), min.getMonth(), min.getDate())) return true;
|
|
141
|
+
if (max && d > new Date(max.getFullYear(), max.getMonth(), max.getDate())) return true;
|
|
142
|
+
return false;
|
|
143
|
+
};
|
|
144
|
+
const calendarCells = useMemo(() => {
|
|
145
|
+
const total = daysInMonth(viewYear, viewMonth);
|
|
146
|
+
const start = startWeekday(viewYear, viewMonth);
|
|
147
|
+
const cells = [];
|
|
148
|
+
for (let i = 0; i < start; i++) cells.push(null);
|
|
149
|
+
for (let d = 1; d <= total; d++) cells.push(d);
|
|
150
|
+
while (cells.length % 7 !== 0) cells.push(null);
|
|
151
|
+
return cells;
|
|
152
|
+
}, [viewYear, viewMonth]);
|
|
153
|
+
const hours = hourCycle === 12 ? Array.from({
|
|
154
|
+
length: 12
|
|
155
|
+
}, (_, i) => i + 1) : Array.from({
|
|
156
|
+
length: 24
|
|
157
|
+
}, (_, i) => i);
|
|
158
|
+
const minutes = Array.from({
|
|
159
|
+
length: 60
|
|
160
|
+
}, (_, i) => i);
|
|
161
|
+
const trigger = renderTrigger ? renderTrigger({
|
|
162
|
+
open: openPicker,
|
|
163
|
+
display,
|
|
164
|
+
value
|
|
165
|
+
}) : /*#__PURE__*/_jsxs(View, {
|
|
166
|
+
style: [inputStyles.wrapper, containerStyle],
|
|
167
|
+
testID: testID,
|
|
168
|
+
children: [label && variant !== 'floating' ? /*#__PURE__*/_jsxs(Text, {
|
|
169
|
+
style: [inputStyles.label, labelStyle],
|
|
170
|
+
children: [label, required ? ' *' : '']
|
|
171
|
+
}) : null, /*#__PURE__*/_jsxs(Pressable, {
|
|
172
|
+
onPress: openPicker,
|
|
173
|
+
disabled: disabled,
|
|
174
|
+
style: [inputStyles.inputContainer, triggerStyle],
|
|
175
|
+
accessibilityRole: "button",
|
|
176
|
+
accessibilityLabel: label ?? 'Date picker',
|
|
177
|
+
accessibilityState: {
|
|
178
|
+
disabled: Boolean(disabled)
|
|
179
|
+
},
|
|
180
|
+
children: [resolvedLeft ? /*#__PURE__*/_jsx(Pressable, {
|
|
181
|
+
onPress: onLeftIconPress,
|
|
182
|
+
disabled: !onLeftIconPress,
|
|
183
|
+
style: [inputStyles.iconSlot, inputStyles.iconSlotLeft],
|
|
184
|
+
hitSlop: 8,
|
|
185
|
+
children: renderFieldFlowIcon(resolvedLeft, iconColor, iconSize)
|
|
186
|
+
}) : null, /*#__PURE__*/_jsx(Text, {
|
|
187
|
+
style: [inputStyles.input, {
|
|
188
|
+
paddingVertical: theme.spacing.paddingVertical
|
|
189
|
+
}, !display && {
|
|
190
|
+
color: theme.colors.placeholder
|
|
191
|
+
}],
|
|
192
|
+
numberOfLines: 1,
|
|
193
|
+
children: display || placeholder
|
|
194
|
+
}), clearable && value && !disabled ? /*#__PURE__*/_jsx(Pressable, {
|
|
195
|
+
onPress: () => onChange(''),
|
|
196
|
+
style: [inputStyles.iconSlot, inputStyles.iconSlotRight],
|
|
197
|
+
hitSlop: 8,
|
|
198
|
+
accessibilityRole: "button",
|
|
199
|
+
accessibilityLabel: "Clear",
|
|
200
|
+
children: renderFieldFlowIcon('clear', iconColor, iconSize)
|
|
201
|
+
}) : resolvedRight ? /*#__PURE__*/_jsx(Pressable, {
|
|
202
|
+
onPress: onRightIconPress ?? openPicker,
|
|
203
|
+
style: [inputStyles.iconSlot, inputStyles.iconSlotRight],
|
|
204
|
+
hitSlop: 8,
|
|
205
|
+
children: renderFieldFlowIcon(resolvedRight, iconColor, iconSize)
|
|
206
|
+
}) : null]
|
|
207
|
+
}), (helperText || errorText || successText) && /*#__PURE__*/_jsx(View, {
|
|
208
|
+
style: inputStyles.footerRow,
|
|
209
|
+
children: errorText ? /*#__PURE__*/_jsx(Text, {
|
|
210
|
+
style: [inputStyles.errorText, helperStyle],
|
|
211
|
+
children: errorText
|
|
212
|
+
}) : successText ? /*#__PURE__*/_jsx(Text, {
|
|
213
|
+
style: [inputStyles.successText, helperStyle],
|
|
214
|
+
children: successText
|
|
215
|
+
}) : helperText ? /*#__PURE__*/_jsx(Text, {
|
|
216
|
+
style: [inputStyles.helperText, helperStyle],
|
|
217
|
+
children: helperText
|
|
218
|
+
}) : null
|
|
219
|
+
})]
|
|
220
|
+
});
|
|
221
|
+
const showDate = mode === 'date' || mode === 'datetime';
|
|
222
|
+
const showTime = mode === 'time' || mode === 'datetime';
|
|
223
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
224
|
+
children: [trigger, /*#__PURE__*/_jsx(Modal, {
|
|
225
|
+
visible: open,
|
|
226
|
+
transparent: true,
|
|
227
|
+
animationType: "fade",
|
|
228
|
+
onRequestClose: () => setOpen(false),
|
|
229
|
+
children: /*#__PURE__*/_jsx(Pressable, {
|
|
230
|
+
style: styles.backdrop,
|
|
231
|
+
onPress: () => setOpen(false),
|
|
232
|
+
children: /*#__PURE__*/_jsxs(Pressable, {
|
|
233
|
+
style: [styles.sheet, modalStyle],
|
|
234
|
+
onPress: e => e.stopPropagation(),
|
|
235
|
+
children: [/*#__PURE__*/_jsxs(View, {
|
|
236
|
+
style: styles.header,
|
|
237
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
238
|
+
style: styles.title,
|
|
239
|
+
children: title ?? label ?? 'Select'
|
|
240
|
+
}), /*#__PURE__*/_jsx(Pressable, {
|
|
241
|
+
onPress: () => setOpen(false),
|
|
242
|
+
hitSlop: 8,
|
|
243
|
+
children: renderFieldFlowIcon('clear', theme.colors.icon, 18)
|
|
244
|
+
})]
|
|
245
|
+
}), showDate ? /*#__PURE__*/_jsxs(View, {
|
|
246
|
+
children: [/*#__PURE__*/_jsxs(View, {
|
|
247
|
+
style: styles.monthRow,
|
|
248
|
+
children: [/*#__PURE__*/_jsx(Pressable, {
|
|
249
|
+
onPress: () => {
|
|
250
|
+
if (viewMonth === 0) {
|
|
251
|
+
setViewMonth(11);
|
|
252
|
+
setViewYear(y => y - 1);
|
|
253
|
+
} else setViewMonth(m => m - 1);
|
|
254
|
+
},
|
|
255
|
+
hitSlop: 8,
|
|
256
|
+
children: renderFieldFlowIcon('chevronLeft', theme.colors.icon, 20)
|
|
257
|
+
}), /*#__PURE__*/_jsxs(Text, {
|
|
258
|
+
style: styles.monthLabel,
|
|
259
|
+
children: [MONTHS[viewMonth], " ", viewYear]
|
|
260
|
+
}), /*#__PURE__*/_jsx(Pressable, {
|
|
261
|
+
onPress: () => {
|
|
262
|
+
if (viewMonth === 11) {
|
|
263
|
+
setViewMonth(0);
|
|
264
|
+
setViewYear(y => y + 1);
|
|
265
|
+
} else setViewMonth(m => m + 1);
|
|
266
|
+
},
|
|
267
|
+
hitSlop: 8,
|
|
268
|
+
children: renderFieldFlowIcon('chevronRight', theme.colors.icon, 20)
|
|
269
|
+
})]
|
|
270
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
271
|
+
style: styles.weekRow,
|
|
272
|
+
children: WEEKDAYS.map(d => /*#__PURE__*/_jsx(Text, {
|
|
273
|
+
style: styles.weekday,
|
|
274
|
+
children: d
|
|
275
|
+
}, d))
|
|
276
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
277
|
+
style: styles.grid,
|
|
278
|
+
children: calendarCells.map((day, idx) => {
|
|
279
|
+
if (day == null) return /*#__PURE__*/_jsx(View, {
|
|
280
|
+
style: styles.dayCell
|
|
281
|
+
}, `e-${idx}`);
|
|
282
|
+
const selected = draft.getFullYear() === viewYear && draft.getMonth() === viewMonth && draft.getDate() === day;
|
|
283
|
+
const dayDisabled = isDayDisabled(day);
|
|
284
|
+
return /*#__PURE__*/_jsx(Pressable, {
|
|
285
|
+
style: [styles.dayCell, selected && styles.daySelected, dayDisabled && styles.dayDisabled],
|
|
286
|
+
disabled: dayDisabled,
|
|
287
|
+
onPress: () => {
|
|
288
|
+
const next = new Date(draft);
|
|
289
|
+
next.setFullYear(viewYear, viewMonth, day);
|
|
290
|
+
setDraft(next);
|
|
291
|
+
},
|
|
292
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
293
|
+
style: [styles.dayText, selected && styles.dayTextSelected],
|
|
294
|
+
children: day
|
|
295
|
+
})
|
|
296
|
+
}, `${viewYear}-${viewMonth}-${day}`);
|
|
297
|
+
})
|
|
298
|
+
})]
|
|
299
|
+
}) : null, showTime ? /*#__PURE__*/_jsxs(View, {
|
|
300
|
+
style: styles.timeRow,
|
|
301
|
+
children: [/*#__PURE__*/_jsx(ScrollView, {
|
|
302
|
+
style: styles.timeCol,
|
|
303
|
+
showsVerticalScrollIndicator: false,
|
|
304
|
+
children: hours.map(h => {
|
|
305
|
+
const currentH = draft.getHours();
|
|
306
|
+
const selected = hourCycle === 12 ? (currentH % 12 || 12) === h : currentH === h;
|
|
307
|
+
return /*#__PURE__*/_jsx(Pressable, {
|
|
308
|
+
style: [styles.timeItem, selected && styles.timeItemSelected],
|
|
309
|
+
onPress: () => {
|
|
310
|
+
const next = new Date(draft);
|
|
311
|
+
if (hourCycle === 12) {
|
|
312
|
+
const isPM = draft.getHours() >= 12;
|
|
313
|
+
let hour24 = h % 12;
|
|
314
|
+
if (isPM) hour24 += 12;
|
|
315
|
+
next.setHours(hour24);
|
|
316
|
+
} else {
|
|
317
|
+
next.setHours(h);
|
|
318
|
+
}
|
|
319
|
+
setDraft(next);
|
|
320
|
+
},
|
|
321
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
322
|
+
style: [styles.timeText, selected && styles.timeTextSelected],
|
|
323
|
+
children: pad(h)
|
|
324
|
+
})
|
|
325
|
+
}, `h-${h}`);
|
|
326
|
+
})
|
|
327
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
328
|
+
style: styles.timeColon,
|
|
329
|
+
children: ":"
|
|
330
|
+
}), /*#__PURE__*/_jsx(ScrollView, {
|
|
331
|
+
style: styles.timeCol,
|
|
332
|
+
showsVerticalScrollIndicator: false,
|
|
333
|
+
children: minutes.map(m => {
|
|
334
|
+
const selected = draft.getMinutes() === m;
|
|
335
|
+
return /*#__PURE__*/_jsx(Pressable, {
|
|
336
|
+
style: [styles.timeItem, selected && styles.timeItemSelected],
|
|
337
|
+
onPress: () => {
|
|
338
|
+
const next = new Date(draft);
|
|
339
|
+
next.setMinutes(m);
|
|
340
|
+
setDraft(next);
|
|
341
|
+
},
|
|
342
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
343
|
+
style: [styles.timeText, selected && styles.timeTextSelected],
|
|
344
|
+
children: pad(m)
|
|
345
|
+
})
|
|
346
|
+
}, `m-${m}`);
|
|
347
|
+
})
|
|
348
|
+
}), hourCycle === 12 ? /*#__PURE__*/_jsx(View, {
|
|
349
|
+
style: styles.ampmCol,
|
|
350
|
+
children: ['AM', 'PM'].map(period => {
|
|
351
|
+
const isPM = draft.getHours() >= 12;
|
|
352
|
+
const selected = period === 'PM' ? isPM : !isPM;
|
|
353
|
+
return /*#__PURE__*/_jsx(Pressable, {
|
|
354
|
+
style: [styles.timeItem, selected && styles.timeItemSelected],
|
|
355
|
+
onPress: () => {
|
|
356
|
+
const next = new Date(draft);
|
|
357
|
+
const h = next.getHours();
|
|
358
|
+
if (period === 'AM' && h >= 12) next.setHours(h - 12);
|
|
359
|
+
if (period === 'PM' && h < 12) next.setHours(h + 12);
|
|
360
|
+
setDraft(next);
|
|
361
|
+
},
|
|
362
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
363
|
+
style: [styles.timeText, selected && styles.timeTextSelected],
|
|
364
|
+
children: period
|
|
365
|
+
})
|
|
366
|
+
}, period);
|
|
367
|
+
})
|
|
368
|
+
}) : null]
|
|
369
|
+
}) : null, /*#__PURE__*/_jsxs(View, {
|
|
370
|
+
style: styles.actions,
|
|
371
|
+
children: [/*#__PURE__*/_jsx(Pressable, {
|
|
372
|
+
onPress: () => setOpen(false),
|
|
373
|
+
style: styles.btnGhost,
|
|
374
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
375
|
+
style: styles.btnGhostText,
|
|
376
|
+
children: cancelLabel
|
|
377
|
+
})
|
|
378
|
+
}), /*#__PURE__*/_jsx(Pressable, {
|
|
379
|
+
onPress: confirm,
|
|
380
|
+
style: styles.btnPrimary,
|
|
381
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
382
|
+
style: styles.btnPrimaryText,
|
|
383
|
+
children: confirmLabel
|
|
384
|
+
})
|
|
385
|
+
})]
|
|
386
|
+
})]
|
|
387
|
+
})
|
|
388
|
+
})
|
|
389
|
+
})]
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
function createModalStyles(theme) {
|
|
393
|
+
return StyleSheet.create({
|
|
394
|
+
backdrop: {
|
|
395
|
+
flex: 1,
|
|
396
|
+
backgroundColor: 'rgba(0,0,0,0.45)',
|
|
397
|
+
justifyContent: 'center',
|
|
398
|
+
padding: 20
|
|
399
|
+
},
|
|
400
|
+
sheet: {
|
|
401
|
+
backgroundColor: theme.colors.background,
|
|
402
|
+
borderRadius: theme.spacing.borderRadius + 4,
|
|
403
|
+
padding: 16,
|
|
404
|
+
maxHeight: '85%'
|
|
405
|
+
},
|
|
406
|
+
header: {
|
|
407
|
+
flexDirection: 'row',
|
|
408
|
+
alignItems: 'center',
|
|
409
|
+
justifyContent: 'space-between',
|
|
410
|
+
marginBottom: 12
|
|
411
|
+
},
|
|
412
|
+
title: {
|
|
413
|
+
fontSize: theme.typography.fontSize + 2,
|
|
414
|
+
fontWeight: '600',
|
|
415
|
+
color: theme.colors.text,
|
|
416
|
+
fontFamily: theme.typography.fontFamily
|
|
417
|
+
},
|
|
418
|
+
monthRow: {
|
|
419
|
+
flexDirection: 'row',
|
|
420
|
+
alignItems: 'center',
|
|
421
|
+
justifyContent: 'space-between',
|
|
422
|
+
marginBottom: 10
|
|
423
|
+
},
|
|
424
|
+
monthLabel: {
|
|
425
|
+
fontSize: theme.typography.fontSize,
|
|
426
|
+
fontWeight: '600',
|
|
427
|
+
color: theme.colors.text
|
|
428
|
+
},
|
|
429
|
+
weekRow: {
|
|
430
|
+
flexDirection: 'row',
|
|
431
|
+
marginBottom: 4
|
|
432
|
+
},
|
|
433
|
+
weekday: {
|
|
434
|
+
flex: 1,
|
|
435
|
+
textAlign: 'center',
|
|
436
|
+
fontSize: theme.typography.helperFontSize,
|
|
437
|
+
color: theme.colors.placeholder,
|
|
438
|
+
fontWeight: '500'
|
|
439
|
+
},
|
|
440
|
+
grid: {
|
|
441
|
+
flexDirection: 'row',
|
|
442
|
+
flexWrap: 'wrap'
|
|
443
|
+
},
|
|
444
|
+
dayCell: {
|
|
445
|
+
width: `${100 / 7}%`,
|
|
446
|
+
aspectRatio: 1,
|
|
447
|
+
alignItems: 'center',
|
|
448
|
+
justifyContent: 'center',
|
|
449
|
+
borderRadius: theme.spacing.borderRadius
|
|
450
|
+
},
|
|
451
|
+
daySelected: {
|
|
452
|
+
backgroundColor: theme.colors.borderFocused
|
|
453
|
+
},
|
|
454
|
+
dayDisabled: {
|
|
455
|
+
opacity: 0.3
|
|
456
|
+
},
|
|
457
|
+
dayText: {
|
|
458
|
+
fontSize: theme.typography.fontSize,
|
|
459
|
+
color: theme.colors.text
|
|
460
|
+
},
|
|
461
|
+
dayTextSelected: {
|
|
462
|
+
color: '#FFFFFF',
|
|
463
|
+
fontWeight: '600'
|
|
464
|
+
},
|
|
465
|
+
timeRow: {
|
|
466
|
+
flexDirection: 'row',
|
|
467
|
+
alignItems: 'center',
|
|
468
|
+
justifyContent: 'center',
|
|
469
|
+
marginTop: 12,
|
|
470
|
+
maxHeight: 160
|
|
471
|
+
},
|
|
472
|
+
timeCol: {
|
|
473
|
+
maxHeight: 160,
|
|
474
|
+
width: 64
|
|
475
|
+
},
|
|
476
|
+
ampmCol: {
|
|
477
|
+
marginLeft: 8,
|
|
478
|
+
justifyContent: 'center',
|
|
479
|
+
gap: 8
|
|
480
|
+
},
|
|
481
|
+
timeColon: {
|
|
482
|
+
fontSize: 22,
|
|
483
|
+
fontWeight: '700',
|
|
484
|
+
color: theme.colors.text,
|
|
485
|
+
marginHorizontal: 6
|
|
486
|
+
},
|
|
487
|
+
timeItem: {
|
|
488
|
+
paddingVertical: 8,
|
|
489
|
+
alignItems: 'center',
|
|
490
|
+
borderRadius: theme.spacing.borderRadius
|
|
491
|
+
},
|
|
492
|
+
timeItemSelected: {
|
|
493
|
+
backgroundColor: theme.colors.borderFocused
|
|
494
|
+
},
|
|
495
|
+
timeText: {
|
|
496
|
+
fontSize: theme.typography.fontSize,
|
|
497
|
+
color: theme.colors.text
|
|
498
|
+
},
|
|
499
|
+
timeTextSelected: {
|
|
500
|
+
color: '#FFFFFF',
|
|
501
|
+
fontWeight: '600'
|
|
502
|
+
},
|
|
503
|
+
actions: {
|
|
504
|
+
flexDirection: 'row',
|
|
505
|
+
justifyContent: 'flex-end',
|
|
506
|
+
gap: 12,
|
|
507
|
+
marginTop: 16
|
|
508
|
+
},
|
|
509
|
+
btnGhost: {
|
|
510
|
+
paddingHorizontal: 14,
|
|
511
|
+
paddingVertical: 10
|
|
512
|
+
},
|
|
513
|
+
btnGhostText: {
|
|
514
|
+
color: theme.colors.label,
|
|
515
|
+
fontSize: theme.typography.fontSize,
|
|
516
|
+
fontWeight: '500'
|
|
517
|
+
},
|
|
518
|
+
btnPrimary: {
|
|
519
|
+
paddingHorizontal: 16,
|
|
520
|
+
paddingVertical: 10,
|
|
521
|
+
backgroundColor: theme.colors.borderFocused,
|
|
522
|
+
borderRadius: theme.spacing.borderRadius
|
|
523
|
+
},
|
|
524
|
+
btnPrimaryText: {
|
|
525
|
+
color: '#FFFFFF',
|
|
526
|
+
fontSize: theme.typography.fontSize,
|
|
527
|
+
fontWeight: '600'
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
//# sourceMappingURL=FieldFlowDateTimePicker.js.map
|