@mbao01/common 0.0.44 → 0.0.46
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/dist/types/components/Chart/Chart.d.ts +2 -0
- package/dist/types/components/Chart/ChartContext.d.ts +2 -0
- package/dist/types/components/Chart/components/ChartLegend.d.ts +4 -0
- package/dist/types/components/Chart/components/ChartStyle.d.ts +2 -0
- package/dist/types/components/Chart/components/ChartTooltip.d.ts +4 -0
- package/dist/types/components/Chart/components/index.d.ts +3 -0
- package/dist/types/components/Chart/constants.d.ts +22 -0
- package/dist/types/components/Chart/helpers.d.ts +11 -0
- package/dist/types/components/Chart/hooks/index.d.ts +1 -0
- package/dist/types/components/Chart/hooks/useChart/index.d.ts +1 -0
- package/dist/types/components/Chart/hooks/useChart/useChart.d.ts +1 -0
- package/dist/types/components/Chart/index.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/activeShapeArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/animationArgs.d.ts +12 -0
- package/dist/types/components/Chart/stories/args/areaArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/areaChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/barArgs.d.ts +5 -0
- package/dist/types/components/Chart/stories/args/barChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/cartesianChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/cartesianSharedArgs.d.ts +11 -0
- package/dist/types/components/Chart/stories/args/chartArgs.d.ts +6 -0
- package/dist/types/components/Chart/stories/args/dotArgs.d.ts +10 -0
- package/dist/types/components/Chart/stories/args/events.d.ts +804 -0
- package/dist/types/components/Chart/stories/args/labelListArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/legendArgs.d.ts +3 -0
- package/dist/types/components/Chart/stories/args/lineArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/lineChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/pieArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/pieChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/polarChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/polarSharedArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/radarArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/radarChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/radialBarArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/radialBarChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/rectangleArgs.d.ts +9 -0
- package/dist/types/components/Chart/stories/args/referenceSharedArgs.d.ts +4 -0
- package/dist/types/components/Chart/stories/args/sectorArgs.d.ts +7 -0
- package/dist/types/components/Chart/stories/args/sharedAxisArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/stylesArgs.d.ts +6 -0
- package/dist/types/components/Chart/stories/args/textArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/tooltipArgs.d.ts +4 -0
- package/dist/types/components/Chart/stories/args/types.d.ts +13 -0
- package/dist/types/components/Chart/stories/args/xAxisArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/yAxisArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/examples/AreaChart.d.ts +16 -0
- package/dist/types/components/Chart/stories/examples/BarChart.d.ts +20 -0
- package/dist/types/components/Chart/stories/examples/LineChart.d.ts +16 -0
- package/dist/types/components/Chart/stories/examples/PieChart.d.ts +19 -0
- package/dist/types/components/Chart/stories/examples/RadarChart.d.ts +24 -0
- package/dist/types/components/Chart/stories/examples/RadialChart.d.ts +17 -0
- package/dist/types/components/Chart/stories/examples/Tooltip.d.ts +15 -0
- package/dist/types/components/Chart/stories/helpers/index.d.ts +9 -0
- package/dist/types/components/Chart/types.d.ts +37 -0
- package/dist/types/components/DragAndDrop/Draggable/Draggable.d.ts +29 -0
- package/dist/types/components/DragAndDrop/Draggable/Draggable.example.d.ts +24 -0
- package/dist/types/components/DragAndDrop/Draggable/constants.d.ts +9 -0
- package/dist/types/components/DragAndDrop/Draggable/index.d.ts +1 -0
- package/dist/types/components/DragAndDrop/Draggable/types.d.ts +41 -0
- package/dist/types/components/DragAndDrop/Droppable/Droppable.d.ts +2 -0
- package/dist/types/components/DragAndDrop/Droppable/Droppable.example.d.ts +10 -0
- package/dist/types/components/DragAndDrop/Droppable/constants.d.ts +5 -0
- package/dist/types/components/DragAndDrop/Droppable/index.d.ts +1 -0
- package/dist/types/components/DragAndDrop/Droppable/types.d.ts +4 -0
- package/dist/types/components/DragAndDrop/Sortable/Sortable.d.ts +2 -0
- package/dist/types/components/DragAndDrop/Sortable/Sortable.example.d.ts +6 -0
- package/dist/types/components/DragAndDrop/Sortable/constants.d.ts +4 -0
- package/dist/types/components/DragAndDrop/Sortable/index.d.ts +1 -0
- package/dist/types/components/DragAndDrop/Sortable/types.d.ts +7 -0
- package/dist/types/components/DragAndDrop/index.d.ts +3 -0
- package/dist/types/components/Widget/InternalWidgetsContext.d.ts +2 -0
- package/dist/types/components/Widget/Widget.d.ts +2 -0
- package/dist/types/components/Widget/Widgets.example.d.ts +1 -0
- package/dist/types/components/Widget/WidgetsContext.d.ts +2 -0
- package/dist/types/components/Widget/hooks/index.d.ts +2 -0
- package/dist/types/components/Widget/hooks/useWidget/index.d.ts +1 -0
- package/dist/types/components/Widget/hooks/useWidget/useWidget.d.ts +7 -0
- package/dist/types/components/Widget/hooks/useWidgets/index.d.ts +1 -0
- package/dist/types/components/Widget/hooks/useWidgets/useWidgets.d.ts +1 -0
- package/dist/types/components/Widget/index.d.ts +3 -0
- package/dist/types/components/Widget/modifiers/index.d.ts +1 -0
- package/dist/types/components/Widget/modifiers/restrictToElement.d.ts +2 -0
- package/dist/types/components/Widget/types.d.ts +28 -0
- package/package.json +9 -3
- package/src/components/Chart/Chart.tsx +26 -0
- package/src/components/Chart/ChartContext.tsx +4 -0
- package/src/components/Chart/components/ChartLegend.tsx +52 -0
- package/src/components/Chart/components/ChartStyle.tsx +32 -0
- package/src/components/Chart/components/ChartTooltip.tsx +126 -0
- package/src/components/Chart/components/index.ts +3 -0
- package/src/components/Chart/constants.ts +78 -0
- package/src/components/Chart/helpers.ts +27 -0
- package/src/components/Chart/hooks/index.ts +1 -0
- package/src/components/Chart/hooks/useChart/index.ts +1 -0
- package/src/components/Chart/hooks/useChart/useChart.ts +12 -0
- package/src/components/Chart/index.ts +2 -0
- package/src/components/Chart/stories/args/activeShapeArgs.ts +34 -0
- package/src/components/Chart/stories/args/animationArgs.ts +67 -0
- package/src/components/Chart/stories/args/areaArgs.ts +16 -0
- package/src/components/Chart/stories/args/areaChartArgs.ts +19 -0
- package/src/components/Chart/stories/args/barArgs.ts +123 -0
- package/src/components/Chart/stories/args/barChartArgs.ts +65 -0
- package/src/components/Chart/stories/args/cartesianChartArgs.ts +42 -0
- package/src/components/Chart/stories/args/cartesianSharedArgs.ts +136 -0
- package/src/components/Chart/stories/args/chartArgs.ts +244 -0
- package/src/components/Chart/stories/args/dotArgs.ts +46 -0
- package/src/components/Chart/stories/args/events.ts +343 -0
- package/src/components/Chart/stories/args/index.ts +178 -0
- package/src/components/Chart/stories/args/labelListArgs.ts +124 -0
- package/src/components/Chart/stories/args/legendArgs.ts +205 -0
- package/src/components/Chart/stories/args/lineArgs.ts +87 -0
- package/src/components/Chart/stories/args/lineChartArgs.ts +17 -0
- package/src/components/Chart/stories/args/pieArgs.ts +18 -0
- package/src/components/Chart/stories/args/pieChartArgs.ts +7 -0
- package/src/components/Chart/stories/args/polarChartArgs.ts +86 -0
- package/src/components/Chart/stories/args/polarSharedArgs.ts +42 -0
- package/src/components/Chart/stories/args/radarArgs.ts +26 -0
- package/src/components/Chart/stories/args/radarChartArgs.ts +26 -0
- package/src/components/Chart/stories/args/radialBarArgs.ts +36 -0
- package/src/components/Chart/stories/args/radialBarChartArgs.ts +16 -0
- package/src/components/Chart/stories/args/rectangleArgs.ts +35 -0
- package/src/components/Chart/stories/args/referenceSharedArgs.ts +75 -0
- package/src/components/Chart/stories/args/sectorArgs.ts +106 -0
- package/src/components/Chart/stories/args/sharedAxisArgs.ts +332 -0
- package/src/components/Chart/stories/args/stylesArgs.ts +258 -0
- package/src/components/Chart/stories/args/textArgs.ts +97 -0
- package/src/components/Chart/stories/args/tooltipArgs.ts +41 -0
- package/src/components/Chart/stories/args/types.ts +23 -0
- package/src/components/Chart/stories/args/xAxisArgs.ts +109 -0
- package/src/components/Chart/stories/args/yAxisArgs.ts +73 -0
- package/src/components/Chart/stories/examples/AreaChart.tsx +156 -0
- package/src/components/Chart/stories/examples/BarChart.tsx +425 -0
- package/src/components/Chart/stories/examples/LineChart.tsx +144 -0
- package/src/components/Chart/stories/examples/PieChart.tsx +238 -0
- package/src/components/Chart/stories/examples/RadarChart.tsx +261 -0
- package/src/components/Chart/stories/examples/RadialChart.tsx +239 -0
- package/src/components/Chart/stories/examples/Tooltip.tsx +68 -0
- package/src/components/Chart/stories/helpers/index.tsx +75 -0
- package/src/components/Chart/types.ts +39 -0
- package/src/components/DragAndDrop/Draggable/Draggable.example.tsx +147 -0
- package/src/components/DragAndDrop/Draggable/Draggable.tsx +161 -0
- package/src/components/DragAndDrop/Draggable/constants.ts +47 -0
- package/src/components/DragAndDrop/Draggable/index.ts +1 -0
- package/src/components/DragAndDrop/Draggable/types.ts +56 -0
- package/src/components/DragAndDrop/Droppable/Droppable.example.tsx +86 -0
- package/src/components/DragAndDrop/Droppable/Droppable.tsx +38 -0
- package/src/components/DragAndDrop/Droppable/constants.ts +15 -0
- package/src/components/DragAndDrop/Droppable/index.ts +1 -0
- package/src/components/DragAndDrop/Droppable/types.ts +7 -0
- package/src/components/DragAndDrop/Sortable/Sortable.example.tsx +61 -0
- package/src/components/DragAndDrop/Sortable/Sortable.tsx +65 -0
- package/src/components/DragAndDrop/Sortable/constants.ts +12 -0
- package/src/components/DragAndDrop/Sortable/index.ts +1 -0
- package/src/components/DragAndDrop/Sortable/types.ts +11 -0
- package/src/components/DragAndDrop/index.ts +3 -0
- package/src/components/Widget/InternalWidgetsContext.tsx +4 -0
- package/src/components/Widget/Widget.tsx +17 -0
- package/src/components/Widget/Widgets.example.tsx +118 -0
- package/src/components/Widget/WidgetsContext.tsx +97 -0
- package/src/components/Widget/hooks/index.ts +2 -0
- package/src/components/Widget/hooks/useWidget/index.ts +1 -0
- package/src/components/Widget/hooks/useWidget/useWidget.ts +21 -0
- package/src/components/Widget/hooks/useWidgets/index.ts +1 -0
- package/src/components/Widget/hooks/useWidgets/useWidgets.ts +12 -0
- package/src/components/Widget/index.ts +3 -0
- package/src/components/Widget/modifiers/index.ts +1 -0
- package/src/components/Widget/modifiers/restrictToElement.ts +8 -0
- package/src/components/Widget/types.ts +30 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { CSSProperties, Ref } from "react";
|
|
4
|
+
import { forwardRef } from "react";
|
|
5
|
+
import { createPortal } from "react-dom";
|
|
6
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
7
|
+
import { DragOverlay, useDndContext, useDraggable } from "@dnd-kit/core";
|
|
8
|
+
import type {
|
|
9
|
+
DraggableActionProps,
|
|
10
|
+
DraggableOverlayProps,
|
|
11
|
+
DraggableProps,
|
|
12
|
+
DraggableRootProps,
|
|
13
|
+
} from "./types";
|
|
14
|
+
import { cn } from "../../../utilities";
|
|
15
|
+
import { DROP_ANIMATION_CONFIG, getDraggableClasses, getDraggableRootClasses } from "./constants";
|
|
16
|
+
|
|
17
|
+
const Draggable = ({
|
|
18
|
+
id,
|
|
19
|
+
axis,
|
|
20
|
+
data,
|
|
21
|
+
disabled,
|
|
22
|
+
attributes,
|
|
23
|
+
style,
|
|
24
|
+
handle,
|
|
25
|
+
className,
|
|
26
|
+
...props
|
|
27
|
+
}: DraggableProps) => {
|
|
28
|
+
const {
|
|
29
|
+
attributes: draggableAttributes,
|
|
30
|
+
isDragging,
|
|
31
|
+
listeners,
|
|
32
|
+
transform,
|
|
33
|
+
setNodeRef,
|
|
34
|
+
setActivatorNodeRef,
|
|
35
|
+
} = useDraggable({
|
|
36
|
+
id,
|
|
37
|
+
data,
|
|
38
|
+
disabled,
|
|
39
|
+
attributes,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<DraggableRoot
|
|
44
|
+
{...props}
|
|
45
|
+
{...draggableAttributes}
|
|
46
|
+
ref={setNodeRef}
|
|
47
|
+
activatorNodeRef={setActivatorNodeRef}
|
|
48
|
+
axis={axis}
|
|
49
|
+
handle={handle}
|
|
50
|
+
isDragging={isDragging}
|
|
51
|
+
listeners={listeners}
|
|
52
|
+
transform={transform}
|
|
53
|
+
style={style}
|
|
54
|
+
className={cn(className, getDraggableClasses({ isDragging }))}
|
|
55
|
+
data-draggable={true}
|
|
56
|
+
data-draggable-active={isDragging || undefined}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const DraggableRoot = forwardRef<HTMLDivElement, DraggableRootProps>(
|
|
62
|
+
(
|
|
63
|
+
{
|
|
64
|
+
handle,
|
|
65
|
+
actions,
|
|
66
|
+
activatorNodeRef,
|
|
67
|
+
className,
|
|
68
|
+
isDragging,
|
|
69
|
+
isDragOverlay,
|
|
70
|
+
listeners,
|
|
71
|
+
transform,
|
|
72
|
+
style,
|
|
73
|
+
children,
|
|
74
|
+
...props
|
|
75
|
+
},
|
|
76
|
+
ref
|
|
77
|
+
) => {
|
|
78
|
+
const draggable = { listeners, ref: activatorNodeRef };
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div
|
|
82
|
+
{...props}
|
|
83
|
+
{...(actions || handle ? {} : listeners)}
|
|
84
|
+
ref={ref}
|
|
85
|
+
style={
|
|
86
|
+
{
|
|
87
|
+
...style,
|
|
88
|
+
"--translate-x": `${transform?.x ?? 0}px`,
|
|
89
|
+
"--translate-y": `${transform?.y ?? 0}px`,
|
|
90
|
+
} as CSSProperties
|
|
91
|
+
}
|
|
92
|
+
className={cn(className, getDraggableRootClasses({ isDragging, isDragOverlay }))}
|
|
93
|
+
>
|
|
94
|
+
{actions?.({ draggable })}
|
|
95
|
+
{handle ? (
|
|
96
|
+
<Slot {...draggable.listeners} ref={draggable.ref}>
|
|
97
|
+
{handle}
|
|
98
|
+
</Slot>
|
|
99
|
+
) : null}
|
|
100
|
+
{children}
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
DraggableRoot.displayName = "DraggableRoot";
|
|
106
|
+
|
|
107
|
+
const DraggableAction = forwardRef<HTMLElement, DraggableActionProps>(
|
|
108
|
+
({ active, children, className, cursor, style, ...props }, ref) => {
|
|
109
|
+
return (
|
|
110
|
+
<button
|
|
111
|
+
ref={ref as Ref<HTMLButtonElement>}
|
|
112
|
+
{...props}
|
|
113
|
+
tabIndex={0}
|
|
114
|
+
className={className}
|
|
115
|
+
style={
|
|
116
|
+
{
|
|
117
|
+
...style,
|
|
118
|
+
cursor,
|
|
119
|
+
"--fill": active?.fill,
|
|
120
|
+
"--background": active?.background,
|
|
121
|
+
} as CSSProperties
|
|
122
|
+
}
|
|
123
|
+
>
|
|
124
|
+
{children}
|
|
125
|
+
</button>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
DraggableAction.displayName = "DraggableAction";
|
|
130
|
+
|
|
131
|
+
const DraggableOverlay = ({
|
|
132
|
+
axis,
|
|
133
|
+
dropAnimation = DROP_ANIMATION_CONFIG,
|
|
134
|
+
className,
|
|
135
|
+
...props
|
|
136
|
+
}: DraggableOverlayProps) => {
|
|
137
|
+
const { active, activeNode } = useDndContext();
|
|
138
|
+
|
|
139
|
+
return createPortal(
|
|
140
|
+
<DragOverlay dropAnimation={dropAnimation} {...props}>
|
|
141
|
+
{active ? (
|
|
142
|
+
<DraggableRoot
|
|
143
|
+
axis={axis}
|
|
144
|
+
isDragging
|
|
145
|
+
isDragOverlay
|
|
146
|
+
className={cn(className, activeNode?.className)}
|
|
147
|
+
>
|
|
148
|
+
<div dangerouslySetInnerHTML={{ __html: activeNode?.innerHTML ?? "" }} />
|
|
149
|
+
</DraggableRoot>
|
|
150
|
+
) : null}
|
|
151
|
+
</DragOverlay>,
|
|
152
|
+
document.body
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
DraggableOverlay.displayName = "DraggableOverlay";
|
|
156
|
+
|
|
157
|
+
Draggable.Root = DraggableRoot;
|
|
158
|
+
Draggable.Action = DraggableAction;
|
|
159
|
+
Draggable.Overlay = DraggableOverlay;
|
|
160
|
+
|
|
161
|
+
export { Draggable };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { DropAnimation } from "@dnd-kit/core";
|
|
2
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
3
|
+
import { cva } from "../../../libs";
|
|
4
|
+
|
|
5
|
+
export const DROP_ANIMATION_CONFIG: DropAnimation = {
|
|
6
|
+
keyframes({ transform }) {
|
|
7
|
+
return [
|
|
8
|
+
{ transform: CSS.Transform.toString(transform.initial) },
|
|
9
|
+
{
|
|
10
|
+
transform: CSS.Transform.toString({
|
|
11
|
+
...transform.final,
|
|
12
|
+
scaleX: 0.96,
|
|
13
|
+
scaleY: 0.96,
|
|
14
|
+
}),
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
|
+
},
|
|
18
|
+
sideEffects({ active }) {
|
|
19
|
+
active.node.style.opacity = "0";
|
|
20
|
+
|
|
21
|
+
return () => {
|
|
22
|
+
active.node.style.opacity = "";
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const getDraggableClasses = cva(
|
|
28
|
+
"translate-x-[--translate-x] translate-y-[--translate-y] translate-z-0",
|
|
29
|
+
{
|
|
30
|
+
variants: {
|
|
31
|
+
isDragging: {
|
|
32
|
+
true: "transition-none z-10 cursor-grabbing",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export const getDraggableRootClasses = cva("relative", {
|
|
39
|
+
variants: {
|
|
40
|
+
isDragging: {
|
|
41
|
+
true: "",
|
|
42
|
+
},
|
|
43
|
+
isDragOverlay: {
|
|
44
|
+
true: "",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Draggable } from "./Draggable";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DraggableSyntheticListeners,
|
|
3
|
+
DragOverlayProps,
|
|
4
|
+
DropAnimation,
|
|
5
|
+
UseDraggableArguments,
|
|
6
|
+
} from "@dnd-kit/core";
|
|
7
|
+
import type { CSSProperties, ReactNode, Ref } from "react";
|
|
8
|
+
import { type Transform } from "@dnd-kit/utilities";
|
|
9
|
+
|
|
10
|
+
export enum DraggableAxis {
|
|
11
|
+
All,
|
|
12
|
+
Vertical,
|
|
13
|
+
Horizontal,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type DraggableHandleElement = JSX.Element | null;
|
|
17
|
+
|
|
18
|
+
export type DraggableActionsArgs = {
|
|
19
|
+
draggable: {
|
|
20
|
+
ref: Ref<HTMLElement> | undefined;
|
|
21
|
+
listeners: DraggableSyntheticListeners;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type BaseDraggableProps = Partial<{
|
|
26
|
+
axis: DraggableAxis;
|
|
27
|
+
style: CSSProperties;
|
|
28
|
+
handle: DraggableHandleElement;
|
|
29
|
+
actions: (args: Partial<DraggableActionsArgs>) => ReactNode;
|
|
30
|
+
}> &
|
|
31
|
+
React.HTMLAttributes<HTMLDivElement>;
|
|
32
|
+
|
|
33
|
+
export type DraggableProps = BaseDraggableProps & UseDraggableArguments;
|
|
34
|
+
|
|
35
|
+
export type DraggableRootProps = BaseDraggableProps &
|
|
36
|
+
Partial<{
|
|
37
|
+
isDragOverlay: boolean;
|
|
38
|
+
|
|
39
|
+
isDragging: boolean;
|
|
40
|
+
listeners: DraggableSyntheticListeners;
|
|
41
|
+
transform: Transform | null;
|
|
42
|
+
activatorNodeRef: Ref<HTMLElement>;
|
|
43
|
+
}>;
|
|
44
|
+
|
|
45
|
+
export type DraggableActionProps = React.HTMLAttributes<HTMLButtonElement> & {
|
|
46
|
+
active?: Partial<{
|
|
47
|
+
fill: string;
|
|
48
|
+
background: string;
|
|
49
|
+
}>;
|
|
50
|
+
cursor?: CSSProperties["cursor"];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type DraggableOverlayProps = {
|
|
54
|
+
axis?: DraggableRootProps["axis"];
|
|
55
|
+
dropAnimation?: DropAnimation | null;
|
|
56
|
+
} & DragOverlayProps;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Modifiers, UniqueIdentifier } from "@dnd-kit/core";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
closestCenter,
|
|
5
|
+
closestCorners,
|
|
6
|
+
DndContext,
|
|
7
|
+
pointerWithin,
|
|
8
|
+
rectIntersection,
|
|
9
|
+
} from "@dnd-kit/core";
|
|
10
|
+
import { Draggable } from "../Draggable";
|
|
11
|
+
import { Droppable } from "./Droppable";
|
|
12
|
+
|
|
13
|
+
type CollisionDetectionType =
|
|
14
|
+
| "rectIntersection"
|
|
15
|
+
| "closestCenter"
|
|
16
|
+
| "closestCorners"
|
|
17
|
+
| "pointerWithin";
|
|
18
|
+
|
|
19
|
+
const collisionDetectionAlgorithms = {
|
|
20
|
+
rectIntersection,
|
|
21
|
+
closestCenter,
|
|
22
|
+
closestCorners,
|
|
23
|
+
pointerWithin,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type DroppableExampleProps = {
|
|
27
|
+
collisionDetection?: CollisionDetectionType;
|
|
28
|
+
containers?: UniqueIdentifier[];
|
|
29
|
+
modifiers?: Modifiers;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const DroppableExample = ({
|
|
33
|
+
containers = ["A"],
|
|
34
|
+
collisionDetection = "rectIntersection",
|
|
35
|
+
modifiers,
|
|
36
|
+
}: DroppableExampleProps) => {
|
|
37
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
38
|
+
const [parentContainerId, setParentContainerId] = useState<UniqueIdentifier | null>(null);
|
|
39
|
+
|
|
40
|
+
const item = (
|
|
41
|
+
<Draggable
|
|
42
|
+
id="my-draggable"
|
|
43
|
+
className="w-fit border border-base-content rounded-md p-2 flex items-center gap-2 data-[draggable-active]:opacity-0"
|
|
44
|
+
>
|
|
45
|
+
Go ahead, drag me.
|
|
46
|
+
</Draggable>
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<DndContext
|
|
51
|
+
collisionDetection={collisionDetectionAlgorithms[collisionDetection]}
|
|
52
|
+
modifiers={parentContainerId !== null ? undefined : modifiers}
|
|
53
|
+
onDragStart={() => setIsDragging(true)}
|
|
54
|
+
onDragEnd={({ over }) => {
|
|
55
|
+
setParentContainerId(over ? over.id : null);
|
|
56
|
+
setIsDragging(false);
|
|
57
|
+
}}
|
|
58
|
+
onDragCancel={() => setIsDragging(false)}
|
|
59
|
+
>
|
|
60
|
+
<div className="flex gap-6 items-center">
|
|
61
|
+
<div className="my-10 w-52">{parentContainerId === null ? item : null}</div>
|
|
62
|
+
<div className="grid grid-cols-2 gap-6">
|
|
63
|
+
{containers.map((id) => (
|
|
64
|
+
<Droppable
|
|
65
|
+
key={id}
|
|
66
|
+
id={id}
|
|
67
|
+
isDragging={isDragging}
|
|
68
|
+
className="relative p-6 border border-base-300 rounded-md w-72 h-72 bg-base-200 box-border data-[draggable-active]:opacity-80 data-[draggable-over]:opacity-100 transition-opacity"
|
|
69
|
+
>
|
|
70
|
+
<div className="absolute bottom-6">Container {id}</div>
|
|
71
|
+
{parentContainerId === id ? item : null}
|
|
72
|
+
</Droppable>
|
|
73
|
+
))}
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
<Draggable.Overlay />
|
|
77
|
+
</DndContext>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const CollisionDetectionAlgorithmsDroppableExample = ({
|
|
82
|
+
collisionDetection,
|
|
83
|
+
...props
|
|
84
|
+
}: DroppableExampleProps) => {
|
|
85
|
+
return <DroppableExample {...props} collisionDetection={collisionDetection} />;
|
|
86
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useDroppable } from "@dnd-kit/core";
|
|
4
|
+
import { cn } from "../../../utilities";
|
|
5
|
+
import { getDroppableClasses } from "./constants";
|
|
6
|
+
import { type DroppableProps } from "./types";
|
|
7
|
+
|
|
8
|
+
export const Droppable = ({
|
|
9
|
+
children,
|
|
10
|
+
id,
|
|
11
|
+
disabled,
|
|
12
|
+
data,
|
|
13
|
+
resizeObserverConfig,
|
|
14
|
+
isDragging,
|
|
15
|
+
className,
|
|
16
|
+
...props
|
|
17
|
+
}: DroppableProps) => {
|
|
18
|
+
const { isOver, setNodeRef } = useDroppable({
|
|
19
|
+
id,
|
|
20
|
+
data,
|
|
21
|
+
disabled,
|
|
22
|
+
resizeObserverConfig,
|
|
23
|
+
});
|
|
24
|
+
const isEmpty = !children || undefined;
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div
|
|
28
|
+
ref={setNodeRef}
|
|
29
|
+
className={cn(className, getDroppableClasses({ isDragging, isOver, isEmpty }))}
|
|
30
|
+
data-empty={isEmpty}
|
|
31
|
+
data-draggable-over={isOver || undefined}
|
|
32
|
+
data-draggable-active={isDragging || undefined}
|
|
33
|
+
{...props}
|
|
34
|
+
>
|
|
35
|
+
{children}
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Droppable } from "./Droppable";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { UniqueIdentifier } from "@dnd-kit/core";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { DndContext } from "@dnd-kit/core";
|
|
4
|
+
import { arrayMove, SortableContext } from "@dnd-kit/sortable";
|
|
5
|
+
import { cn } from "../../../utilities";
|
|
6
|
+
import { Draggable } from "../Draggable";
|
|
7
|
+
import { Sortable } from "./Sortable";
|
|
8
|
+
import { type SortableProps } from "./types";
|
|
9
|
+
|
|
10
|
+
type SortableExampleProps = Partial<SortableProps> & { hasDraggableOverlay?: boolean };
|
|
11
|
+
|
|
12
|
+
export const SortableExample = ({ hasDraggableOverlay, ...props }: SortableExampleProps) => {
|
|
13
|
+
const [activeId, setActiveId] = useState<UniqueIdentifier | null>(null);
|
|
14
|
+
const [items, setItems] = useState<UniqueIdentifier[]>(["1", "2", "3", "4", "5", "6", "7", "8"]);
|
|
15
|
+
|
|
16
|
+
const activeIndex = activeId ? items.indexOf(activeId) : -1;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<DndContext
|
|
20
|
+
onDragStart={({ active }) => {
|
|
21
|
+
if (!active) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
setActiveId(active.id);
|
|
26
|
+
}}
|
|
27
|
+
onDragEnd={({ over }) => {
|
|
28
|
+
setActiveId(null);
|
|
29
|
+
|
|
30
|
+
if (over) {
|
|
31
|
+
const overIndex = items.indexOf(over.id);
|
|
32
|
+
if (activeIndex !== overIndex) {
|
|
33
|
+
setItems((items) => arrayMove(items, activeIndex, overIndex));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}}
|
|
37
|
+
onDragCancel={() => setActiveId(null)}
|
|
38
|
+
>
|
|
39
|
+
<SortableContext items={items}>
|
|
40
|
+
<div className="grid grid-cols-3 gap-4">
|
|
41
|
+
{items.map((item) => (
|
|
42
|
+
<Sortable
|
|
43
|
+
{...props}
|
|
44
|
+
key={item}
|
|
45
|
+
id={item}
|
|
46
|
+
className={cn(
|
|
47
|
+
"flex items-center justify-center w-32 h-32 bg-base-100 border border-primary-content/30 rounded-md text-sm p-2 data-[draggable]:shadow data-[draggable-active]:z-20",
|
|
48
|
+
{
|
|
49
|
+
"data-[draggable-active]:opacity-30": hasDraggableOverlay,
|
|
50
|
+
}
|
|
51
|
+
)}
|
|
52
|
+
>
|
|
53
|
+
{item}
|
|
54
|
+
</Sortable>
|
|
55
|
+
))}
|
|
56
|
+
{hasDraggableOverlay ? <Draggable.Overlay className="bg-base-100 shadow-lg" /> : null}
|
|
57
|
+
</div>
|
|
58
|
+
</SortableContext>
|
|
59
|
+
</DndContext>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useSortable } from "@dnd-kit/sortable";
|
|
2
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
3
|
+
import { cn } from "../../../utilities";
|
|
4
|
+
import { Draggable } from "../Draggable";
|
|
5
|
+
import { getSortableClasses } from "./constants";
|
|
6
|
+
import { type SortableProps } from "./types";
|
|
7
|
+
|
|
8
|
+
export const Sortable = ({
|
|
9
|
+
id,
|
|
10
|
+
data,
|
|
11
|
+
style,
|
|
12
|
+
className,
|
|
13
|
+
children,
|
|
14
|
+
disabled,
|
|
15
|
+
attributes,
|
|
16
|
+
resizeObserverConfig,
|
|
17
|
+
animateLayoutChanges,
|
|
18
|
+
getNewIndex,
|
|
19
|
+
strategy,
|
|
20
|
+
transition,
|
|
21
|
+
...props
|
|
22
|
+
}: SortableProps) => {
|
|
23
|
+
const {
|
|
24
|
+
attributes: sortableAttributes,
|
|
25
|
+
isDragging,
|
|
26
|
+
isSorting,
|
|
27
|
+
listeners,
|
|
28
|
+
setNodeRef,
|
|
29
|
+
setActivatorNodeRef,
|
|
30
|
+
transform,
|
|
31
|
+
transition: sortableTransition,
|
|
32
|
+
} = useSortable({
|
|
33
|
+
id,
|
|
34
|
+
data,
|
|
35
|
+
disabled,
|
|
36
|
+
attributes,
|
|
37
|
+
transition,
|
|
38
|
+
resizeObserverConfig,
|
|
39
|
+
animateLayoutChanges,
|
|
40
|
+
getNewIndex,
|
|
41
|
+
strategy,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Draggable.Root
|
|
46
|
+
{...props}
|
|
47
|
+
{...sortableAttributes}
|
|
48
|
+
ref={setNodeRef}
|
|
49
|
+
activatorNodeRef={setActivatorNodeRef}
|
|
50
|
+
isDragging={isDragging}
|
|
51
|
+
listeners={listeners}
|
|
52
|
+
transform={transform}
|
|
53
|
+
style={{
|
|
54
|
+
...style,
|
|
55
|
+
transform: CSS.Transform.toString(transform),
|
|
56
|
+
transition: sortableTransition,
|
|
57
|
+
}}
|
|
58
|
+
className={cn(className, getSortableClasses({ isDragging, isSorting }))}
|
|
59
|
+
data-draggable={true}
|
|
60
|
+
data-draggable-active={isDragging || undefined}
|
|
61
|
+
>
|
|
62
|
+
{children}
|
|
63
|
+
</Draggable.Root>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Sortable } from "./Sortable";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { UseSortableArguments } from "@dnd-kit/sortable";
|
|
2
|
+
import type { CSSProperties } from "react";
|
|
3
|
+
import type { DraggableAxis, DraggableRootProps } from "../Draggable/types";
|
|
4
|
+
|
|
5
|
+
export type SortableProps = Omit<React.HTMLAttributes<HTMLDivElement>, "id"> &
|
|
6
|
+
UseSortableArguments &
|
|
7
|
+
Pick<DraggableRootProps, "handle" | "actions"> &
|
|
8
|
+
Partial<{
|
|
9
|
+
axis: DraggableAxis;
|
|
10
|
+
style: CSSProperties;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Sortable } from "../DragAndDrop";
|
|
4
|
+
import { useWidget } from "./hooks";
|
|
5
|
+
import { WidgetProps } from "./types";
|
|
6
|
+
|
|
7
|
+
export const Widget = ({ id, children, actions, ...props }: WidgetProps) => {
|
|
8
|
+
const { widget, deleteWidget } = useWidget(id);
|
|
9
|
+
|
|
10
|
+
if (!widget) return null;
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<Sortable id={id} actions={(args) => actions?.({ deleteWidget, ...args })} {...props}>
|
|
14
|
+
{children}
|
|
15
|
+
</Sortable>
|
|
16
|
+
);
|
|
17
|
+
};
|