@navikt/ds-react 8.8.0 → 8.9.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.
Files changed (228) hide show
  1. package/cjs/data/drag-and-drop/drag-handler/DragAndDropDragHandler.d.ts +13 -0
  2. package/cjs/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js +59 -0
  3. package/cjs/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js.map +1 -0
  4. package/cjs/data/drag-and-drop/item/DragAndDropItem.d.ts +31 -0
  5. package/cjs/data/drag-and-drop/item/DragAndDropItem.js +48 -0
  6. package/cjs/data/drag-and-drop/item/DragAndDropItem.js.map +1 -0
  7. package/cjs/data/drag-and-drop/root/DragAndDrop.context.d.ts +17 -0
  8. package/cjs/data/drag-and-drop/root/DragAndDrop.context.js +10 -0
  9. package/cjs/data/drag-and-drop/root/DragAndDrop.context.js.map +1 -0
  10. package/cjs/data/drag-and-drop/root/DragAndDropRoot.d.ts +38 -0
  11. package/cjs/data/drag-and-drop/root/DragAndDropRoot.js +219 -0
  12. package/cjs/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -0
  13. package/cjs/data/drag-and-drop/types.d.ts +4 -0
  14. package/cjs/data/drag-and-drop/types.js +3 -0
  15. package/cjs/data/drag-and-drop/types.js.map +1 -0
  16. package/cjs/data/table/helpers/selection/getMultipleSelectProps.d.ts +14 -0
  17. package/cjs/data/table/helpers/selection/getMultipleSelectProps.js +48 -0
  18. package/cjs/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -0
  19. package/cjs/data/table/helpers/selection/getSingleSelectProps.d.ts +10 -0
  20. package/cjs/data/table/helpers/selection/getSingleSelectProps.js +26 -0
  21. package/cjs/data/table/helpers/selection/getSingleSelectProps.js.map +1 -0
  22. package/cjs/data/table/helpers/selection/selection.types.d.ts +42 -0
  23. package/cjs/data/table/helpers/selection/selection.types.js +3 -0
  24. package/cjs/data/table/helpers/selection/selection.types.js.map +1 -0
  25. package/cjs/data/table/{root → hooks}/useTableKeyboardNav.js +1 -1
  26. package/cjs/data/table/hooks/useTableKeyboardNav.js.map +1 -0
  27. package/cjs/data/table/hooks/useTableSelection.d.ts +8 -0
  28. package/cjs/data/table/hooks/useTableSelection.js +49 -0
  29. package/cjs/data/table/hooks/useTableSelection.js.map +1 -0
  30. package/cjs/data/table/root/DataTableAuto.d.ts +4 -4
  31. package/cjs/data/table/root/DataTableAuto.js +23 -11
  32. package/cjs/data/table/root/DataTableAuto.js.map +1 -1
  33. package/cjs/data/table/root/DataTableRoot.d.ts +1 -1
  34. package/cjs/data/table/root/DataTableRoot.js +1 -1
  35. package/cjs/data/table/root/DataTableRoot.js.map +1 -1
  36. package/cjs/data/table/td/DataTableTd.d.ts +4 -0
  37. package/cjs/data/table/td/DataTableTd.js +4 -2
  38. package/cjs/data/table/td/DataTableTd.js.map +1 -1
  39. package/cjs/data/table/th/DataTableTh.d.ts +4 -0
  40. package/cjs/data/table/th/DataTableTh.js +6 -3
  41. package/cjs/data/table/th/DataTableTh.js.map +1 -1
  42. package/cjs/data/token-filter/AutoSuggest.js +37 -4
  43. package/cjs/data/token-filter/AutoSuggest.js.map +1 -1
  44. package/cjs/data/token-filter/FilterChip.d.ts +10 -0
  45. package/cjs/data/token-filter/FilterChip.js +65 -0
  46. package/cjs/data/token-filter/FilterChip.js.map +1 -0
  47. package/cjs/data/token-filter/TokenFilter.d.ts +1 -0
  48. package/cjs/data/token-filter/TokenFilter.js +4 -10
  49. package/cjs/data/token-filter/TokenFilter.js.map +1 -1
  50. package/cjs/data/toolbar/root/DataToolbarRoot.d.ts +6 -23
  51. package/cjs/data/toolbar/root/DataToolbarRoot.js +42 -7
  52. package/cjs/data/toolbar/root/DataToolbarRoot.js.map +1 -1
  53. package/cjs/date/Date.Input.js +8 -9
  54. package/cjs/date/Date.Input.js.map +1 -1
  55. package/cjs/date/datepicker/hooks/useDatepicker.js +4 -3
  56. package/cjs/date/datepicker/hooks/useDatepicker.js.map +1 -1
  57. package/cjs/date/monthpicker/hooks/useMonthPicker.js +3 -2
  58. package/cjs/date/monthpicker/hooks/useMonthPicker.js.map +1 -1
  59. package/cjs/form/checkbox/Checkbox.js +19 -33
  60. package/cjs/form/checkbox/Checkbox.js.map +1 -1
  61. package/cjs/form/checkbox/checkbox-input/CheckboxInput.d.ts +21 -0
  62. package/cjs/form/checkbox/checkbox-input/CheckboxInput.js +65 -0
  63. package/cjs/form/checkbox/checkbox-input/CheckboxInput.js.map +1 -0
  64. package/cjs/form/checkbox/types.d.ts +1 -1
  65. package/cjs/form/fieldset/Fieldset.js +2 -6
  66. package/cjs/form/fieldset/Fieldset.js.map +1 -1
  67. package/cjs/form/radio/Radio.js +9 -7
  68. package/cjs/form/radio/Radio.js.map +1 -1
  69. package/cjs/form/radio/radio-input/RadioInput.d.ts +19 -0
  70. package/cjs/{data/drag-and-drop/root/DataDragAndDropRoot.js → form/radio/radio-input/RadioInput.js} +17 -23
  71. package/cjs/form/radio/radio-input/RadioInput.js.map +1 -0
  72. package/cjs/internal-header/InternalHeaderButton.d.ts +5 -0
  73. package/cjs/internal-header/InternalHeaderButton.js +2 -2
  74. package/cjs/internal-header/InternalHeaderButton.js.map +1 -1
  75. package/cjs/utils/components/Listbox/group/ListboxGroup.js +2 -1
  76. package/cjs/utils/components/Listbox/group/ListboxGroup.js.map +1 -1
  77. package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.d.ts +13 -0
  78. package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js +53 -0
  79. package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js.map +1 -0
  80. package/esm/data/drag-and-drop/item/DragAndDropItem.d.ts +31 -0
  81. package/esm/data/drag-and-drop/item/DragAndDropItem.js +42 -0
  82. package/esm/data/drag-and-drop/item/DragAndDropItem.js.map +1 -0
  83. package/esm/data/drag-and-drop/root/DragAndDrop.context.d.ts +17 -0
  84. package/esm/data/drag-and-drop/root/DragAndDrop.context.js +6 -0
  85. package/esm/data/drag-and-drop/root/DragAndDrop.context.js.map +1 -0
  86. package/esm/data/drag-and-drop/root/DragAndDropRoot.d.ts +38 -0
  87. package/esm/data/drag-and-drop/root/DragAndDropRoot.js +179 -0
  88. package/esm/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -0
  89. package/esm/data/drag-and-drop/types.d.ts +4 -0
  90. package/esm/data/drag-and-drop/types.js +2 -0
  91. package/esm/data/drag-and-drop/types.js.map +1 -0
  92. package/esm/data/table/helpers/selection/getMultipleSelectProps.d.ts +14 -0
  93. package/esm/data/table/helpers/selection/getMultipleSelectProps.js +46 -0
  94. package/esm/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -0
  95. package/esm/data/table/helpers/selection/getSingleSelectProps.d.ts +10 -0
  96. package/esm/data/table/helpers/selection/getSingleSelectProps.js +24 -0
  97. package/esm/data/table/helpers/selection/getSingleSelectProps.js.map +1 -0
  98. package/esm/data/table/helpers/selection/selection.types.d.ts +42 -0
  99. package/esm/data/table/helpers/selection/selection.types.js +2 -0
  100. package/esm/data/table/helpers/selection/selection.types.js.map +1 -0
  101. package/esm/data/table/{root → hooks}/useTableKeyboardNav.js +1 -1
  102. package/esm/data/table/hooks/useTableKeyboardNav.js.map +1 -0
  103. package/esm/data/table/hooks/useTableSelection.d.ts +8 -0
  104. package/esm/data/table/hooks/useTableSelection.js +47 -0
  105. package/esm/data/table/hooks/useTableSelection.js.map +1 -0
  106. package/esm/data/table/root/DataTableAuto.d.ts +4 -4
  107. package/esm/data/table/root/DataTableAuto.js +23 -11
  108. package/esm/data/table/root/DataTableAuto.js.map +1 -1
  109. package/esm/data/table/root/DataTableRoot.d.ts +1 -1
  110. package/esm/data/table/root/DataTableRoot.js +1 -1
  111. package/esm/data/table/root/DataTableRoot.js.map +1 -1
  112. package/esm/data/table/td/DataTableTd.d.ts +4 -0
  113. package/esm/data/table/td/DataTableTd.js +4 -2
  114. package/esm/data/table/td/DataTableTd.js.map +1 -1
  115. package/esm/data/table/th/DataTableTh.d.ts +4 -0
  116. package/esm/data/table/th/DataTableTh.js +6 -3
  117. package/esm/data/table/th/DataTableTh.js.map +1 -1
  118. package/esm/data/token-filter/AutoSuggest.js +38 -5
  119. package/esm/data/token-filter/AutoSuggest.js.map +1 -1
  120. package/esm/data/token-filter/FilterChip.d.ts +10 -0
  121. package/esm/data/token-filter/FilterChip.js +30 -0
  122. package/esm/data/token-filter/FilterChip.js.map +1 -0
  123. package/esm/data/token-filter/TokenFilter.d.ts +1 -0
  124. package/esm/data/token-filter/TokenFilter.js +4 -10
  125. package/esm/data/token-filter/TokenFilter.js.map +1 -1
  126. package/esm/data/toolbar/root/DataToolbarRoot.d.ts +6 -23
  127. package/esm/data/toolbar/root/DataToolbarRoot.js +9 -7
  128. package/esm/data/toolbar/root/DataToolbarRoot.js.map +1 -1
  129. package/esm/date/Date.Input.js +9 -10
  130. package/esm/date/Date.Input.js.map +1 -1
  131. package/esm/date/datepicker/hooks/useDatepicker.js +4 -3
  132. package/esm/date/datepicker/hooks/useDatepicker.js.map +1 -1
  133. package/esm/date/monthpicker/hooks/useMonthPicker.js +3 -2
  134. package/esm/date/monthpicker/hooks/useMonthPicker.js.map +1 -1
  135. package/esm/form/checkbox/Checkbox.js +19 -33
  136. package/esm/form/checkbox/Checkbox.js.map +1 -1
  137. package/esm/form/checkbox/checkbox-input/CheckboxInput.d.ts +21 -0
  138. package/esm/form/checkbox/checkbox-input/CheckboxInput.js +29 -0
  139. package/esm/form/checkbox/checkbox-input/CheckboxInput.js.map +1 -0
  140. package/esm/form/checkbox/types.d.ts +1 -1
  141. package/esm/form/fieldset/Fieldset.js +2 -6
  142. package/esm/form/fieldset/Fieldset.js.map +1 -1
  143. package/esm/form/radio/Radio.js +9 -7
  144. package/esm/form/radio/Radio.js.map +1 -1
  145. package/esm/form/radio/radio-input/RadioInput.d.ts +19 -0
  146. package/esm/form/radio/radio-input/RadioInput.js +19 -0
  147. package/esm/form/radio/radio-input/RadioInput.js.map +1 -0
  148. package/esm/internal-header/InternalHeaderButton.d.ts +5 -0
  149. package/esm/internal-header/InternalHeaderButton.js +2 -2
  150. package/esm/internal-header/InternalHeaderButton.js.map +1 -1
  151. package/esm/utils/components/Listbox/group/ListboxGroup.js +2 -1
  152. package/esm/utils/components/Listbox/group/ListboxGroup.js.map +1 -1
  153. package/package.json +4 -4
  154. package/src/data/drag-and-drop/drag-handler/DragAndDropDragHandler.tsx +94 -0
  155. package/src/data/drag-and-drop/item/DragAndDropItem.tsx +75 -0
  156. package/src/data/drag-and-drop/root/DragAndDrop.context.tsx +27 -0
  157. package/src/data/drag-and-drop/root/DragAndDropRoot.tsx +294 -0
  158. package/src/data/drag-and-drop/types.ts +4 -0
  159. package/src/data/table/helpers/selection/getMultipleSelectProps.ts +70 -0
  160. package/src/data/table/helpers/selection/getSingleSelectProps.ts +36 -0
  161. package/src/data/table/helpers/selection/selection.types.ts +56 -0
  162. package/src/data/table/hooks/__tests__/useTableSelection.test.ts +327 -0
  163. package/src/data/table/{root → hooks}/useTableKeyboardNav.ts +1 -1
  164. package/src/data/table/hooks/useTableSelection.ts +78 -0
  165. package/src/data/table/root/DataTableAuto.tsx +58 -25
  166. package/src/data/table/root/DataTableRoot.tsx +2 -2
  167. package/src/data/table/td/DataTableTd.tsx +15 -2
  168. package/src/data/table/th/DataTableTh.tsx +13 -2
  169. package/src/data/token-filter/AutoSuggest.tsx +65 -3
  170. package/src/data/token-filter/FilterChip.tsx +100 -0
  171. package/src/data/token-filter/TokenFilter.tsx +9 -24
  172. package/src/data/toolbar/root/DataToolbarRoot.tsx +29 -32
  173. package/src/date/Date.Input.tsx +17 -16
  174. package/src/date/datepicker/hooks/useDatepicker.tsx +4 -5
  175. package/src/date/monthpicker/hooks/useMonthPicker.tsx +3 -4
  176. package/src/form/checkbox/Checkbox.tsx +37 -64
  177. package/src/form/checkbox/checkbox-input/CheckboxInput.tsx +69 -0
  178. package/src/form/checkbox/types.ts +1 -1
  179. package/src/form/fieldset/Fieldset.tsx +4 -6
  180. package/src/form/radio/Radio.tsx +43 -38
  181. package/src/form/radio/radio-input/RadioInput.tsx +32 -0
  182. package/src/internal-header/InternalHeaderButton.tsx +18 -9
  183. package/src/utils/components/Listbox/group/ListboxGroup.tsx +9 -2
  184. package/cjs/data/action-bar/root/DataActionBarRoot.d.ts +0 -27
  185. package/cjs/data/action-bar/root/DataActionBarRoot.js +0 -49
  186. package/cjs/data/action-bar/root/DataActionBarRoot.js.map +0 -1
  187. package/cjs/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.d.ts +0 -21
  188. package/cjs/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.js +0 -24
  189. package/cjs/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.js.map +0 -1
  190. package/cjs/data/drag-and-drop/item/DataDragAndDropItem.d.ts +0 -27
  191. package/cjs/data/drag-and-drop/item/DataDragAndDropItem.js +0 -41
  192. package/cjs/data/drag-and-drop/item/DataDragAndDropItem.js.map +0 -1
  193. package/cjs/data/drag-and-drop/root/DataDragAndDrop.context.d.ts +0 -8
  194. package/cjs/data/drag-and-drop/root/DataDragAndDrop.context.js +0 -10
  195. package/cjs/data/drag-and-drop/root/DataDragAndDrop.context.js.map +0 -1
  196. package/cjs/data/drag-and-drop/root/DataDragAndDropRoot.d.ts +0 -34
  197. package/cjs/data/drag-and-drop/root/DataDragAndDropRoot.js.map +0 -1
  198. package/cjs/data/table/root/useTableKeyboardNav.js.map +0 -1
  199. package/cjs/data/table/root/useTableSelection.d.ts +0 -55
  200. package/cjs/data/table/root/useTableSelection.js +0 -79
  201. package/cjs/data/table/root/useTableSelection.js.map +0 -1
  202. package/esm/data/action-bar/root/DataActionBarRoot.d.ts +0 -27
  203. package/esm/data/action-bar/root/DataActionBarRoot.js +0 -43
  204. package/esm/data/action-bar/root/DataActionBarRoot.js.map +0 -1
  205. package/esm/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.d.ts +0 -21
  206. package/esm/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.js +0 -18
  207. package/esm/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.js.map +0 -1
  208. package/esm/data/drag-and-drop/item/DataDragAndDropItem.d.ts +0 -27
  209. package/esm/data/drag-and-drop/item/DataDragAndDropItem.js +0 -35
  210. package/esm/data/drag-and-drop/item/DataDragAndDropItem.js.map +0 -1
  211. package/esm/data/drag-and-drop/root/DataDragAndDrop.context.d.ts +0 -8
  212. package/esm/data/drag-and-drop/root/DataDragAndDrop.context.js +0 -6
  213. package/esm/data/drag-and-drop/root/DataDragAndDrop.context.js.map +0 -1
  214. package/esm/data/drag-and-drop/root/DataDragAndDropRoot.d.ts +0 -34
  215. package/esm/data/drag-and-drop/root/DataDragAndDropRoot.js +0 -21
  216. package/esm/data/drag-and-drop/root/DataDragAndDropRoot.js.map +0 -1
  217. package/esm/data/table/root/useTableKeyboardNav.js.map +0 -1
  218. package/esm/data/table/root/useTableSelection.d.ts +0 -55
  219. package/esm/data/table/root/useTableSelection.js +0 -77
  220. package/esm/data/table/root/useTableSelection.js.map +0 -1
  221. package/src/data/action-bar/root/DataActionBarRoot.tsx +0 -59
  222. package/src/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.tsx +0 -63
  223. package/src/data/drag-and-drop/item/DataDragAndDropItem.tsx +0 -54
  224. package/src/data/drag-and-drop/root/DataDragAndDrop.context.tsx +0 -14
  225. package/src/data/drag-and-drop/root/DataDragAndDropRoot.tsx +0 -54
  226. package/src/data/table/root/useTableSelection.ts +0 -126
  227. /package/cjs/data/table/{root → hooks}/useTableKeyboardNav.d.ts +0 -0
  228. /package/esm/data/table/{root → hooks}/useTableKeyboardNav.d.ts +0 -0
