no-frills-ui 0.0.14-alpha.8 → 0.0.14-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.js +847 -718
- package/dist/index.js.map +1 -1
- package/lib-esm/components/Accordion/Accordion.d.ts +9 -13
- package/lib-esm/components/Accordion/Accordion.js +13 -11
- package/lib-esm/components/Accordion/Accordion.js.map +1 -1
- package/lib-esm/components/Accordion/AccordionStep.d.ts +22 -22
- package/lib-esm/components/Accordion/AccordionStep.js +34 -29
- package/lib-esm/components/Accordion/AccordionStep.js.map +1 -1
- package/lib-esm/components/Badge/Badge.d.ts +13 -16
- package/lib-esm/components/Badge/Badge.js +10 -20
- package/lib-esm/components/Badge/Badge.js.map +1 -1
- package/lib-esm/components/Button/ActionButton.d.ts +9 -5
- package/lib-esm/components/Button/ActionButton.js +18 -3
- package/lib-esm/components/Button/ActionButton.js.map +1 -1
- package/lib-esm/components/Button/Button.d.ts +9 -5
- package/lib-esm/components/Button/Button.js +17 -5
- package/lib-esm/components/Button/Button.js.map +1 -1
- package/lib-esm/components/Button/IconButton.d.ts +9 -5
- package/lib-esm/components/Button/IconButton.js +18 -3
- package/lib-esm/components/Button/IconButton.js.map +1 -1
- package/lib-esm/components/Button/LinkButton.d.ts +9 -5
- package/lib-esm/components/Button/LinkButton.js +18 -3
- package/lib-esm/components/Button/LinkButton.js.map +1 -1
- package/lib-esm/components/Button/RaisedButton.d.ts +9 -5
- package/lib-esm/components/Button/RaisedButton.js +18 -3
- package/lib-esm/components/Button/RaisedButton.js.map +1 -1
- package/lib-esm/components/Card/Card.d.ts +4 -6
- package/lib-esm/components/Card/Card.js +16 -3
- package/lib-esm/components/Card/Card.js.map +1 -1
- package/lib-esm/components/Chip/Chip.d.ts +2 -2
- package/lib-esm/components/Chip/Chip.js +14 -8
- package/lib-esm/components/Chip/Chip.js.map +1 -1
- package/lib-esm/components/ChipInput/ChipInput.d.ts +28 -39
- package/lib-esm/components/ChipInput/ChipInput.js +37 -37
- package/lib-esm/components/ChipInput/ChipInput.js.map +1 -1
- package/lib-esm/components/Dialog/AlertDialog.d.ts +11 -12
- package/lib-esm/components/Dialog/AlertDialog.js +4 -11
- package/lib-esm/components/Dialog/AlertDialog.js.map +1 -1
- package/lib-esm/components/Dialog/ConfirmDialog.d.ts +13 -14
- package/lib-esm/components/Dialog/ConfirmDialog.js +4 -12
- package/lib-esm/components/Dialog/ConfirmDialog.js.map +1 -1
- package/lib-esm/components/Dialog/Dialog.d.ts +8 -14
- package/lib-esm/components/Dialog/Dialog.js +11 -9
- package/lib-esm/components/Dialog/Dialog.js.map +1 -1
- package/lib-esm/components/Dialog/PromptDialog.d.ts +18 -19
- package/lib-esm/components/Dialog/PromptDialog.js +10 -18
- package/lib-esm/components/Dialog/PromptDialog.js.map +1 -1
- package/lib-esm/components/DragAndDrop/DragAndDrop.d.ts +37 -59
- package/lib-esm/components/DragAndDrop/DragAndDrop.js +23 -26
- package/lib-esm/components/DragAndDrop/DragAndDrop.js.map +1 -1
- package/lib-esm/components/DragAndDrop/DragItem.d.ts +2 -2
- package/lib-esm/components/DragAndDrop/DragItem.js +40 -38
- package/lib-esm/components/DragAndDrop/DragItem.js.map +1 -1
- package/lib-esm/components/DragAndDrop/types.d.ts +3 -3
- package/lib-esm/components/DragAndDrop/types.js.map +1 -1
- package/lib-esm/components/Drawer/Drawer.d.ts +24 -31
- package/lib-esm/components/Drawer/Drawer.js +49 -45
- package/lib-esm/components/Drawer/Drawer.js.map +1 -1
- package/lib-esm/components/Groups/Group.d.ts +6 -8
- package/lib-esm/components/Groups/Group.js +12 -10
- package/lib-esm/components/Groups/Group.js.map +1 -1
- package/lib-esm/components/Input/Checkbox.d.ts +12 -15
- package/lib-esm/components/Input/Checkbox.js +30 -26
- package/lib-esm/components/Input/Checkbox.js.map +1 -1
- package/lib-esm/components/Input/Dropdown.d.ts +8 -18
- package/lib-esm/components/Input/Dropdown.js +42 -17
- package/lib-esm/components/Input/Dropdown.js.map +1 -1
- package/lib-esm/components/Input/Input.d.ts +8 -3
- package/lib-esm/components/Input/Input.js +20 -19
- package/lib-esm/components/Input/Input.js.map +1 -1
- package/lib-esm/components/Input/Radio.d.ts +4 -8
- package/lib-esm/components/Input/Radio.js +16 -13
- package/lib-esm/components/Input/Radio.js.map +1 -1
- package/lib-esm/components/Input/RadioButton.d.ts +4 -8
- package/lib-esm/components/Input/RadioButton.js +15 -12
- package/lib-esm/components/Input/RadioButton.js.map +1 -1
- package/lib-esm/components/Input/Select.d.ts +6 -13
- package/lib-esm/components/Input/Select.js +21 -18
- package/lib-esm/components/Input/Select.js.map +1 -1
- package/lib-esm/components/Input/TextArea.d.ts +6 -13
- package/lib-esm/components/Input/TextArea.js +29 -24
- package/lib-esm/components/Input/TextArea.js.map +1 -1
- package/lib-esm/components/Input/Toggle.d.ts +4 -9
- package/lib-esm/components/Input/Toggle.js +12 -10
- package/lib-esm/components/Input/Toggle.js.map +1 -1
- package/lib-esm/components/Menu/Menu.d.ts +4 -14
- package/lib-esm/components/Menu/Menu.js +24 -16
- package/lib-esm/components/Menu/Menu.js.map +1 -1
- package/lib-esm/components/Menu/MenuContext.d.ts +4 -4
- package/lib-esm/components/Menu/MenuContext.js +1 -0
- package/lib-esm/components/Menu/MenuContext.js.map +1 -1
- package/lib-esm/components/Menu/MenuItem.d.ts +10 -4
- package/lib-esm/components/Menu/MenuItem.js +19 -5
- package/lib-esm/components/Menu/MenuItem.js.map +1 -1
- package/lib-esm/components/Modal/Modal.d.ts +17 -23
- package/lib-esm/components/Modal/Modal.js +37 -34
- package/lib-esm/components/Modal/Modal.js.map +1 -1
- package/lib-esm/components/Notification/Notification.d.ts +39 -34
- package/lib-esm/components/Notification/Notification.js +16 -39
- package/lib-esm/components/Notification/Notification.js.map +1 -1
- package/lib-esm/components/Notification/NotificationManager.d.ts +4 -4
- package/lib-esm/components/Notification/NotificationManager.js +18 -14
- package/lib-esm/components/Notification/NotificationManager.js.map +1 -1
- package/lib-esm/components/Notification/index.d.ts +1 -0
- package/lib-esm/components/Notification/style.d.ts +2 -3
- package/lib-esm/components/Notification/style.js +11 -11
- package/lib-esm/components/Notification/style.js.map +1 -1
- package/lib-esm/components/Popover/Popover.d.ts +21 -20
- package/lib-esm/components/Popover/Popover.js +42 -44
- package/lib-esm/components/Popover/Popover.js.map +1 -1
- package/lib-esm/components/Spinner/Spinner.d.ts +14 -15
- package/lib-esm/components/Spinner/Spinner.js +12 -13
- package/lib-esm/components/Spinner/Spinner.js.map +1 -1
- package/lib-esm/components/Stepper/Step.d.ts +15 -12
- package/lib-esm/components/Stepper/Step.js +10 -8
- package/lib-esm/components/Stepper/Step.js.map +1 -1
- package/lib-esm/components/Stepper/Stepper.d.ts +11 -17
- package/lib-esm/components/Stepper/Stepper.js +25 -23
- package/lib-esm/components/Stepper/Stepper.js.map +1 -1
- package/lib-esm/components/Tabs/Tab.d.ts +10 -16
- package/lib-esm/components/Tabs/Tab.js +0 -8
- package/lib-esm/components/Tabs/Tab.js.map +1 -1
- package/lib-esm/components/Tabs/Tabs.d.ts +11 -22
- package/lib-esm/components/Tabs/Tabs.js +39 -31
- package/lib-esm/components/Tabs/Tabs.js.map +1 -1
- package/lib-esm/components/Toast/Toast.d.ts +7 -7
- package/lib-esm/components/Toast/Toast.js +13 -12
- package/lib-esm/components/Toast/Toast.js.map +1 -1
- package/lib-esm/components/Toast/ToastStory.d.ts +21 -24
- package/lib-esm/components/Tooltip/Tooltip.d.ts +11 -14
- package/lib-esm/components/Tooltip/Tooltip.js +11 -21
- package/lib-esm/components/Tooltip/Tooltip.js.map +1 -1
- package/lib-esm/icons/CheckCircle.js +2 -2
- package/lib-esm/icons/CheckCircle.js.map +1 -1
- package/lib-esm/icons/ErrorOutline.js +2 -2
- package/lib-esm/icons/ErrorOutline.js.map +1 -1
- package/lib-esm/icons/Info.js +2 -2
- package/lib-esm/icons/Info.js.map +1 -1
- package/lib-esm/icons/ReportProblem.js +2 -2
- package/lib-esm/icons/ReportProblem.js.map +1 -1
- package/lib-esm/index.js +43 -0
- package/lib-esm/shared/LayerManager.d.ts +5 -4
- package/lib-esm/shared/LayerManager.js +111 -111
- package/lib-esm/shared/LayerManager.js.map +1 -1
- package/lib-esm/shared/styles.d.ts +1 -1
- package/lib-esm/shared/styles.js +9 -9
- package/lib-esm/shared/styles.js.map +1 -1
- package/package.json +66 -31
- package/lib-esm/components/index.js +0 -43
- /package/lib-esm/{components/index.js.map → index.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PromptDialog.js","sources":["../../../src/components/Dialog/PromptDialog.tsx"],"sourcesContent":["import React, { createRef } from 'react';\nimport
|
|
1
|
+
{"version":3,"file":"PromptDialog.js","sources":["../../../src/components/Dialog/PromptDialog.tsx"],"sourcesContent":["import React, { createRef } from 'react';\nimport styled from '@emotion/styled';\nimport { Button, ActionButton } from '../Button';\nimport { Input } from '../Input';\nimport Dialog, { DialogHeader, DialogBody, DialogFooter } from './Dialog';\n\ntype PromptOption = {\n /** Shown as header of the dialog */\n header: string;\n /** Rendered as the body of the dialog */\n body: string;\n /** Default value for the input. */\n defaultValue?: string;\n /** Submit button text. Default value is 'Submit' */\n submitText?: string;\n /** Cancel button text. Default value is 'Cancel' */\n cancelText?: string;\n /** Props for the input. */\n inputProps?: React.HTMLProps<HTMLInputElement>;\n /** Additional props for the dialog. */\n dialogProps?: React.ComponentProps<typeof Dialog>;\n};\n\nconst BodyText = styled.p`\n margin-top: 0;\n`;\n\nconst InputContainer = styled.div`\n display: flex;\n flex: 1;\n margin-top: 10px;\n\n & > label {\n flex: 1;\n width: 100%;\n padding: 0;\n\n & > input {\n width: 100%;\n padding: 0 8px;\n box-sizing: border-box;\n }\n }\n`;\n\nconst StyledInput = styled(Input)`\n flex: 1;\n padding: 0;\n`;\n\nexport default class PromptDialog extends React.Component<PromptOption, { value?: string }> {\n static defaultProps = {\n cancelText: 'Cancel',\n submitText: 'Submit',\n defaultValue: '',\n };\n\n constructor(props: PromptOption) {\n super(props);\n this.state = {\n value: props.defaultValue,\n };\n }\n\n private dialog = createRef<Dialog>();\n\n private valueChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n this.setState({\n value: e.target.value,\n });\n };\n\n private cancel = () => this.dialog.current?.close();\n\n private submit = (e: React.SyntheticEvent) => {\n e.preventDefault();\n if (!this.state.value) return;\n this.dialog.current?.close(this.state.value);\n };\n\n public show = () => {\n return new Promise((resolve, reject) => {\n const onClose = (value: unknown) => {\n if (value) {\n resolve(value);\n } else {\n reject();\n }\n this.setState({\n value: this.props.defaultValue,\n });\n };\n this.dialog.current?.open(onClose);\n });\n };\n\n render() {\n const { header, body, inputProps, submitText, cancelText, dialogProps } = this.props;\n\n return (\n <Dialog\n {...dialogProps}\n ref={this.dialog}\n closeOnEsc={false}\n closeOnOverlayClick={false}\n >\n <form onSubmit={this.submit}>\n {header && <DialogHeader>{header}</DialogHeader>}\n <DialogBody>\n <BodyText>{body}</BodyText>\n <InputContainer>\n <StyledInput\n value={this.state.value}\n onChange={this.valueChange}\n {...inputProps}\n />\n </InputContainer>\n </DialogBody>\n <DialogFooter>\n <Button type=\"button\" onClick={this.cancel}>\n {cancelText}\n </Button>\n <ActionButton onClick={this.submit}>{submitText}</ActionButton>\n </DialogFooter>\n </form>\n </Dialog>\n );\n }\n}\n"],"names":["BodyText","styled","InputContainer","StyledInput","Input","PromptDialog","React","Component","render","header","body","inputProps","submitText","cancelText","dialogProps","props","_jsx","Dialog","ref","dialog","closeOnEsc","closeOnOverlayClick","_jsxs","form","onSubmit","submit","DialogHeader","DialogBody","value","state","onChange","valueChange","DialogFooter","Button","type","onClick","cancel","ActionButton","createRef","e","setState","target","current","close","preventDefault","show","Promise","resolve","reject","onClose","defaultValue","open","defaultProps"],"mappings":";;;;;;;;;AAuBA,MAAMA,QAAAA,iBAAWC,MAAAA,CAAAA,GAAAA,EAAAA;;;;AAIjB,MAAMC,cAAAA,iBAAiBD,MAAAA,CAAAA,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AA,EAAOb,MAAMmC;AACjB,SAAA;AACJ,IAAA;AAkEJ;AA9EqB7C,YAAAA,CACV+C,YAAAA,GAAe;IAClBvC,UAAAA,EAAY,QAAA;IACZD,UAAAA,EAAY,QAAA;IACZsC,YAAAA,EAAc;AAClB,CAAA;;;;"}
|
|
@@ -1,69 +1,47 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { ORIENTATION } from './types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
|
|
3
|
+
declare const DragAndDrop: React.ForwardRefExoticComponent<{
|
|
4
|
+
/**
|
|
5
|
+
* Orientation of the list layout
|
|
6
|
+
* @default ORIENTATION.VERTICAL
|
|
7
|
+
*/
|
|
8
|
+
orientation?: ORIENTATION;
|
|
6
9
|
/** Drop event handler */
|
|
7
10
|
onDrop: (start: number, end: number) => void;
|
|
8
|
-
/** Shows drag indicator against each list item
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
/** Shows drag indicator against each list item
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
showIndicator?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* i18n: Template for item aria-label. Placeholders: {:position}, {:grabKey}, {:moveKeys}, {:dropKey}, {:altDropKey}
|
|
17
|
+
* @default 'Item {:position}. Press {:grabKey} to grab, {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop'
|
|
18
|
+
*/
|
|
11
19
|
itemAriaLabelTemplate?: string;
|
|
12
|
-
/** i18n: Aria label for drag handle
|
|
20
|
+
/** i18n: Aria label for drag handle
|
|
21
|
+
* @default 'Drag to reorder'
|
|
22
|
+
*/
|
|
13
23
|
dragHandleAriaLabel?: string;
|
|
14
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* i18n: Template for grabbed announcement. Placeholders: {:position}, {:moveKeys}, {:dropKey}, {:altDropKey}, {:cancelKey}
|
|
26
|
+
* @default 'Item {:position} grabbed. Use {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop, {:cancelKey} to cancel'
|
|
27
|
+
*/
|
|
15
28
|
grabbedAnnouncementTemplate?: string;
|
|
16
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* i18n: Template for moved announcement. Placeholders: {:position}
|
|
31
|
+
* @default 'Item moved to position {:position}'
|
|
32
|
+
*/
|
|
17
33
|
movedAnnouncementTemplate?: string;
|
|
18
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* i18n: Template for dropped announcement. Placeholders: {:position}
|
|
36
|
+
* @default 'Item dropped at position {:position}'
|
|
37
|
+
*/
|
|
19
38
|
droppedAnnouncementTemplate?: string;
|
|
20
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* i18n: Template for cancelled announcement
|
|
41
|
+
* @default 'Drag cancelled, item restored to original position'
|
|
42
|
+
*/
|
|
21
43
|
cancelledAnnouncementTemplate?: string;
|
|
22
|
-
} &
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
* @component
|
|
27
|
-
* @example
|
|
28
|
-
* ```tsx
|
|
29
|
-
* <DragAndDrop
|
|
30
|
-
* orientation={ORIENTATION.VERTICAL}
|
|
31
|
-
* onDrop={(start, end) => handleReorder(start, end)}
|
|
32
|
-
* showIndicator={true}
|
|
33
|
-
* >
|
|
34
|
-
* <div>Item 1</div>
|
|
35
|
-
* <div>Item 2</div>
|
|
36
|
-
* <div>Item 3</div>
|
|
37
|
-
* </DragAndDrop>
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @param {DragAndDropProps} props - The component props
|
|
41
|
-
* @param {ORIENTATION} props.orientation - Determines the layout direction (horizontal or vertical). Defaults to VERTICAL.
|
|
42
|
-
* @param {(start: number, end: number) => void} props.onDrop - Callback fired when an item is dropped, receives the start and end indices
|
|
43
|
-
* @param {boolean} props.showIndicator - Whether to display drag indicators for each list item. Defaults to false.
|
|
44
|
-
* @param {React.ReactNode} props.children - Child elements to be rendered as draggable items
|
|
45
|
-
*
|
|
46
|
-
* @returns {JSX.Element} A draggable container with reorderable items
|
|
47
|
-
*/
|
|
48
|
-
declare function DragAndDrop(props: DragAndDropProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
49
|
-
declare namespace DragAndDrop {
|
|
50
|
-
var defaultProps: {
|
|
51
|
-
/** Orientation of the list layout */
|
|
52
|
-
orientation: ORIENTATION;
|
|
53
|
-
/** Whether to display drag indicators for each list item */
|
|
54
|
-
showIndicator: boolean;
|
|
55
|
-
/** Default item aria-label template */
|
|
56
|
-
itemAriaLabelTemplate: string;
|
|
57
|
-
/** Default drag handle aria-label */
|
|
58
|
-
dragHandleAriaLabel: string;
|
|
59
|
-
/** Default grabbed announcement template */
|
|
60
|
-
grabbedAnnouncementTemplate: string;
|
|
61
|
-
/** Default moved announcement template */
|
|
62
|
-
movedAnnouncementTemplate: string;
|
|
63
|
-
/** Default dropped announcement template */
|
|
64
|
-
droppedAnnouncementTemplate: string;
|
|
65
|
-
/** Default cancelled announcement template */
|
|
66
|
-
cancelledAnnouncementTemplate: string;
|
|
67
|
-
};
|
|
68
|
-
}
|
|
44
|
+
} & {
|
|
45
|
+
children?: React.ReactNode | undefined;
|
|
46
|
+
} & React.RefAttributes<HTMLDivElement>>;
|
|
69
47
|
export default DragAndDrop;
|
|
@@ -2,14 +2,14 @@ import { jsxs, Fragment, jsx } from '@emotion/react/jsx-runtime';
|
|
|
2
2
|
import React, { useState } from 'react';
|
|
3
3
|
import styled from '@emotion/styled';
|
|
4
4
|
import DragItem from './DragItem.js';
|
|
5
|
-
import {
|
|
5
|
+
import { ORIENTATION, DragContext } from './types.js';
|
|
6
6
|
|
|
7
|
-
/** Container Component */ const Container = /*#__PURE__*/ styled("div", {
|
|
8
|
-
target: "
|
|
7
|
+
/** Container Component */ const Container$6 = /*#__PURE__*/ styled("div", {
|
|
8
|
+
target: "e18d6tqk0",
|
|
9
9
|
label: "Container"
|
|
10
10
|
})("flex:1;display:flex;position:relative;flex-wrap:wrap;flex-direction:", (props)=>props.orientation === ORIENTATION.HORIZONTAL ? 'row' : 'column', ";");
|
|
11
|
-
/** Visually hidden but accessible to screen readers */ const VisuallyHidden = /*#__PURE__*/ styled("div", {
|
|
12
|
-
target: "
|
|
11
|
+
/** Visually hidden but accessible to screen readers */ const VisuallyHidden$2 = /*#__PURE__*/ styled("div", {
|
|
12
|
+
target: "e18d6tqk1",
|
|
13
13
|
label: "VisuallyHidden"
|
|
14
14
|
})("position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0;");
|
|
15
15
|
/**
|
|
@@ -29,15 +29,19 @@ import { DragContext, ORIENTATION } from './types.js';
|
|
|
29
29
|
* </DragAndDrop>
|
|
30
30
|
* ```
|
|
31
31
|
*
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
32
|
+
* @param props - The component props
|
|
33
|
+
* @param props.orientation - Determines the layout direction (horizontal or vertical). Defaults to VERTICAL.
|
|
34
|
+
* @param props.onDrop - Callback fired when an item is dropped, receives the start and end indices
|
|
35
|
+
* @param props.showIndicator - Whether to display drag indicators for each list item. Defaults to false.
|
|
36
|
+
* @param props.children - Child elements to be rendered as draggable items
|
|
37
37
|
*
|
|
38
|
-
* @returns
|
|
39
|
-
*/
|
|
40
|
-
|
|
38
|
+
* @returns A draggable container with reorderable items
|
|
39
|
+
*/ /**
|
|
40
|
+
* DragAndDrop Component
|
|
41
|
+
* @param props - Component props
|
|
42
|
+
* @param ref - Ref forwarded to the underlying HTMLDivElement
|
|
43
|
+
*/ function DragAndDropComponent(props, ref) {
|
|
44
|
+
const { orientation = ORIENTATION.VERTICAL, children, onDrop, showIndicator = false, itemAriaLabelTemplate = 'Item {:position}. Press {:grabKey} to grab, {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop', dragHandleAriaLabel = 'Drag to reorder', grabbedAnnouncementTemplate = 'Item {:position} grabbed. Use {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop, {:cancelKey} to cancel', movedAnnouncementTemplate = 'Item moved to position {:position}', droppedAnnouncementTemplate = 'Item dropped at position {:position}', cancelledAnnouncementTemplate = 'Drag cancelled, item restored to original position', ...rest } = props;
|
|
41
45
|
const [startIndex, setStartIndex] = useState(null);
|
|
42
46
|
const [originalIndex, setOriginalIndex] = useState(null);
|
|
43
47
|
const [isDragging, setIsDragging] = useState(false);
|
|
@@ -64,7 +68,7 @@ import { DragContext, ORIENTATION } from './types.js';
|
|
|
64
68
|
* Drop handler invoked when a draggable item is released.
|
|
65
69
|
* @param index
|
|
66
70
|
*/ const drop = (index)=>{
|
|
67
|
-
if (startIndex !== null) {
|
|
71
|
+
if (startIndex !== null && index !== null) {
|
|
68
72
|
onDrop?.(startIndex, index);
|
|
69
73
|
}
|
|
70
74
|
setStartIndex(null);
|
|
@@ -103,7 +107,9 @@ import { DragContext, ORIENTATION } from './types.js';
|
|
|
103
107
|
setDragOver,
|
|
104
108
|
i18n
|
|
105
109
|
},
|
|
106
|
-
children: /*#__PURE__*/ jsx(Container, {
|
|
110
|
+
children: /*#__PURE__*/ jsx(Container$6, {
|
|
111
|
+
...rest,
|
|
112
|
+
ref: ref,
|
|
107
113
|
orientation: orientation,
|
|
108
114
|
role: "list",
|
|
109
115
|
children: React.Children.map(childrenArray, (child, index)=>/*#__PURE__*/ jsx(DragItem, {
|
|
@@ -117,7 +123,7 @@ import { DragContext, ORIENTATION } from './types.js';
|
|
|
117
123
|
}))
|
|
118
124
|
})
|
|
119
125
|
}),
|
|
120
|
-
/*#__PURE__*/ jsx(VisuallyHidden, {
|
|
126
|
+
/*#__PURE__*/ jsx(VisuallyHidden$2, {
|
|
121
127
|
role: "status",
|
|
122
128
|
"aria-live": "polite",
|
|
123
129
|
"aria-atomic": "true",
|
|
@@ -126,16 +132,7 @@ import { DragContext, ORIENTATION } from './types.js';
|
|
|
126
132
|
]
|
|
127
133
|
});
|
|
128
134
|
}
|
|
129
|
-
DragAndDrop
|
|
130
|
-
/** Orientation of the list layout */ orientation: ORIENTATION.VERTICAL,
|
|
131
|
-
/** Whether to display drag indicators for each list item */ showIndicator: false,
|
|
132
|
-
/** Default item aria-label template */ itemAriaLabelTemplate: 'Item {:position}. Press {:grabKey} to grab, {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop',
|
|
133
|
-
/** Default drag handle aria-label */ dragHandleAriaLabel: 'Drag to reorder',
|
|
134
|
-
/** Default grabbed announcement template */ grabbedAnnouncementTemplate: 'Item {:position} grabbed. Use {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop, {:cancelKey} to cancel',
|
|
135
|
-
/** Default moved announcement template */ movedAnnouncementTemplate: 'Item moved to position {:position}',
|
|
136
|
-
/** Default dropped announcement template */ droppedAnnouncementTemplate: 'Item dropped at position {:position}',
|
|
137
|
-
/** Default cancelled announcement template */ cancelledAnnouncementTemplate: 'Drag cancelled, item restored to original position'
|
|
138
|
-
};
|
|
135
|
+
const DragAndDrop = /*#__PURE__*/ React.forwardRef(DragAndDropComponent);
|
|
139
136
|
|
|
140
137
|
export { DragAndDrop as default };
|
|
141
138
|
//# sourceMappingURL=DragAndDrop.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DragAndDrop.js","sources":["../../../src/components/DragAndDrop/DragAndDrop.tsx"],"sourcesContent":["import React, { PropsWithChildren, useState } from 'react';\nimport styled from '@emotion/styled';\nimport DragItem from './DragItem';\nimport { ORIENTATION, DragContext } from './types';\n\ntype DragAndDropProps = {\n /** Orientation of the list layout */\n orientation: ORIENTATION;\n /** Drop event handler */\n onDrop: (start: number, end: number) => void;\n /** Shows drag indicator against each list item */\n showIndicator: boolean;\n /** i18n: Template for item aria-label. Placeholders: {:position}, {:grabKey}, {:moveKeys}, {:dropKey}, {:altDropKey} */\n itemAriaLabelTemplate?: string;\n /** i18n: Aria label for drag handle */\n dragHandleAriaLabel?: string;\n /** i18n: Template for grabbed announcement. Placeholders: {:position}, {:moveKeys}, {:dropKey}, {:altDropKey}, {:cancelKey} */\n grabbedAnnouncementTemplate?: string;\n /** i18n: Template for moved announcement. Placeholders: {:position} */\n movedAnnouncementTemplate?: string;\n /** i18n: Template for dropped announcement. Placeholders: {:position} */\n droppedAnnouncementTemplate?: string;\n /** i18n: Template for cancelled announcement */\n cancelledAnnouncementTemplate?: string;\n} & PropsWithChildren<unknown>;\n\n/** Container Component */\nconst Container = styled.div<{ orientation: ORIENTATION }>`\n flex: 1;\n display: flex;\n position: relative;\n flex-wrap: wrap;\n flex-direction: ${(props) => (props.orientation === ORIENTATION.HORIZONTAL ? 'row' : 'column')};\n`;\n\n/** Visually hidden but accessible to screen readers */\nconst VisuallyHidden = styled.div`\n position: absolute;\n width: 1px;\n height: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border-width: 0;\n`;\n\n/**\n * A drag and drop container component that enables reordering of child elements.\n *\n * @component\n * @example\n * ```tsx\n * <DragAndDrop\n * orientation={ORIENTATION.VERTICAL}\n * onDrop={(start, end) => handleReorder(start, end)}\n * showIndicator={true}\n * >\n * <div>Item 1</div>\n * <div>Item 2</div>\n * <div>Item 3</div>\n * </DragAndDrop>\n * ```\n *\n * @param {DragAndDropProps} props - The component props\n * @param {ORIENTATION} props.orientation - Determines the layout direction (horizontal or vertical). Defaults to VERTICAL.\n * @param {(start: number, end: number) => void} props.onDrop - Callback fired when an item is dropped, receives the start and end indices\n * @param {boolean} props.showIndicator - Whether to display drag indicators for each list item. Defaults to false.\n * @param {React.ReactNode} props.children - Child elements to be rendered as draggable items\n *\n * @returns {JSX.Element} A draggable container with reorderable items\n */\nexport default function DragAndDrop(props: DragAndDropProps) {\n const {\n orientation,\n children,\n onDrop,\n showIndicator,\n itemAriaLabelTemplate,\n dragHandleAriaLabel,\n grabbedAnnouncementTemplate,\n movedAnnouncementTemplate,\n droppedAnnouncementTemplate,\n cancelledAnnouncementTemplate,\n } = props;\n const [startIndex, setStartIndex] = useState<number>(null);\n const [originalIndex, setOriginalIndex] = useState<number>(null);\n const [isDragging, setIsDragging] = useState<boolean>(false);\n const [dragOver, setDragOver] = useState<number>(null);\n const [announcement, setAnnouncement] = useState('');\n const childrenArray = React.Children.toArray(children);\n const totalItems = childrenArray.length;\n\n /**\n * Replace placeholders in i18n templates\n */\n const replacePlaceholders = (\n template: string,\n data: {\n position?: number;\n grabKey?: string;\n dropKey?: string;\n altDropKey?: string;\n cancelKey?: string;\n moveKeys?: string;\n },\n ): string => {\n return template\n .replace(/\\{:position\\}/g, String(data.position ?? ''))\n .replace(/\\{:grabKey\\}/g, data.grabKey ?? 'Space')\n .replace(/\\{:dropKey\\}/g, data.dropKey ?? 'Space')\n .replace(/\\{:altDropKey\\}/g, data.altDropKey ?? 'Enter')\n .replace(/\\{:cancelKey\\}/g, data.cancelKey ?? 'Escape')\n .replace(\n /\\{:moveKeys\\}/g,\n data.moveKeys ??\n (orientation === ORIENTATION.VERTICAL ? 'Arrow Up/Down' : 'Arrow Left/Right'),\n );\n };\n\n // i18n configuration object\n const i18n = {\n itemAriaLabelTemplate:\n itemAriaLabelTemplate ??\n 'Item {:position}. Press {:grabKey} to grab, {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop',\n dragHandleAriaLabel: dragHandleAriaLabel ?? 'Drag to reorder',\n grabbedAnnouncementTemplate:\n grabbedAnnouncementTemplate ??\n 'Item {:position} grabbed. Use {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop, {:cancelKey} to cancel',\n movedAnnouncementTemplate:\n movedAnnouncementTemplate ?? 'Item moved to position {:position}',\n droppedAnnouncementTemplate:\n droppedAnnouncementTemplate ?? 'Item dropped at position {:position}',\n cancelledAnnouncementTemplate:\n cancelledAnnouncementTemplate ?? 'Drag cancelled, item restored to original position',\n replacePlaceholders,\n };\n\n /**\n * Drop handler invoked when a draggable item is released.\n * @param index\n */\n const drop = (index: number) => {\n if (startIndex !== null) {\n onDrop?.(startIndex, index);\n }\n setStartIndex(null);\n setOriginalIndex(null);\n setIsDragging(false);\n };\n\n /**\n * Cancel handler to restore item to original position\n */\n const cancel = () => {\n if (originalIndex !== null && startIndex !== null && startIndex !== originalIndex) {\n onDrop?.(startIndex, originalIndex);\n }\n setStartIndex(null);\n setOriginalIndex(null);\n setIsDragging(false);\n };\n\n /**\n * Start grab handler to track original position\n */\n const startGrab = (index: number) => {\n setStartIndex(index);\n setOriginalIndex(index);\n setIsDragging(true);\n };\n\n return (\n <>\n <DragContext.Provider\n value={{\n startIndex,\n setStartIndex,\n drop,\n onDrop,\n cancel,\n startGrab,\n isDragging,\n setIsDragging,\n setDragOver,\n i18n,\n }}\n >\n <Container orientation={orientation} role=\"list\">\n {React.Children.map(childrenArray, (child, index) => (\n <DragItem\n index={index}\n orientation={orientation}\n showIndicator={showIndicator}\n dragOver={dragOver}\n totalItems={totalItems}\n setAnnouncement={setAnnouncement}\n >\n {child}\n </DragItem>\n ))}\n </Container>\n </DragContext.Provider>\n <VisuallyHidden role=\"status\" aria-live=\"polite\" aria-atomic=\"true\">\n {announcement}\n </VisuallyHidden>\n </>\n );\n}\n\nDragAndDrop.defaultProps = {\n /** Orientation of the list layout */\n orientation: ORIENTATION.VERTICAL,\n /** Whether to display drag indicators for each list item */\n showIndicator: false,\n /** Default item aria-label template */\n itemAriaLabelTemplate:\n 'Item {:position}. Press {:grabKey} to grab, {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop',\n /** Default drag handle aria-label */\n dragHandleAriaLabel: 'Drag to reorder',\n /** Default grabbed announcement template */\n grabbedAnnouncementTemplate:\n 'Item {:position} grabbed. Use {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop, {:cancelKey} to cancel',\n /** Default moved announcement template */\n movedAnnouncementTemplate: 'Item moved to position {:position}',\n /** Default dropped announcement template */\n droppedAnnouncementTemplate: 'Item dropped at position {:position}',\n /** Default cancelled announcement template */\n cancelledAnnouncementTemplate: 'Drag cancelled, item restored to original position',\n};\n"],"names":["Container","styled","props","orientation","ORIENTATION","HORIZONTAL","VisuallyHidden","DragAndDrop","children","onDrop","showIndicator","itemAriaLabelTemplate","dragHandleAriaLabel","grabbedAnnouncementTemplate","movedAnnouncementTemplate","droppedAnnouncementTemplate","cancelledAnnouncementTemplate","startIndex","setStartIndex","useState","originalIndex","setOriginalIndex","isDragging","setIsDragging","dragOver","setDragOver","announcement","setAnnouncement","childrenArray","React","Children","toArray","totalItems","length","replacePlaceholders","template","data","replace","String","position","grabKey","dropKey","altDropKey","cancelKey","moveKeys","VERTICAL","i18n","drop","index","cancel","startGrab","_jsxs","_Fragment","_jsx","DragContext","Provider","value","role","map","child","DragItem","aria-live","aria-atomic","defaultProps"],"mappings":";;;;;;AA0BA,2BACA,MAAMA,SAAAA,iBAAYC,MAAAA,CAAAA,KAAAA,EAAAA;;;AAKI,CAAA,CAAA,CAAA,sEAAA,EAAA,CAACC,QAAWA,KAAAA,CAAMC,WAAW,KAAKC,WAAAA,CAAYC,UAAU,GAAG,KAAA,GAAQ,QAAA,EAAA,GAAA,CAAA;AAGzF,wDACA,MAAMC,cAAAA,iBAAiBL,MAAAA,CAAAA,KAAAA,EAAAA;;;;AAYvB;;;;;;;;;;;;;;;;;;;;;;;;IAyBe,SAASM,WAAAA,CAAYL,KAAuB,EAAA;IACvD,MAAM,EACFC,WAAW,EACXK,QAAQ,EACRC,MAAM,EACNC,aAAa,EACbC,qBAAqB,EACrBC,mBAAmB,EACnBC,2BAA2B,EAC3BC,yBAAyB,EACzBC,2BAA2B,EAC3BC,6BAA6B,EAChC,GAAGd,KAAAA;AACJ,IAAA,MAAM,CAACe,UAAAA,EAAYC,aAAAA,CAAc,GAAGC,QAAAA,CAAiB,IAAA,CAAA;AACrD,IAAA,MAAM,CAACC,aAAAA,EAAeC,gBAAAA,CAAiB,GAAGF,QAAAA,CAAiB,IAAA,CAAA;AAC3D,IAAA,MAAM,CAACG,UAAAA,EAAYC,aAAAA,CAAc,GAAGJ,QAAAA,CAAkB,KAAA,CAAA;AACtD,IA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,WAAAA,EAAaA,WAAAA;oBAAasD,IAAAA,EAAK,MAAA;8BACrC5B,KAAAA,CAAMC,QAAQ,CAAC4B,GAAG,CAAC9B,eAAe,CAAC+B,KAAAA,EAAOX,sBACvCK,GAAA,CAACO,QAAAA,EAAAA;4BACGZ,KAAAA,EAAOA,KAAAA;4BACP7C,WAAAA,EAAaA,WAAAA;4BACbO,aAAAA,EAAeA,aAAAA;4BACfc,QAAAA,EAAUA,QAAAA;4BACVQ,UAAAA,EAAYA,UAAAA;4BACZL,eAAAA,EAAiBA,eAAAA;AAEhBgC,4BAAAA,QAAAA,EAAAA;;;;0BAKjBN,GAAA,CAAC/C,cAAAA,EAAAA;gBAAemD,IAAAA,EAAK,QAAA;gBAASI,WAAAA,EAAU,QAAA;gBAASC,aAAAA,EAAY,MAAA;AACxDpC,gBAAAA,QAAAA,EAAAA;;;;AAIjB;AAEAnB,WAAAA,CAAYwD,YAAY,GAAG;0CAEvB5D,WAAAA,EAAaC,WAAAA,CAAYyC,QAAQ;AACjC,iEACAnC,aAAAA,EAAe,KAAA;AACf,4CACAC,qBAAAA,EACI,sGAAA;AACJ,0CACAC,mBAAAA,EAAqB,iBAAA;AACrB,iDACAC,2BAAAA,EACI,gHAAA;AACJ,+CACAC,yBAAAA,EAA2B,oCAAA;AAC3B,iDACAC,2BAAAA,EAA6B,sCAAA;AAC7B,mDACAC,6BAAAA,EAA+B;AACnC,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"DragAndDrop.js","sources":["../../../src/components/DragAndDrop/DragAndDrop.tsx"],"sourcesContent":["import React, { PropsWithChildren, useState } from 'react';\nimport styled from '@emotion/styled';\nimport DragItem from './DragItem';\nimport { ORIENTATION, DragContext } from './types';\n\ntype DragAndDropProps = {\n /**\n * Orientation of the list layout\n * @default ORIENTATION.VERTICAL\n */\n orientation?: ORIENTATION;\n /** Drop event handler */\n onDrop: (start: number, end: number) => void;\n /** Shows drag indicator against each list item\n * @default false\n */\n showIndicator?: boolean;\n /**\n * i18n: Template for item aria-label. Placeholders: {:position}, {:grabKey}, {:moveKeys}, {:dropKey}, {:altDropKey}\n * @default 'Item {:position}. Press {:grabKey} to grab, {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop'\n */\n itemAriaLabelTemplate?: string;\n /** i18n: Aria label for drag handle\n * @default 'Drag to reorder'\n */\n dragHandleAriaLabel?: string;\n /**\n * i18n: Template for grabbed announcement. Placeholders: {:position}, {:moveKeys}, {:dropKey}, {:altDropKey}, {:cancelKey}\n * @default 'Item {:position} grabbed. Use {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop, {:cancelKey} to cancel'\n */\n grabbedAnnouncementTemplate?: string;\n /**\n * i18n: Template for moved announcement. Placeholders: {:position}\n * @default 'Item moved to position {:position}'\n */\n movedAnnouncementTemplate?: string;\n /**\n * i18n: Template for dropped announcement. Placeholders: {:position}\n * @default 'Item dropped at position {:position}'\n */\n droppedAnnouncementTemplate?: string;\n /**\n * i18n: Template for cancelled announcement\n * @default 'Drag cancelled, item restored to original position'\n */\n cancelledAnnouncementTemplate?: string;\n} & PropsWithChildren<unknown>;\n\n/** Container Component */\nconst Container = styled.div<{ orientation: ORIENTATION }>`\n flex: 1;\n display: flex;\n position: relative;\n flex-wrap: wrap;\n flex-direction: ${(props) => (props.orientation === ORIENTATION.HORIZONTAL ? 'row' : 'column')};\n`;\n\n/** Visually hidden but accessible to screen readers */\nconst VisuallyHidden = styled.div`\n position: absolute;\n width: 1px;\n height: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border-width: 0;\n`;\n\n/**\n * A drag and drop container component that enables reordering of child elements.\n *\n * @component\n * @example\n * ```tsx\n * <DragAndDrop\n * orientation={ORIENTATION.VERTICAL}\n * onDrop={(start, end) => handleReorder(start, end)}\n * showIndicator={true}\n * >\n * <div>Item 1</div>\n * <div>Item 2</div>\n * <div>Item 3</div>\n * </DragAndDrop>\n * ```\n *\n * @param props - The component props\n * @param props.orientation - Determines the layout direction (horizontal or vertical). Defaults to VERTICAL.\n * @param props.onDrop - Callback fired when an item is dropped, receives the start and end indices\n * @param props.showIndicator - Whether to display drag indicators for each list item. Defaults to false.\n * @param props.children - Child elements to be rendered as draggable items\n *\n * @returns A draggable container with reorderable items\n */\n/**\n * DragAndDrop Component\n * @param props - Component props\n * @param ref - Ref forwarded to the underlying HTMLDivElement\n */\nfunction DragAndDropComponent(props: DragAndDropProps, ref: React.Ref<HTMLDivElement>) {\n const {\n orientation = ORIENTATION.VERTICAL,\n children,\n onDrop,\n showIndicator = false,\n itemAriaLabelTemplate = 'Item {:position}. Press {:grabKey} to grab, {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop',\n dragHandleAriaLabel = 'Drag to reorder',\n grabbedAnnouncementTemplate = 'Item {:position} grabbed. Use {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop, {:cancelKey} to cancel',\n movedAnnouncementTemplate = 'Item moved to position {:position}',\n droppedAnnouncementTemplate = 'Item dropped at position {:position}',\n cancelledAnnouncementTemplate = 'Drag cancelled, item restored to original position',\n ...rest\n } = props;\n const [startIndex, setStartIndex] = useState<number | null>(null);\n const [originalIndex, setOriginalIndex] = useState<number | null>(null);\n const [isDragging, setIsDragging] = useState<boolean>(false);\n const [dragOver, setDragOver] = useState<number | null>(null);\n const [announcement, setAnnouncement] = useState<string | undefined>('');\n const childrenArray = React.Children.toArray(children);\n const totalItems = childrenArray.length;\n\n /**\n * Replace placeholders in i18n templates\n */\n const replacePlaceholders = (\n template: string,\n data: {\n position?: number;\n grabKey?: string;\n dropKey?: string;\n altDropKey?: string;\n cancelKey?: string;\n moveKeys?: string;\n },\n ): string => {\n return template\n .replace(/\\{:position\\}/g, String(data.position ?? ''))\n .replace(/\\{:grabKey\\}/g, data.grabKey ?? 'Space')\n .replace(/\\{:dropKey\\}/g, data.dropKey ?? 'Space')\n .replace(/\\{:altDropKey\\}/g, data.altDropKey ?? 'Enter')\n .replace(/\\{:cancelKey\\}/g, data.cancelKey ?? 'Escape')\n .replace(\n /\\{:moveKeys\\}/g,\n data.moveKeys ??\n (orientation === ORIENTATION.VERTICAL ? 'Arrow Up/Down' : 'Arrow Left/Right'),\n );\n };\n\n // i18n configuration object\n const i18n = {\n itemAriaLabelTemplate:\n itemAriaLabelTemplate ??\n 'Item {:position}. Press {:grabKey} to grab, {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop',\n dragHandleAriaLabel: dragHandleAriaLabel ?? 'Drag to reorder',\n grabbedAnnouncementTemplate:\n grabbedAnnouncementTemplate ??\n 'Item {:position} grabbed. Use {:moveKeys} to move, {:dropKey} or {:altDropKey} to drop, {:cancelKey} to cancel',\n movedAnnouncementTemplate:\n movedAnnouncementTemplate ?? 'Item moved to position {:position}',\n droppedAnnouncementTemplate:\n droppedAnnouncementTemplate ?? 'Item dropped at position {:position}',\n cancelledAnnouncementTemplate:\n cancelledAnnouncementTemplate ?? 'Drag cancelled, item restored to original position',\n replacePlaceholders,\n };\n\n /**\n * Drop handler invoked when a draggable item is released.\n * @param index\n */\n const drop = (index: number | null) => {\n if (startIndex !== null && index !== null) {\n onDrop?.(startIndex, index);\n }\n setStartIndex(null);\n setOriginalIndex(null);\n setIsDragging(false);\n };\n\n /**\n * Cancel handler to restore item to original position\n */\n const cancel = () => {\n if (originalIndex !== null && startIndex !== null && startIndex !== originalIndex) {\n onDrop?.(startIndex, originalIndex);\n }\n setStartIndex(null);\n setOriginalIndex(null);\n setIsDragging(false);\n };\n\n /**\n * Start grab handler to track original position\n */\n const startGrab = (index: number) => {\n setStartIndex(index);\n setOriginalIndex(index);\n setIsDragging(true);\n };\n\n return (\n <>\n <DragContext.Provider\n value={{\n startIndex,\n setStartIndex,\n drop,\n onDrop,\n cancel,\n startGrab,\n isDragging,\n setIsDragging,\n setDragOver,\n i18n,\n }}\n >\n <Container {...rest} ref={ref} orientation={orientation} role=\"list\">\n {React.Children.map(childrenArray, (child, index) => (\n <DragItem\n index={index}\n orientation={orientation}\n showIndicator={showIndicator}\n dragOver={dragOver}\n totalItems={totalItems}\n setAnnouncement={setAnnouncement}\n >\n {child}\n </DragItem>\n ))}\n </Container>\n </DragContext.Provider>\n <VisuallyHidden role=\"status\" aria-live=\"polite\" aria-atomic=\"true\">\n {announcement}\n </VisuallyHidden>\n </>\n );\n}\n\nconst DragAndDrop = React.forwardRef(DragAndDropComponent);\nexport default DragAndDrop;\n"],"names":["Container","styled","props","orientation","ORIENTATION","HORIZONTAL","VisuallyHidden","DragAndDropComponent","ref","VERTICAL","children","onDrop","showIndicator","itemAriaLabelTemplate","dragHandleAriaLabel","grabbedAnnouncementTemplate","movedAnnouncementTemplate","droppedAnnouncementTemplate","cancelledAnnouncementTemplate","rest","startIndex","setStartIndex","useState","originalIndex","setOriginalIndex","isDragging","setIsDragging","dragOver","setDragOver","announcement","setAnnouncement","childrenArray","React","Children","toArray","totalItems","length","replacePlaceholders","template","data","replace","String","position","grabKey","dropKey","altDropKey","cancelKey","moveKeys","i18n","drop","index","cancel","startGrab","_jsxs","_Fragment","_jsx","DragContext","Provider","value","role","map","child","DragItem","aria-live","aria-atomic","DragAndDrop","forwardRef"],"mappings":";;;;;;AAgDA,2BACA,MAAMA,WAAAA,iBAAYC,MAAAA,CAAAA,KAAAA,EAAAA;;;AAKI,CAAA,CAAA,CAAA,sEAAA,EAAA,CAACC,QAAWA,KAAAA,CAAMC,WAAW,KAAKC,WAAAA,CAAYC,UAAU,GAAG,KAAA,GAAQ,QAAA,EAAA,GAAA,CAAA;AAGzF,wDACA,MAAMC,gBAAAA,iBAAiBL,MAAAA,CAAAA,KAAAA,EAAAA;;;;AAYvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BC,IACD,SAASM,oBAAAA,CAAqBL,KAAuB,EAAEM,GAA8B,EAAA;AACjF,IAAA,MAAM,EACFL,WAAAA,GAAcC,WAAAA,CAAYK,QAAQ,EAClCC,QAAQ,EACRC,MAAM,EACNC,aAAAA,GAAgB,KAAK,EACrBC,qBAA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|
|
8
8
|
/** Whether to show a drag handle indicator instead of making the entire item draggable */
|
|
9
9
|
showIndicator: boolean;
|
|
10
10
|
/** The index of the item currently being dragged over */
|
|
11
|
-
dragOver: number;
|
|
11
|
+
dragOver: number | null;
|
|
12
12
|
/** Total number of items in the list */
|
|
13
13
|
totalItems: number;
|
|
14
14
|
/** Callback to set announcement for screen readers */
|
|
15
|
-
setAnnouncement: (message
|
|
15
|
+
setAnnouncement: (message?: string) => void;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* A draggable item component that supports both mouse and touch interactions for drag-and-drop functionality.
|
|
@@ -6,15 +6,15 @@ import { DragContext, ORIENTATION } from './types.js';
|
|
|
6
6
|
import CheckCircle from '../../icons/DragIndicator.js';
|
|
7
7
|
|
|
8
8
|
/** Styled component for the draggable item container */ const Item = /*#__PURE__*/ styled("div", {
|
|
9
|
-
target: "
|
|
9
|
+
target: "ertl9d70",
|
|
10
10
|
label: "Item"
|
|
11
|
-
})("cursor:", (props)=>props.showIndicator ? 'default' : 'move', ";display:flex;user-select:", (props)=>props.showIndicator ? 'auto' : 'none', ";border-top:2px dashed\n ", (props)=>props.orientation === ORIENTATION.VERTICAL && props.active > 0 ? getThemeValue(THEME_NAME.PRIMARY) : 'transparent', ";border-bottom:2px dashed\n ", (props)=>props.orientation === ORIENTATION.VERTICAL && props.active < 0 ? getThemeValue(THEME_NAME.PRIMARY) : 'transparent', ";border-left:2px dashed\n ", (props)=>props.orientation === ORIENTATION.HORIZONTAL && props.active > 0 ? getThemeValue(THEME_NAME.PRIMARY) : 'transparent', ";border-right:2px dashed\n ", (props)=>props.orientation === ORIENTATION.HORIZONTAL && props.active < 0 ? getThemeValue(THEME_NAME.PRIMARY) : 'transparent', ";opacity:", (props)=>props.dragging ? 0.5 : 1, ";border-radius:10px;&:focus{box-shadow:0 0 0 4px ", getThemeValue(THEME_NAME.PRIMARY_LIGHT), ";}&:focus:not(:focus-visible){box-shadow:none;}&:focus-visible{box-shadow:0 0 0 4px ", getThemeValue(THEME_NAME.PRIMARY_LIGHT), ";}");
|
|
11
|
+
})("cursor:", (props)=>props.showIndicator ? 'default' : 'move', ";display:flex;user-select:", (props)=>props.showIndicator ? 'auto' : 'none', ";border-top:2px dashed\n ", (props)=>props.orientation === ORIENTATION.VERTICAL && props.active !== null && props.active > 0 ? getThemeValue(THEME_NAME.PRIMARY) : 'transparent', ";border-bottom:2px dashed\n ", (props)=>props.orientation === ORIENTATION.VERTICAL && props.active !== null && props.active < 0 ? getThemeValue(THEME_NAME.PRIMARY) : 'transparent', ";border-left:2px dashed\n ", (props)=>props.orientation === ORIENTATION.HORIZONTAL && props.active !== null && props.active > 0 ? getThemeValue(THEME_NAME.PRIMARY) : 'transparent', ";border-right:2px dashed\n ", (props)=>props.orientation === ORIENTATION.HORIZONTAL && props.active !== null && props.active < 0 ? getThemeValue(THEME_NAME.PRIMARY) : 'transparent', ";opacity:", (props)=>props.dragging ? 0.5 : 1, ";border-radius:10px;&:focus{box-shadow:0 0 0 4px ", getThemeValue(THEME_NAME.PRIMARY_LIGHT), ";}&:focus:not(:focus-visible){box-shadow:none;}&:focus-visible{box-shadow:0 0 0 4px ", getThemeValue(THEME_NAME.PRIMARY_LIGHT), ";}");
|
|
12
12
|
/** Styled component for the drag handle indicator */ const DragKnob = /*#__PURE__*/ styled("div", {
|
|
13
|
-
target: "
|
|
13
|
+
target: "ertl9d71",
|
|
14
14
|
label: "DragKnob"
|
|
15
15
|
})("padding-top:8px;cursor:move;touch-action:none;color:", getThemeValue(THEME_NAME.DISABLED), ";");
|
|
16
|
-
/** Container for the children */ const Container = /*#__PURE__*/ styled("div", {
|
|
17
|
-
target: "
|
|
16
|
+
/** Container for the children */ const Container$7 = /*#__PURE__*/ styled("div", {
|
|
17
|
+
target: "ertl9d72",
|
|
18
18
|
label: "Container"
|
|
19
19
|
})("flex:1;");
|
|
20
20
|
/**
|
|
@@ -65,8 +65,8 @@ import CheckCircle from '../../icons/DragIndicator.js';
|
|
|
65
65
|
* Drag start event handler
|
|
66
66
|
* @param e Event
|
|
67
67
|
*/ const dragStartHandler = ()=>{
|
|
68
|
-
context
|
|
69
|
-
context
|
|
68
|
+
context?.setStartIndex(index);
|
|
69
|
+
context?.setIsDragging(true);
|
|
70
70
|
};
|
|
71
71
|
/**
|
|
72
72
|
* Drag over event handler
|
|
@@ -74,7 +74,9 @@ import CheckCircle from '../../icons/DragIndicator.js';
|
|
|
74
74
|
*/ const dragOverHandler = (e)=>{
|
|
75
75
|
e.preventDefault();
|
|
76
76
|
e.stopPropagation();
|
|
77
|
-
|
|
77
|
+
if (context && context.startIndex !== null) {
|
|
78
|
+
setActive(context.startIndex - index);
|
|
79
|
+
}
|
|
78
80
|
};
|
|
79
81
|
/**
|
|
80
82
|
* Drag leave event handler
|
|
@@ -87,8 +89,8 @@ import CheckCircle from '../../icons/DragIndicator.js';
|
|
|
87
89
|
*/ const dropHandler = (e)=>{
|
|
88
90
|
e.preventDefault();
|
|
89
91
|
setActive(0);
|
|
90
|
-
context
|
|
91
|
-
context
|
|
92
|
+
context?.drop(index);
|
|
93
|
+
context?.setIsDragging(false);
|
|
92
94
|
};
|
|
93
95
|
/**
|
|
94
96
|
* Touch start event handler
|
|
@@ -99,9 +101,9 @@ import CheckCircle from '../../icons/DragIndicator.js';
|
|
|
99
101
|
clearTimeout(touchTimerRef.current);
|
|
100
102
|
}
|
|
101
103
|
touchTimerRef.current = setTimeout(()=>{
|
|
102
|
-
context
|
|
103
|
-
context
|
|
104
|
-
context
|
|
104
|
+
context?.setStartIndex(index);
|
|
105
|
+
context?.setIsDragging(true);
|
|
106
|
+
context?.setDragOver(index);
|
|
105
107
|
document.body.style.overflow = 'hidden';
|
|
106
108
|
vibrate(50);
|
|
107
109
|
}, 200);
|
|
@@ -113,7 +115,7 @@ import CheckCircle from '../../icons/DragIndicator.js';
|
|
|
113
115
|
*/ const touchMoveHandler = (e)=>{
|
|
114
116
|
const touch = e.touches[0];
|
|
115
117
|
if (!touch) return;
|
|
116
|
-
if (context
|
|
118
|
+
if (context?.isDragging) {
|
|
117
119
|
e.preventDefault();
|
|
118
120
|
// get the element under the touch point
|
|
119
121
|
const el = document.elementFromPoint(touch.clientX, touch.clientY);
|
|
@@ -121,7 +123,7 @@ import CheckCircle from '../../icons/DragIndicator.js';
|
|
|
121
123
|
const overIndex = overAttr != null ? parseInt(overAttr, 10) : null;
|
|
122
124
|
// if we know which index we're over, update visual state
|
|
123
125
|
if (overIndex !== null) {
|
|
124
|
-
context
|
|
126
|
+
context?.setDragOver(overIndex);
|
|
125
127
|
}
|
|
126
128
|
} else if (touchTimerRef.current) {
|
|
127
129
|
clearTimeout(touchTimerRef.current);
|
|
@@ -136,10 +138,10 @@ import CheckCircle from '../../icons/DragIndicator.js';
|
|
|
136
138
|
clearTimeout(touchTimerRef.current);
|
|
137
139
|
touchTimerRef.current = null;
|
|
138
140
|
}
|
|
139
|
-
if (context
|
|
140
|
-
context
|
|
141
|
+
if (context?.isDragging) {
|
|
142
|
+
context?.drop(dragOver);
|
|
141
143
|
vibrate(50);
|
|
142
|
-
context
|
|
144
|
+
context?.setIsDragging(false);
|
|
143
145
|
document.body.style.overflow = 'auto';
|
|
144
146
|
}
|
|
145
147
|
};
|
|
@@ -150,35 +152,35 @@ import CheckCircle from '../../icons/DragIndicator.js';
|
|
|
150
152
|
const isVertical = orientation === ORIENTATION.VERTICAL;
|
|
151
153
|
const moveUp = isVertical ? 'ArrowUp' : 'ArrowLeft';
|
|
152
154
|
const moveDown = isVertical ? 'ArrowDown' : 'ArrowRight';
|
|
153
|
-
const isGrabbed = context
|
|
155
|
+
const isGrabbed = context?.isDragging && context?.startIndex === index;
|
|
154
156
|
// Space to grab/drop
|
|
155
157
|
if (e.key === ' ' || e.key === 'Spacebar') {
|
|
156
158
|
e.preventDefault();
|
|
157
159
|
if (isGrabbed) {
|
|
158
160
|
// Drop at current position
|
|
159
|
-
context
|
|
160
|
-
setAnnouncement(context
|
|
161
|
+
context?.drop(index);
|
|
162
|
+
setAnnouncement(context?.i18n.replacePlaceholders(context?.i18n.droppedAnnouncementTemplate, {
|
|
161
163
|
position: index + 1
|
|
162
164
|
}));
|
|
163
165
|
} else {
|
|
164
166
|
// Grab item
|
|
165
|
-
context
|
|
166
|
-
setAnnouncement(context
|
|
167
|
+
context?.startGrab(index);
|
|
168
|
+
setAnnouncement(context?.i18n.replacePlaceholders(context?.i18n.grabbedAnnouncementTemplate, {
|
|
167
169
|
position: index + 1
|
|
168
170
|
}));
|
|
169
171
|
}
|
|
170
172
|
} else if (e.key === 'Enter' && isGrabbed) {
|
|
171
173
|
e.preventDefault();
|
|
172
|
-
context
|
|
173
|
-
setAnnouncement(context
|
|
174
|
+
context?.drop(index);
|
|
175
|
+
setAnnouncement(context?.i18n.replacePlaceholders(context?.i18n.droppedAnnouncementTemplate, {
|
|
174
176
|
position: index + 1
|
|
175
177
|
}));
|
|
176
178
|
} else if (e.key === 'Escape' && isGrabbed) {
|
|
177
179
|
e.preventDefault();
|
|
178
|
-
context
|
|
179
|
-
setAnnouncement(context
|
|
180
|
+
context?.cancel();
|
|
181
|
+
setAnnouncement(context?.i18n.cancelledAnnouncementTemplate);
|
|
180
182
|
} else if (isGrabbed) {
|
|
181
|
-
if (e.key === moveUp && index > 0) {
|
|
183
|
+
if (e.key === moveUp && index > 0 && context.startIndex !== null) {
|
|
182
184
|
e.preventDefault();
|
|
183
185
|
// Move without dropping - just reorder and update startIndex
|
|
184
186
|
const newIndex = index - 1;
|
|
@@ -187,7 +189,7 @@ import CheckCircle from '../../icons/DragIndicator.js';
|
|
|
187
189
|
setAnnouncement(context.i18n.replacePlaceholders(context.i18n.movedAnnouncementTemplate, {
|
|
188
190
|
position: newIndex + 1
|
|
189
191
|
}));
|
|
190
|
-
} else if (e.key === moveDown && index < totalItems - 1) {
|
|
192
|
+
} else if (e.key === moveDown && index < totalItems - 1 && context.startIndex !== null) {
|
|
191
193
|
e.preventDefault();
|
|
192
194
|
// Move without dropping - just reorder and update startIndex
|
|
193
195
|
const newIndex = index + 1;
|
|
@@ -209,30 +211,30 @@ import CheckCircle from '../../icons/DragIndicator.js';
|
|
|
209
211
|
};
|
|
210
212
|
}, []);
|
|
211
213
|
/** Update active state based on dragOver changes */ useEffect(()=>{
|
|
212
|
-
if (context
|
|
213
|
-
setActive(context
|
|
214
|
+
if (context?.isDragging && context?.startIndex !== null && dragOver === index) {
|
|
215
|
+
setActive(context?.startIndex - index);
|
|
214
216
|
} else {
|
|
215
217
|
setActive(0);
|
|
216
218
|
}
|
|
217
219
|
}, [
|
|
218
220
|
dragOver,
|
|
219
|
-
context
|
|
221
|
+
context?.startIndex,
|
|
220
222
|
index,
|
|
221
|
-
context
|
|
223
|
+
context?.isDragging
|
|
222
224
|
]);
|
|
223
225
|
return /*#__PURE__*/ jsxs(Item, {
|
|
224
226
|
draggable: !showIndicator,
|
|
225
227
|
showIndicator: showIndicator,
|
|
226
228
|
active: active,
|
|
227
|
-
dragging: context
|
|
229
|
+
dragging: !!(context?.isDragging && context.startIndex === index),
|
|
228
230
|
orientation: orientation,
|
|
229
231
|
"data-drag-index": index,
|
|
230
232
|
tabIndex: 0,
|
|
231
233
|
role: "listitem",
|
|
232
|
-
"aria-label": context
|
|
234
|
+
"aria-label": context?.i18n.replacePlaceholders(context.i18n.itemAriaLabelTemplate, {
|
|
233
235
|
position: index + 1
|
|
234
236
|
}),
|
|
235
|
-
"aria-grabbed": context
|
|
237
|
+
"aria-grabbed": context?.isDragging && context.startIndex === index,
|
|
236
238
|
onKeyDown: handleKeyDown,
|
|
237
239
|
onDragStart: !showIndicator ? dragStartHandler : undefined,
|
|
238
240
|
onDragOver: dragOverHandler,
|
|
@@ -246,14 +248,14 @@ import CheckCircle from '../../icons/DragIndicator.js';
|
|
|
246
248
|
showIndicator && /*#__PURE__*/ jsx(DragKnob, {
|
|
247
249
|
draggable: true,
|
|
248
250
|
role: "button",
|
|
249
|
-
"aria-label": context
|
|
251
|
+
"aria-label": context?.i18n.dragHandleAriaLabel,
|
|
250
252
|
onDragStart: dragStartHandler,
|
|
251
253
|
onTouchStart: touchStartHandler,
|
|
252
254
|
onKeyDown: handleKeyDown,
|
|
253
255
|
tabIndex: -1,
|
|
254
256
|
children: /*#__PURE__*/ jsx(CheckCircle, {})
|
|
255
257
|
}),
|
|
256
|
-
/*#__PURE__*/ jsx(Container, {
|
|
258
|
+
/*#__PURE__*/ jsx(Container$7, {
|
|
257
259
|
children: children
|
|
258
260
|
})
|
|
259
261
|
]
|