@navikt/ds-react 8.7.0 → 8.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/alert/base-alert/root/BaseAlertRoot.js +1 -2
- package/cjs/alert/base-alert/root/BaseAlertRoot.js.map +1 -1
- package/cjs/alert/info-card/index.d.ts +2 -2
- package/cjs/alert/info-card/index.js +2 -1
- package/cjs/alert/info-card/index.js.map +1 -1
- package/cjs/alert/info-card/message/InfoCardMessage.d.ts +23 -0
- package/cjs/alert/info-card/message/InfoCardMessage.js +73 -0
- package/cjs/alert/info-card/message/InfoCardMessage.js.map +1 -0
- package/cjs/alert/info-card/root/InfoCardRoot.d.ts +15 -2
- package/cjs/alert/info-card/root/InfoCardRoot.js +4 -1
- package/cjs/alert/info-card/root/InfoCardRoot.js.map +1 -1
- package/cjs/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.d.ts +21 -0
- package/cjs/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.js +24 -0
- package/cjs/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.js.map +1 -0
- package/cjs/data/drag-and-drop/item/DataDragAndDropItem.js +7 -57
- package/cjs/data/drag-and-drop/item/DataDragAndDropItem.js.map +1 -1
- package/cjs/data/drag-and-drop/root/DataDragAndDrop.context.d.ts +4 -1
- package/cjs/data/drag-and-drop/root/DataDragAndDrop.context.js +7 -3
- package/cjs/data/drag-and-drop/root/DataDragAndDrop.context.js.map +1 -1
- package/cjs/data/drag-and-drop/root/DataDragAndDropRoot.d.ts +12 -2
- package/cjs/data/drag-and-drop/root/DataDragAndDropRoot.js +14 -64
- package/cjs/data/drag-and-drop/root/DataDragAndDropRoot.js.map +1 -1
- package/cjs/data/drag-and-drop-old/drag-handler/DataDragAndDropDragHandler.d.ts +22 -0
- package/cjs/data/drag-and-drop-old/drag-handler/DataDragAndDropDragHandler.js +35 -0
- package/cjs/data/drag-and-drop-old/drag-handler/DataDragAndDropDragHandler.js.map +1 -0
- package/cjs/data/drag-and-drop-old/item/DataDragAndDropItem.d.ts +27 -0
- package/cjs/data/drag-and-drop-old/item/DataDragAndDropItem.js +86 -0
- package/cjs/data/drag-and-drop-old/item/DataDragAndDropItem.js.map +1 -0
- package/cjs/data/drag-and-drop-old/root/DataDragAndDrop.context.d.ts +5 -0
- package/cjs/data/drag-and-drop-old/root/DataDragAndDrop.context.js +6 -0
- package/cjs/data/drag-and-drop-old/root/DataDragAndDrop.context.js.map +1 -0
- package/cjs/data/drag-and-drop-old/root/DataDragAndDropRoot.d.ts +24 -0
- package/cjs/data/drag-and-drop-old/root/DataDragAndDropRoot.js +108 -0
- package/cjs/data/drag-and-drop-old/root/DataDragAndDropRoot.js.map +1 -0
- package/cjs/data/table/empty-state/DataTableEmptyState.d.ts +5 -0
- package/cjs/data/table/empty-state/DataTableEmptyState.js +57 -0
- package/cjs/data/table/empty-state/DataTableEmptyState.js.map +1 -0
- package/cjs/data/table/helpers/table-focus.js +7 -1
- package/cjs/data/table/helpers/table-focus.js.map +1 -1
- package/cjs/data/table/helpers/table-keyboard.d.ts +0 -1
- package/cjs/data/table/helpers/table-keyboard.js +2 -4
- package/cjs/data/table/helpers/table-keyboard.js.map +1 -1
- package/cjs/data/table/loading-state/DataTableLoadingState.d.ts +5 -0
- package/cjs/data/table/loading-state/DataTableLoadingState.js +57 -0
- package/cjs/data/table/loading-state/DataTableLoadingState.js.map +1 -0
- package/cjs/data/table/root/DataTable.types.d.ts +13 -0
- package/cjs/data/table/root/DataTable.types.js +3 -0
- package/cjs/data/table/root/DataTable.types.js.map +1 -0
- package/cjs/data/table/root/DataTableAuto.d.ts +60 -0
- package/cjs/data/table/root/DataTableAuto.js +99 -0
- package/cjs/data/table/root/DataTableAuto.js.map +1 -0
- package/cjs/data/table/root/DataTableRoot.context.d.ts +3 -2
- package/cjs/data/table/root/DataTableRoot.context.js.map +1 -1
- package/cjs/data/table/root/DataTableRoot.d.ts +30 -3
- package/cjs/data/table/root/DataTableRoot.js +8 -2
- package/cjs/data/table/root/DataTableRoot.js.map +1 -1
- package/cjs/data/table/root/useTableKeyboardNav.js +1 -0
- package/cjs/data/table/root/useTableKeyboardNav.js.map +1 -1
- package/cjs/data/table/root/useTableSelection.d.ts +55 -0
- package/cjs/data/table/root/useTableSelection.js +79 -0
- package/cjs/data/table/root/useTableSelection.js.map +1 -0
- package/cjs/data/table/td/DataTableTd.d.ts +10 -0
- package/cjs/data/table/td/DataTableTd.js +4 -2
- package/cjs/data/table/td/DataTableTd.js.map +1 -1
- package/cjs/data/table/th/DataTableTh.d.ts +10 -4
- package/cjs/data/table/th/DataTableTh.js +24 -22
- package/cjs/data/table/th/DataTableTh.js.map +1 -1
- package/cjs/data/table/th/useTableColumnResize.d.ts +64 -0
- package/cjs/data/table/th/useTableColumnResize.js +144 -0
- package/cjs/data/table/th/useTableColumnResize.js.map +1 -0
- package/cjs/data/table/thead/DataTableThead.context.d.ts +4 -0
- package/cjs/data/table/thead/DataTableThead.context.js +45 -0
- package/cjs/data/table/thead/DataTableThead.context.js.map +1 -0
- package/cjs/data/table/thead/DataTableThead.js +3 -1
- package/cjs/data/table/thead/DataTableThead.js.map +1 -1
- package/cjs/data/table/tr/DataTableTr.js +4 -3
- package/cjs/data/table/tr/DataTableTr.js.map +1 -1
- package/cjs/data/token-filter/AutoSuggest.js +4 -6
- package/cjs/data/token-filter/AutoSuggest.js.map +1 -1
- package/cjs/date/Date.Input.js +1 -1
- package/cjs/date/Date.Input.js.map +1 -1
- package/cjs/date/datepicker/hooks/useDatepicker.d.ts +12 -1
- package/cjs/date/datepicker/hooks/useDatepicker.js.map +1 -1
- package/cjs/date/monthpicker/hooks/useMonthPicker.d.ts +11 -1
- package/cjs/date/monthpicker/hooks/useMonthPicker.js.map +1 -1
- package/cjs/form/checkbox/CheckboxGroup.js +1 -1
- package/cjs/form/checkbox/CheckboxGroup.js.map +1 -1
- package/cjs/form/fieldset/Fieldset.d.ts +25 -5
- package/cjs/form/fieldset/Fieldset.js +19 -2
- package/cjs/form/fieldset/Fieldset.js.map +1 -1
- package/cjs/form/radio/RadioGroup.js +1 -1
- package/cjs/form/radio/RadioGroup.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/read-more/ReadMore.d.ts +10 -0
- package/cjs/read-more/ReadMore.js +4 -6
- package/cjs/read-more/ReadMore.js.map +1 -1
- package/cjs/types/index.d.ts +1 -1
- package/cjs/types/index.js +0 -15
- package/cjs/types/index.js.map +1 -1
- package/cjs/utils/components/Listbox/input-slot/ListboxInputSlot.js +1 -1
- package/cjs/utils/components/Listbox/input-slot/ListboxInputSlot.js.map +1 -1
- package/cjs/utils/components/Listbox/option/ListboxOption.d.ts +24 -0
- package/cjs/utils/components/Listbox/{item/ListboxItem.js → option/ListboxOption.js} +8 -8
- package/cjs/utils/components/Listbox/option/ListboxOption.js.map +1 -0
- package/cjs/utils/components/Listbox/options/ListboxOptions.d.ts +8 -0
- package/cjs/utils/components/Listbox/{list/ListboxList.js → options/ListboxOptions.js} +8 -8
- package/cjs/utils/components/Listbox/options/ListboxOptions.js.map +1 -0
- package/cjs/utils/components/Listbox/root/ListboxRoot.d.ts +6 -6
- package/cjs/utils/components/Listbox/root/ListboxRoot.js +28 -28
- package/cjs/utils/components/Listbox/root/ListboxRoot.js.map +1 -1
- package/cjs/utils/components/Listbox/root/domHelpers.d.ts +3 -3
- package/cjs/utils/components/Listbox/root/domHelpers.js +8 -8
- package/cjs/utils/components/Listbox/root/domHelpers.js.map +1 -1
- package/cjs/utils/components/floating/Floating.d.ts +1 -1
- package/cjs/utils/components/floating/Floating.js +1 -1
- package/cjs/utils/components/floating/Floating.js.map +1 -1
- package/cjs/utils/components/focus-boundary/FocusBoundary.d.ts +0 -1
- package/cjs/utils/components/focus-boundary/FocusBoundary.js +1 -1
- package/cjs/utils/components/focus-boundary/FocusBoundary.js.map +1 -1
- package/cjs/utils/components/link-anchor/LinkAnchor.js +10 -0
- package/cjs/utils/components/link-anchor/LinkAnchor.js.map +1 -1
- package/cjs/utils/helpers/className.js +1 -1
- package/cjs/utils/helpers/className.js.map +1 -1
- package/cjs/utils/helpers/focus.d.ts +3 -1
- package/cjs/utils/helpers/focus.js +2 -2
- package/cjs/utils/helpers/focus.js.map +1 -1
- package/cjs/utils/helpers/index.d.ts +9 -9
- package/cjs/utils/helpers/index.js +22 -23
- package/cjs/utils/helpers/index.js.map +1 -1
- package/cjs/utils/hooks/index.d.ts +13 -13
- package/cjs/utils/hooks/index.js +31 -28
- package/cjs/utils/hooks/index.js.map +1 -1
- package/cjs/utils/hooks/useScrollLock.js +41 -11
- package/cjs/utils/hooks/useScrollLock.js.map +1 -1
- package/esm/alert/base-alert/root/BaseAlertRoot.js +1 -2
- package/esm/alert/base-alert/root/BaseAlertRoot.js.map +1 -1
- package/esm/alert/info-card/index.d.ts +2 -2
- package/esm/alert/info-card/index.js +1 -1
- package/esm/alert/info-card/index.js.map +1 -1
- package/esm/alert/info-card/message/InfoCardMessage.d.ts +23 -0
- package/esm/alert/info-card/message/InfoCardMessage.js +37 -0
- package/esm/alert/info-card/message/InfoCardMessage.js.map +1 -0
- package/esm/alert/info-card/root/InfoCardRoot.d.ts +15 -2
- package/esm/alert/info-card/root/InfoCardRoot.js +3 -1
- package/esm/alert/info-card/root/InfoCardRoot.js.map +1 -1
- package/esm/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.d.ts +21 -0
- package/esm/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.js +18 -0
- package/esm/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.js.map +1 -0
- package/esm/data/drag-and-drop/item/DataDragAndDropItem.js +4 -24
- package/esm/data/drag-and-drop/item/DataDragAndDropItem.js.map +1 -1
- package/esm/data/drag-and-drop/root/DataDragAndDrop.context.d.ts +4 -1
- package/esm/data/drag-and-drop/root/DataDragAndDrop.context.js +5 -2
- package/esm/data/drag-and-drop/root/DataDragAndDrop.context.js.map +1 -1
- package/esm/data/drag-and-drop/root/DataDragAndDropRoot.d.ts +12 -2
- package/esm/data/drag-and-drop/root/DataDragAndDropRoot.js +15 -65
- package/esm/data/drag-and-drop/root/DataDragAndDropRoot.js.map +1 -1
- package/esm/data/drag-and-drop-old/drag-handler/DataDragAndDropDragHandler.d.ts +22 -0
- package/esm/data/drag-and-drop-old/drag-handler/DataDragAndDropDragHandler.js +29 -0
- package/esm/data/drag-and-drop-old/drag-handler/DataDragAndDropDragHandler.js.map +1 -0
- package/esm/data/drag-and-drop-old/item/DataDragAndDropItem.d.ts +27 -0
- package/esm/data/drag-and-drop-old/item/DataDragAndDropItem.js +50 -0
- package/esm/data/drag-and-drop-old/item/DataDragAndDropItem.js.map +1 -0
- package/esm/data/drag-and-drop-old/root/DataDragAndDrop.context.d.ts +5 -0
- package/esm/data/drag-and-drop-old/root/DataDragAndDrop.context.js +3 -0
- package/esm/data/drag-and-drop-old/root/DataDragAndDrop.context.js.map +1 -0
- package/esm/data/drag-and-drop-old/root/DataDragAndDropRoot.d.ts +24 -0
- package/esm/data/drag-and-drop-old/root/DataDragAndDropRoot.js +68 -0
- package/esm/data/drag-and-drop-old/root/DataDragAndDropRoot.js.map +1 -0
- package/esm/data/table/empty-state/DataTableEmptyState.d.ts +5 -0
- package/esm/data/table/empty-state/DataTableEmptyState.js +21 -0
- package/esm/data/table/empty-state/DataTableEmptyState.js.map +1 -0
- package/esm/data/table/helpers/table-focus.js +7 -1
- package/esm/data/table/helpers/table-focus.js.map +1 -1
- package/esm/data/table/helpers/table-keyboard.d.ts +0 -1
- package/esm/data/table/helpers/table-keyboard.js +2 -4
- package/esm/data/table/helpers/table-keyboard.js.map +1 -1
- package/esm/data/table/loading-state/DataTableLoadingState.d.ts +5 -0
- package/esm/data/table/loading-state/DataTableLoadingState.js +21 -0
- package/esm/data/table/loading-state/DataTableLoadingState.js.map +1 -0
- package/esm/data/table/root/DataTable.types.d.ts +13 -0
- package/esm/data/table/root/DataTable.types.js +2 -0
- package/esm/data/table/root/DataTable.types.js.map +1 -0
- package/esm/data/table/root/DataTableAuto.d.ts +60 -0
- package/esm/data/table/root/DataTableAuto.js +63 -0
- package/esm/data/table/root/DataTableAuto.js.map +1 -0
- package/esm/data/table/root/DataTableRoot.context.d.ts +3 -2
- package/esm/data/table/root/DataTableRoot.context.js.map +1 -1
- package/esm/data/table/root/DataTableRoot.d.ts +30 -3
- package/esm/data/table/root/DataTableRoot.js +6 -2
- package/esm/data/table/root/DataTableRoot.js.map +1 -1
- package/esm/data/table/root/useTableKeyboardNav.js +1 -0
- package/esm/data/table/root/useTableKeyboardNav.js.map +1 -1
- package/esm/data/table/root/useTableSelection.d.ts +55 -0
- package/esm/data/table/root/useTableSelection.js +77 -0
- package/esm/data/table/root/useTableSelection.js.map +1 -0
- package/esm/data/table/td/DataTableTd.d.ts +10 -0
- package/esm/data/table/td/DataTableTd.js +4 -2
- package/esm/data/table/td/DataTableTd.js.map +1 -1
- package/esm/data/table/th/DataTableTh.d.ts +10 -4
- package/esm/data/table/th/DataTableTh.js +25 -23
- package/esm/data/table/th/DataTableTh.js.map +1 -1
- package/esm/data/table/th/useTableColumnResize.d.ts +64 -0
- package/esm/data/table/th/useTableColumnResize.js +142 -0
- package/esm/data/table/th/useTableColumnResize.js.map +1 -0
- package/esm/data/table/thead/DataTableThead.context.d.ts +4 -0
- package/esm/data/table/thead/DataTableThead.context.js +8 -0
- package/esm/data/table/thead/DataTableThead.context.js.map +1 -0
- package/esm/data/table/thead/DataTableThead.js +3 -1
- package/esm/data/table/thead/DataTableThead.js.map +1 -1
- package/esm/data/table/tr/DataTableTr.js +4 -3
- package/esm/data/table/tr/DataTableTr.js.map +1 -1
- package/esm/data/token-filter/AutoSuggest.js +4 -6
- package/esm/data/token-filter/AutoSuggest.js.map +1 -1
- package/esm/date/Date.Input.js +1 -1
- package/esm/date/Date.Input.js.map +1 -1
- package/esm/date/datepicker/hooks/useDatepicker.d.ts +12 -1
- package/esm/date/datepicker/hooks/useDatepicker.js.map +1 -1
- package/esm/date/monthpicker/hooks/useMonthPicker.d.ts +11 -1
- package/esm/date/monthpicker/hooks/useMonthPicker.js.map +1 -1
- package/esm/form/checkbox/CheckboxGroup.js +1 -1
- package/esm/form/checkbox/CheckboxGroup.js.map +1 -1
- package/esm/form/fieldset/Fieldset.d.ts +25 -5
- package/esm/form/fieldset/Fieldset.js +19 -2
- package/esm/form/fieldset/Fieldset.js.map +1 -1
- package/esm/form/radio/RadioGroup.js +1 -1
- package/esm/form/radio/RadioGroup.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js.map +1 -1
- package/esm/read-more/ReadMore.d.ts +10 -0
- package/esm/read-more/ReadMore.js +4 -6
- package/esm/read-more/ReadMore.js.map +1 -1
- package/esm/types/index.d.ts +1 -1
- package/esm/types/index.js +1 -1
- package/esm/types/index.js.map +1 -1
- package/esm/utils/components/Listbox/input-slot/ListboxInputSlot.js +1 -1
- package/esm/utils/components/Listbox/input-slot/ListboxInputSlot.js.map +1 -1
- package/esm/utils/components/Listbox/option/ListboxOption.d.ts +24 -0
- package/esm/utils/components/Listbox/{item/ListboxItem.js → option/ListboxOption.js} +7 -7
- package/esm/utils/components/Listbox/option/ListboxOption.js.map +1 -0
- package/esm/utils/components/Listbox/options/ListboxOptions.d.ts +8 -0
- package/esm/utils/components/Listbox/{list/ListboxList.js → options/ListboxOptions.js} +8 -8
- package/esm/utils/components/Listbox/options/ListboxOptions.js.map +1 -0
- package/esm/utils/components/Listbox/root/ListboxRoot.d.ts +6 -6
- package/esm/utils/components/Listbox/root/ListboxRoot.js +29 -29
- package/esm/utils/components/Listbox/root/ListboxRoot.js.map +1 -1
- package/esm/utils/components/Listbox/root/domHelpers.d.ts +3 -3
- package/esm/utils/components/Listbox/root/domHelpers.js +7 -7
- package/esm/utils/components/Listbox/root/domHelpers.js.map +1 -1
- package/esm/utils/components/floating/Floating.d.ts +1 -1
- package/esm/utils/components/floating/Floating.js +1 -1
- package/esm/utils/components/floating/Floating.js.map +1 -1
- package/esm/utils/components/focus-boundary/FocusBoundary.d.ts +0 -1
- package/esm/utils/components/focus-boundary/FocusBoundary.js +1 -1
- package/esm/utils/components/focus-boundary/FocusBoundary.js.map +1 -1
- package/esm/utils/components/link-anchor/LinkAnchor.js +10 -0
- package/esm/utils/components/link-anchor/LinkAnchor.js.map +1 -1
- package/esm/utils/helpers/className.js +1 -1
- package/esm/utils/helpers/className.js.map +1 -1
- package/esm/utils/helpers/focus.d.ts +3 -1
- package/esm/utils/helpers/focus.js +2 -2
- package/esm/utils/helpers/focus.js.map +1 -1
- package/esm/utils/helpers/index.d.ts +9 -9
- package/esm/utils/helpers/index.js +9 -9
- package/esm/utils/helpers/index.js.map +1 -1
- package/esm/utils/hooks/index.d.ts +13 -13
- package/esm/utils/hooks/index.js +13 -13
- package/esm/utils/hooks/index.js.map +1 -1
- package/esm/utils/hooks/useScrollLock.js +41 -11
- package/esm/utils/hooks/useScrollLock.js.map +1 -1
- package/package.json +5 -5
- package/src/alert/base-alert/root/BaseAlertRoot.tsx +1 -1
- package/src/alert/info-card/index.ts +2 -0
- package/src/alert/info-card/message/InfoCardMessage.tsx +48 -0
- package/src/alert/info-card/root/InfoCardRoot.tsx +20 -1
- package/src/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.tsx +63 -0
- package/src/data/drag-and-drop/item/DataDragAndDropItem.tsx +6 -53
- package/src/data/drag-and-drop/root/DataDragAndDrop.context.tsx +9 -4
- package/src/data/drag-and-drop/root/DataDragAndDropRoot.tsx +19 -63
- package/src/data/drag-and-drop-old/drag-handler/DataDragAndDropDragHandler.tsx +104 -0
- package/src/data/drag-and-drop-old/item/DataDragAndDropItem.tsx +74 -0
- package/src/data/drag-and-drop-old/root/DataDragAndDrop.context.tsx +11 -0
- package/src/data/drag-and-drop-old/root/DataDragAndDropRoot.tsx +96 -0
- package/src/data/table/empty-state/DataTableEmptyState.tsx +26 -0
- package/src/data/table/helpers/table-focus.ts +10 -1
- package/src/data/table/helpers/table-keyboard.ts +2 -6
- package/src/data/table/loading-state/DataTableLoadingState.tsx +26 -0
- package/src/data/table/root/DataTable.types.ts +16 -0
- package/src/data/table/root/DataTableAuto.tsx +182 -0
- package/src/data/table/root/DataTableRoot.context.ts +3 -2
- package/src/data/table/root/DataTableRoot.tsx +45 -2
- package/src/data/table/root/useTableKeyboardNav.ts +1 -0
- package/src/data/table/root/useTableSelection.ts +126 -0
- package/src/data/table/td/DataTableTd.tsx +14 -1
- package/src/data/table/th/DataTableTh.tsx +48 -36
- package/src/data/table/th/useTableColumnResize.ts +276 -0
- package/src/data/table/thead/DataTableThead.context.ts +10 -0
- package/src/data/table/thead/DataTableThead.tsx +8 -5
- package/src/data/table/tr/DataTableTr.tsx +8 -3
- package/src/data/token-filter/AutoSuggest.tsx +11 -12
- package/src/date/Date.Input.tsx +1 -1
- package/src/date/datepicker/hooks/useDatepicker.tsx +12 -1
- package/src/date/monthpicker/hooks/useMonthPicker.tsx +11 -1
- package/src/form/checkbox/CheckboxGroup.tsx +1 -1
- package/src/form/fieldset/Fieldset.tsx +31 -7
- package/src/form/radio/RadioGroup.tsx +1 -1
- package/src/index.ts +1 -0
- package/src/read-more/ReadMore.tsx +15 -16
- package/src/types/index.ts +1 -1
- package/src/utils/components/Listbox/input-slot/ListboxInputSlot.tsx +1 -1
- package/src/utils/components/Listbox/{item/ListboxItem.tsx → option/ListboxOption.tsx} +14 -14
- package/src/utils/components/Listbox/{list/ListboxList.tsx → options/ListboxOptions.tsx} +10 -10
- package/src/utils/components/Listbox/root/ListboxRoot.tsx +31 -31
- package/src/utils/components/Listbox/root/domHelpers.ts +8 -7
- package/src/utils/components/floating/Floating.tsx +2 -2
- package/src/utils/components/focus-boundary/FocusBoundary.tsx +1 -2
- package/src/utils/components/link-anchor/LinkAnchor.tsx +11 -0
- package/src/utils/helpers/className.ts +1 -1
- package/src/utils/helpers/focus.ts +5 -2
- package/src/utils/helpers/index.ts +9 -9
- package/src/utils/hooks/index.ts +20 -13
- package/src/utils/hooks/useScrollLock.ts +57 -13
- package/cjs/utils/components/Listbox/item/ListboxItem.d.ts +0 -24
- package/cjs/utils/components/Listbox/item/ListboxItem.js.map +0 -1
- package/cjs/utils/components/Listbox/list/ListboxList.d.ts +0 -8
- package/cjs/utils/components/Listbox/list/ListboxList.js.map +0 -1
- package/esm/utils/components/Listbox/item/ListboxItem.d.ts +0 -24
- package/esm/utils/components/Listbox/item/ListboxItem.js.map +0 -1
- package/esm/utils/components/Listbox/list/ListboxList.d.ts +0 -8
- package/esm/utils/components/Listbox/list/ListboxList.js.map +0 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
CaretDownCircleFillIcon,
|
|
4
|
+
CaretUpCircleFillIcon,
|
|
5
|
+
DragVerticalIcon,
|
|
6
|
+
} from "@navikt/aksel-icons";
|
|
7
|
+
|
|
8
|
+
export interface DataDragAndDropDragHandlerProps {
|
|
9
|
+
/**
|
|
10
|
+
* Whether the drag handler is disabled
|
|
11
|
+
*/
|
|
12
|
+
// disabled?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Wether dragging is done by keyboard. Used to conditionally render drag indicators.
|
|
15
|
+
*/
|
|
16
|
+
keyboardDragging?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Handle ref is forwarded to the button element serving as drag handle.
|
|
19
|
+
*/
|
|
20
|
+
handleRef: React.Ref<HTMLDivElement>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* DataDragAndDropDragHandler
|
|
25
|
+
*
|
|
26
|
+
* A button component that serves as a drag handle for drag and drop operations.
|
|
27
|
+
* Can be used to initiate dragging of elements in a data table or list.
|
|
28
|
+
*/
|
|
29
|
+
export const DataDragAndDropDragHandler = React.forwardRef<
|
|
30
|
+
HTMLButtonElement,
|
|
31
|
+
DataDragAndDropDragHandlerProps
|
|
32
|
+
>(({ keyboardDragging, handleRef }) => {
|
|
33
|
+
return (
|
|
34
|
+
<div className="aksel-data-drag-and-drop__drag-handler__alt">
|
|
35
|
+
{keyboardDragging && (
|
|
36
|
+
<span
|
|
37
|
+
className="aksel-data-drag-and-drop__drag-handler__arrow"
|
|
38
|
+
data-direction="up"
|
|
39
|
+
>
|
|
40
|
+
<CaretUpCircleFillIcon aria-hidden fontSize="1.2rem" />
|
|
41
|
+
</span>
|
|
42
|
+
)}
|
|
43
|
+
<div
|
|
44
|
+
ref={handleRef}
|
|
45
|
+
className="aksel-data-drag-and-drop__drag-handler__button"
|
|
46
|
+
>
|
|
47
|
+
<DragVerticalIcon
|
|
48
|
+
aria-hidden
|
|
49
|
+
title="Dra for å flytte"
|
|
50
|
+
fontSize="1.5rem"
|
|
51
|
+
/>
|
|
52
|
+
</div>
|
|
53
|
+
{keyboardDragging && (
|
|
54
|
+
<span
|
|
55
|
+
className="aksel-data-drag-and-drop__drag-handler__arrow"
|
|
56
|
+
data-direction="down"
|
|
57
|
+
>
|
|
58
|
+
<CaretDownCircleFillIcon aria-hidden fontSize="1.2rem" />
|
|
59
|
+
</span>
|
|
60
|
+
)}
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
});
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import React, { useRef } from "react";
|
|
3
|
-
import {
|
|
4
|
-
CaretDownCircleFillIcon,
|
|
5
|
-
CaretUpCircleFillIcon,
|
|
6
|
-
DragVerticalIcon,
|
|
7
|
-
} from "@navikt/aksel-icons";
|
|
1
|
+
import React from "react";
|
|
8
2
|
import { HStack } from "../../../primitives/stack";
|
|
9
3
|
import { cl } from "../../../utils/helpers";
|
|
10
|
-
import { useMergeRefs } from "../../../utils/hooks";
|
|
11
|
-
import { DataDragAndDropContext } from "../root/DataDragAndDrop.context";
|
|
12
4
|
|
|
13
5
|
interface DataDragAndDropItemProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
14
6
|
children: React.ReactNode;
|
|
@@ -36,60 +28,21 @@ interface DataDragAndDropItemProps extends React.HTMLAttributes<HTMLDivElement>
|
|
|
36
28
|
const DataDragAndDropItem = React.forwardRef<
|
|
37
29
|
HTMLDivElement,
|
|
38
30
|
DataDragAndDropItemProps
|
|
39
|
-
>(({ children,
|
|
40
|
-
const
|
|
41
|
-
const { ref, isDragging, isDropTarget } = useSortable({
|
|
42
|
-
id,
|
|
43
|
-
index,
|
|
44
|
-
handle: handleRef,
|
|
45
|
-
});
|
|
46
|
-
const mergedRef = useMergeRefs(ref, forwardedRef);
|
|
47
|
-
const context = React.useContext(DataDragAndDropContext);
|
|
48
|
-
const mouseDragging = isDragging && context?.inputMethod === "mouse";
|
|
49
|
-
const mouseDropTarget = isDropTarget && context?.inputMethod === "mouse";
|
|
50
|
-
const keyboardDragging = isDragging && context?.inputMethod === "keyboard";
|
|
31
|
+
>(({ children, className, ...rest }, forwardedRef) => {
|
|
32
|
+
// const context = useDataDragAndDropContext();
|
|
51
33
|
|
|
52
34
|
return (
|
|
53
35
|
<HStack gap="space-8" align="center" wrap={false} asChild>
|
|
54
36
|
{/* TODO Should this be a <li>? */}
|
|
55
37
|
<div
|
|
56
|
-
ref={
|
|
38
|
+
ref={forwardedRef}
|
|
57
39
|
{...rest}
|
|
58
40
|
className={cl("aksel-data-table__drag-and-drop-item", className)}
|
|
59
|
-
data-dragging={isDragging}
|
|
41
|
+
/*data-dragging={isDragging}
|
|
60
42
|
data-mouse-dragging={mouseDragging}
|
|
61
43
|
data-keyboard-dragging={keyboardDragging}
|
|
62
|
-
data-drop-target={mouseDropTarget}
|
|
63
|
-
tabIndex={-1}
|
|
44
|
+
data-drop-target={mouseDropTarget}*/
|
|
64
45
|
>
|
|
65
|
-
<div
|
|
66
|
-
className="aksel-data-table__drag-and-drop-item-drag-handler"
|
|
67
|
-
ref={handleRef}
|
|
68
|
-
// TODO Consider moving this to its own component
|
|
69
|
-
// TODO Perhaps make it a button where clicking also enables arrow icons?
|
|
70
|
-
>
|
|
71
|
-
{keyboardDragging && (
|
|
72
|
-
<span
|
|
73
|
-
className="aksel-data-table__drag-and-drop-item-keyboard-drag-icon"
|
|
74
|
-
data-direction="up"
|
|
75
|
-
>
|
|
76
|
-
<CaretUpCircleFillIcon aria-hidden fontSize="1.2rem" />
|
|
77
|
-
</span>
|
|
78
|
-
)}
|
|
79
|
-
<DragVerticalIcon
|
|
80
|
-
aria-hidden
|
|
81
|
-
title="Dra for å flytte"
|
|
82
|
-
fontSize="1.5rem"
|
|
83
|
-
/>
|
|
84
|
-
{keyboardDragging && (
|
|
85
|
-
<span
|
|
86
|
-
className="aksel-data-table__drag-and-drop-item-keyboard-drag-icon"
|
|
87
|
-
data-direction="down"
|
|
88
|
-
>
|
|
89
|
-
<CaretDownCircleFillIcon aria-hidden fontSize="1.2rem" />
|
|
90
|
-
</span>
|
|
91
|
-
)}
|
|
92
|
-
</div>
|
|
93
46
|
<div>{children}</div>
|
|
94
47
|
</div>
|
|
95
48
|
</HStack>
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createStrictContext } from "../../../utils/helpers";
|
|
2
2
|
|
|
3
3
|
interface DataDragAndDropContextType {
|
|
4
4
|
inputMethod: "mouse" | "keyboard" | null;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export const
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
export const {
|
|
8
|
+
Provider: DataDragAndDropProvider,
|
|
9
|
+
useContext: useDataDragAndDropContext,
|
|
10
|
+
} = createStrictContext<DataDragAndDropContextType | undefined>({
|
|
11
|
+
errorMessage:
|
|
12
|
+
"useDataDragAndDropContext must be used within a DataDragAndDropProvider",
|
|
13
|
+
name: "DataDragAndDropContext",
|
|
14
|
+
});
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isSortable } from "@dnd-kit/react/sortable";
|
|
3
|
-
import React, { forwardRef, isValidElement } from "react";
|
|
4
|
-
import { VStack } from "../../../primitives/stack";
|
|
1
|
+
import React, { forwardRef } from "react";
|
|
5
2
|
import DataDragAndDropItem, {
|
|
6
3
|
DataDragAndDropItemProps,
|
|
7
4
|
} from "../item/DataDragAndDropItem";
|
|
8
|
-
import {
|
|
5
|
+
import { DataDragAndDropProvider } from "./DataDragAndDrop.context";
|
|
9
6
|
|
|
10
|
-
interface DataDragAndDropProps extends React.HTMLAttributes<
|
|
7
|
+
interface DataDragAndDropProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
11
8
|
children: any[];
|
|
12
9
|
setItems: React.Dispatch<React.SetStateAction<any[]>>;
|
|
13
10
|
}
|
|
14
11
|
|
|
15
12
|
interface DataDragAndDropRootComponent extends React.ForwardRefExoticComponent<
|
|
16
|
-
DataDragAndDropProps & React.RefAttributes<
|
|
13
|
+
DataDragAndDropProps & React.RefAttributes<HTMLDivElement>
|
|
17
14
|
> {
|
|
18
15
|
/**
|
|
19
16
|
* @see 🏷️ {@link DataDragAndDropItemProps}
|
|
@@ -29,64 +26,23 @@ interface DataDragAndDropRootComponent extends React.ForwardRefExoticComponent<
|
|
|
29
26
|
Item: typeof DataDragAndDropItem;
|
|
30
27
|
}
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
newItems.splice(targetIndex, 0, movedItem);
|
|
43
|
-
return newItems;
|
|
44
|
-
});
|
|
45
|
-
};
|
|
29
|
+
/**
|
|
30
|
+
* TODO
|
|
31
|
+
* setItems on root
|
|
32
|
+
* state : active element
|
|
33
|
+
* pointer over listener / state, onPointerEnter, onPointerLeave
|
|
34
|
+
* Overlay - Use floating component
|
|
35
|
+
* Keyboard navigation
|
|
36
|
+
* Handle - button, arrows also button
|
|
37
|
+
* UU - announce on drag start, item moved, drag end
|
|
38
|
+
*/
|
|
46
39
|
|
|
40
|
+
const DataDragAndDrop = forwardRef<HTMLDivElement, DataDragAndDropProps>(
|
|
41
|
+
({ children }, forwardedRef) => {
|
|
47
42
|
return (
|
|
48
|
-
<
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
onBeforeDragStart={(event) =>
|
|
52
|
-
setInputMethod(
|
|
53
|
-
event.operation.activatorEvent?.type === "pointerdown"
|
|
54
|
-
? "mouse"
|
|
55
|
-
: "keyboard",
|
|
56
|
-
)
|
|
57
|
-
}
|
|
58
|
-
onDragOver={(event) => {
|
|
59
|
-
if (event.operation.activatorEvent?.type === "pointerdown") {
|
|
60
|
-
// Prevents items to rearrange while dragging with mouse, but allows keyboard dragging to work as intended
|
|
61
|
-
event.preventDefault();
|
|
62
|
-
}
|
|
63
|
-
}}
|
|
64
|
-
onDragEnd={(event) => {
|
|
65
|
-
if (event.operation.activatorEvent?.type === "pointerdown") {
|
|
66
|
-
const { source, target } = event.operation;
|
|
67
|
-
if (!isSortable(source) || !isSortable(target)) return;
|
|
68
|
-
setItemOrder(source.initialIndex, target.index);
|
|
69
|
-
}
|
|
70
|
-
}}
|
|
71
|
-
>
|
|
72
|
-
<VStack asChild gap="space-12">
|
|
73
|
-
<div {...rest} ref={forwardedRef}>
|
|
74
|
-
{children}
|
|
75
|
-
</div>
|
|
76
|
-
</VStack>
|
|
77
|
-
<DragOverlay>
|
|
78
|
-
{(source) => {
|
|
79
|
-
// Overlay not needed and causes glitching when using keyboard
|
|
80
|
-
if (inputMethod === "keyboard") return null;
|
|
81
|
-
if (!isSortable(source)) return null;
|
|
82
|
-
if (isValidElement(children[source.initialIndex])) {
|
|
83
|
-
return children[source.initialIndex];
|
|
84
|
-
}
|
|
85
|
-
return null;
|
|
86
|
-
}}
|
|
87
|
-
</DragOverlay>
|
|
88
|
-
</DragDropProvider>
|
|
89
|
-
</DataDragAndDropContext.Provider>
|
|
43
|
+
<DataDragAndDropProvider inputMethod={null}>
|
|
44
|
+
<div ref={forwardedRef}>{children}</div>
|
|
45
|
+
</DataDragAndDropProvider>
|
|
90
46
|
);
|
|
91
47
|
},
|
|
92
48
|
) as DataDragAndDropRootComponent;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
CaretDownCircleFillIcon,
|
|
4
|
+
CaretUpCircleFillIcon,
|
|
5
|
+
DragVerticalIcon,
|
|
6
|
+
} from "@navikt/aksel-icons";
|
|
7
|
+
import { Floating } from "../../../utils/components/floating/Floating";
|
|
8
|
+
|
|
9
|
+
export interface DataDragAndDropDragHandlerProps {
|
|
10
|
+
/**
|
|
11
|
+
* Whether the drag handler is disabled
|
|
12
|
+
*/
|
|
13
|
+
// disabled?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Wether dragging is done by keyboard. Used to conditionally render drag indicators.
|
|
16
|
+
*/
|
|
17
|
+
keyboardDragging?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Handle ref is forwarded to the button element serving as drag handle.
|
|
20
|
+
*/
|
|
21
|
+
handleRef: React.Ref<HTMLDivElement>;
|
|
22
|
+
// Just for testing purposes, to render an alternative drag handler
|
|
23
|
+
alt?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* DataDragAndDropDragHandler
|
|
28
|
+
*
|
|
29
|
+
* A button component that serves as a drag handle for drag and drop operations.
|
|
30
|
+
* Can be used to initiate dragging of elements in a data table or list.
|
|
31
|
+
*/
|
|
32
|
+
export const DataDragAndDropDragHandler = React.forwardRef<
|
|
33
|
+
HTMLButtonElement,
|
|
34
|
+
DataDragAndDropDragHandlerProps
|
|
35
|
+
>(({ keyboardDragging, handleRef, alt }) => {
|
|
36
|
+
if (alt) {
|
|
37
|
+
return (
|
|
38
|
+
<div className="aksel-data-drag-and-drop__drag-handler__alt">
|
|
39
|
+
{keyboardDragging && (
|
|
40
|
+
<span
|
|
41
|
+
className="aksel-data-drag-and-drop__drag-handler__arrow"
|
|
42
|
+
data-direction="up"
|
|
43
|
+
>
|
|
44
|
+
<CaretUpCircleFillIcon aria-hidden fontSize="1.2rem" />
|
|
45
|
+
</span>
|
|
46
|
+
)}
|
|
47
|
+
<div
|
|
48
|
+
ref={handleRef}
|
|
49
|
+
className="aksel-data-drag-and-drop__drag-handler__button"
|
|
50
|
+
>
|
|
51
|
+
<DragVerticalIcon
|
|
52
|
+
aria-hidden
|
|
53
|
+
title="Dra for å flytte"
|
|
54
|
+
fontSize="1.5rem"
|
|
55
|
+
/>
|
|
56
|
+
</div>
|
|
57
|
+
{keyboardDragging && (
|
|
58
|
+
<span
|
|
59
|
+
className="aksel-data-drag-and-drop__drag-handler__arrow"
|
|
60
|
+
data-direction="down"
|
|
61
|
+
>
|
|
62
|
+
<CaretDownCircleFillIcon aria-hidden fontSize="1.2rem" />
|
|
63
|
+
</span>
|
|
64
|
+
)}
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<Floating>
|
|
71
|
+
{keyboardDragging && (
|
|
72
|
+
<Floating.Content
|
|
73
|
+
side="top"
|
|
74
|
+
avoidCollisions={false}
|
|
75
|
+
updatePositionStrategy="always"
|
|
76
|
+
className="aksel-data-drag-and-drop__drag-handler__arrow"
|
|
77
|
+
>
|
|
78
|
+
<CaretUpCircleFillIcon aria-hidden fontSize="1.2rem" />
|
|
79
|
+
</Floating.Content>
|
|
80
|
+
)}
|
|
81
|
+
<Floating.Anchor asChild>
|
|
82
|
+
<div
|
|
83
|
+
ref={handleRef}
|
|
84
|
+
className="aksel-data-drag-and-drop__drag-handler__button"
|
|
85
|
+
>
|
|
86
|
+
<DragVerticalIcon
|
|
87
|
+
aria-hidden
|
|
88
|
+
title="Dra for å flytte"
|
|
89
|
+
fontSize="1.5rem"
|
|
90
|
+
/>
|
|
91
|
+
</div>
|
|
92
|
+
</Floating.Anchor>
|
|
93
|
+
{keyboardDragging && (
|
|
94
|
+
<Floating.Content
|
|
95
|
+
avoidCollisions={false}
|
|
96
|
+
updatePositionStrategy="always"
|
|
97
|
+
className="aksel-data-drag-and-drop__drag-handler__arrow"
|
|
98
|
+
>
|
|
99
|
+
<CaretDownCircleFillIcon aria-hidden fontSize="1.2rem" />
|
|
100
|
+
</Floating.Content>
|
|
101
|
+
)}
|
|
102
|
+
</Floating>
|
|
103
|
+
);
|
|
104
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useSortable } from "@dnd-kit/react/sortable";
|
|
2
|
+
import React, { useRef } from "react";
|
|
3
|
+
import { HStack } from "../../../primitives/stack";
|
|
4
|
+
import { cl } from "../../../utils/helpers";
|
|
5
|
+
import { useMergeRefs } from "../../../utils/hooks";
|
|
6
|
+
import { DataDragAndDropDragHandler } from "../drag-handler/DataDragAndDropDragHandler";
|
|
7
|
+
import { DataDragAndDropContext } from "../root/DataDragAndDrop.context";
|
|
8
|
+
|
|
9
|
+
interface DataDragAndDropItemProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
/**
|
|
12
|
+
* Unique id
|
|
13
|
+
*/
|
|
14
|
+
id: string;
|
|
15
|
+
/**
|
|
16
|
+
* Index of the item being dragged
|
|
17
|
+
*/
|
|
18
|
+
index: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* TODO
|
|
23
|
+
*
|
|
24
|
+
* @see 🏷️ {@link DataDragAndDropItemProps}
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* <DragAndDrop.Item numOfSelectedRows={selectedRows.length} onClear={handleClear}>
|
|
28
|
+
* TODO
|
|
29
|
+
* </DragAndDrop.Item>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const DataDragAndDropItem = React.forwardRef<
|
|
33
|
+
HTMLDivElement,
|
|
34
|
+
DataDragAndDropItemProps
|
|
35
|
+
>(({ children, id, index, className, ...rest }, forwardedRef) => {
|
|
36
|
+
const handleRef = useRef<HTMLDivElement>(null);
|
|
37
|
+
const { ref, isDragging, isDropTarget } = useSortable({
|
|
38
|
+
id,
|
|
39
|
+
index,
|
|
40
|
+
handle: handleRef,
|
|
41
|
+
});
|
|
42
|
+
const mergedRef = useMergeRefs(ref, forwardedRef);
|
|
43
|
+
const context = React.useContext(DataDragAndDropContext);
|
|
44
|
+
const mouseDragging = isDragging && context?.inputMethod === "mouse";
|
|
45
|
+
const mouseDropTarget = isDropTarget && context?.inputMethod === "mouse";
|
|
46
|
+
const keyboardDragging = isDragging && context?.inputMethod === "keyboard";
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<HStack gap="space-8" align="center" wrap={false} asChild>
|
|
50
|
+
{/* TODO Should this be a <li>? */}
|
|
51
|
+
<div
|
|
52
|
+
ref={mergedRef}
|
|
53
|
+
{...rest}
|
|
54
|
+
className={cl("aksel-data-table__drag-and-drop-item", className)}
|
|
55
|
+
data-dragging={isDragging}
|
|
56
|
+
data-mouse-dragging={mouseDragging}
|
|
57
|
+
data-keyboard-dragging={keyboardDragging}
|
|
58
|
+
data-drop-target={mouseDropTarget}
|
|
59
|
+
tabIndex={-1}
|
|
60
|
+
>
|
|
61
|
+
<DataDragAndDropDragHandler
|
|
62
|
+
handleRef={handleRef}
|
|
63
|
+
keyboardDragging={keyboardDragging}
|
|
64
|
+
alt
|
|
65
|
+
/>
|
|
66
|
+
<div>{children}</div>
|
|
67
|
+
</div>
|
|
68
|
+
</HStack>
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export default DataDragAndDropItem;
|
|
73
|
+
export { DataDragAndDropItem };
|
|
74
|
+
export type { DataDragAndDropItemProps };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
|
|
3
|
+
interface DataDragAndDropContextType {
|
|
4
|
+
inputMethod: "mouse" | "keyboard" | null;
|
|
5
|
+
// setInputMethod: (method: "mouse" | "keyboard" | null) => void;
|
|
6
|
+
// setItems: React.Dispatch<React.SetStateAction<any[]>>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const DataDragAndDropContext = createContext<
|
|
10
|
+
DataDragAndDropContextType | undefined
|
|
11
|
+
>(undefined);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { DragDropProvider, DragOverlay } from "@dnd-kit/react";
|
|
2
|
+
import { isSortable } from "@dnd-kit/react/sortable";
|
|
3
|
+
import React, { forwardRef, isValidElement } from "react";
|
|
4
|
+
import { VStack } from "../../../primitives/stack";
|
|
5
|
+
import DataDragAndDropItem, {
|
|
6
|
+
DataDragAndDropItemProps,
|
|
7
|
+
} from "../item/DataDragAndDropItem";
|
|
8
|
+
import { DataDragAndDropContext } from "./DataDragAndDrop.context";
|
|
9
|
+
|
|
10
|
+
interface DataDragAndDropProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
11
|
+
children: any[];
|
|
12
|
+
setItems: React.Dispatch<React.SetStateAction<any[]>>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface DataDragAndDropRootComponent extends React.ForwardRefExoticComponent<
|
|
16
|
+
DataDragAndDropProps & React.RefAttributes<HTMLDivElement>
|
|
17
|
+
> {
|
|
18
|
+
/**
|
|
19
|
+
* @see 🏷️ {@link DataDragAndDropItemProps}
|
|
20
|
+
* * @example
|
|
21
|
+
* ```jsx
|
|
22
|
+
* <DragAndDrop>
|
|
23
|
+
* <DragAndDrop.Item id="1" index={0}>
|
|
24
|
+
* ...
|
|
25
|
+
* </DragAndDrop.Item>
|
|
26
|
+
* </DragAndDrop>
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
Item: typeof DataDragAndDropItem;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const DataDragAndDrop = forwardRef<HTMLDivElement, DataDragAndDropProps>(
|
|
33
|
+
({ setItems, children, ...rest }, forwardedRef) => {
|
|
34
|
+
const [inputMethod, setInputMethod] = React.useState<
|
|
35
|
+
"mouse" | "keyboard" | null
|
|
36
|
+
>(null);
|
|
37
|
+
|
|
38
|
+
const setItemOrder = (initalIndex: number, targetIndex: number) => {
|
|
39
|
+
setItems((items) => {
|
|
40
|
+
const newItems = [...items];
|
|
41
|
+
const [movedItem] = newItems.splice(initalIndex, 1);
|
|
42
|
+
newItems.splice(targetIndex, 0, movedItem);
|
|
43
|
+
return newItems;
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<DataDragAndDropContext.Provider value={{ inputMethod }}>
|
|
49
|
+
<DragDropProvider
|
|
50
|
+
// TODO Look into overriding default keybinds, might eliminate context need
|
|
51
|
+
onBeforeDragStart={(event) =>
|
|
52
|
+
setInputMethod(
|
|
53
|
+
event.operation.activatorEvent?.type === "pointerdown"
|
|
54
|
+
? "mouse"
|
|
55
|
+
: "keyboard",
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
onDragOver={(event) => {
|
|
59
|
+
if (event.operation.activatorEvent?.type === "pointerdown") {
|
|
60
|
+
// Prevents items to rearrange while dragging with mouse, but allows keyboard dragging to work as intended
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
}
|
|
63
|
+
}}
|
|
64
|
+
onDragEnd={(event) => {
|
|
65
|
+
const { source, target } = event.operation;
|
|
66
|
+
if (!isSortable(source) || !isSortable(target)) return;
|
|
67
|
+
setItemOrder(source.initialIndex, target.index);
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
<VStack asChild gap="space-12">
|
|
71
|
+
<div {...rest} ref={forwardedRef}>
|
|
72
|
+
{children}
|
|
73
|
+
</div>
|
|
74
|
+
</VStack>
|
|
75
|
+
<DragOverlay dropAnimation={null}>
|
|
76
|
+
{(source) => {
|
|
77
|
+
// Overlay not needed and causes glitching when using keyboard
|
|
78
|
+
if (inputMethod === "keyboard") return null;
|
|
79
|
+
if (!isSortable(source)) return null;
|
|
80
|
+
if (isValidElement(children[source.initialIndex])) {
|
|
81
|
+
return children[source.initialIndex];
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}}
|
|
85
|
+
</DragOverlay>
|
|
86
|
+
</DragDropProvider>
|
|
87
|
+
</DataDragAndDropContext.Provider>
|
|
88
|
+
);
|
|
89
|
+
},
|
|
90
|
+
) as DataDragAndDropRootComponent;
|
|
91
|
+
|
|
92
|
+
DataDragAndDrop.Item = DataDragAndDropItem;
|
|
93
|
+
|
|
94
|
+
export { DataDragAndDrop, DataDragAndDropItem };
|
|
95
|
+
export default DataDragAndDrop;
|
|
96
|
+
export type { DataDragAndDropItemProps, DataDragAndDropProps };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { forwardRef } from "react";
|
|
2
|
+
import { cl } from "../../../utils/helpers";
|
|
3
|
+
|
|
4
|
+
type DataTableEmptyStateProps = React.HTMLAttributes<HTMLDivElement>;
|
|
5
|
+
|
|
6
|
+
const DataTableEmptyState = forwardRef<
|
|
7
|
+
HTMLDivElement,
|
|
8
|
+
DataTableEmptyStateProps
|
|
9
|
+
>(({ className, children, ...rest }, forwardedRef) => {
|
|
10
|
+
return (
|
|
11
|
+
<tr>
|
|
12
|
+
<td colSpan={999}>
|
|
13
|
+
<div
|
|
14
|
+
{...rest}
|
|
15
|
+
ref={forwardedRef}
|
|
16
|
+
className={cl("aksel-data-table__empty-state", className)}
|
|
17
|
+
>
|
|
18
|
+
{children}
|
|
19
|
+
</div>
|
|
20
|
+
</td>
|
|
21
|
+
</tr>
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export { DataTableEmptyState };
|
|
26
|
+
export type { DataTableEmptyStateProps };
|
|
@@ -34,7 +34,11 @@ function restoreTabIndex(cell: Element): void {
|
|
|
34
34
|
*/
|
|
35
35
|
function findFocusableElementInCell(cell: Element): HTMLElement | null {
|
|
36
36
|
const el = cell as HTMLElement | null;
|
|
37
|
-
if (
|
|
37
|
+
if (
|
|
38
|
+
!el ||
|
|
39
|
+
isHiddenElement(el) ||
|
|
40
|
+
el.hasAttribute("data-block-keyboard-nav")
|
|
41
|
+
) {
|
|
38
42
|
return null;
|
|
39
43
|
}
|
|
40
44
|
|
|
@@ -48,6 +52,11 @@ function findFocusableElementInCell(cell: Element): HTMLElement | null {
|
|
|
48
52
|
|
|
49
53
|
for (let i = 0; i < focusables.length; i += 1) {
|
|
50
54
|
const focusable = focusables[i] as HTMLElement;
|
|
55
|
+
/* Ignore element if it has [data-block-keyboard-nav="true"] */
|
|
56
|
+
if (focusable.hasAttribute("data-block-keyboard-nav")) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
51
60
|
if (!isHiddenElement(focusable) && !isDisabledElement(focusable)) {
|
|
52
61
|
return focusable;
|
|
53
62
|
}
|
|
@@ -52,7 +52,6 @@ function getNavigationAction(event: KeyboardEvent): NavigationAction | null {
|
|
|
52
52
|
* - Select arrow down/up for opening popup
|
|
53
53
|
* - User is navigating inside multiline textarea
|
|
54
54
|
* - contenteditable attrb is in use
|
|
55
|
-
* - element has attribute data-block-keyboard-nav="true"
|
|
56
55
|
*/
|
|
57
56
|
function shouldBlockNavigation(event: KeyboardEvent): boolean {
|
|
58
57
|
const key = event.key;
|
|
@@ -71,7 +70,7 @@ function shouldBlockNavigation(event: KeyboardEvent): boolean {
|
|
|
71
70
|
|
|
72
71
|
/* If not any of these elements, assume "safe" to navigate */
|
|
73
72
|
const editable = el.closest(
|
|
74
|
-
'input, textarea, select, [contenteditable="true"]
|
|
73
|
+
'input, textarea, select, [contenteditable="true"]',
|
|
75
74
|
);
|
|
76
75
|
|
|
77
76
|
if (!editable) {
|
|
@@ -93,10 +92,7 @@ function shouldBlockNavigation(event: KeyboardEvent): boolean {
|
|
|
93
92
|
return false;
|
|
94
93
|
}
|
|
95
94
|
|
|
96
|
-
return (
|
|
97
|
-
editable.hasAttribute("contenteditable") ||
|
|
98
|
-
editable.hasAttribute("data-block-keyboard-nav")
|
|
99
|
-
);
|
|
95
|
+
return editable.hasAttribute("contenteditable");
|
|
100
96
|
}
|
|
101
97
|
|
|
102
98
|
function shouldBlockInputArrow(input: HTMLInputElement, key: string): boolean {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { forwardRef } from "react";
|
|
2
|
+
import { cl } from "../../../utils/helpers";
|
|
3
|
+
|
|
4
|
+
type DataTableLoadingStateProps = React.HTMLAttributes<HTMLDivElement>;
|
|
5
|
+
|
|
6
|
+
const DataTableLoadingState = forwardRef<
|
|
7
|
+
HTMLDivElement,
|
|
8
|
+
DataTableLoadingStateProps
|
|
9
|
+
>(({ className, children, ...rest }, forwardedRef) => {
|
|
10
|
+
return (
|
|
11
|
+
<tr>
|
|
12
|
+
<td colSpan={999}>
|
|
13
|
+
<div
|
|
14
|
+
{...rest}
|
|
15
|
+
ref={forwardedRef}
|
|
16
|
+
className={cl("aksel-data-table__loading-state", className)}
|
|
17
|
+
>
|
|
18
|
+
{children}
|
|
19
|
+
</div>
|
|
20
|
+
</td>
|
|
21
|
+
</tr>
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export { DataTableLoadingState };
|
|
26
|
+
export type { DataTableLoadingStateProps };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type ColumnDefinition<T> = {
|
|
2
|
+
id?: string;
|
|
3
|
+
header: React.ReactNode;
|
|
4
|
+
width?: number | string;
|
|
5
|
+
minWidth?: number | string;
|
|
6
|
+
maxWidth?: number | string;
|
|
7
|
+
/* isRowHeader?: boolean; */
|
|
8
|
+
/**
|
|
9
|
+
* TODO: Could add table/row/cell context into callback
|
|
10
|
+
*/
|
|
11
|
+
cell: (item: T) => React.ReactNode;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type ColumnDefinitions<T> = ColumnDefinition<T>[];
|
|
15
|
+
|
|
16
|
+
export type { ColumnDefinition, ColumnDefinitions };
|