cpk-ui 0.8.0-beta.6 → 0.8.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 +18 -14
- package/components/uis/Button/Button.d.ts.map +1 -1
- package/components/uis/Button/Button.js +3 -10
- package/components/uis/Calendar/Calendar.d.ts.map +1 -1
- package/components/uis/Calendar/Calendar.js +48 -7
- package/components/uis/Calendar/CalendarDay.d.ts.map +1 -1
- package/components/uis/Calendar/CalendarDay.js +47 -19
- package/components/uis/Calendar/types.d.ts +7 -0
- package/components/uis/Calendar/types.d.ts.map +1 -1
- package/components/uis/DonutChart/DonutChart.d.ts +24 -0
- package/components/uis/DonutChart/DonutChart.d.ts.map +1 -0
- package/components/uis/DonutChart/DonutChart.js +73 -0
- package/components/uis/LineChart/LineChart.d.ts +37 -0
- package/components/uis/LineChart/LineChart.d.ts.map +1 -0
- package/components/uis/LineChart/LineChart.js +111 -0
- package/components/uis/RadioGroup/RadioButton.d.ts +3 -1
- package/components/uis/RadioGroup/RadioButton.d.ts.map +1 -1
- package/components/uis/RadioGroup/RadioButton.js +7 -29
- package/components/uis/SelectionFeedback/SelectionFeedback.d.ts +21 -0
- package/components/uis/SelectionFeedback/SelectionFeedback.d.ts.map +1 -0
- package/components/uis/SelectionFeedback/SelectionFeedback.js +47 -0
- package/components/uis/TimePicker/TimePicker.d.ts +61 -0
- package/components/uis/TimePicker/TimePicker.d.ts.map +1 -0
- package/components/uis/TimePicker/TimePicker.js +222 -0
- package/components/uis/TimePicker/timeFormat.d.ts +41 -0
- package/components/uis/TimePicker/timeFormat.d.ts.map +1 -0
- package/components/uis/TimePicker/timeFormat.js +176 -0
- package/index.d.ts +4 -0
- package/index.d.ts.map +1 -1
- package/index.js +4 -0
- package/package.json +2 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useState } from 'react';
|
|
3
|
+
import { Pressable, StyleSheet, View, } from 'react-native';
|
|
4
|
+
import Svg, { Circle, G, Line, Path, Rect, Text as SvgText, } from 'react-native-svg';
|
|
5
|
+
import { useTheme } from '../../../providers/ThemeProvider';
|
|
6
|
+
const DEFAULT_WIDTH = 320;
|
|
7
|
+
const REGULAR_HEIGHT = 220;
|
|
8
|
+
const COMPACT_HEIGHT = 160;
|
|
9
|
+
const HORIZONTAL_INSET = 20;
|
|
10
|
+
const TOP_INSET = 30;
|
|
11
|
+
const BOTTOM_INSET = 30;
|
|
12
|
+
function safeNumber(value) {
|
|
13
|
+
return Number.isFinite(value) ? value : 0;
|
|
14
|
+
}
|
|
15
|
+
// Each target reaches halfway to its neighbours, so a tap selects the
|
|
16
|
+
// nearest point rather than an equal-width column.
|
|
17
|
+
function targetSlot(points, index, width) {
|
|
18
|
+
const point = points[index];
|
|
19
|
+
const previous = points[index - 1];
|
|
20
|
+
const next = points[index + 1];
|
|
21
|
+
if (!point)
|
|
22
|
+
return { left: 0, width: 0 };
|
|
23
|
+
const left = previous ? (previous.x + point.x) / 2 : 0;
|
|
24
|
+
const right = next ? (point.x + next.x) / 2 : width;
|
|
25
|
+
return { left, width: Math.max(0, right - left) };
|
|
26
|
+
}
|
|
27
|
+
function makePath(points) {
|
|
28
|
+
return points
|
|
29
|
+
.map((point, index) => `${index === 0 ? 'M' : 'L'} ${point.x} ${point.y}`)
|
|
30
|
+
.join(' ');
|
|
31
|
+
}
|
|
32
|
+
export function LineChart({ data, selectedKey, onSelect, formatValue = String, palette, variant = 'regular', showGrid = true, emptyLabel = 'No data', accessibilityLabel, style, styles, testID = 'line-chart', }) {
|
|
33
|
+
const { theme } = useTheme();
|
|
34
|
+
const defaultHeight = variant === 'compact' ? COMPACT_HEIGHT : REGULAR_HEIGHT;
|
|
35
|
+
const [frame, setFrame] = useState({
|
|
36
|
+
height: defaultHeight,
|
|
37
|
+
width: DEFAULT_WIDTH,
|
|
38
|
+
});
|
|
39
|
+
const colors = {
|
|
40
|
+
line: palette?.line ?? theme.role.success,
|
|
41
|
+
point: palette?.point ?? theme.bg.basic,
|
|
42
|
+
selectedPoint: palette?.selectedPoint ?? theme.role.success,
|
|
43
|
+
grid: palette?.grid ?? theme.role.border,
|
|
44
|
+
label: palette?.label ?? theme.text.label,
|
|
45
|
+
tooltipBackground: palette?.tooltipBackground ?? theme.role.primary,
|
|
46
|
+
tooltipText: palette?.tooltipText ?? theme.text.contrast,
|
|
47
|
+
};
|
|
48
|
+
const points = useMemo(() => {
|
|
49
|
+
if (data.length === 0)
|
|
50
|
+
return [];
|
|
51
|
+
const values = data.map((datum) => safeNumber(datum.value));
|
|
52
|
+
const minimum = Math.min(0, ...values);
|
|
53
|
+
const maximum = Math.max(0, ...values);
|
|
54
|
+
// An all-zero series sits on the baseline, not on the top edge.
|
|
55
|
+
const top = maximum === minimum ? minimum + 1 : maximum;
|
|
56
|
+
const range = top - minimum;
|
|
57
|
+
const innerWidth = Math.max(1, frame.width - HORIZONTAL_INSET * 2);
|
|
58
|
+
const innerHeight = Math.max(1, frame.height - TOP_INSET - BOTTOM_INSET);
|
|
59
|
+
return data.map((datum, index) => ({
|
|
60
|
+
...datum,
|
|
61
|
+
index,
|
|
62
|
+
x: HORIZONTAL_INSET +
|
|
63
|
+
(data.length === 1
|
|
64
|
+
? innerWidth / 2
|
|
65
|
+
: (innerWidth * index) / (data.length - 1)),
|
|
66
|
+
y: TOP_INSET + ((top - safeNumber(datum.value)) / range) * innerHeight,
|
|
67
|
+
}));
|
|
68
|
+
}, [data, frame.height, frame.width]);
|
|
69
|
+
const selectedPoint = points.find((point) => point.key === selectedKey);
|
|
70
|
+
// Points are interactive only with `onSelect`; a read-only chart is one
|
|
71
|
+
// image, and interactive point buttons must not nest inside an image.
|
|
72
|
+
const interactive = onSelect !== undefined;
|
|
73
|
+
const summary = accessibilityLabel ??
|
|
74
|
+
(data.length === 0
|
|
75
|
+
? emptyLabel
|
|
76
|
+
: data
|
|
77
|
+
.map((datum) => `${datum.label}: ${formatValue(datum.value)}`)
|
|
78
|
+
.join(', '));
|
|
79
|
+
const onLayout = ({ nativeEvent }) => {
|
|
80
|
+
const { height, width } = nativeEvent.layout;
|
|
81
|
+
if (height > 0 && width > 0)
|
|
82
|
+
setFrame({ height, width });
|
|
83
|
+
};
|
|
84
|
+
return (_jsxs(View, { accessibilityLabel: summary, accessible: !interactive, onLayout: onLayout, role: interactive ? 'group' : 'img', style: [
|
|
85
|
+
componentStyles.container,
|
|
86
|
+
{ height: defaultHeight },
|
|
87
|
+
styles?.container,
|
|
88
|
+
style,
|
|
89
|
+
], testID: testID, children: [_jsx(View, { style: [StyleSheet.absoluteFill, styles?.chart], children: _jsxs(Svg, { height: "100%", width: "100%", children: [showGrid
|
|
90
|
+
? [0, 1, 2, 3].map((index) => {
|
|
91
|
+
const y = TOP_INSET +
|
|
92
|
+
((frame.height - TOP_INSET - BOTTOM_INSET) * index) / 3;
|
|
93
|
+
return (_jsx(Line, { stroke: colors.grid, strokeDasharray: "3 4", strokeWidth: StyleSheet.hairlineWidth, x1: HORIZONTAL_INSET, x2: frame.width - HORIZONTAL_INSET, y1: y, y2: y }, `grid-${index}`));
|
|
94
|
+
})
|
|
95
|
+
: null, points.length > 1 ? (_jsx(Path, { d: makePath(points), fill: "none", stroke: colors.line, strokeLinejoin: "round", strokeWidth: 2.5 })) : null, points.map((point) => {
|
|
96
|
+
const selected = point.key === selectedKey;
|
|
97
|
+
return (_jsxs(G, { children: [_jsx(Circle, { cx: point.x, cy: point.y, fill: selected ? colors.selectedPoint : colors.point, r: selected ? 5 : 3.5, stroke: colors.line, strokeWidth: 2 }), _jsx(SvgText, { fill: colors.label, fontSize: 10, textAnchor: "middle", x: point.x, y: frame.height - 8, children: point.label })] }, point.key));
|
|
98
|
+
}), selectedPoint ? (_jsxs(G, { children: [_jsx(Rect, { fill: colors.tooltipBackground, height: 26, rx: 6, width: 88, x: Math.min(Math.max(selectedPoint.x - 44, 4), frame.width - 92), y: Math.max(2, selectedPoint.y - 36) }), _jsx(SvgText, { fill: colors.tooltipText, fontSize: 11, fontWeight: "600", textAnchor: "middle", x: Math.min(Math.max(selectedPoint.x, 48), frame.width - 48), y: Math.max(19, selectedPoint.y - 19), children: formatValue(selectedPoint.value) })] })) : null, points.length === 0 ? (_jsx(SvgText, { fill: colors.label, fontSize: 13, textAnchor: "middle", testID: `${testID}-empty`, x: frame.width / 2, y: frame.height / 2, children: emptyLabel })) : null] }) }), (interactive ? points : []).map((point, index) => (_jsx(Pressable, { accessibilityLabel: point.accessibilityLabel ??
|
|
99
|
+
`${point.label}: ${formatValue(point.value)}`, accessibilityRole: "button", accessibilityState: { selected: point.key === selectedKey }, onPress: () => {
|
|
100
|
+
const datum = data[point.index];
|
|
101
|
+
if (datum)
|
|
102
|
+
onSelect?.(datum, point.index);
|
|
103
|
+
}, style: [
|
|
104
|
+
componentStyles.target,
|
|
105
|
+
targetSlot(points, index, frame.width),
|
|
106
|
+
], testID: `${testID}-point-${point.index}` }, `target-${point.key}`)))] }));
|
|
107
|
+
}
|
|
108
|
+
const componentStyles = StyleSheet.create({
|
|
109
|
+
container: { alignSelf: 'stretch', minWidth: 1 },
|
|
110
|
+
target: { bottom: 0, position: 'absolute', top: 0 },
|
|
111
|
+
});
|
|
@@ -19,11 +19,13 @@ export type RadioButtonProps = {
|
|
|
19
19
|
size?: RadioButtonSizeType;
|
|
20
20
|
disabled?: boolean;
|
|
21
21
|
selected?: boolean;
|
|
22
|
+
/** Confirm a newly selected mark; honours the native reduced-motion setting. */
|
|
23
|
+
selectionAnimation?: boolean;
|
|
22
24
|
endElement?: ReactElement;
|
|
23
25
|
startElement?: ReactElement;
|
|
24
26
|
accessibilityLabel?: string;
|
|
25
27
|
};
|
|
26
|
-
export default function RadioButton({ testID, style, styles, endElement, startElement, type, size, disabled, selected, onPress, label, labelPosition, accessibilityLabel, }: RadioButtonProps): ReactElement;
|
|
28
|
+
export default function RadioButton({ testID, style, styles, endElement, startElement, type, size, disabled, selected, selectionAnimation, onPress, label, labelPosition, accessibilityLabel, }: RadioButtonProps): ReactElement;
|
|
27
29
|
declare const MemoizedRadioButton: React.MemoExoticComponent<typeof RadioButton>;
|
|
28
30
|
export { MemoizedRadioButton as RadioButton };
|
|
29
31
|
//# sourceMappingURL=RadioButton.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioButton.d.ts","sourceRoot":"","sources":["../../../../src/components/uis/RadioGroup/RadioButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"RadioButton.d.ts","sourceRoot":"","sources":["../../../../src/components/uis/RadioGroup/RadioButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiC,KAAK,YAAY,EAAC,MAAM,OAAO,CAAC;AAC/E,OAAO,KAAK,EAGV,SAAS,EACT,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AAUtB,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAGlD,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAExE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,aAAa,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACjC,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,IAAI,CAAC,EAAE,mBAAmB,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gFAAgF;IAChF,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAOF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,MAAM,EACN,KAAK,EACL,MAAM,EACN,UAAU,EACV,YAAY,EACZ,IAAgB,EAChB,IAAe,EACf,QAAgB,EAChB,QAAQ,EACR,kBAAyB,EACzB,OAAO,EACP,KAAK,EACL,aAAuB,EACvB,kBAAkB,GACnB,EAAE,gBAAgB,GAAG,YAAY,CA0GjC;AAGD,QAAA,MAAM,mBAAmB,+CAA0B,CAAC;AACpD,OAAO,EAAC,mBAAmB,IAAI,WAAW,EAAC,CAAC"}
|
|
@@ -1,40 +1,19 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import React, { useCallback,
|
|
3
|
-
import {
|
|
2
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
4
|
import { styled, css } from 'kstyled';
|
|
5
5
|
import { ColoredText, RadioButtonWrapper, RadioWrapper, } from '../Styled/StyledComponents';
|
|
6
|
+
import { SelectionFeedback } from '../SelectionFeedback/SelectionFeedback';
|
|
6
7
|
const Container = styled.TouchableOpacity `
|
|
7
8
|
flex-direction: row;
|
|
8
9
|
align-items: center;
|
|
9
10
|
`;
|
|
10
|
-
|
|
11
|
-
export default function RadioButton({ testID, style, styles, endElement, startElement, type = 'primary', size = 'medium', disabled = false, selected, onPress, label, labelPosition = 'right', accessibilityLabel, }) {
|
|
11
|
+
export default function RadioButton({ testID, style, styles, endElement, startElement, type = 'primary', size = 'medium', disabled = false, selected, selectionAnimation = true, onPress, label, labelPosition = 'right', accessibilityLabel, }) {
|
|
12
12
|
const [innerLayout, setInnerLayout] = useState();
|
|
13
|
-
const fadeAnim = useRef(new Animated.Value(selected ? 1 : 0)).current;
|
|
14
|
-
const scaleAnim = useRef(new Animated.Value(selected ? 1 : 0)).current;
|
|
15
13
|
// Memoize layout handler
|
|
16
14
|
const handleLayout = useCallback((e) => {
|
|
17
15
|
setInnerLayout(e.nativeEvent.layout);
|
|
18
16
|
}, []);
|
|
19
|
-
// Memoize animation config
|
|
20
|
-
const animationConfig = useMemo(() => ({
|
|
21
|
-
useNativeDriver: Platform.select({
|
|
22
|
-
web: false,
|
|
23
|
-
default: true,
|
|
24
|
-
}),
|
|
25
|
-
}), []);
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
Animated.parallel([
|
|
28
|
-
Animated.spring(fadeAnim, {
|
|
29
|
-
toValue: !selected ? 0 : 1,
|
|
30
|
-
...animationConfig,
|
|
31
|
-
}),
|
|
32
|
-
Animated.spring(scaleAnim, {
|
|
33
|
-
toValue: !selected ? 0 : 1,
|
|
34
|
-
...animationConfig,
|
|
35
|
-
}),
|
|
36
|
-
]).start();
|
|
37
|
-
}, [fadeAnim, scaleAnim, selected, animationConfig]);
|
|
38
17
|
// Memoize container styles
|
|
39
18
|
const containerStyles = useMemo(() => [
|
|
40
19
|
css `
|
|
@@ -58,11 +37,10 @@ export default function RadioButton({ testID, style, styles, endElement, startEl
|
|
|
58
37
|
{
|
|
59
38
|
margin: innerLayout ? 2 : 0,
|
|
60
39
|
borderRadius: innerLayout ? innerLayout.width / 2 : 0,
|
|
61
|
-
opacity:
|
|
62
|
-
transform: [{ scale: scaleAnim }],
|
|
40
|
+
opacity: selected ? 1 : 0,
|
|
63
41
|
},
|
|
64
|
-
], [innerLayout, styles?.circle,
|
|
65
|
-
return (_jsx(Container, { accessibilityLabel: accessibilityLabel ?? label, accessibilityRole: "radio", accessibilityState: { checked: !!selected, disabled }, "aria-checked": !!selected, "aria-disabled": disabled, activeOpacity: 0.9, disabled: disabled, onPress: onPress, style: style, testID: testID, children: _jsxs(View, { style: containerStyles, children: [startElement, label && labelPosition === 'left' ? (_jsx(ColoredText, { "$disabled": !!disabled, "$selected": !!selected, "$size": size, style: styles?.label, "$type": type, children: label })) : null, _jsx(RadioButtonWrapper, { "$disabled": disabled, "$selected": !!selected, "$size": size, style: styles?.circleWrapper, "$type": type, children: _jsx(
|
|
42
|
+
], [innerLayout, styles?.circle, selected]);
|
|
43
|
+
return (_jsx(Container, { accessibilityLabel: accessibilityLabel ?? label, accessibilityRole: "radio", accessibilityState: { checked: !!selected, disabled }, "aria-checked": !!selected, "aria-disabled": disabled, activeOpacity: 0.9, disabled: disabled, onPress: onPress, style: style, testID: testID, children: _jsxs(View, { style: containerStyles, children: [startElement, label && labelPosition === 'left' ? (_jsx(ColoredText, { "$disabled": !!disabled, "$selected": !!selected, "$size": size, style: styles?.label, "$type": type, children: label })) : null, _jsx(SelectionFeedback, { active: !!selected && !disabled, selection: selected ? 1 : 0, reducedMotion: selectionAnimation ? undefined : true, variant: "pop", children: _jsx(RadioButtonWrapper, { "$disabled": disabled, "$selected": !!selected, "$size": size, style: styles?.circleWrapper, "$type": type, children: _jsx(RadioWrapper, { "$disabled": !!disabled, onLayout: handleLayout, "$selected": !!selected, style: animatedStyles, testID: `circle-${testID}`, "$type": type }) }) }), label && labelPosition === 'right' ? (_jsx(ColoredText, { "$disabled": !!disabled, "$selected": !!selected, "$size": size, style: styles?.label, "$type": type, children: label })) : null, endElement] }) }));
|
|
66
44
|
}
|
|
67
45
|
// Export memoized component for better performance
|
|
68
46
|
const MemoizedRadioButton = React.memo(RadioButton);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ViewProps } from 'react-native';
|
|
3
|
+
/** Ink must fit its stable target even at the top of the confirmation spring. */
|
|
4
|
+
export declare const SELECTION_FEEDBACK_PEAK_SCALE = 1.12;
|
|
5
|
+
export interface SelectionFeedbackProps extends ViewProps {
|
|
6
|
+
/** Committed selection identity. Initial rendering never animates. */
|
|
7
|
+
selection?: string | number;
|
|
8
|
+
/** Pop starts a little smaller before rising; pulse confirms an existing mark. */
|
|
9
|
+
variant?: 'pulse' | 'pop';
|
|
10
|
+
/** For a group, only the newly selected item's contents should pulse. */
|
|
11
|
+
active?: boolean;
|
|
12
|
+
/** `true` keeps the item still. `false` cannot override the system setting. */
|
|
13
|
+
reducedMotion?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface SelectionFeedbackHandle {
|
|
16
|
+
/** Play after a user action has committed; never call during render. */
|
|
17
|
+
play: () => void;
|
|
18
|
+
}
|
|
19
|
+
/** Brief confirmation for a changed selection, inside a stable touch target. */
|
|
20
|
+
export declare const SelectionFeedback: React.ForwardRefExoticComponent<SelectionFeedbackProps & React.RefAttributes<SelectionFeedbackHandle>>;
|
|
21
|
+
//# sourceMappingURL=SelectionFeedback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectionFeedback.d.ts","sourceRoot":"","sources":["../../../../src/components/uis/SelectionFeedback/SelectionFeedback.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAa5C,iFAAiF;AACjF,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAElD,MAAM,WAAW,sBAAuB,SAAQ,SAAS;IACvD,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,kFAAkF;IAClF,OAAO,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC1B,yEAAyE;IACzE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,+EAA+E;IAC/E,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,uBAAuB;IACtC,wEAAwE;IACxE,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,gFAAgF;AAChF,eAAO,MAAM,iBAAiB,wGA8D5B,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, } from 'react';
|
|
3
|
+
import Animated, { cancelAnimation, Easing, ReduceMotion, useAnimatedStyle, useReducedMotion, useSharedValue, withSequence, withSpring, withTiming, } from 'react-native-reanimated';
|
|
4
|
+
/** Ink must fit its stable target even at the top of the confirmation spring. */
|
|
5
|
+
export const SELECTION_FEEDBACK_PEAK_SCALE = 1.12;
|
|
6
|
+
/** Brief confirmation for a changed selection, inside a stable touch target. */
|
|
7
|
+
export const SelectionFeedback = forwardRef(function SelectionFeedback({ selection, active = true, variant = 'pulse', reducedMotion, style, children, ...props }, ref) {
|
|
8
|
+
const previous = useRef(selection);
|
|
9
|
+
const scale = useSharedValue(1);
|
|
10
|
+
const systemReducedMotion = useReducedMotion();
|
|
11
|
+
const reduce = reducedMotion === true || systemReducedMotion;
|
|
12
|
+
const play = useCallback(() => {
|
|
13
|
+
cancelAnimation(scale);
|
|
14
|
+
if (!active || reduce) {
|
|
15
|
+
scale.set(1);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (variant === 'pop')
|
|
19
|
+
scale.set(0.9);
|
|
20
|
+
const preference = ReduceMotion.System;
|
|
21
|
+
scale.set(withSequence(preference, withTiming(SELECTION_FEEDBACK_PEAK_SCALE, {
|
|
22
|
+
duration: 100,
|
|
23
|
+
easing: Easing.bezier(0.23, 1, 0.32, 1),
|
|
24
|
+
reduceMotion: preference,
|
|
25
|
+
}), withSpring(1, {
|
|
26
|
+
duration: 300,
|
|
27
|
+
dampingRatio: 0.8,
|
|
28
|
+
reduceMotion: preference,
|
|
29
|
+
})));
|
|
30
|
+
}, [active, reduce, scale, variant]);
|
|
31
|
+
useImperativeHandle(ref, () => ({ play }), [play]);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const changed = !Object.is(previous.current, selection);
|
|
34
|
+
previous.current = selection;
|
|
35
|
+
if (changed && selection !== undefined)
|
|
36
|
+
play();
|
|
37
|
+
else if (!active || reduce) {
|
|
38
|
+
cancelAnimation(scale);
|
|
39
|
+
scale.set(1);
|
|
40
|
+
}
|
|
41
|
+
return () => cancelAnimation(scale);
|
|
42
|
+
}, [active, play, reduce, scale, selection]);
|
|
43
|
+
const motionStyle = useAnimatedStyle(() => ({
|
|
44
|
+
transform: [{ scale: scale.get() }],
|
|
45
|
+
}));
|
|
46
|
+
return (_jsx(Animated.View, { ...props, style: [style, motionStyle], children: children }));
|
|
47
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React, { type ReactElement } from 'react';
|
|
2
|
+
import type { StyleProp, TextStyle, ViewStyle } from 'react-native';
|
|
3
|
+
import type { CpkTheme } from '../../../utils/theme';
|
|
4
|
+
import { type TimePickerHourCycle } from './timeFormat';
|
|
5
|
+
export { resolveTimeFormat, type TimePickerFormat, type TimePickerHourCycle, type TimePickerSegment, } from './timeFormat';
|
|
6
|
+
/** The resolved colour set. Every key defaults to a cpk-ui theme token. */
|
|
7
|
+
export type TimePickerPalette = Readonly<{
|
|
8
|
+
fieldBackground: string;
|
|
9
|
+
fieldBorder: string;
|
|
10
|
+
focusedFieldBorder: string;
|
|
11
|
+
text: string;
|
|
12
|
+
separator: string;
|
|
13
|
+
selectedBackground: string;
|
|
14
|
+
selectedText: string;
|
|
15
|
+
unselectedText: string;
|
|
16
|
+
disabledText: string;
|
|
17
|
+
}>;
|
|
18
|
+
export type TimePickerColors = Partial<TimePickerPalette>;
|
|
19
|
+
/** Screen reader names. Defaults come from `Intl.DisplayNames` where the runtime has it. */
|
|
20
|
+
export type TimePickerLabels = {
|
|
21
|
+
hour?: string;
|
|
22
|
+
minute?: string;
|
|
23
|
+
dayPeriod?: string;
|
|
24
|
+
};
|
|
25
|
+
export type TimePickerStyles = {
|
|
26
|
+
container?: StyleProp<ViewStyle>;
|
|
27
|
+
field?: StyleProp<TextStyle>;
|
|
28
|
+
focusedField?: StyleProp<TextStyle>;
|
|
29
|
+
separator?: StyleProp<TextStyle>;
|
|
30
|
+
dayPeriod?: StyleProp<ViewStyle>;
|
|
31
|
+
dayPeriodOption?: StyleProp<ViewStyle>;
|
|
32
|
+
selectedDayPeriodOption?: StyleProp<ViewStyle>;
|
|
33
|
+
dayPeriodText?: StyleProp<TextStyle>;
|
|
34
|
+
};
|
|
35
|
+
export type TimePickerProps = {
|
|
36
|
+
/** Only the hours and minutes are read. The date part is kept on change. */
|
|
37
|
+
value: Date;
|
|
38
|
+
/**
|
|
39
|
+
* Fires with a copy of `value` carrying the new hours and minutes, seconds zeroed,
|
|
40
|
+
* whenever a typed digit or a day period press forms a valid time.
|
|
41
|
+
*/
|
|
42
|
+
onChange?: (date: Date) => void;
|
|
43
|
+
/** BCP-47 tag. Decides the hour cycle, separator, order and day period words. */
|
|
44
|
+
locale?: string;
|
|
45
|
+
/** Overrides the locale's hour cycle. */
|
|
46
|
+
hourCycle?: TimePickerHourCycle;
|
|
47
|
+
disabled?: boolean;
|
|
48
|
+
colors?: TimePickerColors;
|
|
49
|
+
labels?: TimePickerLabels;
|
|
50
|
+
/** Multiplier cap applied to every text node. */
|
|
51
|
+
maxFontSizeMultiplier?: number;
|
|
52
|
+
style?: StyleProp<ViewStyle>;
|
|
53
|
+
styles?: TimePickerStyles;
|
|
54
|
+
/** Prefix for `-hour`, `-minute`, `-am` and `-pm`. */
|
|
55
|
+
testID?: string;
|
|
56
|
+
};
|
|
57
|
+
export declare function resolveTimePickerPalette(theme: CpkTheme, colors?: TimePickerColors): TimePickerPalette;
|
|
58
|
+
declare function TimePickerContainer({ value, onChange, locale: localeProp, hourCycle: hourCycleProp, disabled, colors, labels: labelsProp, maxFontSizeMultiplier, style, styles, testID, }: TimePickerProps): ReactElement;
|
|
59
|
+
export declare const TimePicker: React.MemoExoticComponent<typeof TimePickerContainer>;
|
|
60
|
+
export default TimePicker;
|
|
61
|
+
//# sourceMappingURL=TimePicker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimePicker.d.ts","sourceRoot":"","sources":["../../../../src/components/uis/TimePicker/TimePicker.tsx"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useCallback, useMemo, useRef, useState, } from 'react';
|
|
3
|
+
import { Pressable, StyleSheet, Text, TextInput, useWindowDimensions, View, } from 'react-native';
|
|
4
|
+
import { css } from 'kstyled';
|
|
5
|
+
import { useTheme } from '../../../providers/ThemeProvider';
|
|
6
|
+
import { isWeb } from '../../../utils/platform';
|
|
7
|
+
import { resolveLocale } from '../Calendar/intl';
|
|
8
|
+
import { displayHour, padTwo, readTimeField, resolveTimeFormat, toHours24, } from './timeFormat';
|
|
9
|
+
export { resolveTimeFormat, } from './timeFormat';
|
|
10
|
+
export function resolveTimePickerPalette(theme, colors) {
|
|
11
|
+
return Object.freeze({
|
|
12
|
+
fieldBackground: colors?.fieldBackground ?? theme.bg.basic,
|
|
13
|
+
fieldBorder: colors?.fieldBorder ?? theme.role.border,
|
|
14
|
+
focusedFieldBorder: colors?.focusedFieldBorder ?? theme.role.primary,
|
|
15
|
+
text: colors?.text ?? theme.text.basic,
|
|
16
|
+
separator: colors?.separator ?? theme.text.label,
|
|
17
|
+
selectedBackground: colors?.selectedBackground ?? theme.role.primary,
|
|
18
|
+
selectedText: colors?.selectedText ?? theme.text.contrast,
|
|
19
|
+
unselectedText: colors?.unselectedText ?? theme.text.label,
|
|
20
|
+
disabledText: colors?.disabledText ?? theme.text.disabled,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const FALLBACK_LABELS = {
|
|
24
|
+
hour: 'Hour',
|
|
25
|
+
minute: 'Minute',
|
|
26
|
+
dayPeriod: 'AM/PM',
|
|
27
|
+
};
|
|
28
|
+
function defaultLabels(locale) {
|
|
29
|
+
const DisplayNames = Intl.DisplayNames;
|
|
30
|
+
if (typeof DisplayNames !== 'function') {
|
|
31
|
+
return FALLBACK_LABELS;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const names = new DisplayNames([locale], { type: 'dateTimeField' });
|
|
35
|
+
return {
|
|
36
|
+
hour: names.of('hour') ?? FALLBACK_LABELS.hour,
|
|
37
|
+
minute: names.of('minute') ?? FALLBACK_LABELS.minute,
|
|
38
|
+
dayPeriod: names.of('dayPeriod') ?? FALLBACK_LABELS.dayPeriod,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return FALLBACK_LABELS;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const ROW = css `
|
|
46
|
+
flex-direction: row;
|
|
47
|
+
align-items: center;
|
|
48
|
+
gap: 8px;
|
|
49
|
+
`;
|
|
50
|
+
const CLOCK = css `
|
|
51
|
+
flex-direction: row;
|
|
52
|
+
align-items: center;
|
|
53
|
+
gap: 4px;
|
|
54
|
+
`;
|
|
55
|
+
const FIELD = css `
|
|
56
|
+
min-height: 44px;
|
|
57
|
+
padding: 6px 8px;
|
|
58
|
+
border-width: 1px;
|
|
59
|
+
border-radius: 10px;
|
|
60
|
+
`;
|
|
61
|
+
const DAY_PERIOD = css `
|
|
62
|
+
flex-direction: row;
|
|
63
|
+
border-width: 1px;
|
|
64
|
+
border-radius: 10px;
|
|
65
|
+
overflow: hidden;
|
|
66
|
+
`;
|
|
67
|
+
const DAY_PERIOD_OPTION = css `
|
|
68
|
+
min-width: 48px;
|
|
69
|
+
min-height: 44px;
|
|
70
|
+
padding: 6px 10px;
|
|
71
|
+
align-items: center;
|
|
72
|
+
justify-content: center;
|
|
73
|
+
`;
|
|
74
|
+
const FIELD_FONT_SIZE = 20;
|
|
75
|
+
const textStyles = StyleSheet.create({
|
|
76
|
+
field: {
|
|
77
|
+
fontFamily: 'Pretendard',
|
|
78
|
+
fontSize: FIELD_FONT_SIZE,
|
|
79
|
+
fontVariant: ['tabular-nums'],
|
|
80
|
+
includeFontPadding: false,
|
|
81
|
+
lineHeight: 26,
|
|
82
|
+
textAlign: 'center',
|
|
83
|
+
},
|
|
84
|
+
separator: {
|
|
85
|
+
fontFamily: 'Pretendard',
|
|
86
|
+
fontSize: 20,
|
|
87
|
+
lineHeight: 26,
|
|
88
|
+
},
|
|
89
|
+
dayPeriod: {
|
|
90
|
+
fontFamily: 'Pretendard',
|
|
91
|
+
fontSize: 15,
|
|
92
|
+
lineHeight: 20,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
const WEB_FIELD = { outlineWidth: 0 };
|
|
96
|
+
/**
|
|
97
|
+
* Two tabular digits plus padding and border at the current font scale. A web
|
|
98
|
+
* input otherwise takes the browser's ~20 character intrinsic width.
|
|
99
|
+
*/
|
|
100
|
+
function timePickerFieldWidth(fontScale) {
|
|
101
|
+
return Math.max(52, Math.ceil(FIELD_FONT_SIZE * fontScale * 1.3 + 18));
|
|
102
|
+
}
|
|
103
|
+
function TimePickerContainer({ value, onChange, locale: localeProp, hourCycle: hourCycleProp, disabled = false, colors, labels: labelsProp, maxFontSizeMultiplier = 1.6, style, styles, testID = 'time-picker', }) {
|
|
104
|
+
const { theme } = useTheme();
|
|
105
|
+
const { fontScale } = useWindowDimensions();
|
|
106
|
+
const fieldWidth = timePickerFieldWidth(Math.min(fontScale, maxFontSizeMultiplier));
|
|
107
|
+
const locale = useMemo(() => localeProp ?? resolveLocale(), [localeProp]);
|
|
108
|
+
const format = useMemo(() => resolveTimeFormat(locale, hourCycleProp), [locale, hourCycleProp]);
|
|
109
|
+
const palette = useMemo(() => resolveTimePickerPalette(theme, colors), [theme, colors]);
|
|
110
|
+
const labels = useMemo(() => ({ ...defaultLabels(locale), ...labelsProp }), [locale, labelsProp]);
|
|
111
|
+
const [focused, setFocused] = useState(null);
|
|
112
|
+
const [draft, setDraft] = useState('');
|
|
113
|
+
const minuteRef = useRef(null);
|
|
114
|
+
const hours = value.getHours();
|
|
115
|
+
const minutes = value.getMinutes();
|
|
116
|
+
const isAfternoon = hours >= 12;
|
|
117
|
+
const hourText = format.padHour
|
|
118
|
+
? padTwo(displayHour(hours, format.hourCycle))
|
|
119
|
+
: String(displayHour(hours, format.hourCycle));
|
|
120
|
+
const minuteText = padTwo(minutes);
|
|
121
|
+
const commit = useCallback((nextHours, nextMinutes) => {
|
|
122
|
+
if (nextHours === hours && nextMinutes === minutes) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const next = new Date(value.getTime());
|
|
126
|
+
next.setHours(nextHours, nextMinutes, 0, 0);
|
|
127
|
+
onChange?.(next);
|
|
128
|
+
}, [hours, minutes, onChange, value]);
|
|
129
|
+
const handleChangeText = useCallback((field, text) => {
|
|
130
|
+
const entry = disabled
|
|
131
|
+
? null
|
|
132
|
+
: readTimeField(text, field, format.hourCycle);
|
|
133
|
+
if (!entry) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
setDraft(entry.draft);
|
|
137
|
+
if (entry.value !== null) {
|
|
138
|
+
if (field === 'hour') {
|
|
139
|
+
commit(toHours24(entry.value, format.hourCycle, isAfternoon), minutes);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
commit(hours, entry.value);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (field === 'hour' && entry.complete) {
|
|
146
|
+
minuteRef.current?.focus();
|
|
147
|
+
}
|
|
148
|
+
}, [commit, disabled, format.hourCycle, hours, isAfternoon, minutes]);
|
|
149
|
+
const handleFocus = useCallback((field) => {
|
|
150
|
+
setFocused(field);
|
|
151
|
+
setDraft(field === 'hour' ? hourText : minuteText);
|
|
152
|
+
}, [hourText, minuteText]);
|
|
153
|
+
const handleBlur = useCallback((field) => {
|
|
154
|
+
setFocused((current) => (current === field ? null : current));
|
|
155
|
+
}, []);
|
|
156
|
+
const chooseDayPeriod = useCallback((afternoon) => {
|
|
157
|
+
if (disabled || afternoon === isAfternoon) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
commit(afternoon ? hours + 12 : hours - 12, minutes);
|
|
161
|
+
}, [commit, disabled, hours, isAfternoon, minutes]);
|
|
162
|
+
const textColor = disabled ? palette.disabledText : palette.text;
|
|
163
|
+
const renderField = (field) => {
|
|
164
|
+
const isFocused = focused === field;
|
|
165
|
+
return (_jsx(TextInput, { accessibilityLabel: labels[field], accessibilityState: { disabled }, editable: !disabled, keyboardType: "number-pad", maxFontSizeMultiplier: maxFontSizeMultiplier, maxLength: 2, onBlur: () => handleBlur(field), onChangeText: (text) => handleChangeText(field, text), onFocus: () => handleFocus(field), ref: field === 'minute' ? minuteRef : undefined, returnKeyType: "done", selectTextOnFocus: true, selectionColor: palette.focusedFieldBorder, style: [
|
|
166
|
+
FIELD,
|
|
167
|
+
textStyles.field,
|
|
168
|
+
{
|
|
169
|
+
backgroundColor: palette.fieldBackground,
|
|
170
|
+
borderColor: isFocused
|
|
171
|
+
? palette.focusedFieldBorder
|
|
172
|
+
: palette.fieldBorder,
|
|
173
|
+
color: textColor,
|
|
174
|
+
width: fieldWidth,
|
|
175
|
+
},
|
|
176
|
+
isWeb() && WEB_FIELD,
|
|
177
|
+
styles?.field,
|
|
178
|
+
isFocused && styles?.focusedField,
|
|
179
|
+
], testID: `${testID}-${field}`, value: isFocused ? draft : field === 'hour' ? hourText : minuteText }));
|
|
180
|
+
};
|
|
181
|
+
const clock = (_jsx(View, { style: CLOCK, children: format.order
|
|
182
|
+
.filter((segment) => segment !== 'dayPeriod')
|
|
183
|
+
.map((segment, index) => (_jsxs(React.Fragment, { children: [index > 0 ? (_jsx(Text, { maxFontSizeMultiplier: maxFontSizeMultiplier, style: [
|
|
184
|
+
textStyles.separator,
|
|
185
|
+
{ color: disabled ? palette.disabledText : palette.separator },
|
|
186
|
+
styles?.separator,
|
|
187
|
+
], children: format.separator })) : null, renderField(segment)] }, segment))) }, "clock"));
|
|
188
|
+
const dayPeriod = format.hourCycle === 'h12' ? (_jsx(View, { accessibilityLabel: labels.dayPeriod, accessibilityRole: "radiogroup", style: [
|
|
189
|
+
DAY_PERIOD,
|
|
190
|
+
{ borderColor: palette.fieldBorder },
|
|
191
|
+
styles?.dayPeriod,
|
|
192
|
+
], children: format.dayPeriods.map((word, index) => {
|
|
193
|
+
const afternoon = index === 1;
|
|
194
|
+
const selected = afternoon === isAfternoon;
|
|
195
|
+
return (_jsx(Pressable, { accessibilityLabel: word, accessibilityRole: "radio", accessibilityState: { checked: selected, disabled }, disabled: disabled, onPress: () => chooseDayPeriod(afternoon), style: [
|
|
196
|
+
DAY_PERIOD_OPTION,
|
|
197
|
+
{
|
|
198
|
+
backgroundColor: selected
|
|
199
|
+
? palette.selectedBackground
|
|
200
|
+
: palette.fieldBackground,
|
|
201
|
+
},
|
|
202
|
+
styles?.dayPeriodOption,
|
|
203
|
+
selected && styles?.selectedDayPeriodOption,
|
|
204
|
+
], testID: `${testID}-${afternoon ? 'pm' : 'am'}`, children: _jsx(Text, { maxFontSizeMultiplier: maxFontSizeMultiplier, style: [
|
|
205
|
+
textStyles.dayPeriod,
|
|
206
|
+
{
|
|
207
|
+
color: disabled
|
|
208
|
+
? palette.disabledText
|
|
209
|
+
: selected
|
|
210
|
+
? palette.selectedText
|
|
211
|
+
: palette.unselectedText,
|
|
212
|
+
fontWeight: selected ? '600' : '400',
|
|
213
|
+
},
|
|
214
|
+
styles?.dayPeriodText,
|
|
215
|
+
], children: word }) }, word));
|
|
216
|
+
}) }, "dayPeriod")) : null;
|
|
217
|
+
const dayPeriodFirst = format.order.indexOf('dayPeriod') >= 0 &&
|
|
218
|
+
format.order.indexOf('dayPeriod') < format.order.indexOf('hour');
|
|
219
|
+
return (_jsx(View, { style: [ROW, style, styles?.container], testID: testID, children: dayPeriodFirst ? [dayPeriod, clock] : [clock, dayPeriod] }));
|
|
220
|
+
}
|
|
221
|
+
export const TimePicker = React.memo(TimePickerContainer);
|
|
222
|
+
export default TimePicker;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** `h12`: 1–12 with a day period (AM/PM). `h23`: 0–23. */
|
|
2
|
+
export type TimePickerHourCycle = 'h12' | 'h23';
|
|
3
|
+
export type TimePickerField = 'hour' | 'minute';
|
|
4
|
+
export type TimePickerSegment = TimePickerField | 'dayPeriod';
|
|
5
|
+
/** How one locale writes a time of day, read once from `Intl.DateTimeFormat`. */
|
|
6
|
+
export type TimePickerFormat = Readonly<{
|
|
7
|
+
hourCycle: TimePickerHourCycle;
|
|
8
|
+
/** The literal between hour and minute, e.g. `:` in English, `.` in Indonesian. */
|
|
9
|
+
separator: string;
|
|
10
|
+
/** The order the locale writes the segments, e.g. `오전 9:05` vs `9:05 AM`. */
|
|
11
|
+
order: readonly TimePickerSegment[];
|
|
12
|
+
/** `[AM, PM]` in the locale's own words. Read only when `hourCycle` is `h12`. */
|
|
13
|
+
dayPeriods: readonly [string, string];
|
|
14
|
+
/** Whether the locale writes 9 o'clock as `09`. Minutes are always two digits. */
|
|
15
|
+
padHour: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Hour cycle, separator, segment order and day period words for `locale`.
|
|
19
|
+
* An explicit `hourCycle` overrides the locale's preference but keeps its words.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveTimeFormat(locale: string, hourCycle?: TimePickerHourCycle): TimePickerFormat;
|
|
22
|
+
/** The hour as a h12 or h23 field shows it. */
|
|
23
|
+
export declare function displayHour(hours: number, hourCycle: TimePickerHourCycle): number;
|
|
24
|
+
/** A typed hour back to 0–23. */
|
|
25
|
+
export declare function toHours24(hour: number, hourCycle: TimePickerHourCycle, isAfternoon: boolean): number;
|
|
26
|
+
export declare function padTwo(value: number): string;
|
|
27
|
+
export type TimeFieldEntry = Readonly<{
|
|
28
|
+
/** What the field shows while it has focus. */
|
|
29
|
+
draft: string;
|
|
30
|
+
/** The typed number, or `null` while it cannot be one yet (`0` in a h12 hour). */
|
|
31
|
+
value: number | null;
|
|
32
|
+
/** No further digit can follow, so focus may move on. */
|
|
33
|
+
complete: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Reads one keystroke's worth of field text. Returns `null` when the text can
|
|
37
|
+
* never become a valid value (`25` hours, `60` minutes), so the field keeps
|
|
38
|
+
* its previous draft.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readTimeField(text: string, field: TimePickerField, hourCycle: TimePickerHourCycle): TimeFieldEntry | null;
|
|
41
|
+
//# sourceMappingURL=timeFormat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeFormat.d.ts","sourceRoot":"","sources":["../../../../src/components/uis/TimePicker/timeFormat.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,KAAK,CAAC;AAEhD,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEhD,MAAM,MAAM,iBAAiB,GAAG,eAAe,GAAG,WAAW,CAAC;AAE9D,iFAAiF;AACjF,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACtC,SAAS,EAAE,mBAAmB,CAAC;IAC/B,mFAAmF;IACnF,SAAS,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,KAAK,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACpC,iFAAiF;IACjF,UAAU,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,kFAAkF;IAClF,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC,CAAC;AAsIH;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,mBAAmB,GAC9B,gBAAgB,CA+BlB;AAED,+CAA+C;AAC/C,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,mBAAmB,GAC7B,MAAM,CAMR;AAED,iCAAiC;AACjC,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,mBAAmB,EAC9B,WAAW,EAAE,OAAO,GACnB,MAAM,CAMR;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC;IACpC,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,kFAAkF;IAClF,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,yDAAyD;IACzD,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC,CAAC;AAqBH;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,eAAe,EACtB,SAAS,EAAE,mBAAmB,GAC7B,cAAc,GAAG,IAAI,CAwBvB"}
|