@yamada-ui/resizable 1.0.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/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/chunk-DVZSQNDW.mjs +185 -0
- package/dist/chunk-OSM43TND.mjs +42 -0
- package/dist/chunk-PA5IMAOA.mjs +33 -0
- package/dist/chunk-VSORTT66.mjs +104 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +360 -0
- package/dist/index.mjs +17 -0
- package/dist/resizable-item.d.mts +16 -0
- package/dist/resizable-item.d.ts +16 -0
- package/dist/resizable-item.js +131 -0
- package/dist/resizable-item.mjs +7 -0
- package/dist/resizable-trigger.d.mts +24 -0
- package/dist/resizable-trigger.d.ts +24 -0
- package/dist/resizable-trigger.js +185 -0
- package/dist/resizable-trigger.mjs +9 -0
- package/dist/resizable.d.mts +22 -0
- package/dist/resizable.d.ts +22 -0
- package/dist/resizable.js +114 -0
- package/dist/resizable.mjs +7 -0
- package/dist/use-resizable.d.mts +162 -0
- package/dist/use-resizable.d.ts +162 -0
- package/dist/use-resizable.js +209 -0
- package/dist/use-resizable.mjs +14 -0
- package/package.json +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Hirotomo Yamada
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @yamada-ui/resizable
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
$ pnpm add @yamada-ui/resizable
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
or
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
$ yarn add @yamada-ui/resizable
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
or
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
$ npm install @yamada-ui/resizable
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Contribution
|
|
22
|
+
|
|
23
|
+
Wouldn't you like to contribute? That's amazing! We have prepared a [contribution guide](./CONTRIBUTING.md) to assist you.
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
This package is licensed under the terms of the
|
|
28
|
+
[MIT license](https://github.com/hirotomoyamada/yamada-ui/blob/main/LICENSE).
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// src/use-resizable.ts
|
|
2
|
+
import { createContext, dataAttr, handlerAll } from "@yamada-ui/utils";
|
|
3
|
+
import { useCallback, useEffect, useId, useState } from "react";
|
|
4
|
+
import {
|
|
5
|
+
getPanelElement,
|
|
6
|
+
getPanelGroupElement,
|
|
7
|
+
getResizeHandleElement
|
|
8
|
+
} from "react-resizable-panels";
|
|
9
|
+
var [ResizableProvider, useResizableContext] = createContext({
|
|
10
|
+
name: "ResizableContext",
|
|
11
|
+
errorMessage: `useResizableContext returned is 'undefined'. Seems you forgot to wrap the components in "<Resizable />"`
|
|
12
|
+
});
|
|
13
|
+
var useResizable = ({
|
|
14
|
+
id,
|
|
15
|
+
direction = "horizontal",
|
|
16
|
+
storageKey,
|
|
17
|
+
keyboardStep,
|
|
18
|
+
isDisabled = false,
|
|
19
|
+
onLayout,
|
|
20
|
+
storage,
|
|
21
|
+
ref,
|
|
22
|
+
groupProps,
|
|
23
|
+
...rest
|
|
24
|
+
}) => {
|
|
25
|
+
id != null ? id : id = useId();
|
|
26
|
+
const getContainerProps = useCallback(
|
|
27
|
+
(props = {}, ref2 = null) => ({ ...props, ref: ref2, ...rest }),
|
|
28
|
+
[rest]
|
|
29
|
+
);
|
|
30
|
+
const getGroupProps = useCallback(
|
|
31
|
+
(props = {}) => {
|
|
32
|
+
const { as, ...rest2 } = groupProps != null ? groupProps : {};
|
|
33
|
+
return {
|
|
34
|
+
...props,
|
|
35
|
+
id,
|
|
36
|
+
direction,
|
|
37
|
+
tagName: as,
|
|
38
|
+
autoSaveId: storageKey,
|
|
39
|
+
keyboardResizeBy: keyboardStep,
|
|
40
|
+
onLayout,
|
|
41
|
+
storage,
|
|
42
|
+
...rest2
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
[id, direction, groupProps, storageKey, keyboardStep, onLayout, storage]
|
|
46
|
+
);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!id)
|
|
49
|
+
return;
|
|
50
|
+
const el = getPanelGroupElement(id);
|
|
51
|
+
if (ref)
|
|
52
|
+
ref.current = el;
|
|
53
|
+
}, [ref, id]);
|
|
54
|
+
return {
|
|
55
|
+
isDisabled,
|
|
56
|
+
getContainerProps,
|
|
57
|
+
getGroupProps
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
var useResizableItem = ({
|
|
61
|
+
id,
|
|
62
|
+
ref,
|
|
63
|
+
collapsedSize,
|
|
64
|
+
collapsible,
|
|
65
|
+
defaultSize,
|
|
66
|
+
maxSize,
|
|
67
|
+
minSize,
|
|
68
|
+
onCollapse,
|
|
69
|
+
onExpand,
|
|
70
|
+
onResize,
|
|
71
|
+
order,
|
|
72
|
+
controlRef,
|
|
73
|
+
itemProps,
|
|
74
|
+
...innerProps
|
|
75
|
+
}) => {
|
|
76
|
+
id != null ? id : id = useId();
|
|
77
|
+
const getPanelProps = useCallback(
|
|
78
|
+
(props = {}) => {
|
|
79
|
+
const { as, ...rest } = itemProps != null ? itemProps : {};
|
|
80
|
+
return {
|
|
81
|
+
...props,
|
|
82
|
+
ref: controlRef,
|
|
83
|
+
id,
|
|
84
|
+
tagName: as,
|
|
85
|
+
collapsible,
|
|
86
|
+
defaultSize,
|
|
87
|
+
maxSize,
|
|
88
|
+
minSize,
|
|
89
|
+
collapsedSize,
|
|
90
|
+
onCollapse,
|
|
91
|
+
onExpand,
|
|
92
|
+
onResize,
|
|
93
|
+
order,
|
|
94
|
+
...rest
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
[
|
|
98
|
+
id,
|
|
99
|
+
controlRef,
|
|
100
|
+
itemProps,
|
|
101
|
+
collapsedSize,
|
|
102
|
+
collapsible,
|
|
103
|
+
defaultSize,
|
|
104
|
+
maxSize,
|
|
105
|
+
minSize,
|
|
106
|
+
onCollapse,
|
|
107
|
+
onExpand,
|
|
108
|
+
onResize,
|
|
109
|
+
order
|
|
110
|
+
]
|
|
111
|
+
);
|
|
112
|
+
const getItemProps = useCallback(
|
|
113
|
+
(props = {}, ref2 = null) => ({ ...props, ref: ref2, ...innerProps }),
|
|
114
|
+
[innerProps]
|
|
115
|
+
);
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (!id)
|
|
118
|
+
return;
|
|
119
|
+
const el = getPanelElement(id);
|
|
120
|
+
if (ref)
|
|
121
|
+
ref.current = el;
|
|
122
|
+
}, [ref, id]);
|
|
123
|
+
return {
|
|
124
|
+
getPanelProps,
|
|
125
|
+
getItemProps
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
var useResizableTrigger = ({
|
|
129
|
+
id,
|
|
130
|
+
ref,
|
|
131
|
+
as,
|
|
132
|
+
disabled,
|
|
133
|
+
isDisabled,
|
|
134
|
+
onDragging,
|
|
135
|
+
...rest
|
|
136
|
+
}) => {
|
|
137
|
+
id != null ? id : id = useId();
|
|
138
|
+
const { isDisabled: isGroupDisabled } = useResizableContext();
|
|
139
|
+
const [isActive, setIsActive] = useState(false);
|
|
140
|
+
const trulyDisabled = disabled || isDisabled || isGroupDisabled;
|
|
141
|
+
const getTriggerProps = useCallback(
|
|
142
|
+
(props = {}) => ({
|
|
143
|
+
...props,
|
|
144
|
+
id,
|
|
145
|
+
tagName: as,
|
|
146
|
+
disabled: trulyDisabled,
|
|
147
|
+
onDragging: handlerAll(onDragging, (isActive2) => setIsActive(isActive2)),
|
|
148
|
+
...rest,
|
|
149
|
+
"data-active": dataAttr(isActive),
|
|
150
|
+
style: {
|
|
151
|
+
...props.style,
|
|
152
|
+
...rest.style,
|
|
153
|
+
...trulyDisabled ? { cursor: "default" } : {}
|
|
154
|
+
}
|
|
155
|
+
}),
|
|
156
|
+
[id, as, trulyDisabled, onDragging, rest, isActive]
|
|
157
|
+
);
|
|
158
|
+
const getIconProps = useCallback(
|
|
159
|
+
(props = {}, ref2 = null) => ({
|
|
160
|
+
...props,
|
|
161
|
+
ref: ref2,
|
|
162
|
+
"data-active": dataAttr(isActive)
|
|
163
|
+
}),
|
|
164
|
+
[isActive]
|
|
165
|
+
);
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
if (!id)
|
|
168
|
+
return;
|
|
169
|
+
const el = getResizeHandleElement(id);
|
|
170
|
+
if (ref)
|
|
171
|
+
ref.current = el;
|
|
172
|
+
}, [ref, id]);
|
|
173
|
+
return {
|
|
174
|
+
getTriggerProps,
|
|
175
|
+
getIconProps
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export {
|
|
180
|
+
ResizableProvider,
|
|
181
|
+
useResizableContext,
|
|
182
|
+
useResizable,
|
|
183
|
+
useResizableItem,
|
|
184
|
+
useResizableTrigger
|
|
185
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ResizableProvider,
|
|
3
|
+
useResizable
|
|
4
|
+
} from "./chunk-DVZSQNDW.mjs";
|
|
5
|
+
|
|
6
|
+
// src/resizable.tsx
|
|
7
|
+
import {
|
|
8
|
+
ui,
|
|
9
|
+
forwardRef,
|
|
10
|
+
useMultiComponentStyle,
|
|
11
|
+
omitThemeProps
|
|
12
|
+
} from "@yamada-ui/core";
|
|
13
|
+
import { cx } from "@yamada-ui/utils";
|
|
14
|
+
import { PanelGroup } from "react-resizable-panels";
|
|
15
|
+
import { jsx } from "react/jsx-runtime";
|
|
16
|
+
var Resizable = forwardRef(
|
|
17
|
+
({ direction = "horizontal", ...props }, ref) => {
|
|
18
|
+
const [styles, mergedProps] = useMultiComponentStyle("Resizable", {
|
|
19
|
+
direction,
|
|
20
|
+
...props
|
|
21
|
+
});
|
|
22
|
+
const { className, children, containerRef, ...computedProps } = omitThemeProps(mergedProps);
|
|
23
|
+
const { getContainerProps, getGroupProps, ...rest } = useResizable({
|
|
24
|
+
ref,
|
|
25
|
+
...computedProps
|
|
26
|
+
});
|
|
27
|
+
const css = { w: "full", h: "full", ...styles.container };
|
|
28
|
+
return /* @__PURE__ */ jsx(ResizableProvider, { value: { styles, ...rest }, children: /* @__PURE__ */ jsx(
|
|
29
|
+
ui.div,
|
|
30
|
+
{
|
|
31
|
+
className: cx("ui-resizable", className),
|
|
32
|
+
__css: css,
|
|
33
|
+
...getContainerProps({}, containerRef),
|
|
34
|
+
children: /* @__PURE__ */ jsx(PanelGroup, { ...getGroupProps(), children })
|
|
35
|
+
}
|
|
36
|
+
) });
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
Resizable
|
|
42
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useResizableContext,
|
|
3
|
+
useResizableItem
|
|
4
|
+
} from "./chunk-DVZSQNDW.mjs";
|
|
5
|
+
|
|
6
|
+
// src/resizable-item.tsx
|
|
7
|
+
import { ui, forwardRef } from "@yamada-ui/core";
|
|
8
|
+
import { cx } from "@yamada-ui/utils";
|
|
9
|
+
import { Panel } from "react-resizable-panels";
|
|
10
|
+
import { jsx } from "react/jsx-runtime";
|
|
11
|
+
var ResizableItem = forwardRef(
|
|
12
|
+
({ className, children, innerRef, ...rest }, ref) => {
|
|
13
|
+
const { styles } = useResizableContext();
|
|
14
|
+
const { getPanelProps, getItemProps } = useResizableItem({
|
|
15
|
+
ref,
|
|
16
|
+
...rest
|
|
17
|
+
});
|
|
18
|
+
const css = { boxSize: "full", ...styles.item };
|
|
19
|
+
return /* @__PURE__ */ jsx(Panel, { ...getPanelProps(), children: /* @__PURE__ */ jsx(
|
|
20
|
+
ui.div,
|
|
21
|
+
{
|
|
22
|
+
className: cx("ui-resizable__item", className),
|
|
23
|
+
__css: css,
|
|
24
|
+
...getItemProps({}, innerRef),
|
|
25
|
+
children
|
|
26
|
+
}
|
|
27
|
+
) });
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
ResizableItem
|
|
33
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useResizableContext,
|
|
3
|
+
useResizableTrigger
|
|
4
|
+
} from "./chunk-DVZSQNDW.mjs";
|
|
5
|
+
|
|
6
|
+
// src/resizable-trigger.tsx
|
|
7
|
+
import { ui, forwardRef } from "@yamada-ui/core";
|
|
8
|
+
import { Icon } from "@yamada-ui/icon";
|
|
9
|
+
import { cx } from "@yamada-ui/utils";
|
|
10
|
+
import { PanelResizeHandle } from "react-resizable-panels";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
var ResizableTrigger = forwardRef(
|
|
13
|
+
({ className, icon, children, iconProps, ...rest }, ref) => {
|
|
14
|
+
const { styles } = useResizableContext();
|
|
15
|
+
const { getTriggerProps, getIconProps } = useResizableTrigger({
|
|
16
|
+
ref,
|
|
17
|
+
...rest
|
|
18
|
+
});
|
|
19
|
+
const css = { position: "relative", ...styles.trigger };
|
|
20
|
+
return /* @__PURE__ */ jsxs(
|
|
21
|
+
ui.div,
|
|
22
|
+
{
|
|
23
|
+
as: PanelResizeHandle,
|
|
24
|
+
className: cx("ui-resizable__trigger", className),
|
|
25
|
+
__css: css,
|
|
26
|
+
...getTriggerProps(),
|
|
27
|
+
children: [
|
|
28
|
+
icon ? /* @__PURE__ */ jsx(
|
|
29
|
+
ui.div,
|
|
30
|
+
{
|
|
31
|
+
className: "ui-resizable__trigger__icon",
|
|
32
|
+
__css: {
|
|
33
|
+
position: "absolute",
|
|
34
|
+
top: "50%",
|
|
35
|
+
left: "50%",
|
|
36
|
+
transform: "auto",
|
|
37
|
+
translateY: "-50%",
|
|
38
|
+
translateX: "-50%",
|
|
39
|
+
display: "flex",
|
|
40
|
+
justifyContent: "center",
|
|
41
|
+
alignItems: "center",
|
|
42
|
+
...styles.icon
|
|
43
|
+
},
|
|
44
|
+
...getIconProps(iconProps),
|
|
45
|
+
children: icon
|
|
46
|
+
}
|
|
47
|
+
) : null,
|
|
48
|
+
children
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
var ResizableTriggerIcon = (rest) => {
|
|
55
|
+
return /* @__PURE__ */ jsxs(Icon, { viewBox: "0 0 23 39", w: "2", h: "4", ...rest, children: [
|
|
56
|
+
/* @__PURE__ */ jsx(
|
|
57
|
+
"path",
|
|
58
|
+
{
|
|
59
|
+
d: "M 5 0 C 7.761 0 10 2.239 10 5 C 10 7.761 7.761 10 5 10 C 2.239 10 0 7.761 0 5 C 0 2.239 2.239 0 5 0 Z",
|
|
60
|
+
fill: "currentColor"
|
|
61
|
+
}
|
|
62
|
+
),
|
|
63
|
+
/* @__PURE__ */ jsx(
|
|
64
|
+
"path",
|
|
65
|
+
{
|
|
66
|
+
d: "M 19 0 C 21.761 0 24 2.239 24 5 C 24 7.761 21.761 10 19 10 C 16.239 10 14 7.761 14 5 C 14 2.239 16.239 0 19 0 Z",
|
|
67
|
+
fill: "currentColor"
|
|
68
|
+
}
|
|
69
|
+
),
|
|
70
|
+
/* @__PURE__ */ jsx(
|
|
71
|
+
"path",
|
|
72
|
+
{
|
|
73
|
+
d: "M 19 14 C 21.761 14 24 16.239 24 19 C 24 21.761 21.761 24 19 24 C 16.239 24 14 21.761 14 19 C 14 16.239 16.239 14 19 14 Z",
|
|
74
|
+
fill: "currentColor"
|
|
75
|
+
}
|
|
76
|
+
),
|
|
77
|
+
/* @__PURE__ */ jsx(
|
|
78
|
+
"path",
|
|
79
|
+
{
|
|
80
|
+
d: "M 5 14 C 7.761 14 10 16.239 10 19 C 10 21.761 7.761 24 5 24 C 2.239 24 0 21.761 0 19 C 0 16.239 2.239 14 5 14 Z",
|
|
81
|
+
fill: "currentColor"
|
|
82
|
+
}
|
|
83
|
+
),
|
|
84
|
+
/* @__PURE__ */ jsx(
|
|
85
|
+
"path",
|
|
86
|
+
{
|
|
87
|
+
d: "M 5 28 C 7.761 28 10 30.239 10 33 C 10 35.761 7.761 38 5 38 C 2.239 38 0 35.761 0 33 C 0 30.239 2.239 28 5 28 Z",
|
|
88
|
+
fill: "currentColor"
|
|
89
|
+
}
|
|
90
|
+
),
|
|
91
|
+
/* @__PURE__ */ jsx(
|
|
92
|
+
"path",
|
|
93
|
+
{
|
|
94
|
+
d: "M 19 28 C 21.761 28 24 30.239 24 33 C 24 35.761 21.761 38 19 38 C 16.239 38 14 35.761 14 33 C 14 30.239 16.239 28 19 28 Z",
|
|
95
|
+
fill: "currentColor"
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
] });
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export {
|
|
102
|
+
ResizableTrigger,
|
|
103
|
+
ResizableTriggerIcon
|
|
104
|
+
};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Resizable, ResizableProps } from './resizable.mjs';
|
|
2
|
+
export { ResizableItem, ResizableItemProps } from './resizable-item.mjs';
|
|
3
|
+
export { ResizableTrigger, ResizableTriggerIcon, ResizableTriggerIconProps, ResizableTriggerProps } from './resizable-trigger.mjs';
|
|
4
|
+
export { ResizableItemControl, ResizableStorage } from './use-resizable.mjs';
|
|
5
|
+
import '@yamada-ui/core';
|
|
6
|
+
import 'react';
|
|
7
|
+
import '@yamada-ui/icon';
|
|
8
|
+
import '@yamada-ui/utils';
|
|
9
|
+
import 'react-resizable-panels';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Resizable, ResizableProps } from './resizable.js';
|
|
2
|
+
export { ResizableItem, ResizableItemProps } from './resizable-item.js';
|
|
3
|
+
export { ResizableTrigger, ResizableTriggerIcon, ResizableTriggerIconProps, ResizableTriggerProps } from './resizable-trigger.js';
|
|
4
|
+
export { ResizableItemControl, ResizableStorage } from './use-resizable.js';
|
|
5
|
+
import '@yamada-ui/core';
|
|
6
|
+
import 'react';
|
|
7
|
+
import '@yamada-ui/icon';
|
|
8
|
+
import '@yamada-ui/utils';
|
|
9
|
+
import 'react-resizable-panels';
|