react-miui 0.33.0 → 0.35.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/.claude/settings.json +12 -0
- package/.claude/settings.local.json +5 -1
- package/.storybook/preview.tsx +10 -4
- package/CHANGELOG.md +22 -0
- package/dist/components/form/index.d.ts +1 -0
- package/dist/components/form/index.d.ts.map +1 -1
- package/dist/components/form/index.js +1 -0
- package/dist/components/form/index.js.map +1 -1
- package/dist/components/form/input/Input.d.ts.map +1 -1
- package/dist/components/form/input/Input.js +9 -5
- package/dist/components/form/input/Input.js.map +1 -1
- package/dist/components/form/timepicker/TimePicker.css.d.ts +99 -0
- package/dist/components/form/timepicker/TimePicker.css.d.ts.map +1 -0
- package/dist/components/form/timepicker/TimePicker.css.js +116 -0
- package/dist/components/form/timepicker/TimePicker.css.js.map +1 -0
- package/dist/components/form/timepicker/TimePicker.d.ts +22 -0
- package/dist/components/form/timepicker/TimePicker.d.ts.map +1 -0
- package/dist/components/form/timepicker/TimePicker.js +141 -0
- package/dist/components/form/timepicker/TimePicker.js.map +1 -0
- package/dist/components/form/timepicker/TimePicker.styled.d.ts +936 -0
- package/dist/components/form/timepicker/TimePicker.styled.d.ts.map +1 -0
- package/dist/components/form/timepicker/TimePicker.styled.js +29 -0
- package/dist/components/form/timepicker/TimePicker.styled.js.map +1 -0
- package/dist/components/form/timepicker/TimePickerModal.d.ts +17 -0
- package/dist/components/form/timepicker/TimePickerModal.d.ts.map +1 -0
- package/dist/components/form/timepicker/TimePickerModal.js +92 -0
- package/dist/components/form/timepicker/TimePickerModal.js.map +1 -0
- package/dist/components/form/timepicker/Wheel.d.ts +12 -0
- package/dist/components/form/timepicker/Wheel.d.ts.map +1 -0
- package/dist/components/form/timepicker/Wheel.js +187 -0
- package/dist/components/form/timepicker/Wheel.js.map +1 -0
- package/dist/components/form/timepicker/utils.d.ts +4 -0
- package/dist/components/form/timepicker/utils.d.ts.map +1 -0
- package/dist/components/form/timepicker/utils.js +62 -0
- package/dist/components/form/timepicker/utils.js.map +1 -0
- package/dist/components/icons/Clock.d.ts +7 -0
- package/dist/components/icons/Clock.d.ts.map +1 -0
- package/dist/components/icons/Clock.js +45 -0
- package/dist/components/icons/Clock.js.map +1 -0
- package/dist/components/icons/Icon.d.ts +2 -1
- package/dist/components/icons/Icon.d.ts.map +1 -1
- package/dist/components/icons/Icon.js +3 -0
- package/dist/components/icons/Icon.js.map +1 -1
- package/dist/components/ui/drawer/Drawer.d.ts +10 -1
- package/dist/components/ui/drawer/Drawer.d.ts.map +1 -1
- package/dist/components/ui/drawer/Drawer.js +135 -15
- package/dist/components/ui/drawer/Drawer.js.map +1 -1
- package/dist/components/ui/drawer/Drawer.styled.d.ts +86 -1
- package/dist/components/ui/drawer/Drawer.styled.d.ts.map +1 -1
- package/dist/components/ui/drawer/Drawer.styled.js +13 -1
- package/dist/components/ui/drawer/Drawer.styled.js.map +1 -1
- package/dist/components/ui/modal/Modal.d.ts +1 -2
- package/dist/components/ui/modal/Modal.d.ts.map +1 -1
- package/dist/components/ui/modal/Modal.js +114 -42
- package/dist/components/ui/modal/Modal.js.map +1 -1
- package/dist/components/ui/modal/Modal.styled.d.ts +1 -1
- package/dist/components/ui/modal/Modal.styled.d.ts.map +1 -1
- package/dist/components/ui/modal/Modal.styled.js +40 -25
- package/dist/components/ui/modal/Modal.styled.js.map +1 -1
- package/dist/components/ui/toaster/Toaster.d.ts.map +1 -1
- package/dist/components/ui/toaster/Toaster.js +7 -1
- package/dist/components/ui/toaster/Toaster.js.map +1 -1
- package/dist/components/ui/tooltip/Tooltip.d.ts +30 -0
- package/dist/components/ui/tooltip/Tooltip.d.ts.map +1 -0
- package/dist/components/ui/tooltip/Tooltip.js +81 -0
- package/dist/components/ui/tooltip/Tooltip.js.map +1 -0
- package/dist/components/ui/tooltip/Tooltip.styled.d.ts +173 -0
- package/dist/components/ui/tooltip/Tooltip.styled.d.ts.map +1 -0
- package/dist/components/ui/tooltip/Tooltip.styled.js +65 -0
- package/dist/components/ui/tooltip/Tooltip.styled.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/theme.css-global.d.ts.map +1 -1
- package/dist/theme.css-global.js +0 -1
- package/dist/theme.css-global.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/useNativeValidity.d.ts +11 -0
- package/dist/utils/useNativeValidity.d.ts.map +1 -0
- package/dist/utils/useNativeValidity.js +32 -0
- package/dist/utils/useNativeValidity.js.map +1 -0
- package/docs/assets/highlight.css +7 -0
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/index.Pop.html +7 -7
- package/docs/documents/Test.html +2 -2
- package/docs/enums/index.ICON.html +3 -2
- package/docs/functions/index.Action.html +3 -3
- package/docs/functions/index.Button.html +4 -4
- package/docs/functions/index.Card.html +3 -3
- package/docs/functions/index.Checkbox.html +3 -3
- package/docs/functions/index.Choice.html +2 -2
- package/docs/functions/index.ColorPicker.html +3 -3
- package/docs/functions/index.CoveringLoader.html +3 -3
- package/docs/functions/index.DirectionPad.html +2 -2
- package/docs/functions/index.Drawer.html +2 -2
- package/docs/functions/index.EqualActions.html +2 -2
- package/docs/functions/index.FullLoader.html +3 -3
- package/docs/functions/index.Gap.html +3 -3
- package/docs/functions/index.HandleEsc.html +3 -3
- package/docs/functions/index.Header.html +3 -3
- package/docs/functions/index.HeaderIconAction.html +3 -3
- package/docs/functions/index.Icon-1.html +2 -2
- package/docs/functions/index.If.html +3 -3
- package/docs/functions/index.Input.html +1 -1
- package/docs/functions/index.KeyValue.html +2 -2
- package/docs/functions/index.Label.html +2 -2
- package/docs/functions/index.Line.html +4 -4
- package/docs/functions/index.List.html +2 -2
- package/docs/functions/index.Loader.html +3 -3
- package/docs/functions/index.Loading.html +3 -3
- package/docs/functions/index.Message.html +4 -4
- package/docs/functions/index.Modal.html +2 -2
- package/docs/functions/index.ModalButtons.html +3 -3
- package/docs/functions/index.PopLoader.html +3 -3
- package/docs/functions/index.PopOption.html +2 -2
- package/docs/functions/index.Progress.html +2 -2
- package/docs/functions/index.SearchContainer.html +3 -3
- package/docs/functions/index.Section.html +4 -4
- package/docs/functions/index.Select.html +3 -3
- package/docs/functions/index.Selector.html +2 -2
- package/docs/functions/index.Spacer.html +3 -3
- package/docs/functions/index.Stats.html +2 -2
- package/docs/functions/index.StickyHeader.html +4 -4
- package/docs/functions/index.Table.html +3 -3
- package/docs/functions/index.TextArea.html +2 -2
- package/docs/functions/index.TimePicker.html +10 -0
- package/docs/functions/index.ToasterProvider.html +3 -3
- package/docs/functions/index.Toggle.html +3 -3
- package/docs/functions/index.ToolButton.html +4 -4
- package/docs/functions/index.Tooltip.html +18 -0
- package/docs/functions/index.TooltipProvider.html +6 -0
- package/docs/functions/index.borderPxToRem.html +1 -1
- package/docs/functions/index.createTheme.html +1 -1
- package/docs/functions/index.css.html +1 -1
- package/docs/functions/index.dimensionsPxToRem.html +1 -1
- package/docs/functions/index.fontPxToRem.html +1 -1
- package/docs/functions/index.getCssText.html +1 -1
- package/docs/functions/index.globalCss.html +2 -2
- package/docs/functions/index.injectGlobalStyles.html +1 -1
- package/docs/functions/index.keyframes.html +1 -1
- package/docs/functions/index.pxToRem.html +1 -1
- package/docs/functions/index.styled.html +1 -1
- package/docs/functions/index.toast.html +2 -2
- package/docs/functions/index.useToaster.html +1 -1
- package/docs/index.html +2 -2
- package/docs/interfaces/index.IconProps.html +2 -2
- package/docs/interfaces/index.InputCustomProps.html +3 -3
- package/docs/interfaces/index.LoaderProps.html +6 -6
- package/docs/interfaces/index.StickyHeaderProps.html +4 -4
- package/docs/interfaces/index.ToasterProviderProps.html +3 -3
- package/docs/interfaces/index.TooltipProps.html +36 -0
- package/docs/interfaces/index.TooltipProviderProps.html +13 -0
- package/docs/modules/index.html +1 -1
- package/docs/modules.html +1 -1
- package/docs/types/index.ActionProps.html +1 -1
- package/docs/types/index.CardProps.html +1 -1
- package/docs/types/index.CheckboxProps.html +2 -2
- package/docs/types/index.ChoiceProps.html +1 -1
- package/docs/types/index.ColorPickerProps.html +1 -1
- package/docs/types/index.DirectionPadProps.html +1 -1
- package/docs/types/index.DrawerFrom.html +1 -0
- package/docs/types/index.DrawerProps.html +28 -1
- package/docs/types/index.EqualActionsProps.html +1 -1
- package/docs/types/index.HeaderProps.html +1 -1
- package/docs/types/index.InputProps.html +1 -1
- package/docs/types/index.KeyValueProps.html +1 -1
- package/docs/types/index.LabelProps.html +1 -1
- package/docs/types/index.OverwriteProps.html +1 -1
- package/docs/types/index.ProgressProps.html +2 -2
- package/docs/types/index.SelectProps.html +1 -1
- package/docs/types/index.SelectorProps.html +1 -1
- package/docs/types/index.Stat.html +1 -1
- package/docs/types/index.StatsProps.html +1 -1
- package/docs/types/index.TextAreaProps.html +1 -1
- package/docs/types/index.ThemeCSS.html +1 -1
- package/docs/types/index.TimePickerProps.html +1 -0
- package/docs/types/index.ToggleProps.html +2 -2
- package/docs/variables/index.ActionBadgeSelector.html +1 -1
- package/docs/variables/index.ActionCircleSelector.html +1 -1
- package/docs/variables/index.CheckboxCheckmarkWrapperSelector.html +1 -1
- package/docs/variables/index.CheckboxTextLabelSelector.html +1 -1
- package/docs/variables/index.ChoiceItemSelector.html +1 -1
- package/docs/variables/index.ColorPickerColorDisplaySelector.html +1 -1
- package/docs/variables/index.DirectionPadButtonDotSelector.html +1 -1
- package/docs/variables/index.DirectionPadButtonSelector.html +1 -1
- package/docs/variables/index.DirectionPadLineSelector.html +1 -1
- package/docs/variables/index.DirectionPadMiddleSelector.html +1 -1
- package/docs/variables/index.DrawerContentSelector.html +1 -1
- package/docs/variables/index.HeaderAfterSelector.html +1 -1
- package/docs/variables/index.HeaderBeforeSelector.html +1 -1
- package/docs/variables/index.HeaderContentsSelector.html +1 -1
- package/docs/variables/index.HeaderIconActionIconSelector.html +1 -1
- package/docs/variables/index.InputContainerSelector.html +1 -1
- package/docs/variables/index.InputInputSelector.html +1 -1
- package/docs/variables/index.InputLabelSelector.html +1 -1
- package/docs/variables/index.InputPrefixSelector.html +1 -1
- package/docs/variables/index.InputSuffixSelector.html +1 -1
- package/docs/variables/index.KeyValueIconSelector.html +1 -1
- package/docs/variables/index.KeyValueItemSelector.html +1 -1
- package/docs/variables/index.KeyValueKeySelector.html +1 -1
- package/docs/variables/index.KeyValuePairSelector.html +1 -1
- package/docs/variables/index.KeyValueValueSelector.html +1 -1
- package/docs/variables/index.LabelTextSelector.html +1 -1
- package/docs/variables/index.ListItemInnerContainerClassNameSelector.html +1 -1
- package/docs/variables/index.ModalContainerSelector.html +1 -1
- package/docs/variables/index.ModalRemovePaddingSelector.html +1 -1
- package/docs/variables/index.ModalTitleSelector.html +1 -1
- package/docs/variables/index.PopListSelector.html +1 -1
- package/docs/variables/index.PopOptionButtonSelector.html +1 -1
- package/docs/variables/index.PopOptionIconSelector.html +1 -1
- package/docs/variables/index.PopOverlaySelector.html +1 -1
- package/docs/variables/index.ProgressBackgroundSelector.html +1 -1
- package/docs/variables/index.ProgressValueSelector.html +1 -1
- package/docs/variables/index.SelectorItemSelector.html +1 -1
- package/docs/variables/index.StatsItemSelector.html +1 -1
- package/docs/variables/index.StatsLabelSelector.html +1 -1
- package/docs/variables/index.StatsSeparatorSelector.html +1 -1
- package/docs/variables/index.StatsValueSelector.html +1 -1
- package/docs/variables/index.TextAreaLabelSelector.html +1 -1
- package/docs/variables/index.TextAreaTextAreaSelector.html +1 -1
- package/docs/variables/index.TextAreaWrapperSelector.html +1 -1
- package/docs/variables/index.ToggleStyledToggleSelector.html +1 -1
- package/docs/variables/index.TooltipContentSelector.html +1 -0
- package/docs/variables/index.config.html +1 -1
- package/docs/variables/index.cssReset.html +2 -2
- package/docs/variables/index.darkTheme.html +1 -1
- package/docs/variables/index.miuiScrollbars.html +1 -1
- package/docs/variables/index.theme.html +1 -1
- package/esm/components/form/index.d.ts +1 -0
- package/esm/components/form/index.d.ts.map +1 -1
- package/esm/components/form/index.js +1 -0
- package/esm/components/form/index.js.map +1 -1
- package/esm/components/form/input/Input.d.ts.map +1 -1
- package/esm/components/form/input/Input.js +9 -5
- package/esm/components/form/input/Input.js.map +1 -1
- package/esm/components/form/timepicker/TimePicker.css.d.ts +99 -0
- package/esm/components/form/timepicker/TimePicker.css.d.ts.map +1 -0
- package/esm/components/form/timepicker/TimePicker.css.js +102 -0
- package/esm/components/form/timepicker/TimePicker.css.js.map +1 -0
- package/esm/components/form/timepicker/TimePicker.d.ts +22 -0
- package/esm/components/form/timepicker/TimePicker.d.ts.map +1 -0
- package/esm/components/form/timepicker/TimePicker.js +93 -0
- package/esm/components/form/timepicker/TimePicker.js.map +1 -0
- package/esm/components/form/timepicker/TimePicker.styled.d.ts +936 -0
- package/esm/components/form/timepicker/TimePicker.styled.d.ts.map +1 -0
- package/esm/components/form/timepicker/TimePicker.styled.js +20 -0
- package/esm/components/form/timepicker/TimePicker.styled.js.map +1 -0
- package/esm/components/form/timepicker/TimePickerModal.d.ts +17 -0
- package/esm/components/form/timepicker/TimePickerModal.d.ts.map +1 -0
- package/esm/components/form/timepicker/TimePickerModal.js +56 -0
- package/esm/components/form/timepicker/TimePickerModal.js.map +1 -0
- package/esm/components/form/timepicker/Wheel.d.ts +12 -0
- package/esm/components/form/timepicker/Wheel.d.ts.map +1 -0
- package/esm/components/form/timepicker/Wheel.js +151 -0
- package/esm/components/form/timepicker/Wheel.js.map +1 -0
- package/esm/components/form/timepicker/utils.d.ts +4 -0
- package/esm/components/form/timepicker/utils.d.ts.map +1 -0
- package/esm/components/form/timepicker/utils.js +58 -0
- package/esm/components/form/timepicker/utils.js.map +1 -0
- package/esm/components/icons/Clock.d.ts +7 -0
- package/esm/components/icons/Clock.d.ts.map +1 -0
- package/esm/components/icons/Clock.js +9 -0
- package/esm/components/icons/Clock.js.map +1 -0
- package/esm/components/icons/Icon.d.ts +2 -1
- package/esm/components/icons/Icon.d.ts.map +1 -1
- package/esm/components/icons/Icon.js +3 -0
- package/esm/components/icons/Icon.js.map +1 -1
- package/esm/components/ui/drawer/Drawer.d.ts +10 -1
- package/esm/components/ui/drawer/Drawer.d.ts.map +1 -1
- package/esm/components/ui/drawer/Drawer.js +139 -15
- package/esm/components/ui/drawer/Drawer.js.map +1 -1
- package/esm/components/ui/drawer/Drawer.styled.d.ts +86 -1
- package/esm/components/ui/drawer/Drawer.styled.d.ts.map +1 -1
- package/esm/components/ui/drawer/Drawer.styled.js +12 -1
- package/esm/components/ui/drawer/Drawer.styled.js.map +1 -1
- package/esm/components/ui/modal/Modal.d.ts +1 -2
- package/esm/components/ui/modal/Modal.d.ts.map +1 -1
- package/esm/components/ui/modal/Modal.js +103 -43
- package/esm/components/ui/modal/Modal.js.map +1 -1
- package/esm/components/ui/modal/Modal.styled.d.ts +1 -1
- package/esm/components/ui/modal/Modal.styled.d.ts.map +1 -1
- package/esm/components/ui/modal/Modal.styled.js +40 -25
- package/esm/components/ui/modal/Modal.styled.js.map +1 -1
- package/esm/components/ui/toaster/Toaster.d.ts.map +1 -1
- package/esm/components/ui/toaster/Toaster.js +8 -2
- package/esm/components/ui/toaster/Toaster.js.map +1 -1
- package/esm/components/ui/tooltip/Tooltip.d.ts +30 -0
- package/esm/components/ui/tooltip/Tooltip.d.ts.map +1 -0
- package/esm/components/ui/tooltip/Tooltip.js +43 -0
- package/esm/components/ui/tooltip/Tooltip.js.map +1 -0
- package/esm/components/ui/tooltip/Tooltip.styled.d.ts +173 -0
- package/esm/components/ui/tooltip/Tooltip.styled.d.ts.map +1 -0
- package/esm/components/ui/tooltip/Tooltip.styled.js +28 -0
- package/esm/components/ui/tooltip/Tooltip.styled.js.map +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/theme.css-global.d.ts.map +1 -1
- package/esm/theme.css-global.js +0 -1
- package/esm/theme.css-global.js.map +1 -1
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.d.ts.map +1 -1
- package/esm/utils/index.js +1 -0
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/useNativeValidity.d.ts +11 -0
- package/esm/utils/useNativeValidity.d.ts.map +1 -0
- package/esm/utils/useNativeValidity.js +29 -0
- package/esm/utils/useNativeValidity.js.map +1 -0
- package/package.json +2 -1
- package/pnpm-workspace.yaml +3 -0
- package/src/bugfixes/ToastsFromModal.stories.tsx +59 -0
- package/src/components/form/index.ts +1 -0
- package/src/components/form/input/Input.stories.tsx +47 -1
- package/src/components/form/input/Input.tsx +11 -5
- package/src/components/form/timepicker/TimePicker.css.ts +132 -0
- package/src/components/form/timepicker/TimePicker.stories.tsx +107 -0
- package/src/components/form/timepicker/TimePicker.styled.ts +52 -0
- package/src/components/form/timepicker/TimePicker.tsx +229 -0
- package/src/components/form/timepicker/TimePickerModal.tsx +131 -0
- package/src/components/form/timepicker/Wheel.tsx +201 -0
- package/src/components/form/timepicker/utils.ts +66 -0
- package/src/components/icons/Clock.tsx +38 -0
- package/src/components/icons/Icon.tsx +3 -0
- package/src/components/ui/drawer/Drawer.stories.tsx +143 -59
- package/src/components/ui/drawer/Drawer.styled.ts +13 -0
- package/src/components/ui/drawer/Drawer.tsx +214 -20
- package/src/components/ui/modal/Modal.stories.tsx +43 -7
- package/src/components/ui/modal/Modal.styled.ts +46 -25
- package/src/components/ui/modal/Modal.tsx +135 -52
- package/src/components/ui/toaster/Toaster.tsx +12 -2
- package/src/components/ui/tooltip/Tooltip.stories.tsx +285 -0
- package/src/components/ui/tooltip/Tooltip.styled.ts +36 -0
- package/src/components/ui/tooltip/Tooltip.tsx +195 -0
- package/src/index.ts +1 -0
- package/src/theme.css-global.ts +0 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/useNativeValidity.ts +57 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useCallback,
|
|
4
|
+
useEffect,
|
|
5
|
+
useId,
|
|
6
|
+
useState,
|
|
7
|
+
} from "react";
|
|
8
|
+
|
|
9
|
+
import { useForwardedRef } from "@bedrock-layout/use-forwarded-ref";
|
|
10
|
+
|
|
11
|
+
import { useNativeValidity } from "../../../utils/useNativeValidity";
|
|
12
|
+
import { Clock } from "../../icons/Clock";
|
|
13
|
+
import {
|
|
14
|
+
StyledInputContainer,
|
|
15
|
+
StyledLabel,
|
|
16
|
+
StyledSuffix,
|
|
17
|
+
StyledWrapper,
|
|
18
|
+
} from "../input/Input.styled";
|
|
19
|
+
import {
|
|
20
|
+
StyledSuffixButton,
|
|
21
|
+
StyledTimeInput,
|
|
22
|
+
} from "./TimePicker.styled";
|
|
23
|
+
import { TimePickerModal } from "./TimePickerModal";
|
|
24
|
+
|
|
25
|
+
const PATTERN_HHMM = "(?:[01]\\d|2[0-3]):[0-5]\\d";
|
|
26
|
+
const PATTERN_HHMMSS = "(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";
|
|
27
|
+
const MAX_LEN_HHMM = 5;
|
|
28
|
+
const MAX_LEN_HHMMSS = 8;
|
|
29
|
+
|
|
30
|
+
const assertStep = (name: string, step: number): void => {
|
|
31
|
+
if (!Number.isInteger(step) || step < 1 || step > 60) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`TimePicker: \`${name}\` must be an integer between 1 and 60, got ${String(step)}`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
interface CustomProps {
|
|
39
|
+
children?: never;
|
|
40
|
+
label?: string;
|
|
41
|
+
pinnedLabel?: boolean;
|
|
42
|
+
error?: boolean;
|
|
43
|
+
withSeconds?: boolean;
|
|
44
|
+
minuteStep?: number;
|
|
45
|
+
secondStep?: number;
|
|
46
|
+
value?: string;
|
|
47
|
+
defaultValue?: string;
|
|
48
|
+
onChange?: (value: string) => void;
|
|
49
|
+
modalTitle?: React.ReactNode;
|
|
50
|
+
okLabel?: React.ReactNode;
|
|
51
|
+
cancelLabel?: React.ReactNode;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type InputAttrs = Omit<
|
|
55
|
+
React.InputHTMLAttributes<HTMLInputElement>,
|
|
56
|
+
"value" | "defaultValue" | "onChange" | "type" | "prefix" | "pattern" | "placeholder" | "maxLength"
|
|
57
|
+
>;
|
|
58
|
+
|
|
59
|
+
type Props = InputAttrs & CustomProps;
|
|
60
|
+
|
|
61
|
+
// eslint-disable-next-line max-lines-per-function,max-statements
|
|
62
|
+
const TimePickerInner = ({
|
|
63
|
+
className,
|
|
64
|
+
label,
|
|
65
|
+
pinnedLabel = false,
|
|
66
|
+
error,
|
|
67
|
+
withSeconds = false,
|
|
68
|
+
minuteStep = 1,
|
|
69
|
+
secondStep = 1,
|
|
70
|
+
value,
|
|
71
|
+
defaultValue,
|
|
72
|
+
onChange,
|
|
73
|
+
onFocus,
|
|
74
|
+
onBlur,
|
|
75
|
+
disabled,
|
|
76
|
+
readOnly,
|
|
77
|
+
id,
|
|
78
|
+
modalTitle,
|
|
79
|
+
okLabel = "OK",
|
|
80
|
+
cancelLabel = "Cancel",
|
|
81
|
+
...rest
|
|
82
|
+
}: Props, ref: React.Ref<HTMLInputElement>) => {
|
|
83
|
+
assertStep("minuteStep", minuteStep);
|
|
84
|
+
if (withSeconds) {
|
|
85
|
+
assertStep("secondStep", secondStep);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const isControlled = value !== undefined;
|
|
89
|
+
const [internalValue, setInternalValue] = useState(defaultValue ?? "");
|
|
90
|
+
const currentValue = isControlled ? (value ?? "") : internalValue;
|
|
91
|
+
|
|
92
|
+
const [focused, setFocused] = useState(false);
|
|
93
|
+
const validity = useNativeValidity(error);
|
|
94
|
+
const { revalidate } = validity;
|
|
95
|
+
const inputRef = useForwardedRef(ref);
|
|
96
|
+
const generatedId = useId();
|
|
97
|
+
const inputId = id ?? (label ? generatedId : undefined);
|
|
98
|
+
|
|
99
|
+
const [modalOpen, setModalOpen] = useState(false);
|
|
100
|
+
|
|
101
|
+
const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
|
102
|
+
const next = e.target.value;
|
|
103
|
+
if (!isControlled) {
|
|
104
|
+
setInternalValue(next);
|
|
105
|
+
}
|
|
106
|
+
validity.onChange(e);
|
|
107
|
+
onChange?.(next);
|
|
108
|
+
}, [isControlled, onChange, validity]);
|
|
109
|
+
|
|
110
|
+
const handleFocus = useCallback((e: React.FocusEvent<HTMLInputElement>) => {
|
|
111
|
+
setFocused(true);
|
|
112
|
+
onFocus?.(e);
|
|
113
|
+
}, [onFocus]);
|
|
114
|
+
|
|
115
|
+
const handleBlur = useCallback((e: React.FocusEvent<HTMLInputElement>) => {
|
|
116
|
+
setFocused(false);
|
|
117
|
+
validity.onBlur(e);
|
|
118
|
+
onBlur?.(e);
|
|
119
|
+
}, [onBlur, validity]);
|
|
120
|
+
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
revalidate(inputRef.current);
|
|
123
|
+
}, [currentValue, revalidate, inputRef]);
|
|
124
|
+
|
|
125
|
+
const openModal = useCallback(() => {
|
|
126
|
+
setModalOpen(true);
|
|
127
|
+
}, []);
|
|
128
|
+
|
|
129
|
+
const closeModal = useCallback(() => {
|
|
130
|
+
setModalOpen(false);
|
|
131
|
+
inputRef.current?.focus();
|
|
132
|
+
}, [inputRef]);
|
|
133
|
+
|
|
134
|
+
const confirmModal = useCallback((next: string) => {
|
|
135
|
+
if (!isControlled) {
|
|
136
|
+
setInternalValue(next);
|
|
137
|
+
}
|
|
138
|
+
onChange?.(next);
|
|
139
|
+
setModalOpen(false);
|
|
140
|
+
inputRef.current?.focus();
|
|
141
|
+
}, [isControlled, onChange, inputRef]);
|
|
142
|
+
|
|
143
|
+
const hasValue = currentValue.length > 0;
|
|
144
|
+
const floating = Boolean(label) && (pinnedLabel || focused || hasValue);
|
|
145
|
+
const placeholder = withSeconds ? "--:--:--" : "--:--";
|
|
146
|
+
const pattern = withSeconds ? PATTERN_HHMMSS : PATTERN_HHMM;
|
|
147
|
+
const maxLength = withSeconds ? MAX_LEN_HHMMSS : MAX_LEN_HHMM;
|
|
148
|
+
const finalError = validity.finalError;
|
|
149
|
+
|
|
150
|
+
const labelElem = label
|
|
151
|
+
? (
|
|
152
|
+
<StyledLabel
|
|
153
|
+
htmlFor={inputId}
|
|
154
|
+
floating={floating}
|
|
155
|
+
error={finalError}
|
|
156
|
+
>
|
|
157
|
+
{label}
|
|
158
|
+
</StyledLabel>
|
|
159
|
+
)
|
|
160
|
+
: null;
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<>
|
|
164
|
+
<StyledWrapper
|
|
165
|
+
className={className}
|
|
166
|
+
focused={focused}
|
|
167
|
+
disabled={Boolean(disabled)}
|
|
168
|
+
readOnly={Boolean(readOnly)}
|
|
169
|
+
error={finalError}
|
|
170
|
+
>
|
|
171
|
+
<StyledInputContainer>
|
|
172
|
+
{labelElem}
|
|
173
|
+
<StyledTimeInput
|
|
174
|
+
ref={inputRef}
|
|
175
|
+
{...rest}
|
|
176
|
+
id={inputId}
|
|
177
|
+
type={"text"}
|
|
178
|
+
inputMode={"numeric"}
|
|
179
|
+
autoComplete={"off"}
|
|
180
|
+
value={currentValue}
|
|
181
|
+
placeholder={placeholder}
|
|
182
|
+
pattern={pattern}
|
|
183
|
+
maxLength={maxLength}
|
|
184
|
+
disabled={disabled}
|
|
185
|
+
readOnly={readOnly}
|
|
186
|
+
onChange={handleChange}
|
|
187
|
+
onFocus={handleFocus}
|
|
188
|
+
onBlur={handleBlur}
|
|
189
|
+
onInvalid={validity.onInvalid}
|
|
190
|
+
data-error={finalError}
|
|
191
|
+
/>
|
|
192
|
+
</StyledInputContainer>
|
|
193
|
+
<StyledSuffix>
|
|
194
|
+
<StyledSuffixButton
|
|
195
|
+
type={"button"}
|
|
196
|
+
onClick={openModal}
|
|
197
|
+
disabled={disabled}
|
|
198
|
+
aria-label={"Open time picker"}
|
|
199
|
+
>
|
|
200
|
+
<Clock />
|
|
201
|
+
</StyledSuffixButton>
|
|
202
|
+
</StyledSuffix>
|
|
203
|
+
</StyledWrapper>
|
|
204
|
+
<TimePickerModal
|
|
205
|
+
isOpen={modalOpen}
|
|
206
|
+
initialValue={currentValue}
|
|
207
|
+
withSeconds={withSeconds}
|
|
208
|
+
minuteStep={minuteStep}
|
|
209
|
+
secondStep={secondStep}
|
|
210
|
+
readOnly={Boolean(readOnly)}
|
|
211
|
+
title={modalTitle}
|
|
212
|
+
okLabel={okLabel}
|
|
213
|
+
cancelLabel={cancelLabel}
|
|
214
|
+
onClose={closeModal}
|
|
215
|
+
onConfirm={confirmModal}
|
|
216
|
+
/>
|
|
217
|
+
</>
|
|
218
|
+
);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const TimePickerRef = forwardRef(TimePickerInner);
|
|
222
|
+
TimePickerRef.displayName = "TimePicker";
|
|
223
|
+
TimePickerRef.toString = () => StyledWrapper.toString();
|
|
224
|
+
|
|
225
|
+
const TimePicker = TimePickerRef;
|
|
226
|
+
|
|
227
|
+
export { TimePicker };
|
|
228
|
+
|
|
229
|
+
export type { Props as TimePickerProps };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { Modal } from "../../ui/modal/Modal";
|
|
4
|
+
import { ModalButtons } from "../../ui/modal/ModalButtons";
|
|
5
|
+
import {
|
|
6
|
+
StyledWheelHighlight,
|
|
7
|
+
StyledWheelsContainer,
|
|
8
|
+
StyledWheelSeparator,
|
|
9
|
+
} from "./TimePicker.styled";
|
|
10
|
+
import { padTwo, parseTimeText } from "./utils";
|
|
11
|
+
import { Wheel } from "./Wheel";
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
isOpen: boolean;
|
|
15
|
+
/** Current input value, parsed to seed the wheels when the modal opens. */
|
|
16
|
+
initialValue: string;
|
|
17
|
+
withSeconds: boolean;
|
|
18
|
+
minuteStep: number;
|
|
19
|
+
secondStep: number;
|
|
20
|
+
readOnly: boolean;
|
|
21
|
+
title?: React.ReactNode;
|
|
22
|
+
okLabel: React.ReactNode;
|
|
23
|
+
cancelLabel: React.ReactNode;
|
|
24
|
+
onClose: () => void;
|
|
25
|
+
onConfirm: (value: string) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const snapToStep = (v: number, step: number, max: number): number => {
|
|
29
|
+
const snapped = Math.round(v / step) * step;
|
|
30
|
+
return Math.min(snapped, max - (max % step === 0 ? step : max % step));
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const TimePickerModal = ({
|
|
34
|
+
isOpen,
|
|
35
|
+
initialValue,
|
|
36
|
+
withSeconds,
|
|
37
|
+
minuteStep,
|
|
38
|
+
secondStep,
|
|
39
|
+
readOnly,
|
|
40
|
+
title,
|
|
41
|
+
okLabel,
|
|
42
|
+
cancelLabel,
|
|
43
|
+
onClose,
|
|
44
|
+
onConfirm,
|
|
45
|
+
}: Props) => {
|
|
46
|
+
const [draftHours, setDraftHours] = useState(0);
|
|
47
|
+
const [draftMinutes, setDraftMinutes] = useState(0);
|
|
48
|
+
const [draftSeconds, setDraftSeconds] = useState(0);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!isOpen) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const digits = parseTimeText(initialValue, withSeconds);
|
|
55
|
+
const hh = digits.length >= 2 ? parseInt(digits.slice(0, 2), 10) : 0;
|
|
56
|
+
const mmRaw = digits.length >= 4 ? parseInt(digits.slice(2, 4), 10) : 0;
|
|
57
|
+
const ssRaw = digits.length >= 6 ? parseInt(digits.slice(4, 6), 10) : 0;
|
|
58
|
+
setDraftHours(hh);
|
|
59
|
+
setDraftMinutes(snapToStep(mmRaw, minuteStep, 60));
|
|
60
|
+
setDraftSeconds(snapToStep(ssRaw, secondStep, 60));
|
|
61
|
+
}, [isOpen, initialValue, withSeconds, minuteStep, secondStep]);
|
|
62
|
+
|
|
63
|
+
const handleConfirm = useCallback(() => {
|
|
64
|
+
const next = padTwo(draftHours) + ":" + padTwo(draftMinutes)
|
|
65
|
+
+ (withSeconds ? ":" + padTwo(draftSeconds) : "");
|
|
66
|
+
onConfirm(next);
|
|
67
|
+
}, [draftHours, draftMinutes, draftSeconds, withSeconds, onConfirm]);
|
|
68
|
+
|
|
69
|
+
const handleWheelsKeyDown = useCallback((e: React.KeyboardEvent<HTMLDivElement>) => {
|
|
70
|
+
if (e.key === "Enter" && !readOnly) {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
handleConfirm();
|
|
73
|
+
}
|
|
74
|
+
}, [readOnly, handleConfirm]);
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Modal
|
|
78
|
+
isOpen={isOpen}
|
|
79
|
+
onClose={onClose}
|
|
80
|
+
title={title}
|
|
81
|
+
>
|
|
82
|
+
<StyledWheelsContainer onKeyDown={handleWheelsKeyDown}>
|
|
83
|
+
<Wheel
|
|
84
|
+
count={24}
|
|
85
|
+
step={1}
|
|
86
|
+
value={draftHours}
|
|
87
|
+
onChange={setDraftHours}
|
|
88
|
+
ariaLabel={"Hours"}
|
|
89
|
+
autoFocus={true}
|
|
90
|
+
/>
|
|
91
|
+
<StyledWheelSeparator>{":"}</StyledWheelSeparator>
|
|
92
|
+
<Wheel
|
|
93
|
+
count={60}
|
|
94
|
+
step={minuteStep}
|
|
95
|
+
value={draftMinutes}
|
|
96
|
+
onChange={setDraftMinutes}
|
|
97
|
+
ariaLabel={"Minutes"}
|
|
98
|
+
/>
|
|
99
|
+
{withSeconds
|
|
100
|
+
? (
|
|
101
|
+
<>
|
|
102
|
+
<StyledWheelSeparator>{":"}</StyledWheelSeparator>
|
|
103
|
+
<Wheel
|
|
104
|
+
count={60}
|
|
105
|
+
step={secondStep}
|
|
106
|
+
value={draftSeconds}
|
|
107
|
+
onChange={setDraftSeconds}
|
|
108
|
+
ariaLabel={"Seconds"}
|
|
109
|
+
/>
|
|
110
|
+
</>
|
|
111
|
+
)
|
|
112
|
+
: null}
|
|
113
|
+
<StyledWheelHighlight aria-hidden={true} />
|
|
114
|
+
</StyledWheelsContainer>
|
|
115
|
+
<ModalButtons>
|
|
116
|
+
<ModalButtons.Button onClick={onClose}>
|
|
117
|
+
{cancelLabel}
|
|
118
|
+
</ModalButtons.Button>
|
|
119
|
+
{readOnly
|
|
120
|
+
? null
|
|
121
|
+
: (
|
|
122
|
+
<ModalButtons.Button variant={"main"} onClick={handleConfirm}>
|
|
123
|
+
{okLabel}
|
|
124
|
+
</ModalButtons.Button>
|
|
125
|
+
)}
|
|
126
|
+
</ModalButtons>
|
|
127
|
+
</Modal>
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export { TimePickerModal };
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useLayoutEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
StyledWheelFocusRing,
|
|
5
|
+
StyledWheelItem,
|
|
6
|
+
StyledWheelPadder,
|
|
7
|
+
StyledWheelViewport,
|
|
8
|
+
StyledWheelWrapper,
|
|
9
|
+
} from "./TimePicker.styled";
|
|
10
|
+
import { padTwo } from "./utils";
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
count: number;
|
|
14
|
+
step: number;
|
|
15
|
+
value: number;
|
|
16
|
+
onChange: (v: number) => void;
|
|
17
|
+
ariaLabel: string;
|
|
18
|
+
autoFocus?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const PAGE_JUMP = 3;
|
|
22
|
+
|
|
23
|
+
const Wheel = ({ count, step, value, onChange, ariaLabel, autoFocus = false }: Props) => {
|
|
24
|
+
const viewportRef = useRef<HTMLDivElement>(null);
|
|
25
|
+
const itemRef = useRef<HTMLDivElement>(null);
|
|
26
|
+
const itemHeightRef = useRef<number>(0);
|
|
27
|
+
const scrollRafRef = useRef<number | null>(null);
|
|
28
|
+
const valueRef = useRef(value);
|
|
29
|
+
valueRef.current = value;
|
|
30
|
+
|
|
31
|
+
const items = Math.ceil(count / step);
|
|
32
|
+
const lastValue = (items - 1) * step;
|
|
33
|
+
|
|
34
|
+
const valueToIndex = useCallback((v: number) => {
|
|
35
|
+
const idx = Math.round(v / step);
|
|
36
|
+
if (idx < 0) {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
if (idx >= items) {
|
|
40
|
+
return items - 1;
|
|
41
|
+
}
|
|
42
|
+
return idx;
|
|
43
|
+
}, [items, step]);
|
|
44
|
+
|
|
45
|
+
const scrollToValue = useCallback((v: number, behavior: ScrollBehavior) => {
|
|
46
|
+
const vp = viewportRef.current;
|
|
47
|
+
const h = itemHeightRef.current;
|
|
48
|
+
if (!vp || h === 0) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const idx = valueToIndex(v);
|
|
52
|
+
vp.scrollTo({ top: idx * h, behavior });
|
|
53
|
+
}, [valueToIndex]);
|
|
54
|
+
|
|
55
|
+
useLayoutEffect(() => {
|
|
56
|
+
const item = itemRef.current;
|
|
57
|
+
if (!item) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
itemHeightRef.current = item.getBoundingClientRect().height;
|
|
61
|
+
scrollToValue(valueRef.current, "auto");
|
|
62
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
63
|
+
}, []);
|
|
64
|
+
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const item = itemRef.current;
|
|
67
|
+
if (!item || typeof ResizeObserver === "undefined") {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const ro = new ResizeObserver((entries) => {
|
|
71
|
+
const entry = entries[0];
|
|
72
|
+
if (!entry) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const h = entry.contentRect.height;
|
|
76
|
+
if (h > 0 && h !== itemHeightRef.current) {
|
|
77
|
+
itemHeightRef.current = h;
|
|
78
|
+
scrollToValue(valueRef.current, "auto");
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
ro.observe(item);
|
|
82
|
+
return () => {
|
|
83
|
+
ro.disconnect();
|
|
84
|
+
};
|
|
85
|
+
}, [scrollToValue]);
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
const vp = viewportRef.current;
|
|
89
|
+
const h = itemHeightRef.current;
|
|
90
|
+
if (!vp || h === 0) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const currentIdx = Math.round(vp.scrollTop / h);
|
|
94
|
+
const desiredIdx = valueToIndex(value);
|
|
95
|
+
if (currentIdx !== desiredIdx) {
|
|
96
|
+
scrollToValue(value, "smooth");
|
|
97
|
+
}
|
|
98
|
+
}, [value, valueToIndex, scrollToValue]);
|
|
99
|
+
|
|
100
|
+
const handleScroll = useCallback(() => {
|
|
101
|
+
const vp = viewportRef.current;
|
|
102
|
+
if (!vp) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (scrollRafRef.current != null) {
|
|
106
|
+
cancelAnimationFrame(scrollRafRef.current);
|
|
107
|
+
}
|
|
108
|
+
scrollRafRef.current = requestAnimationFrame(() => {
|
|
109
|
+
scrollRafRef.current = null;
|
|
110
|
+
const vpInner = viewportRef.current;
|
|
111
|
+
const h = itemHeightRef.current;
|
|
112
|
+
if (!vpInner || h === 0) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const rawIdx = Math.round(vpInner.scrollTop / h);
|
|
116
|
+
const clamped = Math.max(0, Math.min(items - 1, rawIdx));
|
|
117
|
+
const newValue = clamped * step;
|
|
118
|
+
if (newValue !== valueRef.current) {
|
|
119
|
+
onChange(newValue);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}, [items, step, onChange]);
|
|
123
|
+
|
|
124
|
+
const handleKeyDown = useCallback((e: React.KeyboardEvent<HTMLDivElement>) => {
|
|
125
|
+
let next: number;
|
|
126
|
+
switch (e.key) {
|
|
127
|
+
case "ArrowDown":
|
|
128
|
+
next = valueRef.current + step;
|
|
129
|
+
break;
|
|
130
|
+
case "ArrowUp":
|
|
131
|
+
next = valueRef.current - step;
|
|
132
|
+
break;
|
|
133
|
+
case "PageDown":
|
|
134
|
+
next = valueRef.current + (step * PAGE_JUMP);
|
|
135
|
+
break;
|
|
136
|
+
case "PageUp":
|
|
137
|
+
next = valueRef.current - (step * PAGE_JUMP);
|
|
138
|
+
break;
|
|
139
|
+
case "Home":
|
|
140
|
+
next = 0;
|
|
141
|
+
break;
|
|
142
|
+
case "End":
|
|
143
|
+
next = lastValue;
|
|
144
|
+
break;
|
|
145
|
+
default:
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
const clamped = Math.max(0, Math.min(lastValue, next));
|
|
150
|
+
if (clamped !== valueRef.current) {
|
|
151
|
+
onChange(clamped);
|
|
152
|
+
}
|
|
153
|
+
}, [step, lastValue, onChange]);
|
|
154
|
+
|
|
155
|
+
useEffect(() => () => {
|
|
156
|
+
if (scrollRafRef.current != null) {
|
|
157
|
+
cancelAnimationFrame(scrollRafRef.current);
|
|
158
|
+
}
|
|
159
|
+
}, []);
|
|
160
|
+
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
if (autoFocus) {
|
|
163
|
+
viewportRef.current?.focus({ preventScroll: true });
|
|
164
|
+
}
|
|
165
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
166
|
+
}, []);
|
|
167
|
+
|
|
168
|
+
const itemElems: React.ReactElement[] = [];
|
|
169
|
+
for (let i = 0; i < items; i++) {
|
|
170
|
+
const v = i * step;
|
|
171
|
+
itemElems.push(
|
|
172
|
+
<StyledWheelItem key={i} ref={i === 0 ? itemRef : undefined}>
|
|
173
|
+
{padTwo(v)}
|
|
174
|
+
</StyledWheelItem>,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<StyledWheelWrapper>
|
|
180
|
+
<StyledWheelViewport
|
|
181
|
+
ref={viewportRef}
|
|
182
|
+
onScroll={handleScroll}
|
|
183
|
+
onKeyDown={handleKeyDown}
|
|
184
|
+
role={"spinbutton"}
|
|
185
|
+
aria-label={ariaLabel}
|
|
186
|
+
aria-valuemin={0}
|
|
187
|
+
aria-valuemax={lastValue}
|
|
188
|
+
aria-valuenow={value}
|
|
189
|
+
aria-valuetext={padTwo(value)}
|
|
190
|
+
tabIndex={0}
|
|
191
|
+
>
|
|
192
|
+
<StyledWheelPadder />
|
|
193
|
+
{itemElems}
|
|
194
|
+
<StyledWheelPadder />
|
|
195
|
+
</StyledWheelViewport>
|
|
196
|
+
<StyledWheelFocusRing aria-hidden={true} />
|
|
197
|
+
</StyledWheelWrapper>
|
|
198
|
+
);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export { Wheel };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Pads a number to a 2-digit string with a leading zero (e.g. `7` → `"07"`). */
|
|
2
|
+
const padTwo = (n: number): string => n.toString().padStart(2, "0");
|
|
3
|
+
|
|
4
|
+
/** Clamps each completed pair in the digit buffer to a valid range: HH≤23, MM≤59, SS≤59. */
|
|
5
|
+
const clampDigits = (digits: string, withSeconds: boolean): string => {
|
|
6
|
+
if (digits.length < 2) {
|
|
7
|
+
return digits;
|
|
8
|
+
}
|
|
9
|
+
let hh = parseInt(digits.slice(0, 2), 10);
|
|
10
|
+
if (hh > 23) {
|
|
11
|
+
hh = 23;
|
|
12
|
+
}
|
|
13
|
+
let out = padTwo(hh);
|
|
14
|
+
if (digits.length < 4) {
|
|
15
|
+
return out + digits.slice(2);
|
|
16
|
+
}
|
|
17
|
+
let mm = parseInt(digits.slice(2, 4), 10);
|
|
18
|
+
if (mm > 59) {
|
|
19
|
+
mm = 59;
|
|
20
|
+
}
|
|
21
|
+
out += padTwo(mm);
|
|
22
|
+
if (!withSeconds || digits.length < 6) {
|
|
23
|
+
return out + digits.slice(4);
|
|
24
|
+
}
|
|
25
|
+
let ss = parseInt(digits.slice(4, 6), 10);
|
|
26
|
+
if (ss > 59) {
|
|
27
|
+
ss = 59;
|
|
28
|
+
}
|
|
29
|
+
out += padTwo(ss);
|
|
30
|
+
return out;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Parses a free-form time string into a clamped 2/4/6-digit buffer.
|
|
35
|
+
* Colon-aware: each colon-separated segment is padded to 2 digits, so `"3:40"` → `"0340"`.
|
|
36
|
+
* Used by the modal to extract HH/MM/SS from whatever the user typed.
|
|
37
|
+
*/
|
|
38
|
+
const parseTimeText = (text: string, withSeconds: boolean): string => {
|
|
39
|
+
if (!text) {
|
|
40
|
+
return "";
|
|
41
|
+
}
|
|
42
|
+
const max = withSeconds ? 6 : 4;
|
|
43
|
+
const segments = text.split(":");
|
|
44
|
+
let raw: string;
|
|
45
|
+
if (segments.length === 1) {
|
|
46
|
+
raw = (segments[0] ?? "").replace(/\D/gu, "");
|
|
47
|
+
if (raw.length === 1) {
|
|
48
|
+
raw = "0" + raw;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
raw = segments.map((s) => {
|
|
53
|
+
const d = s.replace(/\D/gu, "");
|
|
54
|
+
if (d.length === 0) {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
if (d.length === 1) {
|
|
58
|
+
return "0" + d;
|
|
59
|
+
}
|
|
60
|
+
return d.slice(0, 2);
|
|
61
|
+
}).join("");
|
|
62
|
+
}
|
|
63
|
+
return clampDigits(raw.slice(0, max), withSeconds);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { padTwo, parseTimeText };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { forwardRef } from "react";
|
|
2
|
+
|
|
3
|
+
interface Props {
|
|
4
|
+
className?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const Clock = forwardRef<SVGSVGElement, Props>((props, ref) => {
|
|
8
|
+
return (
|
|
9
|
+
<svg
|
|
10
|
+
ref={ref}
|
|
11
|
+
width={"16"}
|
|
12
|
+
height={"16"}
|
|
13
|
+
viewBox={"0 0 16 16"}
|
|
14
|
+
xmlns={"http://www.w3.org/2000/svg"}
|
|
15
|
+
className={props.className}
|
|
16
|
+
>
|
|
17
|
+
<circle
|
|
18
|
+
cx={"8"}
|
|
19
|
+
cy={"8"}
|
|
20
|
+
r={"6.5"}
|
|
21
|
+
fill={"none"}
|
|
22
|
+
stroke={"currentColor"}
|
|
23
|
+
strokeWidth={"1.5"}
|
|
24
|
+
/>
|
|
25
|
+
<path
|
|
26
|
+
fill={"none"}
|
|
27
|
+
stroke={"currentColor"}
|
|
28
|
+
strokeWidth={"1.5"}
|
|
29
|
+
strokeLinecap={"round"}
|
|
30
|
+
d={"M8 4.5V8l2.5 1.75"}
|
|
31
|
+
/>
|
|
32
|
+
</svg>
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
Clock.displayName = "Clock";
|
|
37
|
+
|
|
38
|
+
export { Clock };
|
|
@@ -3,6 +3,7 @@ import React, { forwardRef } from "react";
|
|
|
3
3
|
import { Back } from "./Back";
|
|
4
4
|
import { Battery } from "./Battery";
|
|
5
5
|
import { Checkmark } from "./Checkmark";
|
|
6
|
+
import { Clock } from "./Clock";
|
|
6
7
|
import { Config } from "./Config";
|
|
7
8
|
import { Dots } from "./Dots";
|
|
8
9
|
import { Forward } from "./Forward";
|
|
@@ -20,6 +21,7 @@ enum ICON {
|
|
|
20
21
|
trash = "trash",
|
|
21
22
|
config = "config",
|
|
22
23
|
dots = "dots",
|
|
24
|
+
clock = "clock",
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
interface Props {
|
|
@@ -39,6 +41,7 @@ const iconsMap = new Map<ICON, IconComponent>([
|
|
|
39
41
|
[ICON.trash, Trash],
|
|
40
42
|
[ICON.config, Config],
|
|
41
43
|
[ICON.dots, Dots],
|
|
44
|
+
[ICON.clock, Clock],
|
|
42
45
|
]);
|
|
43
46
|
|
|
44
47
|
const Icon = forwardRef<SVGSVGElement, Props>(({ name: iconName, ...props }, ref) => {
|