@navikt/ds-react 8.8.0 → 8.9.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/data/drag-and-drop/drag-handler/DragAndDropDragHandler.d.ts +12 -0
- package/cjs/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js +57 -0
- package/cjs/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js.map +1 -0
- package/cjs/data/drag-and-drop/item/DragAndDropItem.d.ts +27 -0
- package/cjs/data/drag-and-drop/item/DragAndDropItem.js +52 -0
- package/cjs/data/drag-and-drop/item/DragAndDropItem.js.map +1 -0
- package/cjs/data/drag-and-drop/root/DragAndDrop.context.d.ts +16 -0
- package/cjs/data/drag-and-drop/root/DragAndDrop.context.js +10 -0
- package/cjs/data/drag-and-drop/root/DragAndDrop.context.js.map +1 -0
- package/cjs/data/drag-and-drop/root/{DataDragAndDropRoot.d.ts → DragAndDropRoot.d.ts} +11 -9
- package/cjs/data/drag-and-drop/root/DragAndDropRoot.js +187 -0
- package/cjs/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -0
- package/cjs/data/drag-and-drop/types.d.ts +4 -0
- package/cjs/data/drag-and-drop/types.js +3 -0
- package/cjs/data/drag-and-drop/types.js.map +1 -0
- package/cjs/data/table/helpers/selection/getMultipleSelectProps.d.ts +14 -0
- package/cjs/data/table/helpers/selection/getMultipleSelectProps.js +48 -0
- package/cjs/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -0
- package/cjs/data/table/helpers/selection/getSingleSelectProps.d.ts +10 -0
- package/cjs/data/table/helpers/selection/getSingleSelectProps.js +23 -0
- package/cjs/data/table/helpers/selection/getSingleSelectProps.js.map +1 -0
- package/cjs/data/table/helpers/selection/selection.types.d.ts +42 -0
- package/cjs/data/table/helpers/selection/selection.types.js +3 -0
- package/cjs/data/table/helpers/selection/selection.types.js.map +1 -0
- package/cjs/data/table/{root → hooks}/useTableKeyboardNav.js +1 -1
- package/cjs/data/table/hooks/useTableKeyboardNav.js.map +1 -0
- package/cjs/data/table/hooks/useTableSelection.d.ts +8 -0
- package/cjs/data/table/hooks/useTableSelection.js +49 -0
- package/cjs/data/table/hooks/useTableSelection.js.map +1 -0
- package/cjs/data/table/root/DataTableAuto.d.ts +4 -4
- package/cjs/data/table/root/DataTableAuto.js +24 -10
- package/cjs/data/table/root/DataTableAuto.js.map +1 -1
- package/cjs/data/table/root/DataTableRoot.d.ts +1 -1
- package/cjs/data/table/root/DataTableRoot.js +1 -1
- package/cjs/data/table/root/DataTableRoot.js.map +1 -1
- package/cjs/data/token-filter/AutoSuggest.js +37 -4
- package/cjs/data/token-filter/AutoSuggest.js.map +1 -1
- package/cjs/data/token-filter/TokenFilter.d.ts +1 -0
- package/cjs/data/token-filter/TokenFilter.js +1 -0
- package/cjs/data/token-filter/TokenFilter.js.map +1 -1
- package/cjs/data/toolbar/root/DataToolbarRoot.d.ts +6 -23
- package/cjs/data/toolbar/root/DataToolbarRoot.js +42 -7
- package/cjs/data/toolbar/root/DataToolbarRoot.js.map +1 -1
- package/cjs/date/Date.Input.js +8 -9
- package/cjs/date/Date.Input.js.map +1 -1
- package/cjs/date/datepicker/hooks/useDatepicker.js +4 -3
- package/cjs/date/datepicker/hooks/useDatepicker.js.map +1 -1
- package/cjs/date/monthpicker/hooks/useMonthPicker.js +3 -2
- package/cjs/date/monthpicker/hooks/useMonthPicker.js.map +1 -1
- package/cjs/internal-header/InternalHeaderButton.d.ts +5 -0
- package/cjs/internal-header/InternalHeaderButton.js +2 -2
- package/cjs/internal-header/InternalHeaderButton.js.map +1 -1
- package/cjs/utils/components/Listbox/group/ListboxGroup.js +2 -1
- package/cjs/utils/components/Listbox/group/ListboxGroup.js.map +1 -1
- package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.d.ts +12 -0
- package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js +51 -0
- package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js.map +1 -0
- package/esm/data/drag-and-drop/item/DragAndDropItem.d.ts +27 -0
- package/esm/data/drag-and-drop/item/DragAndDropItem.js +46 -0
- package/esm/data/drag-and-drop/item/DragAndDropItem.js.map +1 -0
- package/esm/data/drag-and-drop/root/DragAndDrop.context.d.ts +16 -0
- package/esm/data/drag-and-drop/root/DragAndDrop.context.js +6 -0
- package/esm/data/drag-and-drop/root/DragAndDrop.context.js.map +1 -0
- package/esm/data/drag-and-drop/root/{DataDragAndDropRoot.d.ts → DragAndDropRoot.d.ts} +11 -9
- package/esm/data/drag-and-drop/root/DragAndDropRoot.js +147 -0
- package/esm/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -0
- package/esm/data/drag-and-drop/types.d.ts +4 -0
- package/esm/data/drag-and-drop/types.js +2 -0
- package/esm/data/drag-and-drop/types.js.map +1 -0
- package/esm/data/table/helpers/selection/getMultipleSelectProps.d.ts +14 -0
- package/esm/data/table/helpers/selection/getMultipleSelectProps.js +46 -0
- package/esm/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -0
- package/esm/data/table/helpers/selection/getSingleSelectProps.d.ts +10 -0
- package/esm/data/table/helpers/selection/getSingleSelectProps.js +21 -0
- package/esm/data/table/helpers/selection/getSingleSelectProps.js.map +1 -0
- package/esm/data/table/helpers/selection/selection.types.d.ts +42 -0
- package/esm/data/table/helpers/selection/selection.types.js +2 -0
- package/esm/data/table/helpers/selection/selection.types.js.map +1 -0
- package/esm/data/table/{root → hooks}/useTableKeyboardNav.js +1 -1
- package/esm/data/table/hooks/useTableKeyboardNav.js.map +1 -0
- package/esm/data/table/hooks/useTableSelection.d.ts +8 -0
- package/esm/data/table/hooks/useTableSelection.js +47 -0
- package/esm/data/table/hooks/useTableSelection.js.map +1 -0
- package/esm/data/table/root/DataTableAuto.d.ts +4 -4
- package/esm/data/table/root/DataTableAuto.js +24 -10
- package/esm/data/table/root/DataTableAuto.js.map +1 -1
- package/esm/data/table/root/DataTableRoot.d.ts +1 -1
- package/esm/data/table/root/DataTableRoot.js +1 -1
- package/esm/data/table/root/DataTableRoot.js.map +1 -1
- package/esm/data/token-filter/AutoSuggest.js +38 -5
- package/esm/data/token-filter/AutoSuggest.js.map +1 -1
- package/esm/data/token-filter/TokenFilter.d.ts +1 -0
- package/esm/data/token-filter/TokenFilter.js +1 -0
- package/esm/data/token-filter/TokenFilter.js.map +1 -1
- package/esm/data/toolbar/root/DataToolbarRoot.d.ts +6 -23
- package/esm/data/toolbar/root/DataToolbarRoot.js +9 -7
- package/esm/data/toolbar/root/DataToolbarRoot.js.map +1 -1
- package/esm/date/Date.Input.js +9 -10
- package/esm/date/Date.Input.js.map +1 -1
- package/esm/date/datepicker/hooks/useDatepicker.js +4 -3
- package/esm/date/datepicker/hooks/useDatepicker.js.map +1 -1
- package/esm/date/monthpicker/hooks/useMonthPicker.js +3 -2
- package/esm/date/monthpicker/hooks/useMonthPicker.js.map +1 -1
- package/esm/internal-header/InternalHeaderButton.d.ts +5 -0
- package/esm/internal-header/InternalHeaderButton.js +2 -2
- package/esm/internal-header/InternalHeaderButton.js.map +1 -1
- package/esm/utils/components/Listbox/group/ListboxGroup.js +2 -1
- package/esm/utils/components/Listbox/group/ListboxGroup.js.map +1 -1
- package/package.json +4 -4
- package/src/data/drag-and-drop/drag-handler/DragAndDropDragHandler.tsx +90 -0
- package/src/data/drag-and-drop/item/DragAndDropItem.tsx +71 -0
- package/src/data/drag-and-drop/root/DragAndDrop.context.tsx +25 -0
- package/src/data/drag-and-drop/root/DragAndDropRoot.tsx +245 -0
- package/src/data/drag-and-drop/types.ts +4 -0
- package/src/data/table/helpers/selection/getMultipleSelectProps.ts +70 -0
- package/src/data/table/helpers/selection/getSingleSelectProps.ts +33 -0
- package/src/data/table/helpers/selection/selection.types.ts +56 -0
- package/src/data/table/hooks/__tests__/useTableSelection.test.ts +327 -0
- package/src/data/table/{root → hooks}/useTableKeyboardNav.ts +1 -1
- package/src/data/table/hooks/useTableSelection.ts +78 -0
- package/src/data/table/root/DataTableAuto.tsx +46 -23
- package/src/data/table/root/DataTableRoot.tsx +2 -2
- package/src/data/token-filter/AutoSuggest.tsx +65 -3
- package/src/data/token-filter/TokenFilter.tsx +1 -0
- package/src/data/toolbar/root/DataToolbarRoot.tsx +29 -32
- package/src/date/Date.Input.tsx +17 -16
- package/src/date/datepicker/hooks/useDatepicker.tsx +4 -5
- package/src/date/monthpicker/hooks/useMonthPicker.tsx +3 -4
- package/src/internal-header/InternalHeaderButton.tsx +18 -9
- package/src/utils/components/Listbox/group/ListboxGroup.tsx +9 -2
- package/cjs/data/action-bar/root/DataActionBarRoot.d.ts +0 -27
- package/cjs/data/action-bar/root/DataActionBarRoot.js +0 -49
- package/cjs/data/action-bar/root/DataActionBarRoot.js.map +0 -1
- package/cjs/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.d.ts +0 -21
- package/cjs/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.js +0 -24
- package/cjs/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.js.map +0 -1
- package/cjs/data/drag-and-drop/item/DataDragAndDropItem.d.ts +0 -27
- package/cjs/data/drag-and-drop/item/DataDragAndDropItem.js +0 -41
- package/cjs/data/drag-and-drop/item/DataDragAndDropItem.js.map +0 -1
- package/cjs/data/drag-and-drop/root/DataDragAndDrop.context.d.ts +0 -8
- package/cjs/data/drag-and-drop/root/DataDragAndDrop.context.js +0 -10
- package/cjs/data/drag-and-drop/root/DataDragAndDrop.context.js.map +0 -1
- package/cjs/data/drag-and-drop/root/DataDragAndDropRoot.js +0 -61
- package/cjs/data/drag-and-drop/root/DataDragAndDropRoot.js.map +0 -1
- package/cjs/data/table/root/useTableKeyboardNav.js.map +0 -1
- package/cjs/data/table/root/useTableSelection.d.ts +0 -55
- package/cjs/data/table/root/useTableSelection.js +0 -79
- package/cjs/data/table/root/useTableSelection.js.map +0 -1
- package/esm/data/action-bar/root/DataActionBarRoot.d.ts +0 -27
- package/esm/data/action-bar/root/DataActionBarRoot.js +0 -43
- package/esm/data/action-bar/root/DataActionBarRoot.js.map +0 -1
- package/esm/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.d.ts +0 -21
- package/esm/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.js +0 -18
- package/esm/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.js.map +0 -1
- package/esm/data/drag-and-drop/item/DataDragAndDropItem.d.ts +0 -27
- package/esm/data/drag-and-drop/item/DataDragAndDropItem.js +0 -35
- package/esm/data/drag-and-drop/item/DataDragAndDropItem.js.map +0 -1
- package/esm/data/drag-and-drop/root/DataDragAndDrop.context.d.ts +0 -8
- package/esm/data/drag-and-drop/root/DataDragAndDrop.context.js +0 -6
- package/esm/data/drag-and-drop/root/DataDragAndDrop.context.js.map +0 -1
- package/esm/data/drag-and-drop/root/DataDragAndDropRoot.js +0 -21
- package/esm/data/drag-and-drop/root/DataDragAndDropRoot.js.map +0 -1
- package/esm/data/table/root/useTableKeyboardNav.js.map +0 -1
- package/esm/data/table/root/useTableSelection.d.ts +0 -55
- package/esm/data/table/root/useTableSelection.js +0 -77
- package/esm/data/table/root/useTableSelection.js.map +0 -1
- package/src/data/action-bar/root/DataActionBarRoot.tsx +0 -59
- package/src/data/drag-and-drop/drag-handler/DataDragAndDropDragHandler.tsx +0 -63
- package/src/data/drag-and-drop/item/DataDragAndDropItem.tsx +0 -54
- package/src/data/drag-and-drop/root/DataDragAndDrop.context.tsx +0 -14
- package/src/data/drag-and-drop/root/DataDragAndDropRoot.tsx +0 -54
- package/src/data/table/root/useTableSelection.ts +0 -126
- /package/cjs/data/table/{root → hooks}/useTableKeyboardNav.d.ts +0 -0
- /package/esm/data/table/{root → hooks}/useTableKeyboardNav.d.ts +0 -0
|
@@ -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 };
|
|
File without changes
|
|
File without changes
|