@gfazioli/mantine-split-pane 1.0.0 → 1.0.2

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