@gild-ui/vue 0.0.0 → 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +97 -2
- package/dist/Button.cjs +238 -0
- package/dist/Button.d.cts +17 -0
- package/dist/Button.d.mts +17 -0
- package/dist/Button.mjs +237 -0
- package/dist/Button.types-BnJ28ym9.d.mts +1113 -0
- package/dist/Flex.cjs +25 -0
- package/dist/Flex.d.cts +11 -0
- package/dist/Flex.d.mts +11 -0
- package/dist/Flex.mjs +24 -0
- package/dist/Modal.cjs +369 -0
- package/dist/Modal.d.cts +23 -0
- package/dist/Modal.d.mts +23 -0
- package/dist/Modal.mjs +368 -0
- package/dist/TextInput.cjs +299 -0
- package/dist/TextInput.d.cts +37 -0
- package/dist/TextInput.d.mts +37 -0
- package/dist/TextInput.mjs +298 -0
- package/dist/ThemeProvider-CareN7BO.mjs +58 -0
- package/dist/ThemeProvider-DIeSdYou.cjs +63 -0
- package/dist/ThemeProvider.cjs +3 -0
- package/dist/ThemeProvider.d.cts +25 -0
- package/dist/ThemeProvider.d.mts +25 -0
- package/dist/ThemeProvider.mjs +1 -0
- package/dist/Typography.cjs +72 -0
- package/dist/Typography.d.cts +15 -0
- package/dist/Typography.d.mts +15 -0
- package/dist/Typography.mjs +71 -0
- package/dist/View.cjs +12 -0
- package/dist/View.d.cts +11 -0
- package/dist/View.d.mts +11 -0
- package/dist/View.mjs +11 -0
- package/dist/ViewRoot-CsaIxrtD.mjs +40 -0
- package/dist/ViewRoot-X9F9RROv.cjs +45 -0
- package/dist/bridge-D-x2kK4r.d.mts +36 -0
- package/dist/bridge-t6zHXVt-.d.cts +36 -0
- package/dist/engine.cjs +82 -0
- package/dist/engine.d.cts +46 -0
- package/dist/engine.d.mts +46 -0
- package/dist/engine.mjs +26 -0
- package/dist/index.cjs +57 -0
- package/dist/index.d.cts +37 -0
- package/dist/index.d.mts +37 -0
- package/dist/index.mjs +6 -0
- package/dist/props-BRLGZVjJ.d.mts +21 -0
- package/dist/props-Bzm7Wbdv.d.cts +21 -0
- package/dist/props-DDBSpAkG.mjs +49 -0
- package/dist/props-DxoB9cT4.cjs +72 -0
- package/dist/styled-Cmxvlft5.mjs +34 -0
- package/dist/styled-JHkZtq_1.cjs +39 -0
- package/dist/themes-BqxOUMCB.cjs +12 -0
- package/dist/themes-CgFrk0_b.d.cts +1112 -0
- package/dist/themes-rGHVhV5e.mjs +8 -0
- package/dist/useDefaultProps--fOGOSGa.mjs +18 -0
- package/dist/useDefaultProps-qCDgeYFm.cjs +23 -0
- package/dist/useTheme.cjs +8 -0
- package/dist/useTheme.d.cts +3 -0
- package/dist/useTheme.d.mts +3 -0
- package/dist/useTheme.mjs +1 -0
- package/package.json +167 -4
package/dist/Modal.mjs
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { r as styled$1 } from "./styled-Cmxvlft5.mjs";
|
|
2
|
+
import { i as mergeOverrides, n as flag, t as declare } from "./props-DDBSpAkG.mjs";
|
|
3
|
+
import { t as ViewRoot } from "./ViewRoot-CsaIxrtD.mjs";
|
|
4
|
+
import { Teleport, defineComponent, h, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
5
|
+
import { ThemeScope } from "@umber-style/vue";
|
|
6
|
+
import { createShouldForwardProp } from "@soroush.tech/styled-system/should-forward-prop";
|
|
7
|
+
// src/Modal/FocusTrap.ts
|
|
8
|
+
const FOCUSABLE_SELECTOR = [
|
|
9
|
+
"a[href]",
|
|
10
|
+
"button:not([disabled])",
|
|
11
|
+
"textarea:not([disabled])",
|
|
12
|
+
"input:not([disabled])",
|
|
13
|
+
"select:not([disabled])",
|
|
14
|
+
"[tabindex]:not([tabindex=\"-1\"])"
|
|
15
|
+
].join(",");
|
|
16
|
+
function getFocusable(node) {
|
|
17
|
+
return Array.from(node.querySelectorAll(FOCUSABLE_SELECTOR)).filter((element) => element.tabIndex >= 0);
|
|
18
|
+
}
|
|
19
|
+
/** Move focus to the first focusable descendant, or the node itself when there is none. */
|
|
20
|
+
function focusFirst(node) {
|
|
21
|
+
const [first] = getFocusable(node);
|
|
22
|
+
(first ?? node).focus();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Keeps keyboard focus within `node` until the returned function is called: moves focus in, cycles Tab
|
|
26
|
+
* and Shift+Tab at the boundaries, pulls focus back when it escapes, and gives focus back to the element
|
|
27
|
+
* that had it before. It is the behavior of `FocusTrap` of `@gild-ui/react`.
|
|
28
|
+
*/
|
|
29
|
+
function trapFocus(node, options) {
|
|
30
|
+
const { shouldAutoFocus = true, shouldTrapFocus = true, shouldEnforceFocus = true, shouldRestoreFocus = true } = options;
|
|
31
|
+
const doc = node.ownerDocument;
|
|
32
|
+
const previouslyFocused = doc.activeElement;
|
|
33
|
+
if (shouldAutoFocus) focusFirst(node);
|
|
34
|
+
const handleFocusIn = (event) => {
|
|
35
|
+
if (!(event.target instanceof Node && node.contains(event.target))) focusFirst(node);
|
|
36
|
+
};
|
|
37
|
+
if (shouldEnforceFocus) doc.addEventListener("focusin", handleFocusIn);
|
|
38
|
+
const handleKeyDown = (event) => {
|
|
39
|
+
if (!shouldTrapFocus || event.key !== "Tab") return;
|
|
40
|
+
const focusable = getFocusable(node);
|
|
41
|
+
if (focusable.length === 0) {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const first = focusable[0];
|
|
46
|
+
const last = focusable.at(-1);
|
|
47
|
+
const active = doc.activeElement;
|
|
48
|
+
if (event.shiftKey && active === first) {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
last?.focus();
|
|
51
|
+
} else if (!event.shiftKey && active === last) {
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
first?.focus();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
node.addEventListener("keydown", handleKeyDown);
|
|
57
|
+
return () => {
|
|
58
|
+
doc.removeEventListener("focusin", handleFocusIn);
|
|
59
|
+
node.removeEventListener("keydown", handleKeyDown);
|
|
60
|
+
if (shouldRestoreFocus && previouslyFocused instanceof HTMLElement) previouslyFocused.focus();
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// ../react/src/utils/ownerDocument.ts
|
|
64
|
+
/**
|
|
65
|
+
* Returns the `Document` that owns the given node, falling back to the global
|
|
66
|
+
* `document`. Lets the modal logic work across iframes / portaled containers.
|
|
67
|
+
*/
|
|
68
|
+
function ownerDocument(node) {
|
|
69
|
+
return node?.ownerDocument ?? document;
|
|
70
|
+
}
|
|
71
|
+
// ../react/src/Modal/utils/ownerWindow.ts
|
|
72
|
+
/**
|
|
73
|
+
* Returns the `Window` that owns the given node, falling back to the global
|
|
74
|
+
* `window`. Used to read viewport metrics for scroll-lock calculations.
|
|
75
|
+
*/
|
|
76
|
+
function ownerWindow(node) {
|
|
77
|
+
return ownerDocument(node).defaultView ?? window;
|
|
78
|
+
}
|
|
79
|
+
// ../react/src/Modal/utils/getScrollbarSize.ts
|
|
80
|
+
/**
|
|
81
|
+
* Width of the vertical scrollbar for the given window, in pixels. Equal to the
|
|
82
|
+
* gap between the inner window width and the document's client width. Used to
|
|
83
|
+
* pad the container when scroll-lock hides the scrollbar, preventing layout jump.
|
|
84
|
+
*/
|
|
85
|
+
function getScrollbarSize(win) {
|
|
86
|
+
const documentWidth = win.document.documentElement.clientWidth;
|
|
87
|
+
return Math.abs(win.innerWidth - documentWidth);
|
|
88
|
+
}
|
|
89
|
+
// ../react/src/Modal/ModalManager.ts
|
|
90
|
+
const ARIA_HIDDEN_FORBIDDEN_TAGS = /* @__PURE__ */ new Set([
|
|
91
|
+
"TEMPLATE",
|
|
92
|
+
"SCRIPT",
|
|
93
|
+
"STYLE",
|
|
94
|
+
"LINK",
|
|
95
|
+
"MAP",
|
|
96
|
+
"META",
|
|
97
|
+
"NOSCRIPT",
|
|
98
|
+
"PICTURE",
|
|
99
|
+
"COL",
|
|
100
|
+
"COLGROUP",
|
|
101
|
+
"PARAM",
|
|
102
|
+
"SLOT",
|
|
103
|
+
"SOURCE",
|
|
104
|
+
"TRACK"
|
|
105
|
+
]);
|
|
106
|
+
/** Hides an element from assistive tech. */
|
|
107
|
+
function hideFromAria(element) {
|
|
108
|
+
element.setAttribute("aria-hidden", "true");
|
|
109
|
+
}
|
|
110
|
+
/** Reveals an element to assistive tech again. */
|
|
111
|
+
function exposeToAria(element) {
|
|
112
|
+
element.removeAttribute("aria-hidden");
|
|
113
|
+
}
|
|
114
|
+
function isAriaHiddenForbidden(element) {
|
|
115
|
+
if (ARIA_HIDDEN_FORBIDDEN_TAGS.has(element.tagName)) return true;
|
|
116
|
+
return element.tagName === "INPUT" && element.getAttribute("type") === "hidden";
|
|
117
|
+
}
|
|
118
|
+
function ariaHiddenSiblings(container, mountElement, currentElement, hiddenSiblings, apply) {
|
|
119
|
+
const exclude = /* @__PURE__ */ new Set([
|
|
120
|
+
mountElement,
|
|
121
|
+
currentElement,
|
|
122
|
+
...hiddenSiblings
|
|
123
|
+
]);
|
|
124
|
+
Array.from(container.children).forEach((element) => {
|
|
125
|
+
if (!exclude.has(element) && !isAriaHiddenForbidden(element)) apply(element);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function getHiddenSiblings(container) {
|
|
129
|
+
return Array.from(container.children).filter((element) => element.getAttribute("aria-hidden") === "true");
|
|
130
|
+
}
|
|
131
|
+
function isOverflowing(container) {
|
|
132
|
+
const doc = ownerDocument(container);
|
|
133
|
+
if (container === doc.body) return ownerWindow(container).innerWidth > doc.documentElement.clientWidth;
|
|
134
|
+
return container.scrollHeight > container.clientHeight;
|
|
135
|
+
}
|
|
136
|
+
function getPaddingRight(element) {
|
|
137
|
+
return Number.parseFloat(ownerWindow(element).getComputedStyle(element).paddingRight) || 0;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Locks scrolling on the container, padding it by the scrollbar width so hiding
|
|
141
|
+
* the scrollbar causes no horizontal layout shift. Returns a function that
|
|
142
|
+
* restores the exact prior inline styles.
|
|
143
|
+
*/
|
|
144
|
+
function lockScroll(container) {
|
|
145
|
+
const restores = [];
|
|
146
|
+
const setStyle = (property, value) => {
|
|
147
|
+
const previous = container.style.getPropertyValue(property);
|
|
148
|
+
restores.push(() => {
|
|
149
|
+
if (previous) container.style.setProperty(property, previous);
|
|
150
|
+
else container.style.removeProperty(property);
|
|
151
|
+
});
|
|
152
|
+
container.style.setProperty(property, value);
|
|
153
|
+
};
|
|
154
|
+
if (isOverflowing(container)) {
|
|
155
|
+
const scrollbarSize = container === ownerDocument(container).body ? getScrollbarSize(ownerWindow(container)) : container.offsetWidth - container.clientWidth;
|
|
156
|
+
setStyle("padding-right", `${getPaddingRight(container) + scrollbarSize}px`);
|
|
157
|
+
}
|
|
158
|
+
setStyle("overflow", "hidden");
|
|
159
|
+
return () => restores.forEach((restore) => restore());
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Tracks every open modal and the containers they live in. A single shared
|
|
163
|
+
* instance coordinates stacking (`isTopModal`), scroll-lock, and `aria-hidden`
|
|
164
|
+
* on background siblings so assistive tech only sees the active modal.
|
|
165
|
+
*/
|
|
166
|
+
var ModalManager = class {
|
|
167
|
+
modals = [];
|
|
168
|
+
containers = [];
|
|
169
|
+
add(modal, container, disableAriaHidden = false) {
|
|
170
|
+
const existingIndex = this.modals.indexOf(modal);
|
|
171
|
+
if (existingIndex !== -1) return existingIndex;
|
|
172
|
+
const modalIndex = this.modals.length;
|
|
173
|
+
this.modals.push(modal);
|
|
174
|
+
exposeToAria(modal.modalRef);
|
|
175
|
+
const hiddenSiblings = getHiddenSiblings(container);
|
|
176
|
+
if (!disableAriaHidden) ariaHiddenSiblings(container, modal.mount, modal.modalRef, hiddenSiblings, hideFromAria);
|
|
177
|
+
const containerState = this.containers.find((item) => item.container === container);
|
|
178
|
+
if (containerState) {
|
|
179
|
+
containerState.modals.push(modal);
|
|
180
|
+
if (!disableAriaHidden) containerState.ariaHiddenApplied = true;
|
|
181
|
+
return modalIndex;
|
|
182
|
+
}
|
|
183
|
+
this.containers.push({
|
|
184
|
+
container,
|
|
185
|
+
modals: [modal],
|
|
186
|
+
restore: null,
|
|
187
|
+
hiddenSiblings,
|
|
188
|
+
ariaHiddenApplied: !disableAriaHidden
|
|
189
|
+
});
|
|
190
|
+
return modalIndex;
|
|
191
|
+
}
|
|
192
|
+
mount(modal, props) {
|
|
193
|
+
const containerState = this.containers.find((item) => item.modals.includes(modal));
|
|
194
|
+
containerState.restore ??= props.disableScrollLock ? () => {} : lockScroll(containerState.container);
|
|
195
|
+
}
|
|
196
|
+
remove(modal, ariaHiddenState = true) {
|
|
197
|
+
const modalIndex = this.modals.indexOf(modal);
|
|
198
|
+
if (modalIndex === -1) return modalIndex;
|
|
199
|
+
const containerState = this.containers.find((item) => item.modals.includes(modal));
|
|
200
|
+
containerState.modals.splice(containerState.modals.indexOf(modal), 1);
|
|
201
|
+
this.modals.splice(modalIndex, 1);
|
|
202
|
+
if (containerState.modals.length === 0) {
|
|
203
|
+
if (containerState.restore) containerState.restore();
|
|
204
|
+
(ariaHiddenState ? hideFromAria : exposeToAria)(modal.modalRef);
|
|
205
|
+
if (containerState.ariaHiddenApplied) ariaHiddenSiblings(containerState.container, modal.mount, modal.modalRef, containerState.hiddenSiblings, exposeToAria);
|
|
206
|
+
this.containers.splice(this.containers.indexOf(containerState), 1);
|
|
207
|
+
} else {
|
|
208
|
+
const nextTop = containerState.modals.at(-1);
|
|
209
|
+
(ariaHiddenState ? hideFromAria : exposeToAria)(modal.modalRef);
|
|
210
|
+
exposeToAria(nextTop.modalRef);
|
|
211
|
+
}
|
|
212
|
+
return modalIndex;
|
|
213
|
+
}
|
|
214
|
+
isTopModal(modal) {
|
|
215
|
+
return this.modals.at(-1) === modal;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
// src/Modal/Modal.ts
|
|
219
|
+
const shouldForwardProp = createShouldForwardProp(["scroll", "layer"]);
|
|
220
|
+
const ModalRoot = styled$1(ViewRoot, {
|
|
221
|
+
name: "Modal",
|
|
222
|
+
label: "Modal",
|
|
223
|
+
shouldForwardProp
|
|
224
|
+
})(({ theme, scroll, layer }) => ({
|
|
225
|
+
position: "fixed",
|
|
226
|
+
inset: 0,
|
|
227
|
+
zIndex: theme.zOrder[layer],
|
|
228
|
+
display: "flex",
|
|
229
|
+
...scroll === "paper" ? {
|
|
230
|
+
alignItems: "center",
|
|
231
|
+
justifyContent: "center"
|
|
232
|
+
} : {
|
|
233
|
+
flexDirection: "column",
|
|
234
|
+
overflowY: "auto",
|
|
235
|
+
"& > :not([aria-hidden=\"true\"])": { margin: "auto" }
|
|
236
|
+
}
|
|
237
|
+
}));
|
|
238
|
+
const BackdropRoot = styled$1(ViewRoot, {
|
|
239
|
+
name: "Backdrop",
|
|
240
|
+
label: "Backdrop"
|
|
241
|
+
})({
|
|
242
|
+
position: "fixed",
|
|
243
|
+
inset: 0,
|
|
244
|
+
zIndex: -1,
|
|
245
|
+
pointerEvents: "none"
|
|
246
|
+
});
|
|
247
|
+
const FocusTrapRoot = styled$1("div", {
|
|
248
|
+
name: "FocusTrap",
|
|
249
|
+
label: "FocusTrap"
|
|
250
|
+
})({ outline: "none" });
|
|
251
|
+
const modalManager = new ModalManager();
|
|
252
|
+
const resolveContainer = (container) => (typeof container === "function" ? container() : container) ?? null;
|
|
253
|
+
/**
|
|
254
|
+
* @description Accessible overlay primitive: teleports its content, dims the page, traps focus, locks
|
|
255
|
+
* scroll, and closes on Escape or backdrop click. The content is the default slot.
|
|
256
|
+
*/
|
|
257
|
+
const Modal = defineComponent((props, { emit, slots }) => {
|
|
258
|
+
const root = ref(null);
|
|
259
|
+
const trap = ref(null);
|
|
260
|
+
let modal;
|
|
261
|
+
let release;
|
|
262
|
+
const isTopModal = () => modal !== void 0 && modalManager.isTopModal(modal);
|
|
263
|
+
const sync = () => {
|
|
264
|
+
release?.();
|
|
265
|
+
release = void 0;
|
|
266
|
+
const element = root.value;
|
|
267
|
+
const content = trap.value;
|
|
268
|
+
if (!props.isOpen || !element || !content) return;
|
|
269
|
+
const registered = {
|
|
270
|
+
mount: element,
|
|
271
|
+
modalRef: element
|
|
272
|
+
};
|
|
273
|
+
modal = registered;
|
|
274
|
+
const container = resolveContainer(props.portalContainer) ?? element.ownerDocument.body;
|
|
275
|
+
modalManager.add(registered, container, props.disableAriaHidden);
|
|
276
|
+
modalManager.mount(registered, { disableScrollLock: !props.shouldLockScroll });
|
|
277
|
+
const releaseFocus = trapFocus(content, props);
|
|
278
|
+
release = () => {
|
|
279
|
+
releaseFocus();
|
|
280
|
+
modalManager.remove(registered);
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
onMounted(sync);
|
|
284
|
+
watch(() => [
|
|
285
|
+
props.isOpen,
|
|
286
|
+
props.portalContainer,
|
|
287
|
+
props.shouldLockScroll,
|
|
288
|
+
props.disableAriaHidden,
|
|
289
|
+
props.shouldAutoFocus,
|
|
290
|
+
props.shouldTrapFocus,
|
|
291
|
+
props.shouldEnforceFocus,
|
|
292
|
+
props.shouldRestoreFocus
|
|
293
|
+
], sync, { flush: "post" });
|
|
294
|
+
onBeforeUnmount(() => release?.());
|
|
295
|
+
const close = (event, reason) => {
|
|
296
|
+
emit("close", event, reason);
|
|
297
|
+
emit("update:isOpen", false);
|
|
298
|
+
};
|
|
299
|
+
const handleClick = (event) => {
|
|
300
|
+
if (event.target === event.currentTarget) close(event, "backdropClick");
|
|
301
|
+
};
|
|
302
|
+
const handleKeydown = (event) => {
|
|
303
|
+
if (event.key !== "Escape" || event.isComposing || !isTopModal()) return;
|
|
304
|
+
event.stopPropagation();
|
|
305
|
+
close(event, "escapeKey");
|
|
306
|
+
};
|
|
307
|
+
return () => {
|
|
308
|
+
const { isOpen, scroll = "paper", layer = "modal", style, slotProps } = props;
|
|
309
|
+
if (!props.shouldKeepMounted && !isOpen) return null;
|
|
310
|
+
const content = h(ModalRoot, {
|
|
311
|
+
scroll,
|
|
312
|
+
layer,
|
|
313
|
+
role: "presentation",
|
|
314
|
+
onKeydown: handleKeydown,
|
|
315
|
+
onClick: handleClick,
|
|
316
|
+
ref: root,
|
|
317
|
+
...mergeOverrides(slotProps?.root, { style })
|
|
318
|
+
}, () => [props.hasBackdrop && h(BackdropRoot, {
|
|
319
|
+
bg: "backdrop",
|
|
320
|
+
"aria-hidden": true
|
|
321
|
+
}), h(FocusTrapRoot, {
|
|
322
|
+
ref: trap,
|
|
323
|
+
tabindex: -1
|
|
324
|
+
}, () => slots.default?.())].filter(Boolean));
|
|
325
|
+
if (!props.shouldUsePortal) return content;
|
|
326
|
+
return typeof document === "undefined" ? null : h(Teleport, { to: resolveContainer(props.portalContainer) ?? document.body }, h(ThemeScope, null, () => content));
|
|
327
|
+
};
|
|
328
|
+
}, {
|
|
329
|
+
name: "Modal",
|
|
330
|
+
inheritAttrs: false,
|
|
331
|
+
props: {
|
|
332
|
+
...declare("portalContainer", "scroll", "layer", "style", "slotProps"),
|
|
333
|
+
isOpen: {
|
|
334
|
+
type: Boolean,
|
|
335
|
+
required: true
|
|
336
|
+
},
|
|
337
|
+
hasBackdrop: {
|
|
338
|
+
type: Boolean,
|
|
339
|
+
default: true
|
|
340
|
+
},
|
|
341
|
+
shouldKeepMounted: {
|
|
342
|
+
type: Boolean,
|
|
343
|
+
default: false
|
|
344
|
+
},
|
|
345
|
+
shouldUsePortal: {
|
|
346
|
+
type: Boolean,
|
|
347
|
+
default: true
|
|
348
|
+
},
|
|
349
|
+
shouldLockScroll: {
|
|
350
|
+
type: Boolean,
|
|
351
|
+
default: true
|
|
352
|
+
},
|
|
353
|
+
disableAriaHidden: {
|
|
354
|
+
type: Boolean,
|
|
355
|
+
default: false
|
|
356
|
+
},
|
|
357
|
+
shouldAutoFocus: flag,
|
|
358
|
+
shouldTrapFocus: flag,
|
|
359
|
+
shouldEnforceFocus: flag,
|
|
360
|
+
shouldRestoreFocus: flag
|
|
361
|
+
},
|
|
362
|
+
emits: {
|
|
363
|
+
close: () => true,
|
|
364
|
+
"update:isOpen": () => true
|
|
365
|
+
},
|
|
366
|
+
slots: {}
|
|
367
|
+
});
|
|
368
|
+
export { Modal };
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_styled = require("./styled-JHkZtq_1.cjs");
|
|
3
|
+
const require_props = require("./props-DxoB9cT4.cjs");
|
|
4
|
+
let vue = require("vue");
|
|
5
|
+
let _umber_style_vue = require("@umber-style/vue");
|
|
6
|
+
let _gild_ui_core_theme = require("@gild-ui/core/theme");
|
|
7
|
+
let _soroush_tech_styled_system_should_forward_prop = require("@soroush.tech/styled-system/should-forward-prop");
|
|
8
|
+
let _soroush_tech_styled_system = require("@soroush.tech/styled-system");
|
|
9
|
+
// src/TextInput/TextAreaAutoResize.ts
|
|
10
|
+
const adjust = (el, minRows, maxRows) => {
|
|
11
|
+
const style = getComputedStyle(el);
|
|
12
|
+
const lineHeight = Number.parseFloat(style.lineHeight) || Number.parseFloat(style.fontSize) * 1.2;
|
|
13
|
+
const paddingY = Number.parseFloat(style.paddingTop) + Number.parseFloat(style.paddingBottom);
|
|
14
|
+
el.style.height = "auto";
|
|
15
|
+
const scrollHeight = el.scrollHeight;
|
|
16
|
+
const min = minRows == null ? 0 : Number(minRows) * lineHeight + paddingY;
|
|
17
|
+
const max = maxRows == null ? 1e400 : Number(maxRows) * lineHeight + paddingY;
|
|
18
|
+
el.style.height = `${Math.min(max, Math.max(min, scrollHeight))}px`;
|
|
19
|
+
el.style.overflow = scrollHeight > max ? "auto" : "hidden";
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* A textarea that grows with its content: its height is set again whenever its value or its row limits
|
|
23
|
+
* change, and as the user types. It takes the attributes of a textarea, `minRows` and `maxRows`.
|
|
24
|
+
*/
|
|
25
|
+
const TextAreaAutoResize = (0, vue.defineComponent)((props, { attrs }) => {
|
|
26
|
+
const element = (0, vue.ref)(null);
|
|
27
|
+
const resize = () => element.value && adjust(element.value, props.minRows, props.maxRows);
|
|
28
|
+
(0, vue.onMounted)(resize);
|
|
29
|
+
(0, vue.watch)(() => [
|
|
30
|
+
props.value,
|
|
31
|
+
props.minRows,
|
|
32
|
+
props.maxRows
|
|
33
|
+
], () => (0, vue.nextTick)(resize));
|
|
34
|
+
return () => (0, vue.h)("textarea", {
|
|
35
|
+
...attrs,
|
|
36
|
+
ref: element,
|
|
37
|
+
value: props.value,
|
|
38
|
+
onInput: (event) => {
|
|
39
|
+
resize();
|
|
40
|
+
const listener = attrs.onInput;
|
|
41
|
+
if (typeof listener === "function") listener(event);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}, {
|
|
45
|
+
name: "TextAreaAutoResize",
|
|
46
|
+
inheritAttrs: false,
|
|
47
|
+
props: {
|
|
48
|
+
value: [
|
|
49
|
+
String,
|
|
50
|
+
Number,
|
|
51
|
+
Array
|
|
52
|
+
],
|
|
53
|
+
minRows: [Number, String],
|
|
54
|
+
maxRows: [Number, String]
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
// ../react/src/utils/inputVariantStyles.ts
|
|
58
|
+
const inputVariantStyles = (0, _soroush_tech_styled_system.variant)({
|
|
59
|
+
prop: "variant",
|
|
60
|
+
variants: {
|
|
61
|
+
outlined: {
|
|
62
|
+
borderRadius: "sq",
|
|
63
|
+
borderWidth: "thin",
|
|
64
|
+
borderStyle: "solid"
|
|
65
|
+
},
|
|
66
|
+
default: {
|
|
67
|
+
borderRadius: "sq",
|
|
68
|
+
borderStyle: "none"
|
|
69
|
+
},
|
|
70
|
+
underline: {
|
|
71
|
+
borderRadius: "sq",
|
|
72
|
+
borderStyle: "none",
|
|
73
|
+
borderBottomWidth: "thin",
|
|
74
|
+
borderBottomStyle: "solid"
|
|
75
|
+
},
|
|
76
|
+
text: {
|
|
77
|
+
borderRadius: "sq",
|
|
78
|
+
borderStyle: "none"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
// ../react/src/utils/inputStyles.ts
|
|
83
|
+
/** The least width of a field that does not fill its row: `theme.defaults.inputMinWidth`, else `'12rem'`. */
|
|
84
|
+
const getInputMinWidth = (theme) => (0, _gild_ui_core_theme.themeDefault)(theme, "inputMinWidth", "12rem");
|
|
85
|
+
/**
|
|
86
|
+
* The keyboard focus ring of every input - the one the border takes on focus: the error color
|
|
87
|
+
* while it is in error, else the field's own color.
|
|
88
|
+
*/
|
|
89
|
+
const getFocusRing = (theme, color, isError = false) => {
|
|
90
|
+
return {
|
|
91
|
+
outline: `2px solid ${(0, _soroush_tech_styled_system.get)(theme, `palette.${isError ? "error" : color}.main`)}`,
|
|
92
|
+
outlineOffset: "2px"
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
// src/TextInput/TextInput.ts
|
|
96
|
+
const shouldForwardProp = (0, _soroush_tech_styled_system_should_forward_prop.createShouldForwardProp)([
|
|
97
|
+
..._soroush_tech_styled_system_should_forward_prop.props,
|
|
98
|
+
"as",
|
|
99
|
+
"color",
|
|
100
|
+
"textColor",
|
|
101
|
+
"variant",
|
|
102
|
+
"error",
|
|
103
|
+
"disabled",
|
|
104
|
+
"fullWidth"
|
|
105
|
+
]);
|
|
106
|
+
const baseStyle = {
|
|
107
|
+
display: "inline-flex",
|
|
108
|
+
alignItems: "center",
|
|
109
|
+
transition: "border-color 0.15s ease"
|
|
110
|
+
};
|
|
111
|
+
const backgroundStyle = ({ theme, textColor, color = (0, _gild_ui_core_theme.themeDefault)(theme, "color", "primary") }) => {
|
|
112
|
+
return {
|
|
113
|
+
backgroundColor: (0, _soroush_tech_styled_system.get)(theme, `background.${(0, _gild_ui_core_theme.themeDefault)(theme, "inputBg", "terminal")}`),
|
|
114
|
+
color: textColor ? (0, _soroush_tech_styled_system.get)(theme, `text.${textColor}`) : (0, _soroush_tech_styled_system.get)(theme, `palette.${color}.main`),
|
|
115
|
+
fontFamily: (0, _soroush_tech_styled_system.get)(theme, "fonts.body"),
|
|
116
|
+
fontSize: (0, _soroush_tech_styled_system.get)(theme, "fontSizes.1"),
|
|
117
|
+
lineHeight: (0, _soroush_tech_styled_system.get)(theme, "lineHeights.base")
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
const colorBorder = ({ theme, color = (0, _gild_ui_core_theme.themeDefault)(theme, "color", "primary"), error }) => {
|
|
121
|
+
return { borderColor: error ? (0, _soroush_tech_styled_system.get)(theme, "palette.error.main") : (0, _soroush_tech_styled_system.get)(theme, `palette.${color}.light`) };
|
|
122
|
+
};
|
|
123
|
+
const focusVisibleRing = ({ theme, color = (0, _gild_ui_core_theme.themeDefault)(theme, "color", "primary"), error }) => ({ "&:has(:focus-visible)": getFocusRing(theme, color, error) });
|
|
124
|
+
const focusWithinColor = ({ theme, color = (0, _gild_ui_core_theme.themeDefault)(theme, "color", "primary"), error }) => ({ "&:focus-within": { borderColor: error ? (0, _soroush_tech_styled_system.get)(theme, "palette.error.main") : (0, _soroush_tech_styled_system.get)(theme, `palette.${color}.main`) } });
|
|
125
|
+
const borderRadiusStyle = ({ variant: v = "default", borderRadius, theme }) => {
|
|
126
|
+
if (v === "underline" || v === "text" || !borderRadius) return {};
|
|
127
|
+
return { borderRadius: (0, _soroush_tech_styled_system.get)(theme, `radii.${borderRadius}`) };
|
|
128
|
+
};
|
|
129
|
+
const layoutStyles = ({ theme, fullWidth, disabled }) => ({
|
|
130
|
+
minWidth: getInputMinWidth(theme),
|
|
131
|
+
...fullWidth ? {
|
|
132
|
+
display: "flex",
|
|
133
|
+
width: "100%"
|
|
134
|
+
} : {},
|
|
135
|
+
...disabled ? {
|
|
136
|
+
opacity: .5,
|
|
137
|
+
cursor: "not-allowed",
|
|
138
|
+
pointerEvents: "none"
|
|
139
|
+
} : {}
|
|
140
|
+
});
|
|
141
|
+
const nativeBaseStyles = {
|
|
142
|
+
flex: 1,
|
|
143
|
+
minWidth: 0,
|
|
144
|
+
width: "100%",
|
|
145
|
+
border: "none",
|
|
146
|
+
outline: "none",
|
|
147
|
+
background: "transparent",
|
|
148
|
+
color: "inherit",
|
|
149
|
+
fontFamily: "inherit",
|
|
150
|
+
lineHeight: "inherit",
|
|
151
|
+
"&::placeholder": {
|
|
152
|
+
color: "inherit",
|
|
153
|
+
opacity: .5
|
|
154
|
+
},
|
|
155
|
+
"&:disabled": { cursor: "not-allowed" }
|
|
156
|
+
};
|
|
157
|
+
const textAreaBaseStyles = {
|
|
158
|
+
resize: "none",
|
|
159
|
+
overflow: "auto"
|
|
160
|
+
};
|
|
161
|
+
const InputBase = (0, vue.defineComponent)((props, { attrs }) => () => (0, vue.h)(props.inputComponent ?? "input", {
|
|
162
|
+
...attrs,
|
|
163
|
+
size: props.inputSize
|
|
164
|
+
}), {
|
|
165
|
+
name: "InputBase",
|
|
166
|
+
inheritAttrs: false,
|
|
167
|
+
props: {
|
|
168
|
+
inputSize: Number,
|
|
169
|
+
inputComponent: { type: null }
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
const widthStyles = (0, _soroush_tech_styled_system.system)({
|
|
173
|
+
width: true,
|
|
174
|
+
minWidth: true,
|
|
175
|
+
maxWidth: true
|
|
176
|
+
});
|
|
177
|
+
const sizeVariants = ({ theme, size }) => {
|
|
178
|
+
const s = theme.sizes[size];
|
|
179
|
+
return {
|
|
180
|
+
paddingTop: theme.space[s.paddingTop],
|
|
181
|
+
paddingBottom: theme.space[s.paddingBottom],
|
|
182
|
+
paddingLeft: theme.space[s.paddingLeft],
|
|
183
|
+
paddingRight: theme.space[s.paddingRight],
|
|
184
|
+
fontSize: theme.fontSizes[s.fontSize]
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
const TextInputRoot = require_styled.styled("div", {
|
|
188
|
+
name: "TextInput",
|
|
189
|
+
label: "TextInput",
|
|
190
|
+
shouldForwardProp,
|
|
191
|
+
systemProps: [_soroush_tech_styled_system.space, widthStyles]
|
|
192
|
+
})(baseStyle, inputVariantStyles, borderRadiusStyle, colorBorder, focusWithinColor, focusVisibleRing, backgroundStyle, layoutStyles);
|
|
193
|
+
const StyledInput = require_styled.styled(InputBase, {
|
|
194
|
+
name: "TextInput",
|
|
195
|
+
slot: "input",
|
|
196
|
+
label: "TextInputInput"
|
|
197
|
+
})(nativeBaseStyles, sizeVariants);
|
|
198
|
+
const shouldForwardInputProps = (prop) => prop !== "size";
|
|
199
|
+
const StyledTextarea = require_styled.styled("textarea", {
|
|
200
|
+
name: "TextInput",
|
|
201
|
+
slot: "input",
|
|
202
|
+
label: "TextInputTextarea",
|
|
203
|
+
shouldForwardProp: shouldForwardInputProps
|
|
204
|
+
})(nativeBaseStyles, textAreaBaseStyles, sizeVariants);
|
|
205
|
+
const StyledAutoResizeTextarea = require_styled.styled(TextAreaAutoResize, {
|
|
206
|
+
name: "TextInput",
|
|
207
|
+
slot: "input",
|
|
208
|
+
label: "TextInputTextarea",
|
|
209
|
+
shouldForwardProp: shouldForwardInputProps
|
|
210
|
+
})(nativeBaseStyles, textAreaBaseStyles, sizeVariants);
|
|
211
|
+
/** The value of the field an event came from, which is the target of an `input` event. */
|
|
212
|
+
const valueOf = (event) => {
|
|
213
|
+
const { target } = event;
|
|
214
|
+
return target && "value" in target && typeof target.value === "string" ? target.value : "";
|
|
215
|
+
};
|
|
216
|
+
const TextInput = (0, vue.defineComponent)((props, { attrs, emit }) => {
|
|
217
|
+
const theme = (0, _umber_style_vue.useTheme)();
|
|
218
|
+
return () => {
|
|
219
|
+
const { class: className, ...otherAttributes } = attrs;
|
|
220
|
+
const { classes, components, inputProps, slotProps, multiline, rows, resize, minRows } = props;
|
|
221
|
+
const { value } = theme;
|
|
222
|
+
const size = props.size ?? (0, _gild_ui_core_theme.themeDefault)(value, "size", "md");
|
|
223
|
+
const color = props.color ?? (0, _gild_ui_core_theme.themeDefault)(value, "color", "primary");
|
|
224
|
+
const type = props.type ?? "text";
|
|
225
|
+
const isAutoResize = resize ?? false;
|
|
226
|
+
const isMultiline = (multiline ?? false) || rows !== void 0 && Number(rows) > 1;
|
|
227
|
+
const isTextarea = (isAutoResize || isMultiline) && (!type || type === "text");
|
|
228
|
+
const inputComponent = props.inputComponent ?? components?.Input;
|
|
229
|
+
const inputElProps = {
|
|
230
|
+
...inputProps,
|
|
231
|
+
id: props.id,
|
|
232
|
+
name: props.name,
|
|
233
|
+
disabled: props.disabled ?? false,
|
|
234
|
+
required: props.required ?? false,
|
|
235
|
+
autocomplete: props.autoComplete,
|
|
236
|
+
autofocus: props.autoFocus,
|
|
237
|
+
placeholder: props.placeholder,
|
|
238
|
+
readonly: props.readOnly,
|
|
239
|
+
value: props.modelValue ?? props.value,
|
|
240
|
+
onInput: (event) => {
|
|
241
|
+
emit("update:modelValue", valueOf(event));
|
|
242
|
+
emit("change", event);
|
|
243
|
+
},
|
|
244
|
+
...require_props.mergeOverrides({ className: classes?.input }, slotProps?.input),
|
|
245
|
+
type: isTextarea ? void 0 : type,
|
|
246
|
+
rows: isMultiline && rows !== void 0 ? Number(rows) : void 0,
|
|
247
|
+
size,
|
|
248
|
+
"aria-describedby": inputProps?.["aria-describedby"]
|
|
249
|
+
};
|
|
250
|
+
let inputElement = (0, vue.h)(StyledInput, {
|
|
251
|
+
inputComponent,
|
|
252
|
+
inputSize: props.inputSize ?? (inputComponent ? void 0 : 1),
|
|
253
|
+
...inputElProps
|
|
254
|
+
});
|
|
255
|
+
if (isTextarea) inputElement = isAutoResize ? (0, vue.h)(StyledAutoResizeTextarea, {
|
|
256
|
+
...inputElProps,
|
|
257
|
+
cols: 1,
|
|
258
|
+
minRows: minRows ?? rows,
|
|
259
|
+
maxRows: props.maxRows
|
|
260
|
+
}) : (0, vue.h)(StyledTextarea, {
|
|
261
|
+
...inputElProps,
|
|
262
|
+
cols: 1
|
|
263
|
+
});
|
|
264
|
+
return (0, vue.h)(TextInputRoot, {
|
|
265
|
+
as: components?.Root,
|
|
266
|
+
color,
|
|
267
|
+
textColor: props.textColor,
|
|
268
|
+
variant: props.variant ?? (0, _gild_ui_core_theme.themeDefault)(value, "inputVariant", "default"),
|
|
269
|
+
error: props.error ?? false,
|
|
270
|
+
disabled: props.disabled ?? false,
|
|
271
|
+
fullWidth: props.fullWidth ?? false,
|
|
272
|
+
borderRadius: props.borderRadius,
|
|
273
|
+
...require_props.mergeOverrides(slotProps?.root, {
|
|
274
|
+
style: props.style,
|
|
275
|
+
class: [classes?.root, className]
|
|
276
|
+
}),
|
|
277
|
+
...otherAttributes
|
|
278
|
+
}, () => inputElement);
|
|
279
|
+
};
|
|
280
|
+
}, {
|
|
281
|
+
name: "TextInput",
|
|
282
|
+
inheritAttrs: false,
|
|
283
|
+
props: {
|
|
284
|
+
...require_props.declare("borderRadius", "autoComplete", "autoFocus", "classes", "components", "color", "textColor", "id", "inputComponent", "inputProps", "inputSize", "maxRows", "minRows", "name", "placeholder", "rows", "size", "type", "variant", "value", "modelValue", "slotProps", "style"),
|
|
285
|
+
disabled: require_props.flag,
|
|
286
|
+
error: require_props.flag,
|
|
287
|
+
fullWidth: require_props.flag,
|
|
288
|
+
multiline: require_props.flag,
|
|
289
|
+
readOnly: require_props.flag,
|
|
290
|
+
required: require_props.flag,
|
|
291
|
+
resize: require_props.flag
|
|
292
|
+
},
|
|
293
|
+
emits: {
|
|
294
|
+
change: () => true,
|
|
295
|
+
"update:modelValue": () => true
|
|
296
|
+
},
|
|
297
|
+
slots: {}
|
|
298
|
+
});
|
|
299
|
+
exports.TextInput = TextInput;
|