@mantine/core 9.5.0 → 9.5.1-alpha.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.
- package/cjs/components/FloatingWindow/FloatingWindow.cjs +5 -2
- package/cjs/components/FloatingWindow/FloatingWindow.cjs.map +1 -1
- package/cjs/components/FloatingWindow/FloatingWindow.context.cjs.map +1 -1
- package/cjs/components/FloatingWindow/FloatingWindowResizeHandle.cjs +53 -28
- package/cjs/components/FloatingWindow/FloatingWindowResizeHandle.cjs.map +1 -1
- package/cjs/components/Input/InputLabel/InputLabel.cjs +3 -1
- package/cjs/components/Input/InputLabel/InputLabel.cjs.map +1 -1
- package/cjs/components/Input/InputWrapper/InputWrapper.cjs.map +1 -1
- package/esm/components/FloatingWindow/FloatingWindow.context.mjs.map +1 -1
- package/esm/components/FloatingWindow/FloatingWindow.mjs +5 -2
- package/esm/components/FloatingWindow/FloatingWindow.mjs.map +1 -1
- package/esm/components/FloatingWindow/FloatingWindowResizeHandle.mjs +53 -28
- package/esm/components/FloatingWindow/FloatingWindowResizeHandle.mjs.map +1 -1
- package/esm/components/Input/InputLabel/InputLabel.mjs +3 -1
- package/esm/components/Input/InputLabel/InputLabel.mjs.map +1 -1
- package/esm/components/Input/InputWrapper/InputWrapper.mjs.map +1 -1
- package/lib/components/FloatingWindow/FloatingWindow.context.d.ts +9 -0
- package/lib/components/FloatingWindow/FloatingWindow.d.ts +7 -1
- package/lib/components/FloatingWindow/index.d.ts +1 -1
- package/lib/components/Input/InputWrapper/InputWrapper.d.ts +5 -5
- package/lib/components/Input/use-input-props.d.ts +4 -4
- package/lib/components/MaskInput/use-mask-input-props.d.ts +4 -4
- package/package.json +2 -2
|
@@ -24,7 +24,7 @@ function clampDimension(value, min, max) {
|
|
|
24
24
|
}
|
|
25
25
|
const FloatingWindow = require_factory.factory((_props) => {
|
|
26
26
|
const props = require_use_props.useProps("FloatingWindow", defaultProps, _props);
|
|
27
|
-
const { classNames, className, style, styles, unstyled, vars, mod, enabled, constrainToViewport, constrainOffset, dragHandleSelector, excludeDragHandleSelector, axis, initialPosition, onPositionChange, onDragStart, onDragEnd, setPositionRef, withinPortal, portalProps, zIndex, dimensions, ref, ...others } = props;
|
|
27
|
+
const { classNames, className, style, styles, unstyled, vars, mod, enabled, constrainToViewport, constrainOffset, dragHandleSelector, excludeDragHandleSelector, axis, initialPosition, onPositionChange, onDragStart, onDragEnd, setPositionRef, withinPortal, portalProps, zIndex, dimensions, onSizeChange, onResizeStart, onResizeEnd, ref, ...others } = props;
|
|
28
28
|
const rootRef = (0, react.useRef)(null);
|
|
29
29
|
const getStyles = require_use_styles.useStyles({
|
|
30
30
|
name: "FloatingWindow",
|
|
@@ -58,7 +58,10 @@ const FloatingWindow = require_factory.factory((_props) => {
|
|
|
58
58
|
rootRef,
|
|
59
59
|
dimensions,
|
|
60
60
|
constrainToViewport,
|
|
61
|
-
constrainOffset
|
|
61
|
+
constrainOffset,
|
|
62
|
+
onSizeChange,
|
|
63
|
+
onResizeStart,
|
|
64
|
+
onResizeEnd
|
|
62
65
|
},
|
|
63
66
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_OptionalPortal.OptionalPortal, {
|
|
64
67
|
withinPortal,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FloatingWindow.cjs","names":["getDefaultZIndex","factory","useProps","useStyles","FloatingWindowProvider","OptionalPortal","Paper","classes","FloatingWindowResizeHandle"],"sources":["../../../src/components/FloatingWindow/FloatingWindow.tsx"],"sourcesContent":["import { useImperativeHandle, useRef } from 'react';\nimport {\n SetFloatingWindowPosition,\n useFloatingWindow,\n UseFloatingWindowOptions,\n useMergedRef,\n} from '@mantine/hooks';\nimport {\n BoxProps,\n ElementProps,\n factory,\n Factory,\n getDefaultZIndex,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport { Paper, PaperBaseProps } from '../Paper';\nimport { OptionalPortal, PortalProps } from '../Portal';\nimport {
|
|
1
|
+
{"version":3,"file":"FloatingWindow.cjs","names":["getDefaultZIndex","factory","useProps","useStyles","FloatingWindowProvider","OptionalPortal","Paper","classes","FloatingWindowResizeHandle"],"sources":["../../../src/components/FloatingWindow/FloatingWindow.tsx"],"sourcesContent":["import { useImperativeHandle, useRef } from 'react';\nimport {\n SetFloatingWindowPosition,\n useFloatingWindow,\n UseFloatingWindowOptions,\n useMergedRef,\n} from '@mantine/hooks';\nimport {\n BoxProps,\n ElementProps,\n factory,\n Factory,\n getDefaultZIndex,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport { Paper, PaperBaseProps } from '../Paper';\nimport { OptionalPortal, PortalProps } from '../Portal';\nimport {\n FloatingWindowDimensions,\n FloatingWindowProvider,\n FloatingWindowSize,\n} from './FloatingWindow.context';\nimport { FloatingWindowResizeHandle } from './FloatingWindowResizeHandle';\nimport classes from './FloatingWindow.module.css';\n\nexport type FloatingWindowStylesNames = 'root';\n\nexport interface FloatingWindowProps\n extends\n UseFloatingWindowOptions,\n PaperBaseProps,\n BoxProps,\n StylesApiProps<FloatingWindowFactory>,\n ElementProps<'div', keyof UseFloatingWindowOptions> {\n /** Assigns ref to set position programmatically */\n setPositionRef?: React.RefObject<SetFloatingWindowPosition | null>;\n\n /** Determines whether the window should be rendered inside `Portal` @default true */\n withinPortal?: boolean;\n\n /** Props passed down to `Portal` component */\n portalProps?: Omit<PortalProps, 'children'>;\n\n /** `z-index` of the root element @default 400 */\n zIndex?: React.CSSProperties['zIndex'];\n\n /** Dimensions configuration for resizable floating window */\n dimensions?: FloatingWindowDimensions;\n\n /** Called when the window is resized with `FloatingWindow.ResizeHandle` */\n onSizeChange?: (size: FloatingWindowSize) => void;\n\n /** Called when the resize with `FloatingWindow.ResizeHandle` starts. Not called for keyboard resize. */\n onResizeStart?: () => void;\n\n /** Called when the resize with `FloatingWindow.ResizeHandle` stops. Not called for keyboard resize. */\n onResizeEnd?: () => void;\n}\n\nexport type FloatingWindowFactory = Factory<{\n props: FloatingWindowProps;\n ref: HTMLDivElement;\n stylesNames: FloatingWindowStylesNames;\n staticComponents: {\n ResizeHandle: typeof FloatingWindowResizeHandle;\n };\n}>;\n\nconst defaultProps = {\n constrainToViewport: true,\n zIndex: getDefaultZIndex('overlay'),\n} satisfies Partial<FloatingWindowProps>;\n\nfunction clampDimension(value: number, min?: number, max?: number): number {\n let v = value;\n if (min != null) {\n v = Math.max(v, min);\n }\n if (max != null) {\n v = Math.min(v, max);\n }\n return v;\n}\n\nexport const FloatingWindow = factory<FloatingWindowFactory>((_props) => {\n const props = useProps('FloatingWindow', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n mod,\n enabled,\n constrainToViewport,\n constrainOffset,\n dragHandleSelector,\n excludeDragHandleSelector,\n axis,\n initialPosition,\n onPositionChange,\n onDragStart,\n onDragEnd,\n setPositionRef,\n withinPortal,\n portalProps,\n zIndex,\n dimensions,\n onSizeChange,\n onResizeStart,\n onResizeEnd,\n ref,\n ...others\n } = props;\n\n const rootRef = useRef<HTMLDivElement>(null);\n\n const getStyles = useStyles<FloatingWindowFactory>({\n name: 'FloatingWindow',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n vars,\n });\n\n const floatingWindow = useFloatingWindow({\n enabled,\n constrainToViewport,\n constrainOffset,\n dragHandleSelector,\n excludeDragHandleSelector,\n axis,\n initialPosition,\n onPositionChange,\n onDragStart,\n onDragEnd,\n });\n\n useImperativeHandle(setPositionRef, () => floatingWindow.setPosition, [\n floatingWindow.setPosition,\n ]);\n\n const cssVars: Record<string, string | undefined> = {\n '--floating-window-z-index': zIndex.toString(),\n };\n\n if (dimensions?.initialWidth != null) {\n cssVars['--floating-window-width'] =\n `${clampDimension(dimensions.initialWidth, dimensions.minWidth, dimensions.maxWidth)}px`;\n }\n\n if (dimensions?.initialHeight != null) {\n cssVars['--floating-window-height'] =\n `${clampDimension(dimensions.initialHeight, dimensions.minHeight, dimensions.maxHeight)}px`;\n }\n\n return (\n <FloatingWindowProvider\n value={{\n rootRef,\n dimensions,\n constrainToViewport,\n constrainOffset,\n onSizeChange,\n onResizeStart,\n onResizeEnd,\n }}\n >\n <OptionalPortal withinPortal={withinPortal} {...portalProps}>\n <Paper\n ref={useMergedRef(ref, floatingWindow.ref, rootRef)}\n mod={[{ dragging: floatingWindow.isDragging }, mod]}\n {...getStyles('root')}\n {...others}\n __vars={cssVars}\n />\n </OptionalPortal>\n </FloatingWindowProvider>\n );\n});\n\nFloatingWindow.displayName = '@mantine/core/FloatingWindow';\nFloatingWindow.classes = classes;\nFloatingWindow.ResizeHandle = FloatingWindowResizeHandle;\n"],"mappings":";;;;;;;;;;;;;;AAsEA,MAAM,eAAe;CACnB,qBAAqB;CACrB,QAAQA,4BAAAA,iBAAiB,SAAS;AACpC;AAEA,SAAS,eAAe,OAAe,KAAc,KAAsB;CACzE,IAAI,IAAI;CACR,IAAI,OAAO,MACT,IAAI,KAAK,IAAI,GAAG,GAAG;CAErB,IAAI,OAAO,MACT,IAAI,KAAK,IAAI,GAAG,GAAG;CAErB,OAAO;AACT;AAEA,MAAa,iBAAiBC,gBAAAA,SAAgC,WAAW;CACvE,MAAM,QAAQC,kBAAAA,SAAS,kBAAkB,cAAc,MAAM;CAC7D,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,KACA,SACA,qBACA,iBACA,oBACA,2BACA,MACA,iBACA,kBACA,aACA,WACA,gBACA,cACA,aACA,QACA,YACA,cACA,eACA,aACA,KACA,GAAG,WACD;CAEJ,MAAM,WAAA,GAAA,MAAA,OAAA,CAAiC,IAAI;CAE3C,MAAM,YAAYC,mBAAAA,UAAiC;EACjD,MAAM;EACN,SAAA,8BAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,kBAAA,GAAA,eAAA,kBAAA,CAAmC;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,CAAA,GAAA,MAAA,oBAAA,CAAoB,sBAAsB,eAAe,aAAa,CACpE,eAAe,WACjB,CAAC;CAED,MAAM,UAA8C,EAClD,6BAA6B,OAAO,SAAS,EAC/C;CAEA,IAAI,YAAY,gBAAgB,MAC9B,QAAQ,6BACN,GAAG,eAAe,WAAW,cAAc,WAAW,UAAU,WAAW,QAAQ,EAAE;CAGzF,IAAI,YAAY,iBAAiB,MAC/B,QAAQ,8BACN,GAAG,eAAe,WAAW,eAAe,WAAW,WAAW,WAAW,SAAS,EAAE;CAG5F,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,+BAAAA,wBAAD;EACE,OAAO;GACL;GACA;GACA;GACA;GACA;GACA;GACA;EACF;YAEA,iBAAA,GAAA,kBAAA,IAAA,CAACC,uBAAAA,gBAAD;GAA8B;GAAc,GAAI;aAC9C,iBAAA,GAAA,kBAAA,IAAA,CAACC,cAAAA,OAAD;IACE,MAAA,GAAA,eAAA,aAAA,CAAkB,KAAK,eAAe,KAAK,OAAO;IAClD,KAAK,CAAC,EAAE,UAAU,eAAe,WAAW,GAAG,GAAG;IAClD,GAAI,UAAU,MAAM;IACpB,GAAI;IACJ,QAAQ;GACT,CAAA;EACa,CAAA;CACM,CAAA;AAE5B,CAAC;AAED,eAAe,cAAc;AAC7B,eAAe,UAAUC,8BAAAA;AACzB,eAAe,eAAeC,mCAAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FloatingWindow.context.cjs","names":["createSafeContext"],"sources":["../../../src/components/FloatingWindow/FloatingWindow.context.ts"],"sourcesContent":["import { createSafeContext } from '../../core';\n\nexport interface FloatingWindowDimensions {\n /** Initial width of the floating window in px */\n initialWidth?: number;\n\n /** Minimum width of the floating window in px */\n minWidth?: number;\n\n /** Maximum width of the floating window in px */\n maxWidth?: number;\n\n /** Initial height of the floating window in px */\n initialHeight?: number;\n\n /** Minimum height of the floating window in px */\n minHeight?: number;\n\n /** Maximum height of the floating window in px */\n maxHeight?: number;\n}\n\nexport interface FloatingWindowContextValue {\n rootRef: React.RefObject<HTMLDivElement | null>;\n dimensions: FloatingWindowDimensions | undefined;\n constrainToViewport: boolean | undefined;\n constrainOffset: number | undefined;\n}\n\nexport const [FloatingWindowProvider, useFloatingWindowContext] =\n createSafeContext<FloatingWindowContextValue>(\n 'FloatingWindow.ResizeHandle must be used within FloatingWindow'\n );\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"FloatingWindow.context.cjs","names":["createSafeContext"],"sources":["../../../src/components/FloatingWindow/FloatingWindow.context.ts"],"sourcesContent":["import { createSafeContext } from '../../core';\n\nexport interface FloatingWindowDimensions {\n /** Initial width of the floating window in px */\n initialWidth?: number;\n\n /** Minimum width of the floating window in px */\n minWidth?: number;\n\n /** Maximum width of the floating window in px */\n maxWidth?: number;\n\n /** Initial height of the floating window in px */\n initialHeight?: number;\n\n /** Minimum height of the floating window in px */\n minHeight?: number;\n\n /** Maximum height of the floating window in px */\n maxHeight?: number;\n}\n\nexport interface FloatingWindowSize {\n /** Width of the floating window in px */\n width: number;\n\n /** Height of the floating window in px */\n height: number;\n}\n\nexport interface FloatingWindowContextValue {\n rootRef: React.RefObject<HTMLDivElement | null>;\n dimensions: FloatingWindowDimensions | undefined;\n constrainToViewport: boolean | undefined;\n constrainOffset: number | undefined;\n onResizeStart: (() => void) | undefined;\n onResizeEnd: (() => void) | undefined;\n onSizeChange: ((size: FloatingWindowSize) => void) | undefined;\n}\n\nexport const [FloatingWindowProvider, useFloatingWindowContext] =\n createSafeContext<FloatingWindowContextValue>(\n 'FloatingWindow.ResizeHandle must be used within FloatingWindow'\n );\n"],"mappings":";;AAwCA,MAAa,CAAC,wBAAwB,kGACpCA,CAAAA,CAAAA,kBACE,gEACF"}
|
|
@@ -16,30 +16,24 @@ function clampDimension(value, min, max, viewportMax) {
|
|
|
16
16
|
if (viewportMax != null) v = Math.min(v, viewportMax);
|
|
17
17
|
return v;
|
|
18
18
|
}
|
|
19
|
-
function getViewportLimits(
|
|
19
|
+
function getViewportLimits(rect, constrainToViewport, constrainOffset) {
|
|
20
20
|
if (!constrainToViewport) return {
|
|
21
21
|
maxWidth: void 0,
|
|
22
22
|
maxHeight: void 0
|
|
23
23
|
};
|
|
24
|
-
const rect = root.getBoundingClientRect();
|
|
25
24
|
const offset = constrainOffset ?? 0;
|
|
26
25
|
return {
|
|
27
26
|
maxWidth: window.innerWidth - rect.left - offset,
|
|
28
27
|
maxHeight: window.innerHeight - rect.top - offset
|
|
29
28
|
};
|
|
30
29
|
}
|
|
31
|
-
function constrainWidth(root, width, dimensions, constrainToViewport, constrainOffset) {
|
|
32
|
-
const { maxWidth: vpMax } = getViewportLimits(root, constrainToViewport, constrainOffset);
|
|
33
|
-
return clampDimension(width, dimensions?.minWidth, dimensions?.maxWidth, vpMax);
|
|
34
|
-
}
|
|
35
|
-
function constrainHeight(root, height, dimensions, constrainToViewport, constrainOffset) {
|
|
36
|
-
const { maxHeight: vpMax } = getViewportLimits(root, constrainToViewport, constrainOffset);
|
|
37
|
-
return clampDimension(height, dimensions?.minHeight, dimensions?.maxHeight, vpMax);
|
|
38
|
-
}
|
|
39
30
|
const FloatingWindowResizeHandle = require_factory.factory((_props) => {
|
|
40
31
|
const { children, ref, style, ...others } = require_use_props.useProps("FloatingWindowResizeHandle", defaultProps, _props);
|
|
41
32
|
const ctx = require_FloatingWindow_context.useFloatingWindowContext();
|
|
42
33
|
const handleRef = (0, react.useRef)(null);
|
|
34
|
+
const ctxRef = (0, react.useRef)(ctx);
|
|
35
|
+
ctxRef.current = ctx;
|
|
36
|
+
const valueNowRef = (0, react.useRef)(null);
|
|
43
37
|
const hasWidth = ctx.dimensions?.initialWidth != null || ctx.dimensions?.minWidth != null || ctx.dimensions?.maxWidth != null;
|
|
44
38
|
const hasHeight = ctx.dimensions?.initialHeight != null || ctx.dimensions?.minHeight != null || ctx.dimensions?.maxHeight != null;
|
|
45
39
|
(0, react.useEffect)(() => {
|
|
@@ -53,23 +47,35 @@ const FloatingWindowResizeHandle = require_factory.factory((_props) => {
|
|
|
53
47
|
let startWidth = 0;
|
|
54
48
|
let startHeight = 0;
|
|
55
49
|
const applySize = (width, height) => {
|
|
56
|
-
|
|
50
|
+
if (width === null && height === null) return;
|
|
51
|
+
const { dimensions, constrainToViewport, constrainOffset, onSizeChange } = ctxRef.current;
|
|
52
|
+
const root = ctxRef.current.rootRef.current;
|
|
57
53
|
if (!root) return;
|
|
54
|
+
const viewportLimits = getViewportLimits(root.getBoundingClientRect(), constrainToViewport, constrainOffset);
|
|
58
55
|
if (width !== null) {
|
|
59
|
-
const
|
|
60
|
-
root.style.width = `${
|
|
61
|
-
handle.setAttribute("aria-valuenow", String(Math.round(w)));
|
|
56
|
+
const nextWidth = clampDimension(width, dimensions?.minWidth, dimensions?.maxWidth, viewportLimits.maxWidth);
|
|
57
|
+
root.style.width = `${nextWidth}px`;
|
|
62
58
|
}
|
|
63
59
|
if (height !== null) {
|
|
64
|
-
const
|
|
65
|
-
root.style.height = `${
|
|
60
|
+
const nextHeight = clampDimension(height, dimensions?.minHeight, dimensions?.maxHeight, viewportLimits.maxHeight);
|
|
61
|
+
root.style.height = `${nextHeight}px`;
|
|
62
|
+
}
|
|
63
|
+
const resizedRect = root.getBoundingClientRect();
|
|
64
|
+
if (width !== null) {
|
|
65
|
+
valueNowRef.current = resizedRect.width;
|
|
66
|
+
handle.setAttribute("aria-valuenow", String(Math.round(resizedRect.width)));
|
|
66
67
|
}
|
|
68
|
+
onSizeChange?.({
|
|
69
|
+
width: resizedRect.width,
|
|
70
|
+
height: resizedRect.height
|
|
71
|
+
});
|
|
67
72
|
};
|
|
68
73
|
const onStart = (e) => {
|
|
69
74
|
if ("button" in e && e.button !== 0) return;
|
|
70
75
|
e.stopPropagation();
|
|
71
76
|
e.preventDefault();
|
|
72
|
-
|
|
77
|
+
if (!hasWidth && !hasHeight) return;
|
|
78
|
+
const root = ctxRef.current.rootRef.current;
|
|
73
79
|
if (!root) return;
|
|
74
80
|
const point = "touches" in e ? e.touches[0] : e;
|
|
75
81
|
startX = point.clientX;
|
|
@@ -80,6 +86,7 @@ const FloatingWindowResizeHandle = require_factory.factory((_props) => {
|
|
|
80
86
|
isResizing = true;
|
|
81
87
|
document.body.style.userSelect = "none";
|
|
82
88
|
document.body.style.webkitUserSelect = "none";
|
|
89
|
+
ctxRef.current.onResizeStart?.();
|
|
83
90
|
document.addEventListener("mousemove", onMove, { signal });
|
|
84
91
|
document.addEventListener("mouseup", onEnd, { signal });
|
|
85
92
|
document.addEventListener("touchmove", onMove, {
|
|
@@ -87,6 +94,7 @@ const FloatingWindowResizeHandle = require_factory.factory((_props) => {
|
|
|
87
94
|
passive: false
|
|
88
95
|
});
|
|
89
96
|
document.addEventListener("touchend", onEnd, { signal });
|
|
97
|
+
document.addEventListener("touchcancel", onEnd, { signal });
|
|
90
98
|
};
|
|
91
99
|
const onMove = (e) => {
|
|
92
100
|
if (!isResizing) return;
|
|
@@ -101,9 +109,11 @@ const FloatingWindowResizeHandle = require_factory.factory((_props) => {
|
|
|
101
109
|
isResizing = false;
|
|
102
110
|
document.body.style.userSelect = "";
|
|
103
111
|
document.body.style.webkitUserSelect = "";
|
|
112
|
+
ctxRef.current.onResizeEnd?.();
|
|
104
113
|
};
|
|
105
114
|
const onKeyDown = (e) => {
|
|
106
|
-
const
|
|
115
|
+
const { dimensions } = ctxRef.current;
|
|
116
|
+
const root = ctxRef.current.rootRef.current;
|
|
107
117
|
if (!root) return;
|
|
108
118
|
const rect = root.getBoundingClientRect();
|
|
109
119
|
let newWidth = null;
|
|
@@ -113,11 +123,11 @@ const FloatingWindowResizeHandle = require_factory.factory((_props) => {
|
|
|
113
123
|
else if (e.key === "ArrowDown" && hasHeight) newHeight = rect.height + KEYBOARD_STEP;
|
|
114
124
|
else if (e.key === "ArrowUp" && hasHeight) newHeight = rect.height - KEYBOARD_STEP;
|
|
115
125
|
else if (e.key === "Home") {
|
|
116
|
-
if (hasWidth) newWidth =
|
|
117
|
-
if (hasHeight) newHeight =
|
|
126
|
+
if (hasWidth) newWidth = dimensions?.minWidth ?? rect.width;
|
|
127
|
+
if (hasHeight) newHeight = dimensions?.minHeight ?? rect.height;
|
|
118
128
|
} else if (e.key === "End") {
|
|
119
|
-
if (hasWidth) newWidth =
|
|
120
|
-
if (hasHeight) newHeight =
|
|
129
|
+
if (hasWidth) newWidth = dimensions?.maxWidth ?? rect.width;
|
|
130
|
+
if (hasHeight) newHeight = dimensions?.maxHeight ?? rect.height;
|
|
121
131
|
}
|
|
122
132
|
if (newWidth !== null || newHeight !== null) {
|
|
123
133
|
e.preventDefault();
|
|
@@ -131,21 +141,36 @@ const FloatingWindowResizeHandle = require_factory.factory((_props) => {
|
|
|
131
141
|
});
|
|
132
142
|
handle.addEventListener("keydown", onKeyDown, { signal });
|
|
133
143
|
return () => {
|
|
144
|
+
onEnd();
|
|
134
145
|
controller.abort();
|
|
135
146
|
};
|
|
147
|
+
}, [hasWidth, hasHeight]);
|
|
148
|
+
(0, react.useEffect)(() => {
|
|
149
|
+
const handle = handleRef.current;
|
|
150
|
+
if (!handle) return;
|
|
151
|
+
if (!hasWidth) {
|
|
152
|
+
valueNowRef.current = null;
|
|
153
|
+
handle.removeAttribute("aria-valuenow");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (valueNowRef.current !== null) return;
|
|
157
|
+
const initialWidth = ctx.dimensions?.initialWidth;
|
|
158
|
+
if (initialWidth == null) {
|
|
159
|
+
handle.removeAttribute("aria-valuenow");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const width = clampDimension(initialWidth, ctx.dimensions?.minWidth, ctx.dimensions?.maxWidth, void 0);
|
|
163
|
+
handle.setAttribute("aria-valuenow", String(Math.round(width)));
|
|
136
164
|
}, [
|
|
137
|
-
ctx.rootRef,
|
|
138
|
-
ctx.dimensions,
|
|
139
|
-
ctx.constrainToViewport,
|
|
140
|
-
ctx.constrainOffset,
|
|
141
165
|
hasWidth,
|
|
142
|
-
|
|
166
|
+
ctx.dimensions?.initialWidth,
|
|
167
|
+
ctx.dimensions?.minWidth,
|
|
168
|
+
ctx.dimensions?.maxWidth
|
|
143
169
|
]);
|
|
144
170
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Box.Box, {
|
|
145
171
|
ref: (0, _mantine_hooks.useMergedRef)(ref, handleRef),
|
|
146
172
|
role: "separator",
|
|
147
173
|
"aria-label": "Resize window",
|
|
148
|
-
"aria-valuenow": ctx.dimensions?.initialWidth,
|
|
149
174
|
"aria-valuemin": ctx.dimensions?.minWidth,
|
|
150
175
|
"aria-valuemax": ctx.dimensions?.maxWidth,
|
|
151
176
|
tabIndex: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FloatingWindowResizeHandle.cjs","names":["factory","useProps","useFloatingWindowContext","Box"],"sources":["../../../src/components/FloatingWindow/FloatingWindowResizeHandle.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-deprecated */\nimport { useEffect, useRef } from 'react';\nimport { useMergedRef } from '@mantine/hooks';\nimport { Box, BoxProps, ElementProps, factory, Factory, useProps } from '../../core';\nimport { FloatingWindowDimensions, useFloatingWindowContext } from './FloatingWindow.context';\n\nexport interface FloatingWindowResizeHandleProps extends BoxProps, ElementProps<'div', 'role'> {}\n\nexport type FloatingWindowResizeHandleFactory = Factory<{\n props: FloatingWindowResizeHandleProps;\n ref: HTMLDivElement;\n}>;\n\nconst defaultProps = {} satisfies Partial<FloatingWindowResizeHandleProps>;\n\nconst KEYBOARD_STEP = 10;\n\nfunction clampDimension(\n value: number,\n min: number | undefined,\n max: number | undefined,\n viewportMax: number | undefined\n) {\n let v = value;\n if (min != null) {\n v = Math.max(v, min);\n }\n if (max != null) {\n v = Math.min(v, max);\n }\n if (viewportMax != null) {\n v = Math.min(v, viewportMax);\n }\n return v;\n}\n\nfunction getViewportLimits(\n root: HTMLElement,\n constrainToViewport: boolean | undefined,\n constrainOffset: number | undefined\n) {\n if (!constrainToViewport) {\n return { maxWidth: undefined, maxHeight: undefined };\n }\n const rect = root.getBoundingClientRect();\n const offset = constrainOffset ?? 0;\n return {\n maxWidth: window.innerWidth - rect.left - offset,\n maxHeight: window.innerHeight - rect.top - offset,\n };\n}\n\nfunction constrainWidth(\n root: HTMLElement,\n width: number,\n dimensions: FloatingWindowDimensions | undefined,\n constrainToViewport: boolean | undefined,\n constrainOffset: number | undefined\n) {\n const { maxWidth: vpMax } = getViewportLimits(root, constrainToViewport, constrainOffset);\n return clampDimension(width, dimensions?.minWidth, dimensions?.maxWidth, vpMax);\n}\n\nfunction constrainHeight(\n root: HTMLElement,\n height: number,\n dimensions: FloatingWindowDimensions | undefined,\n constrainToViewport: boolean | undefined,\n constrainOffset: number | undefined\n) {\n const { maxHeight: vpMax } = getViewportLimits(root, constrainToViewport, constrainOffset);\n return clampDimension(height, dimensions?.minHeight, dimensions?.maxHeight, vpMax);\n}\n\nexport const FloatingWindowResizeHandle = factory<FloatingWindowResizeHandleFactory>((_props) => {\n const props = useProps('FloatingWindowResizeHandle', defaultProps, _props);\n const { children, ref, style, ...others } = props;\n const ctx = useFloatingWindowContext();\n const handleRef = useRef<HTMLDivElement>(null);\n\n const hasWidth =\n ctx.dimensions?.initialWidth != null ||\n ctx.dimensions?.minWidth != null ||\n ctx.dimensions?.maxWidth != null;\n const hasHeight =\n ctx.dimensions?.initialHeight != null ||\n ctx.dimensions?.minHeight != null ||\n ctx.dimensions?.maxHeight != null;\n\n useEffect(() => {\n const handle = handleRef.current;\n if (!handle) {\n return;\n }\n\n const controller = new AbortController();\n const { signal } = controller;\n let isResizing = false;\n let startX = 0;\n let startY = 0;\n let startWidth = 0;\n let startHeight = 0;\n\n const applySize = (width: number | null, height: number | null) => {\n const root = ctx.rootRef.current;\n if (!root) {\n return;\n }\n\n if (width !== null) {\n const w = constrainWidth(\n root,\n width,\n ctx.dimensions,\n ctx.constrainToViewport,\n ctx.constrainOffset\n );\n root.style.width = `${w}px`;\n handle.setAttribute('aria-valuenow', String(Math.round(w)));\n }\n\n if (height !== null) {\n const h = constrainHeight(\n root,\n height,\n ctx.dimensions,\n ctx.constrainToViewport,\n ctx.constrainOffset\n );\n root.style.height = `${h}px`;\n }\n };\n\n const onStart = (e: MouseEvent | TouchEvent) => {\n if ('button' in e && e.button !== 0) {\n return;\n }\n\n e.stopPropagation();\n e.preventDefault();\n\n const root = ctx.rootRef.current;\n if (!root) {\n return;\n }\n\n const point = 'touches' in e ? e.touches[0] : e;\n startX = point.clientX;\n startY = point.clientY;\n const rect = root.getBoundingClientRect();\n startWidth = rect.width;\n startHeight = rect.height;\n isResizing = true;\n\n document.body.style.userSelect = 'none';\n document.body.style.webkitUserSelect = 'none';\n\n document.addEventListener('mousemove', onMove, { signal });\n document.addEventListener('mouseup', onEnd, { signal });\n document.addEventListener('touchmove', onMove, { signal, passive: false });\n document.addEventListener('touchend', onEnd, { signal });\n };\n\n const onMove = (e: MouseEvent | TouchEvent) => {\n if (!isResizing) {\n return;\n }\n\n e.preventDefault();\n const point = 'touches' in e ? e.touches[0] : e;\n const deltaX = point.clientX - startX;\n const deltaY = point.clientY - startY;\n applySize(hasWidth ? startWidth + deltaX : null, hasHeight ? startHeight + deltaY : null);\n };\n\n const onEnd = () => {\n if (!isResizing) {\n return;\n }\n\n isResizing = false;\n document.body.style.userSelect = '';\n document.body.style.webkitUserSelect = '';\n };\n\n const onKeyDown = (e: KeyboardEvent) => {\n const root = ctx.rootRef.current;\n if (!root) {\n return;\n }\n\n const rect = root.getBoundingClientRect();\n let newWidth: number | null = null;\n let newHeight: number | null = null;\n\n if (e.key === 'ArrowRight' && hasWidth) {\n newWidth = rect.width + KEYBOARD_STEP;\n } else if (e.key === 'ArrowLeft' && hasWidth) {\n newWidth = rect.width - KEYBOARD_STEP;\n } else if (e.key === 'ArrowDown' && hasHeight) {\n newHeight = rect.height + KEYBOARD_STEP;\n } else if (e.key === 'ArrowUp' && hasHeight) {\n newHeight = rect.height - KEYBOARD_STEP;\n } else if (e.key === 'Home') {\n if (hasWidth) {\n newWidth = ctx.dimensions?.minWidth ?? rect.width;\n }\n if (hasHeight) {\n newHeight = ctx.dimensions?.minHeight ?? rect.height;\n }\n } else if (e.key === 'End') {\n if (hasWidth) {\n newWidth = ctx.dimensions?.maxWidth ?? rect.width;\n }\n if (hasHeight) {\n newHeight = ctx.dimensions?.maxHeight ?? rect.height;\n }\n }\n\n if (newWidth !== null || newHeight !== null) {\n e.preventDefault();\n applySize(newWidth, newHeight);\n }\n };\n\n handle.addEventListener('mousedown', onStart, { signal });\n handle.addEventListener('touchstart', onStart, { signal, passive: false });\n handle.addEventListener('keydown', onKeyDown, { signal });\n\n return () => {\n controller.abort();\n };\n }, [\n ctx.rootRef,\n ctx.dimensions,\n ctx.constrainToViewport,\n ctx.constrainOffset,\n hasWidth,\n hasHeight,\n ]);\n\n return (\n <Box\n ref={useMergedRef(ref, handleRef)}\n role=\"separator\"\n aria-label=\"Resize window\"\n aria-valuenow={ctx.dimensions?.initialWidth}\n aria-valuemin={ctx.dimensions?.minWidth}\n aria-valuemax={ctx.dimensions?.maxWidth}\n tabIndex={0}\n {...others}\n style={[{ touchAction: 'none' }, style]}\n >\n {children}\n </Box>\n );\n});\n\nFloatingWindowResizeHandle.displayName = '@mantine/core/FloatingWindowResizeHandle';\n"],"mappings":";;;;;;;;;AAaA,MAAM,eAAe,CAAC;AAEtB,MAAM,gBAAgB;AAEtB,SAAS,eACP,OACA,KACA,KACA,aACA;CACA,IAAI,IAAI;CACR,IAAI,OAAO,MACT,IAAI,KAAK,IAAI,GAAG,GAAG;CAErB,IAAI,OAAO,MACT,IAAI,KAAK,IAAI,GAAG,GAAG;CAErB,IAAI,eAAe,MACjB,IAAI,KAAK,IAAI,GAAG,WAAW;CAE7B,OAAO;AACT;AAEA,SAAS,kBACP,MACA,qBACA,iBACA;CACA,IAAI,CAAC,qBACH,OAAO;EAAE,UAAU,KAAA;EAAW,WAAW,KAAA;CAAU;CAErD,MAAM,OAAO,KAAK,sBAAsB;CACxC,MAAM,SAAS,mBAAmB;C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AI;EACJ,OAAO,CAAC,EAAE,aAAa,OAAO,GAAG,KAAK;EAErC;CACE,CAAA;AAET,CAAC;AAED,2BAA2B,cAAc"}
|
|
1
|
+
{"version":3,"file":"FloatingWindowResizeHandle.cjs","names":["factory","useProps","useFloatingWindowContext","Box"],"sources":["../../../src/components/FloatingWindow/FloatingWindowResizeHandle.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-deprecated */\nimport { useEffect, useRef } from 'react';\nimport { useMergedRef } from '@mantine/hooks';\nimport { Box, BoxProps, ElementProps, factory, Factory, useProps } from '../../core';\nimport { useFloatingWindowContext } from './FloatingWindow.context';\n\nexport interface FloatingWindowResizeHandleProps extends BoxProps, ElementProps<'div', 'role'> {}\n\nexport type FloatingWindowResizeHandleFactory = Factory<{\n props: FloatingWindowResizeHandleProps;\n ref: HTMLDivElement;\n}>;\n\nconst defaultProps = {} satisfies Partial<FloatingWindowResizeHandleProps>;\n\nconst KEYBOARD_STEP = 10;\n\nfunction clampDimension(\n value: number,\n min: number | undefined,\n max: number | undefined,\n viewportMax: number | undefined\n) {\n let v = value;\n if (min != null) {\n v = Math.max(v, min);\n }\n if (max != null) {\n v = Math.min(v, max);\n }\n if (viewportMax != null) {\n v = Math.min(v, viewportMax);\n }\n return v;\n}\n\nfunction getViewportLimits(\n rect: DOMRect,\n constrainToViewport: boolean | undefined,\n constrainOffset: number | undefined\n) {\n if (!constrainToViewport) {\n return { maxWidth: undefined, maxHeight: undefined };\n }\n const offset = constrainOffset ?? 0;\n return {\n maxWidth: window.innerWidth - rect.left - offset,\n maxHeight: window.innerHeight - rect.top - offset,\n };\n}\n\nexport const FloatingWindowResizeHandle = factory<FloatingWindowResizeHandleFactory>((_props) => {\n const props = useProps('FloatingWindowResizeHandle', defaultProps, _props);\n const { children, ref, style, ...others } = props;\n const ctx = useFloatingWindowContext();\n const handleRef = useRef<HTMLDivElement>(null);\n const ctxRef = useRef(ctx);\n ctxRef.current = ctx;\n const valueNowRef = useRef<number | null>(null);\n\n const hasWidth =\n ctx.dimensions?.initialWidth != null ||\n ctx.dimensions?.minWidth != null ||\n ctx.dimensions?.maxWidth != null;\n const hasHeight =\n ctx.dimensions?.initialHeight != null ||\n ctx.dimensions?.minHeight != null ||\n ctx.dimensions?.maxHeight != null;\n\n useEffect(() => {\n const handle = handleRef.current;\n if (!handle) {\n return;\n }\n\n const controller = new AbortController();\n const { signal } = controller;\n let isResizing = false;\n let startX = 0;\n let startY = 0;\n let startWidth = 0;\n let startHeight = 0;\n\n const applySize = (width: number | null, height: number | null) => {\n if (width === null && height === null) {\n return;\n }\n\n const { dimensions, constrainToViewport, constrainOffset, onSizeChange } = ctxRef.current;\n const root = ctxRef.current.rootRef.current;\n if (!root) {\n return;\n }\n\n const rect = root.getBoundingClientRect();\n const viewportLimits = getViewportLimits(rect, constrainToViewport, constrainOffset);\n\n if (width !== null) {\n const nextWidth = clampDimension(\n width,\n dimensions?.minWidth,\n dimensions?.maxWidth,\n viewportLimits.maxWidth\n );\n root.style.width = `${nextWidth}px`;\n }\n\n if (height !== null) {\n const nextHeight = clampDimension(\n height,\n dimensions?.minHeight,\n dimensions?.maxHeight,\n viewportLimits.maxHeight\n );\n root.style.height = `${nextHeight}px`;\n }\n\n const resizedRect = root.getBoundingClientRect();\n\n if (width !== null) {\n valueNowRef.current = resizedRect.width;\n handle.setAttribute('aria-valuenow', String(Math.round(resizedRect.width)));\n }\n\n onSizeChange?.({ width: resizedRect.width, height: resizedRect.height });\n };\n\n const onStart = (e: MouseEvent | TouchEvent) => {\n if ('button' in e && e.button !== 0) {\n return;\n }\n\n e.stopPropagation();\n e.preventDefault();\n\n if (!hasWidth && !hasHeight) {\n return;\n }\n\n const root = ctxRef.current.rootRef.current;\n if (!root) {\n return;\n }\n\n const point = 'touches' in e ? e.touches[0] : e;\n startX = point.clientX;\n startY = point.clientY;\n const rect = root.getBoundingClientRect();\n startWidth = rect.width;\n startHeight = rect.height;\n isResizing = true;\n\n document.body.style.userSelect = 'none';\n document.body.style.webkitUserSelect = 'none';\n\n ctxRef.current.onResizeStart?.();\n\n document.addEventListener('mousemove', onMove, { signal });\n document.addEventListener('mouseup', onEnd, { signal });\n document.addEventListener('touchmove', onMove, { signal, passive: false });\n document.addEventListener('touchend', onEnd, { signal });\n document.addEventListener('touchcancel', onEnd, { signal });\n };\n\n const onMove = (e: MouseEvent | TouchEvent) => {\n if (!isResizing) {\n return;\n }\n\n e.preventDefault();\n const point = 'touches' in e ? e.touches[0] : e;\n const deltaX = point.clientX - startX;\n const deltaY = point.clientY - startY;\n applySize(hasWidth ? startWidth + deltaX : null, hasHeight ? startHeight + deltaY : null);\n };\n\n const onEnd = () => {\n if (!isResizing) {\n return;\n }\n\n isResizing = false;\n document.body.style.userSelect = '';\n document.body.style.webkitUserSelect = '';\n ctxRef.current.onResizeEnd?.();\n };\n\n const onKeyDown = (e: KeyboardEvent) => {\n const { dimensions } = ctxRef.current;\n const root = ctxRef.current.rootRef.current;\n if (!root) {\n return;\n }\n\n const rect = root.getBoundingClientRect();\n let newWidth: number | null = null;\n let newHeight: number | null = null;\n\n if (e.key === 'ArrowRight' && hasWidth) {\n newWidth = rect.width + KEYBOARD_STEP;\n } else if (e.key === 'ArrowLeft' && hasWidth) {\n newWidth = rect.width - KEYBOARD_STEP;\n } else if (e.key === 'ArrowDown' && hasHeight) {\n newHeight = rect.height + KEYBOARD_STEP;\n } else if (e.key === 'ArrowUp' && hasHeight) {\n newHeight = rect.height - KEYBOARD_STEP;\n } else if (e.key === 'Home') {\n if (hasWidth) {\n newWidth = dimensions?.minWidth ?? rect.width;\n }\n if (hasHeight) {\n newHeight = dimensions?.minHeight ?? rect.height;\n }\n } else if (e.key === 'End') {\n if (hasWidth) {\n newWidth = dimensions?.maxWidth ?? rect.width;\n }\n if (hasHeight) {\n newHeight = dimensions?.maxHeight ?? rect.height;\n }\n }\n\n if (newWidth !== null || newHeight !== null) {\n e.preventDefault();\n applySize(newWidth, newHeight);\n }\n };\n\n handle.addEventListener('mousedown', onStart, { signal });\n handle.addEventListener('touchstart', onStart, { signal, passive: false });\n handle.addEventListener('keydown', onKeyDown, { signal });\n\n return () => {\n onEnd();\n controller.abort();\n };\n }, [hasWidth, hasHeight]);\n\n useEffect(() => {\n const handle = handleRef.current;\n if (!handle) {\n return;\n }\n\n if (!hasWidth) {\n valueNowRef.current = null;\n handle.removeAttribute('aria-valuenow');\n return;\n }\n\n if (valueNowRef.current !== null) {\n return;\n }\n\n const initialWidth = ctx.dimensions?.initialWidth;\n\n if (initialWidth == null) {\n handle.removeAttribute('aria-valuenow');\n return;\n }\n\n const width = clampDimension(\n initialWidth,\n ctx.dimensions?.minWidth,\n ctx.dimensions?.maxWidth,\n undefined\n );\n\n handle.setAttribute('aria-valuenow', String(Math.round(width)));\n }, [hasWidth, ctx.dimensions?.initialWidth, ctx.dimensions?.minWidth, ctx.dimensions?.maxWidth]);\n\n return (\n <Box\n ref={useMergedRef(ref, handleRef)}\n role=\"separator\"\n aria-label=\"Resize window\"\n aria-valuemin={ctx.dimensions?.minWidth}\n aria-valuemax={ctx.dimensions?.maxWidth}\n tabIndex={0}\n {...others}\n style={[{ touchAction: 'none' }, style]}\n >\n {children}\n </Box>\n );\n});\n\nFloatingWindowResizeHandle.displayName = '@mantine/core/FloatingWindowResizeHandle';\n"],"mappings":";;;;;;;;;AAaA,MAAM,eAAe,CAAC;AAEtB,MAAM,gBAAgB;AAEtB,SAAS,eACP,OACA,KACA,KACA,aACA;CACA,IAAI,IAAI;CACR,IAAI,OAAO,MACT,IAAI,KAAK,IAAI,GAAG,GAAG;CAErB,IAAI,OAAO,MACT,IAAI,KAAK,IAAI,GAAG,GAAG;CAErB,IAAI,eAAe,MACjB,IAAI,KAAK,IAAI,GAAG,WAAW;CAE7B,OAAO;AACT;AAEA,SAAS,kBACP,MACA,qBACA,iBACA;CACA,IAAI,CAAC,qBACH,OAAO;EAAE,UAAU,KAAA;EAAW,WAAW,KAAA;CAAU;CAErD,MAAM,SAAS,mBAAmB;CAClC,O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,CAAC;CAExB,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,MAAM,SAAS,UAAU;EACzB,IAAI,CAAC,QACH;EAGF,IAAI,CAAC,UAAU;GACb,YAAY,UAAU;GACtB,OAAO,gBAAgB,eAAe;GACtC;EACF;EAEA,IAAI,YAAY,YAAY,MAC1B;EAGF,MAAM,eAAe,IAAI,YAAY;EAErC,IAAI,gBAAgB,MAAM;GACxB,OAAO,gBAAgB,eAAe;GACtC;EACF;EAEA,MAAM,QAAQ,eACZ,cACA,IAAI,YAAY,UAChB,IAAI,YAAY,UAChB,KAAA,CACF;EAEA,OAAO,aAAa,iBAAiB,OAAO,KAAK,MAAM,KAAK,CAAC,CAAC;CAChE,GAAG;EAAC;EAAU,IAAI,YAAY;EAAc,IAAI,YAAY;EAAU,IAAI,YAAY;CAAQ,CAAC;CAE/F,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,YAAAA,KAAD;EACE,MAAA,GAAA,eAAA,aAAA,CAAkB,KAAK,SAAS;EAChC,MAAK;EACL,cAAW;EACX,iBAAe,IAAI,YAAY;EAC/B,iBAAe,IAAI,YAAY;EAC/B,UAAU;EACV,GAAI;EACJ,OAAO,CAAC,EAAE,aAAa,OAAO,GAAG,KAAK;EAErC;CACE,CAAA;AAET,CAAC;AAED,2BAA2B,cAAc"}
|
|
@@ -34,13 +34,15 @@ const InputLabel = require_factory.factory((_props) => {
|
|
|
34
34
|
});
|
|
35
35
|
const ctx = (0, react.use)(require_InputWrapper_context.InputWrapperContext);
|
|
36
36
|
const getStyles = ctx?.getStyles || _getStyles;
|
|
37
|
+
const rootElement = others.component || labelElement;
|
|
38
|
+
const supportsHtmlFor = typeof rootElement !== "string" || rootElement === "label";
|
|
37
39
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Box.Box, {
|
|
38
40
|
...getStyles("label", ctx?.getStyles ? {
|
|
39
41
|
className,
|
|
40
42
|
style
|
|
41
43
|
} : void 0),
|
|
42
44
|
component: labelElement,
|
|
43
|
-
htmlFor:
|
|
45
|
+
htmlFor: supportsHtmlFor ? htmlFor : void 0,
|
|
44
46
|
mod: [{ required }, mod],
|
|
45
47
|
onMouseDown: (event) => {
|
|
46
48
|
onMouseDown?.(event);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputLabel.cjs","names":["createVarsResolver","getFontSize","factory","useProps","useStyles","InputWrapperContext","Box","classes"],"sources":["../../../../src/components/Input/InputLabel/InputLabel.tsx"],"sourcesContent":["import { use } from 'react';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getFontSize,\n MantineFontSize,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../../core';\nimport { InputWrapperContext } from '../InputWrapper.context';\nimport classes from '../Input.module.css';\n\nexport type InputLabelStylesNames = 'label' | 'required';\nexport type InputLabelCssVariables = {\n label: '--input-asterisk-color' | '--input-label-size';\n};\n\nexport interface InputLabelProps\n extends BoxProps, StylesApiProps<InputLabelFactory>, ElementProps<'label'> {\n __staticSelector?: string;\n\n /** If set, the required asterisk is displayed next to the label */\n required?: boolean;\n\n /** Controls label `font-size` @default 'sm' */\n size?: MantineFontSize;\n\n /** Root element of the label @default 'label' */\n labelElement?: 'label' | 'div';\n}\n\nexport type InputLabelFactory = Factory<{\n props: InputLabelProps;\n ref: HTMLLabelElement;\n stylesNames: InputLabelStylesNames;\n vars: InputLabelCssVariables;\n}>;\n\nconst defaultProps = {\n labelElement: 'label',\n} satisfies Partial<InputLabelProps>;\n\nconst varsResolver = createVarsResolver<InputLabelFactory>((_, { size }) => ({\n label: {\n '--input-label-size': getFontSize(size),\n '--input-asterisk-color': undefined,\n },\n}));\n\nexport const InputLabel = factory<InputLabelFactory>((_props) => {\n const props = useProps('InputLabel', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n labelElement,\n required,\n htmlFor,\n onMouseDown,\n children,\n __staticSelector,\n mod,\n attributes,\n ...others\n } = props;\n\n const _getStyles = useStyles<InputLabelFactory>({\n name: ['InputWrapper', __staticSelector],\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n rootSelector: 'label',\n vars,\n varsResolver,\n });\n\n const ctx = use(InputWrapperContext);\n const getStyles = ctx?.getStyles || _getStyles;\n\n return (\n <Box\n {...getStyles('label', ctx?.getStyles ? { className, style } : undefined)}\n component={labelElement as 'label'}\n htmlFor={
|
|
1
|
+
{"version":3,"file":"InputLabel.cjs","names":["createVarsResolver","getFontSize","factory","useProps","useStyles","InputWrapperContext","Box","classes"],"sources":["../../../../src/components/Input/InputLabel/InputLabel.tsx"],"sourcesContent":["import { use } from 'react';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getFontSize,\n MantineFontSize,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../../core';\nimport { InputWrapperContext } from '../InputWrapper.context';\nimport classes from '../Input.module.css';\n\nexport type InputLabelStylesNames = 'label' | 'required';\nexport type InputLabelCssVariables = {\n label: '--input-asterisk-color' | '--input-label-size';\n};\n\nexport interface InputLabelProps\n extends BoxProps, StylesApiProps<InputLabelFactory>, ElementProps<'label'> {\n __staticSelector?: string;\n\n /** If set, the required asterisk is displayed next to the label */\n required?: boolean;\n\n /** Controls label `font-size` @default 'sm' */\n size?: MantineFontSize;\n\n /** Root element of the label @default 'label' */\n labelElement?: 'label' | 'div';\n}\n\nexport type InputLabelFactory = Factory<{\n props: InputLabelProps;\n ref: HTMLLabelElement;\n stylesNames: InputLabelStylesNames;\n vars: InputLabelCssVariables;\n}>;\n\nconst defaultProps = {\n labelElement: 'label',\n} satisfies Partial<InputLabelProps>;\n\nconst varsResolver = createVarsResolver<InputLabelFactory>((_, { size }) => ({\n label: {\n '--input-label-size': getFontSize(size),\n '--input-asterisk-color': undefined,\n },\n}));\n\nexport const InputLabel = factory<InputLabelFactory>((_props) => {\n const props = useProps('InputLabel', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n labelElement,\n required,\n htmlFor,\n onMouseDown,\n children,\n __staticSelector,\n mod,\n attributes,\n ...others\n } = props;\n\n const _getStyles = useStyles<InputLabelFactory>({\n name: ['InputWrapper', __staticSelector],\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n rootSelector: 'label',\n vars,\n varsResolver,\n });\n\n const ctx = use(InputWrapperContext);\n const getStyles = ctx?.getStyles || _getStyles;\n const rootElement = (others as { component?: React.ElementType }).component || labelElement;\n const supportsHtmlFor = typeof rootElement !== 'string' || rootElement === 'label';\n\n return (\n <Box\n {...getStyles('label', ctx?.getStyles ? { className, style } : undefined)}\n component={labelElement as 'label'}\n htmlFor={supportsHtmlFor ? htmlFor : undefined}\n mod={[{ required }, mod]}\n onMouseDown={(event) => {\n onMouseDown?.(event);\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault();\n }\n }}\n {...others}\n >\n {children}\n {required && (\n <span {...getStyles('required')} aria-hidden>\n {' *'}\n </span>\n )}\n </Box>\n );\n});\n\nInputLabel.classes = classes;\nInputLabel.varsResolver = varsResolver;\nInputLabel.displayName = '@mantine/core/InputLabel';\n"],"mappings":";;;;;;;;;;;;AA2CA,MAAM,eAAe,EACnB,cAAc,QAChB;AAEA,MAAM,eAAeA,6BAAAA,oBAAuC,GAAG,EAAE,YAAY,EAC3E,OAAO;CACL,sBAAsBC,iBAAAA,YAAY,IAAI;CACtC,0BAA0B,KAAA;AAC5B,EACF,EAAE;AAEF,MAAa,aAAaC,gBAAAA,SAA4B,WAAW;CAC/D,MAAM,QAAQC,kBAAAA,SAAS,cAAc,cAAc,MAAM;CACzD,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,cACA,UACA,SACA,aACA,UACA,kBACA,KACA,YACA,GAAG,WACD;CAEJ,MAAM,aAAaC,mBAAAA,UAA6B;EAC9C,MAAM,CAAC,gBAAgB,gBAAgB;EACvC;EACA,SAAA,qBAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,cAAc;EACd;EACA;CACF,CAAC;CAED,MAAM,OAAA,GAAA,MAAA,IAAA,CAAUC,6BAAAA,mBAAmB;CACnC,MAAM,YAAY,KAAK,aAAa;CACpC,MAAM,cAAe,OAA6C,aAAa;CAC/E,MAAM,kBAAkB,OAAO,gBAAgB,YAAY,gBAAgB;CAE3E,OACE,iBAAA,GAAA,kBAAA,KAAA,CAACC,YAAAA,KAAD;EACE,GAAI,UAAU,SAAS,KAAK,YAAY;GAAE;GAAW;EAAM,IAAI,KAAA,CAAS;EACxE,WAAW;EACX,SAAS,kBAAkB,UAAU,KAAA;EACrC,KAAK,CAAC,EAAE,SAAS,GAAG,GAAG;EACvB,cAAc,UAAU;GACtB,cAAc,KAAK;GACnB,IAAI,CAAC,MAAM,oBAAoB,MAAM,SAAS,GAC5C,MAAM,eAAe;EAEzB;EACA,GAAI;YAXN,CAaG,UACA,YACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;GAAM,GAAI,UAAU,UAAU;GAAG,eAAA;aAC9B;EACG,CAAA,CAEL;;AAET,CAAC;AAED,WAAW,UAAUC,qBAAAA;AACrB,WAAW,eAAe;AAC1B,WAAW,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputWrapper.cjs","names":["createVarsResolver","getFontSize","rem","factory","useProps","useStyles","InputLabel","InputDescription","Fragment","InputError","InputSuccess","InputWrapperContext","getInputOffsets","Box","classes"],"sources":["../../../../src/components/Input/InputWrapper/InputWrapper.tsx"],"sourcesContent":["import { Fragment } from 'react';\nimport { useId } from '@mantine/hooks';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n DataAttributes,\n ElementProps,\n factory,\n Factory,\n getFontSize,\n MantineFontSize,\n rem,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../../core';\nimport {\n InputDescription,\n InputDescriptionCssVariables,\n InputDescriptionProps,\n InputDescriptionStylesNames,\n} from '../InputDescription/InputDescription';\nimport {\n InputError,\n InputErrorCssVariables,\n InputErrorProps,\n InputErrorStylesNames,\n} from '../InputError/InputError';\nimport {\n InputLabel,\n InputLabelCssVariables,\n InputLabelProps,\n InputLabelStylesNames,\n} from '../InputLabel/InputLabel';\nimport {\n InputSuccess,\n InputSuccessCssVariables,\n InputSuccessProps,\n InputSuccessStylesNames,\n} from '../InputSuccess/InputSuccess';\nimport { InputWrapperContext } from '../InputWrapper.context';\nimport { getInputOffsets } from './get-input-offsets/get-input-offsets';\nimport classes from '../Input.module.css';\n\nexport type InputWrapperCssVariables = InputLabelCssVariables &\n InputErrorCssVariables &\n InputSuccessCssVariables &\n InputDescriptionCssVariables;\n\nexport type InputWrapperStylesNames =\n | 'root'\n | InputLabelStylesNames\n | InputDescriptionStylesNames\n | InputErrorStylesNames\n | InputSuccessStylesNames;\n\nexport interface __InputWrapperProps {\n /** Contents of `Input.Label` component. If not set, label is not displayed. */\n label?: React.ReactNode;\n\n /** Contents of `Input.Description` component. If not set, description is not displayed. */\n description?: React.ReactNode;\n\n /** Contents of `Input.Error` component. If not set, error is not displayed. */\n error?: React.ReactNode;\n\n /** Contents of `Input.Success` component. If not set, success is not displayed. */\n success?: React.ReactNode;\n\n /** Adds required attribute to the input and a red asterisk on the right side of label @default false */\n required?: boolean;\n\n /** If set, the required asterisk is displayed next to the label. Overrides `required` prop. Does not add required attribute to the input. @default false */\n withAsterisk?: boolean;\n\n /** Props passed down to the `Input.Label` component */\n labelProps?: InputLabelProps & DataAttributes;\n\n /** Props passed down to the `Input.Description` component */\n descriptionProps?: InputDescriptionProps & DataAttributes;\n\n /** Props passed down to the `Input.Error` component */\n errorProps?: InputErrorProps & DataAttributes;\n\n /** Props passed down to the `Input.Success` component */\n successProps?: InputSuccessProps & DataAttributes;\n\n /** Render function to wrap the input element. Useful for adding tooltips, popovers, or other wrappers around the input. @default React.Fragment */\n inputContainer?: (children: React.ReactNode) => React.ReactNode;\n\n /** Controls order and visibility of wrapper elements. Only elements included in this array will be rendered. @default ['label', 'description', 'input', 'error'] */\n inputWrapperOrder?: ('label' | 'input' | 'description' | 'error')[];\n}\n\nexport interface InputWrapperProps\n extends __InputWrapperProps, BoxProps, StylesApiProps<InputWrapperFactory>, ElementProps<'div'> {\n __staticSelector?: string;\n\n /** Props passed to Styles API context, replaces Input.Wrapper props */\n __stylesApiProps?: Record<string, any>;\n\n /** Static id used as base to generate `aria-` attributes, by default generates random id */\n id?: string;\n\n /** Controls size of `Input.Label`, `Input.Description` and `Input.Error` components */\n size?: MantineFontSize;\n\n /** Root element for the label. Use `'div'` when wrapper contains multiple input elements and you need to handle `htmlFor` manually. @default 'label' */\n labelElement?: 'label' | 'div';\n}\n\nexport type InputWrapperFactory = Factory<{\n props: InputWrapperProps;\n ref: HTMLDivElement;\n stylesNames: InputWrapperStylesNames;\n vars: InputWrapperCssVariables;\n}>;\n\nconst defaultProps = {\n labelElement: 'label',\n inputContainer: (children) => children,\n inputWrapperOrder: ['label', 'description', 'input', 'error'],\n} satisfies Partial<InputWrapperProps>;\n\nconst varsResolver = createVarsResolver<InputWrapperFactory>((_, { size }) => ({\n label: {\n '--input-label-size': getFontSize(size),\n '--input-asterisk-color': undefined,\n },\n\n error: {\n '--input-error-size': size === undefined ? undefined : `calc(${getFontSize(size)} - ${rem(2)})`,\n },\n\n success: {\n '--input-success-size':\n size === undefined ? undefined : `calc(${getFontSize(size)} - ${rem(2)})`,\n },\n\n description: {\n '--input-description-size':\n size === undefined ? undefined : `calc(${getFontSize(size)} - ${rem(2)})`,\n },\n}));\n\nexport const InputWrapper = factory<InputWrapperFactory>((_props) => {\n const props = useProps('InputWrapper', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n size,\n variant,\n __staticSelector,\n inputContainer,\n inputWrapperOrder,\n label,\n error,\n success,\n description,\n labelProps,\n descriptionProps,\n errorProps,\n successProps,\n labelElement,\n children,\n withAsterisk,\n id,\n required,\n __stylesApiProps,\n mod,\n attributes,\n ...others\n } = props;\n\n const getStyles = useStyles<InputWrapperFactory>({\n name: ['InputWrapper', __staticSelector],\n props: __stylesApiProps || props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const sharedProps = {\n size,\n variant,\n __staticSelector,\n };\n\n const idBase = useId(id);\n const isRequired = typeof withAsterisk === 'boolean' ? withAsterisk : required;\n const errorId = errorProps?.id || `${idBase}-error`;\n const successId = successProps?.id || `${idBase}-success`;\n const descriptionId = descriptionProps?.id || `${idBase}-description`;\n const inputId = idBase;\n const hasError = !!error && typeof error !== 'boolean';\n const hasSuccess = !!success && typeof success !== 'boolean' && !error;\n const hasDescription = !!description;\n const errorRendered = hasError && inputWrapperOrder.includes('error');\n const successRendered = hasSuccess && inputWrapperOrder.includes('error');\n const descriptionRendered = hasDescription && inputWrapperOrder.includes('description');\n const _describedBy = `${errorRendered ? errorId : ''} ${successRendered ? successId : ''} ${descriptionRendered ? descriptionId : ''}`;\n const describedBy = _describedBy.trim().length > 0 ? _describedBy.trim() : undefined;\n const labelId = labelProps?.id || `${idBase}-label`;\n\n const _label = label && (\n <InputLabel\n key=\"label\"\n labelElement={labelElement}\n id={labelId}\n htmlFor={inputId}\n required={isRequired}\n {...sharedProps}\n {...labelProps}\n >\n {label}\n </InputLabel>\n );\n\n const _description = hasDescription && (\n <InputDescription\n key=\"description\"\n {...descriptionProps}\n {...sharedProps}\n size={descriptionProps?.size || sharedProps.size}\n id={descriptionProps?.id || descriptionId}\n >\n {description}\n </InputDescription>\n );\n\n const _input = <Fragment key=\"input\">{inputContainer(children)}</Fragment>;\n\n const _error = hasError && (\n <InputError\n {...errorProps}\n {...sharedProps}\n size={errorProps?.size || sharedProps.size}\n key=\"error\"\n id={errorProps?.id || errorId}\n >\n {error}\n </InputError>\n );\n\n const _success = hasSuccess && (\n <InputSuccess\n {...successProps}\n {...sharedProps}\n size={successProps?.size || sharedProps.size}\n key=\"success\"\n id={successProps?.id || successId}\n >\n {success}\n </InputSuccess>\n );\n\n const content = inputWrapperOrder.map((part) => {\n switch (part) {\n case 'label':\n return _label;\n case 'input':\n return _input;\n case 'description':\n return _description;\n case 'error':\n return _error || _success;\n default:\n return null;\n }\n });\n\n return (\n <InputWrapperContext\n value={{\n getStyles,\n describedBy,\n inputId,\n labelId,\n ...getInputOffsets(inputWrapperOrder, { hasDescription, hasError: hasError || hasSuccess }),\n }}\n >\n <Box\n variant={variant}\n size={size}\n mod={[{ error: !!error, success: !!success && !error }, mod]}\n id={labelElement === 'label' ? undefined : id}\n {...getStyles('root')}\n {...others}\n >\n {content}\n </Box>\n </InputWrapperContext>\n );\n});\n\nInputWrapper.classes = classes;\nInputWrapper.varsResolver = varsResolver;\nInputWrapper.displayName = '@mantine/core/InputWrapper';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuHA,MAAM,eAAe;CACnB,cAAc;CACd,iBAAiB,aAAa;CAC9B,mBAAmB;EAAC;EAAS;EAAe;EAAS;CAAO;AAC9D;AAEA,MAAM,eAAeA,6BAAAA,oBAAyC,GAAG,EAAE,YAAY;CAC7E,OAAO;EACL,sBAAsBC,iBAAAA,YAAY,IAAI;EACtC,0BAA0B,KAAA;CAC5B;CAEA,OAAO,EACL,sBAAsB,SAAS,KAAA,IAAY,KAAA,IAAY,QAAQA,iBAAAA,YAAY,IAAI,EAAE,KAAKC,YAAAA,IAAI,CAAC,EAAE,GAC/F;CAEA,SAAS,EACP,wBACE,SAAS,KAAA,IAAY,KAAA,IAAY,QAAQD,iBAAAA,YAAY,IAAI,EAAE,KAAKC,YAAAA,IAAI,CAAC,EAAE,GAC3E;CAEA,aAAa,EACX,4BACE,SAAS,KAAA,IAAY,KAAA,IAAY,QAAQD,iBAAAA,YAAY,IAAI,EAAE,KAAKC,YAAAA,IAAI,CAAC,EAAE,GAC3E;AACF,EAAE;AAEF,MAAa,eAAeC,gBAAAA,SAA8B,WAAW;CACnE,MAAM,QAAQC,kBAAAA,SAAS,gBAAgB,cAAc,MAAM;CAC3D,MAA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I,UAAU,MAAM;GACpB,GAAI;aAEH;EACE,CAAA;CACc,CAAA;AAEzB,CAAC;AAED,aAAa,UAAUC,qBAAAA;AACvB,aAAa,eAAe;AAC5B,aAAa,cAAc"}
|
|
1
|
+
{"version":3,"file":"InputWrapper.cjs","names":["createVarsResolver","getFontSize","rem","factory","useProps","useStyles","InputLabel","InputDescription","Fragment","InputError","InputSuccess","InputWrapperContext","getInputOffsets","Box","classes"],"sources":["../../../../src/components/Input/InputWrapper/InputWrapper.tsx"],"sourcesContent":["import { Fragment } from 'react';\nimport { useId } from '@mantine/hooks';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n DataAttributes,\n ElementProps,\n factory,\n Factory,\n getFontSize,\n MantineFontSize,\n PlaceholderPolymorphicProps,\n rem,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../../core';\nimport {\n InputDescription,\n InputDescriptionCssVariables,\n InputDescriptionProps,\n InputDescriptionStylesNames,\n} from '../InputDescription/InputDescription';\nimport {\n InputError,\n InputErrorCssVariables,\n InputErrorProps,\n InputErrorStylesNames,\n} from '../InputError/InputError';\nimport {\n InputLabel,\n InputLabelCssVariables,\n InputLabelProps,\n InputLabelStylesNames,\n} from '../InputLabel/InputLabel';\nimport {\n InputSuccess,\n InputSuccessCssVariables,\n InputSuccessProps,\n InputSuccessStylesNames,\n} from '../InputSuccess/InputSuccess';\nimport { InputWrapperContext } from '../InputWrapper.context';\nimport { getInputOffsets } from './get-input-offsets/get-input-offsets';\nimport classes from '../Input.module.css';\n\nexport type InputWrapperCssVariables = InputLabelCssVariables &\n InputErrorCssVariables &\n InputSuccessCssVariables &\n InputDescriptionCssVariables;\n\nexport type InputWrapperStylesNames =\n | 'root'\n | InputLabelStylesNames\n | InputDescriptionStylesNames\n | InputErrorStylesNames\n | InputSuccessStylesNames;\n\nexport interface __InputWrapperProps {\n /** Contents of `Input.Label` component. If not set, label is not displayed. */\n label?: React.ReactNode;\n\n /** Contents of `Input.Description` component. If not set, description is not displayed. */\n description?: React.ReactNode;\n\n /** Contents of `Input.Error` component. If not set, error is not displayed. */\n error?: React.ReactNode;\n\n /** Contents of `Input.Success` component. If not set, success is not displayed. */\n success?: React.ReactNode;\n\n /** Adds required attribute to the input and a red asterisk on the right side of label @default false */\n required?: boolean;\n\n /** If set, the required asterisk is displayed next to the label. Overrides `required` prop. Does not add required attribute to the input. @default false */\n withAsterisk?: boolean;\n\n /** Props passed down to the `Input.Label` component */\n labelProps?: InputLabelProps & DataAttributes & PlaceholderPolymorphicProps;\n\n /** Props passed down to the `Input.Description` component */\n descriptionProps?: InputDescriptionProps & DataAttributes & PlaceholderPolymorphicProps;\n\n /** Props passed down to the `Input.Error` component */\n errorProps?: InputErrorProps & DataAttributes & PlaceholderPolymorphicProps;\n\n /** Props passed down to the `Input.Success` component */\n successProps?: InputSuccessProps & DataAttributes & PlaceholderPolymorphicProps;\n\n /** Render function to wrap the input element. Useful for adding tooltips, popovers, or other wrappers around the input. @default React.Fragment */\n inputContainer?: (children: React.ReactNode) => React.ReactNode;\n\n /** Controls order and visibility of wrapper elements. Only elements included in this array will be rendered. @default ['label', 'description', 'input', 'error'] */\n inputWrapperOrder?: ('label' | 'input' | 'description' | 'error')[];\n}\n\nexport interface InputWrapperProps\n extends __InputWrapperProps, BoxProps, StylesApiProps<InputWrapperFactory>, ElementProps<'div'> {\n __staticSelector?: string;\n\n /** Props passed to Styles API context, replaces Input.Wrapper props */\n __stylesApiProps?: Record<string, any>;\n\n /** Static id used as base to generate `aria-` attributes, by default generates random id */\n id?: string;\n\n /** Controls size of `Input.Label`, `Input.Description` and `Input.Error` components */\n size?: MantineFontSize;\n\n /** Root element for the label. Use `'div'` when wrapper contains multiple input elements and you need to handle `htmlFor` manually. @default 'label' */\n labelElement?: 'label' | 'div';\n}\n\nexport type InputWrapperFactory = Factory<{\n props: InputWrapperProps;\n ref: HTMLDivElement;\n stylesNames: InputWrapperStylesNames;\n vars: InputWrapperCssVariables;\n}>;\n\nconst defaultProps = {\n labelElement: 'label',\n inputContainer: (children) => children,\n inputWrapperOrder: ['label', 'description', 'input', 'error'],\n} satisfies Partial<InputWrapperProps>;\n\nconst varsResolver = createVarsResolver<InputWrapperFactory>((_, { size }) => ({\n label: {\n '--input-label-size': getFontSize(size),\n '--input-asterisk-color': undefined,\n },\n\n error: {\n '--input-error-size': size === undefined ? undefined : `calc(${getFontSize(size)} - ${rem(2)})`,\n },\n\n success: {\n '--input-success-size':\n size === undefined ? undefined : `calc(${getFontSize(size)} - ${rem(2)})`,\n },\n\n description: {\n '--input-description-size':\n size === undefined ? undefined : `calc(${getFontSize(size)} - ${rem(2)})`,\n },\n}));\n\nexport const InputWrapper = factory<InputWrapperFactory>((_props) => {\n const props = useProps('InputWrapper', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n size,\n variant,\n __staticSelector,\n inputContainer,\n inputWrapperOrder,\n label,\n error,\n success,\n description,\n labelProps,\n descriptionProps,\n errorProps,\n successProps,\n labelElement,\n children,\n withAsterisk,\n id,\n required,\n __stylesApiProps,\n mod,\n attributes,\n ...others\n } = props;\n\n const getStyles = useStyles<InputWrapperFactory>({\n name: ['InputWrapper', __staticSelector],\n props: __stylesApiProps || props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const sharedProps = {\n size,\n variant,\n __staticSelector,\n };\n\n const idBase = useId(id);\n const isRequired = typeof withAsterisk === 'boolean' ? withAsterisk : required;\n const errorId = errorProps?.id || `${idBase}-error`;\n const successId = successProps?.id || `${idBase}-success`;\n const descriptionId = descriptionProps?.id || `${idBase}-description`;\n const inputId = idBase;\n const hasError = !!error && typeof error !== 'boolean';\n const hasSuccess = !!success && typeof success !== 'boolean' && !error;\n const hasDescription = !!description;\n const errorRendered = hasError && inputWrapperOrder.includes('error');\n const successRendered = hasSuccess && inputWrapperOrder.includes('error');\n const descriptionRendered = hasDescription && inputWrapperOrder.includes('description');\n const _describedBy = `${errorRendered ? errorId : ''} ${successRendered ? successId : ''} ${descriptionRendered ? descriptionId : ''}`;\n const describedBy = _describedBy.trim().length > 0 ? _describedBy.trim() : undefined;\n const labelId = labelProps?.id || `${idBase}-label`;\n\n const _label = label && (\n <InputLabel\n key=\"label\"\n labelElement={labelElement}\n id={labelId}\n htmlFor={inputId}\n required={isRequired}\n {...sharedProps}\n {...labelProps}\n >\n {label}\n </InputLabel>\n );\n\n const _description = hasDescription && (\n <InputDescription\n key=\"description\"\n {...descriptionProps}\n {...sharedProps}\n size={descriptionProps?.size || sharedProps.size}\n id={descriptionProps?.id || descriptionId}\n >\n {description}\n </InputDescription>\n );\n\n const _input = <Fragment key=\"input\">{inputContainer(children)}</Fragment>;\n\n const _error = hasError && (\n <InputError\n {...errorProps}\n {...sharedProps}\n size={errorProps?.size || sharedProps.size}\n key=\"error\"\n id={errorProps?.id || errorId}\n >\n {error}\n </InputError>\n );\n\n const _success = hasSuccess && (\n <InputSuccess\n {...successProps}\n {...sharedProps}\n size={successProps?.size || sharedProps.size}\n key=\"success\"\n id={successProps?.id || successId}\n >\n {success}\n </InputSuccess>\n );\n\n const content = inputWrapperOrder.map((part) => {\n switch (part) {\n case 'label':\n return _label;\n case 'input':\n return _input;\n case 'description':\n return _description;\n case 'error':\n return _error || _success;\n default:\n return null;\n }\n });\n\n return (\n <InputWrapperContext\n value={{\n getStyles,\n describedBy,\n inputId,\n labelId,\n ...getInputOffsets(inputWrapperOrder, { hasDescription, hasError: hasError || hasSuccess }),\n }}\n >\n <Box\n variant={variant}\n size={size}\n mod={[{ error: !!error, success: !!success && !error }, mod]}\n id={labelElement === 'label' ? undefined : id}\n {...getStyles('root')}\n {...others}\n >\n {content}\n </Box>\n </InputWrapperContext>\n );\n});\n\nInputWrapper.classes = classes;\nInputWrapper.varsResolver = varsResolver;\nInputWrapper.displayName = '@mantine/core/InputWrapper';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwHA,MAAM,eAAe;CACnB,cAAc;CACd,iBAAiB,aAA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qBAAAA,cAAD;EACE,GAAI;EACJ,GAAI;EACJ,MAAM,cAAc,QAAQ,YAAY;EACxC,KAAI;EACJ,IAAI,cAAc,MAAM;CAGZ,GADX,OACW;CAGhB,MAAM,UAAU,kBAAkB,KAAK,SAAS;EAC9C,QAAQ,MAAR;GACE,KAAK,SACH,OAAO;GACT,KAAK,SACH,OAAO;GACT,KAAK,eACH,OAAO;GACT,KAAK,SACH,OAAO,UAAU;GACnB,SACE,OAAO;EACX;CACF,CAAC;CAED,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,6BAAAA,qBAAD;EACE,OAAO;GACL;GACA;GACA;GACA;GACA,GAAGC,0BAAAA,gBAAgB,mBAAmB;IAAE;IAAgB,UAAU,YAAY;GAAW,CAAC;EAC5F;YAEA,iBAAA,GAAA,kBAAA,IAAA,CAACC,YAAAA,KAAD;GACW;GACH;GACN,KAAK,CAAC;IAAE,OAAO,CAAC,CAAC;IAAO,SAAS,CAAC,CAAC,WAAW,CAAC;GAAM,GAAG,GAAG;GAC3D,IAAI,iBAAiB,UAAU,KAAA,IAAY;GAC3C,GAAI,UAAU,MAAM;GACpB,GAAI;aAEH;EACE,CAAA;CACc,CAAA;AAEzB,CAAC;AAED,aAAa,UAAUC,qBAAAA;AACvB,aAAa,eAAe;AAC5B,aAAa,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FloatingWindow.context.mjs","names":[],"sources":["../../../src/components/FloatingWindow/FloatingWindow.context.ts"],"sourcesContent":["import { createSafeContext } from '../../core';\n\nexport interface FloatingWindowDimensions {\n /** Initial width of the floating window in px */\n initialWidth?: number;\n\n /** Minimum width of the floating window in px */\n minWidth?: number;\n\n /** Maximum width of the floating window in px */\n maxWidth?: number;\n\n /** Initial height of the floating window in px */\n initialHeight?: number;\n\n /** Minimum height of the floating window in px */\n minHeight?: number;\n\n /** Maximum height of the floating window in px */\n maxHeight?: number;\n}\n\nexport interface FloatingWindowContextValue {\n rootRef: React.RefObject<HTMLDivElement | null>;\n dimensions: FloatingWindowDimensions | undefined;\n constrainToViewport: boolean | undefined;\n constrainOffset: number | undefined;\n}\n\nexport const [FloatingWindowProvider, useFloatingWindowContext] =\n createSafeContext<FloatingWindowContextValue>(\n 'FloatingWindow.ResizeHandle must be used within FloatingWindow'\n );\n"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"FloatingWindow.context.mjs","names":[],"sources":["../../../src/components/FloatingWindow/FloatingWindow.context.ts"],"sourcesContent":["import { createSafeContext } from '../../core';\n\nexport interface FloatingWindowDimensions {\n /** Initial width of the floating window in px */\n initialWidth?: number;\n\n /** Minimum width of the floating window in px */\n minWidth?: number;\n\n /** Maximum width of the floating window in px */\n maxWidth?: number;\n\n /** Initial height of the floating window in px */\n initialHeight?: number;\n\n /** Minimum height of the floating window in px */\n minHeight?: number;\n\n /** Maximum height of the floating window in px */\n maxHeight?: number;\n}\n\nexport interface FloatingWindowSize {\n /** Width of the floating window in px */\n width: number;\n\n /** Height of the floating window in px */\n height: number;\n}\n\nexport interface FloatingWindowContextValue {\n rootRef: React.RefObject<HTMLDivElement | null>;\n dimensions: FloatingWindowDimensions | undefined;\n constrainToViewport: boolean | undefined;\n constrainOffset: number | undefined;\n onResizeStart: (() => void) | undefined;\n onResizeEnd: (() => void) | undefined;\n onSizeChange: ((size: FloatingWindowSize) => void) | undefined;\n}\n\nexport const [FloatingWindowProvider, useFloatingWindowContext] =\n createSafeContext<FloatingWindowContextValue>(\n 'FloatingWindow.ResizeHandle must be used within FloatingWindow'\n );\n"],"mappings":";;;AAwCA,MAAa,CAAC,wBAAwB,4BACpC,kBACE,gEACF"}
|
|
@@ -24,7 +24,7 @@ function clampDimension(value, min, max) {
|
|
|
24
24
|
}
|
|
25
25
|
const FloatingWindow = factory((_props) => {
|
|
26
26
|
const props = useProps("FloatingWindow", defaultProps, _props);
|
|
27
|
-
const { classNames, className, style, styles, unstyled, vars, mod, enabled, constrainToViewport, constrainOffset, dragHandleSelector, excludeDragHandleSelector, axis, initialPosition, onPositionChange, onDragStart, onDragEnd, setPositionRef, withinPortal, portalProps, zIndex, dimensions, ref, ...others } = props;
|
|
27
|
+
const { classNames, className, style, styles, unstyled, vars, mod, enabled, constrainToViewport, constrainOffset, dragHandleSelector, excludeDragHandleSelector, axis, initialPosition, onPositionChange, onDragStart, onDragEnd, setPositionRef, withinPortal, portalProps, zIndex, dimensions, onSizeChange, onResizeStart, onResizeEnd, ref, ...others } = props;
|
|
28
28
|
const rootRef = useRef(null);
|
|
29
29
|
const getStyles = useStyles({
|
|
30
30
|
name: "FloatingWindow",
|
|
@@ -58,7 +58,10 @@ const FloatingWindow = factory((_props) => {
|
|
|
58
58
|
rootRef,
|
|
59
59
|
dimensions,
|
|
60
60
|
constrainToViewport,
|
|
61
|
-
constrainOffset
|
|
61
|
+
constrainOffset,
|
|
62
|
+
onSizeChange,
|
|
63
|
+
onResizeStart,
|
|
64
|
+
onResizeEnd
|
|
62
65
|
},
|
|
63
66
|
children: /* @__PURE__ */ jsx(OptionalPortal, {
|
|
64
67
|
withinPortal,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FloatingWindow.mjs","names":["classes"],"sources":["../../../src/components/FloatingWindow/FloatingWindow.tsx"],"sourcesContent":["import { useImperativeHandle, useRef } from 'react';\nimport {\n SetFloatingWindowPosition,\n useFloatingWindow,\n UseFloatingWindowOptions,\n useMergedRef,\n} from '@mantine/hooks';\nimport {\n BoxProps,\n ElementProps,\n factory,\n Factory,\n getDefaultZIndex,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport { Paper, PaperBaseProps } from '../Paper';\nimport { OptionalPortal, PortalProps } from '../Portal';\nimport {
|
|
1
|
+
{"version":3,"file":"FloatingWindow.mjs","names":["classes"],"sources":["../../../src/components/FloatingWindow/FloatingWindow.tsx"],"sourcesContent":["import { useImperativeHandle, useRef } from 'react';\nimport {\n SetFloatingWindowPosition,\n useFloatingWindow,\n UseFloatingWindowOptions,\n useMergedRef,\n} from '@mantine/hooks';\nimport {\n BoxProps,\n ElementProps,\n factory,\n Factory,\n getDefaultZIndex,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport { Paper, PaperBaseProps } from '../Paper';\nimport { OptionalPortal, PortalProps } from '../Portal';\nimport {\n FloatingWindowDimensions,\n FloatingWindowProvider,\n FloatingWindowSize,\n} from './FloatingWindow.context';\nimport { FloatingWindowResizeHandle } from './FloatingWindowResizeHandle';\nimport classes from './FloatingWindow.module.css';\n\nexport type FloatingWindowStylesNames = 'root';\n\nexport interface FloatingWindowProps\n extends\n UseFloatingWindowOptions,\n PaperBaseProps,\n BoxProps,\n StylesApiProps<FloatingWindowFactory>,\n ElementProps<'div', keyof UseFloatingWindowOptions> {\n /** Assigns ref to set position programmatically */\n setPositionRef?: React.RefObject<SetFloatingWindowPosition | null>;\n\n /** Determines whether the window should be rendered inside `Portal` @default true */\n withinPortal?: boolean;\n\n /** Props passed down to `Portal` component */\n portalProps?: Omit<PortalProps, 'children'>;\n\n /** `z-index` of the root element @default 400 */\n zIndex?: React.CSSProperties['zIndex'];\n\n /** Dimensions configuration for resizable floating window */\n dimensions?: FloatingWindowDimensions;\n\n /** Called when the window is resized with `FloatingWindow.ResizeHandle` */\n onSizeChange?: (size: FloatingWindowSize) => void;\n\n /** Called when the resize with `FloatingWindow.ResizeHandle` starts. Not called for keyboard resize. */\n onResizeStart?: () => void;\n\n /** Called when the resize with `FloatingWindow.ResizeHandle` stops. Not called for keyboard resize. */\n onResizeEnd?: () => void;\n}\n\nexport type FloatingWindowFactory = Factory<{\n props: FloatingWindowProps;\n ref: HTMLDivElement;\n stylesNames: FloatingWindowStylesNames;\n staticComponents: {\n ResizeHandle: typeof FloatingWindowResizeHandle;\n };\n}>;\n\nconst defaultProps = {\n constrainToViewport: true,\n zIndex: getDefaultZIndex('overlay'),\n} satisfies Partial<FloatingWindowProps>;\n\nfunction clampDimension(value: number, min?: number, max?: number): number {\n let v = value;\n if (min != null) {\n v = Math.max(v, min);\n }\n if (max != null) {\n v = Math.min(v, max);\n }\n return v;\n}\n\nexport const FloatingWindow = factory<FloatingWindowFactory>((_props) => {\n const props = useProps('FloatingWindow', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n mod,\n enabled,\n constrainToViewport,\n constrainOffset,\n dragHandleSelector,\n excludeDragHandleSelector,\n axis,\n initialPosition,\n onPositionChange,\n onDragStart,\n onDragEnd,\n setPositionRef,\n withinPortal,\n portalProps,\n zIndex,\n dimensions,\n onSizeChange,\n onResizeStart,\n onResizeEnd,\n ref,\n ...others\n } = props;\n\n const rootRef = useRef<HTMLDivElement>(null);\n\n const getStyles = useStyles<FloatingWindowFactory>({\n name: 'FloatingWindow',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n vars,\n });\n\n const floatingWindow = useFloatingWindow({\n enabled,\n constrainToViewport,\n constrainOffset,\n dragHandleSelector,\n excludeDragHandleSelector,\n axis,\n initialPosition,\n onPositionChange,\n onDragStart,\n onDragEnd,\n });\n\n useImperativeHandle(setPositionRef, () => floatingWindow.setPosition, [\n floatingWindow.setPosition,\n ]);\n\n const cssVars: Record<string, string | undefined> = {\n '--floating-window-z-index': zIndex.toString(),\n };\n\n if (dimensions?.initialWidth != null) {\n cssVars['--floating-window-width'] =\n `${clampDimension(dimensions.initialWidth, dimensions.minWidth, dimensions.maxWidth)}px`;\n }\n\n if (dimensions?.initialHeight != null) {\n cssVars['--floating-window-height'] =\n `${clampDimension(dimensions.initialHeight, dimensions.minHeight, dimensions.maxHeight)}px`;\n }\n\n return (\n <FloatingWindowProvider\n value={{\n rootRef,\n dimensions,\n constrainToViewport,\n constrainOffset,\n onSizeChange,\n onResizeStart,\n onResizeEnd,\n }}\n >\n <OptionalPortal withinPortal={withinPortal} {...portalProps}>\n <Paper\n ref={useMergedRef(ref, floatingWindow.ref, rootRef)}\n mod={[{ dragging: floatingWindow.isDragging }, mod]}\n {...getStyles('root')}\n {...others}\n __vars={cssVars}\n />\n </OptionalPortal>\n </FloatingWindowProvider>\n );\n});\n\nFloatingWindow.displayName = '@mantine/core/FloatingWindow';\nFloatingWindow.classes = classes;\nFloatingWindow.ResizeHandle = FloatingWindowResizeHandle;\n"],"mappings":";;;;;;;;;;;;;;AAsEA,MAAM,eAAe;CACnB,qBAAqB;CACrB,QAAQ,iBAAiB,SAAS;AACpC;AAEA,SAAS,eAAe,OAAe,KAAc,KAAsB;CACzE,IAAI,IAAI;CACR,IAAI,OAAO,MACT,IAAI,KAAK,IAAI,GAAG,GAAG;CAErB,IAAI,OAAO,MACT,IAAI,KAAK,IAAI,GAAG,GAAG;CAErB,OAAO;AACT;AAEA,MAAa,iBAAiB,SAAgC,WAAW;CACvE,MAAM,QAAQ,SAAS,kBAAkB,cAAc,MAAM;CAC7D,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,KACA,SACA,qBACA,iBACA,oBACA,2BACA,MACA,iBACA,kBACA,aACA,WACA,gBACA,cACA,aACA,QACA,YACA,cACA,eACA,aACA,KACA,GAAG,WACD;CAEJ,MAAM,UAAU,OAAuB,IAAI;CAE3C,MAAM,YAAY,UAAiC;EACjD,MAAM;EACN,SAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,iBAAiB,kBAAkB;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,oBAAoB,sBAAsB,eAAe,aAAa,CACpE,eAAe,WACjB,CAAC;CAED,MAAM,UAA8C,EAClD,6BAA6B,OAAO,SAAS,EAC/C;CAEA,IAAI,YAAY,gBAAgB,MAC9B,QAAQ,6BACN,GAAG,eAAe,WAAW,cAAc,WAAW,UAAU,WAAW,QAAQ,EAAE;CAGzF,IAAI,YAAY,iBAAiB,MAC/B,QAAQ,8BACN,GAAG,eAAe,WAAW,eAAe,WAAW,WAAW,WAAW,SAAS,EAAE;CAG5F,OACE,oBAAC,wBAAD;EACE,OAAO;GACL;GACA;GACA;GACA;GACA;GACA;GACA;EACF;YAEA,oBAAC,gBAAD;GAA8B;GAAc,GAAI;aAC9C,oBAAC,OAAD;IACE,KAAK,aAAa,KAAK,eAAe,KAAK,OAAO;IAClD,KAAK,CAAC,EAAE,UAAU,eAAe,WAAW,GAAG,GAAG;IAClD,GAAI,UAAU,MAAM;IACpB,GAAI;IACJ,QAAQ;GACT,CAAA;EACa,CAAA;CACM,CAAA;AAE5B,CAAC;AAED,eAAe,cAAc;AAC7B,eAAe,UAAUA;AACzB,eAAe,eAAe"}
|
|
@@ -16,30 +16,24 @@ function clampDimension(value, min, max, viewportMax) {
|
|
|
16
16
|
if (viewportMax != null) v = Math.min(v, viewportMax);
|
|
17
17
|
return v;
|
|
18
18
|
}
|
|
19
|
-
function getViewportLimits(
|
|
19
|
+
function getViewportLimits(rect, constrainToViewport, constrainOffset) {
|
|
20
20
|
if (!constrainToViewport) return {
|
|
21
21
|
maxWidth: void 0,
|
|
22
22
|
maxHeight: void 0
|
|
23
23
|
};
|
|
24
|
-
const rect = root.getBoundingClientRect();
|
|
25
24
|
const offset = constrainOffset ?? 0;
|
|
26
25
|
return {
|
|
27
26
|
maxWidth: window.innerWidth - rect.left - offset,
|
|
28
27
|
maxHeight: window.innerHeight - rect.top - offset
|
|
29
28
|
};
|
|
30
29
|
}
|
|
31
|
-
function constrainWidth(root, width, dimensions, constrainToViewport, constrainOffset) {
|
|
32
|
-
const { maxWidth: vpMax } = getViewportLimits(root, constrainToViewport, constrainOffset);
|
|
33
|
-
return clampDimension(width, dimensions?.minWidth, dimensions?.maxWidth, vpMax);
|
|
34
|
-
}
|
|
35
|
-
function constrainHeight(root, height, dimensions, constrainToViewport, constrainOffset) {
|
|
36
|
-
const { maxHeight: vpMax } = getViewportLimits(root, constrainToViewport, constrainOffset);
|
|
37
|
-
return clampDimension(height, dimensions?.minHeight, dimensions?.maxHeight, vpMax);
|
|
38
|
-
}
|
|
39
30
|
const FloatingWindowResizeHandle = factory((_props) => {
|
|
40
31
|
const { children, ref, style, ...others } = useProps("FloatingWindowResizeHandle", defaultProps, _props);
|
|
41
32
|
const ctx = useFloatingWindowContext();
|
|
42
33
|
const handleRef = useRef(null);
|
|
34
|
+
const ctxRef = useRef(ctx);
|
|
35
|
+
ctxRef.current = ctx;
|
|
36
|
+
const valueNowRef = useRef(null);
|
|
43
37
|
const hasWidth = ctx.dimensions?.initialWidth != null || ctx.dimensions?.minWidth != null || ctx.dimensions?.maxWidth != null;
|
|
44
38
|
const hasHeight = ctx.dimensions?.initialHeight != null || ctx.dimensions?.minHeight != null || ctx.dimensions?.maxHeight != null;
|
|
45
39
|
useEffect(() => {
|
|
@@ -53,23 +47,35 @@ const FloatingWindowResizeHandle = factory((_props) => {
|
|
|
53
47
|
let startWidth = 0;
|
|
54
48
|
let startHeight = 0;
|
|
55
49
|
const applySize = (width, height) => {
|
|
56
|
-
|
|
50
|
+
if (width === null && height === null) return;
|
|
51
|
+
const { dimensions, constrainToViewport, constrainOffset, onSizeChange } = ctxRef.current;
|
|
52
|
+
const root = ctxRef.current.rootRef.current;
|
|
57
53
|
if (!root) return;
|
|
54
|
+
const viewportLimits = getViewportLimits(root.getBoundingClientRect(), constrainToViewport, constrainOffset);
|
|
58
55
|
if (width !== null) {
|
|
59
|
-
const
|
|
60
|
-
root.style.width = `${
|
|
61
|
-
handle.setAttribute("aria-valuenow", String(Math.round(w)));
|
|
56
|
+
const nextWidth = clampDimension(width, dimensions?.minWidth, dimensions?.maxWidth, viewportLimits.maxWidth);
|
|
57
|
+
root.style.width = `${nextWidth}px`;
|
|
62
58
|
}
|
|
63
59
|
if (height !== null) {
|
|
64
|
-
const
|
|
65
|
-
root.style.height = `${
|
|
60
|
+
const nextHeight = clampDimension(height, dimensions?.minHeight, dimensions?.maxHeight, viewportLimits.maxHeight);
|
|
61
|
+
root.style.height = `${nextHeight}px`;
|
|
62
|
+
}
|
|
63
|
+
const resizedRect = root.getBoundingClientRect();
|
|
64
|
+
if (width !== null) {
|
|
65
|
+
valueNowRef.current = resizedRect.width;
|
|
66
|
+
handle.setAttribute("aria-valuenow", String(Math.round(resizedRect.width)));
|
|
66
67
|
}
|
|
68
|
+
onSizeChange?.({
|
|
69
|
+
width: resizedRect.width,
|
|
70
|
+
height: resizedRect.height
|
|
71
|
+
});
|
|
67
72
|
};
|
|
68
73
|
const onStart = (e) => {
|
|
69
74
|
if ("button" in e && e.button !== 0) return;
|
|
70
75
|
e.stopPropagation();
|
|
71
76
|
e.preventDefault();
|
|
72
|
-
|
|
77
|
+
if (!hasWidth && !hasHeight) return;
|
|
78
|
+
const root = ctxRef.current.rootRef.current;
|
|
73
79
|
if (!root) return;
|
|
74
80
|
const point = "touches" in e ? e.touches[0] : e;
|
|
75
81
|
startX = point.clientX;
|
|
@@ -80,6 +86,7 @@ const FloatingWindowResizeHandle = factory((_props) => {
|
|
|
80
86
|
isResizing = true;
|
|
81
87
|
document.body.style.userSelect = "none";
|
|
82
88
|
document.body.style.webkitUserSelect = "none";
|
|
89
|
+
ctxRef.current.onResizeStart?.();
|
|
83
90
|
document.addEventListener("mousemove", onMove, { signal });
|
|
84
91
|
document.addEventListener("mouseup", onEnd, { signal });
|
|
85
92
|
document.addEventListener("touchmove", onMove, {
|
|
@@ -87,6 +94,7 @@ const FloatingWindowResizeHandle = factory((_props) => {
|
|
|
87
94
|
passive: false
|
|
88
95
|
});
|
|
89
96
|
document.addEventListener("touchend", onEnd, { signal });
|
|
97
|
+
document.addEventListener("touchcancel", onEnd, { signal });
|
|
90
98
|
};
|
|
91
99
|
const onMove = (e) => {
|
|
92
100
|
if (!isResizing) return;
|
|
@@ -101,9 +109,11 @@ const FloatingWindowResizeHandle = factory((_props) => {
|
|
|
101
109
|
isResizing = false;
|
|
102
110
|
document.body.style.userSelect = "";
|
|
103
111
|
document.body.style.webkitUserSelect = "";
|
|
112
|
+
ctxRef.current.onResizeEnd?.();
|
|
104
113
|
};
|
|
105
114
|
const onKeyDown = (e) => {
|
|
106
|
-
const
|
|
115
|
+
const { dimensions } = ctxRef.current;
|
|
116
|
+
const root = ctxRef.current.rootRef.current;
|
|
107
117
|
if (!root) return;
|
|
108
118
|
const rect = root.getBoundingClientRect();
|
|
109
119
|
let newWidth = null;
|
|
@@ -113,11 +123,11 @@ const FloatingWindowResizeHandle = factory((_props) => {
|
|
|
113
123
|
else if (e.key === "ArrowDown" && hasHeight) newHeight = rect.height + KEYBOARD_STEP;
|
|
114
124
|
else if (e.key === "ArrowUp" && hasHeight) newHeight = rect.height - KEYBOARD_STEP;
|
|
115
125
|
else if (e.key === "Home") {
|
|
116
|
-
if (hasWidth) newWidth =
|
|
117
|
-
if (hasHeight) newHeight =
|
|
126
|
+
if (hasWidth) newWidth = dimensions?.minWidth ?? rect.width;
|
|
127
|
+
if (hasHeight) newHeight = dimensions?.minHeight ?? rect.height;
|
|
118
128
|
} else if (e.key === "End") {
|
|
119
|
-
if (hasWidth) newWidth =
|
|
120
|
-
if (hasHeight) newHeight =
|
|
129
|
+
if (hasWidth) newWidth = dimensions?.maxWidth ?? rect.width;
|
|
130
|
+
if (hasHeight) newHeight = dimensions?.maxHeight ?? rect.height;
|
|
121
131
|
}
|
|
122
132
|
if (newWidth !== null || newHeight !== null) {
|
|
123
133
|
e.preventDefault();
|
|
@@ -131,21 +141,36 @@ const FloatingWindowResizeHandle = factory((_props) => {
|
|
|
131
141
|
});
|
|
132
142
|
handle.addEventListener("keydown", onKeyDown, { signal });
|
|
133
143
|
return () => {
|
|
144
|
+
onEnd();
|
|
134
145
|
controller.abort();
|
|
135
146
|
};
|
|
147
|
+
}, [hasWidth, hasHeight]);
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
const handle = handleRef.current;
|
|
150
|
+
if (!handle) return;
|
|
151
|
+
if (!hasWidth) {
|
|
152
|
+
valueNowRef.current = null;
|
|
153
|
+
handle.removeAttribute("aria-valuenow");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (valueNowRef.current !== null) return;
|
|
157
|
+
const initialWidth = ctx.dimensions?.initialWidth;
|
|
158
|
+
if (initialWidth == null) {
|
|
159
|
+
handle.removeAttribute("aria-valuenow");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const width = clampDimension(initialWidth, ctx.dimensions?.minWidth, ctx.dimensions?.maxWidth, void 0);
|
|
163
|
+
handle.setAttribute("aria-valuenow", String(Math.round(width)));
|
|
136
164
|
}, [
|
|
137
|
-
ctx.rootRef,
|
|
138
|
-
ctx.dimensions,
|
|
139
|
-
ctx.constrainToViewport,
|
|
140
|
-
ctx.constrainOffset,
|
|
141
165
|
hasWidth,
|
|
142
|
-
|
|
166
|
+
ctx.dimensions?.initialWidth,
|
|
167
|
+
ctx.dimensions?.minWidth,
|
|
168
|
+
ctx.dimensions?.maxWidth
|
|
143
169
|
]);
|
|
144
170
|
return /* @__PURE__ */ jsx(Box, {
|
|
145
171
|
ref: useMergedRef(ref, handleRef),
|
|
146
172
|
role: "separator",
|
|
147
173
|
"aria-label": "Resize window",
|
|
148
|
-
"aria-valuenow": ctx.dimensions?.initialWidth,
|
|
149
174
|
"aria-valuemin": ctx.dimensions?.minWidth,
|
|
150
175
|
"aria-valuemax": ctx.dimensions?.maxWidth,
|
|
151
176
|
tabIndex: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FloatingWindowResizeHandle.mjs","names":[],"sources":["../../../src/components/FloatingWindow/FloatingWindowResizeHandle.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-deprecated */\nimport { useEffect, useRef } from 'react';\nimport { useMergedRef } from '@mantine/hooks';\nimport { Box, BoxProps, ElementProps, factory, Factory, useProps } from '../../core';\nimport { FloatingWindowDimensions, useFloatingWindowContext } from './FloatingWindow.context';\n\nexport interface FloatingWindowResizeHandleProps extends BoxProps, ElementProps<'div', 'role'> {}\n\nexport type FloatingWindowResizeHandleFactory = Factory<{\n props: FloatingWindowResizeHandleProps;\n ref: HTMLDivElement;\n}>;\n\nconst defaultProps = {} satisfies Partial<FloatingWindowResizeHandleProps>;\n\nconst KEYBOARD_STEP = 10;\n\nfunction clampDimension(\n value: number,\n min: number | undefined,\n max: number | undefined,\n viewportMax: number | undefined\n) {\n let v = value;\n if (min != null) {\n v = Math.max(v, min);\n }\n if (max != null) {\n v = Math.min(v, max);\n }\n if (viewportMax != null) {\n v = Math.min(v, viewportMax);\n }\n return v;\n}\n\nfunction getViewportLimits(\n root: HTMLElement,\n constrainToViewport: boolean | undefined,\n constrainOffset: number | undefined\n) {\n if (!constrainToViewport) {\n return { maxWidth: undefined, maxHeight: undefined };\n }\n const rect = root.getBoundingClientRect();\n const offset = constrainOffset ?? 0;\n return {\n maxWidth: window.innerWidth - rect.left - offset,\n maxHeight: window.innerHeight - rect.top - offset,\n };\n}\n\nfunction constrainWidth(\n root: HTMLElement,\n width: number,\n dimensions: FloatingWindowDimensions | undefined,\n constrainToViewport: boolean | undefined,\n constrainOffset: number | undefined\n) {\n const { maxWidth: vpMax } = getViewportLimits(root, constrainToViewport, constrainOffset);\n return clampDimension(width, dimensions?.minWidth, dimensions?.maxWidth, vpMax);\n}\n\nfunction constrainHeight(\n root: HTMLElement,\n height: number,\n dimensions: FloatingWindowDimensions | undefined,\n constrainToViewport: boolean | undefined,\n constrainOffset: number | undefined\n) {\n const { maxHeight: vpMax } = getViewportLimits(root, constrainToViewport, constrainOffset);\n return clampDimension(height, dimensions?.minHeight, dimensions?.maxHeight, vpMax);\n}\n\nexport const FloatingWindowResizeHandle = factory<FloatingWindowResizeHandleFactory>((_props) => {\n const props = useProps('FloatingWindowResizeHandle', defaultProps, _props);\n const { children, ref, style, ...others } = props;\n const ctx = useFloatingWindowContext();\n const handleRef = useRef<HTMLDivElement>(null);\n\n const hasWidth =\n ctx.dimensions?.initialWidth != null ||\n ctx.dimensions?.minWidth != null ||\n ctx.dimensions?.maxWidth != null;\n const hasHeight =\n ctx.dimensions?.initialHeight != null ||\n ctx.dimensions?.minHeight != null ||\n ctx.dimensions?.maxHeight != null;\n\n useEffect(() => {\n const handle = handleRef.current;\n if (!handle) {\n return;\n }\n\n const controller = new AbortController();\n const { signal } = controller;\n let isResizing = false;\n let startX = 0;\n let startY = 0;\n let startWidth = 0;\n let startHeight = 0;\n\n const applySize = (width: number | null, height: number | null) => {\n const root = ctx.rootRef.current;\n if (!root) {\n return;\n }\n\n if (width !== null) {\n const w = constrainWidth(\n root,\n width,\n ctx.dimensions,\n ctx.constrainToViewport,\n ctx.constrainOffset\n );\n root.style.width = `${w}px`;\n handle.setAttribute('aria-valuenow', String(Math.round(w)));\n }\n\n if (height !== null) {\n const h = constrainHeight(\n root,\n height,\n ctx.dimensions,\n ctx.constrainToViewport,\n ctx.constrainOffset\n );\n root.style.height = `${h}px`;\n }\n };\n\n const onStart = (e: MouseEvent | TouchEvent) => {\n if ('button' in e && e.button !== 0) {\n return;\n }\n\n e.stopPropagation();\n e.preventDefault();\n\n const root = ctx.rootRef.current;\n if (!root) {\n return;\n }\n\n const point = 'touches' in e ? e.touches[0] : e;\n startX = point.clientX;\n startY = point.clientY;\n const rect = root.getBoundingClientRect();\n startWidth = rect.width;\n startHeight = rect.height;\n isResizing = true;\n\n document.body.style.userSelect = 'none';\n document.body.style.webkitUserSelect = 'none';\n\n document.addEventListener('mousemove', onMove, { signal });\n document.addEventListener('mouseup', onEnd, { signal });\n document.addEventListener('touchmove', onMove, { signal, passive: false });\n document.addEventListener('touchend', onEnd, { signal });\n };\n\n const onMove = (e: MouseEvent | TouchEvent) => {\n if (!isResizing) {\n return;\n }\n\n e.preventDefault();\n const point = 'touches' in e ? e.touches[0] : e;\n const deltaX = point.clientX - startX;\n const deltaY = point.clientY - startY;\n applySize(hasWidth ? startWidth + deltaX : null, hasHeight ? startHeight + deltaY : null);\n };\n\n const onEnd = () => {\n if (!isResizing) {\n return;\n }\n\n isResizing = false;\n document.body.style.userSelect = '';\n document.body.style.webkitUserSelect = '';\n };\n\n const onKeyDown = (e: KeyboardEvent) => {\n const root = ctx.rootRef.current;\n if (!root) {\n return;\n }\n\n const rect = root.getBoundingClientRect();\n let newWidth: number | null = null;\n let newHeight: number | null = null;\n\n if (e.key === 'ArrowRight' && hasWidth) {\n newWidth = rect.width + KEYBOARD_STEP;\n } else if (e.key === 'ArrowLeft' && hasWidth) {\n newWidth = rect.width - KEYBOARD_STEP;\n } else if (e.key === 'ArrowDown' && hasHeight) {\n newHeight = rect.height + KEYBOARD_STEP;\n } else if (e.key === 'ArrowUp' && hasHeight) {\n newHeight = rect.height - KEYBOARD_STEP;\n } else if (e.key === 'Home') {\n if (hasWidth) {\n newWidth = ctx.dimensions?.minWidth ?? rect.width;\n }\n if (hasHeight) {\n newHeight = ctx.dimensions?.minHeight ?? rect.height;\n }\n } else if (e.key === 'End') {\n if (hasWidth) {\n newWidth = ctx.dimensions?.maxWidth ?? rect.width;\n }\n if (hasHeight) {\n newHeight = ctx.dimensions?.maxHeight ?? rect.height;\n }\n }\n\n if (newWidth !== null || newHeight !== null) {\n e.preventDefault();\n applySize(newWidth, newHeight);\n }\n };\n\n handle.addEventListener('mousedown', onStart, { signal });\n handle.addEventListener('touchstart', onStart, { signal, passive: false });\n handle.addEventListener('keydown', onKeyDown, { signal });\n\n return () => {\n controller.abort();\n };\n }, [\n ctx.rootRef,\n ctx.dimensions,\n ctx.constrainToViewport,\n ctx.constrainOffset,\n hasWidth,\n hasHeight,\n ]);\n\n return (\n <Box\n ref={useMergedRef(ref, handleRef)}\n role=\"separator\"\n aria-label=\"Resize window\"\n aria-valuenow={ctx.dimensions?.initialWidth}\n aria-valuemin={ctx.dimensions?.minWidth}\n aria-valuemax={ctx.dimensions?.maxWidth}\n tabIndex={0}\n {...others}\n style={[{ touchAction: 'none' }, style]}\n >\n {children}\n </Box>\n );\n});\n\nFloatingWindowResizeHandle.displayName = '@mantine/core/FloatingWindowResizeHandle';\n"],"mappings":";;;;;;;;;AAaA,MAAM,eAAe,CAAC;AAEtB,MAAM,gBAAgB;AAEtB,SAAS,eACP,OACA,KACA,KACA,aACA;CACA,IAAI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ACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ;EACA;CACF,CAAC;CAED,OACE,oBAAC,KAAD;EACE,KAAK,aAAa,KAAK,SAAS;EAChC,MAAK;EACL,cAAW;EACX,iBAAe,IAAI,YAAY;EAC/B,iBAAe,IAAI,YAAY;EAC/B,iBAAe,IAAI,YAAY;EAC/B,UAAU;EACV,GAAI;EACJ,OAAO,CAAC,EAAE,aAAa,OAAO,GAAG,KAAK;EAErC;CACE,CAAA;AAET,CAAC;AAED,2BAA2B,cAAc"}
|
|
1
|
+
{"version":3,"file":"FloatingWindowResizeHandle.mjs","names":[],"sources":["../../../src/components/FloatingWindow/FloatingWindowResizeHandle.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-deprecated */\nimport { useEffect, useRef } from 'react';\nimport { useMergedRef } from '@mantine/hooks';\nimport { Box, BoxProps, ElementProps, factory, Factory, useProps } from '../../core';\nimport { useFloatingWindowContext } from './FloatingWindow.context';\n\nexport interface FloatingWindowResizeHandleProps extends BoxProps, ElementProps<'div', 'role'> {}\n\nexport type FloatingWindowResizeHandleFactory = Factory<{\n props: FloatingWindowResizeHandleProps;\n ref: HTMLDivElement;\n}>;\n\nconst defaultProps = {} satisfies Partial<FloatingWindowResizeHandleProps>;\n\nconst KEYBOARD_STEP = 10;\n\nfunction clampDimension(\n value: number,\n min: number | undefined,\n max: number | undefined,\n viewportMax: number | undefined\n) {\n let v = value;\n if (min != null) {\n v = Math.max(v, min);\n }\n if (max != null) {\n v = Math.min(v, max);\n }\n if (viewportMax != null) {\n v = Math.min(v, viewportMax);\n }\n return v;\n}\n\nfunction getViewportLimits(\n rect: DOMRect,\n constrainToViewport: boolean | undefined,\n constrainOffset: number | undefined\n) {\n if (!constrainToViewport) {\n return { maxWidth: undefined, maxHeight: undefined };\n }\n const offset = constrainOffset ?? 0;\n return {\n maxWidth: window.innerWidth - rect.left - offset,\n maxHeight: window.innerHeight - rect.top - offset,\n };\n}\n\nexport const FloatingWindowResizeHandle = factory<FloatingWindowResizeHandleFactory>((_props) => {\n const props = useProps('FloatingWindowResizeHandle', defaultProps, _props);\n const { children, ref, style, ...others } = props;\n const ctx = useFloatingWindowContext();\n const handleRef = useRef<HTMLDivElement>(null);\n const ctxRef = useRef(ctx);\n ctxRef.current = ctx;\n const valueNowRef = useRef<number | null>(null);\n\n const hasWidth =\n ctx.dimensions?.initialWidth != null ||\n ctx.dimensions?.minWidth != null ||\n ctx.dimensions?.maxWidth != null;\n const hasHeight =\n ctx.dimensions?.initialHeight != null ||\n ctx.dimensions?.minHeight != null ||\n ctx.dimensions?.maxHeight != null;\n\n useEffect(() => {\n const handle = handleRef.current;\n if (!handle) {\n return;\n }\n\n const controller = new AbortController();\n const { signal } = controller;\n let isResizing = false;\n let startX = 0;\n let startY = 0;\n let startWidth = 0;\n let startHeight = 0;\n\n const applySize = (width: number | null, height: number | null) => {\n if (width === null && height === null) {\n return;\n }\n\n const { dimensions, constrainToViewport, constrainOffset, onSizeChange } = ctxRef.current;\n const root = ctxRef.current.rootRef.current;\n if (!root) {\n return;\n }\n\n const rect = root.getBoundingClientRect();\n const viewportLimits = getViewportLimits(rect, constrainToViewport, constrainOffset);\n\n if (width !== null) {\n const nextWidth = clampDimension(\n width,\n dimensions?.minWidth,\n dimensions?.maxWidth,\n viewportLimits.maxWidth\n );\n root.style.width = `${nextWidth}px`;\n }\n\n if (height !== null) {\n const nextHeight = clampDimension(\n height,\n dimensions?.minHeight,\n dimensions?.maxHeight,\n viewportLimits.maxHeight\n );\n root.style.height = `${nextHeight}px`;\n }\n\n const resizedRect = root.getBoundingClientRect();\n\n if (width !== null) {\n valueNowRef.current = resizedRect.width;\n handle.setAttribute('aria-valuenow', String(Math.round(resizedRect.width)));\n }\n\n onSizeChange?.({ width: resizedRect.width, height: resizedRect.height });\n };\n\n const onStart = (e: MouseEvent | TouchEvent) => {\n if ('button' in e && e.button !== 0) {\n return;\n }\n\n e.stopPropagation();\n e.preventDefault();\n\n if (!hasWidth && !hasHeight) {\n return;\n }\n\n const root = ctxRef.current.rootRef.current;\n if (!root) {\n return;\n }\n\n const point = 'touches' in e ? e.touches[0] : e;\n startX = point.clientX;\n startY = point.clientY;\n const rect = root.getBoundingClientRect();\n startWidth = rect.width;\n startHeight = rect.height;\n isResizing = true;\n\n document.body.style.userSelect = 'none';\n document.body.style.webkitUserSelect = 'none';\n\n ctxRef.current.onResizeStart?.();\n\n document.addEventListener('mousemove', onMove, { signal });\n document.addEventListener('mouseup', onEnd, { signal });\n document.addEventListener('touchmove', onMove, { signal, passive: false });\n document.addEventListener('touchend', onEnd, { signal });\n document.addEventListener('touchcancel', onEnd, { signal });\n };\n\n const onMove = (e: MouseEvent | TouchEvent) => {\n if (!isResizing) {\n return;\n }\n\n e.preventDefault();\n const point = 'touches' in e ? e.touches[0] : e;\n const deltaX = point.clientX - startX;\n const deltaY = point.clientY - startY;\n applySize(hasWidth ? startWidth + deltaX : null, hasHeight ? startHeight + deltaY : null);\n };\n\n const onEnd = () => {\n if (!isResizing) {\n return;\n }\n\n isResizing = false;\n document.body.style.userSelect = '';\n document.body.style.webkitUserSelect = '';\n ctxRef.current.onResizeEnd?.();\n };\n\n const onKeyDown = (e: KeyboardEvent) => {\n const { dimensions } = ctxRef.current;\n const root = ctxRef.current.rootRef.current;\n if (!root) {\n return;\n }\n\n const rect = root.getBoundingClientRect();\n let newWidth: number | null = null;\n let newHeight: number | null = null;\n\n if (e.key === 'ArrowRight' && hasWidth) {\n newWidth = rect.width + KEYBOARD_STEP;\n } else if (e.key === 'ArrowLeft' && hasWidth) {\n newWidth = rect.width - KEYBOARD_STEP;\n } else if (e.key === 'ArrowDown' && hasHeight) {\n newHeight = rect.height + KEYBOARD_STEP;\n } else if (e.key === 'ArrowUp' && hasHeight) {\n newHeight = rect.height - KEYBOARD_STEP;\n } else if (e.key === 'Home') {\n if (hasWidth) {\n newWidth = dimensions?.minWidth ?? rect.width;\n }\n if (hasHeight) {\n newHeight = dimensions?.minHeight ?? rect.height;\n }\n } else if (e.key === 'End') {\n if (hasWidth) {\n newWidth = dimensions?.maxWidth ?? rect.width;\n }\n if (hasHeight) {\n newHeight = dimensions?.maxHeight ?? rect.height;\n }\n }\n\n if (newWidth !== null || newHeight !== null) {\n e.preventDefault();\n applySize(newWidth, newHeight);\n }\n };\n\n handle.addEventListener('mousedown', onStart, { signal });\n handle.addEventListener('touchstart', onStart, { signal, passive: false });\n handle.addEventListener('keydown', onKeyDown, { signal });\n\n return () => {\n onEnd();\n controller.abort();\n };\n }, [hasWidth, hasHeight]);\n\n useEffect(() => {\n const handle = handleRef.current;\n if (!handle) {\n return;\n }\n\n if (!hasWidth) {\n valueNowRef.current = null;\n handle.removeAttribute('aria-valuenow');\n return;\n }\n\n if (valueNowRef.current !== null) {\n return;\n }\n\n const initialWidth = ctx.dimensions?.initialWidth;\n\n if (initialWidth == null) {\n handle.removeAttribute('aria-valuenow');\n return;\n }\n\n const width = clampDimension(\n initialWidth,\n ctx.dimensions?.minWidth,\n ctx.dimensions?.maxWidth,\n undefined\n );\n\n handle.setAttribute('aria-valuenow', String(Math.round(width)));\n }, [hasWidth, ctx.dimensions?.initialWidth, ctx.dimensions?.minWidth, ctx.dimensions?.maxWidth]);\n\n return (\n <Box\n ref={useMergedRef(ref, handleRef)}\n role=\"separator\"\n aria-label=\"Resize window\"\n aria-valuemin={ctx.dimensions?.minWidth}\n aria-valuemax={ctx.dimensions?.maxWidth}\n tabIndex={0}\n {...others}\n style={[{ touchAction: 'none' }, style]}\n >\n {children}\n </Box>\n );\n});\n\nFloatingWindowResizeHandle.displayName = '@mantine/core/FloatingWindowResizeHandle';\n"],"mappings":";;;;;;;;;AAaA,MAAM,eAAe,CAAC;AAEtB,MAAM,gBAAgB;AAEtB,SAAS,eACP,OACA,KACA,KACA,aACA;CACA,IAAI,IAAI;CACR,IAAI,OAAO,MACT,IAAI,KAAK,IAAI,GAAG,GAAG;CAErB,IAAI,OAAO,MACT,IAAI,KAAK,IAAI,GAAG,GAAG;CAErB,IA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AAW,EAAE,OAAO,CAAC;EAExD,aAAa;GACX,MAAM;GACN,WAAW,MAAM;EACnB;CACF,GAAG,CAAC,UAAU,SAAS,CAAC;CAExB,gBAAgB;EACd,MAAM,SAAS,UAAU;EACzB,IAAI,CAAC,QACH;EAGF,IAAI,CAAC,UAAU;GACb,YAAY,UAAU;GACtB,OAAO,gBAAgB,eAAe;GACtC;EACF;EAEA,IAAI,YAAY,YAAY,MAC1B;EAGF,MAAM,eAAe,IAAI,YAAY;EAErC,IAAI,gBAAgB,MAAM;GACxB,OAAO,gBAAgB,eAAe;GACtC;EACF;EAEA,MAAM,QAAQ,eACZ,cACA,IAAI,YAAY,UAChB,IAAI,YAAY,UAChB,KAAA,CACF;EAEA,OAAO,aAAa,iBAAiB,OAAO,KAAK,MAAM,KAAK,CAAC,CAAC;CAChE,GAAG;EAAC;EAAU,IAAI,YAAY;EAAc,IAAI,YAAY;EAAU,IAAI,YAAY;CAAQ,CAAC;CAE/F,OACE,oBAAC,KAAD;EACE,KAAK,aAAa,KAAK,SAAS;EAChC,MAAK;EACL,cAAW;EACX,iBAAe,IAAI,YAAY;EAC/B,iBAAe,IAAI,YAAY;EAC/B,UAAU;EACV,GAAI;EACJ,OAAO,CAAC,EAAE,aAAa,OAAO,GAAG,KAAK;EAErC;CACE,CAAA;AAET,CAAC;AAED,2BAA2B,cAAc"}
|
|
@@ -34,13 +34,15 @@ const InputLabel = factory((_props) => {
|
|
|
34
34
|
});
|
|
35
35
|
const ctx = use(InputWrapperContext);
|
|
36
36
|
const getStyles = ctx?.getStyles || _getStyles;
|
|
37
|
+
const rootElement = others.component || labelElement;
|
|
38
|
+
const supportsHtmlFor = typeof rootElement !== "string" || rootElement === "label";
|
|
37
39
|
return /* @__PURE__ */ jsxs(Box, {
|
|
38
40
|
...getStyles("label", ctx?.getStyles ? {
|
|
39
41
|
className,
|
|
40
42
|
style
|
|
41
43
|
} : void 0),
|
|
42
44
|
component: labelElement,
|
|
43
|
-
htmlFor:
|
|
45
|
+
htmlFor: supportsHtmlFor ? htmlFor : void 0,
|
|
44
46
|
mod: [{ required }, mod],
|
|
45
47
|
onMouseDown: (event) => {
|
|
46
48
|
onMouseDown?.(event);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputLabel.mjs","names":["classes"],"sources":["../../../../src/components/Input/InputLabel/InputLabel.tsx"],"sourcesContent":["import { use } from 'react';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getFontSize,\n MantineFontSize,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../../core';\nimport { InputWrapperContext } from '../InputWrapper.context';\nimport classes from '../Input.module.css';\n\nexport type InputLabelStylesNames = 'label' | 'required';\nexport type InputLabelCssVariables = {\n label: '--input-asterisk-color' | '--input-label-size';\n};\n\nexport interface InputLabelProps\n extends BoxProps, StylesApiProps<InputLabelFactory>, ElementProps<'label'> {\n __staticSelector?: string;\n\n /** If set, the required asterisk is displayed next to the label */\n required?: boolean;\n\n /** Controls label `font-size` @default 'sm' */\n size?: MantineFontSize;\n\n /** Root element of the label @default 'label' */\n labelElement?: 'label' | 'div';\n}\n\nexport type InputLabelFactory = Factory<{\n props: InputLabelProps;\n ref: HTMLLabelElement;\n stylesNames: InputLabelStylesNames;\n vars: InputLabelCssVariables;\n}>;\n\nconst defaultProps = {\n labelElement: 'label',\n} satisfies Partial<InputLabelProps>;\n\nconst varsResolver = createVarsResolver<InputLabelFactory>((_, { size }) => ({\n label: {\n '--input-label-size': getFontSize(size),\n '--input-asterisk-color': undefined,\n },\n}));\n\nexport const InputLabel = factory<InputLabelFactory>((_props) => {\n const props = useProps('InputLabel', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n labelElement,\n required,\n htmlFor,\n onMouseDown,\n children,\n __staticSelector,\n mod,\n attributes,\n ...others\n } = props;\n\n const _getStyles = useStyles<InputLabelFactory>({\n name: ['InputWrapper', __staticSelector],\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n rootSelector: 'label',\n vars,\n varsResolver,\n });\n\n const ctx = use(InputWrapperContext);\n const getStyles = ctx?.getStyles || _getStyles;\n\n return (\n <Box\n {...getStyles('label', ctx?.getStyles ? { className, style } : undefined)}\n component={labelElement as 'label'}\n htmlFor={
|
|
1
|
+
{"version":3,"file":"InputLabel.mjs","names":["classes"],"sources":["../../../../src/components/Input/InputLabel/InputLabel.tsx"],"sourcesContent":["import { use } from 'react';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getFontSize,\n MantineFontSize,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../../core';\nimport { InputWrapperContext } from '../InputWrapper.context';\nimport classes from '../Input.module.css';\n\nexport type InputLabelStylesNames = 'label' | 'required';\nexport type InputLabelCssVariables = {\n label: '--input-asterisk-color' | '--input-label-size';\n};\n\nexport interface InputLabelProps\n extends BoxProps, StylesApiProps<InputLabelFactory>, ElementProps<'label'> {\n __staticSelector?: string;\n\n /** If set, the required asterisk is displayed next to the label */\n required?: boolean;\n\n /** Controls label `font-size` @default 'sm' */\n size?: MantineFontSize;\n\n /** Root element of the label @default 'label' */\n labelElement?: 'label' | 'div';\n}\n\nexport type InputLabelFactory = Factory<{\n props: InputLabelProps;\n ref: HTMLLabelElement;\n stylesNames: InputLabelStylesNames;\n vars: InputLabelCssVariables;\n}>;\n\nconst defaultProps = {\n labelElement: 'label',\n} satisfies Partial<InputLabelProps>;\n\nconst varsResolver = createVarsResolver<InputLabelFactory>((_, { size }) => ({\n label: {\n '--input-label-size': getFontSize(size),\n '--input-asterisk-color': undefined,\n },\n}));\n\nexport const InputLabel = factory<InputLabelFactory>((_props) => {\n const props = useProps('InputLabel', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n labelElement,\n required,\n htmlFor,\n onMouseDown,\n children,\n __staticSelector,\n mod,\n attributes,\n ...others\n } = props;\n\n const _getStyles = useStyles<InputLabelFactory>({\n name: ['InputWrapper', __staticSelector],\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n rootSelector: 'label',\n vars,\n varsResolver,\n });\n\n const ctx = use(InputWrapperContext);\n const getStyles = ctx?.getStyles || _getStyles;\n const rootElement = (others as { component?: React.ElementType }).component || labelElement;\n const supportsHtmlFor = typeof rootElement !== 'string' || rootElement === 'label';\n\n return (\n <Box\n {...getStyles('label', ctx?.getStyles ? { className, style } : undefined)}\n component={labelElement as 'label'}\n htmlFor={supportsHtmlFor ? htmlFor : undefined}\n mod={[{ required }, mod]}\n onMouseDown={(event) => {\n onMouseDown?.(event);\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault();\n }\n }}\n {...others}\n >\n {children}\n {required && (\n <span {...getStyles('required')} aria-hidden>\n {' *'}\n </span>\n )}\n </Box>\n );\n});\n\nInputLabel.classes = classes;\nInputLabel.varsResolver = varsResolver;\nInputLabel.displayName = '@mantine/core/InputLabel';\n"],"mappings":";;;;;;;;;;;;AA2CA,MAAM,eAAe,EACnB,cAAc,QAChB;AAEA,MAAM,eAAe,oBAAuC,GAAG,EAAE,YAAY,EAC3E,OAAO;CACL,sBAAsB,YAAY,IAAI;CACtC,0BAA0B,KAAA;AAC5B,EACF,EAAE;AAEF,MAAa,aAAa,SAA4B,WAAW;CAC/D,MAAM,QAAQ,SAAS,cAAc,cAAc,MAAM;CACzD,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,cACA,UACA,SACA,aACA,UACA,kBACA,KACA,YACA,GAAG,WACD;CAEJ,MAAM,aAAa,UAA6B;EAC9C,MAAM,CAAC,gBAAgB,gBAAgB;EACvC;EACA,SAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,cAAc;EACd;EACA;CACF,CAAC;CAED,MAAM,MAAM,IAAI,mBAAmB;CACnC,MAAM,YAAY,KAAK,aAAa;CACpC,MAAM,cAAe,OAA6C,aAAa;CAC/E,MAAM,kBAAkB,OAAO,gBAAgB,YAAY,gBAAgB;CAE3E,OACE,qBAAC,KAAD;EACE,GAAI,UAAU,SAAS,KAAK,YAAY;GAAE;GAAW;EAAM,IAAI,KAAA,CAAS;EACxE,WAAW;EACX,SAAS,kBAAkB,UAAU,KAAA;EACrC,KAAK,CAAC,EAAE,SAAS,GAAG,GAAG;EACvB,cAAc,UAAU;GACtB,cAAc,KAAK;GACnB,IAAI,CAAC,MAAM,oBAAoB,MAAM,SAAS,GAC5C,MAAM,eAAe;EAEzB;EACA,GAAI;YAXN,CAaG,UACA,YACC,oBAAC,QAAD;GAAM,GAAI,UAAU,UAAU;GAAG,eAAA;aAC9B;EACG,CAAA,CAEL;;AAET,CAAC;AAED,WAAW,UAAUA;AACrB,WAAW,eAAe;AAC1B,WAAW,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputWrapper.mjs","names":["useId","classes"],"sources":["../../../../src/components/Input/InputWrapper/InputWrapper.tsx"],"sourcesContent":["import { Fragment } from 'react';\nimport { useId } from '@mantine/hooks';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n DataAttributes,\n ElementProps,\n factory,\n Factory,\n getFontSize,\n MantineFontSize,\n rem,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../../core';\nimport {\n InputDescription,\n InputDescriptionCssVariables,\n InputDescriptionProps,\n InputDescriptionStylesNames,\n} from '../InputDescription/InputDescription';\nimport {\n InputError,\n InputErrorCssVariables,\n InputErrorProps,\n InputErrorStylesNames,\n} from '../InputError/InputError';\nimport {\n InputLabel,\n InputLabelCssVariables,\n InputLabelProps,\n InputLabelStylesNames,\n} from '../InputLabel/InputLabel';\nimport {\n InputSuccess,\n InputSuccessCssVariables,\n InputSuccessProps,\n InputSuccessStylesNames,\n} from '../InputSuccess/InputSuccess';\nimport { InputWrapperContext } from '../InputWrapper.context';\nimport { getInputOffsets } from './get-input-offsets/get-input-offsets';\nimport classes from '../Input.module.css';\n\nexport type InputWrapperCssVariables = InputLabelCssVariables &\n InputErrorCssVariables &\n InputSuccessCssVariables &\n InputDescriptionCssVariables;\n\nexport type InputWrapperStylesNames =\n | 'root'\n | InputLabelStylesNames\n | InputDescriptionStylesNames\n | InputErrorStylesNames\n | InputSuccessStylesNames;\n\nexport interface __InputWrapperProps {\n /** Contents of `Input.Label` component. If not set, label is not displayed. */\n label?: React.ReactNode;\n\n /** Contents of `Input.Description` component. If not set, description is not displayed. */\n description?: React.ReactNode;\n\n /** Contents of `Input.Error` component. If not set, error is not displayed. */\n error?: React.ReactNode;\n\n /** Contents of `Input.Success` component. If not set, success is not displayed. */\n success?: React.ReactNode;\n\n /** Adds required attribute to the input and a red asterisk on the right side of label @default false */\n required?: boolean;\n\n /** If set, the required asterisk is displayed next to the label. Overrides `required` prop. Does not add required attribute to the input. @default false */\n withAsterisk?: boolean;\n\n /** Props passed down to the `Input.Label` component */\n labelProps?: InputLabelProps & DataAttributes;\n\n /** Props passed down to the `Input.Description` component */\n descriptionProps?: InputDescriptionProps & DataAttributes;\n\n /** Props passed down to the `Input.Error` component */\n errorProps?: InputErrorProps & DataAttributes;\n\n /** Props passed down to the `Input.Success` component */\n successProps?: InputSuccessProps & DataAttributes;\n\n /** Render function to wrap the input element. Useful for adding tooltips, popovers, or other wrappers around the input. @default React.Fragment */\n inputContainer?: (children: React.ReactNode) => React.ReactNode;\n\n /** Controls order and visibility of wrapper elements. Only elements included in this array will be rendered. @default ['label', 'description', 'input', 'error'] */\n inputWrapperOrder?: ('label' | 'input' | 'description' | 'error')[];\n}\n\nexport interface InputWrapperProps\n extends __InputWrapperProps, BoxProps, StylesApiProps<InputWrapperFactory>, ElementProps<'div'> {\n __staticSelector?: string;\n\n /** Props passed to Styles API context, replaces Input.Wrapper props */\n __stylesApiProps?: Record<string, any>;\n\n /** Static id used as base to generate `aria-` attributes, by default generates random id */\n id?: string;\n\n /** Controls size of `Input.Label`, `Input.Description` and `Input.Error` components */\n size?: MantineFontSize;\n\n /** Root element for the label. Use `'div'` when wrapper contains multiple input elements and you need to handle `htmlFor` manually. @default 'label' */\n labelElement?: 'label' | 'div';\n}\n\nexport type InputWrapperFactory = Factory<{\n props: InputWrapperProps;\n ref: HTMLDivElement;\n stylesNames: InputWrapperStylesNames;\n vars: InputWrapperCssVariables;\n}>;\n\nconst defaultProps = {\n labelElement: 'label',\n inputContainer: (children) => children,\n inputWrapperOrder: ['label', 'description', 'input', 'error'],\n} satisfies Partial<InputWrapperProps>;\n\nconst varsResolver = createVarsResolver<InputWrapperFactory>((_, { size }) => ({\n label: {\n '--input-label-size': getFontSize(size),\n '--input-asterisk-color': undefined,\n },\n\n error: {\n '--input-error-size': size === undefined ? undefined : `calc(${getFontSize(size)} - ${rem(2)})`,\n },\n\n success: {\n '--input-success-size':\n size === undefined ? undefined : `calc(${getFontSize(size)} - ${rem(2)})`,\n },\n\n description: {\n '--input-description-size':\n size === undefined ? undefined : `calc(${getFontSize(size)} - ${rem(2)})`,\n },\n}));\n\nexport const InputWrapper = factory<InputWrapperFactory>((_props) => {\n const props = useProps('InputWrapper', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n size,\n variant,\n __staticSelector,\n inputContainer,\n inputWrapperOrder,\n label,\n error,\n success,\n description,\n labelProps,\n descriptionProps,\n errorProps,\n successProps,\n labelElement,\n children,\n withAsterisk,\n id,\n required,\n __stylesApiProps,\n mod,\n attributes,\n ...others\n } = props;\n\n const getStyles = useStyles<InputWrapperFactory>({\n name: ['InputWrapper', __staticSelector],\n props: __stylesApiProps || props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const sharedProps = {\n size,\n variant,\n __staticSelector,\n };\n\n const idBase = useId(id);\n const isRequired = typeof withAsterisk === 'boolean' ? withAsterisk : required;\n const errorId = errorProps?.id || `${idBase}-error`;\n const successId = successProps?.id || `${idBase}-success`;\n const descriptionId = descriptionProps?.id || `${idBase}-description`;\n const inputId = idBase;\n const hasError = !!error && typeof error !== 'boolean';\n const hasSuccess = !!success && typeof success !== 'boolean' && !error;\n const hasDescription = !!description;\n const errorRendered = hasError && inputWrapperOrder.includes('error');\n const successRendered = hasSuccess && inputWrapperOrder.includes('error');\n const descriptionRendered = hasDescription && inputWrapperOrder.includes('description');\n const _describedBy = `${errorRendered ? errorId : ''} ${successRendered ? successId : ''} ${descriptionRendered ? descriptionId : ''}`;\n const describedBy = _describedBy.trim().length > 0 ? _describedBy.trim() : undefined;\n const labelId = labelProps?.id || `${idBase}-label`;\n\n const _label = label && (\n <InputLabel\n key=\"label\"\n labelElement={labelElement}\n id={labelId}\n htmlFor={inputId}\n required={isRequired}\n {...sharedProps}\n {...labelProps}\n >\n {label}\n </InputLabel>\n );\n\n const _description = hasDescription && (\n <InputDescription\n key=\"description\"\n {...descriptionProps}\n {...sharedProps}\n size={descriptionProps?.size || sharedProps.size}\n id={descriptionProps?.id || descriptionId}\n >\n {description}\n </InputDescription>\n );\n\n const _input = <Fragment key=\"input\">{inputContainer(children)}</Fragment>;\n\n const _error = hasError && (\n <InputError\n {...errorProps}\n {...sharedProps}\n size={errorProps?.size || sharedProps.size}\n key=\"error\"\n id={errorProps?.id || errorId}\n >\n {error}\n </InputError>\n );\n\n const _success = hasSuccess && (\n <InputSuccess\n {...successProps}\n {...sharedProps}\n size={successProps?.size || sharedProps.size}\n key=\"success\"\n id={successProps?.id || successId}\n >\n {success}\n </InputSuccess>\n );\n\n const content = inputWrapperOrder.map((part) => {\n switch (part) {\n case 'label':\n return _label;\n case 'input':\n return _input;\n case 'description':\n return _description;\n case 'error':\n return _error || _success;\n default:\n return null;\n }\n });\n\n return (\n <InputWrapperContext\n value={{\n getStyles,\n describedBy,\n inputId,\n labelId,\n ...getInputOffsets(inputWrapperOrder, { hasDescription, hasError: hasError || hasSuccess }),\n }}\n >\n <Box\n variant={variant}\n size={size}\n mod={[{ error: !!error, success: !!success && !error }, mod]}\n id={labelElement === 'label' ? undefined : id}\n {...getStyles('root')}\n {...others}\n >\n {content}\n </Box>\n </InputWrapperContext>\n );\n});\n\nInputWrapper.classes = classes;\nInputWrapper.varsResolver = varsResolver;\nInputWrapper.displayName = '@mantine/core/InputWrapper';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuHA,MAAM,eAAe;CACnB,cAAc;CACd,iBAAiB,aAAa;CAC9B,mBAAmB;EAAC;EAAS;EAAe;EAAS;CAAO;AAC9D;AAEA,MAAM,eAAe,oBAAyC,GAAG,EAAE,YAAY;CAC7E,OAAO;EACL,sBAAsB,YAAY,IAAI;EACtC,0BAA0B,KAAA;CAC5B;CAEA,OAAO,EACL,sBAAsB,SAAS,KAAA,IAAY,KAAA,IAAY,QAAQ,YAAY,IAAI,EAAE,KAAK,IAAI,CAAC,EAAE,GAC/F;CAEA,SAAS,EACP,wBACE,SAAS,KAAA,IAAY,KAAA,IAAY,QAAQ,YAAY,IAAI,EAAE,KAAK,IAAI,CAAC,EAAE,GAC3E;CAEA,aAAa,EACX,4BACE,SAAS,KAAA,IAAY,KAAA,IAAY,QAAQ,YAAY,IAAI,EAAE,KAAK,IAAI,CAAC,EAAE,GAC3E;AACF,EAAE;AAEF,MAAa,eAAe,SAA8B,WAAW;CACnE,MAAM,QAAQ,SAAS,gBAAgB,cAAc,MAAM;CAC3D,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,MACA,SACA,kBACA,gBACA,mBACA,OACA,OACA,SACA,aACA,YACA,kBACA,YACA,cACA,cACA,UACA,cACA,IACA,UACA,kBACA,KACA,YACA,GAAG,WACD;CAEJ,MAAM,YAAY,UAA+B;EAC/C,MAAM,CAAC,gBAAgB,gBAAgB;EACvC,OAAO,oBAAoB;EAC3B,SAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,cAAc;EAClB;EACA;EACA;CACF;CAEA,MAAM,SAASA,QAAM,EAAE;CACvB,MAAM,aAAa,OAAO,iBAAiB,YAAY,eAAe;CACtE,MAAM,UAAU,YAAY,MAAM,G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Ac,MAAM;CAGZ,GADX,OACW;CAGhB,MAAM,UAAU,kBAAkB,KAAK,SAAS;EAC9C,QAAQ,MAAR;GACE,KAAK,SACH,OAAO;GACT,KAAK,SACH,OAAO;GACT,KAAK,eACH,OAAO;GACT,KAAK,SACH,OAAO,UAAU;GACnB,SACE,OAAO;EACX;CACF,CAAC;CAED,OACE,oBAAC,qBAAD;EACE,OAAO;GACL;GACA;GACA;GACA;GACA,GAAG,gBAAgB,mBAAmB;IAAE;IAAgB,UAAU,YAAY;GAAW,CAAC;EAC5F;YAEA,oBAAC,KAAD;GACW;GACH;GACN,KAAK,CAAC;IAAE,OAAO,CAAC,CAAC;IAAO,SAAS,CAAC,CAAC,WAAW,CAAC;GAAM,GAAG,GAAG;GAC3D,IAAI,iBAAiB,UAAU,KAAA,IAAY;GAC3C,GAAI,UAAU,MAAM;GACpB,GAAI;aAEH;EACE,CAAA;CACc,CAAA;AAEzB,CAAC;AAED,aAAa,UAAUC;AACvB,aAAa,eAAe;AAC5B,aAAa,cAAc"}
|
|
1
|
+
{"version":3,"file":"InputWrapper.mjs","names":["useId","classes"],"sources":["../../../../src/components/Input/InputWrapper/InputWrapper.tsx"],"sourcesContent":["import { Fragment } from 'react';\nimport { useId } from '@mantine/hooks';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n DataAttributes,\n ElementProps,\n factory,\n Factory,\n getFontSize,\n MantineFontSize,\n PlaceholderPolymorphicProps,\n rem,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../../core';\nimport {\n InputDescription,\n InputDescriptionCssVariables,\n InputDescriptionProps,\n InputDescriptionStylesNames,\n} from '../InputDescription/InputDescription';\nimport {\n InputError,\n InputErrorCssVariables,\n InputErrorProps,\n InputErrorStylesNames,\n} from '../InputError/InputError';\nimport {\n InputLabel,\n InputLabelCssVariables,\n InputLabelProps,\n InputLabelStylesNames,\n} from '../InputLabel/InputLabel';\nimport {\n InputSuccess,\n InputSuccessCssVariables,\n InputSuccessProps,\n InputSuccessStylesNames,\n} from '../InputSuccess/InputSuccess';\nimport { InputWrapperContext } from '../InputWrapper.context';\nimport { getInputOffsets } from './get-input-offsets/get-input-offsets';\nimport classes from '../Input.module.css';\n\nexport type InputWrapperCssVariables = InputLabelCssVariables &\n InputErrorCssVariables &\n InputSuccessCssVariables &\n InputDescriptionCssVariables;\n\nexport type InputWrapperStylesNames =\n | 'root'\n | InputLabelStylesNames\n | InputDescriptionStylesNames\n | InputErrorStylesNames\n | InputSuccessStylesNames;\n\nexport interface __InputWrapperProps {\n /** Contents of `Input.Label` component. If not set, label is not displayed. */\n label?: React.ReactNode;\n\n /** Contents of `Input.Description` component. If not set, description is not displayed. */\n description?: React.ReactNode;\n\n /** Contents of `Input.Error` component. If not set, error is not displayed. */\n error?: React.ReactNode;\n\n /** Contents of `Input.Success` component. If not set, success is not displayed. */\n success?: React.ReactNode;\n\n /** Adds required attribute to the input and a red asterisk on the right side of label @default false */\n required?: boolean;\n\n /** If set, the required asterisk is displayed next to the label. Overrides `required` prop. Does not add required attribute to the input. @default false */\n withAsterisk?: boolean;\n\n /** Props passed down to the `Input.Label` component */\n labelProps?: InputLabelProps & DataAttributes & PlaceholderPolymorphicProps;\n\n /** Props passed down to the `Input.Description` component */\n descriptionProps?: InputDescriptionProps & DataAttributes & PlaceholderPolymorphicProps;\n\n /** Props passed down to the `Input.Error` component */\n errorProps?: InputErrorProps & DataAttributes & PlaceholderPolymorphicProps;\n\n /** Props passed down to the `Input.Success` component */\n successProps?: InputSuccessProps & DataAttributes & PlaceholderPolymorphicProps;\n\n /** Render function to wrap the input element. Useful for adding tooltips, popovers, or other wrappers around the input. @default React.Fragment */\n inputContainer?: (children: React.ReactNode) => React.ReactNode;\n\n /** Controls order and visibility of wrapper elements. Only elements included in this array will be rendered. @default ['label', 'description', 'input', 'error'] */\n inputWrapperOrder?: ('label' | 'input' | 'description' | 'error')[];\n}\n\nexport interface InputWrapperProps\n extends __InputWrapperProps, BoxProps, StylesApiProps<InputWrapperFactory>, ElementProps<'div'> {\n __staticSelector?: string;\n\n /** Props passed to Styles API context, replaces Input.Wrapper props */\n __stylesApiProps?: Record<string, any>;\n\n /** Static id used as base to generate `aria-` attributes, by default generates random id */\n id?: string;\n\n /** Controls size of `Input.Label`, `Input.Description` and `Input.Error` components */\n size?: MantineFontSize;\n\n /** Root element for the label. Use `'div'` when wrapper contains multiple input elements and you need to handle `htmlFor` manually. @default 'label' */\n labelElement?: 'label' | 'div';\n}\n\nexport type InputWrapperFactory = Factory<{\n props: InputWrapperProps;\n ref: HTMLDivElement;\n stylesNames: InputWrapperStylesNames;\n vars: InputWrapperCssVariables;\n}>;\n\nconst defaultProps = {\n labelElement: 'label',\n inputContainer: (children) => children,\n inputWrapperOrder: ['label', 'description', 'input', 'error'],\n} satisfies Partial<InputWrapperProps>;\n\nconst varsResolver = createVarsResolver<InputWrapperFactory>((_, { size }) => ({\n label: {\n '--input-label-size': getFontSize(size),\n '--input-asterisk-color': undefined,\n },\n\n error: {\n '--input-error-size': size === undefined ? undefined : `calc(${getFontSize(size)} - ${rem(2)})`,\n },\n\n success: {\n '--input-success-size':\n size === undefined ? undefined : `calc(${getFontSize(size)} - ${rem(2)})`,\n },\n\n description: {\n '--input-description-size':\n size === undefined ? undefined : `calc(${getFontSize(size)} - ${rem(2)})`,\n },\n}));\n\nexport const InputWrapper = factory<InputWrapperFactory>((_props) => {\n const props = useProps('InputWrapper', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n size,\n variant,\n __staticSelector,\n inputContainer,\n inputWrapperOrder,\n label,\n error,\n success,\n description,\n labelProps,\n descriptionProps,\n errorProps,\n successProps,\n labelElement,\n children,\n withAsterisk,\n id,\n required,\n __stylesApiProps,\n mod,\n attributes,\n ...others\n } = props;\n\n const getStyles = useStyles<InputWrapperFactory>({\n name: ['InputWrapper', __staticSelector],\n props: __stylesApiProps || props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const sharedProps = {\n size,\n variant,\n __staticSelector,\n };\n\n const idBase = useId(id);\n const isRequired = typeof withAsterisk === 'boolean' ? withAsterisk : required;\n const errorId = errorProps?.id || `${idBase}-error`;\n const successId = successProps?.id || `${idBase}-success`;\n const descriptionId = descriptionProps?.id || `${idBase}-description`;\n const inputId = idBase;\n const hasError = !!error && typeof error !== 'boolean';\n const hasSuccess = !!success && typeof success !== 'boolean' && !error;\n const hasDescription = !!description;\n const errorRendered = hasError && inputWrapperOrder.includes('error');\n const successRendered = hasSuccess && inputWrapperOrder.includes('error');\n const descriptionRendered = hasDescription && inputWrapperOrder.includes('description');\n const _describedBy = `${errorRendered ? errorId : ''} ${successRendered ? successId : ''} ${descriptionRendered ? descriptionId : ''}`;\n const describedBy = _describedBy.trim().length > 0 ? _describedBy.trim() : undefined;\n const labelId = labelProps?.id || `${idBase}-label`;\n\n const _label = label && (\n <InputLabel\n key=\"label\"\n labelElement={labelElement}\n id={labelId}\n htmlFor={inputId}\n required={isRequired}\n {...sharedProps}\n {...labelProps}\n >\n {label}\n </InputLabel>\n );\n\n const _description = hasDescription && (\n <InputDescription\n key=\"description\"\n {...descriptionProps}\n {...sharedProps}\n size={descriptionProps?.size || sharedProps.size}\n id={descriptionProps?.id || descriptionId}\n >\n {description}\n </InputDescription>\n );\n\n const _input = <Fragment key=\"input\">{inputContainer(children)}</Fragment>;\n\n const _error = hasError && (\n <InputError\n {...errorProps}\n {...sharedProps}\n size={errorProps?.size || sharedProps.size}\n key=\"error\"\n id={errorProps?.id || errorId}\n >\n {error}\n </InputError>\n );\n\n const _success = hasSuccess && (\n <InputSuccess\n {...successProps}\n {...sharedProps}\n size={successProps?.size || sharedProps.size}\n key=\"success\"\n id={successProps?.id || successId}\n >\n {success}\n </InputSuccess>\n );\n\n const content = inputWrapperOrder.map((part) => {\n switch (part) {\n case 'label':\n return _label;\n case 'input':\n return _input;\n case 'description':\n return _description;\n case 'error':\n return _error || _success;\n default:\n return null;\n }\n });\n\n return (\n <InputWrapperContext\n value={{\n getStyles,\n describedBy,\n inputId,\n labelId,\n ...getInputOffsets(inputWrapperOrder, { hasDescription, hasError: hasError || hasSuccess }),\n }}\n >\n <Box\n variant={variant}\n size={size}\n mod={[{ error: !!error, success: !!success && !error }, mod]}\n id={labelElement === 'label' ? undefined : id}\n {...getStyles('root')}\n {...others}\n >\n {content}\n </Box>\n </InputWrapperContext>\n );\n});\n\nInputWrapper.classes = classes;\nInputWrapper.varsResolver = varsResolver;\nInputWrapper.displayName = '@mantine/core/InputWrapper';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwHA,MAAM,eAAe;CACnB,cAAc;CACd,iBAAiB,aAAa;CAC9B,mBAAmB;EAAC;EAAS;EAAe;EAAS;CAAO;AAC9D;AAEA,MAAM,eAAe,oBAAyC,GAAG,EAAE,YAAY;CAC7E,OAAO;EACL,sBAAsB,YAAY,IAAI;EACtC,0BAA0B,KAAA;CAC5B;CAEA,OAAO,EACL,sBAAsB,SAAS,KAAA,IAAY,KAAA,IAAY,QAAQ,YAAY,IAAI,EAAE,KAAK,IAAI,CAAC,EAAE,GAC/F;CAEA,SAAS,EACP,wBACE,SAAS,KAAA,IAAY,KAAA,IAAY,QAAQ,YAAY,IAAI,EAAE,KAAK,IAAI,CAAC,EAAE,GAC3E;CAEA,aAAa,EACX,4BACE,SAAS,KAAA,IAAY,KAAA,IAAY,QAAQ,YAAY,IAAI,EAAE,KAAK,IAAI,CAAC,EAAE,GAC3E;AACF,EAAE;AAEF,MAAa,eAAe,SAA8B,WAAW;CACnE,MAAM,QAAQ,SAAS,gBAAgB,cAAc,MAAM;CAC3D,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,MACA,SACA,kBACA,gBACA,mBACA,OACA,OACA,SACA,aACA,YACA,kBACA,YACA,cACA,cACA,UACA,cACA,IACA,UACA,kBACA,KACA,YACA,GAAG,WACD;CAEJ,MAAM,YAAY,UAA+B;EAC/C,MAAM,CAAC,gBAAgB,gBAAgB;EACv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ACE,GAAI;EACJ,GAAI;EACJ,MAAM,YAAY,QAAQ,YAAY;EACtC,KAAI;EACJ,IAAI,YAAY,MAAM;CAGZ,GADT,KACS;CAGd,MAAM,WAAW,cACf,8BAAC,cAAD;EACE,GAAI;EACJ,GAAI;EACJ,MAAM,cAAc,QAAQ,YAAY;EACxC,KAAI;EACJ,IAAI,cAAc,MAAM;CAGZ,GADX,OACW;CAGhB,MAAM,UAAU,kBAAkB,KAAK,SAAS;EAC9C,QAAQ,MAAR;GACE,KAAK,SACH,OAAO;GACT,KAAK,SACH,OAAO;GACT,KAAK,eACH,OAAO;GACT,KAAK,SACH,OAAO,UAAU;GACnB,SACE,OAAO;EACX;CACF,CAAC;CAED,OACE,oBAAC,qBAAD;EACE,OAAO;GACL;GACA;GACA;GACA;GACA,GAAG,gBAAgB,mBAAmB;IAAE;IAAgB,UAAU,YAAY;GAAW,CAAC;EAC5F;YAEA,oBAAC,KAAD;GACW;GACH;GACN,KAAK,CAAC;IAAE,OAAO,CAAC,CAAC;IAAO,SAAS,CAAC,CAAC,WAAW,CAAC;GAAM,GAAG,GAAG;GAC3D,IAAI,iBAAiB,UAAU,KAAA,IAAY;GAC3C,GAAI,UAAU,MAAM;GACpB,GAAI;aAEH;EACE,CAAA;CACc,CAAA;AAEzB,CAAC;AAED,aAAa,UAAUC;AACvB,aAAa,eAAe;AAC5B,aAAa,cAAc"}
|
|
@@ -12,10 +12,19 @@ export interface FloatingWindowDimensions {
|
|
|
12
12
|
/** Maximum height of the floating window in px */
|
|
13
13
|
maxHeight?: number;
|
|
14
14
|
}
|
|
15
|
+
export interface FloatingWindowSize {
|
|
16
|
+
/** Width of the floating window in px */
|
|
17
|
+
width: number;
|
|
18
|
+
/** Height of the floating window in px */
|
|
19
|
+
height: number;
|
|
20
|
+
}
|
|
15
21
|
export interface FloatingWindowContextValue {
|
|
16
22
|
rootRef: React.RefObject<HTMLDivElement | null>;
|
|
17
23
|
dimensions: FloatingWindowDimensions | undefined;
|
|
18
24
|
constrainToViewport: boolean | undefined;
|
|
19
25
|
constrainOffset: number | undefined;
|
|
26
|
+
onResizeStart: (() => void) | undefined;
|
|
27
|
+
onResizeEnd: (() => void) | undefined;
|
|
28
|
+
onSizeChange: ((size: FloatingWindowSize) => void) | undefined;
|
|
20
29
|
}
|
|
21
30
|
export declare const FloatingWindowProvider: import("react").Context<FloatingWindowContextValue | null>, useFloatingWindowContext: () => FloatingWindowContextValue;
|
|
@@ -2,7 +2,7 @@ import { SetFloatingWindowPosition, UseFloatingWindowOptions } from '@mantine/ho
|
|
|
2
2
|
import { BoxProps, ElementProps, Factory, StylesApiProps } from '../../core';
|
|
3
3
|
import { PaperBaseProps } from '../Paper';
|
|
4
4
|
import { PortalProps } from '../Portal';
|
|
5
|
-
import { FloatingWindowDimensions } from './FloatingWindow.context';
|
|
5
|
+
import { FloatingWindowDimensions, FloatingWindowSize } from './FloatingWindow.context';
|
|
6
6
|
import { FloatingWindowResizeHandle } from './FloatingWindowResizeHandle';
|
|
7
7
|
export type FloatingWindowStylesNames = 'root';
|
|
8
8
|
export interface FloatingWindowProps extends UseFloatingWindowOptions, PaperBaseProps, BoxProps, StylesApiProps<FloatingWindowFactory>, ElementProps<'div', keyof UseFloatingWindowOptions> {
|
|
@@ -16,6 +16,12 @@ export interface FloatingWindowProps extends UseFloatingWindowOptions, PaperBase
|
|
|
16
16
|
zIndex?: React.CSSProperties['zIndex'];
|
|
17
17
|
/** Dimensions configuration for resizable floating window */
|
|
18
18
|
dimensions?: FloatingWindowDimensions;
|
|
19
|
+
/** Called when the window is resized with `FloatingWindow.ResizeHandle` */
|
|
20
|
+
onSizeChange?: (size: FloatingWindowSize) => void;
|
|
21
|
+
/** Called when the resize with `FloatingWindow.ResizeHandle` starts. Not called for keyboard resize. */
|
|
22
|
+
onResizeStart?: () => void;
|
|
23
|
+
/** Called when the resize with `FloatingWindow.ResizeHandle` stops. Not called for keyboard resize. */
|
|
24
|
+
onResizeEnd?: () => void;
|
|
19
25
|
}
|
|
20
26
|
export type FloatingWindowFactory = Factory<{
|
|
21
27
|
props: FloatingWindowProps;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FloatingWindowFactory, FloatingWindowProps, FloatingWindowStylesNames } from './FloatingWindow';
|
|
2
2
|
export { FloatingWindow } from './FloatingWindow';
|
|
3
3
|
export type { FloatingWindowProps, FloatingWindowStylesNames, FloatingWindowFactory };
|
|
4
|
-
export type { FloatingWindowDimensions } from './FloatingWindow.context';
|
|
4
|
+
export type { FloatingWindowDimensions, FloatingWindowSize } from './FloatingWindow.context';
|
|
5
5
|
export type { FloatingWindowResizeHandleProps, FloatingWindowResizeHandleFactory, } from './FloatingWindowResizeHandle';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BoxProps, DataAttributes, ElementProps, Factory, MantineFontSize, StylesApiProps } from '../../../core';
|
|
1
|
+
import { BoxProps, DataAttributes, ElementProps, Factory, MantineFontSize, PlaceholderPolymorphicProps, StylesApiProps } from '../../../core';
|
|
2
2
|
import { InputDescriptionCssVariables, InputDescriptionProps, InputDescriptionStylesNames } from '../InputDescription/InputDescription';
|
|
3
3
|
import { InputErrorCssVariables, InputErrorProps, InputErrorStylesNames } from '../InputError/InputError';
|
|
4
4
|
import { InputLabelCssVariables, InputLabelProps, InputLabelStylesNames } from '../InputLabel/InputLabel';
|
|
@@ -19,13 +19,13 @@ export interface __InputWrapperProps {
|
|
|
19
19
|
/** If set, the required asterisk is displayed next to the label. Overrides `required` prop. Does not add required attribute to the input. @default false */
|
|
20
20
|
withAsterisk?: boolean;
|
|
21
21
|
/** Props passed down to the `Input.Label` component */
|
|
22
|
-
labelProps?: InputLabelProps & DataAttributes;
|
|
22
|
+
labelProps?: InputLabelProps & DataAttributes & PlaceholderPolymorphicProps;
|
|
23
23
|
/** Props passed down to the `Input.Description` component */
|
|
24
|
-
descriptionProps?: InputDescriptionProps & DataAttributes;
|
|
24
|
+
descriptionProps?: InputDescriptionProps & DataAttributes & PlaceholderPolymorphicProps;
|
|
25
25
|
/** Props passed down to the `Input.Error` component */
|
|
26
|
-
errorProps?: InputErrorProps & DataAttributes;
|
|
26
|
+
errorProps?: InputErrorProps & DataAttributes & PlaceholderPolymorphicProps;
|
|
27
27
|
/** Props passed down to the `Input.Success` component */
|
|
28
|
-
successProps?: InputSuccessProps & DataAttributes;
|
|
28
|
+
successProps?: InputSuccessProps & DataAttributes & PlaceholderPolymorphicProps;
|
|
29
29
|
/** Render function to wrap the input element. Useful for adding tooltips, popovers, or other wrappers around the input. @default React.Fragment */
|
|
30
30
|
inputContainer?: (children: React.ReactNode) => React.ReactNode;
|
|
31
31
|
/** Controls order and visibility of wrapper elements. Only elements included in this array will be rendered. @default ['label', 'description', 'input', 'error'] */
|
|
@@ -303,10 +303,10 @@ export declare function useInputProps<T extends BaseProps, U extends Partial<T>
|
|
|
303
303
|
classNames: Partial<Record<string, string | undefined>> | ((theme: import("../..").MantineTheme, props: any, ctx: unknown) => Partial<Record<string, string | undefined>>) | undefined;
|
|
304
304
|
__staticSelector: string | undefined;
|
|
305
305
|
__stylesApiProps: Record<string, any> | BaseProps;
|
|
306
|
-
errorProps: (import(".").InputErrorProps & import("../..").DataAttributes) | undefined;
|
|
307
|
-
successProps: (import(".").InputSuccessProps & import("../..").DataAttributes) | undefined;
|
|
308
|
-
labelProps: (import(".").InputLabelProps & import("../..").DataAttributes) | undefined;
|
|
309
|
-
descriptionProps: (import(".").InputDescriptionProps & import("../..").DataAttributes) | undefined;
|
|
306
|
+
errorProps: (import(".").InputErrorProps & import("../..").DataAttributes & import("../..").PlaceholderPolymorphicProps) | undefined;
|
|
307
|
+
successProps: (import(".").InputSuccessProps & import("../..").DataAttributes & import("../..").PlaceholderPolymorphicProps) | undefined;
|
|
308
|
+
labelProps: (import(".").InputLabelProps & import("../..").DataAttributes & import("../..").PlaceholderPolymorphicProps) | undefined;
|
|
309
|
+
descriptionProps: (import(".").InputDescriptionProps & import("../..").DataAttributes & import("../..").PlaceholderPolymorphicProps) | undefined;
|
|
310
310
|
unstyled: boolean | undefined;
|
|
311
311
|
styles: Partial<Record<string, import("../..").CSSProperties>> | ((theme: import("../..").MantineTheme, props: any, ctx: unknown) => Partial<Record<string, import("../..").CSSProperties>>) | undefined;
|
|
312
312
|
size: (string & {}) | import("../..").MantineSize | undefined;
|
|
@@ -74,10 +74,10 @@ export declare function useMaskInputProps(props: MaskInputProps & {
|
|
|
74
74
|
success?: React.ReactNode;
|
|
75
75
|
required?: boolean;
|
|
76
76
|
withAsterisk?: boolean;
|
|
77
|
-
labelProps?: import("..").InputLabelProps & import("../..").DataAttributes;
|
|
78
|
-
descriptionProps?: import("..").InputDescriptionProps & import("../..").DataAttributes;
|
|
79
|
-
errorProps?: import("..").InputErrorProps & import("../..").DataAttributes;
|
|
80
|
-
successProps?: import("..").InputSuccessProps & import("../..").DataAttributes;
|
|
77
|
+
labelProps?: import("..").InputLabelProps & import("../..").DataAttributes & import("../..").PlaceholderPolymorphicProps;
|
|
78
|
+
descriptionProps?: import("..").InputDescriptionProps & import("../..").DataAttributes & import("../..").PlaceholderPolymorphicProps;
|
|
79
|
+
errorProps?: import("..").InputErrorProps & import("../..").DataAttributes & import("../..").PlaceholderPolymorphicProps;
|
|
80
|
+
successProps?: import("..").InputSuccessProps & import("../..").DataAttributes & import("../..").PlaceholderPolymorphicProps;
|
|
81
81
|
inputContainer?: (children: React.ReactNode) => React.ReactNode;
|
|
82
82
|
inputWrapperOrder?: ("label" | "input" | "description" | "error")[];
|
|
83
83
|
leftSection?: React.ReactNode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mantine/core",
|
|
3
|
-
"version": "9.5.
|
|
3
|
+
"version": "9.5.1-alpha.1",
|
|
4
4
|
"description": "React components library focused on usability, accessibility and developer experience",
|
|
5
5
|
"homepage": "https://mantine.dev/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"directory": "packages/@mantine/core"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@mantine/hooks": "9.5.
|
|
46
|
+
"@mantine/hooks": "9.5.1-alpha.1",
|
|
47
47
|
"react": "^19.2.0",
|
|
48
48
|
"react-dom": "^19.2.0"
|
|
49
49
|
},
|