@@ -1,77 +0,0 @@
1
- import { useControllableState } from "../../../utils/hooks/index.js";
2
- function useTableSelection({ selectionMode, defaultSelectedKeys, selectedKeys: selectedKeysProp, onSelectionChange, disabledKeys = [], data, }) {
3
- const [selectedKeys, setSelectedKeys] = useControllableState({
4
- value: selectedKeysProp,
5
- defaultValue: defaultSelectedKeys !== null && defaultSelectedKeys !== void 0 ? defaultSelectedKeys : [],
6
- onChange: onSelectionChange,
7
- });
8
- const handleSelectionChange = (key) => {
9
- if (selectionMode === "none") {
10
- return;
11
- }
12
- if (key === "all") {
13
- if (selectedKeys === "all" ||
14
- (Array.isArray(selectedKeys) && selectedKeys.length === data.length)) {
15
- setSelectedKeys([]);
16
- }
17
- else {
18
- const allKeys = data.map((item) => item.id);
19
- setSelectedKeys(allKeys);
20
- }
21
- }
22
- else {
23
- const value = key.value;
24
- if (selectedKeys === "all") {
25
- setSelectedKeys(data.map((item) => item.id).filter((id) => id !== value));
26
- }
27
- else if (Array.isArray(selectedKeys)) {
28
- if (selectedKeys.includes(value)) {
29
- setSelectedKeys(selectedKeys.filter((k) => k !== value));
30
- }
31
- else {
32
- setSelectedKeys([...selectedKeys, value]);
33
- }
34
- }
35
- }
36
- };
37
- if (selectionMode === "none") {
38
- return {
39
- selectedKeys: [],
40
- handleSelectionChange: () => { },
41
- selectionMode,
42
- disabledKeys,
43
- };
44
- }
45
- return {
46
- selectedKeys,
47
- handleSelectionChange,
48
- selectionMode,
49
- disabledKeys,
50
- getTheadCheckboxProps: () => {
51
- const indeterminate = Array.isArray(selectedKeys) &&
52
- selectedKeys.length > 0 &&
53
- selectedKeys.length < data.length;
54
- return {
55
- /* TODO: i18n */
56
- children: selectionMode === "single" ? "Select row" : "Select all rows",
57
- onChange: () => handleSelectionChange("all"),
58
- checked: (selectedKeys === "all" ||
59
- (Array.isArray(selectedKeys) && selectedKeys.length > 0)) &&
60
- !indeterminate,
61
- indeterminate,
62
- disabled: disabledKeys.length === data.length,
63
- hideLabel: true,
64
- };
65
- },
66
- getRowCheckboxProps: (key) => ({
67
- children: `Select row with id ${key}`,
68
- onChange: () => handleSelectionChange({ value: key }),
69
- checked: selectedKeys === "all" ||
70
- (Array.isArray(selectedKeys) && selectedKeys.includes(key)),
71
- disabled: disabledKeys.includes(key),
72
- hideLabel: true,
73
- }),
74
- };
75
- }
76
- export { useTableSelection };
77
- //# sourceMappingURL=useTableSelection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTableSelection.js","sourceRoot":"","sources":["../../../../src/data/table/root/useTableSelection.ts"],"names":[],"mappings":"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"}
@@ -1,59 +0,0 @@
1
- import React from "react";
2
- import { Button } from "../../../button";
3
- import { Box } from "../../../primitives/box";
4
- import { HStack, Spacer } from "../../../primitives/stack";
5
- import { BodyShort } from "../../../typography";
6
-
7
- interface DataActionBarProps extends React.HTMLAttributes<HTMLDivElement> {
8
- children: React.ReactNode;
9
- /**
10
- * Number of selected rows
11
- */
12
- numOfSelectedRows: number;
13
- /**
14
- * Callback for the clear button
15
- */
16
- onClear: () => void;
17
- }
18
-
19
- /**
20
- * TODO
21
- *
22
- * @see 🏷️ {@link DataActionBarProps}
23
- * @example
24
- * ```tsx
25
- * <DataActionBar numOfSelectedRows={selectedRows.length} onClear={handleClear}>
26
- * TODO
27
- * </DataActionBar>
28
- * ```
29
- */
30
- const DataActionBar = React.forwardRef<HTMLDivElement, DataActionBarProps>(
31
- ({ children, numOfSelectedRows, onClear, ...rest }, forwardRef) => {
32
- return (
33
- <Box
34
- asChild
35
- borderWidth="1"
36
- borderRadius="16"
37
- borderColor="neutral"
38
- background="raised"
39
- padding="space-16"
40
- data-color="neutral"
41
- >
42
- <HStack gap="space-16" align="center" ref={forwardRef} {...rest}>
43
- <BodyShort textColor="subtle">
44
- {numOfSelectedRows} rad{numOfSelectedRows > 1 ? "er" : ""} valgt
45
- </BodyShort>
46
- <Button variant="secondary" size="small" onClick={onClear}>
47
- Nullstill valg
48
- </Button>
49
- <Spacer />
50
- {children}
51
- </HStack>
52
- </Box>
53
- );
54
- },
55
- );
56
-
57
- export default DataActionBar;
58
- export { DataActionBar };
59
- export type { DataActionBarProps };
@@ -1,63 +0,0 @@
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,54 +0,0 @@
1
- import React from "react";
2
- import { HStack } from "../../../primitives/stack";
3
- import { cl } from "../../../utils/helpers";
4
-
5
- interface DataDragAndDropItemProps extends React.HTMLAttributes<HTMLDivElement> {
6
- children: React.ReactNode;
7
- /**
8
- * Unique id
9
- */
10
- id: string;
11
- /**
12
- * Index of the item being dragged
13
- */
14
- index: number;
15
- }
16
-
17
- /**
18
- * TODO
19
- *
20
- * @see 🏷️ {@link DataDragAndDropItemProps}
21
- * @example
22
- * ```tsx
23
- * <DragAndDrop.Item numOfSelectedRows={selectedRows.length} onClear={handleClear}>
24
- * TODO
25
- * </DragAndDrop.Item>
26
- * ```
27
- */
28
- const DataDragAndDropItem = React.forwardRef<
29
- HTMLDivElement,
30
- DataDragAndDropItemProps
31
- >(({ children, className, ...rest }, forwardedRef) => {
32
- // const context = useDataDragAndDropContext();
33
-
34
- return (
35
- <HStack gap="space-8" align="center" wrap={false} asChild>
36
- {/* TODO Should this be a <li>? */}
37
- <div
38
- ref={forwardedRef}
39
- {...rest}
40
- className={cl("aksel-data-table__drag-and-drop-item", className)}
41
- /*data-dragging={isDragging}
42
- data-mouse-dragging={mouseDragging}
43
- data-keyboard-dragging={keyboardDragging}
44
- data-drop-target={mouseDropTarget}*/
45
- >
46
- <div>{children}</div>
47
- </div>
48
- </HStack>
49
- );
50
- });
51
-
52
- export default DataDragAndDropItem;
53
- export { DataDragAndDropItem };
54
- export type { DataDragAndDropItemProps };
@@ -1,14 +0,0 @@
1
- import { createStrictContext } from "../../../utils/helpers";
2
-
3
- interface DataDragAndDropContextType {
4
- inputMethod: "mouse" | "keyboard" | null;
5
- }
6
-
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,54 +0,0 @@
1
- import React, { forwardRef } from "react";
2
- import DataDragAndDropItem, {
3
- DataDragAndDropItemProps,
4
- } from "../item/DataDragAndDropItem";
5
- import { DataDragAndDropProvider } from "./DataDragAndDrop.context";
6
-
7
- interface DataDragAndDropProps extends React.HTMLAttributes<HTMLDivElement> {
8
- children: any[];
9
- setItems: React.Dispatch<React.SetStateAction<any[]>>;
10
- }
11
-
12
- interface DataDragAndDropRootComponent extends React.ForwardRefExoticComponent<
13
- DataDragAndDropProps & React.RefAttributes<HTMLDivElement>
14
- > {
15
- /**
16
- * @see 🏷️ {@link DataDragAndDropItemProps}
17
- * * @example
18
- * ```jsx
19
- * <DragAndDrop>
20
- * <DragAndDrop.Item id="1" index={0}>
21
- * ...
22
- * </DragAndDrop.Item>
23
- * </DragAndDrop>
24
- * ```
25
- */
26
- Item: typeof DataDragAndDropItem;
27
- }
28
-
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
- */
39
-
40
- const DataDragAndDrop = forwardRef<HTMLDivElement, DataDragAndDropProps>(
41
- ({ children }, forwardedRef) => {
42
- return (
43
- <DataDragAndDropProvider inputMethod={null}>
44
- <div ref={forwardedRef}>{children}</div>
45
- </DataDragAndDropProvider>
46
- );
47
- },
48
- ) as DataDragAndDropRootComponent;
49
-
50
- DataDragAndDrop.Item = DataDragAndDropItem;
51
-
52
- export { DataDragAndDrop, DataDragAndDropItem };
53
- export default DataDragAndDrop;
54
- export type { DataDragAndDropItemProps, DataDragAndDropProps };
@@ -1,126 +0,0 @@
1
- import type { CheckboxProps } from "../../../form/checkbox/types";
2
- import { useControllableState } from "../../../utils/hooks";
3
-
4
- type SelectionT = (string | number)[] | "all";
5
-
6
- type SelectionProps = {
7
- /**
8
- * Enables selection of rows.
9
- *
10
- *
11
- * When set to "single", only one row can be selected at a time.
12
- *
13
- * When set to "multiple", multiple rows can be selected.
14
- *
15
- * TODO:
16
- * - Implement callbacks for selection changes (e.g. onRowSelect, onSelectAll)
17
- * - Implement controlled state
18
- * - Implement auto-add checkbox to rows and header when selection is enabled
19
- *
20
- * @default "none"
21
- */
22
- selectionMode?: "none" | "single" | "multiple";
23
- selectedKeys?: SelectionT;
24
- defaultSelectedKeys?: SelectionT;
25
- onSelectionChange?: (keys: SelectionT) => void;
26
- disabledKeys?: (string | number)[];
27
- };
28
-
29
- type UseTableSelectionArgs = SelectionProps & {
30
- /* disallowEmptySelection?: boolean; */
31
- /* TODO: Support generics */
32
- data: (any & { id: string | number })[];
33
- };
34
-
35
- function useTableSelection({
36
- selectionMode,
37
- defaultSelectedKeys,
38
- selectedKeys: selectedKeysProp,
39
- onSelectionChange,
40
- disabledKeys = [],
41
- data,
42
- }: UseTableSelectionArgs) {
43
- const [selectedKeys, setSelectedKeys] = useControllableState({
44
- value: selectedKeysProp,
45
- defaultValue: defaultSelectedKeys ?? [],
46
- onChange: onSelectionChange,
47
- });
48
-
49
- const handleSelectionChange = (key: { value: string | number } | "all") => {
50
- if (selectionMode === "none") {
51
- return;
52
- }
53
-
54
- if (key === "all") {
55
- if (
56
- selectedKeys === "all" ||
57
- (Array.isArray(selectedKeys) && selectedKeys.length === data.length)
58
- ) {
59
- setSelectedKeys([]);
60
- } else {
61
- const allKeys = data.map((item) => item.id);
62
- setSelectedKeys(allKeys);
63
- }
64
- } else {
65
- const value = key.value;
66
- if (selectedKeys === "all") {
67
- setSelectedKeys(
68
- data.map((item) => item.id).filter((id) => id !== value),
69
- );
70
- } else if (Array.isArray(selectedKeys)) {
71
- if (selectedKeys.includes(value)) {
72
- setSelectedKeys(selectedKeys.filter((k) => k !== value));
73
- } else {
74
- setSelectedKeys([...selectedKeys, value]);
75
- }
76
- }
77
- }
78
- };
79
-
80
- if (selectionMode === "none") {
81
- return {
82
- selectedKeys: [],
83
- handleSelectionChange: () => {},
84
- selectionMode,
85
- disabledKeys,
86
- };
87
- }
88
-
89
- return {
90
- selectedKeys,
91
- handleSelectionChange,
92
- selectionMode,
93
- disabledKeys,
94
- getTheadCheckboxProps: () => {
95
- const indeterminate =
96
- Array.isArray(selectedKeys) &&
97
- selectedKeys.length > 0 &&
98
- selectedKeys.length < data.length;
99
-
100
- return {
101
- /* TODO: i18n */
102
- children: selectionMode === "single" ? "Select row" : "Select all rows",
103
- onChange: () => handleSelectionChange("all"),
104
- checked:
105
- (selectedKeys === "all" ||
106
- (Array.isArray(selectedKeys) && selectedKeys.length > 0)) &&
107
- !indeterminate,
108
- indeterminate,
109
- disabled: disabledKeys.length === data.length,
110
- hideLabel: true,
111
- };
112
- },
113
- getRowCheckboxProps: (key: string | number): CheckboxProps => ({
114
- children: `Select row with id ${key}`,
115
- onChange: () => handleSelectionChange({ value: key }),
116
- checked:
117
- selectedKeys === "all" ||
118
- (Array.isArray(selectedKeys) && selectedKeys.includes(key)),
119
- disabled: disabledKeys.includes(key),
120
- hideLabel: true,
121
- }),
122
- };
123
- }
124
-
125
- export { useTableSelection };
126
- export type { SelectionProps };