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