@yamada-ui/react 2.1.3-dev-20260315020004 → 2.1.3-dev-20260315080238
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/airy/airy.cjs.map +1 -1
- package/dist/cjs/components/autocomplete/use-autocomplete.cjs +1 -1
- package/dist/cjs/components/autocomplete/use-autocomplete.cjs.map +1 -1
- package/dist/cjs/components/chart/chart.cjs +1 -1
- package/dist/cjs/components/chart/chart.cjs.map +1 -1
- package/dist/cjs/components/date-picker/use-date-picker.cjs +1 -1
- package/dist/cjs/components/date-picker/use-date-picker.cjs.map +1 -1
- package/dist/cjs/components/dropzone/dropzone.cjs.map +1 -1
- package/dist/cjs/components/flip/flip.cjs.map +1 -1
- package/dist/cjs/components/native-popover/use-native-popover.cjs +1 -1
- package/dist/cjs/components/native-popover/use-native-popover.cjs.map +1 -1
- package/dist/cjs/components/popover/use-popover.cjs +1 -1
- package/dist/cjs/components/popover/use-popover.cjs.map +1 -1
- package/dist/cjs/components/rotate/rotate.cjs.map +1 -1
- package/dist/cjs/components/snacks/snacks.cjs +1 -1
- package/dist/cjs/components/snacks/snacks.cjs.map +1 -1
- package/dist/cjs/components/snacks/use-snacks.cjs.map +1 -1
- package/dist/cjs/components/stack/stack.cjs +1 -1
- package/dist/cjs/components/stack/stack.cjs.map +1 -1
- package/dist/cjs/core/components/use-component-style.cjs +1 -1
- package/dist/cjs/core/components/use-component-style.cjs.map +1 -1
- package/dist/cjs/core/system/color-mode-provider.cjs +1 -1
- package/dist/cjs/core/system/color-mode-provider.cjs.map +1 -1
- package/dist/cjs/core/system/styled.cjs +1 -1
- package/dist/cjs/core/system/styled.cjs.map +1 -1
- package/dist/cjs/core/system/theme-provider.cjs +1 -1
- package/dist/cjs/core/system/theme-provider.cjs.map +1 -1
- package/dist/cjs/core/system/var.cjs +2 -2
- package/dist/cjs/core/system/var.cjs.map +1 -1
- package/dist/cjs/utils/effect.cjs +1 -1
- package/dist/cjs/utils/effect.cjs.map +1 -1
- package/dist/esm/components/airy/airy.js.map +1 -1
- package/dist/esm/components/autocomplete/use-autocomplete.js +1 -1
- package/dist/esm/components/autocomplete/use-autocomplete.js.map +1 -1
- package/dist/esm/components/chart/chart.js +1 -1
- package/dist/esm/components/chart/chart.js.map +1 -1
- package/dist/esm/components/date-picker/use-date-picker.js +1 -1
- package/dist/esm/components/date-picker/use-date-picker.js.map +1 -1
- package/dist/esm/components/dropzone/dropzone.js.map +1 -1
- package/dist/esm/components/flip/flip.js.map +1 -1
- package/dist/esm/components/native-popover/use-native-popover.js +1 -1
- package/dist/esm/components/native-popover/use-native-popover.js.map +1 -1
- package/dist/esm/components/popover/use-popover.js +1 -1
- package/dist/esm/components/popover/use-popover.js.map +1 -1
- package/dist/esm/components/rotate/rotate.js.map +1 -1
- package/dist/esm/components/snacks/snacks.js +1 -1
- package/dist/esm/components/snacks/snacks.js.map +1 -1
- package/dist/esm/components/snacks/use-snacks.js.map +1 -1
- package/dist/esm/components/stack/stack.js +1 -1
- package/dist/esm/components/stack/stack.js.map +1 -1
- package/dist/esm/core/components/use-component-style.js +1 -1
- package/dist/esm/core/components/use-component-style.js.map +1 -1
- package/dist/esm/core/system/color-mode-provider.js +1 -1
- package/dist/esm/core/system/color-mode-provider.js.map +1 -1
- package/dist/esm/core/system/styled.js +1 -1
- package/dist/esm/core/system/styled.js.map +1 -1
- package/dist/esm/core/system/theme-provider.js +1 -1
- package/dist/esm/core/system/theme-provider.js.map +1 -1
- package/dist/esm/core/system/var.js +2 -2
- package/dist/esm/core/system/var.js.map +1 -1
- package/dist/esm/utils/effect.js +1 -1
- package/dist/esm/utils/effect.js.map +1 -1
- package/dist/types/components/accordion/accordion.d.ts +2 -2
- package/dist/types/components/accordion/accordion.style.d.ts +1 -1
- package/dist/types/components/accordion/use-accordion.d.ts +11 -11
- package/dist/types/components/airy/airy.d.ts +3 -3
- package/dist/types/components/alert/alert.d.ts +2 -2
- package/dist/types/components/alpha-slider/alpha-slider.d.ts +2 -2
- package/dist/types/components/aspect-ratio/aspect-ratio.d.ts +2 -2
- package/dist/types/components/autocomplete/autocomplete.d.ts +2 -2
- package/dist/types/components/autocomplete/autocomplete.style.d.ts +1 -1
- package/dist/types/components/autocomplete/use-autocomplete.d.ts +5 -5
- package/dist/types/components/avatar/avatar.d.ts +5 -5
- package/dist/types/components/avatar/avatar.style.d.ts +1 -1
- package/dist/types/components/avatar/use-avatar-group.d.ts +2 -2
- package/dist/types/components/badge/badge.d.ts +2 -2
- package/dist/types/components/bleed/bleed.d.ts +2 -2
- package/dist/types/components/blockquote/blockquote.d.ts +2 -2
- package/dist/types/components/breadcrumb/breadcrumb.d.ts +2 -2
- package/dist/types/components/breadcrumb/breadcrumb.style.d.ts +1 -1
- package/dist/types/components/breadcrumb/use-breadcrumb.d.ts +2 -2
- package/dist/types/components/button/button.d.ts +2 -2
- package/dist/types/components/button/icon-button.d.ts +2 -2
- package/dist/types/components/calendar/calendar.d.ts +2 -2
- package/dist/types/components/calendar/calendar.style.d.ts +2 -2
- package/dist/types/components/calendar/use-calendar.d.ts +8 -8
- package/dist/types/components/card/card.d.ts +2 -2
- package/dist/types/components/carousel/carousel.d.ts +2 -2
- package/dist/types/components/carousel/carousel.style.d.ts +2 -2
- package/dist/types/components/carousel/use-carousel.d.ts +3 -3
- package/dist/types/components/center/center.d.ts +2 -2
- package/dist/types/components/chart/area-chart.d.ts +2 -2
- package/dist/types/components/chart/bar-chart.d.ts +2 -2
- package/dist/types/components/chart/chart.d.ts +5 -5
- package/dist/types/components/chart/composed-chart.d.ts +2 -2
- package/dist/types/components/chart/donut-chart.d.ts +2 -2
- package/dist/types/components/chart/pie-chart.d.ts +2 -2
- package/dist/types/components/chart/radar-chart.d.ts +2 -2
- package/dist/types/components/chart/use-chart.d.ts +2 -2
- package/dist/types/components/checkbox/checkbox.d.ts +5 -5
- package/dist/types/components/checkbox/checkbox.style.d.ts +1 -1
- package/dist/types/components/checkbox/use-checkbox-group.d.ts +2 -2
- package/dist/types/components/checkbox-card/checkbox-card.d.ts +5 -5
- package/dist/types/components/checkbox-card/checkbox-card.style.d.ts +1 -1
- package/dist/types/components/circle-progress/circle-progress.d.ts +2 -2
- package/dist/types/components/close-button/close-button.d.ts +2 -2
- package/dist/types/components/code/code.d.ts +2 -2
- package/dist/types/components/collapse/collapse.d.ts +2 -2
- package/dist/types/components/color-picker/color-picker.d.ts +2 -2
- package/dist/types/components/color-picker/color-picker.style.d.ts +1 -1
- package/dist/types/components/color-picker/use-color-picker.d.ts +2 -2
- package/dist/types/components/color-selector/color-selector.d.ts +2 -2
- package/dist/types/components/color-selector/color-selector.style.d.ts +2 -2
- package/dist/types/components/color-selector/use-color-selector.d.ts +3 -3
- package/dist/types/components/color-swatch/color-swatch.d.ts +2 -2
- package/dist/types/components/container/container.d.ts +2 -2
- package/dist/types/components/data-list/data-list.d.ts +2 -2
- package/dist/types/components/data-list/data-list.style.d.ts +1 -1
- package/dist/types/components/date-picker/date-picker.d.ts +2 -2
- package/dist/types/components/date-picker/date-picker.style.d.ts +1 -1
- package/dist/types/components/date-picker/use-date-picker.d.ts +4 -4
- package/dist/types/components/drawer/drawer.d.ts +2 -2
- package/dist/types/components/dropzone/dropzone.d.ts +4 -5
- package/dist/types/components/editable/editable.d.ts +4 -4
- package/dist/types/components/editable/use-editable.d.ts +2 -2
- package/dist/types/components/em/em.d.ts +2 -2
- package/dist/types/components/empty-state/empty-state.d.ts +2 -2
- package/dist/types/components/empty-state/empty-state.style.d.ts +2 -2
- package/dist/types/components/fade/fade.d.ts +2 -2
- package/dist/types/components/field/field.d.ts +3 -3
- package/dist/types/components/field/use-field-props.d.ts +4 -4
- package/dist/types/components/fieldset/fieldset.d.ts +3 -3
- package/dist/types/components/file-button/file-button.d.ts +2 -2
- package/dist/types/components/file-button/use-file-button.d.ts +17 -17
- package/dist/types/components/file-input/file-input.d.ts +2 -2
- package/dist/types/components/file-input/use-file-input.d.ts +17 -17
- package/dist/types/components/flex/flex.d.ts +2 -2
- package/dist/types/components/flip/flip.d.ts +5 -5
- package/dist/types/components/flip/flip.style.d.ts +1 -1
- package/dist/types/components/float/float.d.ts +2 -2
- package/dist/types/components/form/form.d.ts +3 -3
- package/dist/types/components/format/format-byte.d.ts +4 -4
- package/dist/types/components/format/format-date-time.d.ts +4 -4
- package/dist/types/components/format/format-number.d.ts +2 -2
- package/dist/types/components/grid/grid-item.d.ts +2 -2
- package/dist/types/components/grid/grid.d.ts +2 -2
- package/dist/types/components/group/group.d.ts +2 -2
- package/dist/types/components/group/use-group.d.ts +2 -2
- package/dist/types/components/heading/heading.d.ts +2 -2
- package/dist/types/components/hue-slider/hue-slider.d.ts +3 -3
- package/dist/types/components/icon/icon.d.ts +5 -5
- package/dist/types/components/image/image.d.ts +2 -2
- package/dist/types/components/indicator/indicator.d.ts +4 -4
- package/dist/types/components/infinite-scroll-area/infinite-scroll-area.d.ts +2 -2
- package/dist/types/components/input/input-addon.d.ts +2 -2
- package/dist/types/components/input/input-element.d.ts +2 -2
- package/dist/types/components/input/input.d.ts +2 -2
- package/dist/types/components/kbd/kbd.d.ts +2 -2
- package/dist/types/components/link/link.d.ts +2 -2
- package/dist/types/components/link-box/link-box.d.ts +2 -2
- package/dist/types/components/list/list.d.ts +2 -2
- package/dist/types/components/list/list.style.d.ts +2 -2
- package/dist/types/components/loading/loading-provider.d.ts +2 -2
- package/dist/types/components/loading/loading.d.ts +3 -3
- package/dist/types/components/mark/mark.d.ts +2 -2
- package/dist/types/components/menu/menu.d.ts +2 -2
- package/dist/types/components/menu/menu.style.d.ts +2 -2
- package/dist/types/components/menu/use-menu.d.ts +11 -11
- package/dist/types/components/modal/modal.d.ts +2 -2
- package/dist/types/components/native-accordion/native-accordion.d.ts +2 -2
- package/dist/types/components/native-accordion/native-accordion.style.d.ts +2 -2
- package/dist/types/components/native-accordion/use-native-accordion.d.ts +2 -2
- package/dist/types/components/native-popover/native-popover.d.ts +2 -2
- package/dist/types/components/native-select/native-select.d.ts +2 -2
- package/dist/types/components/native-table/native-table.d.ts +4 -4
- package/dist/types/components/notice/notice.style.d.ts +1 -1
- package/dist/types/components/number-input/number-input.d.ts +2 -2
- package/dist/types/components/number-input/number-input.style.d.ts +1 -1
- package/dist/types/components/pagination/pagination.d.ts +2 -2
- package/dist/types/components/pagination/pagination.style.d.ts +1 -1
- package/dist/types/components/pagination/use-pagination.d.ts +2 -2
- package/dist/types/components/password-input/password-input.d.ts +2 -2
- package/dist/types/components/password-input/strength-meter.d.ts +2 -2
- package/dist/types/components/password-input/strength-meter.style.d.ts +1 -1
- package/dist/types/components/password-input/use-password-input.d.ts +2 -2
- package/dist/types/components/pin-input/pin-input.d.ts +2 -2
- package/dist/types/components/pin-input/use-pin-input.d.ts +7 -7
- package/dist/types/components/popover/popover.d.ts +2 -2
- package/dist/types/components/progress/progress.d.ts +4 -4
- package/dist/types/components/progress/use-progress.d.ts +706 -706
- package/dist/types/components/qr-code/qr-code.d.ts +2 -2
- package/dist/types/components/radio/radio.d.ts +5 -5
- package/dist/types/components/radio/radio.style.d.ts +1 -1
- package/dist/types/components/radio/use-radio-group.d.ts +2 -2
- package/dist/types/components/radio-card/radio-card.d.ts +5 -5
- package/dist/types/components/radio-card/radio-card.style.d.ts +1 -1
- package/dist/types/components/rating/rating.style.d.ts +2 -2
- package/dist/types/components/rating/use-rating.d.ts +7 -7
- package/dist/types/components/reorder/reorder.d.ts +2 -2
- package/dist/types/components/reorder/reorder.style.d.ts +1 -1
- package/dist/types/components/reorder/use-reorder.d.ts +4 -4
- package/dist/types/components/resizable/resizable.d.ts +2 -2
- package/dist/types/components/resizable/resizable.style.d.ts +2 -2
- package/dist/types/components/resizable/use-resizable.d.ts +2 -2
- package/dist/types/components/ripple/ripple.d.ts +2 -2
- package/dist/types/components/ripple/use-ripple.d.ts +2 -2
- package/dist/types/components/rotate/rotate.d.ts +3 -3
- package/dist/types/components/saturation-slider/saturation-slider.d.ts +2 -2
- package/dist/types/components/saturation-slider/use-saturation-slider.d.ts +2 -2
- package/dist/types/components/scroll-area/scroll-area.d.ts +2 -2
- package/dist/types/components/segmented-control/segmented-control.d.ts +2 -2
- package/dist/types/components/segmented-control/segmented-control.style.d.ts +2 -2
- package/dist/types/components/segmented-control/use-segmented-control.d.ts +9 -9
- package/dist/types/components/select/select.d.ts +2 -2
- package/dist/types/components/select/select.style.d.ts +1 -1
- package/dist/types/components/select/use-select.d.ts +4 -4
- package/dist/types/components/separator/separator.d.ts +2 -2
- package/dist/types/components/simple-grid/simple-grid.d.ts +2 -2
- package/dist/types/components/skeleton/skeleton.d.ts +2 -2
- package/dist/types/components/slide/slide.d.ts +2 -2
- package/dist/types/components/slide-fade/slide-fade.d.ts +2 -2
- package/dist/types/components/slider/slider.d.ts +2 -2
- package/dist/types/components/slider/use-slider.d.ts +2 -2
- package/dist/types/components/stack/h-stack.d.ts +2 -2
- package/dist/types/components/stack/stack.d.ts +2 -2
- package/dist/types/components/stack/v-stack.d.ts +2 -2
- package/dist/types/components/stack/z-stack.d.ts +2 -2
- package/dist/types/components/stat/stat.d.ts +2 -2
- package/dist/types/components/stat/stat.style.d.ts +2 -2
- package/dist/types/components/status/status.d.ts +2 -2
- package/dist/types/components/status/status.style.d.ts +2 -2
- package/dist/types/components/steps/steps.d.ts +2 -2
- package/dist/types/components/steps/steps.style.d.ts +1 -1
- package/dist/types/components/steps/use-steps.d.ts +10 -10
- package/dist/types/components/switch/switch.d.ts +2 -2
- package/dist/types/components/table/table.d.ts +2 -2
- package/dist/types/components/tabs/tabs.d.ts +2 -2
- package/dist/types/components/tabs/tabs.style.d.ts +1 -1
- package/dist/types/components/tabs/use-tabs.d.ts +16 -16
- package/dist/types/components/tag/tag.d.ts +2 -2
- package/dist/types/components/text/text.d.ts +2 -2
- package/dist/types/components/textarea/textarea.d.ts +2 -2
- package/dist/types/components/textarea/use-autosize.d.ts +2 -2
- package/dist/types/components/timeline/timeline.d.ts +4 -4
- package/dist/types/components/timeline/timeline.style.d.ts +2 -2
- package/dist/types/components/toggle/toggle.d.ts +5 -5
- package/dist/types/components/toggle/use-toggle-group.d.ts +2 -2
- package/dist/types/components/toggle/use-toggle.d.ts +2 -2
- package/dist/types/components/tooltip/tooltip.d.ts +2 -2
- package/dist/types/components/visually-hidden/visually-hidden.d.ts +2 -2
- package/dist/types/components/wrap/wrap.d.ts +2 -2
- package/dist/types/core/components/create-component.d.ts +7 -7
- package/dist/types/core/system/color-mode-provider.d.ts +2 -2
- package/dist/types/core/system/storage-script.d.ts +3 -3
- package/dist/types/core/system/styled.d.ts +2 -2
- package/dist/types/core/system/system-provider.d.ts +2 -2
- package/dist/types/hooks/use-breakpoint/use-breakpoint-state.d.ts +2 -2
- package/dist/types/hooks/use-clickable/index.d.ts +9 -9
- package/dist/types/hooks/use-clipboard/index.d.ts +2 -2
- package/dist/types/hooks/use-combobox/index.d.ts +12 -12
- package/dist/types/hooks/use-counter/index.d.ts +2 -2
- package/dist/types/hooks/use-descendants/index.d.ts +2 -2
- package/dist/types/hooks/use-field-sizing/index.d.ts +2 -2
- package/dist/types/hooks/use-hover/index.d.ts +2 -2
- package/dist/types/hooks/use-popper/index.d.ts +2 -2
- package/dist/types/hooks/use-resize-observer/index.d.ts +3 -3
- package/dist/types/providers/i18n-provider/i18n-provider.d.ts +3 -3
- package/dist/types/providers/ui-provider/ui-provider.d.ts +2 -2
- package/dist/types/utils/children.d.ts +2 -2
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"airy.cjs","names":["createComponent","airyStyle","useControllableState","motion","useInjectVarsIntoCss","useInjectVarsIntoProps"],"sources":["../../../../src/components/airy/airy.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ReactNode } from \"react\"\nimport type { KeyframeIdent, ThemeProps } from \"../../core\"\nimport type { HTMLMotionProps } from \"../motion\"\nimport type { AiryStyle } from \"./airy.style\"\nimport { useAnimation } from \"motion/react\"\nimport { useCallback } from \"react\"\nimport {\n createComponent,\n useInjectVarsIntoCss,\n useInjectVarsIntoProps,\n} from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { dataAttr, handlerAll } from \"../../utils\"\nimport { motion } from \"../motion\"\nimport { airyStyle } from \"./airy.style\"\n\nexport interface AiryProps\n extends Omit<HTMLMotionProps<\"button\">, \"onChange\">, ThemeProps<AiryStyle> {\n /**\n * Passing React elements to \"from\" is required.\n */\n from: ReactNode\n /**\n * Passing React elements to \"to\" is required.\n */\n to: ReactNode\n /**\n * You can set the initial state.\n *\n * @default 'from'\n */\n defaultValue?: KeyframeIdent\n /**\n *
|
|
1
|
+
{"version":3,"file":"airy.cjs","names":["createComponent","airyStyle","useControllableState","motion","useInjectVarsIntoCss","useInjectVarsIntoProps"],"sources":["../../../../src/components/airy/airy.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ReactNode } from \"react\"\nimport type { KeyframeIdent, ThemeProps } from \"../../core\"\nimport type { HTMLMotionProps } from \"../motion\"\nimport type { AiryStyle } from \"./airy.style\"\nimport { useAnimation } from \"motion/react\"\nimport { useCallback } from \"react\"\nimport {\n createComponent,\n useInjectVarsIntoCss,\n useInjectVarsIntoProps,\n} from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { dataAttr, handlerAll } from \"../../utils\"\nimport { motion } from \"../motion\"\nimport { airyStyle } from \"./airy.style\"\n\nexport interface AiryProps\n extends Omit<HTMLMotionProps<\"button\">, \"onChange\">, ThemeProps<AiryStyle> {\n /**\n * Passing React elements to \"from\" is required.\n */\n from: ReactNode\n /**\n * Passing React elements to \"to\" is required.\n */\n to: ReactNode\n /**\n * You can set the initial state.\n *\n * @default 'from'\n */\n defaultValue?: KeyframeIdent\n /**\n * The animation delay.\n *\n * @default 0\n */\n delay?: number\n /**\n * If `true`, the component is disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The animation duration.\n *\n * @default 0.2\n */\n duration?: number\n /**\n * If `true`, the component is readonly.\n *\n * @default false\n */\n readOnly?: boolean\n /**\n * Use this when you want to control the animation from outside the component.\n */\n value?: KeyframeIdent\n /**\n * This is a callback function that is called when the animation state changes.\n */\n onChange?: (value: KeyframeIdent) => void\n}\n\nconst {\n PropsContext: AiryPropsContext,\n usePropsContext: useAiryPropsContext,\n withContext,\n} = createComponent<AiryProps, AiryStyle>(\"airy\", airyStyle)\n\nexport { AiryPropsContext, useAiryPropsContext }\n\n/**\n * `Airy` is a component that creates an airy animation, switching between two elements when one is clicked.\n *\n * @see https://yamada-ui.com/docs/components/airy\n */\nexport const Airy = withContext<\"button\", AiryProps>(\n ({\n defaultValue = \"from\",\n delay = 0,\n disabled,\n duration = 0.2,\n from,\n readOnly,\n to,\n value: valueProp,\n onChange,\n onClick: onClickProp,\n ...rest\n }) => {\n const opacity = \"var(--opacity)\"\n const animate = useAnimation()\n const [value, setValue] = useControllableState<KeyframeIdent>({\n defaultValue,\n value: valueProp,\n onChange,\n })\n\n const onClick = useCallback(async () => {\n if (readOnly) return\n\n await animate.start({ opacity: 0, transition: { delay, duration } })\n\n setValue((prev) => (prev === \"from\" ? \"to\" : \"from\"))\n\n await animate.start({ opacity, transition: { duration } })\n }, [animate, setValue, readOnly, opacity, duration, delay])\n\n return (\n <motion.button\n type=\"button\"\n data-disabled={dataAttr(disabled)}\n data-readonly={dataAttr(readOnly)}\n data-value={value}\n animate={animate}\n disabled={disabled}\n initial={{ opacity }}\n onClick={handlerAll(onClickProp, onClick)}\n {...rest}\n >\n {value === \"from\" ? from : to}\n </motion.button>\n )\n },\n)(undefined, (props) => {\n const css = useInjectVarsIntoCss(props.css, { opacity: \"opacity\" })\n const rest = useInjectVarsIntoProps(props, { opacity: \"opacity\" })\n\n return { ...rest, css, opacity: \"{opacity}\" }\n})\n"],"mappings":";;;;;;;;;;;;;;;;AAoEA,MAAM,EACJ,cAAc,kBACd,iBAAiB,qBACjB,gBACEA,yCAAsC,QAAQC,6BAAU;;;;;;AAS5D,MAAa,OAAO,aACjB,EACC,eAAe,QACf,QAAQ,GACR,UACA,WAAW,IACX,MACA,UACA,IACA,OAAO,WACP,UACA,SAAS,aACT,GAAG,WACC;CACJ,MAAM,UAAU;CAChB,MAAM,0CAAwB;CAC9B,MAAM,CAAC,OAAO,YAAYC,gEAAoC;EAC5D;EACA,OAAO;EACP;EACD,CAAC;CAEF,MAAM,iCAAsB,YAAY;AACtC,MAAI,SAAU;AAEd,QAAM,QAAQ,MAAM;GAAE,SAAS;GAAG,YAAY;IAAE;IAAO;IAAU;GAAE,CAAC;AAEpE,YAAU,SAAU,SAAS,SAAS,OAAO,OAAQ;AAErD,QAAM,QAAQ,MAAM;GAAE;GAAS,YAAY,EAAE,UAAU;GAAE,CAAC;IACzD;EAAC;EAAS;EAAU;EAAU;EAAS;EAAU;EAAM,CAAC;AAE3D,QACE,2CAACC,uBAAO;EACN,MAAK;EACL,iEAAwB,SAAS;EACjC,iEAAwB,SAAS;EACjC,cAAY;EACH;EACC;EACV,SAAS,EAAE,SAAS;EACpB,2DAAoB,aAAa,QAAQ;EACzC,GAAI;YAEH,UAAU,SAAS,OAAO;GACb;EAGrB,CAAC,SAAY,UAAU;CACtB,MAAM,MAAMC,6CAAqB,MAAM,KAAK,EAAE,SAAS,WAAW,CAAC;AAGnE,QAAO;EAAE,GAFIC,+CAAuB,OAAO,EAAE,SAAS,WAAW,CAAC;EAEhD;EAAK,SAAS;EAAa;EAC7C"}
|
|
@@ -192,7 +192,7 @@ const useAutocomplete = (props = {}) => {
|
|
|
192
192
|
require_dom.runKeyAction(ev, {
|
|
193
193
|
Backspace: (ev$1) => {
|
|
194
194
|
if (!(0, require_utils_index.utils_exports.isArray)(value)) return;
|
|
195
|
-
if (
|
|
195
|
+
if (inputValue$1.length) return;
|
|
196
196
|
ev$1.preventDefault();
|
|
197
197
|
setValue((prev) => prev.slice(0, -1));
|
|
198
198
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-autocomplete.cjs","names":["defaultRender: AutocompleteItemRender","defaultFilter: AutocompleteFilter","items","item","defaultMatcher: AutocompleteMatcher","createContext","useI18n","useFieldProps","valueMap: { [key: string]: ComboboxItemWithValue }","valueMap","useControllableState","useCombobox","value","onClear","inputValue","isComposing","getRootProps: PropGetter","props","getFieldProps: PropGetter","mergeRefs","ref","getInputProps: PropGetter<\"input\">","visuallyHiddenAttributes","getContentProps: PropGetter","getIconProps: PropGetter","runKeyAction","useComboboxItem"],"sources":["../../../../src/components/autocomplete/use-autocomplete.tsx"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n} from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type {\n ComboboxItem,\n ComboboxItemWithValue,\n UseComboboxItemProps,\n UseComboboxProps,\n} from \"../../hooks/use-combobox\"\nimport type { Dict } from \"../../utils\"\nimport type { FieldProps } from \"../field\"\nimport {\n cloneElement,\n isValidElement,\n useCallback,\n useMemo,\n useRef,\n useState,\n} from \"react\"\nimport { useCombobox, useComboboxItem } from \"../../hooks/use-combobox\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n ariaAttr,\n cast,\n contains,\n createContext,\n dataAttr,\n handlerAll,\n isArray,\n isComposing,\n isNumber,\n isString,\n isUndefined,\n mergeRefs,\n runIfFn,\n runKeyAction,\n useUpdateEffect,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface AutocompleteRenderProps extends ComboboxItemWithValue {\n count: number\n focused: boolean\n index: number\n separator: string\n onClear: () => void\n max?: number\n}\n\nexport interface AutocompleteItemRender {\n (props: AutocompleteRenderProps): ReactNode\n}\n\nconst defaultRender: AutocompleteItemRender = ({\n count,\n focused,\n index,\n label,\n max,\n separator,\n}) => {\n const last = count - 1 === index\n\n return (\n <span style={{ marginInlineEnd: \"var(--gap)\" }}>\n {label}\n {((!isNumber(max) || count < max) && focused) || !last ? separator : null}\n </span>\n )\n}\n\nconst getInputValue = (item?: ComboboxItemWithValue) =>\n isString(item?.label) ? item.label : (item?.query ?? \"\")\n\nexport interface AutocompleteFilter {\n (\n inputValue: string,\n items: ComboboxItem[],\n matcher: AutocompleteMatcher,\n ): ComboboxItem[]\n}\n\nconst defaultFilter: AutocompleteFilter = (inputValue, items, matcher) => {\n if (!inputValue.length) return items\n\n return items\n .map((item) => {\n if (\"items\" in item) {\n const items = item.items.filter((item) => {\n if (\"query\" in item) {\n return matcher(inputValue, item.query)\n } else if (isString(item.label)) {\n return matcher(inputValue, item.label)\n }\n })\n\n if (items.length) return { ...item, items }\n } else if (\"query\" in item) {\n if (matcher(inputValue, item.query)) return item\n } else if (isString(item.label)) {\n if (matcher(inputValue, item.label)) return item\n }\n })\n .filter(Boolean) as ComboboxItem[]\n}\n\nexport interface AutocompleteMatcher {\n (input: string, target?: string): boolean\n}\n\nconst defaultMatcher: AutocompleteMatcher = (input, target) =>\n target?.toLowerCase().includes(input.toLowerCase()) ?? false\n\ninterface AutocompleteContext extends Pick<\n UseAutocompleteReturn,\n \"max\" | \"value\"\n> {}\n\nconst [AutocompleteContext, useAutocompleteContext] =\n createContext<AutocompleteContext>({\n name: \"AutocompleteContext\",\n })\n\nexport { AutocompleteContext, useAutocompleteContext }\n\nexport interface UseAutocompleteProps<Multiple extends boolean = false>\n extends\n Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"ref\" | \"value\">,\n Omit<\n UseComboboxProps,\n \"defaultValue\" | \"initialFocusValue\" | \"onChange\" | \"ref\" | \"value\"\n >,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, the autocomplete will allow custom value.\n *\n * @default false\n */\n allowCustomValue?: boolean\n /**\n * If `true`, the autocomplete will be closed when the input value changes.\n *\n * @default false\n */\n closeOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * The initial value of the input.\n */\n defaultInputValue?: string\n /**\n * The initial value of the autocomplete.\n */\n defaultValue?: Multiple extends true ? string[] : string\n /**\n * The message displayed when the search yields no hits.\n *\n * @default 'No results found'\n */\n emptyMessage?: ReactNode\n /**\n * The function to filter the items.\n */\n filter?: AutocompleteFilter\n /**\n * If `true`, the input will be focused when the clear icon is clicked.\n *\n * @default true\n */\n focusOnClear?: boolean\n /**\n * The `id` attribute of the input element.\n */\n id?: string\n /**\n * The value of the input.\n */\n inputValue?: string\n /**\n * If provided, generate options based on items.\n *\n * @default []\n */\n items?: ComboboxItem[]\n /**\n * The function to match the items.\n */\n matcher?: AutocompleteMatcher\n /**\n * The maximum selectable value.\n */\n max?: number\n /**\n * If `true`, the autocomplete will be multiple.\n *\n * @default false\n */\n multiple?: Multiple\n /**\n * The `name` attribute of the input element.\n */\n name?: string\n /**\n * If `true`, the autocomplete will be opened when the input value changes.\n *\n * @default true\n */\n openOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * If `true`, the autocomplete will be opened when the input is focused.\n *\n * @default true\n */\n openOnFocus?: boolean\n /**\n * The placeholder for autocomplete.\n */\n placeholder?: string\n /**\n * The visual separator between each value.\n *\n * @default ','\n */\n separator?: string\n /**\n * The value of the autocomplete.\n */\n value?: Multiple extends true ? string[] : string\n /**\n * The callback invoked when value state changes.\n */\n onChange?: (value: Multiple extends true ? string[] : string) => void\n /**\n * The callback invoked when input value state changes.\n */\n onInputChange?: (value: string) => void\n /**\n * The function to render the selected items.\n */\n render?: (props: AutocompleteRenderProps) => ReactNode\n}\n\nexport const useAutocomplete = <Multiple extends boolean = false>(\n props: UseAutocompleteProps<Multiple> = {},\n) => {\n type MaybeValue = Multiple extends true ? string[] : string\n\n const { t } = useI18n(\"autocomplete\")\n const {\n props: {\n id,\n ref,\n name,\n allowCustomValue = false,\n closeOnChange = false,\n multiple = false,\n closeOnSelect = !multiple,\n defaultInputValue,\n defaultValue = (multiple ? [] : \"\") as MaybeValue,\n disabled,\n emptyMessage = t(\"No results found\"),\n filter = defaultFilter,\n focusOnClear = true,\n inputValue: inputValueProp,\n items = [],\n matcher = defaultMatcher,\n max,\n openOnChange = true,\n openOnClick = true,\n openOnFocus = true,\n placeholder,\n readOnly,\n render = defaultRender,\n required,\n separator = \",\",\n value: valueProp,\n onChange: onChangeProp,\n onInputChange: onInputChangeProp,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const fieldRef = useRef<HTMLDivElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const inputRef = useRef<HTMLInputElement>(null)\n const focusByClickRef = useRef<boolean>(false)\n const valueMap = useMemo<{ [key: string]: ComboboxItemWithValue }>(() => {\n const valueMap: { [key: string]: ComboboxItemWithValue } = {}\n\n items.forEach((item) => {\n if (\"items\" in item) {\n item.items.forEach((item) => {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n })\n } else {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n }\n })\n\n return valueMap\n }, [items])\n const [focused, setFocused] = useState(false)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const [inputValue, setInputValue] = useControllableState({\n defaultValue:\n defaultInputValue ??\n getInputValue(isArray(value) ? undefined : valueMap[value as string]),\n value: inputValueProp,\n onChange: onInputChangeProp,\n })\n const onChange = useCallback(\n (selectedValue: string) => {\n setValue((prev) => {\n if (isArray(prev)) {\n if (prev.includes(selectedValue)) {\n return prev.filter(\n (prevValue) => prevValue !== selectedValue,\n ) as MaybeValue\n } else if (!isNumber(max) || prev.length < max) {\n return [...prev, selectedValue] as MaybeValue\n } else {\n return prev\n }\n } else {\n return selectedValue as MaybeValue\n }\n })\n\n if (isArray(value)) {\n setInputValue(\"\")\n } else {\n const item = valueMap[selectedValue]\n\n setInputValue(getInputValue(item))\n }\n },\n [max, setInputValue, setValue, value, valueMap],\n )\n const {\n activeDescendant,\n descendants,\n interactive,\n open,\n getContentProps: getComboboxContentProps,\n getSeparatorProps,\n getTriggerProps,\n popoverProps,\n onActiveDescendant,\n onClose,\n onOpen,\n onOpenWithActiveDescendant,\n onSelect,\n } = useCombobox({\n closeOnSelect,\n disabled,\n initialFocusValue: isArray(value) ? value[0] : value,\n openOnClick: false,\n openOnEnter: false,\n openOnSpace: false,\n readOnly,\n selectFocusRef: inputRef,\n selectOnSpace: false,\n onChange,\n ...ariaProps,\n ...dataProps,\n ...eventProps,\n ...rest,\n })\n const filteredItems = useMemo<ComboboxItem[]>(() => {\n if (!items.length) return []\n\n return filter(inputValue, items, matcher)\n }, [filter, inputValue, items, matcher])\n const resolvedItems = useMemo<ComboboxItem[]>(() => {\n return filteredItems.length\n ? filteredItems\n : [{ \"data-empty\": \"\", label: emptyMessage }]\n }, [filteredItems, emptyMessage])\n const empty = useMemo(\n () => !resolvedItems.filter(({ hidden }) => !hidden).length,\n [resolvedItems],\n )\n const children = useMemo<ReactNode>(() => {\n if (!isArray(value)) return null\n\n const count = value.length\n\n return value.map((value, index) => {\n const item = valueMap[value] ?? { label: value, value }\n\n const onClear = (ev?: MouseEvent<HTMLElement>) => {\n ev?.preventDefault()\n ev?.stopPropagation()\n\n if (item.value) onChange(item.value)\n }\n\n const component = render({\n count,\n focused,\n index,\n max,\n separator,\n onClear,\n ...item,\n })\n\n if (isValidElement<Dict>(component)) {\n return cloneElement(component, { ...component.props, key: index })\n } else {\n return component\n }\n })\n }, [focused, max, onChange, render, separator, value, valueMap])\n const hasValues = isArray(value) && !!value.length\n\n const onInputChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (isArray(value) && value.length === max) return\n\n if (runIfFn(closeOnChange, ev)) {\n onClose()\n } else if (runIfFn(openOnChange, ev)) {\n onOpen()\n }\n\n activeDescendant.current = null\n\n const inputValue = ev.target.value\n\n setInputValue(inputValue)\n\n if (inputValue.length || isArray(value)) return\n\n setValue(\"\" as MaybeValue)\n },\n [\n activeDescendant,\n closeOnChange,\n max,\n onClose,\n onOpen,\n openOnChange,\n setInputValue,\n setValue,\n value,\n ],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (disabled || isComposing(ev)) return\n\n const inputValue = cast<HTMLInputElement>(ev.target).value\n\n runKeyAction(\n ev,\n {\n Backspace: (ev) => {\n if (!isArray(value)) return\n if (!!inputValue.length) return\n\n ev.preventDefault()\n\n setValue((prev) => prev.slice(0, -1) as MaybeValue)\n },\n Enter: (ev) => {\n if (!open || !inputValue.length || activeDescendant.current) return\n\n const item = filteredItems[0]\n\n if (!item) {\n if (!allowCustomValue || !isArray(value)) return\n\n ev.preventDefault()\n\n onSelect(inputValue)\n } else {\n ev.preventDefault()\n\n if (\"items\" in item) {\n onSelect(item.items[0]?.value)\n } else {\n onSelect(item.value)\n }\n }\n },\n },\n { preventDefault: false },\n )\n },\n [\n activeDescendant,\n allowCustomValue,\n disabled,\n filteredItems,\n onSelect,\n open,\n setValue,\n value,\n ],\n )\n\n const onClick = useCallback(() => {\n if (!interactive) return\n\n focusByClickRef.current = true\n\n inputRef.current?.focus()\n\n if (openOnClick) onOpenWithActiveDescendant(descendants.enabledFirstValue)\n }, [descendants, interactive, onOpenWithActiveDescendant, openOnClick])\n\n const onMouseDown = useCallback(\n (ev: MouseEvent<HTMLInputElement>) => {\n if (!openOnFocus) return\n\n ev.preventDefault()\n ev.stopPropagation()\n },\n [openOnFocus],\n )\n\n const onFocus = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n ev.preventDefault()\n ev.stopPropagation()\n\n setFocused(true)\n\n if (openOnFocus && !focusByClickRef.current)\n onOpenWithActiveDescendant(descendants.enabledFirstValue)\n\n focusByClickRef.current = false\n },\n [openOnFocus, onOpenWithActiveDescendant, descendants.enabledFirstValue],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n if (\n contains(fieldRef.current, ev.relatedTarget) ||\n contains(contentRef.current, ev.relatedTarget)\n ) {\n ev.preventDefault()\n } else {\n setFocused(false)\n\n if (isArray(value)) {\n setInputValue(\"\")\n } else {\n if (allowCustomValue) {\n if (inputValue) setValue(inputValue as MaybeValue)\n } else {\n const item = valueMap[value as string]\n\n setInputValue(getInputValue(item))\n }\n }\n }\n },\n [allowCustomValue, inputValue, setInputValue, setValue, value, valueMap],\n )\n\n const onClear = useCallback(() => {\n if (!interactive) return\n\n setValue((prev) => (isArray(prev) ? [] : \"\") as MaybeValue)\n setInputValue(\"\")\n\n if (focusOnClear) inputRef.current?.focus()\n }, [focusOnClear, interactive, setInputValue, setValue])\n\n useUpdateEffect(() => {\n if (isArray(valueProp)) return\n\n setInputValue(\n getInputValue(valueProp ? valueMap[valueProp as string] : undefined),\n )\n }, [valueProp])\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({\n ...dataProps,\n ...props,\n }),\n [dataProps],\n )\n\n const getFieldProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getTriggerProps({\n ref: mergeRefs(ref, fieldRef),\n tabIndex: -1,\n ...props,\n onClick: handlerAll(props.onClick, onClick),\n }),\n\n [getTriggerProps, onClick],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => ({\n id,\n ref: mergeRefs(props.ref, ref, inputRef),\n name,\n style: {\n ...(!focused && isArray(value) && !!value.length\n ? visuallyHiddenAttributes.style\n : {}),\n ...props.style,\n },\n \"data-max\": dataAttr(\n isArray(value) && isNumber(max) && value.length >= max,\n ),\n autoCapitalize: \"off\",\n autoComplete: \"off\",\n autoCorrect: \"off\",\n disabled,\n placeholder: hasValues ? undefined : placeholder,\n readOnly,\n required,\n spellCheck: false,\n value: inputValue,\n ...dataProps,\n ...props,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onInputChange),\n onFocus: handlerAll(props.onFocus, onFocus),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n onMouseDown: handlerAll(props.onMouseDown, onMouseDown),\n }),\n [\n dataProps,\n disabled,\n focused,\n hasValues,\n id,\n inputValue,\n max,\n name,\n onBlur,\n onFocus,\n onInputChange,\n onKeyDown,\n onMouseDown,\n placeholder,\n readOnly,\n ref,\n required,\n value,\n ],\n )\n\n const getContentProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getComboboxContentProps({\n ref: mergeRefs(ref, contentRef),\n hidden: empty,\n ...props,\n }),\n [empty, getComboboxContentProps],\n )\n\n const getIconProps: PropGetter = useCallback(\n (props) => ({ ...dataProps, ...props }),\n [dataProps],\n )\n\n const getClearIconProps: PropGetter = useCallback(\n (props = {}) =>\n getIconProps({\n \"aria-disabled\": ariaAttr(!interactive),\n \"aria-label\": t(\"Clear value\"),\n role: \"button\",\n tabIndex: interactive ? 0 : -1,\n ...props,\n onClick: handlerAll(props.onClick, onClear),\n onKeyDown: handlerAll(props.onKeyDown, (ev) =>\n runKeyAction(ev, { Enter: onClear, Space: onClear }),\n ),\n }),\n [getIconProps, interactive, onClear, t],\n )\n\n return {\n children,\n descendants,\n inputValue,\n interactive,\n items: resolvedItems,\n max,\n open,\n setInputValue,\n setValue,\n value,\n valueMap,\n getClearIconProps,\n getContentProps,\n getFieldProps,\n getIconProps,\n getInputProps,\n getRootProps,\n getSeparatorProps,\n popoverProps,\n onActiveDescendant,\n onChange,\n onClose,\n onInputChange,\n onOpen,\n onSelect,\n }\n}\n\nexport type UseAutocompleteReturn = ReturnType<typeof useAutocomplete>\n\nexport interface UseAutocompleteOptionProps extends UseComboboxItemProps {}\n\nexport const useAutocompleteOption = ({\n children,\n closeOnSelect,\n disabled,\n hidden,\n value,\n ...rest\n}: UseAutocompleteOptionProps = {}) => {\n const { max, value: selectedValue } = useAutocompleteContext()\n\n value ??= isString(children) ? children : undefined\n\n const selected = isArray(selectedValue)\n ? !isUndefined(value) && selectedValue.includes(value)\n : selectedValue === value\n const completed =\n isNumber(max) && isArray(selectedValue) && selectedValue.length >= max\n const { getIndicatorProps, getItemProps } = useComboboxItem({\n children,\n closeOnSelect,\n disabled: disabled || hidden || (completed && !selected),\n hidden,\n selected,\n value,\n ...rest,\n })\n\n const getOptionProps: PropGetter = useCallback(\n (props = {}) => getItemProps(props),\n [getItemProps],\n )\n\n return { getIndicatorProps, getOptionProps }\n}\n\nexport type UseAutocompleteOptionReturn = ReturnType<\n typeof useAutocompleteOption\n>\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8DA,MAAMA,iBAAyC,EAC7C,OACA,SACA,OACA,OACA,KACA,gBACI;CACJ,MAAM,OAAO,QAAQ,MAAM;AAE3B,QACE,4CAAC;EAAK,OAAO,EAAE,iBAAiB,cAAc;aAC3C,QACE,iDAAU,IAAI,IAAI,QAAQ,QAAQ,WAAY,CAAC,OAAO,YAAY;GAChE;;AAIX,MAAM,iBAAiB,yDACZ,MAAM,MAAM,GAAG,KAAK,QAAS,MAAM,SAAS;AAUvD,MAAMC,iBAAqC,YAAY,OAAO,YAAY;AACxE,KAAI,CAAC,WAAW,OAAQ,QAAO;AAE/B,QAAO,MACJ,KAAK,SAAS;AACb,MAAI,WAAW,MAAM;GACnB,MAAMC,UAAQ,KAAK,MAAM,QAAQ,WAAS;AACxC,QAAI,WAAWC,OACb,QAAO,QAAQ,YAAYA,OAAK,MAAM;6DACpBA,OAAK,MAAM,CAC7B,QAAO,QAAQ,YAAYA,OAAK,MAAM;KAExC;AAEF,OAAID,QAAM,OAAQ,QAAO;IAAE,GAAG;IAAM;IAAO;aAClC,WAAW,MACpB;OAAI,QAAQ,YAAY,KAAK,MAAM,CAAE,QAAO;6DAC1B,KAAK,MAAM,EAC7B;OAAI,QAAQ,YAAY,KAAK,MAAM,CAAE,QAAO;;GAE9C,CACD,OAAO,QAAQ;;AAOpB,MAAME,kBAAuC,OAAO,WAClD,QAAQ,aAAa,CAAC,SAAS,MAAM,aAAa,CAAC,IAAI;AAOzD,MAAM,CAAC,qBAAqB,0BAC1BC,8BAAmC,EACjC,MAAM,uBACP,CAAC;AAyHJ,MAAa,mBACX,QAAwC,EAAE,KACvC;CAGH,MA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A;EACA;EACA,OAAO;EACP;EACA;EACA;EACA;EACA;EACA;EACA,2CA3BC,UAAQ,EAAE,KACT,aAAa;GACX,iEAA0B,CAAC,YAAY;GACvC,cAAc,EAAE,cAAc;GAC9B,MAAM;GACN,UAAU,cAAc,IAAI;GAC5B,GAAGA;GACH,2DAAoBA,QAAM,SAAS,QAAQ;GAC3C,6DAAsBA,QAAM,YAAY,OACtCQ,yBAAa,IAAI;IAAE,OAAO;IAAS,OAAO;IAAS,CAAC,CACrD;GACF,CAAC,EACJ;GAAC;GAAc;GAAa;GAAS;GAAE,CACxC;EAeC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD;;AAOH,MAAa,yBAAyB,EACpC,UACA,eACA,UACA,QACA,OACA,GAAG,SAC2B,EAAE,KAAK;CACrC,MAAM,EAAE,KAAK,OAAO,kBAAkB,wBAAwB;AAE9D,2DAAmB,SAAS,GAAG,WAAW;CAE1C,MAAM,0DAAmB,cAAc,GACnC,oDAAa,MAAM,IAAI,cAAc,SAAS,MAAM,GACpD,kBAAkB;CACtB,MAAM,4DACK,IAAI,mDAAY,cAAc,IAAI,cAAc,UAAU;CACrE,MAAM,EAAE,mBAAmB,iBAAiBC,iDAAgB;EAC1D;EACA;EACA,UAAU,YAAY,UAAW,aAAa,CAAC;EAC/C;EACA;EACA;EACA,GAAG;EACJ,CAAC;AAOF,QAAO;EAAE;EAAmB,wCAJzB,QAAQ,EAAE,KAAK,aAAa,MAAM,EACnC,CAAC,aAAa,CACf;EAE2C"}
|
|
1
|
+
{"version":3,"file":"use-autocomplete.cjs","names":["defaultRender: AutocompleteItemRender","defaultFilter: AutocompleteFilter","items","item","defaultMatcher: AutocompleteMatcher","createContext","useI18n","useFieldProps","valueMap: { [key: string]: ComboboxItemWithValue }","valueMap","useControllableState","useCombobox","value","onClear","inputValue","isComposing","getRootProps: PropGetter","props","getFieldProps: PropGetter","mergeRefs","ref","getInputProps: PropGetter<\"input\">","visuallyHiddenAttributes","getContentProps: PropGetter","getIconProps: PropGetter","runKeyAction","useComboboxItem"],"sources":["../../../../src/components/autocomplete/use-autocomplete.tsx"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n} from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type {\n ComboboxItem,\n ComboboxItemWithValue,\n UseComboboxItemProps,\n UseComboboxProps,\n} from \"../../hooks/use-combobox\"\nimport type { Dict } from \"../../utils\"\nimport type { FieldProps } from \"../field\"\nimport {\n cloneElement,\n isValidElement,\n useCallback,\n useMemo,\n useRef,\n useState,\n} from \"react\"\nimport { useCombobox, useComboboxItem } from \"../../hooks/use-combobox\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n ariaAttr,\n cast,\n contains,\n createContext,\n dataAttr,\n handlerAll,\n isArray,\n isComposing,\n isNumber,\n isString,\n isUndefined,\n mergeRefs,\n runIfFn,\n runKeyAction,\n useUpdateEffect,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface AutocompleteRenderProps extends ComboboxItemWithValue {\n count: number\n focused: boolean\n index: number\n separator: string\n onClear: () => void\n max?: number\n}\n\nexport interface AutocompleteItemRender {\n (props: AutocompleteRenderProps): ReactNode\n}\n\nconst defaultRender: AutocompleteItemRender = ({\n count,\n focused,\n index,\n label,\n max,\n separator,\n}) => {\n const last = count - 1 === index\n\n return (\n <span style={{ marginInlineEnd: \"var(--gap)\" }}>\n {label}\n {((!isNumber(max) || count < max) && focused) || !last ? separator : null}\n </span>\n )\n}\n\nconst getInputValue = (item?: ComboboxItemWithValue) =>\n isString(item?.label) ? item.label : (item?.query ?? \"\")\n\nexport interface AutocompleteFilter {\n (\n inputValue: string,\n items: ComboboxItem[],\n matcher: AutocompleteMatcher,\n ): ComboboxItem[]\n}\n\nconst defaultFilter: AutocompleteFilter = (inputValue, items, matcher) => {\n if (!inputValue.length) return items\n\n return items\n .map((item) => {\n if (\"items\" in item) {\n const items = item.items.filter((item) => {\n if (\"query\" in item) {\n return matcher(inputValue, item.query)\n } else if (isString(item.label)) {\n return matcher(inputValue, item.label)\n }\n })\n\n if (items.length) return { ...item, items }\n } else if (\"query\" in item) {\n if (matcher(inputValue, item.query)) return item\n } else if (isString(item.label)) {\n if (matcher(inputValue, item.label)) return item\n }\n })\n .filter(Boolean) as ComboboxItem[]\n}\n\nexport interface AutocompleteMatcher {\n (input: string, target?: string): boolean\n}\n\nconst defaultMatcher: AutocompleteMatcher = (input, target) =>\n target?.toLowerCase().includes(input.toLowerCase()) ?? false\n\ninterface AutocompleteContext extends Pick<\n UseAutocompleteReturn,\n \"max\" | \"value\"\n> {}\n\nconst [AutocompleteContext, useAutocompleteContext] =\n createContext<AutocompleteContext>({\n name: \"AutocompleteContext\",\n })\n\nexport { AutocompleteContext, useAutocompleteContext }\n\nexport interface UseAutocompleteProps<Multiple extends boolean = false>\n extends\n Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"ref\" | \"value\">,\n Omit<\n UseComboboxProps,\n \"defaultValue\" | \"initialFocusValue\" | \"onChange\" | \"ref\" | \"value\"\n >,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, the autocomplete will allow custom value.\n *\n * @default false\n */\n allowCustomValue?: boolean\n /**\n * If `true`, the autocomplete will be closed when the input value changes.\n *\n * @default false\n */\n closeOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * The initial value of the input.\n */\n defaultInputValue?: string\n /**\n * The initial value of the autocomplete.\n */\n defaultValue?: Multiple extends true ? string[] : string\n /**\n * The message displayed when the search yields no hits.\n *\n * @default 'No results found'\n */\n emptyMessage?: ReactNode\n /**\n * The function to filter the items.\n */\n filter?: AutocompleteFilter\n /**\n * If `true`, the input will be focused when the clear icon is clicked.\n *\n * @default true\n */\n focusOnClear?: boolean\n /**\n * The `id` attribute of the input element.\n */\n id?: string\n /**\n * The value of the input.\n */\n inputValue?: string\n /**\n * If provided, generate options based on items.\n *\n * @default []\n */\n items?: ComboboxItem[]\n /**\n * The function to match the items.\n */\n matcher?: AutocompleteMatcher\n /**\n * The maximum selectable value.\n */\n max?: number\n /**\n * If `true`, the autocomplete will be multiple.\n *\n * @default false\n */\n multiple?: Multiple\n /**\n * The `name` attribute of the input element.\n */\n name?: string\n /**\n * If `true`, the autocomplete will be opened when the input value changes.\n *\n * @default true\n */\n openOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * If `true`, the autocomplete will be opened when the input is focused.\n *\n * @default true\n */\n openOnFocus?: boolean\n /**\n * The placeholder for autocomplete.\n */\n placeholder?: string\n /**\n * The visual separator between each value.\n *\n * @default ','\n */\n separator?: string\n /**\n * The value of the autocomplete.\n */\n value?: Multiple extends true ? string[] : string\n /**\n * The callback invoked when value state changes.\n */\n onChange?: (value: Multiple extends true ? string[] : string) => void\n /**\n * The callback invoked when input value state changes.\n */\n onInputChange?: (value: string) => void\n /**\n * The function to render the selected items.\n */\n render?: (props: AutocompleteRenderProps) => ReactNode\n}\n\nexport const useAutocomplete = <Multiple extends boolean = false>(\n props: UseAutocompleteProps<Multiple> = {},\n) => {\n type MaybeValue = Multiple extends true ? string[] : string\n\n const { t } = useI18n(\"autocomplete\")\n const {\n props: {\n id,\n ref,\n name,\n allowCustomValue = false,\n closeOnChange = false,\n multiple = false,\n closeOnSelect = !multiple,\n defaultInputValue,\n defaultValue = (multiple ? [] : \"\") as MaybeValue,\n disabled,\n emptyMessage = t(\"No results found\"),\n filter = defaultFilter,\n focusOnClear = true,\n inputValue: inputValueProp,\n items = [],\n matcher = defaultMatcher,\n max,\n openOnChange = true,\n openOnClick = true,\n openOnFocus = true,\n placeholder,\n readOnly,\n render = defaultRender,\n required,\n separator = \",\",\n value: valueProp,\n onChange: onChangeProp,\n onInputChange: onInputChangeProp,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const fieldRef = useRef<HTMLDivElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const inputRef = useRef<HTMLInputElement>(null)\n const focusByClickRef = useRef<boolean>(false)\n const valueMap = useMemo<{ [key: string]: ComboboxItemWithValue }>(() => {\n const valueMap: { [key: string]: ComboboxItemWithValue } = {}\n\n items.forEach((item) => {\n if (\"items\" in item) {\n item.items.forEach((item) => {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n })\n } else {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n }\n })\n\n return valueMap\n }, [items])\n const [focused, setFocused] = useState(false)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const [inputValue, setInputValue] = useControllableState({\n defaultValue:\n defaultInputValue ??\n getInputValue(isArray(value) ? undefined : valueMap[value as string]),\n value: inputValueProp,\n onChange: onInputChangeProp,\n })\n const onChange = useCallback(\n (selectedValue: string) => {\n setValue((prev) => {\n if (isArray(prev)) {\n if (prev.includes(selectedValue)) {\n return prev.filter(\n (prevValue) => prevValue !== selectedValue,\n ) as MaybeValue\n } else if (!isNumber(max) || prev.length < max) {\n return [...prev, selectedValue] as MaybeValue\n } else {\n return prev\n }\n } else {\n return selectedValue as MaybeValue\n }\n })\n\n if (isArray(value)) {\n setInputValue(\"\")\n } else {\n const item = valueMap[selectedValue]\n\n setInputValue(getInputValue(item))\n }\n },\n [max, setInputValue, setValue, value, valueMap],\n )\n const {\n activeDescendant,\n descendants,\n interactive,\n open,\n getContentProps: getComboboxContentProps,\n getSeparatorProps,\n getTriggerProps,\n popoverProps,\n onActiveDescendant,\n onClose,\n onOpen,\n onOpenWithActiveDescendant,\n onSelect,\n } = useCombobox({\n closeOnSelect,\n disabled,\n initialFocusValue: isArray(value) ? value[0] : value,\n openOnClick: false,\n openOnEnter: false,\n openOnSpace: false,\n readOnly,\n selectFocusRef: inputRef,\n selectOnSpace: false,\n onChange,\n ...ariaProps,\n ...dataProps,\n ...eventProps,\n ...rest,\n })\n const filteredItems = useMemo<ComboboxItem[]>(() => {\n if (!items.length) return []\n\n return filter(inputValue, items, matcher)\n }, [filter, inputValue, items, matcher])\n const resolvedItems = useMemo<ComboboxItem[]>(() => {\n return filteredItems.length\n ? filteredItems\n : [{ \"data-empty\": \"\", label: emptyMessage }]\n }, [filteredItems, emptyMessage])\n const empty = useMemo(\n () => !resolvedItems.filter(({ hidden }) => !hidden).length,\n [resolvedItems],\n )\n const children = useMemo<ReactNode>(() => {\n if (!isArray(value)) return null\n\n const count = value.length\n\n return value.map((value, index) => {\n const item = valueMap[value] ?? { label: value, value }\n\n const onClear = (ev?: MouseEvent<HTMLElement>) => {\n ev?.preventDefault()\n ev?.stopPropagation()\n\n if (item.value) onChange(item.value)\n }\n\n const component = render({\n count,\n focused,\n index,\n max,\n separator,\n onClear,\n ...item,\n })\n\n if (isValidElement<Dict>(component)) {\n return cloneElement(component, { ...component.props, key: index })\n } else {\n return component\n }\n })\n }, [focused, max, onChange, render, separator, value, valueMap])\n const hasValues = isArray(value) && !!value.length\n\n const onInputChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (isArray(value) && value.length === max) return\n\n if (runIfFn(closeOnChange, ev)) {\n onClose()\n } else if (runIfFn(openOnChange, ev)) {\n onOpen()\n }\n\n activeDescendant.current = null\n\n const inputValue = ev.target.value\n\n setInputValue(inputValue)\n\n if (inputValue.length || isArray(value)) return\n\n setValue(\"\" as MaybeValue)\n },\n [\n activeDescendant,\n closeOnChange,\n max,\n onClose,\n onOpen,\n openOnChange,\n setInputValue,\n setValue,\n value,\n ],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (disabled || isComposing(ev)) return\n\n const inputValue = cast<HTMLInputElement>(ev.target).value\n\n runKeyAction(\n ev,\n {\n Backspace: (ev) => {\n if (!isArray(value)) return\n if (inputValue.length) return\n\n ev.preventDefault()\n\n setValue((prev) => prev.slice(0, -1) as MaybeValue)\n },\n Enter: (ev) => {\n if (!open || !inputValue.length || activeDescendant.current) return\n\n const item = filteredItems[0]\n\n if (!item) {\n if (!allowCustomValue || !isArray(value)) return\n\n ev.preventDefault()\n\n onSelect(inputValue)\n } else {\n ev.preventDefault()\n\n if (\"items\" in item) {\n onSelect(item.items[0]?.value)\n } else {\n onSelect(item.value)\n }\n }\n },\n },\n { preventDefault: false },\n )\n },\n [\n activeDescendant,\n allowCustomValue,\n disabled,\n filteredItems,\n onSelect,\n open,\n setValue,\n value,\n ],\n )\n\n const onClick = useCallback(() => {\n if (!interactive) return\n\n focusByClickRef.current = true\n\n inputRef.current?.focus()\n\n if (openOnClick) onOpenWithActiveDescendant(descendants.enabledFirstValue)\n }, [descendants, interactive, onOpenWithActiveDescendant, openOnClick])\n\n const onMouseDown = useCallback(\n (ev: MouseEvent<HTMLInputElement>) => {\n if (!openOnFocus) return\n\n ev.preventDefault()\n ev.stopPropagation()\n },\n [openOnFocus],\n )\n\n const onFocus = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n ev.preventDefault()\n ev.stopPropagation()\n\n setFocused(true)\n\n if (openOnFocus && !focusByClickRef.current)\n onOpenWithActiveDescendant(descendants.enabledFirstValue)\n\n focusByClickRef.current = false\n },\n [openOnFocus, onOpenWithActiveDescendant, descendants.enabledFirstValue],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n if (\n contains(fieldRef.current, ev.relatedTarget) ||\n contains(contentRef.current, ev.relatedTarget)\n ) {\n ev.preventDefault()\n } else {\n setFocused(false)\n\n if (isArray(value)) {\n setInputValue(\"\")\n } else {\n if (allowCustomValue) {\n if (inputValue) setValue(inputValue as MaybeValue)\n } else {\n const item = valueMap[value as string]\n\n setInputValue(getInputValue(item))\n }\n }\n }\n },\n [allowCustomValue, inputValue, setInputValue, setValue, value, valueMap],\n )\n\n const onClear = useCallback(() => {\n if (!interactive) return\n\n setValue((prev) => (isArray(prev) ? [] : \"\") as MaybeValue)\n setInputValue(\"\")\n\n if (focusOnClear) inputRef.current?.focus()\n }, [focusOnClear, interactive, setInputValue, setValue])\n\n useUpdateEffect(() => {\n if (isArray(valueProp)) return\n\n setInputValue(\n getInputValue(valueProp ? valueMap[valueProp as string] : undefined),\n )\n }, [valueProp])\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({\n ...dataProps,\n ...props,\n }),\n [dataProps],\n )\n\n const getFieldProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getTriggerProps({\n ref: mergeRefs(ref, fieldRef),\n tabIndex: -1,\n ...props,\n onClick: handlerAll(props.onClick, onClick),\n }),\n\n [getTriggerProps, onClick],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => ({\n id,\n ref: mergeRefs(props.ref, ref, inputRef),\n name,\n style: {\n ...(!focused && isArray(value) && !!value.length\n ? visuallyHiddenAttributes.style\n : {}),\n ...props.style,\n },\n \"data-max\": dataAttr(\n isArray(value) && isNumber(max) && value.length >= max,\n ),\n autoCapitalize: \"off\",\n autoComplete: \"off\",\n autoCorrect: \"off\",\n disabled,\n placeholder: hasValues ? undefined : placeholder,\n readOnly,\n required,\n spellCheck: false,\n value: inputValue,\n ...dataProps,\n ...props,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onInputChange),\n onFocus: handlerAll(props.onFocus, onFocus),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n onMouseDown: handlerAll(props.onMouseDown, onMouseDown),\n }),\n [\n dataProps,\n disabled,\n focused,\n hasValues,\n id,\n inputValue,\n max,\n name,\n onBlur,\n onFocus,\n onInputChange,\n onKeyDown,\n onMouseDown,\n placeholder,\n readOnly,\n ref,\n required,\n value,\n ],\n )\n\n const getContentProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getComboboxContentProps({\n ref: mergeRefs(ref, contentRef),\n hidden: empty,\n ...props,\n }),\n [empty, getComboboxContentProps],\n )\n\n const getIconProps: PropGetter = useCallback(\n (props) => ({ ...dataProps, ...props }),\n [dataProps],\n )\n\n const getClearIconProps: PropGetter = useCallback(\n (props = {}) =>\n getIconProps({\n \"aria-disabled\": ariaAttr(!interactive),\n \"aria-label\": t(\"Clear value\"),\n role: \"button\",\n tabIndex: interactive ? 0 : -1,\n ...props,\n onClick: handlerAll(props.onClick, onClear),\n onKeyDown: handlerAll(props.onKeyDown, (ev) =>\n runKeyAction(ev, { Enter: onClear, Space: onClear }),\n ),\n }),\n [getIconProps, interactive, onClear, t],\n )\n\n return {\n children,\n descendants,\n inputValue,\n interactive,\n items: resolvedItems,\n max,\n open,\n setInputValue,\n setValue,\n value,\n valueMap,\n getClearIconProps,\n getContentProps,\n getFieldProps,\n getIconProps,\n getInputProps,\n getRootProps,\n getSeparatorProps,\n popoverProps,\n onActiveDescendant,\n onChange,\n onClose,\n onInputChange,\n onOpen,\n onSelect,\n }\n}\n\nexport type UseAutocompleteReturn = ReturnType<typeof useAutocomplete>\n\nexport interface UseAutocompleteOptionProps extends UseComboboxItemProps {}\n\nexport const useAutocompleteOption = ({\n children,\n closeOnSelect,\n disabled,\n hidden,\n value,\n ...rest\n}: UseAutocompleteOptionProps = {}) => {\n const { max, value: selectedValue } = useAutocompleteContext()\n\n value ??= isString(children) ? children : undefined\n\n const selected = isArray(selectedValue)\n ? !isUndefined(value) && selectedValue.includes(value)\n : selectedValue === value\n const completed =\n isNumber(max) && isArray(selectedValue) && selectedValue.length >= max\n const { getIndicatorProps, getItemProps } = useComboboxItem({\n children,\n closeOnSelect,\n disabled: disabled || hidden || (completed && !selected),\n hidden,\n selected,\n value,\n ...rest,\n })\n\n const getOptionProps: PropGetter = useCallback(\n (props = {}) => getItemProps(props),\n [getItemProps],\n )\n\n return { getIndicatorProps, getOptionProps }\n}\n\nexport type UseAutocompleteOptionReturn = ReturnType<\n typeof useAut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AoBA,QAAM,SAAS,QAAQ;GAC3C,6DAAsBA,QAAM,YAAY,OACtCQ,yBAAa,IAAI;IAAE,OAAO;IAAS,OAAO;IAAS,CAAC,CACrD;GACF,CAAC,EACJ;GAAC;GAAc;GAAa;GAAS;GAAE,CACxC;EAeC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD;;AAOH,MAAa,yBAAyB,EACpC,UACA,eACA,UACA,QACA,OACA,GAAG,SAC2B,EAAE,KAAK;CACrC,MAAM,EAAE,KAAK,OAAO,kBAAkB,wBAAwB;AAE9D,2DAAmB,SAAS,GAAG,WAAW;CAE1C,MAAM,0DAAmB,cAAc,GACnC,oDAAa,MAAM,IAAI,cAAc,SAAS,MAAM,GACpD,kBAAkB;CACtB,MAAM,4DACK,IAAI,mDAAY,cAAc,IAAI,cAAc,UAAU;CACrE,MAAM,EAAE,mBAAmB,iBAAiBC,iDAAgB;EAC1D;EACA;EACA,UAAU,YAAY,UAAW,aAAa,CAAC;EAC/C;EACA;EACA;EACA,GAAG;EACJ,CAAC;AAOF,QAAO;EAAE;EAAmB,wCAJzB,QAAQ,EAAE,KAAK,aAAa,MAAM,EACnC,CAAC,aAAa,CACf;EAE2C"}
|
|
@@ -159,7 +159,7 @@ const ChartTooltipCursor = withContext("path", "tooltipCursor")(void 0, ({ botto
|
|
|
159
159
|
return {
|
|
160
160
|
asChild: true,
|
|
161
161
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
162
|
-
d:
|
|
162
|
+
d: points ? `M${points[0]?.x},${points[0]?.y}L${points[1]?.x},${points[1]?.y}` : `M ${x},${y} h ${width} v ${height} h -${width} Z`,
|
|
163
163
|
height,
|
|
164
164
|
width
|
|
165
165
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart.cjs","names":["createSlotComponent","chartStyle","useChart","useSplitChildren","ChartContext","styled","ResponsiveContainer","Fragment","varAttr","createContext","useChartLegend","Legend","useChartTooltip","Tooltip","useChartLabelList","LabelList","useChartLabel","Label"],"sources":["../../../../src/components/chart/chart.tsx"],"sourcesContent":["\"use client\"\n\nimport type {\n JSXElementConstructor,\n PropsWithChildren,\n ReactElement,\n ReactNode,\n RefObject,\n} from \"react\"\nimport type {\n ActiveDotProps,\n DataKey,\n DefaultLegendContentProps,\n DotItemDotProps,\n DotProps,\n LabelProps,\n RenderableText,\n ResponsiveContainerProps,\n TooltipContentProps,\n TooltipProps,\n} from \"recharts\"\nimport type { CSSProps, HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { Dict, Merge } from \"../../utils\"\nimport type { ChartStyle } from \"./chart.style\"\nimport type {\n UseChartLabelListProps,\n UseChartLabelProps,\n UseChartLegendProps,\n UseChartLegendReturn,\n UseChartTooltipProps,\n} from \"./use-chart\"\nimport { Fragment, isValidElement, useMemo, useRef } from \"react\"\nimport {\n Label,\n LabelList,\n Legend,\n ResponsiveContainer,\n Tooltip,\n} from \"recharts\"\nimport { createSlotComponent, styled, varAttr } from \"../../core\"\nimport {\n cast,\n createContext,\n isArray,\n isNull,\n isNumber,\n isObject,\n isString,\n isUndefined,\n useSplitChildren,\n} from \"../../utils\"\nimport { chartStyle } from \"./chart.style\"\nimport {\n ChartContext,\n useChart,\n useChartLabel,\n useChartLabelList,\n useChartLegend,\n useChartTooltip,\n} from \"./use-chart\"\n\nexport type ChartDot =\n | ((props: DotItemDotProps) => ReactNode)\n | boolean\n | Merge<Partial<DotProps>, HTMLStyledProps<\"circle\">>\n | ReactElement\n\nexport type ChartActiveDot =\n | ((props: ActiveDotProps) => ReactNode)\n | boolean\n | Merge<Partial<ActiveDotProps>, HTMLStyledProps<\"circle\">>\n | ReactElement\n\nexport type ChartLabel =\n | ((props: any) => ReactElement | RenderableText)\n | boolean\n | (Merge<\n HTMLStyledProps<\"text\">,\n Pick<\n LabelProps,\n | \"angle\"\n | \"content\"\n | \"formatter\"\n | \"index\"\n | \"labelRef\"\n | \"offset\"\n | \"parentViewBox\"\n | \"position\"\n | \"textBreakAll\"\n | \"value\"\n | \"viewBox\"\n | \"zIndex\"\n >\n > & { dataKey?: DataKey<any> })\n | number\n | ReactElement\n | string\n\nexport type ChartLabelList =\n | ((props: LabelProps) => ReactElement | RenderableText)\n | boolean\n | ChartLabelListProps\n | ReactElement\n\nexport type ChartTickLine = boolean | HTMLStyledProps<\"line\">\n\nexport type GradientStrategy = \"invert\" | \"shade\" | \"tint\"\n\nexport function mergeSeries<Y>(\n series: Y[],\n color: CSSProps[\"color\"] = \"mono\",\n strategy: GradientStrategy = \"invert\",\n): (Y & { color: CSSProps[\"color\"] })[] {\n const colors = gradients(series.length, color, strategy)\n\n return series.map((item, index) => ({ ...item, color: colors[index] }))\n}\n\nexport function mergeData<Y>(\n data: Y[],\n color: CSSProps[\"fill\"] = \"mono\",\n strategy: GradientStrategy = \"invert\",\n): (Y & { fill: CSSProps[\"fill\"] })[] {\n const colors = gradients(data.length, color, strategy)\n\n return data.map((item, index) => ({ ...item, fill: colors[index] }))\n}\n\nexport function gradients(\n length: number,\n color: CSSProps[\"color\"] = \"mono\",\n strategy: GradientStrategy = \"invert\",\n): CSSProps[\"color\"][] {\n return Array.from({ length }, (_, index) => {\n const value = Math.floor(100 - (100 / length) * index)\n const percent = `${value}%`\n\n if (strategy === \"invert\") {\n return [\n `tint(colors.${color}, ${percent})`,\n `shade(colors.${color}, ${percent})`,\n ]\n } else {\n return `${strategy}(colors.${color}, ${percent})`\n }\n })\n}\n\nfunction parseJSON(value: any) {\n try {\n return JSON.parse(value)\n } catch {\n return value\n }\n}\n\ninterface ComponentContext extends Pick<\n ChartProps,\n \"legendProps\" | \"tooltipProps\"\n> {\n nameKeyRef: RefObject<string | undefined>\n}\n\nexport interface ChartProps extends HTMLStyledProps, ThemeProps<ChartStyle> {\n /**\n * The components to render the chart components.\n */\n components: {\n component: JSXElementConstructor<any>\n fallback: ReactNode\n }[]\n /**\n * The function to render the chart.\n */\n render: (props: PropsWithChildren) => ReactNode\n /**\n * The color of the label list.\n */\n labelListColor?: CSSProps[\"color\"]\n /**\n * The fill of the label list.\n */\n labelListFill?: CSSProps[\"fill\"]\n /**\n * The fill of the tooltip cursor.\n */\n tooltipCursorFill?: CSSProps[\"fill\"]\n /**\n * The fill opacity of the tooltip cursor.\n */\n tooltipCursorFillOpacity?: CSSProps[\"fillOpacity\"]\n /**\n * The stroke of the tooltip cursor.\n */\n tooltipCursorStroke?: CSSProps[\"stroke\"]\n /**\n * If `true`, legend is visible.\n *\n * @default false\n */\n withLegend?: boolean\n /**\n * If `true`, tooltip is visible.\n *\n * @default true\n */\n withTooltip?: boolean\n /**\n * Props for the legend component.\n */\n legendProps?: ChartLegendProps\n /**\n * Props for the responsive container component.\n */\n responsiveContainerProps?: ResponsiveContainerProps\n /**\n * Props for the tooltip component.\n */\n tooltipProps?: ChartTooltipProps\n}\n\nconst {\n ComponentContext,\n PropsContext: ChartPropsContext,\n useComponentContext: useChartComponentContext,\n usePropsContext: useChartPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<ChartProps, ChartStyle, ComponentContext>(\n \"chart\",\n chartStyle,\n)\n\nexport { ChartPropsContext, useChartComponentContext, useChartPropsContext }\n\nexport const Chart = withProvider(\n ({\n children,\n components: componentsProp,\n render,\n withLegend = false,\n withTooltip = true,\n legendProps,\n responsiveContainerProps,\n tooltipProps,\n ...rest\n }: ChartProps) => {\n const { highlightedDataKey, onHighlight } = useChart()\n const nameKeyRef = useRef<string | undefined>(undefined)\n const components = useMemo(\n () => [\n ...componentsProp,\n {\n component: ChartLegend,\n fallback: withLegend ? <ChartLegend /> : null,\n },\n {\n component: ChartTooltip,\n fallback: withTooltip ? <ChartTooltip /> : null,\n },\n ],\n [componentsProp, withLegend, withTooltip],\n )\n const [omittedChildren, ...customComponents] = useSplitChildren(\n children,\n ...components.map(({ component }) => component),\n )\n const context = useMemo(\n () => ({\n highlightedDataKey,\n onHighlight,\n }),\n [highlightedDataKey, onHighlight],\n )\n const componentContext = useMemo(\n () => ({\n nameKeyRef,\n legendProps,\n tooltipProps,\n }),\n [legendProps, tooltipProps],\n )\n\n return (\n <ChartContext value={context}>\n <ComponentContext value={componentContext}>\n <styled.div {...rest}>\n <ResponsiveContainer {...responsiveContainerProps}>\n {render({\n children: (\n <>\n {components.map(({ fallback }, index) => (\n <Fragment key={index}>\n {customComponents[index] ?? fallback}\n </Fragment>\n ))}\n\n {omittedChildren}\n </>\n ),\n })}\n </ResponsiveContainer>\n </styled.div>\n </ComponentContext>\n </ChartContext>\n )\n },\n \"root\",\n)(\n undefined,\n ({\n labelListColor,\n labelListFill,\n tooltipCursorFill,\n tooltipCursorFillOpacity,\n tooltipCursorStroke,\n ...rest\n }) => ({\n \"--label-list-color\": varAttr(labelListColor, \"colors\"),\n \"--label-list-fill\": varAttr(labelListFill, \"colors\"),\n \"--tooltip-cursor-fill\": varAttr(tooltipCursorFill, \"colors\"),\n \"--tooltip-cursor-fill-opacity\": tooltipCursorFillOpacity,\n \"--tooltip-cursor-stroke\": varAttr(tooltipCursorStroke, \"colors\"),\n ...rest,\n }),\n)\n\ninterface ChartLegendContext extends Pick<\n UseChartLegendReturn,\n \"getLegendItemProps\"\n> {}\n\nconst [ChartLegendContext, useChartLegendContext] =\n createContext<ChartLegendContext>({\n name: \"ChartLegendContext\",\n })\n\nexport interface ChartLegendProps extends Merge<\n HTMLStyledProps,\n UseChartLegendProps\n> {\n /**\n * Props for the content component.\n */\n contentProps?: Omit<ChartLegendContentProps, \"formatter\" | \"payload\">\n}\n\nexport const ChartLegend = withContext<\"div\", ChartLegendProps>((props) => {\n const { legendProps } = useChartComponentContext()\n const { contentProps, ...rest } = { ...legendProps, ...props }\n const {\n getLegendContentProps,\n getLegendItemProps,\n getLegendProps,\n getRootProps,\n } = useChartLegend({\n content: ({ formatter, payload }) => (\n <ChartLegendContent\n formatter={formatter}\n payload={payload}\n {...getLegendContentProps(contentProps)}\n />\n ),\n ...rest,\n })\n const context = useMemo(() => ({ getLegendItemProps }), [getLegendItemProps])\n\n return (\n <ChartLegendContext value={context}>\n <styled.div asChild {...getRootProps()}>\n <Legend {...getLegendProps()} />\n </styled.div>\n </ChartLegendContext>\n )\n}, \"legend\")()\n\ninterface ChartLegendContentProps\n extends\n HTMLStyledProps,\n Pick<DefaultLegendContentProps, \"formatter\" | \"payload\"> {\n /**\n * If `true`, swatch is visible.\n */\n withSwatch?: boolean\n}\n\nconst ChartLegendContent = withContext<\"div\", ChartLegendContentProps>(\n ({ formatter, payload, withSwatch = true, ...rest }) => {\n const { nameKeyRef } = useChartComponentContext()\n const { getLegendItemProps } = useChartLegendContext()\n\n return (\n <styled.div {...rest}>\n {payload?.map((data, index) => {\n let value = data.value\n\n if (nameKeyRef.current)\n value = (data.payload as any)?.[nameKeyRef.current]\n\n const dataKey =\n isString(data.dataKey) || isNumber(data.dataKey)\n ? data.dataKey\n : value\n const color = parseJSON(data.color)\n const formattedValue = formatter?.(value, data, index) ?? value\n\n return (\n <ChartLegendItem key={index} {...getLegendItemProps({ dataKey })}>\n {withSwatch ? <ChartLegendSwatch bg={color} /> : null}\n <ChartLegendValue>{formattedValue}</ChartLegendValue>\n </ChartLegendItem>\n )\n })}\n </styled.div>\n )\n },\n \"legendContent\",\n)()\n\ninterface ChartLegendItemProps extends HTMLStyledProps {}\n\nconst ChartLegendItem = withContext<\"div\", ChartLegendItemProps>(\n \"div\",\n \"legendItem\",\n)()\n\ninterface ChartLegendSwatchProps extends HTMLStyledProps {}\n\nconst ChartLegendSwatch = withContext<\"div\", ChartLegendSwatchProps>(\n \"div\",\n \"legendSwatch\",\n)()\n\ninterface ChartLegendValueProps extends HTMLStyledProps<\"span\"> {}\n\nconst ChartLegendValue = withContext<\"span\", ChartLegendValueProps>(\n \"span\",\n \"legendValue\",\n)()\n\nexport interface ChartTooltipProps<\n Y extends (number | string)[] | number | string = number,\n M extends number | string = string,\n> extends Omit<Merge<HTMLStyledProps, UseChartTooltipProps<Y, M>>, \"cursor\"> {\n /**\n * Props for the cursor component.\n */\n cursor?: boolean | ChartTooltipCursorProps | ReactElement\n /**\n * Props for the content component.\n */\n contentProps?: Omit<\n ChartTooltipContentProps,\n \"formatter\" | \"label\" | \"labelFormatter\" | \"payload\"\n >\n}\n\nexport const ChartTooltip = <\n Y extends (number | string)[] | number | string,\n M extends number | string,\n>(\n props: ChartTooltipProps<Y, M>,\n) => {\n const { tooltipProps } = useChartComponentContext()\n const {\n cursor = false,\n contentProps,\n ...rest\n } = {\n ...tooltipProps,\n ...props,\n } as ChartTooltipProps<Y, M>\n const { getContentProps, getRootProps } = useChartTooltip<Y, M>({\n content: ({ formatter, label, labelFormatter, payload }) => (\n <ChartTooltipContent\n formatter={formatter}\n label={label}\n labelFormatter={labelFormatter}\n payload={payload}\n {...getContentProps(contentProps)}\n />\n ),\n cursor:\n isValidElement(cursor) || !cursor ? (\n cursor\n ) : (\n <ChartTooltipCursor {...(isObject(cursor) ? cursor : {})} />\n ),\n ...rest,\n })\n\n return <Tooltip {...cast<TooltipProps>(getRootProps())} />\n}\n\ninterface ChartTooltipCursorProps extends Omit<\n HTMLStyledProps<\"path\">,\n \"height\" | \"points\" | \"width\"\n> {\n brushBottom?: number\n height?: number\n payload?: Dict[]\n payloadIndex?: number\n points?: { x: number; y: number }[]\n width?: number\n}\n\nconst ChartTooltipCursor = withContext<\"path\", ChartTooltipCursorProps>(\n \"path\",\n \"tooltipCursor\",\n)(\n undefined,\n ({\n bottom: _bottom,\n brushBottom: _brushBottom,\n fill,\n height,\n left: _left,\n payload: _payload,\n payloadIndex: _payloadIndex,\n points,\n right: _right,\n stroke,\n top: _top,\n width,\n x,\n y,\n ...rest\n }) => {\n const d = !!points\n ? `M${points[0]?.x},${points[0]?.y}L${points[1]?.x},${points[1]?.y}`\n : `M ${x},${y} h ${width} v ${height} h -${width} Z`\n return {\n asChild: true,\n children: <path d={d} height={height} width={width} />,\n fill: fill === \"#ccc\" ? undefined : fill,\n stroke: stroke === \"#ccc\" ? undefined : stroke,\n ...rest,\n }\n },\n)\n\ninterface ChartTooltipContentProps\n extends\n HTMLStyledProps,\n Pick<\n TooltipContentProps<any, any>,\n \"formatter\" | \"label\" | \"labelFormatter\" | \"payload\"\n > {\n /**\n * If `true`, swatch is visible.\n */\n withSwatch?: boolean\n}\n\nconst ChartTooltipContent = withContext<\"div\", ChartTooltipContentProps>(\n ({\n formatter,\n label: labelProp,\n labelFormatter,\n payload,\n withSwatch = true,\n ...rest\n }) => {\n const { nameKeyRef } = useChartComponentContext()\n const label = labelFormatter\n ? labelFormatter(labelProp, payload)\n : labelProp\n\n return (\n <styled.div {...rest}>\n {!isUndefined(label) && !isNull(label) ? (\n <ChartTooltipLabel>{label}</ChartTooltipLabel>\n ) : null}\n\n <ChartTooltipList>\n {payload.map((data, index) => {\n if (nameKeyRef.current) data.name = data.payload[nameKeyRef.current]\n\n const color = parseJSON(data.color) || data.payload.fill\n const result =\n formatter?.(data.value, data.name, data, index, payload) ??\n (isArray(data.value) ? data.value.join(\", \") : data.value)\n const [value, name] = isArray(result) ? result : [result, data.name]\n\n return (\n <ChartTooltipItem key={index}>\n {withSwatch ? <ChartTooltipSwatch bg={color} /> : null}\n <ChartTooltipName>{name}</ChartTooltipName>\n <ChartTooltipValue>{value}</ChartTooltipValue>\n </ChartTooltipItem>\n )\n })}\n </ChartTooltipList>\n </styled.div>\n )\n },\n \"tooltipContent\",\n)()\n\ninterface ChartTooltipLabel extends HTMLStyledProps<\"p\"> {}\n\nconst ChartTooltipLabel = withContext<\"p\", ChartTooltipLabel>(\n \"p\",\n \"tooltipLabel\",\n)()\n\ninterface ChartTooltipList extends HTMLStyledProps {}\n\nconst ChartTooltipList = withContext<\"div\", ChartTooltipList>(\n \"div\",\n \"tooltipList\",\n)()\n\ninterface ChartTooltipItem extends HTMLStyledProps {}\n\nconst ChartTooltipItem = withContext<\"div\", ChartTooltipItem>(\n \"div\",\n \"tooltipItem\",\n)()\n\ninterface ChartTooltipSwatch extends HTMLStyledProps {}\n\nconst ChartTooltipSwatch = withContext<\"div\", ChartTooltipSwatch>(\n \"div\",\n \"tooltipSwatch\",\n)()\n\ninterface ChartTooltipName extends HTMLStyledProps<\"span\"> {}\n\nconst ChartTooltipName = withContext<\"span\", ChartTooltipName>(\n \"span\",\n \"tooltipName\",\n)()\n\ninterface ChartTooltipValue extends HTMLStyledProps<\"span\"> {}\n\nconst ChartTooltipValue = withContext<\"span\", ChartTooltipValue>(\n \"span\",\n \"tooltipValue\",\n)()\n\nexport interface ChartLabelListProps extends Merge<\n HTMLStyledProps<\"text\">,\n UseChartLabelListProps\n> {}\n\nexport const ChartLabelList = withContext<\"text\", ChartLabelListProps>(\n (props) => {\n const { getLabelListProps, getRootProps } = useChartLabelList(props)\n\n return (\n <styled.text asChild {...getRootProps()}>\n <LabelList {...getLabelListProps()} />\n </styled.text>\n )\n },\n \"labelList\",\n)()\n\nexport interface ChartLabelProps extends Merge<\n HTMLStyledProps<\"text\">,\n UseChartLabelProps\n> {}\n\nexport const ChartLabel = withContext<\"text\", ChartLabelProps>((props) => {\n const { getLabelProps, getRootProps } = useChartLabel(props)\n\n return (\n <styled.text asChild {...getRootProps()}>\n <Label {...getLabelProps()} />\n </styled.text>\n )\n}, \"label\")()\n"],"mappings":";;;;;;;;;;;;;;;;;AA4GA,SAAgB,YACd,QACA,QAA2B,QAC3B,WAA6B,UACS;CACtC,MAAM,SAAS,UAAU,OAAO,QAAQ,OAAO,SAAS;AAExD,QAAO,OAAO,KAAK,MAAM,WAAW;EAAE,GAAG;EAAM,OAAO,OAAO;EAAQ,EAAE;;AAGzE,SAAgB,UACd,MACA,QAA0B,QAC1B,WAA6B,UACO;CACpC,MAAM,SAAS,UAAU,KAAK,QAAQ,OAAO,SAAS;AAEtD,QAAO,KAAK,KAAK,MAAM,WAAW;EAAE,GAAG;EAAM,MAAM,OAAO;EAAQ,EAAE;;AAGtE,SAAgB,UACd,QACA,QAA2B,QAC3B,WAA6B,UACR;AACrB,QAAO,MAAM,KAAK,EAAE,QAAQ,GAAG,GAAG,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AAK;EAAQ,GAAI,cAAc;YACrC,2CAACU,sBAAU,GAAI,mBAAmB,GAAI;GAC1B;GAGlB,YACD,EAAE;AAOH,MAAa,aAAa,aAAsC,UAAU;CACxE,MAAM,EAAE,eAAe,iBAAiBC,gCAAc,MAAM;AAE5D,QACE,2CAACX,uBAAO;EAAK;EAAQ,GAAI,cAAc;YACrC,2CAACY,kBAAM,GAAI,eAAe,GAAI;GAClB;GAEf,QAAQ,EAAE"}
|
|
1
|
+
{"version":3,"file":"chart.cjs","names":["createSlotComponent","chartStyle","useChart","useSplitChildren","ChartContext","styled","ResponsiveContainer","Fragment","varAttr","createContext","useChartLegend","Legend","useChartTooltip","Tooltip","useChartLabelList","LabelList","useChartLabel","Label"],"sources":["../../../../src/components/chart/chart.tsx"],"sourcesContent":["\"use client\"\n\nimport type {\n JSXElementConstructor,\n PropsWithChildren,\n ReactElement,\n ReactNode,\n RefObject,\n} from \"react\"\nimport type {\n ActiveDotProps,\n DataKey,\n DefaultLegendContentProps,\n DotItemDotProps,\n DotProps,\n LabelProps,\n RenderableText,\n ResponsiveContainerProps,\n TooltipContentProps,\n TooltipProps,\n} from \"recharts\"\nimport type { CSSProps, HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { Dict, Merge } from \"../../utils\"\nimport type { ChartStyle } from \"./chart.style\"\nimport type {\n UseChartLabelListProps,\n UseChartLabelProps,\n UseChartLegendProps,\n UseChartLegendReturn,\n UseChartTooltipProps,\n} from \"./use-chart\"\nimport { Fragment, isValidElement, useMemo, useRef } from \"react\"\nimport {\n Label,\n LabelList,\n Legend,\n ResponsiveContainer,\n Tooltip,\n} from \"recharts\"\nimport { createSlotComponent, styled, varAttr } from \"../../core\"\nimport {\n cast,\n createContext,\n isArray,\n isNull,\n isNumber,\n isObject,\n isString,\n isUndefined,\n useSplitChildren,\n} from \"../../utils\"\nimport { chartStyle } from \"./chart.style\"\nimport {\n ChartContext,\n useChart,\n useChartLabel,\n useChartLabelList,\n useChartLegend,\n useChartTooltip,\n} from \"./use-chart\"\n\nexport type ChartDot =\n | ((props: DotItemDotProps) => ReactNode)\n | boolean\n | Merge<Partial<DotProps>, HTMLStyledProps<\"circle\">>\n | ReactElement\n\nexport type ChartActiveDot =\n | ((props: ActiveDotProps) => ReactNode)\n | boolean\n | Merge<Partial<ActiveDotProps>, HTMLStyledProps<\"circle\">>\n | ReactElement\n\nexport type ChartLabel =\n | ((props: any) => ReactElement | RenderableText)\n | boolean\n | (Merge<\n HTMLStyledProps<\"text\">,\n Pick<\n LabelProps,\n | \"angle\"\n | \"content\"\n | \"formatter\"\n | \"index\"\n | \"labelRef\"\n | \"offset\"\n | \"parentViewBox\"\n | \"position\"\n | \"textBreakAll\"\n | \"value\"\n | \"viewBox\"\n | \"zIndex\"\n >\n > & { dataKey?: DataKey<any> })\n | number\n | ReactElement\n | string\n\nexport type ChartLabelList =\n | ((props: LabelProps) => ReactElement | RenderableText)\n | boolean\n | ChartLabelListProps\n | ReactElement\n\nexport type ChartTickLine = boolean | HTMLStyledProps<\"line\">\n\nexport type GradientStrategy = \"invert\" | \"shade\" | \"tint\"\n\nexport function mergeSeries<Y>(\n series: Y[],\n color: CSSProps[\"color\"] = \"mono\",\n strategy: GradientStrategy = \"invert\",\n): (Y & { color: CSSProps[\"color\"] })[] {\n const colors = gradients(series.length, color, strategy)\n\n return series.map((item, index) => ({ ...item, color: colors[index] }))\n}\n\nexport function mergeData<Y>(\n data: Y[],\n color: CSSProps[\"fill\"] = \"mono\",\n strategy: GradientStrategy = \"invert\",\n): (Y & { fill: CSSProps[\"fill\"] })[] {\n const colors = gradients(data.length, color, strategy)\n\n return data.map((item, index) => ({ ...item, fill: colors[index] }))\n}\n\nexport function gradients(\n length: number,\n color: CSSProps[\"color\"] = \"mono\",\n strategy: GradientStrategy = \"invert\",\n): CSSProps[\"color\"][] {\n return Array.from({ length }, (_, index) => {\n const value = Math.floor(100 - (100 / length) * index)\n const percent = `${value}%`\n\n if (strategy === \"invert\") {\n return [\n `tint(colors.${color}, ${percent})`,\n `shade(colors.${color}, ${percent})`,\n ]\n } else {\n return `${strategy}(colors.${color}, ${percent})`\n }\n })\n}\n\nfunction parseJSON(value: any) {\n try {\n return JSON.parse(value)\n } catch {\n return value\n }\n}\n\ninterface ComponentContext extends Pick<\n ChartProps,\n \"legendProps\" | \"tooltipProps\"\n> {\n nameKeyRef: RefObject<string | undefined>\n}\n\nexport interface ChartProps extends HTMLStyledProps, ThemeProps<ChartStyle> {\n /**\n * The components to render the chart components.\n */\n components: {\n component: JSXElementConstructor<any>\n fallback: ReactNode\n }[]\n /**\n * The function to render the chart.\n */\n render: (props: PropsWithChildren) => ReactNode\n /**\n * The color of the label list.\n */\n labelListColor?: CSSProps[\"color\"]\n /**\n * The fill of the label list.\n */\n labelListFill?: CSSProps[\"fill\"]\n /**\n * The fill of the tooltip cursor.\n */\n tooltipCursorFill?: CSSProps[\"fill\"]\n /**\n * The fill opacity of the tooltip cursor.\n */\n tooltipCursorFillOpacity?: CSSProps[\"fillOpacity\"]\n /**\n * The stroke of the tooltip cursor.\n */\n tooltipCursorStroke?: CSSProps[\"stroke\"]\n /**\n * If `true`, legend is visible.\n *\n * @default false\n */\n withLegend?: boolean\n /**\n * If `true`, tooltip is visible.\n *\n * @default true\n */\n withTooltip?: boolean\n /**\n * Props for the legend component.\n */\n legendProps?: ChartLegendProps\n /**\n * Props for the responsive container component.\n */\n responsiveContainerProps?: ResponsiveContainerProps\n /**\n * Props for the tooltip component.\n */\n tooltipProps?: ChartTooltipProps\n}\n\nconst {\n ComponentContext,\n PropsContext: ChartPropsContext,\n useComponentContext: useChartComponentContext,\n usePropsContext: useChartPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<ChartProps, ChartStyle, ComponentContext>(\n \"chart\",\n chartStyle,\n)\n\nexport { ChartPropsContext, useChartComponentContext, useChartPropsContext }\n\nexport const Chart = withProvider(\n ({\n children,\n components: componentsProp,\n render,\n withLegend = false,\n withTooltip = true,\n legendProps,\n responsiveContainerProps,\n tooltipProps,\n ...rest\n }: ChartProps) => {\n const { highlightedDataKey, onHighlight } = useChart()\n const nameKeyRef = useRef<string | undefined>(undefined)\n const components = useMemo(\n () => [\n ...componentsProp,\n {\n component: ChartLegend,\n fallback: withLegend ? <ChartLegend /> : null,\n },\n {\n component: ChartTooltip,\n fallback: withTooltip ? <ChartTooltip /> : null,\n },\n ],\n [componentsProp, withLegend, withTooltip],\n )\n const [omittedChildren, ...customComponents] = useSplitChildren(\n children,\n ...components.map(({ component }) => component),\n )\n const context = useMemo(\n () => ({\n highlightedDataKey,\n onHighlight,\n }),\n [highlightedDataKey, onHighlight],\n )\n const componentContext = useMemo(\n () => ({\n nameKeyRef,\n legendProps,\n tooltipProps,\n }),\n [legendProps, tooltipProps],\n )\n\n return (\n <ChartContext value={context}>\n <ComponentContext value={componentContext}>\n <styled.div {...rest}>\n <ResponsiveContainer {...responsiveContainerProps}>\n {render({\n children: (\n <>\n {components.map(({ fallback }, index) => (\n <Fragment key={index}>\n {customComponents[index] ?? fallback}\n </Fragment>\n ))}\n\n {omittedChildren}\n </>\n ),\n })}\n </ResponsiveContainer>\n </styled.div>\n </ComponentContext>\n </ChartContext>\n )\n },\n \"root\",\n)(\n undefined,\n ({\n labelListColor,\n labelListFill,\n tooltipCursorFill,\n tooltipCursorFillOpacity,\n tooltipCursorStroke,\n ...rest\n }) => ({\n \"--label-list-color\": varAttr(labelListColor, \"colors\"),\n \"--label-list-fill\": varAttr(labelListFill, \"colors\"),\n \"--tooltip-cursor-fill\": varAttr(tooltipCursorFill, \"colors\"),\n \"--tooltip-cursor-fill-opacity\": tooltipCursorFillOpacity,\n \"--tooltip-cursor-stroke\": varAttr(tooltipCursorStroke, \"colors\"),\n ...rest,\n }),\n)\n\ninterface ChartLegendContext extends Pick<\n UseChartLegendReturn,\n \"getLegendItemProps\"\n> {}\n\nconst [ChartLegendContext, useChartLegendContext] =\n createContext<ChartLegendContext>({\n name: \"ChartLegendContext\",\n })\n\nexport interface ChartLegendProps extends Merge<\n HTMLStyledProps,\n UseChartLegendProps\n> {\n /**\n * Props for the content component.\n */\n contentProps?: Omit<ChartLegendContentProps, \"formatter\" | \"payload\">\n}\n\nexport const ChartLegend = withContext<\"div\", ChartLegendProps>((props) => {\n const { legendProps } = useChartComponentContext()\n const { contentProps, ...rest } = { ...legendProps, ...props }\n const {\n getLegendContentProps,\n getLegendItemProps,\n getLegendProps,\n getRootProps,\n } = useChartLegend({\n content: ({ formatter, payload }) => (\n <ChartLegendContent\n formatter={formatter}\n payload={payload}\n {...getLegendContentProps(contentProps)}\n />\n ),\n ...rest,\n })\n const context = useMemo(() => ({ getLegendItemProps }), [getLegendItemProps])\n\n return (\n <ChartLegendContext value={context}>\n <styled.div asChild {...getRootProps()}>\n <Legend {...getLegendProps()} />\n </styled.div>\n </ChartLegendContext>\n )\n}, \"legend\")()\n\ninterface ChartLegendContentProps\n extends\n HTMLStyledProps,\n Pick<DefaultLegendContentProps, \"formatter\" | \"payload\"> {\n /**\n * If `true`, swatch is visible.\n */\n withSwatch?: boolean\n}\n\nconst ChartLegendContent = withContext<\"div\", ChartLegendContentProps>(\n ({ formatter, payload, withSwatch = true, ...rest }) => {\n const { nameKeyRef } = useChartComponentContext()\n const { getLegendItemProps } = useChartLegendContext()\n\n return (\n <styled.div {...rest}>\n {payload?.map((data, index) => {\n let value = data.value\n\n if (nameKeyRef.current)\n value = (data.payload as any)?.[nameKeyRef.current]\n\n const dataKey =\n isString(data.dataKey) || isNumber(data.dataKey)\n ? data.dataKey\n : value\n const color = parseJSON(data.color)\n const formattedValue = formatter?.(value, data, index) ?? value\n\n return (\n <ChartLegendItem key={index} {...getLegendItemProps({ dataKey })}>\n {withSwatch ? <ChartLegendSwatch bg={color} /> : null}\n <ChartLegendValue>{formattedValue}</ChartLegendValue>\n </ChartLegendItem>\n )\n })}\n </styled.div>\n )\n },\n \"legendContent\",\n)()\n\ninterface ChartLegendItemProps extends HTMLStyledProps {}\n\nconst ChartLegendItem = withContext<\"div\", ChartLegendItemProps>(\n \"div\",\n \"legendItem\",\n)()\n\ninterface ChartLegendSwatchProps extends HTMLStyledProps {}\n\nconst ChartLegendSwatch = withContext<\"div\", ChartLegendSwatchProps>(\n \"div\",\n \"legendSwatch\",\n)()\n\ninterface ChartLegendValueProps extends HTMLStyledProps<\"span\"> {}\n\nconst ChartLegendValue = withContext<\"span\", ChartLegendValueProps>(\n \"span\",\n \"legendValue\",\n)()\n\nexport interface ChartTooltipProps<\n Y extends (number | string)[] | number | string = number,\n M extends number | string = string,\n> extends Omit<Merge<HTMLStyledProps, UseChartTooltipProps<Y, M>>, \"cursor\"> {\n /**\n * Props for the cursor component.\n */\n cursor?: boolean | ChartTooltipCursorProps | ReactElement\n /**\n * Props for the content component.\n */\n contentProps?: Omit<\n ChartTooltipContentProps,\n \"formatter\" | \"label\" | \"labelFormatter\" | \"payload\"\n >\n}\n\nexport const ChartTooltip = <\n Y extends (number | string)[] | number | string,\n M extends number | string,\n>(\n props: ChartTooltipProps<Y, M>,\n) => {\n const { tooltipProps } = useChartComponentContext()\n const {\n cursor = false,\n contentProps,\n ...rest\n } = {\n ...tooltipProps,\n ...props,\n } as ChartTooltipProps<Y, M>\n const { getContentProps, getRootProps } = useChartTooltip<Y, M>({\n content: ({ formatter, label, labelFormatter, payload }) => (\n <ChartTooltipContent\n formatter={formatter}\n label={label}\n labelFormatter={labelFormatter}\n payload={payload}\n {...getContentProps(contentProps)}\n />\n ),\n cursor:\n isValidElement(cursor) || !cursor ? (\n cursor\n ) : (\n <ChartTooltipCursor {...(isObject(cursor) ? cursor : {})} />\n ),\n ...rest,\n })\n\n return <Tooltip {...cast<TooltipProps>(getRootProps())} />\n}\n\ninterface ChartTooltipCursorProps extends Omit<\n HTMLStyledProps<\"path\">,\n \"height\" | \"points\" | \"width\"\n> {\n brushBottom?: number\n height?: number\n payload?: Dict[]\n payloadIndex?: number\n points?: { x: number; y: number }[]\n width?: number\n}\n\nconst ChartTooltipCursor = withContext<\"path\", ChartTooltipCursorProps>(\n \"path\",\n \"tooltipCursor\",\n)(\n undefined,\n ({\n bottom: _bottom,\n brushBottom: _brushBottom,\n fill,\n height,\n left: _left,\n payload: _payload,\n payloadIndex: _payloadIndex,\n points,\n right: _right,\n stroke,\n top: _top,\n width,\n x,\n y,\n ...rest\n }) => {\n const d = points\n ? `M${points[0]?.x},${points[0]?.y}L${points[1]?.x},${points[1]?.y}`\n : `M ${x},${y} h ${width} v ${height} h -${width} Z`\n return {\n asChild: true,\n children: <path d={d} height={height} width={width} />,\n fill: fill === \"#ccc\" ? undefined : fill,\n stroke: stroke === \"#ccc\" ? undefined : stroke,\n ...rest,\n }\n },\n)\n\ninterface ChartTooltipContentProps\n extends\n HTMLStyledProps,\n Pick<\n TooltipContentProps<any, any>,\n \"formatter\" | \"label\" | \"labelFormatter\" | \"payload\"\n > {\n /**\n * If `true`, swatch is visible.\n */\n withSwatch?: boolean\n}\n\nconst ChartTooltipContent = withContext<\"div\", ChartTooltipContentProps>(\n ({\n formatter,\n label: labelProp,\n labelFormatter,\n payload,\n withSwatch = true,\n ...rest\n }) => {\n const { nameKeyRef } = useChartComponentContext()\n const label = labelFormatter\n ? labelFormatter(labelProp, payload)\n : labelProp\n\n return (\n <styled.div {...rest}>\n {!isUndefined(label) && !isNull(label) ? (\n <ChartTooltipLabel>{label}</ChartTooltipLabel>\n ) : null}\n\n <ChartTooltipList>\n {payload.map((data, index) => {\n if (nameKeyRef.current) data.name = data.payload[nameKeyRef.current]\n\n const color = parseJSON(data.color) || data.payload.fill\n const result =\n formatter?.(data.value, data.name, data, index, payload) ??\n (isArray(data.value) ? data.value.join(\", \") : data.value)\n const [value, name] = isArray(result) ? result : [result, data.name]\n\n return (\n <ChartTooltipItem key={index}>\n {withSwatch ? <ChartTooltipSwatch bg={color} /> : null}\n <ChartTooltipName>{name}</ChartTooltipName>\n <ChartTooltipValue>{value}</ChartTooltipValue>\n </ChartTooltipItem>\n )\n })}\n </ChartTooltipList>\n </styled.div>\n )\n },\n \"tooltipContent\",\n)()\n\ninterface ChartTooltipLabel extends HTMLStyledProps<\"p\"> {}\n\nconst ChartTooltipLabel = withContext<\"p\", ChartTooltipLabel>(\n \"p\",\n \"tooltipLabel\",\n)()\n\ninterface ChartTooltipList extends HTMLStyledProps {}\n\nconst ChartTooltipList = withContext<\"div\", ChartTooltipList>(\n \"div\",\n \"tooltipList\",\n)()\n\ninterface ChartTooltipItem extends HTMLStyledProps {}\n\nconst ChartTooltipItem = withContext<\"div\", ChartTooltipItem>(\n \"div\",\n \"tooltipItem\",\n)()\n\ninterface ChartTooltipSwatch extends HTMLStyledProps {}\n\nconst ChartTooltipSwatch = withContext<\"div\", ChartTooltipSwatch>(\n \"div\",\n \"tooltipSwatch\",\n)()\n\ninterface ChartTooltipName extends HTMLStyledProps<\"span\"> {}\n\nconst ChartTooltipName = withContext<\"span\", ChartTooltipName>(\n \"span\",\n \"tooltipName\",\n)()\n\ninterface ChartTooltipValue extends HTMLStyledProps<\"span\"> {}\n\nconst ChartTooltipValue = withContext<\"span\", ChartTooltipValue>(\n \"span\",\n \"tooltipValue\",\n)()\n\nexport interface ChartLabelListProps extends Merge<\n HTMLStyledProps<\"text\">,\n UseChartLabelListProps\n> {}\n\nexport const ChartLabelList = withContext<\"text\", ChartLabelListProps>(\n (props) => {\n const { getLabelListProps, getRootProps } = useChartLabelList(props)\n\n return (\n <styled.text asChild {...getRootProps()}>\n <LabelList {...getLabelListProps()} />\n </styled.text>\n )\n },\n \"labelList\",\n)()\n\nexport interface ChartLabelProps extends Merge<\n HTMLStyledProps<\"text\">,\n UseChartLabelProps\n> {}\n\nexport const ChartLabel = withContext<\"text\", ChartLabelProps>((props) => {\n const { getLabelProps, getRootProps } = useChartLabel(props)\n\n return (\n <styled.text asChild {...getRootProps()}>\n <Label {...getLabelProps()} />\n </styled.text>\n )\n}, \"label\")()\n"],"mappings":";;;;;;;;;;;;;;;;;AA4GA,SAAgB,YACd,QACA,QAA2B,QAC3B,WAA6B,UACS;CACtC,MAA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;GACR;GAGjB,iBACD,EAAE;AAIH,MAAM,oBAAoB,YACxB,KACA,eACD,EAAE;AAIH,MAAM,mBAAmB,YACvB,OACA,cACD,EAAE;AAIH,MAAM,mBAAmB,YACvB,OACA,cACD,EAAE;AAIH,MAAM,qBAAqB,YACzB,OACA,gBACD,EAAE;AAIH,MAAM,mBAAmB,YACvB,QACA,cACD,EAAE;AAIH,MAAM,oBAAoB,YACxB,QACA,eACD,EAAE;AAOH,MAAa,iBAAiB,aAC3B,UAAU;CACT,MAAM,EAAE,mBAAmB,iBAAiBS,oCAAkB,MAAM;AAEpE,QACE,2CAACT,uBAAO;EAAK;EAAQ,GAAI,cAAc;YACrC,2CAACU,sBAAU,GAAI,mBAAmB,GAAI;GAC1B;GAGlB,YACD,EAAE;AAOH,MAAa,aAAa,aAAsC,UAAU;CACxE,MAAM,EAAE,eAAe,iBAAiBC,gCAAc,MAAM;AAE5D,QACE,2CAACX,uBAAO;EAAK;EAAQ,GAAI,cAAc;YACrC,2CAACY,kBAAM,GAAI,eAAe,GAAI;GAClB;GAEf,QAAQ,EAAE"}
|
|
@@ -248,7 +248,7 @@ const useDatePicker = ({ maxDate = require_use_calendar.DEFAULT_MAX_DATE, minDat
|
|
|
248
248
|
require_dom.runKeyAction(ev, {
|
|
249
249
|
Backspace: (ev$1) => {
|
|
250
250
|
if (!value || (0, require_utils_index.utils_exports.isDate)(value)) return;
|
|
251
|
-
if (
|
|
251
|
+
if (inputValue$1.length) return;
|
|
252
252
|
if ((0, require_utils_index.utils_exports.isArray)(value)) {
|
|
253
253
|
ev$1.preventDefault();
|
|
254
254
|
setValue((prev) => (0, require_utils_index.utils_exports.isArray)(prev) ? prev.slice(0, -1) : prev);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-date-picker.cjs","names":["defaultRender: DatePickerRender","DEFAULT_MAX_DATE","DEFAULT_MIN_DATE","useI18n","useFieldProps","useDateTimeFormat","inputFormat","calendarFormat","useCalendarProps","useControllableState","value","getAdjustedMonth","isBeforeDate","isAfterDate","useCombobox","onClear","updateMaybeDateValue","startPlaceholder","inputValue","minDate","maxDate","isComposing","ev","getRootProps: PropGetter","props","getFieldProps: PropGetter","mergeRefs","ref","getInputProps: PropGetter<\"input\", { align?: InputAlign }>","inputProps: HTMLProps<\"input\">","visuallyHiddenAttributes","getContentProps: PropGetter","getCalendarProps: PropGetter<UseCalendarProps<Multiple, Range>>","getIconProps: PropGetter","runKeyAction"],"sources":["../../../../src/components/date-picker/use-date-picker.tsx"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n} from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type { UseComboboxProps } from \"../../hooks/use-combobox\"\nimport type { Dict } from \"../../utils\"\nimport type {\n CalendarFormat,\n MaybeDateValue,\n UseCalendarProps,\n} from \"../calendar\"\nimport type { FieldProps } from \"../field\"\nimport dayjs from \"dayjs\"\nimport {\n cloneElement,\n isValidElement,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\"\nimport { useCombobox } from \"../../hooks/use-combobox\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n ariaAttr,\n cast,\n contains,\n dataAttr,\n focusTransfer,\n handlerAll,\n isArray,\n isComposing,\n isDate,\n isNumber,\n isObject,\n mergeRefs,\n runIfFn,\n runKeyAction,\n useUpdateEffect,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport {\n DEFAULT_MAX_DATE,\n DEFAULT_MIN_DATE,\n getAdjustedMonth,\n isAfterDate,\n isBeforeDate,\n updateMaybeDateValue,\n useCalendarProps,\n} from \"../calendar\"\nimport { useFieldProps } from \"../field\"\nimport { useDateTimeFormat } from \"../format\"\n\nexport interface DatePickerFormat extends CalendarFormat {\n input?: Intl.DateTimeFormatOptions | null\n}\n\ntype InputAlign = \"end\" | \"start\"\ntype MaybeInputValue<Range extends boolean = false> = Range extends true\n ? { end?: string; start?: string }\n : string | undefined\n\ninterface DatePickerRenderProps {\n count: number\n date: Date\n focused: boolean\n index: number\n separator: string\n value: string\n onClear: () => void\n max?: number\n}\n\nexport interface DatePickerRender {\n (props: DatePickerRenderProps): ReactNode\n}\n\nconst defaultRender: DatePickerRender = ({\n count,\n focused,\n index,\n max,\n separator,\n value,\n}) => {\n const last = count - 1 === index\n\n return (\n <span style={{ marginInlineEnd: \"var(--gap)\" }}>\n {value}\n {((!isNumber(max) || count < max) && focused) || !last ? separator : null}\n </span>\n )\n}\n\nexport interface UseDatePickerProps<\n Multiple extends boolean = false,\n Range extends boolean = false,\n>\n extends\n Omit<UseCalendarProps<Multiple, Range>, \"format\" | \"ref\">,\n Omit<\n UseComboboxProps,\n \"defaultValue\" | \"initialFocusValue\" | \"onChange\" | \"ref\" | \"value\"\n >,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, allows input.\n *\n * @default true\n */\n allowInput?: boolean\n /**\n * If `true`, allows input of dates beyond the `minDate` and `maxDate` restrictions.\n *\n * @default true\n */\n allowInputBeyond?: boolean\n /**\n * If `true`, the date picker will be closed when the input value changes.\n *\n * @default false\n */\n closeOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * The initial value of the input.\n */\n defaultInputValue?: MaybeInputValue<Range>\n /**\n * If `true`, the input will be focused when the clear icon is clicked.\n *\n * @default true\n */\n focusOnClear?: boolean\n /**\n * The format used for conversion.\n * Check the docs to see the format of possible modifiers you can pass.\n *\n * @see https://day.js.org/docs/en/display/format#list-of-localized-formats\n */\n format?: DatePickerFormat\n /**\n * The `id` attribute of the input element.\n */\n id?: string\n /**\n * The value of the input.\n */\n inputValue?: MaybeInputValue<Range>\n /**\n * The `name` attribute of the input element.\n */\n name?: string\n /**\n * If `true`, the date picker will be opened when the input value changes.\n *\n * @default true\n */\n openOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * If `true`, the date picker will be opened when the input is focused.\n *\n * @default true\n */\n openOnFocus?: boolean\n /**\n * The pattern used to check the input element.\n */\n pattern?: RegExp\n /**\n * The placeholder for date picker.\n */\n placeholder?: string\n /**\n * The visual separator between each value.\n *\n * @default ','\n */\n separator?: string\n /**\n * The callback invoked when input value state changes.\n */\n onInputChange?: (value: MaybeInputValue<Range>) => void\n /**\n * Function that converts the input value to Date type.\n */\n parseDate?: (value: string) => Date | undefined\n /**\n * The function to render the selected date.\n */\n render?: (props: DatePickerRenderProps) => ReactNode\n}\n\nexport const useDatePicker = <\n Multiple extends boolean = false,\n Range extends boolean = false,\n>({\n maxDate = DEFAULT_MAX_DATE,\n minDate = DEFAULT_MIN_DATE,\n ...props\n}: UseDatePickerProps<Multiple, Range> = {}) => {\n if (dayjs(minDate).isAfter(dayjs(maxDate))) maxDate = minDate\n\n const { locale: defaultLocale, t } = useI18n(\"datePicker\")\n const {\n props: {\n id,\n ref,\n name,\n allowInput = true,\n allowInputBeyond = false,\n closeOnChange = false,\n multiple = false,\n closeOnSelect = !multiple,\n defaultInputValue,\n defaultMonth = new Date(),\n range = false,\n defaultValue = (range\n ? { end: undefined, start: undefined }\n : multiple\n ? []\n : undefined) as MaybeDateValue<Multiple, Range>,\n disabled,\n focusOnClear = true,\n format,\n inputValue: inputValueProp,\n locale = defaultLocale,\n max,\n month: monthProp,\n openOnChange = true,\n openOnClick = true,\n openOnFocus = true,\n parseDate,\n pattern,\n placeholder: placeholderProp,\n readOnly,\n render = defaultRender,\n required,\n separator = range ? \"-\" : \",\",\n value: valueProp,\n onChange: onChangeProp,\n onChangeMonth: onChangeMonthProp,\n onInputChange: onInputChangeProp,\n ...computedProps\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const dateTimeFormat = useDateTimeFormat({ locale })\n const { calendarFormat, inputFormat } = useMemo(() => {\n const { input: inputFormat, ...calendarFormat } = format ?? {}\n const defaultInputFormat: Intl.DateTimeFormatOptions = {\n day: \"numeric\",\n month: \"long\",\n year: \"numeric\",\n }\n\n return {\n calendarFormat,\n inputFormat:\n inputFormat !== null ? (inputFormat ?? defaultInputFormat) : undefined,\n }\n }, [format])\n const [calendarProps, rest] = useCalendarProps<Multiple, Range>(computedProps)\n const { excludeDate } = calendarProps\n const fieldRef = useRef<HTMLDivElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const startInputRef = useRef<HTMLInputElement>(null)\n const endInputRef = useRef<HTMLInputElement>(null)\n const focusByClickRef = useRef<boolean>(false)\n const [focused, setFocused] = useState(false)\n const [value, setValue] = useControllableState({\n defaultValue: defaultValue as MaybeDateValue<Multiple, Range>,\n value: valueProp,\n onChange: onChangeProp,\n })\n const [month, setMonth] = useControllableState({\n defaultValue: () => {\n let value = defaultMonth\n\n if (dayjs(minDate).isAfter(dayjs(defaultMonth)))\n value = dayjs(minDate).set(\"date\", 1).toDate()\n\n if (valueProp) {\n value = getAdjustedMonth(valueProp, value)\n } else if (defaultValue) {\n value = getAdjustedMonth(defaultValue, value)\n }\n\n return value\n },\n value: monthProp,\n onChange: onChangeMonthProp,\n })\n const stringToDate = useCallback(\n (value: string, start: Date = minDate, end: Date = maxDate) => {\n let date = parseDate?.(value)\n\n if (!date && dayjs(value).isValid()) date = dayjs(value, locale).toDate()\n\n if (date == null) return undefined\n if (excludeDate?.(date)) return undefined\n\n if (!allowInputBeyond) {\n if (isBeforeDate(date, start)) date = start\n if (isAfterDate(date, end)) date = end\n }\n\n return date\n },\n [allowInputBeyond, excludeDate, locale, maxDate, minDate, parseDate],\n )\n const dateToString = useCallback(\n (date?: Date) => {\n if (date == null) return \"\"\n\n return dateTimeFormat(date, inputFormat)\n },\n [dateTimeFormat, inputFormat],\n )\n const [inputValue, setInputValue] = useControllableState({\n defaultValue: () => {\n if (defaultInputValue) {\n if (isObject(defaultInputValue)) {\n if (dayjs(defaultInputValue.start).isValid())\n defaultInputValue.start = dateTimeFormat(\n dayjs(defaultInputValue.start).toDate(),\n inputFormat,\n )\n\n if (dayjs(defaultInputValue.end).isValid())\n defaultInputValue.end = dateTimeFormat(\n dayjs(defaultInputValue.end).toDate(),\n inputFormat,\n )\n\n return defaultInputValue\n } else {\n if (dayjs(defaultInputValue).isValid()) {\n return dateTimeFormat(\n dayjs(defaultInputValue).toDate(),\n inputFormat,\n ) as MaybeInputValue<Range>\n } else {\n return defaultInputValue as MaybeInputValue<Range>\n }\n }\n } else if (isDate(value)) {\n return dateToString(value) as MaybeInputValue<Range>\n } else if (isObject(value) && !isArray(value)) {\n return {\n end: dateToString(value.end),\n start: dateToString(value.start),\n } as MaybeInputValue<Range>\n } else {\n return \"\" as MaybeInputValue<Range>\n }\n },\n value: inputValueProp,\n onChange: onInputChangeProp,\n })\n const {\n interactive,\n open,\n getContentProps: getComboboxContentProps,\n getTriggerProps,\n popoverProps,\n onClose,\n onOpen,\n } = useCombobox({\n disabled,\n matchWidth: false,\n openOnClick: false,\n openOnEnter: !allowInput,\n openOnSpace: !allowInput,\n placement: \"end-start\",\n readOnly,\n transferFocus: false,\n ...ariaProps,\n ...dataProps,\n ...eventProps,\n ...rest,\n })\n const children = useMemo<ReactNode>(() => {\n if (!isArray(value)) return null\n\n const count = value.length\n\n return value.map((date, index) => {\n const value = dateToString(date)\n\n const onClear = (ev?: MouseEvent<HTMLElement>) => {\n ev?.preventDefault()\n ev?.stopPropagation()\n\n setValue(\n (prev) =>\n updateMaybeDateValue(date, max)(prev) as MaybeDateValue<\n Multiple,\n Range\n >,\n )\n }\n\n const component = render({\n count,\n date,\n focused,\n index,\n max,\n separator,\n value,\n onClear,\n })\n\n if (isValidElement<Dict>(component)) {\n return cloneElement(component, { ...component.props, key: index })\n } else {\n return component\n }\n })\n }, [dateToString, focused, max, render, separator, setValue, value])\n const { endPlaceholder, startPlaceholder } = useMemo(() => {\n if (range) {\n const startPlaceholder =\n placeholderProp ?? dateTimeFormat(new Date(), inputFormat)\n const endPlaceholder =\n placeholderProp ??\n dateTimeFormat(dayjs().add(1, \"day\").toDate(), inputFormat)\n\n return { endPlaceholder, startPlaceholder }\n } else {\n const placeholder =\n placeholderProp ?? dateTimeFormat(new Date(), inputFormat)\n\n return { endPlaceholder: placeholder, startPlaceholder: placeholder }\n }\n }, [dateTimeFormat, inputFormat, placeholderProp, range])\n\n const onChange = useCallback(\n (value: MaybeDateValue<Multiple, Range>) => {\n setValue(value)\n\n if (isArray(value)) {\n setInputValue(\"\" as MaybeInputValue<Range>)\n } else if (isObject(value) && !isDate(value)) {\n setInputValue({\n end: dateToString(value.end),\n start: dateToString(value.start),\n } as MaybeInputValue<Range>)\n } else {\n setInputValue(dateToString(value) as MaybeInputValue<Range>)\n }\n\n if (!closeOnSelect) return\n\n if (isObject(value) && !isArray(value) && !isDate(value)) {\n if (value.end && value.start) onClose()\n } else {\n onClose()\n }\n },\n [setValue, closeOnSelect, setInputValue, dateToString, onClose],\n )\n\n const onInputChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (!allowInput) return\n if (isArray(value) && value.length === max) return\n\n if (runIfFn(closeOnChange, ev)) {\n onClose()\n } else if (runIfFn(openOnChange, ev)) {\n onOpen()\n }\n\n let inputValue = ev.target.value\n\n if (pattern) inputValue = inputValue.replace(pattern, \"\")\n\n if (isArray(value)) {\n const date = stringToDate(inputValue)\n\n setInputValue(inputValue as MaybeInputValue<Range>)\n\n if (date) setMonth(dayjs(date).set(\"date\", 1).toDate())\n } else if (isObject(value) && !isDate(value)) {\n const align = contains(endInputRef.current, ev.target) ? \"end\" : \"start\"\n const minDate =\n value.start && align === \"end\"\n ? dayjs(value.start).add(1, \"day\").toDate()\n : undefined\n const maxDate =\n value.end && align === \"start\"\n ? dayjs(value.end).subtract(1, \"day\").toDate()\n : undefined\n const date = stringToDate(inputValue, minDate, maxDate)\n\n setInputValue((prev) =>\n isObject(prev)\n ? ({\n ...(prev as MaybeInputValue<true>),\n [align]: inputValue,\n } as MaybeInputValue<Range>)\n : prev,\n )\n setValue((prev) =>\n isObject(prev) && !isDate(prev)\n ? ({ ...prev, [align]: date } as MaybeDateValue<Multiple, Range>)\n : prev,\n )\n } else {\n const date = stringToDate(inputValue)\n\n setInputValue(inputValue as MaybeInputValue<Range>)\n setValue(date as MaybeDateValue<Multiple, Range>)\n }\n },\n [\n allowInput,\n closeOnChange,\n max,\n onClose,\n onOpen,\n openOnChange,\n pattern,\n setInputValue,\n setMonth,\n setValue,\n stringToDate,\n value,\n ],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (disabled || isComposing(ev)) return\n\n const inputValue = cast<HTMLInputElement>(ev.target).value\n\n runKeyAction(\n ev,\n {\n Backspace: (ev) => {\n if (!value || isDate(value)) return\n if (!!inputValue.length) return\n\n if (isArray(value)) {\n ev.preventDefault()\n\n setValue((prev) =>\n isArray(prev)\n ? (prev.slice(0, -1) as MaybeDateValue<Multiple, Range>)\n : prev,\n )\n } else if (contains(endInputRef.current, ev.target)) {\n ev.preventDefault()\n\n setInputValue({ end: \"\", start: \"\" } as MaybeInputValue<Range>)\n setValue({ end: undefined, start: undefined } as MaybeDateValue<\n Multiple,\n Range\n >)\n\n startInputRef.current?.focus()\n }\n },\n Enter: (ev) => {\n if (!open || !inputValue.length) return\n\n if (isDate(value) || isArray(value)) {\n const date = stringToDate(inputValue)\n\n if (!date) return\n\n ev.preventDefault()\n\n if (isArray(value)) {\n setInputValue(\"\" as MaybeInputValue<Range>)\n } else {\n setInputValue(dateToString(date) as MaybeInputValue<Range>)\n }\n\n setValue(\n (prev) =>\n updateMaybeDateValue(date, max)(prev) as MaybeDateValue<\n Multiple,\n Range\n >,\n )\n } else if (isObject(value)) {\n const align = contains(endInputRef.current, ev.target)\n ? \"end\"\n : \"start\"\n const minDate =\n value.start && align === \"end\"\n ? dayjs(value.start).add(1, \"day\").toDate()\n : undefined\n const maxDate =\n value.end && align === \"start\"\n ? dayjs(value.end).subtract(1, \"day\").toDate()\n : undefined\n const date = stringToDate(inputValue, minDate, maxDate)\n\n if (!date) return\n\n ev.preventDefault()\n\n setInputValue((prev) =>\n isObject(prev)\n ? ({\n ...(prev as MaybeInputValue<true>),\n [align]: dateToString(date),\n } as MaybeInputValue<Range>)\n : prev,\n )\n setValue((prev) =>\n isObject(prev) && !isDate(prev)\n ? ({ ...prev, [align]: date } as MaybeDateValue<\n Multiple,\n Range\n >)\n : prev,\n )\n\n if (align === \"start\") endInputRef.current?.focus()\n }\n },\n },\n { preventDefault: false },\n )\n },\n [\n dateToString,\n disabled,\n max,\n open,\n setInputValue,\n setValue,\n stringToDate,\n value,\n ],\n )\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n if (!interactive) return\n\n focusByClickRef.current = true\n\n if (allowInput) {\n if (isObject(value) && !isArray(value) && !isDate(value)) {\n if (contains(startInputRef.current, ev.target)) return\n if (contains(endInputRef.current, ev.target)) return\n\n const { end, start } = value\n\n if ((!start && !end) || !!end) {\n startInputRef.current?.focus()\n } else {\n endInputRef.current?.focus()\n }\n } else {\n startInputRef.current?.focus()\n }\n }\n\n if (openOnClick) onOpen()\n },\n [allowInput, interactive, onOpen, openOnClick, value],\n )\n\n const onMouseDown = useCallback(\n (ev: MouseEvent<HTMLDivElement | HTMLInputElement>) => {\n if (!openOnFocus) return\n\n ev.preventDefault()\n ev.stopPropagation()\n },\n [openOnFocus],\n )\n\n const onFieldFocus = useCallback(() => {\n if (allowInput) return\n\n if (openOnFocus) onOpen()\n\n focusByClickRef.current = false\n }, [allowInput, onOpen, openOnFocus])\n\n const onInputFocus = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n ev.preventDefault()\n ev.stopPropagation()\n\n setFocused(true)\n\n if (openOnFocus && !focusByClickRef.current) onOpen()\n\n focusByClickRef.current = false\n },\n [onOpen, openOnFocus],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n setFocused(false)\n\n if (\n contains(fieldRef.current, ev.relatedTarget) ||\n contains(contentRef.current, ev.relatedTarget)\n ) {\n ev.preventDefault()\n } else {\n if (isArray(value)) {\n setInputValue(\"\" as MaybeInputValue<Range>)\n } else if (isObject(value) && !isDate(value)) {\n setInputValue((prev) =>\n isObject(prev)\n ? ({\n end: dateToString(value.end),\n start: dateToString(value.start),\n } as MaybeInputValue<Range>)\n : prev,\n )\n } else {\n setInputValue(dateToString(value) as MaybeInputValue<Range>)\n }\n }\n },\n [dateToString, setInputValue, value],\n )\n\n const onClear = useCallback(() => {\n if (!interactive) return\n\n setValue((prev) => {\n if (isDate(prev)) {\n return undefined as MaybeDateValue<Multiple, Range>\n } else if (isArray(prev)) {\n return [] as unknown as MaybeDateValue<Multiple, Range>\n } else if (isObject(prev)) {\n return { end: undefined, start: undefined } as MaybeDateValue<\n Multiple,\n Range\n >\n } else {\n return prev\n }\n })\n\n setInputValue(\n (range ? { end: \"\", start: \"\" } : \"\") as MaybeInputValue<Range>,\n )\n\n if (focusOnClear) {\n if (allowInput) {\n startInputRef.current?.focus()\n } else {\n fieldRef.current?.focus()\n }\n }\n }, [allowInput, focusOnClear, interactive, range, setInputValue, setValue])\n\n useEffect(() => {\n if (!open) return\n\n return focusTransfer(\n contentRef.current,\n allowInput ? startInputRef.current : fieldRef.current,\n )\n }, [allowInput, open])\n\n useUpdateEffect(() => {\n setMonth((prev) => getAdjustedMonth(value, prev))\n }, [value, range])\n\n useUpdateEffect(() => {\n if (isArray(valueProp)) return\n\n if (isObject(valueProp) && !isDate(valueProp)) {\n setInputValue({\n end: dateToString(valueProp.end),\n start: dateToString(valueProp.start),\n } as MaybeInputValue<Range>)\n } else {\n setInputValue(dateToString(valueProp) as MaybeInputValue<Range>)\n }\n }, [valueProp])\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({\n \"data-range\": dataAttr(range),\n ...dataProps,\n ...props,\n }),\n [dataProps, range],\n )\n\n const getFieldProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getTriggerProps({\n ref: mergeRefs(ref, fieldRef),\n \"aria-haspopup\": \"dialog\",\n tabIndex: !allowInput ? 0 : -1,\n ...props,\n onClick: handlerAll(props.onClick, onClick),\n onFocus: handlerAll(props.onFocus, onFieldFocus),\n onMouseDown: handlerAll(props.onMouseDown, onMouseDown),\n }),\n\n [allowInput, getTriggerProps, onClick, onFieldFocus, onMouseDown],\n )\n\n const getInputProps: PropGetter<\"input\", { align?: InputAlign }> =\n useCallback(\n ({ align = \"start\", ...props } = {}) => {\n const inputProps: HTMLProps<\"input\"> = {\n style: {\n ...(!allowInput ? { pointerEvents: \"none\" } : {}),\n ...props.style,\n },\n autoComplete: \"off\",\n disabled,\n readOnly,\n required,\n tabIndex: allowInput ? 0 : -1,\n ...dataProps,\n ...props,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onInputChange),\n onFocus: handlerAll(props.onFocus, onInputFocus),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n onMouseDown: handlerAll(props.onMouseDown, onMouseDown),\n }\n\n if (isObject(inputValue)) {\n if (align === \"start\") {\n inputProps.ref = mergeRefs(props.ref, ref, startInputRef)\n inputProps.value = inputValue.start\n inputProps.placeholder = startPlaceholder\n } else {\n inputProps.ref = mergeRefs(props.ref, ref, endInputRef)\n inputProps.value = inputValue.end\n inputProps.placeholder = endPlaceholder\n }\n\n if (!inputValue.start && align === \"start\") {\n inputProps.id = id\n inputProps.name = name\n }\n\n if (!!inputValue.start && align === \"end\") {\n inputProps.id = id\n inputProps.name = name\n }\n } else {\n inputProps.ref = mergeRefs(props.ref, ref, startInputRef)\n inputProps.value = inputValue\n inputProps.id = id\n inputProps.name = name\n\n if (isArray(value)) {\n inputProps.style = {\n ...(!focused && !!value.length\n ? visuallyHiddenAttributes.style\n : {}),\n ...inputProps.style,\n }\n inputProps.placeholder = !value.length\n ? startPlaceholder\n : undefined\n inputProps[\"data-max\"] = dataAttr(\n isNumber(max) && value.length >= max,\n )\n } else {\n inputProps.placeholder = startPlaceholder\n }\n }\n\n return inputProps\n },\n [\n allowInput,\n dataProps,\n disabled,\n endPlaceholder,\n focused,\n id,\n inputValue,\n max,\n name,\n onBlur,\n onInputFocus,\n onInputChange,\n onKeyDown,\n onMouseDown,\n readOnly,\n ref,\n required,\n startPlaceholder,\n value,\n ],\n )\n\n const getContentProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getComboboxContentProps({\n ref: mergeRefs(ref, contentRef),\n role: \"dialog\",\n ...props,\n }),\n [getComboboxContentProps],\n )\n\n const getCalendarProps: PropGetter<UseCalendarProps<Multiple, Range>> =\n useCallback(\n (props) =>\n ({\n disabled: !interactive,\n format: calendarFormat,\n locale,\n max,\n maxDate,\n minDate,\n month,\n multiple,\n range,\n value,\n onChange,\n onChangeMonth: setMonth,\n ...calendarProps,\n ...props,\n }) as UseCalendarProps<Multiple, Range>,\n [\n interactive,\n calendarFormat,\n locale,\n max,\n maxDate,\n minDate,\n month,\n multiple,\n range,\n value,\n onChange,\n setMonth,\n calendarProps,\n ],\n )\n\n const getIconProps: PropGetter = useCallback(\n (props) => ({ ...dataProps, ...props }),\n [dataProps],\n )\n\n const getClearIconProps: PropGetter = useCallback(\n (props = {}) =>\n getIconProps({\n \"aria-disabled\": ariaAttr(!interactive),\n \"aria-label\": t(\"Clear value\"),\n role: \"button\",\n tabIndex: interactive ? 0 : -1,\n ...props,\n onClick: handlerAll(props.onClick, onClear),\n onKeyDown: handlerAll(props.onKeyDown, (ev) =>\n runKeyAction(ev, { Enter: onClear, Space: onClear }),\n ),\n }),\n [getIconProps, interactive, onClear, t],\n )\n\n return {\n children,\n dateToString,\n inputValue,\n interactive,\n month,\n open,\n range,\n separator,\n setInputValue,\n setMonth,\n setValue,\n stringToDate,\n value,\n getCalendarProps,\n getClearIconProps,\n getContentProps,\n getFieldProps,\n getIconProps,\n getInputProps,\n getRootProps,\n popoverProps,\n onChange,\n onClose,\n onInputChange,\n onOpen,\n }\n}\n\nexport type UseDatePickerReturn = ReturnType<typeof useDatePicker>\n"],"mappings":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ACA;EACA;EACA;EACA;EACA;EACA,eAAe;EACf,GAAG;EACH,GAAGR;EACJ,GACH;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CACF;CAEH,MAAMS,uCACH,aAAW;EAAE,GAAG;EAAW,GAAGT;EAAO,GACtC,CAAC,UAAU,CACZ;AAkBD,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,2CA9BC,UAAQ,EAAE,KACT,aAAa;GACX,iEAA0B,CAAC,YAAY;GACvC,cAAc,EAAE,cAAc;GAC9B,MAAM;GACN,UAAU,cAAc,IAAI;GAC5B,GAAGA;GACH,2DAAoBA,QAAM,SAAS,QAAQ;GAC3C,6DAAsBA,QAAM,YAAY,OACtCU,yBAAa,IAAI;IAAE,OAAO;IAAS,OAAO;IAAS,CAAC,CACrD;GACF,CAAC,EACJ;GAAC;GAAc;GAAa;GAAS;GAAE,CACxC;EAkBC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
|
|
1
|
+
{"version":3,"file":"use-date-picker.cjs","names":["defaultRender: DatePickerRender","DEFAULT_MAX_DATE","DEFAULT_MIN_DATE","useI18n","useFieldProps","useDateTimeFormat","inputFormat","calendarFormat","useCalendarProps","useControllableState","value","getAdjustedMonth","isBeforeDate","isAfterDate","useCombobox","onClear","updateMaybeDateValue","startPlaceholder","inputValue","minDate","maxDate","isComposing","ev","getRootProps: PropGetter","props","getFieldProps: PropGetter","mergeRefs","ref","getInputProps: PropGetter<\"input\", { align?: InputAlign }>","inputProps: HTMLProps<\"input\">","visuallyHiddenAttributes","getContentProps: PropGetter","getCalendarProps: PropGetter<UseCalendarProps<Multiple, Range>>","getIconProps: PropGetter","runKeyAction"],"sources":["../../../../src/components/date-picker/use-date-picker.tsx"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n} from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type { UseComboboxProps } from \"../../hooks/use-combobox\"\nimport type { Dict } from \"../../utils\"\nimport type {\n CalendarFormat,\n MaybeDateValue,\n UseCalendarProps,\n} from \"../calendar\"\nimport type { FieldProps } from \"../field\"\nimport dayjs from \"dayjs\"\nimport {\n cloneElement,\n isValidElement,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\"\nimport { useCombobox } from \"../../hooks/use-combobox\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n ariaAttr,\n cast,\n contains,\n dataAttr,\n focusTransfer,\n handlerAll,\n isArray,\n isComposing,\n isDate,\n isNumber,\n isObject,\n mergeRefs,\n runIfFn,\n runKeyAction,\n useUpdateEffect,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport {\n DEFAULT_MAX_DATE,\n DEFAULT_MIN_DATE,\n getAdjustedMonth,\n isAfterDate,\n isBeforeDate,\n updateMaybeDateValue,\n useCalendarProps,\n} from \"../calendar\"\nimport { useFieldProps } from \"../field\"\nimport { useDateTimeFormat } from \"../format\"\n\nexport interface DatePickerFormat extends CalendarFormat {\n input?: Intl.DateTimeFormatOptions | null\n}\n\ntype InputAlign = \"end\" | \"start\"\ntype MaybeInputValue<Range extends boolean = false> = Range extends true\n ? { end?: string; start?: string }\n : string | undefined\n\ninterface DatePickerRenderProps {\n count: number\n date: Date\n focused: boolean\n index: number\n separator: string\n value: string\n onClear: () => void\n max?: number\n}\n\nexport interface DatePickerRender {\n (props: DatePickerRenderProps): ReactNode\n}\n\nconst defaultRender: DatePickerRender = ({\n count,\n focused,\n index,\n max,\n separator,\n value,\n}) => {\n const last = count - 1 === index\n\n return (\n <span style={{ marginInlineEnd: \"var(--gap)\" }}>\n {value}\n {((!isNumber(max) || count < max) && focused) || !last ? separator : null}\n </span>\n )\n}\n\nexport interface UseDatePickerProps<\n Multiple extends boolean = false,\n Range extends boolean = false,\n>\n extends\n Omit<UseCalendarProps<Multiple, Range>, \"format\" | \"ref\">,\n Omit<\n UseComboboxProps,\n \"defaultValue\" | \"initialFocusValue\" | \"onChange\" | \"ref\" | \"value\"\n >,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, allows input.\n *\n * @default true\n */\n allowInput?: boolean\n /**\n * If `true`, allows input of dates beyond the `minDate` and `maxDate` restrictions.\n *\n * @default true\n */\n allowInputBeyond?: boolean\n /**\n * If `true`, the date picker will be closed when the input value changes.\n *\n * @default false\n */\n closeOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * The initial value of the input.\n */\n defaultInputValue?: MaybeInputValue<Range>\n /**\n * If `true`, the input will be focused when the clear icon is clicked.\n *\n * @default true\n */\n focusOnClear?: boolean\n /**\n * The format used for conversion.\n * Check the docs to see the format of possible modifiers you can pass.\n *\n * @see https://day.js.org/docs/en/display/format#list-of-localized-formats\n */\n format?: DatePickerFormat\n /**\n * The `id` attribute of the input element.\n */\n id?: string\n /**\n * The value of the input.\n */\n inputValue?: MaybeInputValue<Range>\n /**\n * The `name` attribute of the input element.\n */\n name?: string\n /**\n * If `true`, the date picker will be opened when the input value changes.\n *\n * @default true\n */\n openOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * If `true`, the date picker will be opened when the input is focused.\n *\n * @default true\n */\n openOnFocus?: boolean\n /**\n * The pattern used to check the input element.\n */\n pattern?: RegExp\n /**\n * The placeholder for date picker.\n */\n placeholder?: string\n /**\n * The visual separator between each value.\n *\n * @default ','\n */\n separator?: string\n /**\n * The callback invoked when input value state changes.\n */\n onInputChange?: (value: MaybeInputValue<Range>) => void\n /**\n * Function that converts the input value to Date type.\n */\n parseDate?: (value: string) => Date | undefined\n /**\n * The function to render the selected date.\n */\n render?: (props: DatePickerRenderProps) => ReactNode\n}\n\nexport const useDatePicker = <\n Multiple extends boolean = false,\n Range extends boolean = false,\n>({\n maxDate = DEFAULT_MAX_DATE,\n minDate = DEFAULT_MIN_DATE,\n ...props\n}: UseDatePickerProps<Multiple, Range> = {}) => {\n if (dayjs(minDate).isAfter(dayjs(maxDate))) maxDate = minDate\n\n const { locale: defaultLocale, t } = useI18n(\"datePicker\")\n const {\n props: {\n id,\n ref,\n name,\n allowInput = true,\n allowInputBeyond = false,\n closeOnChange = false,\n multiple = false,\n closeOnSelect = !multiple,\n defaultInputValue,\n defaultMonth = new Date(),\n range = false,\n defaultValue = (range\n ? { end: undefined, start: undefined }\n : multiple\n ? []\n : undefined) as MaybeDateValue<Multiple, Range>,\n disabled,\n focusOnClear = true,\n format,\n inputValue: inputValueProp,\n locale = defaultLocale,\n max,\n month: monthProp,\n openOnChange = true,\n openOnClick = true,\n openOnFocus = true,\n parseDate,\n pattern,\n placeholder: placeholderProp,\n readOnly,\n render = defaultRender,\n required,\n separator = range ? \"-\" : \",\",\n value: valueProp,\n onChange: onChangeProp,\n onChangeMonth: onChangeMonthProp,\n onInputChange: onInputChangeProp,\n ...computedProps\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const dateTimeFormat = useDateTimeFormat({ locale })\n const { calendarFormat, inputFormat } = useMemo(() => {\n const { input: inputFormat, ...calendarFormat } = format ?? {}\n const defaultInputFormat: Intl.DateTimeFormatOptions = {\n day: \"numeric\",\n month: \"long\",\n year: \"numeric\",\n }\n\n return {\n calendarFormat,\n inputFormat:\n inputFormat !== null ? (inputFormat ?? defaultInputFormat) : undefined,\n }\n }, [format])\n const [calendarProps, rest] = useCalendarProps<Multiple, Range>(computedProps)\n const { excludeDate } = calendarProps\n const fieldRef = useRef<HTMLDivElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const startInputRef = useRef<HTMLInputElement>(null)\n const endInputRef = useRef<HTMLInputElement>(null)\n const focusByClickRef = useRef<boolean>(false)\n const [focused, setFocused] = useState(false)\n const [value, setValue] = useControllableState({\n defaultValue: defaultValue as MaybeDateValue<Multiple, Range>,\n value: valueProp,\n onChange: onChangeProp,\n })\n const [month, setMonth] = useControllableState({\n defaultValue: () => {\n let value = defaultMonth\n\n if (dayjs(minDate).isAfter(dayjs(defaultMonth)))\n value = dayjs(minDate).set(\"date\", 1).toDate()\n\n if (valueProp) {\n value = getAdjustedMonth(valueProp, value)\n } else if (defaultValue) {\n value = getAdjustedMonth(defaultValue, value)\n }\n\n return value\n },\n value: monthProp,\n onChange: onChangeMonthProp,\n })\n const stringToDate = useCallback(\n (value: string, start: Date = minDate, end: Date = maxDate) => {\n let date = parseDate?.(value)\n\n if (!date && dayjs(value).isValid()) date = dayjs(value, locale).toDate()\n\n if (date == null) return undefined\n if (excludeDate?.(date)) return undefined\n\n if (!allowInputBeyond) {\n if (isBeforeDate(date, start)) date = start\n if (isAfterDate(date, end)) date = end\n }\n\n return date\n },\n [allowInputBeyond, excludeDate, locale, maxDate, minDate, parseDate],\n )\n const dateToString = useCallback(\n (date?: Date) => {\n if (date == null) return \"\"\n\n return dateTimeFormat(date, inputFormat)\n },\n [dateTimeFormat, inputFormat],\n )\n const [inputValue, setInputValue] = useControllableState({\n defaultValue: () => {\n if (defaultInputValue) {\n if (isObject(defaultInputValue)) {\n if (dayjs(defaultInputValue.start).isValid())\n defaultInputValue.start = dateTimeFormat(\n dayjs(defaultInputValue.start).toDate(),\n inputFormat,\n )\n\n if (dayjs(defaultInputValue.end).isValid())\n defaultInputValue.end = dateTimeFormat(\n dayjs(defaultInputValue.end).toDate(),\n inputFormat,\n )\n\n return defaultInputValue\n } else {\n if (dayjs(defaultInputValue).isValid()) {\n return dateTimeFormat(\n dayjs(defaultInputValue).toDate(),\n inputFormat,\n ) as MaybeInputValue<Range>\n } else {\n return defaultInputValue as MaybeInputValue<Range>\n }\n }\n } else if (isDate(value)) {\n return dateToString(value) as MaybeInputValue<Range>\n } else if (isObject(value) && !isArray(value)) {\n return {\n end: dateToString(value.end),\n start: dateToString(value.start),\n } as MaybeInputValue<Range>\n } else {\n return \"\" as MaybeInputValue<Range>\n }\n },\n value: inputValueProp,\n onChange: onInputChangeProp,\n })\n const {\n interactive,\n open,\n getContentProps: getComboboxContentProps,\n getTriggerProps,\n popoverProps,\n onClose,\n onOpen,\n } = useCombobox({\n disabled,\n matchWidth: false,\n openOnClick: false,\n openOnEnter: !allowInput,\n openOnSpace: !allowInput,\n placement: \"end-start\",\n readOnly,\n transferFocus: false,\n ...ariaProps,\n ...dataProps,\n ...eventProps,\n ...rest,\n })\n const children = useMemo<ReactNode>(() => {\n if (!isArray(value)) return null\n\n const count = value.length\n\n return value.map((date, index) => {\n const value = dateToString(date)\n\n const onClear = (ev?: MouseEvent<HTMLElement>) => {\n ev?.preventDefault()\n ev?.stopPropagation()\n\n setValue(\n (prev) =>\n updateMaybeDateValue(date, max)(prev) as MaybeDateValue<\n Multiple,\n Range\n >,\n )\n }\n\n const component = render({\n count,\n date,\n focused,\n index,\n max,\n separator,\n value,\n onClear,\n })\n\n if (isValidElement<Dict>(component)) {\n return cloneElement(component, { ...component.props, key: index })\n } else {\n return component\n }\n })\n }, [dateToString, focused, max, render, separator, setValue, value])\n const { endPlaceholder, startPlaceholder } = useMemo(() => {\n if (range) {\n const startPlaceholder =\n placeholderProp ?? dateTimeFormat(new Date(), inputFormat)\n const endPlaceholder =\n placeholderProp ??\n dateTimeFormat(dayjs().add(1, \"day\").toDate(), inputFormat)\n\n return { endPlaceholder, startPlaceholder }\n } else {\n const placeholder =\n placeholderProp ?? dateTimeFormat(new Date(), inputFormat)\n\n return { endPlaceholder: placeholder, startPlaceholder: placeholder }\n }\n }, [dateTimeFormat, inputFormat, placeholderProp, range])\n\n const onChange = useCallback(\n (value: MaybeDateValue<Multiple, Range>) => {\n setValue(value)\n\n if (isArray(value)) {\n setInputValue(\"\" as MaybeInputValue<Range>)\n } else if (isObject(value) && !isDate(value)) {\n setInputValue({\n end: dateToString(value.end),\n start: dateToString(value.start),\n } as MaybeInputValue<Range>)\n } else {\n setInputValue(dateToString(value) as MaybeInputValue<Range>)\n }\n\n if (!closeOnSelect) return\n\n if (isObject(value) && !isArray(value) && !isDate(value)) {\n if (value.end && value.start) onClose()\n } else {\n onClose()\n }\n },\n [setValue, closeOnSelect, setInputValue, dateToString, onClose],\n )\n\n const onInputChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (!allowInput) return\n if (isArray(value) && value.length === max) return\n\n if (runIfFn(closeOnChange, ev)) {\n onClose()\n } else if (runIfFn(openOnChange, ev)) {\n onOpen()\n }\n\n let inputValue = ev.target.value\n\n if (pattern) inputValue = inputValue.replace(pattern, \"\")\n\n if (isArray(value)) {\n const date = stringToDate(inputValue)\n\n setInputValue(inputValue as MaybeInputValue<Range>)\n\n if (date) setMonth(dayjs(date).set(\"date\", 1).toDate())\n } else if (isObject(value) && !isDate(value)) {\n const align = contains(endInputRef.current, ev.target) ? \"end\" : \"start\"\n const minDate =\n value.start && align === \"end\"\n ? dayjs(value.start).add(1, \"day\").toDate()\n : undefined\n const maxDate =\n value.end && align === \"start\"\n ? dayjs(value.end).subtract(1, \"day\").toDate()\n : undefined\n const date = stringToDate(inputValue, minDate, maxDate)\n\n setInputValue((prev) =>\n isObject(prev)\n ? ({\n ...(prev as MaybeInputValue<true>),\n [align]: inputValue,\n } as MaybeInputValue<Range>)\n : prev,\n )\n setValue((prev) =>\n isObject(prev) && !isDate(prev)\n ? ({ ...prev, [align]: date } as MaybeDateValue<Multiple, Range>)\n : prev,\n )\n } else {\n const date = stringToDate(inputValue)\n\n setInputValue(inputValue as MaybeInputValue<Range>)\n setValue(date as MaybeDateValue<Multiple, Range>)\n }\n },\n [\n allowInput,\n closeOnChange,\n max,\n onClose,\n onOpen,\n openOnChange,\n pattern,\n setInputValue,\n setMonth,\n setValue,\n stringToDate,\n value,\n ],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (disabled || isComposing(ev)) return\n\n const inputValue = cast<HTMLInputElement>(ev.target).value\n\n runKeyAction(\n ev,\n {\n Backspace: (ev) => {\n if (!value || isDate(value)) return\n if (inputValue.length) return\n\n if (isArray(value)) {\n ev.preventDefault()\n\n setValue((prev) =>\n isArray(prev)\n ? (prev.slice(0, -1) as MaybeDateValue<Multiple, Range>)\n : prev,\n )\n } else if (contains(endInputRef.current, ev.target)) {\n ev.preventDefault()\n\n setInputValue({ end: \"\", start: \"\" } as MaybeInputValue<Range>)\n setValue({ end: undefined, start: undefined } as MaybeDateValue<\n Multiple,\n Range\n >)\n\n startInputRef.current?.focus()\n }\n },\n Enter: (ev) => {\n if (!open || !inputValue.length) return\n\n if (isDate(value) || isArray(value)) {\n const date = stringToDate(inputValue)\n\n if (!date) return\n\n ev.preventDefault()\n\n if (isArray(value)) {\n setInputValue(\"\" as MaybeInputValue<Range>)\n } else {\n setInputValue(dateToString(date) as MaybeInputValue<Range>)\n }\n\n setValue(\n (prev) =>\n updateMaybeDateValue(date, max)(prev) as MaybeDateValue<\n Multiple,\n Range\n >,\n )\n } else if (isObject(value)) {\n const align = contains(endInputRef.current, ev.target)\n ? \"end\"\n : \"start\"\n const minDate =\n value.start && align === \"end\"\n ? dayjs(value.start).add(1, \"day\").toDate()\n : undefined\n const maxDate =\n value.end && align === \"start\"\n ? dayjs(value.end).subtract(1, \"day\").toDate()\n : undefined\n const date = stringToDate(inputValue, minDate, maxDate)\n\n if (!date) return\n\n ev.preventDefault()\n\n setInputValue((prev) =>\n isObject(prev)\n ? ({\n ...(prev as MaybeInputValue<true>),\n [align]: dateToString(date),\n } as MaybeInputValue<Range>)\n : prev,\n )\n setValue((prev) =>\n isObject(prev) && !isDate(prev)\n ? ({ ...prev, [align]: date } as MaybeDateValue<\n Multiple,\n Range\n >)\n : prev,\n )\n\n if (align === \"start\") endInputRef.current?.focus()\n }\n },\n },\n { preventDefault: false },\n )\n },\n [\n dateToString,\n disabled,\n max,\n open,\n setInputValue,\n setValue,\n stringToDate,\n value,\n ],\n )\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n if (!interactive) return\n\n focusByClickRef.current = true\n\n if (allowInput) {\n if (isObject(value) && !isArray(value) && !isDate(value)) {\n if (contains(startInputRef.current, ev.target)) return\n if (contains(endInputRef.current, ev.target)) return\n\n const { end, start } = value\n\n if ((!start && !end) || !!end) {\n startInputRef.current?.focus()\n } else {\n endInputRef.current?.focus()\n }\n } else {\n startInputRef.current?.focus()\n }\n }\n\n if (openOnClick) onOpen()\n },\n [allowInput, interactive, onOpen, openOnClick, value],\n )\n\n const onMouseDown = useCallback(\n (ev: MouseEvent<HTMLDivElement | HTMLInputElement>) => {\n if (!openOnFocus) return\n\n ev.preventDefault()\n ev.stopPropagation()\n },\n [openOnFocus],\n )\n\n const onFieldFocus = useCallback(() => {\n if (allowInput) return\n\n if (openOnFocus) onOpen()\n\n focusByClickRef.current = false\n }, [allowInput, onOpen, openOnFocus])\n\n const onInputFocus = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n ev.preventDefault()\n ev.stopPropagation()\n\n setFocused(true)\n\n if (openOnFocus && !focusByClickRef.current) onOpen()\n\n focusByClickRef.current = false\n },\n [onOpen, openOnFocus],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n setFocused(false)\n\n if (\n contains(fieldRef.current, ev.relatedTarget) ||\n contains(contentRef.current, ev.relatedTarget)\n ) {\n ev.preventDefault()\n } else {\n if (isArray(value)) {\n setInputValue(\"\" as MaybeInputValue<Range>)\n } else if (isObject(value) && !isDate(value)) {\n setInputValue((prev) =>\n isObject(prev)\n ? ({\n end: dateToString(value.end),\n start: dateToString(value.start),\n } as MaybeInputValue<Range>)\n : prev,\n )\n } else {\n setInputValue(dateToString(value) as MaybeInputValue<Range>)\n }\n }\n },\n [dateToString, setInputValue, value],\n )\n\n const onClear = useCallback(() => {\n if (!interactive) return\n\n setValue((prev) => {\n if (isDate(prev)) {\n return undefined as MaybeDateValue<Multiple, Range>\n } else if (isArray(prev)) {\n return [] as unknown as MaybeDateValue<Multiple, Range>\n } else if (isObject(prev)) {\n return { end: undefined, start: undefined } as MaybeDateValue<\n Multiple,\n Range\n >\n } else {\n return prev\n }\n })\n\n setInputValue(\n (range ? { end: \"\", start: \"\" } : \"\") as MaybeInputValue<Range>,\n )\n\n if (focusOnClear) {\n if (allowInput) {\n startInputRef.current?.focus()\n } else {\n fieldRef.current?.focus()\n }\n }\n }, [allowInput, focusOnClear, interactive, range, setInputValue, setValue])\n\n useEffect(() => {\n if (!open) return\n\n return focusTransfer(\n contentRef.current,\n allowInput ? startInputRef.current : fieldRef.current,\n )\n }, [allowInput, open])\n\n useUpdateEffect(() => {\n setMonth((prev) => getAdjustedMonth(value, prev))\n }, [value, range])\n\n useUpdateEffect(() => {\n if (isArray(valueProp)) return\n\n if (isObject(valueProp) && !isDate(valueProp)) {\n setInputValue({\n end: dateToString(valueProp.end),\n start: dateToString(valueProp.start),\n } as MaybeInputValue<Range>)\n } else {\n setInputValue(dateToString(valueProp) as MaybeInputValue<Range>)\n }\n }, [valueProp])\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({\n \"data-range\": dataAttr(range),\n ...dataProps,\n ...props,\n }),\n [dataProps, range],\n )\n\n const getFieldProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getTriggerProps({\n ref: mergeRefs(ref, fieldRef),\n \"aria-haspopup\": \"dialog\",\n tabIndex: !allowInput ? 0 : -1,\n ...props,\n onClick: handlerAll(props.onClick, onClick),\n onFocus: handlerAll(props.onFocus, onFieldFocus),\n onMouseDown: handlerAll(props.onMouseDown, onMouseDown),\n }),\n\n [allowInput, getTriggerProps, onClick, onFieldFocus, onMouseDown],\n )\n\n const getInputProps: PropGetter<\"input\", { align?: InputAlign }> =\n useCallback(\n ({ align = \"start\", ...props } = {}) => {\n const inputProps: HTMLProps<\"input\"> = {\n style: {\n ...(!allowInput ? { pointerEvents: \"none\" } : {}),\n ...props.style,\n },\n autoComplete: \"off\",\n disabled,\n readOnly,\n required,\n tabIndex: allowInput ? 0 : -1,\n ...dataProps,\n ...props,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onInputChange),\n onFocus: handlerAll(props.onFocus, onInputFocus),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n onMouseDown: handlerAll(props.onMouseDown, onMouseDown),\n }\n\n if (isObject(inputValue)) {\n if (align === \"start\") {\n inputProps.ref = mergeRefs(props.ref, ref, startInputRef)\n inputProps.value = inputValue.start\n inputProps.placeholder = startPlaceholder\n } else {\n inputProps.ref = mergeRefs(props.ref, ref, endInputRef)\n inputProps.value = inputValue.end\n inputProps.placeholder = endPlaceholder\n }\n\n if (!inputValue.start && align === \"start\") {\n inputProps.id = id\n inputProps.name = name\n }\n\n if (!!inputValue.start && align === \"end\") {\n inputProps.id = id\n inputProps.name = name\n }\n } else {\n inputProps.ref = mergeRefs(props.ref, ref, startInputRef)\n inputProps.value = inputValue\n inputProps.id = id\n inputProps.name = name\n\n if (isArray(value)) {\n inputProps.style = {\n ...(!focused && !!value.length\n ? visuallyHiddenAttributes.style\n : {}),\n ...inputProps.style,\n }\n inputProps.placeholder = !value.length\n ? startPlaceholder\n : undefined\n inputProps[\"data-max\"] = dataAttr(\n isNumber(max) && value.length >= max,\n )\n } else {\n inputProps.placeholder = startPlaceholder\n }\n }\n\n return inputProps\n },\n [\n allowInput,\n dataProps,\n disabled,\n endPlaceholder,\n focused,\n id,\n inputValue,\n max,\n name,\n onBlur,\n onInputFocus,\n onInputChange,\n onKeyDown,\n onMouseDown,\n readOnly,\n ref,\n required,\n startPlaceholder,\n value,\n ],\n )\n\n const getContentProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getComboboxContentProps({\n ref: mergeRefs(ref, contentRef),\n role: \"dialog\",\n ...props,\n }),\n [getComboboxContentProps],\n )\n\n const getCalendarProps: PropGetter<UseCalendarProps<Multiple, Range>> =\n useCallback(\n (props) =>\n ({\n disabled: !interactive,\n format: calendarFormat,\n locale,\n max,\n maxDate,\n minDate,\n month,\n multiple,\n range,\n value,\n onChange,\n onChangeMonth: setMonth,\n ...calendarProps,\n ...props,\n }) as UseCalendarProps<Multiple, Range>,\n [\n interactive,\n calendarFormat,\n locale,\n max,\n maxDate,\n minDate,\n month,\n multiple,\n range,\n value,\n onChange,\n setMonth,\n calendarProps,\n ],\n )\n\n const getIconProps: PropGetter = useCallback(\n (props) => ({ ...dataProps, ...props }),\n [dataProps],\n )\n\n const getClearIconProps: PropGetter = useCallback(\n (props = {}) =>\n getIconProps({\n \"aria-disabled\": ariaAttr(!interactive),\n \"aria-label\": t(\"Clear value\"),\n role: \"button\",\n tabIndex: interactive ? 0 : -1,\n ...props,\n onClick: handlerAll(props.onClick, onClear),\n onKeyDown: handlerAll(props.onKeyDown, (ev) =>\n runKeyAction(ev, { Enter: onClear, Space: onClear }),\n ),\n }),\n [getIconProps, interactive, onClear, t],\n )\n\n return {\n children,\n dateToString,\n inputValue,\n interactive,\n month,\n open,\n range,\n separator,\n setInputValue,\n setMonth,\n setValue,\n stringToDate,\n value,\n getCalendarProps,\n getClearIconProps,\n getContentProps,\n getFieldProps,\n getIconProps,\n getInputProps,\n getRootProps,\n popoverProps,\n onChange,\n onClose,\n onInputChange,\n onOpen,\n }\n}\n\nexport type UseDatePickerReturn = ReturnType<typeof useDatePicker>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAqFA,MAAMA,iBAAmC,EACvC,OACA,SACA,OACA,KACA,WACA,YACI;CACJ,MAAM,OAAO,QAAQ,MAAM;AAE3B,QACE,4CAAC;EAAK,OAAO,EAAE,iBAAiB,cAAc;aAC3C,QACE,iDAAU,IAAI,IAAI,QAAQ,QAAQ,WAAY,CAAC,OAAO,YAAY;GAChE;;AAuGX,MAAa,iBAGX,EACA,UAAUC,uCACV,UAAUC,uCACV,GAAG,UACoC,EAAE,KAAK;AAC9C,wBAAU,QAAQ,CAAC,2BAAc,QAAQ,CAAC,CAAE,WAAU;CAEtD,MAAM,EAAE,QAAQ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,IAAI;GAC5B,GAAGA;GACH,2DAAoBA,QAAM,SAAS,QAAQ;GAC3C,6DAAsBA,QAAM,YAAY,OACtCU,yBAAa,IAAI;IAAE,OAAO;IAAS,OAAO;IAAS,CAAC,CACrD;GACF,CAAC,EACJ;GAAC;GAAc;GAAa;GAAS;GAAE,CACxC;EAkBC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropzone.cjs","names":["createSlotComponent","dropzoneStyle","useInputBorder","useDropzone","Portal","styled","Fade","useLoadingComponent","DropzoneAccept: FC<DropzoneAcceptProps>","DropzoneReject: FC<DropzoneRejectProps>","DropzoneIdle: FC<DropzoneIdleProps>"],"sources":["../../../../src/components/dropzone/dropzone.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren } from \"react\"\nimport type { HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { Merge } from \"../../utils\"\nimport type { FadeProps } from \"../fade\"\nimport type { UseInputBorderProps } from \"../input\"\nimport type { Loading } from \"../loading\"\nimport type { DropzoneStyle } from \"./dropzone.style\"\nimport type { UseDropzoneProps, UseDropzoneReturn } from \"./use-dropzone\"\nimport { useMemo } from \"react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { Fade } from \"../fade\"\nimport { useInputBorder } from \"../input\"\nimport { useLoadingComponent } from \"../loading\"\nimport { Portal } from \"../portal\"\nimport { dropzoneStyle } from \"./dropzone.style\"\nimport { useDropzone } from \"./use-dropzone\"\n\ninterface ComponentContext extends Pick<\n UseDropzoneReturn,\n \"dragAccept\" | \"dragIdle\" | \"dragReject\" | \"loading\"\n> {}\n\nexport interface DropzoneRootProps\n extends\n Merge<HTMLStyledProps, UseDropzoneProps>,\n UseInputBorderProps,\n ThemeProps<DropzoneStyle>,\n Pick<DropzoneLoadingProps, \"loadingScheme\"> {\n /**\n * Props for dropzone input element.\n */\n inputProps?: HTMLStyledProps<\"input\">\n /**\n * Props for dropzone loading icon element.\n */\n loadingProps?: DropzoneLoadingProps\n /**\n * Props for dropzone overlay element.\n */\n overlayProps?: DropzoneOverlayProps\n}\n\nconst {\n ComponentContext,\n PropsContext: DropzonePropsContext,\n useComponentContext,\n usePropsContext: useDropzonePropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<DropzoneRootProps, DropzoneStyle>(\n \"dropzone\",\n dropzoneStyle,\n)\n\nexport { DropzonePropsContext, useDropzonePropsContext }\n\n/**\n * `Dropzone` is a component used for uploading files via drag and drop.\n *\n * @see https://yamada-ui.com/docs/components/dropzone\n */\nexport const DropzoneRoot = withProvider(\n ({\n children,\n errorBorderColor,\n focusBorderColor,\n loadingScheme,\n inputProps,\n loadingProps,\n overlayProps,\n ...rest\n }) => {\n const varProps = useInputBorder({ errorBorderColor, focusBorderColor })\n const {\n dragAccept,\n dragIdle,\n dragReject,\n loading,\n getInputProps,\n getRootProps,\n } = useDropzone(rest)\n const context = useMemo(\n () => ({\n dragAccept,\n dragIdle,\n dragReject,\n loading,\n }),\n [dragAccept, dragIdle, dragReject, loading],\n )\n\n return (\n <ComponentContext value={context}>\n <Portal>\n <styled.input {...getInputProps(inputProps)} />\n </Portal>\n\n <styled.div data-group {...varProps} {...getRootProps()}>\n <DropzoneOverlay {...overlayProps}>\n <DropzoneLoading loadingScheme={loadingScheme} {...loadingProps} />\n </DropzoneOverlay>\n\n {children}\n </styled.div>\n </ComponentContext>\n )\n },\n \"root\",\n)()\n\nexport interface DropzoneIconProps extends HTMLStyledProps<\"svg\"> {}\n\nexport const DropzoneIcon = withContext<\"svg\", DropzoneIconProps>(\n \"svg\",\n \"icon\",\n)()\n\nexport interface DropzoneTitleProps extends HTMLStyledProps<\"p\"> {}\n\nexport const DropzoneTitle = withContext<\"p\", DropzoneTitleProps>(\n \"p\",\n \"title\",\n)()\n\nexport interface DropzoneDescriptionProps extends HTMLStyledProps<\"p\"> {}\n\nexport const DropzoneDescription = withContext<\"p\", DropzoneDescriptionProps>(\n \"p\",\n \"description\",\n)()\n\
|
|
1
|
+
{"version":3,"file":"dropzone.cjs","names":["createSlotComponent","dropzoneStyle","useInputBorder","useDropzone","Portal","styled","Fade","useLoadingComponent","DropzoneAccept: FC<DropzoneAcceptProps>","DropzoneReject: FC<DropzoneRejectProps>","DropzoneIdle: FC<DropzoneIdleProps>"],"sources":["../../../../src/components/dropzone/dropzone.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren } from \"react\"\nimport type { HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { Merge } from \"../../utils\"\nimport type { FadeProps } from \"../fade\"\nimport type { UseInputBorderProps } from \"../input\"\nimport type { Loading } from \"../loading\"\nimport type { DropzoneStyle } from \"./dropzone.style\"\nimport type { UseDropzoneProps, UseDropzoneReturn } from \"./use-dropzone\"\nimport { useMemo } from \"react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { Fade } from \"../fade\"\nimport { useInputBorder } from \"../input\"\nimport { useLoadingComponent } from \"../loading\"\nimport { Portal } from \"../portal\"\nimport { dropzoneStyle } from \"./dropzone.style\"\nimport { useDropzone } from \"./use-dropzone\"\n\ninterface ComponentContext extends Pick<\n UseDropzoneReturn,\n \"dragAccept\" | \"dragIdle\" | \"dragReject\" | \"loading\"\n> {}\n\nexport interface DropzoneRootProps\n extends\n Merge<HTMLStyledProps, UseDropzoneProps>,\n UseInputBorderProps,\n ThemeProps<DropzoneStyle>,\n Pick<DropzoneLoadingProps, \"loadingScheme\"> {\n /**\n * Props for dropzone input element.\n */\n inputProps?: HTMLStyledProps<\"input\">\n /**\n * Props for dropzone loading icon element.\n */\n loadingProps?: DropzoneLoadingProps\n /**\n * Props for dropzone overlay element.\n */\n overlayProps?: DropzoneOverlayProps\n}\n\nconst {\n ComponentContext,\n PropsContext: DropzonePropsContext,\n useComponentContext,\n usePropsContext: useDropzonePropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<DropzoneRootProps, DropzoneStyle>(\n \"dropzone\",\n dropzoneStyle,\n)\n\nexport { DropzonePropsContext, useDropzonePropsContext }\n\n/**\n * `Dropzone` is a component used for uploading files via drag and drop.\n *\n * @see https://yamada-ui.com/docs/components/dropzone\n */\nexport const DropzoneRoot = withProvider(\n ({\n children,\n errorBorderColor,\n focusBorderColor,\n loadingScheme,\n inputProps,\n loadingProps,\n overlayProps,\n ...rest\n }) => {\n const varProps = useInputBorder({ errorBorderColor, focusBorderColor })\n const {\n dragAccept,\n dragIdle,\n dragReject,\n loading,\n getInputProps,\n getRootProps,\n } = useDropzone(rest)\n const context = useMemo(\n () => ({\n dragAccept,\n dragIdle,\n dragReject,\n loading,\n }),\n [dragAccept, dragIdle, dragReject, loading],\n )\n\n return (\n <ComponentContext value={context}>\n <Portal>\n <styled.input {...getInputProps(inputProps)} />\n </Portal>\n\n <styled.div data-group {...varProps} {...getRootProps()}>\n <DropzoneOverlay {...overlayProps}>\n <DropzoneLoading loadingScheme={loadingScheme} {...loadingProps} />\n </DropzoneOverlay>\n\n {children}\n </styled.div>\n </ComponentContext>\n )\n },\n \"root\",\n)()\n\nexport interface DropzoneIconProps extends HTMLStyledProps<\"svg\"> {}\n\nexport const DropzoneIcon = withContext<\"svg\", DropzoneIconProps>(\n \"svg\",\n \"icon\",\n)()\n\nexport interface DropzoneTitleProps extends HTMLStyledProps<\"p\"> {}\n\nexport const DropzoneTitle = withContext<\"p\", DropzoneTitleProps>(\n \"p\",\n \"title\",\n)()\n\nexport interface DropzoneDescriptionProps extends HTMLStyledProps<\"p\"> {}\n\nexport const DropzoneDescription = withContext<\"p\", DropzoneDescriptionProps>(\n \"p\",\n \"description\",\n)()\n\ninterface DropzoneOverlayProps extends FadeProps {\n loadingProps?: DropzoneLoadingProps\n}\n\nconst DropzoneOverlay = withContext<\"div\", DropzoneOverlayProps>(\n Fade,\n \"overlay\",\n)(undefined, (props) => {\n const { loading } = useComponentContext()\n\n return { open: loading, unmountOnExit: true, ...props }\n})\n\ninterface DropzoneLoadingProps extends Loading.Props {\n /**\n * The loading scheme.\n *\n * @default 'oval'\n */\n loadingScheme?: Loading.Scheme\n}\n\nconst DropzoneLoading = withContext<\"svg\", DropzoneLoadingProps>(\n ({ loadingScheme = \"oval\", ...rest }) => {\n const Component = useLoadingComponent(loadingScheme)\n\n return <Component {...rest} />\n },\n \"loading\",\n)()\n\nexport interface DropzoneAcceptProps extends PropsWithChildren {}\n\nexport const DropzoneAccept: FC<DropzoneAcceptProps> = ({ children }) => {\n const { dragAccept } = useComponentContext()\n\n return dragAccept ? children : null\n}\n\nexport interface DropzoneRejectProps extends PropsWithChildren {}\n\nexport const DropzoneReject: FC<DropzoneRejectProps> = ({ children }) => {\n const { dragReject } = useComponentContext()\n\n return dragReject ? children : null\n}\n\nexport interface DropzoneIdleProps extends PropsWithChildren {}\n\nexport const DropzoneIdle: FC<DropzoneIdleProps> = ({ children }) => {\n const { dragIdle } = useComponentContext()\n\n return dragIdle ? children : null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4CA,MAAM,EACJ,kBACA,cAAc,sBACd,qBACA,iBAAiB,yBACjB,aACA,iBACEA,6CACF,YACAC,qCACD;;;;;;AASD,MAAa,eAAe,cACzB,EACC,UACA,kBACA,kBACA,eACA,YACA,cACA,cACA,GAAG,WACC;CACJ,MAAM,WAAWC,wCAAe;EAAE;EAAkB;EAAkB,CAAC;CACvE,MAAM,EACJ,YACA,UACA,YACA,SACA,eACA,iBACEC,iCAAY,KAAK;AAWrB,QACE,4CAAC;EAAiB,iCAVX;GACL;GACA;GACA;GACA;GACD,GACD;GAAC;GAAY;GAAU;GAAY;GAAQ,CAC5C;aAIG,2CAACC,mCACC,2CAACC,uBAAO,SAAM,GAAI,cAAc,WAAW,GAAI,GACxC,EAET,4CAACA,uBAAO;GAAI;GAAW,GAAI;GAAU,GAAI,cAAc;cACrD,2CAAC;IAAgB,GAAI;cACnB,2CAAC;KAA+B;KAAe,GAAI;MAAgB;KACnD,EAEjB;IACU;GACI;GAGvB,OACD,EAAE;AAIH,MAAa,eAAe,YAC1B,OACA,OACD,EAAE;AAIH,MAAa,gBAAgB,YAC3B,KACA,QACD,EAAE;AAIH,MAAa,sBAAsB,YACjC,KACA,cACD,EAAE;AAMH,MAAM,kBAAkB,YACtBC,mBACA,UACD,CAAC,SAAY,UAAU;CACtB,MAAM,EAAE,YAAY,qBAAqB;AAEzC,QAAO;EAAE,MAAM;EAAS,eAAe;EAAM,GAAG;EAAO;EACvD;AAWF,MAAM,kBAAkB,aACrB,EAAE,gBAAgB,QAAQ,GAAG,WAAW;AAGvC,QAAO,2CAFWC,kDAAoB,cAAc,IAElC,GAAI,OAAQ;GAEhC,UACD,EAAE;AAIH,MAAaC,kBAA2C,EAAE,eAAe;CACvE,MAAM,EAAE,eAAe,qBAAqB;AAE5C,QAAO,aAAa,WAAW;;AAKjC,MAAaC,kBAA2C,EAAE,eAAe;CACvE,MAAM,EAAE,eAAe,qBAAqB;AAE5C,QAAO,aAAa,WAAW;;AAKjC,MAAaC,gBAAuC,EAAE,eAAe;CACnE,MAAM,EAAE,aAAa,qBAAqB;AAE1C,QAAO,WAAW,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flip.cjs","names":["flipVariants: Variants","createSlotComponent","flipStyle","useControllableState","from","to","motion"],"sources":["../../../../src/components/flip/flip.tsx"],"sourcesContent":["\"use client\"\n\nimport type { Variants } from \"motion/react\"\nimport type { ReactNode } from \"react\"\nimport type { KeyframeIdent, Orientation, ThemeProps } from \"../../core\"\nimport type { HTMLMotionProps } from \"../motion\"\nimport type { FlipStyle } from \"./flip.style\"\nimport { useMemo, useRef, useState } from \"react\"\nimport { createSlotComponent } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { dataAttr, handlerAll, useSafeLayoutEffect } from \"../../utils\"\nimport { motion } from \"../motion\"\nimport { flipStyle } from \"./flip.style\"\n\nconst flipVariants: Variants = {\n enter: ({ ident, orientation, visible }) => ({\n [orientation === \"horizontal\" ? \"rotateY\" : \"rotateX\"]:\n ident === \"from\" ? (visible ? 180 : 0) : visible ? 0 : 180,\n }),\n exit: ({ ident, orientation }) => ({\n [orientation === \"horizontal\" ? \"rotateY\" : \"rotateX\"]:\n ident === \"from\" ? 0 : 180,\n }),\n}\n\ninterface Rect {\n height?: number\n width?: number\n}\n\nexport interface FlipProps\n extends Omit<HTMLMotionProps<\"button\">, \"onChange\">, ThemeProps<FlipStyle> {\n /**\n * Passing React elements to \"from\" is required.\n */\n from: ReactNode\n /**\n * Passing React elements to \"to\" is required.\n */\n to: ReactNode\n /**\n * You can set the initial state.\n *\n * @default 'from'\n */\n defaultValue?: KeyframeIdent\n /**\n *
|
|
1
|
+
{"version":3,"file":"flip.cjs","names":["flipVariants: Variants","createSlotComponent","flipStyle","useControllableState","from","to","motion"],"sources":["../../../../src/components/flip/flip.tsx"],"sourcesContent":["\"use client\"\n\nimport type { Variants } from \"motion/react\"\nimport type { ReactNode } from \"react\"\nimport type { KeyframeIdent, Orientation, ThemeProps } from \"../../core\"\nimport type { HTMLMotionProps } from \"../motion\"\nimport type { FlipStyle } from \"./flip.style\"\nimport { useMemo, useRef, useState } from \"react\"\nimport { createSlotComponent } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { dataAttr, handlerAll, useSafeLayoutEffect } from \"../../utils\"\nimport { motion } from \"../motion\"\nimport { flipStyle } from \"./flip.style\"\n\nconst flipVariants: Variants = {\n enter: ({ ident, orientation, visible }) => ({\n [orientation === \"horizontal\" ? \"rotateY\" : \"rotateX\"]:\n ident === \"from\" ? (visible ? 180 : 0) : visible ? 0 : 180,\n }),\n exit: ({ ident, orientation }) => ({\n [orientation === \"horizontal\" ? \"rotateY\" : \"rotateX\"]:\n ident === \"from\" ? 0 : 180,\n }),\n}\n\ninterface Rect {\n height?: number\n width?: number\n}\n\nexport interface FlipProps\n extends Omit<HTMLMotionProps<\"button\">, \"onChange\">, ThemeProps<FlipStyle> {\n /**\n * Passing React elements to \"from\" is required.\n */\n from: ReactNode\n /**\n * Passing React elements to \"to\" is required.\n */\n to: ReactNode\n /**\n * You can set the initial state.\n *\n * @default 'from'\n */\n defaultValue?: KeyframeIdent\n /**\n * The animation delay.\n *\n * @default 0\n */\n delay?: number\n /**\n * If `true`, the component is disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The animation duration.\n *\n * @default 0.4\n */\n duration?: number\n /**\n * The orientation of the flip effect. Determines whether the flip occurs horizontally or vertically.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * If `true`, the component is readonly.\n *\n * @default false\n */\n readOnly?: boolean\n /**\n * Use this when you want to control the animation from outside the component.\n */\n value?: KeyframeIdent\n /**\n * This is a callback function that is called when the animation state changes.\n */\n onChange?: (value: KeyframeIdent) => void\n}\n\nconst {\n PropsContext: FlipPropsContext,\n usePropsContext: useFlipPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<FlipProps, FlipStyle>(\"flip\", flipStyle)\n\nexport { FlipPropsContext, useFlipPropsContext }\n\n/**\n * `Flip` is an animation component that alternates between flipping two elements.\n *\n * @see https://yamada-ui.com/docs/components/flip\n */\nexport const Flip = withProvider(\n ({\n defaultValue = \"from\",\n delay = 0,\n disabled,\n duration = 0.4,\n from,\n orientation = \"horizontal\",\n readOnly,\n to,\n transition = {},\n value: valueProp,\n onChange,\n onClick: onClickProp,\n ...rest\n }) => {\n const [{ height, width }, setRect] = useState<Rect>({})\n const fromRef = useRef<HTMLDivElement | null>(null)\n const toRef = useRef<HTMLDivElement | null>(null)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange,\n })\n const visible = value === \"to\"\n\n const style = useMemo(\n () => ({\n height: height ? `${height}px` : \"auto\",\n width: width ? `${width}px` : \"auto\",\n }),\n [width, height],\n )\n\n const onClick = () => {\n if (readOnly) return\n\n setValue((prev) => (prev === \"from\" ? \"to\" : \"from\"))\n }\n\n useSafeLayoutEffect(() => {\n const from = fromRef.current\n const to = toRef.current\n\n if (!from || !to) return\n\n if (\n from.offsetWidth !== to.offsetWidth ||\n from.offsetHeight !== to.offsetHeight\n ) {\n console.warn(\n `Flip: \"from\" element (width: ${from.offsetWidth}px, height: ${from.offsetHeight}px) does not match \"to\" element (width: ${to.offsetWidth}px, height: ${to.offsetHeight}px). Please ensure both elements have the same dimensions.`,\n )\n }\n\n setRect({ height: from.offsetHeight, width: from.offsetWidth })\n }, [fromRef, toRef])\n\n return (\n <motion.button\n type=\"button\"\n style={style}\n data-disabled={dataAttr(disabled)}\n data-orientation={orientation}\n data-readonly={dataAttr(readOnly)}\n data-value={value}\n disabled={disabled}\n onClick={handlerAll(onClickProp, onClick)}\n {...rest}\n >\n <FlipFrom\n ref={fromRef}\n custom={{ orientation, visible }}\n transition={{ delay, duration, ...transition }}\n >\n {from}\n </FlipFrom>\n\n <FlipTo\n ref={toRef}\n custom={{ orientation, visible }}\n transition={{ delay, duration, ...transition }}\n >\n {to}\n </FlipTo>\n </motion.button>\n )\n },\n \"root\",\n)()\n\ninterface FlipFromProps extends HTMLMotionProps<\"span\"> {}\n\nconst FlipFrom = withContext<\"span\", FlipFromProps>(\n ({ custom, ...rest }) => {\n return (\n <motion.span\n animate=\"enter\"\n custom={{ ident: \"from\", ...custom }}\n initial=\"exit\"\n variants={flipVariants}\n {...rest}\n />\n )\n },\n [\"item\", \"from\"],\n)()\n\ninterface FlipToProps extends HTMLMotionProps<\"span\"> {}\n\nconst FlipTo = withContext<\"span\", FlipToProps>(\n ({ custom, ...rest }) => {\n return (\n <motion.span\n animate=\"enter\"\n custom={{ ident: \"to\", ...custom }}\n initial=\"exit\"\n variants={flipVariants}\n {...rest}\n />\n )\n },\n [\"item\", \"to\"],\n)()\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAMA,eAAyB;CAC7B,QAAQ,EAAE,OAAO,aAAa,eAAe,GAC1C,gBAAgB,eAAe,YAAY,YAC1C,UAAU,SAAU,UAAU,MAAM,IAAK,UAAU,IAAI,KAC1D;CACD,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