@northlight/ui 2.41.0 → 2.41.1
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/lib/components/accordion/accordion-button.tsx +23 -0
- package/lib/components/accordion/accordion-item.tsx +9 -0
- package/lib/components/accordion/accordion-panel.tsx +13 -0
- package/lib/components/accordion/accordion.tsx +49 -0
- package/lib/components/accordion/index.ts +13 -0
- package/lib/components/alert/alert.tsx +64 -0
- package/lib/components/alert/index.ts +7 -0
- package/lib/components/alert/types.ts +7 -0
- package/lib/components/alert-dialog/index.ts +9 -0
- package/lib/components/aspect-ratio/aspect-ratio.tsx +17 -0
- package/lib/components/aspect-ratio/index.ts +2 -0
- package/lib/components/async-error/async-error.tsx +33 -0
- package/lib/components/async-error/index.ts +2 -0
- package/lib/components/async-error/types.ts +5 -0
- package/lib/components/avatar/avatar-badge.tsx +26 -0
- package/lib/components/avatar/avatar-group.tsx +56 -0
- package/lib/components/avatar/avatar.tsx +77 -0
- package/lib/components/avatar/index.ts +3 -0
- package/lib/components/avatar/types.ts +34 -0
- package/lib/components/badge/badge.tsx +69 -0
- package/lib/components/badge/index.ts +2 -0
- package/lib/components/badge/types.ts +15 -0
- package/lib/components/blinker/blinker.tsx +26 -0
- package/lib/components/blinker/index.ts +2 -0
- package/lib/components/blinker/types.ts +5 -0
- package/lib/components/box/index.ts +2 -0
- package/lib/components/breadcrumb/index.ts +6 -0
- package/lib/components/button/button.tsx +111 -0
- package/lib/components/button/index.ts +5 -0
- package/lib/components/button/types.ts +20 -0
- package/lib/components/card/index.ts +6 -0
- package/lib/components/carousel/carousel-arrow.tsx +27 -0
- package/lib/components/carousel/carousel-item.tsx +23 -0
- package/lib/components/carousel/carousel.tsx +223 -0
- package/lib/components/carousel/constants.ts +2 -0
- package/lib/components/carousel/index.ts +1 -0
- package/lib/components/carousel/types.ts +32 -0
- package/lib/components/center/index.ts +4 -0
- package/lib/components/checkbox/checkbox-field.tsx +75 -0
- package/lib/components/checkbox/checkbox-group-field.tsx +49 -0
- package/lib/components/checkbox/checkbox.tsx +54 -0
- package/lib/components/checkbox/index.ts +7 -0
- package/lib/components/checkbox/types.ts +31 -0
- package/lib/components/circle/index.ts +3 -0
- package/lib/components/circular-progress/index.ts +4 -0
- package/lib/components/clickable/clickable.tsx +56 -0
- package/lib/components/clickable/index.ts +2 -0
- package/lib/components/clickable/types.ts +7 -0
- package/lib/components/clipboard-input/clipboard-input.tsx +65 -0
- package/lib/components/clipboard-input/index.ts +2 -0
- package/lib/components/clipboard-input/types.ts +6 -0
- package/lib/components/close-button/index.ts +3 -0
- package/lib/components/code/index.ts +3 -0
- package/lib/components/color-picker/color-button.tsx +51 -0
- package/lib/components/color-picker/color-picker-field.tsx +37 -0
- package/lib/components/color-picker/color-picker.tsx +205 -0
- package/lib/components/color-picker/colors-expand-button.tsx +47 -0
- package/lib/components/color-picker/constants.ts +5 -0
- package/lib/components/color-picker/index.ts +3 -0
- package/lib/components/color-picker/types.ts +44 -0
- package/lib/components/combo-picker/combo-picker-field.tsx +99 -0
- package/lib/components/combo-picker/combo-picker.tsx +165 -0
- package/lib/components/combo-picker/index.ts +3 -0
- package/lib/components/combo-picker/types.ts +35 -0
- package/lib/components/container/index.ts +5 -0
- package/lib/components/createable-select-dropdown/createable-select-dropdown.tsx +282 -0
- package/lib/components/createable-select-dropdown/custom-components.tsx +44 -0
- package/lib/components/createable-select-dropdown/index.ts +1 -0
- package/lib/components/createable-select-dropdown/types.ts +76 -0
- package/lib/components/date-picker/components/calendar/calendar.tsx +56 -0
- package/lib/components/date-picker/components/calendar/components/calendar-cell.tsx +41 -0
- package/lib/components/date-picker/components/calendar/components/calendar-grid.tsx +52 -0
- package/lib/components/date-picker/components/calendar/components/day-labels.tsx +18 -0
- package/lib/components/date-picker/components/calendar/components/get-week-number-start-of-month.ts +68 -0
- package/lib/components/date-picker/components/calendar/components/index.ts +3 -0
- package/lib/components/date-picker/components/calendar/components/month-button.tsx +21 -0
- package/lib/components/date-picker/components/calendar/components/range-cell.tsx +75 -0
- package/lib/components/date-picker/components/calendar/components/standalone-calendar-grid.tsx +108 -0
- package/lib/components/date-picker/components/calendar/components/types.ts +43 -0
- package/lib/components/date-picker/components/calendar/components/utils.ts +5 -0
- package/lib/components/date-picker/components/calendar/constants.ts +14 -0
- package/lib/components/date-picker/components/calendar/date-select/index.ts +4 -0
- package/lib/components/date-picker/components/calendar/date-select/month-select.tsx +36 -0
- package/lib/components/date-picker/components/calendar/date-select/types.ts +29 -0
- package/lib/components/date-picker/components/calendar/date-select/utils.ts +33 -0
- package/lib/components/date-picker/components/calendar/date-select/year-select-calendar.tsx +17 -0
- package/lib/components/date-picker/components/calendar/date-select/year-select-range-calendar.tsx +19 -0
- package/lib/components/date-picker/components/calendar/date-select/year-select.tsx +31 -0
- package/lib/components/date-picker/components/calendar/index.ts +1 -0
- package/lib/components/date-picker/components/calendar/quick-navigation/adjust-range.tsx +227 -0
- package/lib/components/date-picker/components/calendar/quick-navigation/button-row.tsx +31 -0
- package/lib/components/date-picker/components/calendar/quick-navigation/date-button.tsx +32 -0
- package/lib/components/date-picker/components/calendar/quick-navigation/get-quick-select-options.ts +319 -0
- package/lib/components/date-picker/components/calendar/quick-navigation/index.ts +1 -0
- package/lib/components/date-picker/components/calendar/quick-navigation/move-button.tsx +23 -0
- package/lib/components/date-picker/components/calendar/quick-navigation/quick-select.tsx +113 -0
- package/lib/components/date-picker/components/calendar/quick-navigation/types.ts +59 -0
- package/lib/components/date-picker/components/calendar/quick-navigation/utils.ts +8 -0
- package/lib/components/date-picker/components/calendar/range-calendar.tsx +153 -0
- package/lib/components/date-picker/components/calendar/types.ts +19 -0
- package/lib/components/date-picker/components/date-field/date-field.tsx +51 -0
- package/lib/components/date-picker/components/date-field/date-segment.tsx +34 -0
- package/lib/components/date-picker/components/date-field/index.ts +4 -0
- package/lib/components/date-picker/components/date-field/styled-field.tsx +27 -0
- package/lib/components/date-picker/components/date-field/trigger.tsx +27 -0
- package/lib/components/date-picker/components/date-field/types.ts +25 -0
- package/lib/components/date-picker/components/date-field/utils.ts +15 -0
- package/lib/components/date-picker/components/index.ts +2 -0
- package/lib/components/date-picker/date-picker/date-picker-locale-wrapper.tsx +16 -0
- package/lib/components/date-picker/date-picker/date-picker.tsx +145 -0
- package/lib/components/date-picker/date-picker/date-range-picker.tsx +325 -0
- package/lib/components/date-picker/date-picker/index.ts +3 -0
- package/lib/components/date-picker/date-picker-field/date-picker-field.tsx +97 -0
- package/lib/components/date-picker/date-picker-field/date-range-picker-field.tsx +81 -0
- package/lib/components/date-picker/date-picker-field/index.ts +2 -0
- package/lib/components/date-picker/date-picker-field/utils.ts +9 -0
- package/lib/components/date-picker/index.ts +3 -0
- package/lib/components/date-picker/types.ts +108 -0
- package/lib/components/divider/index.ts +3 -0
- package/lib/components/drag-and-drop/drag-and-drop.tsx +15 -0
- package/lib/components/drag-and-drop/drag-handle.tsx +23 -0
- package/lib/components/drag-and-drop/drag-item.tsx +42 -0
- package/lib/components/drag-and-drop/draggable.tsx +94 -0
- package/lib/components/drag-and-drop/drop-zone.tsx +32 -0
- package/lib/components/drag-and-drop/droppable.tsx +58 -0
- package/lib/components/drag-and-drop/index.ts +17 -0
- package/lib/components/drag-and-drop/multi-sort.tsx +198 -0
- package/lib/components/drag-and-drop/sortable-container.tsx +26 -0
- package/lib/components/drag-and-drop/sortable-item.tsx +96 -0
- package/lib/components/drag-and-drop/sortable-list.tsx +163 -0
- package/lib/components/drag-and-drop/sortable.tsx +16 -0
- package/lib/components/drag-and-drop/types.ts +105 -0
- package/lib/components/drawer/index.ts +9 -0
- package/lib/components/editable/index.ts +8 -0
- package/lib/components/editable-text/editable-controls.tsx +72 -0
- package/lib/components/editable-text/editable-text.tsx +83 -0
- package/lib/components/editable-text/index.ts +2 -0
- package/lib/components/editable-text/types.ts +17 -0
- package/lib/components/fast-grid/fast-grid.tsx +123 -0
- package/lib/components/fast-grid/index.ts +2 -0
- package/lib/components/fast-grid/types.ts +26 -0
- package/lib/components/fast-list/fast-list.tsx +53 -0
- package/lib/components/fast-list/index.ts +2 -0
- package/lib/components/fast-list/types.ts +17 -0
- package/lib/components/file-picker/confirm-delete-modal.tsx +45 -0
- package/lib/components/file-picker/constants.ts +7 -0
- package/lib/components/file-picker/file-editor-modal.tsx +105 -0
- package/lib/components/file-picker/file-icon-button.tsx +14 -0
- package/lib/components/file-picker/file-item.tsx +207 -0
- package/lib/components/file-picker/file-picker-field.tsx +73 -0
- package/lib/components/file-picker/file-picker.tsx +365 -0
- package/lib/components/file-picker/index.ts +7 -0
- package/lib/components/file-picker/multi-file-list.tsx +88 -0
- package/lib/components/file-picker/multi-file-picker-field.tsx +95 -0
- package/lib/components/file-picker/multi-file-picker.tsx +95 -0
- package/lib/components/file-picker/multi-file-uploader.tsx +189 -0
- package/lib/components/file-picker/types.ts +132 -0
- package/lib/components/file-picker/utils.ts +283 -0
- package/lib/components/flex/index.ts +4 -0
- package/lib/components/flip-button/flip-button-group-field.tsx +58 -0
- package/lib/components/flip-button/flip-button-group.tsx +70 -0
- package/lib/components/flip-button/flip-button.tsx +185 -0
- package/lib/components/flip-button/index.ts +4 -0
- package/lib/components/flip-button/types.ts +100 -0
- package/lib/components/flip-button/utils.ts +45 -0
- package/lib/components/form/field.tsx +147 -0
- package/lib/components/form/form.tsx +210 -0
- package/lib/components/form/index.ts +5 -0
- package/lib/components/form/trim-form-values.ts +20 -0
- package/lib/components/form/types.ts +99 -0
- package/lib/components/form/use-set-value-refreshed.ts +12 -0
- package/lib/components/form-control/form-label.tsx +29 -0
- package/lib/components/form-control/index.ts +7 -0
- package/lib/components/form-control/types.ts +5 -0
- package/lib/components/grid/index.ts +4 -0
- package/lib/components/heading/index.ts +3 -0
- package/lib/components/highlight/index.ts +1 -0
- package/lib/components/icon/icon.tsx +38 -0
- package/lib/components/icon/index.ts +2 -0
- package/lib/components/icon/types.ts +7 -0
- package/lib/components/icon-button/icon-button.tsx +45 -0
- package/lib/components/icon-button/index.ts +2 -0
- package/lib/components/icon-button/types.ts +6 -0
- package/lib/components/image/index.ts +5 -0
- package/lib/components/index.ts +94 -0
- package/lib/components/input/index.ts +19 -0
- package/lib/components/intent-button/index.ts +1 -0
- package/lib/components/intent-button/intent-button.tsx +118 -0
- package/lib/components/intent-button/timeout-progress-circle.tsx +48 -0
- package/lib/components/intent-button/types.ts +16 -0
- package/lib/components/kbd/index.ts +3 -0
- package/lib/components/keyframes/index.ts +3 -0
- package/lib/components/link/index.ts +3 -0
- package/lib/components/link-overlay/index.ts +4 -0
- package/lib/components/list/index.ts +7 -0
- package/lib/components/mark/index.ts +1 -0
- package/lib/components/mediatool-theme-provider/index.ts +2 -0
- package/lib/components/mediatool-theme-provider/mediatool-theme-provider.tsx +28 -0
- package/lib/components/mediatool-theme-provider/types.ts +8 -0
- package/lib/components/menu/index.ts +13 -0
- package/lib/components/menu/menu.tsx +103 -0
- package/lib/components/menu/types.ts +7 -0
- package/lib/components/modal/index.ts +12 -0
- package/lib/components/modal/modal-base.tsx +22 -0
- package/lib/components/modal/modal-body.tsx +6 -0
- package/lib/components/modal/modal.tsx +18 -0
- package/lib/components/modal/types.ts +9 -0
- package/lib/components/notification-icon-button/index.ts +2 -0
- package/lib/components/notification-icon-button/notification-icon-button.tsx +57 -0
- package/lib/components/notification-icon-button/types.ts +8 -0
- package/lib/components/number-input/advanced-parse-float.ts +30 -0
- package/lib/components/number-input/index.ts +9 -0
- package/lib/components/number-input/number-input-field.tsx +74 -0
- package/lib/components/number-input/number-input-stepper.tsx +47 -0
- package/lib/components/number-input/number-input.tsx +67 -0
- package/lib/components/number-input/types.ts +37 -0
- package/lib/components/organization-logo/index.ts +2 -0
- package/lib/components/organization-logo/organization-logo.tsx +46 -0
- package/lib/components/organization-logo/types.ts +8 -0
- package/lib/components/overflow-group/index.ts +3 -0
- package/lib/components/overflow-group/overflow-group.tsx +189 -0
- package/lib/components/overflow-group/types.ts +10 -0
- package/lib/components/overflow-group/use-overflow-group.ts +12 -0
- package/lib/components/pin-input/index.ts +5 -0
- package/lib/components/pin-input/pin-input.tsx +31 -0
- package/lib/components/pin-input/types.ts +10 -0
- package/lib/components/popover/index.ts +11 -0
- package/lib/components/popover/popover.tsx +6 -0
- package/lib/components/portal/index.ts +3 -0
- package/lib/components/portal/render-in-portal.tsx +17 -0
- package/lib/components/progress/constants.ts +2 -0
- package/lib/components/progress/index.ts +2 -0
- package/lib/components/progress/loading-bar.tsx +93 -0
- package/lib/components/progress/progress-bar.tsx +36 -0
- package/lib/components/progress/types.ts +8 -0
- package/lib/components/progress/utils.ts +17 -0
- package/lib/components/radio/index.ts +8 -0
- package/lib/components/radio/radio-group-field.tsx +49 -0
- package/lib/components/radio/radio-group.tsx +30 -0
- package/lib/components/radio/radio.tsx +23 -0
- package/lib/components/radio/types.ts +33 -0
- package/lib/components/range-slider/index.ts +7 -0
- package/lib/components/resize-handle/index.ts +1 -0
- package/lib/components/resize-handle/resize-handle.tsx +26 -0
- package/lib/components/search-bar/get-components.tsx +76 -0
- package/lib/components/search-bar/index.ts +3 -0
- package/lib/components/search-bar/search-bar-field.tsx +70 -0
- package/lib/components/search-bar/search-bar.tsx +127 -0
- package/lib/components/search-bar/styles.ts +49 -0
- package/lib/components/search-bar/types.ts +53 -0
- package/lib/components/select/get-matching-value.ts +23 -0
- package/lib/components/select/index.ts +13 -0
- package/lib/components/select/select-field.tsx +89 -0
- package/lib/components/select/select.tsx +209 -0
- package/lib/components/select/sortable-select-values.tsx +49 -0
- package/lib/components/select/sortable-select.tsx +428 -0
- package/lib/components/select/types.ts +67 -0
- package/lib/components/show/index.ts +4 -0
- package/lib/components/simple-grid/index.ts +3 -0
- package/lib/components/skeleton/index.ts +5 -0
- package/lib/components/slider/index.ts +7 -0
- package/lib/components/spinner/index.ts +2 -0
- package/lib/components/spinner/spinner.tsx +15 -0
- package/lib/components/spinner/types.ts +3 -0
- package/lib/components/split-pane/index.ts +4 -0
- package/lib/components/split-pane/pane-divider.tsx +25 -0
- package/lib/components/split-pane/pane-item.tsx +14 -0
- package/lib/components/split-pane/split-pane.tsx +75 -0
- package/lib/components/split-pane/types.ts +10 -0
- package/lib/components/stack/index.ts +7 -0
- package/lib/components/stat/index.ts +8 -0
- package/lib/components/status-pin/index.ts +2 -0
- package/lib/components/status-pin/pin-size-map.ts +7 -0
- package/lib/components/status-pin/pin-variant-map.ts +12 -0
- package/lib/components/status-pin/status-pin.tsx +55 -0
- package/lib/components/status-pin/types.ts +7 -0
- package/lib/components/step-stack/index.ts +1 -0
- package/lib/components/step-stack/step-stack.tsx +113 -0
- package/lib/components/step-stack/types.ts +17 -0
- package/lib/components/steps/index.ts +10 -0
- package/lib/components/steps/step-list.tsx +30 -0
- package/lib/components/steps/step-panel.tsx +15 -0
- package/lib/components/steps/step.tsx +52 -0
- package/lib/components/steps/steps.tsx +34 -0
- package/lib/components/steps/types.ts +12 -0
- package/lib/components/switch/index.ts +3 -0
- package/lib/components/switch/switch-field.tsx +74 -0
- package/lib/components/switch/switch.tsx +41 -0
- package/lib/components/switch/types.ts +18 -0
- package/lib/components/table/index.ts +22 -0
- package/lib/components/table/table.tsx +31 -0
- package/lib/components/table/types.ts +5 -0
- package/lib/components/tabs/index.ts +12 -0
- package/lib/components/tabs/tab-panel.tsx +14 -0
- package/lib/components/tabs/tab.tsx +31 -0
- package/lib/components/tabs/tabs.tsx +76 -0
- package/lib/components/tabs/types.ts +12 -0
- package/lib/components/tag/index.ts +9 -0
- package/lib/components/tag/overflow-indicator.tsx +11 -0
- package/lib/components/tag/tag-group.tsx +57 -0
- package/lib/components/tag/tag.tsx +97 -0
- package/lib/components/tag/types.ts +15 -0
- package/lib/components/tags-input/index.ts +2 -0
- package/lib/components/tags-input/tags-input-styles.ts +35 -0
- package/lib/components/tags-input/tags-input.tsx +147 -0
- package/lib/components/tags-input/types.ts +20 -0
- package/lib/components/text/index.ts +3 -0
- package/lib/components/text-field/formatted-number-input-field.tsx +54 -0
- package/lib/components/text-field/formatted-number-input.tsx +167 -0
- package/lib/components/text-field/index.ts +5 -0
- package/lib/components/text-field/masked-text-input.tsx +37 -0
- package/lib/components/text-field/round-to-precision.ts +4 -0
- package/lib/components/text-field/text-field.tsx +61 -0
- package/lib/components/text-field/types.ts +60 -0
- package/lib/components/textarea/index.ts +3 -0
- package/lib/components/textarea/textarea-field.tsx +34 -0
- package/lib/components/textarea/textarea.tsx +27 -0
- package/lib/components/textarea/types.ts +22 -0
- package/lib/components/toast/index.ts +3 -0
- package/lib/components/toast/toast.tsx +75 -0
- package/lib/components/toast/types.ts +16 -0
- package/lib/components/toast/use-toast.tsx +57 -0
- package/lib/components/toolbox/index.ts +5 -0
- package/lib/components/toolbox/toolbox-content.tsx +23 -0
- package/lib/components/toolbox/toolbox-footer.tsx +18 -0
- package/lib/components/toolbox/toolbox-header.tsx +31 -0
- package/lib/components/toolbox/toolbox.tsx +132 -0
- package/lib/components/toolbox/types.ts +34 -0
- package/lib/components/tooltip/index.ts +1 -0
- package/lib/components/tooltip/tooltip.tsx +207 -0
- package/lib/components/tooltip/types.ts +9 -0
- package/lib/components/transitions/collapse.tsx +78 -0
- package/lib/components/transitions/constants.ts +2 -0
- package/lib/components/transitions/fade.tsx +72 -0
- package/lib/components/transitions/index.ts +6 -0
- package/lib/components/transitions/scale-fade.tsx +70 -0
- package/lib/components/transitions/slide-fade.tsx +43 -0
- package/lib/components/transitions/slide.tsx +37 -0
- package/lib/components/transitions/types.ts +37 -0
- package/lib/components/transitions/utils.ts +103 -0
- package/lib/components/types/color/index.ts +24 -0
- package/lib/components/types/index.ts +2 -0
- package/lib/components/types/toastIconMap/index.ts +20 -0
- package/lib/components/types/tooltipIconMap/index.ts +21 -0
- package/lib/components/typography/body/index.ts +2 -0
- package/lib/components/typography/body/p.tsx +31 -0
- package/lib/components/typography/body/types.ts +5 -0
- package/lib/components/typography/headings/h1.tsx +29 -0
- package/lib/components/typography/headings/h2.tsx +30 -0
- package/lib/components/typography/headings/h3.tsx +29 -0
- package/lib/components/typography/headings/h4.tsx +29 -0
- package/lib/components/typography/headings/h5.tsx +29 -0
- package/lib/components/typography/headings/h6.tsx +29 -0
- package/lib/components/typography/headings/index.ts +7 -0
- package/lib/components/typography/headings/types.ts +3 -0
- package/lib/components/typography/index.ts +6 -0
- package/lib/components/typography/labels/index.ts +2 -0
- package/lib/components/typography/labels/label.tsx +39 -0
- package/lib/components/typography/labels/types.ts +6 -0
- package/lib/components/typography/numvals/index.ts +1 -0
- package/lib/components/typography/numvals/numval.tsx +33 -0
- package/lib/components/typography/stylized/blockquote.tsx +32 -0
- package/lib/components/typography/stylized/capitalized.tsx +37 -0
- package/lib/components/typography/stylized/index.ts +5 -0
- package/lib/components/typography/stylized/lead.tsx +37 -0
- package/lib/components/typography/stylized/small.tsx +37 -0
- package/lib/components/typography/stylized/tiny.tsx +37 -0
- package/lib/components/typography/types.ts +11 -0
- package/lib/components/visually-hidden/index.ts +4 -0
- package/lib/components/wrap/index.ts +4 -0
- package/lib/general.d.ts +27 -0
- package/lib/hooks/index.ts +26 -0
- package/lib/hooks/use-arrow-focus/index.ts +76 -0
- package/lib/hooks/use-boolean/index.ts +3 -0
- package/lib/hooks/use-breakpoint-value/index.ts +4 -0
- package/lib/hooks/use-clipboard/index.ts +3 -0
- package/lib/hooks/use-controllable/index.ts +4 -0
- package/lib/hooks/use-controller/index.ts +3 -0
- package/lib/hooks/use-debounce/index.ts +16 -0
- package/lib/hooks/use-did-update-effect/index.ts +12 -0
- package/lib/hooks/use-disclosure/index.ts +3 -0
- package/lib/hooks/use-field-array/index.ts +3 -0
- package/lib/hooks/use-form/index.ts +3 -0
- package/lib/hooks/use-form-context/index.ts +3 -0
- package/lib/hooks/use-form-state/index.ts +3 -0
- package/lib/hooks/use-interval/index.ts +3 -0
- package/lib/hooks/use-loading-message/index.ts +15 -0
- package/lib/hooks/use-media-query/index.ts +3 -0
- package/lib/hooks/use-merge-refs/index.ts +3 -0
- package/lib/hooks/use-outside-click/index.ts +3 -0
- package/lib/hooks/use-outside-rect-click/index.ts +98 -0
- package/lib/hooks/use-prefers-reduced-motion/index.ts +3 -0
- package/lib/hooks/use-resize-width/index.ts +44 -0
- package/lib/hooks/use-screen-size/index.ts +12 -0
- package/lib/hooks/use-scroll-to-bottom/index.ts +18 -0
- package/lib/hooks/use-scroll-to-bottom/utils/smooth-scroll-to-bottom.ts +17 -0
- package/lib/hooks/use-select-callbacks/index.ts +2 -0
- package/lib/hooks/use-select-callbacks/types.ts +25 -0
- package/lib/hooks/use-select-callbacks/use-select-callbacks.ts +43 -0
- package/lib/hooks/use-theme/index.ts +3 -0
- package/lib/hooks/use-token/index.ts +3 -0
- package/lib/hooks/use-watch/index.ts +3 -0
- package/lib/index.ts +6 -0
- package/lib/internal-components/index.ts +1 -0
- package/lib/internal-components/input-group-wrapper/index.ts +2 -0
- package/lib/internal-components/input-group-wrapper/input-group-wrapper.tsx +24 -0
- package/lib/internal-components/input-group-wrapper/types.ts +4 -0
- package/lib/theme/components/alert/index.ts +94 -0
- package/lib/theme/components/avatar/get-avatar-bg-color.ts +11 -0
- package/lib/theme/components/avatar/index.ts +158 -0
- package/lib/theme/components/badge/index.ts +80 -0
- package/lib/theme/components/blinker/index.ts +67 -0
- package/lib/theme/components/breadcrumb/index.ts +22 -0
- package/lib/theme/components/button/index.ts +205 -0
- package/lib/theme/components/calendar/index.ts +47 -0
- package/lib/theme/components/carousel/index.ts +30 -0
- package/lib/theme/components/checkbox/index.ts +90 -0
- package/lib/theme/components/clipboard-input/index.ts +38 -0
- package/lib/theme/components/close-button/index.ts +25 -0
- package/lib/theme/components/color-picker/index.ts +58 -0
- package/lib/theme/components/date-picker/index.ts +70 -0
- package/lib/theme/components/drag-and-drop/index.ts +23 -0
- package/lib/theme/components/editable-text/index.ts +82 -0
- package/lib/theme/components/file-picker/index.ts +111 -0
- package/lib/theme/components/flip-button/index.ts +167 -0
- package/lib/theme/components/icon/index.ts +22 -0
- package/lib/theme/components/index.ts +40 -0
- package/lib/theme/components/input/index.ts +223 -0
- package/lib/theme/components/link/index.ts +16 -0
- package/lib/theme/components/menu/index.ts +50 -0
- package/lib/theme/components/modal/index.ts +49 -0
- package/lib/theme/components/notification-icon-button/index.ts +52 -0
- package/lib/theme/components/number-input/index.ts +118 -0
- package/lib/theme/components/pin-input/index.ts +52 -0
- package/lib/theme/components/popover/index.ts +10 -0
- package/lib/theme/components/progress-bar/index.ts +12 -0
- package/lib/theme/components/radio/index.ts +73 -0
- package/lib/theme/components/select/custom-select.ts +44 -0
- package/lib/theme/components/select/index.ts +65 -0
- package/lib/theme/components/spinner/index.ts +12 -0
- package/lib/theme/components/split-pane/index.ts +33 -0
- package/lib/theme/components/steps/index.ts +2 -0
- package/lib/theme/components/steps/step/index.ts +63 -0
- package/lib/theme/components/steps/step-list/index.ts +13 -0
- package/lib/theme/components/switch/index.ts +23 -0
- package/lib/theme/components/table/index.ts +81 -0
- package/lib/theme/components/tabs/index.ts +115 -0
- package/lib/theme/components/tag/index.ts +81 -0
- package/lib/theme/components/textarea/index.ts +62 -0
- package/lib/theme/components/toolbox/index.ts +64 -0
- package/lib/theme/components/tooltip/index.ts +68 -0
- package/lib/theme/components/typography/body/index.ts +1 -0
- package/lib/theme/components/typography/body/p.ts +32 -0
- package/lib/theme/components/typography/headings/h1.ts +20 -0
- package/lib/theme/components/typography/headings/h2.ts +20 -0
- package/lib/theme/components/typography/headings/h3.ts +20 -0
- package/lib/theme/components/typography/headings/h4.ts +20 -0
- package/lib/theme/components/typography/headings/h5.ts +20 -0
- package/lib/theme/components/typography/headings/h6.ts +20 -0
- package/lib/theme/components/typography/headings/index.ts +6 -0
- package/lib/theme/components/typography/index.ts +5 -0
- package/lib/theme/components/typography/labels/index.ts +1 -0
- package/lib/theme/components/typography/labels/label.ts +71 -0
- package/lib/theme/components/typography/numvals/index.ts +1 -0
- package/lib/theme/components/typography/numvals/numval.ts +95 -0
- package/lib/theme/components/typography/stylized/blockquote.ts +17 -0
- package/lib/theme/components/typography/stylized/capitalized.ts +17 -0
- package/lib/theme/components/typography/stylized/index.ts +5 -0
- package/lib/theme/components/typography/stylized/lead.ts +17 -0
- package/lib/theme/components/typography/stylized/small.ts +17 -0
- package/lib/theme/components/typography/stylized/tiny.ts +17 -0
- package/lib/theme/global/scrollbar.ts +23 -0
- package/lib/theme/index.ts +67 -0
- package/lib/theme/process-color-scheme-based-on-theme.ts +24 -0
- package/lib/theme/skins/camphouse-light/index.ts +34 -0
- package/lib/theme/skins/index.ts +3 -0
- package/lib/theme/skins/tott/index.ts +30 -0
- package/lib/theme/skins/webapp/index.ts +34 -0
- package/lib/types/color/color.ts +24 -0
- package/lib/types/color/index.ts +1 -0
- package/lib/types/index.ts +2 -0
- package/lib/types/input-field/index.ts +1 -0
- package/lib/types/input-field/input-field.ts +4 -0
- package/lib/utils/add-alpha/index.ts +10 -0
- package/lib/utils/clamp/index.ts +2 -0
- package/lib/utils/debounce/create-debounce-function-instance.ts +18 -0
- package/lib/utils/debounce/index.ts +1 -0
- package/lib/utils/get-children-with-props/index.ts +17 -0
- package/lib/utils/get-children-with-props/pass-props-to-child.ts +10 -0
- package/lib/utils/get-consistent-random-color-from-string/index.ts +26 -0
- package/lib/utils/get-contrast-color/index.ts +34 -0
- package/lib/utils/get-field-error/index.ts +12 -0
- package/lib/utils/get-initials/index.ts +6 -0
- package/lib/utils/get-shades/index.ts +31 -0
- package/lib/utils/highlight/index.ts +9 -0
- package/lib/utils/index.ts +13 -0
- package/lib/utils/luminosity/index.ts +21 -0
- package/lib/utils/ring/index.ts +10 -0
- package/lib/utils/use-current-theme/index.ts +10 -0
- package/package.json +3 -2
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import React, { useRef } from 'react'
|
|
2
|
+
import { useMultiStyleConfig } from '@chakra-ui/react'
|
|
3
|
+
import { useDatePicker } from '@react-aria/datepicker'
|
|
4
|
+
import { useDatePickerState } from '@react-stately/datepicker'
|
|
5
|
+
import { FocusScope } from '@react-aria/focus'
|
|
6
|
+
import { XCloseSolid } from '@northlight/icons'
|
|
7
|
+
import { parseDate } from '@internationalized/date'
|
|
8
|
+
import { DateField, StyledField, Trigger } from '../components/date-field'
|
|
9
|
+
import { Calendar } from '../components/calendar'
|
|
10
|
+
import { DatePickerProps } from '../types'
|
|
11
|
+
import { IconButton } from '../../icon-button'
|
|
12
|
+
import { HStack } from '../../stack'
|
|
13
|
+
import { InputGroup, InputRightElement } from '../../input'
|
|
14
|
+
import { Popover, PopoverAnchor, PopoverContent } from '../../popover'
|
|
15
|
+
import { Icon } from '../../icon'
|
|
16
|
+
import { Box } from '../../box'
|
|
17
|
+
import { DatePickerLocaleWrapper } from './date-picker-locale-wrapper'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Popover to select single date
|
|
21
|
+
* @see DatePickerField
|
|
22
|
+
* @see {@link https://northlight.dev/reference/date-picker}
|
|
23
|
+
*
|
|
24
|
+
* @example (Example)
|
|
25
|
+
* ## When is your birthday
|
|
26
|
+
* (?
|
|
27
|
+
* () => {
|
|
28
|
+
* const [ date, setDate ] = useState('2023-10-10')
|
|
29
|
+
*
|
|
30
|
+
* const parseDate = () => {
|
|
31
|
+
* return undefined
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* return (
|
|
35
|
+
* <DatePicker
|
|
36
|
+
* firstDayOfWeek="monday"
|
|
37
|
+
* resetDate={() => setDate(null)} onChange={setDate} value={parseDate(date)}/>
|
|
38
|
+
* )
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* ?)
|
|
42
|
+
* <br />
|
|
43
|
+
* ### Some notes on date format
|
|
44
|
+
* As you can see in the above example, the parseDate function returns undefined.
|
|
45
|
+
* The DatePicker natively handles
|
|
46
|
+
* dates as a DateValue object. To get out a string value on format yyyy-mm-dd,
|
|
47
|
+
* you can use the javascript <b>.toString</b> method,
|
|
48
|
+
* and for getting it back from string to DateValue,
|
|
49
|
+
* you can use the parseDate util.
|
|
50
|
+
* <br />
|
|
51
|
+
* To read more about date formatting, consult the
|
|
52
|
+
* <a target="_blank" style="fontWeight: bold;" href="https://react-spectrum.adobe.com/internationalized/date/CalendarDate.html">react aria internationalized documentation</a>
|
|
53
|
+
*
|
|
54
|
+
* @example (Example)
|
|
55
|
+
* ## Another example
|
|
56
|
+
* (?
|
|
57
|
+
* <DatePicker
|
|
58
|
+
* variant="filled"
|
|
59
|
+
* dateFormat="mm|dd-yyyy"
|
|
60
|
+
* />
|
|
61
|
+
* ?)
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
export const DatePicker = (props: DatePickerProps) => {
|
|
65
|
+
const {
|
|
66
|
+
isDisabled,
|
|
67
|
+
isClearable = true,
|
|
68
|
+
resetDate,
|
|
69
|
+
isInvalid = false,
|
|
70
|
+
dateFormat,
|
|
71
|
+
minValue,
|
|
72
|
+
variant = 'outline',
|
|
73
|
+
firstDayOfWeek = 'monday',
|
|
74
|
+
} = props
|
|
75
|
+
const ref = useRef() as React.MutableRefObject<HTMLInputElement>
|
|
76
|
+
const { group } = useMultiStyleConfig('DatePicker')
|
|
77
|
+
|
|
78
|
+
const state = useDatePickerState({
|
|
79
|
+
...props,
|
|
80
|
+
shouldCloseOnSelect: false,
|
|
81
|
+
hideTimeZone: true,
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const { buttonProps, fieldProps, calendarProps, groupProps, dialogProps } =
|
|
85
|
+
useDatePicker(
|
|
86
|
+
{ ...props, minValue: minValue || parseDate('1994-03-08') },
|
|
87
|
+
state,
|
|
88
|
+
ref
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
const togglePopup = () => state.setOpen(!state.isOpen)
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<Popover
|
|
95
|
+
isOpen={ state.isOpen }
|
|
96
|
+
onClose={ () => state.setOpen(false) }
|
|
97
|
+
placement="bottom-end"
|
|
98
|
+
>
|
|
99
|
+
<PopoverAnchor>
|
|
100
|
+
<HStack minW={ 56 }>
|
|
101
|
+
<InputGroup { ...groupProps } ref={ ref } __css={ group }>
|
|
102
|
+
<StyledField
|
|
103
|
+
isDisabled={ isDisabled }
|
|
104
|
+
isInvalid={ isInvalid }
|
|
105
|
+
variant={ variant }
|
|
106
|
+
>
|
|
107
|
+
<Box paddingInlineStart="1a" paddingInlineEnd={ 10 }>
|
|
108
|
+
<DateField { ...fieldProps } dateFormat={ dateFormat } />
|
|
109
|
+
</Box>
|
|
110
|
+
</StyledField>
|
|
111
|
+
<InputRightElement
|
|
112
|
+
sx={ { height: '100%', paddingRight: '1' } }
|
|
113
|
+
zIndex={ 0 }
|
|
114
|
+
>
|
|
115
|
+
<Trigger
|
|
116
|
+
{ ...buttonProps }
|
|
117
|
+
isDisabled={ isDisabled }
|
|
118
|
+
handleClick={ togglePopup }
|
|
119
|
+
/>
|
|
120
|
+
</InputRightElement>
|
|
121
|
+
</InputGroup>
|
|
122
|
+
<IconButton
|
|
123
|
+
aria-label="reset-date"
|
|
124
|
+
variant="danger"
|
|
125
|
+
size="sm"
|
|
126
|
+
fontSize="xs"
|
|
127
|
+
onClick={ resetDate }
|
|
128
|
+
hidden={ !state.dateValue || !isClearable }
|
|
129
|
+
isDisabled={ isDisabled }
|
|
130
|
+
icon={ <Icon as={ XCloseSolid } /> }
|
|
131
|
+
/>
|
|
132
|
+
</HStack>
|
|
133
|
+
</PopoverAnchor>
|
|
134
|
+
{ state.isOpen && (
|
|
135
|
+
<PopoverContent { ...dialogProps } ref={ ref } w={ 64 } border="none">
|
|
136
|
+
<FocusScope contain={ true } restoreFocus={ true }>
|
|
137
|
+
<DatePickerLocaleWrapper firstDayOfWeek={ firstDayOfWeek }>
|
|
138
|
+
<Calendar { ...calendarProps } firstDayOfWeek={ firstDayOfWeek } />
|
|
139
|
+
</DatePickerLocaleWrapper>
|
|
140
|
+
</FocusScope>
|
|
141
|
+
</PopoverContent>
|
|
142
|
+
) }
|
|
143
|
+
</Popover>
|
|
144
|
+
)
|
|
145
|
+
}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import React, { useRef } from 'react'
|
|
2
|
+
import { FocusScope } from '@react-aria/focus'
|
|
3
|
+
import { useDateRangePickerState } from '@react-stately/datepicker'
|
|
4
|
+
import { useDateRangePicker } from '@react-aria/datepicker'
|
|
5
|
+
import { useMultiStyleConfig, useOutsideClick } from '@chakra-ui/react'
|
|
6
|
+
import { CheckSolid, XCloseSolid } from '@northlight/icons'
|
|
7
|
+
import { identity, isNil } from 'ramda'
|
|
8
|
+
import { DateValue, parseDate } from '@internationalized/date'
|
|
9
|
+
import { DateRange } from '@react-types/datepicker'
|
|
10
|
+
import { DateRangePickerProps, DateRange as NorthlightDateRange } from '../types'
|
|
11
|
+
import { RangeCalendar } from '../components/calendar/quick-navigation'
|
|
12
|
+
import { P } from '../../typography'
|
|
13
|
+
import { HStack } from '../../stack'
|
|
14
|
+
import { Popover, PopoverAnchor, PopoverContent } from '../../popover'
|
|
15
|
+
import { Portal } from '../../portal'
|
|
16
|
+
import { DateField, StyledField, Trigger } from '../components/date-field'
|
|
17
|
+
import { IconButton } from '../../icon-button'
|
|
18
|
+
import { InputGroup, InputRightElement } from '../../input'
|
|
19
|
+
import { Icon } from '../../icon'
|
|
20
|
+
import { isValidDateRange } from '../date-picker-field/utils'
|
|
21
|
+
import { DatePickerLocaleWrapper } from './date-picker-locale-wrapper'
|
|
22
|
+
import { Tooltip } from '../../tooltip'
|
|
23
|
+
|
|
24
|
+
const parseValue = (value: any) => {
|
|
25
|
+
if (!isValidDateRange(value)) return null
|
|
26
|
+
return { start: parseDate(value.startDate), end: parseDate(value.endDate) }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const PortalWrapper = ({
|
|
30
|
+
renderInPortal,
|
|
31
|
+
children,
|
|
32
|
+
}: {
|
|
33
|
+
renderInPortal: boolean
|
|
34
|
+
children: React.ReactNode
|
|
35
|
+
}) => {
|
|
36
|
+
if (renderInPortal) {
|
|
37
|
+
return <Portal>{ children }</Portal>
|
|
38
|
+
}
|
|
39
|
+
return <>{ children }</>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const isDatesEqual = (
|
|
43
|
+
date1: NorthlightDateRange | null,
|
|
44
|
+
date2: NorthlightDateRange | null
|
|
45
|
+
) => date1?.startDate === date2?.startDate && date1?.endDate === date2?.endDate
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Popover to choose date range on format {startDate:' yyyy-mm-dd', endDate: 'yyyy-mm-dd'}
|
|
49
|
+
*
|
|
50
|
+
* @see DatePicker
|
|
51
|
+
* @see DateRangePickerField
|
|
52
|
+
* @see {@link https://northlight.dev/reference/date-range-picker}
|
|
53
|
+
* @example (Example)
|
|
54
|
+
* ## Advanced Mode
|
|
55
|
+
* (Due to it being harder to setup normal date range picker,
|
|
56
|
+
* the date range picker field is demoed,
|
|
57
|
+
* here, you need to pass down and parse a value for the date range picker for it to work properly,
|
|
58
|
+
* consult the date picker documentation and the source code for date range picker
|
|
59
|
+
* field for appropiate use)
|
|
60
|
+
* (?
|
|
61
|
+
* <Form initialValues={{date: null}}>
|
|
62
|
+
* <DateRangePickerField name="date"/>
|
|
63
|
+
* </Form>
|
|
64
|
+
* ?)
|
|
65
|
+
*
|
|
66
|
+
* @example (Example)
|
|
67
|
+
* ## Simple mode
|
|
68
|
+
* The previous example was the date range picker variant
|
|
69
|
+
* for which we call advance, this one is a simpler version with the same core functionality:
|
|
70
|
+
* (?
|
|
71
|
+
* <Form initialValues={{date: null}}>
|
|
72
|
+
* <DateRangePickerField name="date" />
|
|
73
|
+
* </Form>
|
|
74
|
+
* ?)
|
|
75
|
+
*
|
|
76
|
+
* @example (Example)
|
|
77
|
+
* ## Sophisticated example
|
|
78
|
+
* The `DateRangePickerField` can have **fiscalStartMonth** and **fiscalStartDay** as a `number`
|
|
79
|
+
* (?
|
|
80
|
+
* <Form initialValues={{date: null}}>
|
|
81
|
+
* <DateRangePickerField
|
|
82
|
+
* name="date"
|
|
83
|
+
* mode="advanced"
|
|
84
|
+
* variant="filled"
|
|
85
|
+
* fiscalStartMonth={3}
|
|
86
|
+
* fiscalStartDay={5}
|
|
87
|
+
* dateFormat="mm|dd-yyyy"
|
|
88
|
+
* minValue="2023-01-01"
|
|
89
|
+
* maxValue="2028-01-01"
|
|
90
|
+
* />
|
|
91
|
+
* </Form>
|
|
92
|
+
* ?)
|
|
93
|
+
*/
|
|
94
|
+
export const DateRangePicker = (props: DateRangePickerProps) => {
|
|
95
|
+
const {
|
|
96
|
+
isDisabled,
|
|
97
|
+
isClearable = true,
|
|
98
|
+
resetDate,
|
|
99
|
+
isInvalid = false,
|
|
100
|
+
dateFormat,
|
|
101
|
+
fiscalStartMonth,
|
|
102
|
+
fiscalStartDay,
|
|
103
|
+
variant = 'outline',
|
|
104
|
+
onChange: onChangeCallback = identity,
|
|
105
|
+
value,
|
|
106
|
+
minValue = '1994-03-08',
|
|
107
|
+
maxValue,
|
|
108
|
+
renderInPortal = false,
|
|
109
|
+
firstDayOfWeek,
|
|
110
|
+
onSave,
|
|
111
|
+
buttonLabel = 'Save',
|
|
112
|
+
clearButtonLabel = 'Clear',
|
|
113
|
+
savedDateRange,
|
|
114
|
+
defaultDateRange,
|
|
115
|
+
CustomResetButton,
|
|
116
|
+
onCancelChanges,
|
|
117
|
+
'data-testid': dataTestId,
|
|
118
|
+
defaultOpen = false,
|
|
119
|
+
onOpenChange,
|
|
120
|
+
} = props
|
|
121
|
+
const ref = useRef() as React.MutableRefObject<HTMLInputElement>
|
|
122
|
+
const { group } = useMultiStyleConfig('DatePicker')
|
|
123
|
+
const parsedProps = {
|
|
124
|
+
onChange: (date: DateRange) => {
|
|
125
|
+
onChangeCallback({
|
|
126
|
+
startDate: date?.start.toString(),
|
|
127
|
+
endDate: date?.end.toString(),
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
value: parseValue(value) as { start: DateValue, end: DateValue },
|
|
131
|
+
minValue: isNil(minValue) ? undefined : (parseDate(minValue) as DateValue),
|
|
132
|
+
maxValue: isNil(maxValue) ? undefined : (parseDate(maxValue) as DateValue),
|
|
133
|
+
}
|
|
134
|
+
const state = useDateRangePickerState({
|
|
135
|
+
value: parsedProps.value,
|
|
136
|
+
onChange: parsedProps.onChange,
|
|
137
|
+
minValue: parsedProps.minValue,
|
|
138
|
+
maxValue: parsedProps.maxValue,
|
|
139
|
+
isDisabled,
|
|
140
|
+
isInvalid,
|
|
141
|
+
placeholderValue: props.placeholderValue,
|
|
142
|
+
isDateUnavailable: props.isDateUnavailable,
|
|
143
|
+
allowsNonContiguousRanges: props.allowsNonContiguousRanges,
|
|
144
|
+
shouldCloseOnSelect: false,
|
|
145
|
+
hideTimeZone: true,
|
|
146
|
+
defaultOpen,
|
|
147
|
+
onOpenChange,
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
const {
|
|
151
|
+
groupProps,
|
|
152
|
+
startFieldProps,
|
|
153
|
+
endFieldProps,
|
|
154
|
+
buttonProps,
|
|
155
|
+
dialogProps,
|
|
156
|
+
calendarProps,
|
|
157
|
+
} = useDateRangePicker(
|
|
158
|
+
{
|
|
159
|
+
onChange: (date: DateRange) => {
|
|
160
|
+
onChangeCallback({
|
|
161
|
+
startDate: date?.start.toString(),
|
|
162
|
+
endDate: date?.end.toString(),
|
|
163
|
+
})
|
|
164
|
+
},
|
|
165
|
+
value: parseValue(value) as { start: DateValue, end: DateValue },
|
|
166
|
+
minValue: parsedProps.minValue || parseDate('1994-03-08'),
|
|
167
|
+
maxValue: parsedProps.maxValue,
|
|
168
|
+
placeholderValue: props.placeholderValue,
|
|
169
|
+
isDateUnavailable: props.isDateUnavailable,
|
|
170
|
+
allowsNonContiguousRanges: props.allowsNonContiguousRanges,
|
|
171
|
+
isDisabled,
|
|
172
|
+
isInvalid,
|
|
173
|
+
startName: props.startName,
|
|
174
|
+
endName: props.endName,
|
|
175
|
+
'aria-label': 'Date range picker',
|
|
176
|
+
...(!isNil(dataTestId) && { 'data-testid': dataTestId }),
|
|
177
|
+
},
|
|
178
|
+
state,
|
|
179
|
+
ref
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
const togglePopup = () => state.setOpen(!state.isOpen)
|
|
183
|
+
|
|
184
|
+
const handleClose = () => {
|
|
185
|
+
state.setOpen(false)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
useOutsideClick({
|
|
189
|
+
ref,
|
|
190
|
+
handler: () => state.setOpen(false),
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
const ResetButton = CustomResetButton || (
|
|
194
|
+
<IconButton
|
|
195
|
+
aria-label="reset-date"
|
|
196
|
+
variant="danger"
|
|
197
|
+
size="sm"
|
|
198
|
+
fontSize="xs"
|
|
199
|
+
hidden={ !isClearable }
|
|
200
|
+
isDisabled={ isDisabled }
|
|
201
|
+
onClick={ resetDate }
|
|
202
|
+
icon={ <Icon as={ XCloseSolid } /> }
|
|
203
|
+
/>
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
const cancelOrResetDateChange = () => {
|
|
207
|
+
if (onCancelChanges) {
|
|
208
|
+
if (!isNil(savedDateRange)) onChangeCallback(savedDateRange)
|
|
209
|
+
onCancelChanges()
|
|
210
|
+
} else {
|
|
211
|
+
if (!isNil(defaultDateRange)) onChangeCallback(defaultDateRange)
|
|
212
|
+
resetDate()
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const handleSave = () => {
|
|
217
|
+
onSave?.()
|
|
218
|
+
handleClose()
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const handleModalClose = () => {
|
|
222
|
+
if (!isNil(savedDateRange)) onChangeCallback(savedDateRange)
|
|
223
|
+
handleClose()
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// If savedDateRange is null, we consider value saved
|
|
227
|
+
const isCurrentDateSaved =
|
|
228
|
+
isNil(savedDateRange) || isDatesEqual(value, savedDateRange)
|
|
229
|
+
|
|
230
|
+
// If defaultDateRange is null, we consider value resettable
|
|
231
|
+
const isDateResettable =
|
|
232
|
+
isNil(defaultDateRange) || !isDatesEqual(value, defaultDateRange)
|
|
233
|
+
|
|
234
|
+
const canShowSaveAndCancelButtons = !isNil(savedDateRange) && !isNil(defaultDateRange)
|
|
235
|
+
|
|
236
|
+
const shouldShowResetButton =
|
|
237
|
+
!state.isOpen && isCurrentDateSaved && isDateResettable
|
|
238
|
+
|
|
239
|
+
const shouldShowSaveAndCancelButtons =
|
|
240
|
+
canShowSaveAndCancelButtons && !state.isOpen && !isCurrentDateSaved
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
<Popover
|
|
244
|
+
isOpen={ state.isOpen }
|
|
245
|
+
onClose={ handleModalClose }
|
|
246
|
+
placement="bottom-start"
|
|
247
|
+
>
|
|
248
|
+
<PopoverAnchor>
|
|
249
|
+
<HStack>
|
|
250
|
+
<InputGroup { ...groupProps } ref={ ref } __css={ group }>
|
|
251
|
+
<StyledField
|
|
252
|
+
isDisabled={ isDisabled }
|
|
253
|
+
isInvalid={ isInvalid }
|
|
254
|
+
variant={ variant }
|
|
255
|
+
>
|
|
256
|
+
<HStack paddingInlineStart="1a" paddingInlineEnd={ 10 }>
|
|
257
|
+
<DateField { ...startFieldProps } dateFormat={ dateFormat } />
|
|
258
|
+
<P>-</P>
|
|
259
|
+
<DateField { ...endFieldProps } dateFormat={ dateFormat } />
|
|
260
|
+
</HStack>
|
|
261
|
+
</StyledField>
|
|
262
|
+
<InputRightElement sx={ { height: '100%', paddingRight: '1' } }>
|
|
263
|
+
<Trigger
|
|
264
|
+
{ ...buttonProps }
|
|
265
|
+
isDisabled={ isDisabled }
|
|
266
|
+
handleClick={ togglePopup }
|
|
267
|
+
/>
|
|
268
|
+
</InputRightElement>
|
|
269
|
+
</InputGroup>
|
|
270
|
+
{ shouldShowResetButton && (
|
|
271
|
+
ResetButton
|
|
272
|
+
) }
|
|
273
|
+
{ shouldShowSaveAndCancelButtons && (
|
|
274
|
+
<>
|
|
275
|
+
<Tooltip label={ clearButtonLabel }>
|
|
276
|
+
<IconButton
|
|
277
|
+
aria-label="cancel-date-change"
|
|
278
|
+
variant="ghost"
|
|
279
|
+
size="sm"
|
|
280
|
+
fontSize="xs"
|
|
281
|
+
onClick={ onCancelChanges }
|
|
282
|
+
isDisabled={ isDisabled }
|
|
283
|
+
icon={ <Icon as={ XCloseSolid } /> }
|
|
284
|
+
/>
|
|
285
|
+
</Tooltip>
|
|
286
|
+
<Tooltip label={ buttonLabel }>
|
|
287
|
+
<IconButton
|
|
288
|
+
aria-label="save-date"
|
|
289
|
+
variant="brand"
|
|
290
|
+
size="sm"
|
|
291
|
+
fontSize="xs"
|
|
292
|
+
onClick={ handleSave }
|
|
293
|
+
isDisabled={ isDisabled }
|
|
294
|
+
icon={ <Icon as={ CheckSolid } /> }
|
|
295
|
+
/>
|
|
296
|
+
</Tooltip>
|
|
297
|
+
</>
|
|
298
|
+
) }
|
|
299
|
+
</HStack>
|
|
300
|
+
</PopoverAnchor>
|
|
301
|
+
<PortalWrapper renderInPortal={ renderInPortal }>
|
|
302
|
+
{ state.isOpen && (
|
|
303
|
+
<PopoverContent { ...dialogProps } ref={ ref } w="max-content">
|
|
304
|
+
<FocusScope contain={ true } restoreFocus={ true }>
|
|
305
|
+
<DatePickerLocaleWrapper firstDayOfWeek={ firstDayOfWeek }>
|
|
306
|
+
<RangeCalendar
|
|
307
|
+
{ ...calendarProps }
|
|
308
|
+
resetDate={ cancelOrResetDateChange }
|
|
309
|
+
handleClose={ handleModalClose }
|
|
310
|
+
fiscalStartMonth={ fiscalStartMonth || 0 }
|
|
311
|
+
fiscalStartDay={ fiscalStartDay || 0 }
|
|
312
|
+
isClearable={ isClearable }
|
|
313
|
+
firstDayOfWeek={ firstDayOfWeek }
|
|
314
|
+
onSave={ onSave }
|
|
315
|
+
clearButtonLabel={ clearButtonLabel }
|
|
316
|
+
buttonLabel={ buttonLabel }
|
|
317
|
+
/>
|
|
318
|
+
</DatePickerLocaleWrapper>
|
|
319
|
+
</FocusScope>
|
|
320
|
+
</PopoverContent>
|
|
321
|
+
) }
|
|
322
|
+
</PortalWrapper>
|
|
323
|
+
</Popover>
|
|
324
|
+
)
|
|
325
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import { DateValue, parseDate } from '@internationalized/date'
|
|
3
|
+
import { identity } from 'ramda'
|
|
4
|
+
import { DatePickerFieldProps } from '../types'
|
|
5
|
+
import { Field } from '../../form'
|
|
6
|
+
import { DatePicker } from '../date-picker/date-picker'
|
|
7
|
+
import { useFormContext } from '../../../hooks'
|
|
8
|
+
import { InputGroupWrapper } from '../../../internal-components/input-group-wrapper'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The <DatePicker /> component wrapped in a <Field />
|
|
12
|
+
* meant to be used only inside <Form />
|
|
13
|
+
* @see DatePicker
|
|
14
|
+
* @see {@link https://northlight.dev/reference/date-picker-field}
|
|
15
|
+
*
|
|
16
|
+
* @example (Example)
|
|
17
|
+
* ##Fill in your information:
|
|
18
|
+
* (?
|
|
19
|
+
* <Form initialValues={{date: null}}>
|
|
20
|
+
* <DatePickerField name="date" />
|
|
21
|
+
* </Form>
|
|
22
|
+
*
|
|
23
|
+
* ?)
|
|
24
|
+
* <br />
|
|
25
|
+
* ###The simplest way
|
|
26
|
+
* Using the date picker in a form is probably the easiest
|
|
27
|
+
* way to use it, it will handle the state for you and you
|
|
28
|
+
* can retrieve the date at the end as a string on format
|
|
29
|
+
* yyyy-mm-dd on the onSubmit callback on <Form>
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
export const DatePickerField = forwardRef<HTMLDivElement, DatePickerFieldProps>(({
|
|
33
|
+
name,
|
|
34
|
+
minValue,
|
|
35
|
+
maxValue,
|
|
36
|
+
isRequired,
|
|
37
|
+
direction = 'column',
|
|
38
|
+
label,
|
|
39
|
+
validate,
|
|
40
|
+
firstDayOfWeek = 'monday',
|
|
41
|
+
onChange: onChangeCallback = identity,
|
|
42
|
+
inputLeftElement,
|
|
43
|
+
inputRightElement,
|
|
44
|
+
...rest
|
|
45
|
+
}, ref) => {
|
|
46
|
+
const { setValue, setError, trigger } = useFormContext()
|
|
47
|
+
|
|
48
|
+
const handleChange = (date: DateValue) => {
|
|
49
|
+
setValue(name, date?.toString())
|
|
50
|
+
if ((minValue && date < parseDate(minValue)) || (maxValue && date > parseDate(maxValue))) {
|
|
51
|
+
setError(name, {
|
|
52
|
+
type: 'custom',
|
|
53
|
+
message: minValue && maxValue
|
|
54
|
+
? `Date must be between ${minValue}-${maxValue}`
|
|
55
|
+
: minValue
|
|
56
|
+
? `Select date earliest at ${minValue}`
|
|
57
|
+
: `Select date latest at ${maxValue}`
|
|
58
|
+
,
|
|
59
|
+
})
|
|
60
|
+
} else {
|
|
61
|
+
trigger(name)
|
|
62
|
+
}
|
|
63
|
+
onChangeCallback(date)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Field
|
|
68
|
+
name={ name }
|
|
69
|
+
label={ label }
|
|
70
|
+
direction={ direction }
|
|
71
|
+
isRequired={ isRequired }
|
|
72
|
+
validate={ validate }
|
|
73
|
+
ref={ ref }
|
|
74
|
+
>
|
|
75
|
+
{ ({ value, onChange }, { formState: { errors } }) => (
|
|
76
|
+
<InputGroupWrapper
|
|
77
|
+
inputLeftElement={ inputLeftElement }
|
|
78
|
+
inputRightElement={ inputRightElement }
|
|
79
|
+
>
|
|
80
|
+
<DatePicker
|
|
81
|
+
firstDayOfWeek={ firstDayOfWeek }
|
|
82
|
+
aria-label={ label }
|
|
83
|
+
isInvalid={ !!errors[name] }
|
|
84
|
+
onChange={ handleChange }
|
|
85
|
+
resetDate={ () => onChange(null) }
|
|
86
|
+
value={ value ? parseDate(value) as any : null }
|
|
87
|
+
minValue={ minValue ? parseDate(minValue) as DateValue : undefined }
|
|
88
|
+
maxValue={ maxValue ? parseDate(maxValue) as DateValue : undefined }
|
|
89
|
+
validationState={ errors.name ? 'invalid' : 'valid' }
|
|
90
|
+
{ ...rest as any }
|
|
91
|
+
/>
|
|
92
|
+
</InputGroupWrapper>
|
|
93
|
+
) }
|
|
94
|
+
</Field>
|
|
95
|
+
|
|
96
|
+
)
|
|
97
|
+
})
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import { identity } from 'ramda'
|
|
3
|
+
import { DateRangePickerFieldProps, FormBody } from '../types'
|
|
4
|
+
import { Field } from '../../form'
|
|
5
|
+
import { DateRangePicker } from '../date-picker/date-range-picker'
|
|
6
|
+
import { useFormContext } from '../../../hooks'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The <DateRangePicker /> component wrapped in a <Field />
|
|
10
|
+
* meant to be used only inside <Form />
|
|
11
|
+
* @see DateRangePicker
|
|
12
|
+
* @see {@link https://northlight.dev/reference/date-range-picker-field}
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export const DateRangePickerField = forwardRef<HTMLDivElement, DateRangePickerFieldProps>(({
|
|
16
|
+
name,
|
|
17
|
+
minValue,
|
|
18
|
+
maxValue,
|
|
19
|
+
isRequired,
|
|
20
|
+
direction = 'column',
|
|
21
|
+
label,
|
|
22
|
+
validate,
|
|
23
|
+
firstDayOfWeek = 'monday',
|
|
24
|
+
onChange: onChangeCallback = identity,
|
|
25
|
+
isClearable = true,
|
|
26
|
+
onSave,
|
|
27
|
+
buttonLabel = 'Save',
|
|
28
|
+
...rest
|
|
29
|
+
}, ref) => {
|
|
30
|
+
const { setValue, setError, trigger } = useFormContext<FormBody>()
|
|
31
|
+
|
|
32
|
+
const handleChange = (dateRange: { startDate: string, endDate: string }) => {
|
|
33
|
+
setValue(name, dateRange)
|
|
34
|
+
if (
|
|
35
|
+
(minValue && dateRange?.startDate < minValue) ||
|
|
36
|
+
(maxValue && dateRange?.endDate > maxValue)
|
|
37
|
+
) {
|
|
38
|
+
setError(name, {
|
|
39
|
+
type: 'custom',
|
|
40
|
+
message:
|
|
41
|
+
minValue && maxValue
|
|
42
|
+
? `Date must be between ${minValue}-${maxValue}`
|
|
43
|
+
: minValue
|
|
44
|
+
? `Select date earliest at ${minValue}`
|
|
45
|
+
: `Select date latest at ${maxValue}`,
|
|
46
|
+
})
|
|
47
|
+
} else {
|
|
48
|
+
trigger(name)
|
|
49
|
+
}
|
|
50
|
+
onChangeCallback(dateRange)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<Field
|
|
55
|
+
name={ name }
|
|
56
|
+
label={ label }
|
|
57
|
+
direction={ direction }
|
|
58
|
+
isRequired={ isRequired }
|
|
59
|
+
validate={ validate }
|
|
60
|
+
ref={ ref }
|
|
61
|
+
>
|
|
62
|
+
{ ({ value, onChange }, { formState: { errors } }) => (
|
|
63
|
+
<DateRangePicker
|
|
64
|
+
firstDayOfWeek={ firstDayOfWeek }
|
|
65
|
+
aria-label={ label }
|
|
66
|
+
isInvalid={ !!errors[name] }
|
|
67
|
+
onChange={ handleChange }
|
|
68
|
+
onSave={ onSave }
|
|
69
|
+
resetDate={ () => onChange(null) }
|
|
70
|
+
value={ value }
|
|
71
|
+
minValue={ minValue }
|
|
72
|
+
maxValue={ maxValue }
|
|
73
|
+
validationState={ errors.name ? 'invalid' : 'valid' }
|
|
74
|
+
isClearable={ isClearable }
|
|
75
|
+
buttonLabel={ buttonLabel }
|
|
76
|
+
{ ...(rest as any) }
|
|
77
|
+
/>
|
|
78
|
+
) }
|
|
79
|
+
</Field>
|
|
80
|
+
)
|
|
81
|
+
})
|