@gfazioli/mantine-split-pane 1.0.3 → 1.1.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.
@@ -1,6 +1,6 @@
1
1
  'use client';
2
- import { createVarsResolver, parseThemeColor, getSize, rgba, getRadius, getThemeColor, factory, useProps, useStyles, UnstyledButton } from '@mantine/core';
3
2
  import React, { useRef } from 'react';
3
+ import { createVarsResolver, parseThemeColor, getSize, rgba, getRadius, getThemeColor, factory, useProps, useStyles, UnstyledButton } from '@mantine/core';
4
4
  import classes from './SplitPaneResizer.module.css.mjs';
5
5
 
6
6
  const varsResolver = createVarsResolver(
@@ -43,32 +43,17 @@ const varsResolver = createVarsResolver(
43
43
  root: {
44
44
  "--split-resizer-size": getSize(size, "split-resizer-size"),
45
45
  "--split-resizer-color": rgba(colorLightParsed.value, Number(opacity)),
46
- "--split-resizer-color-light": rgba(
47
- colorLightParsed.value,
48
- Number(opacity)
49
- ),
50
- "--split-resizer-color-dark": rgba(
51
- colorDarkParsed.value,
52
- Number(opacity)
53
- ),
54
- "--split-resizer-hover-color-light": rgba(
55
- hoverColorLightParsed.value,
56
- 1
57
- ),
46
+ "--split-resizer-color-light": rgba(colorLightParsed.value, Number(opacity)),
47
+ "--split-resizer-color-dark": rgba(colorDarkParsed.value, Number(opacity)),
48
+ "--split-resizer-hover-color-light": rgba(hoverColorLightParsed.value, 1),
58
49
  "--split-resizer-hover-color-dark": rgba(hoverColorDarkParsed.value, 1),
59
50
  "--split-resizer-radius": getRadius(radius),
60
- "--split-resizer-knob-size": getSize(
61
- knobSize,
62
- "split-resizer-knob-size"
63
- ),
51
+ "--split-resizer-knob-size": getSize(knobSize, "split-resizer-knob-size"),
64
52
  "--split-resizer-knob-opacity": withKnob && knobAlwaysOn && !knobVariant ? knobOpacity : "0",
65
53
  "--split-resizer-knob-hover-opacity": withKnob || knobVariant ? "1" : "0",
66
54
  "--split-resizer-knob-radius": getRadius(knobRadius),
67
55
  "--split-resizer-knob-color": getThemeColor(knobColor, theme),
68
- "--split-resizer-knob-hover-color": getThemeColor(
69
- knobHoverColor,
70
- theme
71
- ),
56
+ "--split-resizer-knob-hover-color": getThemeColor(knobHoverColor, theme),
72
57
  "--split-resizer-spacing": getSize(spacing, "split-resizer-spacing"),
73
58
  "--split-resizer-cursor-vertical": cursorVertical || "col-resize",
74
59
  "--split-resizer-cursor-horizontal": cursorHorizontal || "row-resize"
@@ -96,192 +81,179 @@ const defaultProps = {
96
81
  cursorVertical: "col-resize",
97
82
  cursorHorizontal: "row-resize"
98
83
  };
99
- const SplitPaneResizer = factory(
100
- (_props, ref) => {
101
- const props = useProps("Resizer", defaultProps, _props);
102
- const {
103
- size,
104
- opacity,
105
- radius,
106
- color,
107
- hoverColor,
108
- knobSize,
109
- knobOpacity,
110
- knobRadius,
111
- knobColor,
112
- knobHoverColor,
113
- minWidth,
114
- minHeight,
115
- maxWidth,
116
- maxHeight,
117
- orientation,
118
- onResizeStart,
119
- onResizing,
120
- onResizeEnd,
121
- paneRef,
122
- variant,
123
- withKnob,
124
- knobAlwaysOn,
125
- spacing,
126
- step,
127
- shiftStep,
128
- cursorVertical,
129
- cursorHorizontal,
130
- className,
131
- style,
132
- classNames,
133
- styles,
134
- unstyled,
135
- vars,
136
- mod,
137
- ...others
138
- } = props;
139
- const getStyles = useStyles({
140
- name: "SplitPaneResizer",
141
- classes,
142
- props,
143
- className,
144
- style,
145
- classNames,
146
- styles,
147
- unstyled,
148
- vars,
149
- varsResolver
150
- });
151
- const containerRef = useRef(null);
152
- const handleStart = (event) => {
84
+ const SplitPaneResizer = factory((_props, ref) => {
85
+ const props = useProps("Resizer", defaultProps, _props);
86
+ const {
87
+ size,
88
+ opacity,
89
+ radius,
90
+ color,
91
+ hoverColor,
92
+ knobSize,
93
+ knobOpacity,
94
+ knobRadius,
95
+ knobColor,
96
+ knobHoverColor,
97
+ minWidth,
98
+ minHeight,
99
+ maxWidth,
100
+ maxHeight,
101
+ orientation,
102
+ onResizeStart,
103
+ onResizing,
104
+ onResizeEnd,
105
+ paneRef,
106
+ variant,
107
+ withKnob,
108
+ knobAlwaysOn,
109
+ spacing,
110
+ step,
111
+ shiftStep,
112
+ cursorVertical,
113
+ cursorHorizontal,
114
+ className,
115
+ style,
116
+ classNames,
117
+ styles,
118
+ unstyled,
119
+ vars,
120
+ mod,
121
+ ...others
122
+ } = props;
123
+ const getStyles = useStyles({
124
+ name: "SplitPaneResizer",
125
+ classes,
126
+ props,
127
+ className,
128
+ style,
129
+ classNames,
130
+ styles,
131
+ unstyled,
132
+ vars,
133
+ varsResolver
134
+ });
135
+ const containerRef = useRef(null);
136
+ const handleStart = (event) => {
137
+ event.preventDefault();
138
+ event.stopPropagation();
139
+ document.body.style.userSelect = "none";
140
+ document.body.style.webkitUserSelect = "none";
141
+ if (event.type === "mousedown") {
142
+ document.addEventListener("mousemove", handleMove);
143
+ document.addEventListener("mouseup", handleMouseUp);
144
+ }
145
+ if (event.type === "touchstart") {
146
+ document.addEventListener("touchmove", handleMove);
147
+ document.addEventListener("touchend", handleTouchEnd);
148
+ }
149
+ onResizeStart?.();
150
+ document.body.style.cursor = "col-resize";
151
+ };
152
+ const handleMove = (event) => {
153
+ if (!paneRef.current) return;
154
+ event.preventDefault();
155
+ event.stopPropagation();
156
+ const computedStyle = window.getComputedStyle(containerRef.current);
157
+ const clientX = "clientX" in event ? event.clientX : event.touches[0].clientX;
158
+ const clientY = "clientY" in event ? event.clientY : event.touches[0].clientY;
159
+ if (orientation === "vertical") {
160
+ const margin = parseFloat(computedStyle.getPropertyValue("margin-left")) + 1;
161
+ const delta = clientX - paneRef.current.getBoundingClientRect().right - margin;
162
+ const width = paneRef.current.getBoundingClientRect().width + delta;
163
+ const widthString = `${width}px`;
164
+ if (minWidth && width < minWidth) return;
165
+ if (maxWidth && width > maxWidth) return;
166
+ onResizing?.({
167
+ width: widthString,
168
+ height: paneRef.current.style.height
169
+ });
170
+ paneRef.current.style.width = widthString;
171
+ } else {
172
+ const margin = parseFloat(computedStyle.getPropertyValue("margin-top")) + 1;
173
+ const delta = clientY - paneRef.current.getBoundingClientRect().bottom - margin;
174
+ const height = paneRef.current.getBoundingClientRect().height + delta;
175
+ const heightString = `${height}px`;
176
+ if (minHeight && height < minHeight) return;
177
+ if (maxHeight && height > maxHeight) return;
178
+ onResizing?.({
179
+ width: paneRef.current.style.width,
180
+ height: heightString
181
+ });
182
+ paneRef.current.style.height = heightString;
183
+ }
184
+ };
185
+ const handleMouseUp = () => {
186
+ if (!paneRef.current) return;
187
+ document.body.style.userSelect = "initial";
188
+ document.body.style.webkitUserSelect = "initial";
189
+ document.removeEventListener("mousemove", handleMove);
190
+ document.removeEventListener("mouseup", handleMouseUp);
191
+ document.body.style.cursor = "initial";
192
+ const { width, height } = paneRef.current.style || {};
193
+ onResizeEnd?.({ width, height });
194
+ };
195
+ const handleTouchEnd = () => {
196
+ if (!paneRef.current) return;
197
+ document.removeEventListener("touchmove", handleMove);
198
+ document.removeEventListener("touchend", handleTouchEnd);
199
+ document.body.style.cursor = "initial";
200
+ const { width, height } = paneRef.current.style || {};
201
+ onResizeEnd?.({ width, height });
202
+ };
203
+ const handleKeyUp = (event) => {
204
+ if (containerRef.current !== document.activeElement) {
205
+ return;
206
+ }
207
+ const delta = event.shiftKey ? shiftStep : step;
208
+ if (orientation === "vertical" && (event.nativeEvent.code === "ArrowRight" || event.nativeEvent.code === "ArrowLeft")) {
153
209
  event.preventDefault();
154
210
  event.stopPropagation();
155
- document.body.style.userSelect = "none";
156
- document.body.style.webkitUserSelect = "none";
157
- if (event.type === "mousedown") {
158
- document.addEventListener("mousemove", handleMove);
159
- document.addEventListener("mouseup", handleMouseUp);
160
- }
161
- if (event.type === "touchstart") {
162
- document.addEventListener("touchmove", handleMove);
163
- document.addEventListener("touchend", handleTouchEnd);
164
- }
165
- onResizeStart?.();
166
- document.body.style.cursor = "col-resize";
167
- };
168
- const handleMove = (event) => {
169
- if (!paneRef.current)
170
- return;
211
+ const deltaSign = event.nativeEvent.code === "ArrowRight" ? 1 : -1;
212
+ const width = paneRef.current.getBoundingClientRect().width + delta * deltaSign;
213
+ const widthString = `${width}px`;
214
+ if (minWidth && width < minWidth) return;
215
+ if (maxWidth && width > maxWidth) return;
216
+ onResizing?.({
217
+ width: widthString,
218
+ height: paneRef.current.style.height
219
+ });
220
+ paneRef.current.style.width = widthString;
221
+ }
222
+ if (orientation === "horizontal" && (event.nativeEvent.code === "ArrowUp" || event.nativeEvent.code === "ArrowDown")) {
171
223
  event.preventDefault();
172
224
  event.stopPropagation();
173
- const computedStyle = window.getComputedStyle(containerRef.current);
174
- const clientX = "clientX" in event ? event.clientX : event.touches[0].clientX;
175
- const clientY = "clientY" in event ? event.clientY : event.touches[0].clientY;
176
- if (orientation === "vertical") {
177
- const margin = parseFloat(computedStyle.getPropertyValue("margin-left")) + 1;
178
- const delta = clientX - paneRef.current.getBoundingClientRect().right - margin;
179
- const width = paneRef.current.getBoundingClientRect().width + delta;
180
- const widthString = `${width}px`;
181
- if (minWidth && width < minWidth)
182
- return;
183
- if (maxWidth && width > maxWidth)
184
- return;
185
- onResizing?.({
186
- width: widthString,
187
- height: paneRef.current.style.height
188
- });
189
- paneRef.current.style.width = widthString;
190
- } else {
191
- const margin = parseFloat(computedStyle.getPropertyValue("margin-top")) + 1;
192
- const delta = clientY - paneRef.current.getBoundingClientRect().bottom - margin;
193
- const height = paneRef.current.getBoundingClientRect().height + delta;
194
- const heightString = `${height}px`;
195
- if (minHeight && height < minHeight)
196
- return;
197
- if (maxHeight && height > maxHeight)
198
- return;
199
- onResizing?.({
200
- width: paneRef.current.style.width,
201
- height: heightString
202
- });
203
- paneRef.current.style.height = heightString;
204
- }
205
- };
206
- const handleMouseUp = () => {
207
- if (!paneRef.current)
208
- return;
209
- document.body.style.userSelect = "initial";
210
- document.body.style.webkitUserSelect = "initial";
211
- document.removeEventListener("mousemove", handleMove);
212
- document.removeEventListener("mouseup", handleMouseUp);
213
- document.body.style.cursor = "initial";
214
- const { width, height } = paneRef.current.style || {};
215
- onResizeEnd?.({ width, height });
216
- };
217
- const handleTouchEnd = () => {
218
- if (!paneRef.current)
219
- return;
220
- document.removeEventListener("touchmove", handleMove);
221
- document.removeEventListener("touchend", handleTouchEnd);
222
- document.body.style.cursor = "initial";
223
- const { width, height } = paneRef.current.style || {};
224
- onResizeEnd?.({ width, height });
225
- };
226
- const handleKeyUp = (event) => {
227
- if (containerRef.current !== document.activeElement) {
228
- return;
229
- }
230
- const delta = event.shiftKey ? shiftStep : step;
231
- if (orientation === "vertical" && (event.nativeEvent.code === "ArrowRight" || event.nativeEvent.code === "ArrowLeft")) {
232
- event.preventDefault();
233
- event.stopPropagation();
234
- const deltaSign = event.nativeEvent.code === "ArrowRight" ? 1 : -1;
235
- const width = paneRef.current.getBoundingClientRect().width + delta * deltaSign;
236
- const widthString = `${width}px`;
237
- if (minWidth && width < minWidth)
238
- return;
239
- if (maxWidth && width > maxWidth)
240
- return;
241
- onResizing?.({
242
- width: widthString,
243
- height: paneRef.current.style.height
244
- });
245
- paneRef.current.style.width = widthString;
246
- }
247
- if (orientation === "horizontal" && (event.nativeEvent.code === "ArrowUp" || event.nativeEvent.code === "ArrowDown")) {
248
- event.preventDefault();
249
- event.stopPropagation();
250
- const deltaSign = event.nativeEvent.code === "ArrowDown" ? 1 : -1;
251
- const height = paneRef.current.getBoundingClientRect().height + delta * deltaSign;
252
- const heightString = `${height}px`;
253
- if (minHeight && height < minHeight)
254
- return;
255
- if (maxHeight && height > maxHeight)
256
- return;
257
- onResizing?.({
258
- width: paneRef.current.style.width,
259
- height: heightString
260
- });
261
- paneRef.current.style.height = heightString;
262
- }
263
- if (event.nativeEvent.code === "Escape") {
264
- event.preventDefault();
265
- event.stopPropagation();
266
- containerRef.current.blur();
267
- }
268
- };
269
- return /* @__PURE__ */ React.createElement(
270
- UnstyledButton,
271
- {
272
- onDoubleClick: props?.onDoubleClick,
273
- ref: containerRef,
274
- mod: { orientation },
275
- onMouseDown: handleStart,
276
- onKeyDown: handleKeyUp,
277
- onTouchStart: handleStart,
278
- "aria-label": "Resize",
279
- ...getStyles("root", { variant }),
280
- ...others
281
- }
282
- );
283
- }
284
- );
225
+ const deltaSign = event.nativeEvent.code === "ArrowDown" ? 1 : -1;
226
+ const height = paneRef.current.getBoundingClientRect().height + delta * deltaSign;
227
+ const heightString = `${height}px`;
228
+ if (minHeight && height < minHeight) return;
229
+ if (maxHeight && height > maxHeight) return;
230
+ onResizing?.({
231
+ width: paneRef.current.style.width,
232
+ height: heightString
233
+ });
234
+ paneRef.current.style.height = heightString;
235
+ }
236
+ if (event.nativeEvent.code === "Escape") {
237
+ event.preventDefault();
238
+ event.stopPropagation();
239
+ containerRef.current.blur();
240
+ }
241
+ };
242
+ return /* @__PURE__ */ React.createElement(
243
+ UnstyledButton,
244
+ {
245
+ onDoubleClick: props?.onDoubleClick,
246
+ ref: containerRef,
247
+ mod: { orientation },
248
+ onMouseDown: handleStart,
249
+ onKeyDown: handleKeyUp,
250
+ onTouchStart: handleStart,
251
+ "aria-label": "Resize",
252
+ ...getStyles("root", { variant }),
253
+ ...others
254
+ }
255
+ );
256
+ });
285
257
  SplitPaneResizer.classes = classes;
286
258
  SplitPaneResizer.displayName = "SplitPaneResizer";
287
259