@marwes-ui/react 0.0.4 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +510 -86
- package/dist/index.d.ts +1550 -441
- package/dist/index.js +3978 -246
- package/dist/index.js.map +1 -1
- package/package.json +16 -12
package/dist/index.js
CHANGED
|
@@ -1,45 +1,137 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import * as
|
|
1
|
+
import '@marwes-ui/presets/firstEdition/styles.css';
|
|
2
|
+
import { createRichTextRecipe, resolveRichTextAllowedFormats, normalizeRichTextHtml, isRichTextHtmlEmpty, createDividerRecipe, createSpacingRecipe, createSliderRecipe, richTextCommandByFormat, resolveIconSize, resolveIconStrokeWidth, iconRegistry, resolveIconA11y, ThemeMode, resolveThemeInput, createSpinnerRecipe, createButtonRecipe, ButtonAction, ButtonVariant, IconName, createInputRecipe, createSelectRecipe, resolveSelectMode, createTextareaRecipe, paragraphRecipe, buildInputFieldA11yIds, sanitizeInputOtpValue, createInputOtpRecipe, buildRichTextFieldA11yIds, buildCurrencyHelperText, getCurrencySymbol, createAvatarRecipe, createPurposeSemanticAttributes, checkboxRecipe, buildCheckboxFieldA11yIds, buildCheckboxGroupFieldA11yIds, headingRecipe, createCardRecipe, createToastRecipe, createTooltipRecipe, createAccordionRecipe, buildAccordionFieldA11yIds, radioRecipe, buildRadioGroupFieldA11yIds, createBadgeRecipe, createSwitchRecipe, buildSwitchFieldA11yIds, buildSliderFieldA11yIds, createTabRecipe, resolveTabValue, buildTabGroupA11yIds, moveTabSelection, createDialogRecipe, sanitizeCurrencyValue, themeToCSSVars, extractUsedWeights, extractFontFamilyName, shouldLoadGoogleFont, buildGoogleFontsUrl } from '@marwes-ui/core';
|
|
3
|
+
export { AvatarSize, AvatarType, BadgeVariant, ButtonAction, ButtonSize, ButtonVariant, IconName, Spacings, SwitchSize, ThemeMode, createFontStack, mwAvailableFonts, mwFontFallbacks, mwGoogleFontFamilies, mwStyledTheme, mwThemeVarNames, mwThemeVars, mwVar } from '@marwes-ui/core';
|
|
4
|
+
import * as React6 from 'react';
|
|
5
5
|
import { useEffect } from 'react';
|
|
6
|
-
import {
|
|
6
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
7
|
+
import { createPortal } from 'react-dom';
|
|
7
8
|
|
|
8
|
-
// src/
|
|
9
|
-
var MarwesContext =
|
|
9
|
+
// src/index.ts
|
|
10
|
+
var MarwesContext = React6.createContext(null);
|
|
11
|
+
var loadedFonts = /* @__PURE__ */ new Set();
|
|
12
|
+
var preconnected = false;
|
|
13
|
+
function themeToRootStyle(theme) {
|
|
14
|
+
return {
|
|
15
|
+
...themeToCSSVars(theme),
|
|
16
|
+
backgroundColor: theme.color.background,
|
|
17
|
+
color: theme.color.text
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function applyThemeToElement(element, theme) {
|
|
21
|
+
element.setAttribute("data-marwes-theme", "true");
|
|
22
|
+
for (const [property, value] of Object.entries(themeToRootStyle(theme))) {
|
|
23
|
+
if (property === "backgroundColor") {
|
|
24
|
+
element.style.backgroundColor = value;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
element.style.setProperty(property, value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function ensureFontPreconnect() {
|
|
31
|
+
if (preconnected || typeof document === "undefined") return;
|
|
32
|
+
preconnected = true;
|
|
33
|
+
for (const href of ["https://fonts.googleapis.com", "https://fonts.gstatic.com"]) {
|
|
34
|
+
const linkElement = document.createElement("link");
|
|
35
|
+
linkElement.rel = "preconnect";
|
|
36
|
+
linkElement.href = href;
|
|
37
|
+
if (href.includes("gstatic")) {
|
|
38
|
+
linkElement.crossOrigin = "anonymous";
|
|
39
|
+
}
|
|
40
|
+
document.head.appendChild(linkElement);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function loadGoogleFontToDocument(family, weights) {
|
|
44
|
+
if (typeof document === "undefined") return;
|
|
45
|
+
const cacheKey = `${family}:${weights.join(",")}`;
|
|
46
|
+
if (loadedFonts.has(cacheKey)) return;
|
|
47
|
+
loadedFonts.add(cacheKey);
|
|
48
|
+
ensureFontPreconnect();
|
|
49
|
+
const linkElement = document.createElement("link");
|
|
50
|
+
linkElement.rel = "stylesheet";
|
|
51
|
+
linkElement.href = buildGoogleFontsUrl(family, weights);
|
|
52
|
+
linkElement.dataset.marwesFont = family;
|
|
53
|
+
document.head.appendChild(linkElement);
|
|
54
|
+
}
|
|
55
|
+
function loadThemeFonts(theme, config = "auto") {
|
|
56
|
+
const weights = extractUsedWeights(theme.typography);
|
|
57
|
+
const fontStacks = [theme.font.primary, theme.font.secondary];
|
|
58
|
+
for (const fontStack of fontStacks) {
|
|
59
|
+
const familyName = extractFontFamilyName(fontStack);
|
|
60
|
+
if (familyName && shouldLoadGoogleFont(familyName, config)) {
|
|
61
|
+
loadGoogleFontToDocument(familyName, weights);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
10
65
|
function MarwesProvider({
|
|
11
|
-
preset = firstEdition,
|
|
12
66
|
theme,
|
|
13
|
-
|
|
67
|
+
defaultMode = ThemeMode.light,
|
|
68
|
+
mode: controlledMode,
|
|
69
|
+
fontLoading = "auto",
|
|
14
70
|
onModeChange,
|
|
15
71
|
children
|
|
16
72
|
}) {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
73
|
+
const rootRef = React6.useRef(null);
|
|
74
|
+
const [internalMode, setInternalMode] = React6.useState(defaultMode);
|
|
75
|
+
const activeMode = controlledMode ?? theme?.mode ?? internalMode;
|
|
76
|
+
const isModeControlled = controlledMode !== void 0 || theme?.mode !== void 0;
|
|
77
|
+
const setMode = React6.useCallback(
|
|
78
|
+
(nextMode) => {
|
|
79
|
+
if (!isModeControlled) {
|
|
80
|
+
setInternalMode(nextMode);
|
|
81
|
+
}
|
|
82
|
+
onModeChange?.(nextMode);
|
|
83
|
+
},
|
|
84
|
+
[isModeControlled, onModeChange]
|
|
85
|
+
);
|
|
86
|
+
const toggleMode = React6.useCallback(() => {
|
|
87
|
+
setMode(activeMode === ThemeMode.dark ? ThemeMode.light : ThemeMode.dark);
|
|
88
|
+
}, [activeMode, setMode]);
|
|
89
|
+
const resolved = React6.useMemo(
|
|
90
|
+
() => resolveThemeInput({ ...theme ?? {}, mode: activeMode }),
|
|
91
|
+
[activeMode, theme]
|
|
92
|
+
);
|
|
93
|
+
const rootStyle = React6.useMemo(
|
|
94
|
+
() => themeToRootStyle(resolved),
|
|
95
|
+
[resolved]
|
|
96
|
+
);
|
|
97
|
+
React6.useEffect(() => {
|
|
98
|
+
if (rootRef.current) {
|
|
99
|
+
applyThemeToElement(rootRef.current, resolved);
|
|
100
|
+
}
|
|
101
|
+
}, [resolved]);
|
|
102
|
+
React6.useEffect(() => {
|
|
103
|
+
loadThemeFonts(resolved, fontLoading);
|
|
104
|
+
}, [resolved, fontLoading]);
|
|
105
|
+
return /* @__PURE__ */ jsx(MarwesContext.Provider, { value: { theme: resolved, mode: activeMode, setMode, toggleMode }, children: /* @__PURE__ */ jsx(
|
|
106
|
+
"div",
|
|
107
|
+
{
|
|
108
|
+
ref: rootRef,
|
|
109
|
+
className: `mw-theme--${resolved.mode}`,
|
|
110
|
+
"data-marwes-theme": "true",
|
|
111
|
+
style: rootStyle,
|
|
112
|
+
children
|
|
113
|
+
}
|
|
114
|
+
) });
|
|
115
|
+
}
|
|
116
|
+
function useTheme() {
|
|
117
|
+
const ctx = React6.useContext(MarwesContext);
|
|
34
118
|
if (!ctx) {
|
|
35
119
|
throw new Error("MarwesProvider is missing. Wrap your app in <MarwesProvider />.");
|
|
36
120
|
}
|
|
37
|
-
return ctx.
|
|
121
|
+
return ctx.theme;
|
|
38
122
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
123
|
+
function useThemeMode() {
|
|
124
|
+
const ctx = React6.useContext(MarwesContext);
|
|
125
|
+
if (!ctx) {
|
|
126
|
+
throw new Error("MarwesProvider is missing. Wrap your app in <MarwesProvider />.");
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
mode: ctx.mode,
|
|
130
|
+
setMode: ctx.setMode,
|
|
131
|
+
toggleMode: ctx.toggleMode,
|
|
132
|
+
isDark: ctx.mode === ThemeMode.dark,
|
|
133
|
+
isLight: ctx.mode === ThemeMode.light
|
|
134
|
+
};
|
|
43
135
|
}
|
|
44
136
|
function Icon({
|
|
45
137
|
name,
|
|
@@ -49,12 +141,13 @@ function Icon({
|
|
|
49
141
|
"aria-label": ariaLabel,
|
|
50
142
|
decorative
|
|
51
143
|
}) {
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const px = resolveIconSize(size ?? themeIcon.size);
|
|
55
|
-
const sw = resolveIconStrokeWidth(strokeWidth ?? themeIcon.strokeWidth);
|
|
144
|
+
const px = resolveIconSize(size ?? "sm");
|
|
145
|
+
const sw = resolveIconStrokeWidth(strokeWidth ?? "md");
|
|
56
146
|
const def = iconRegistry[name];
|
|
57
|
-
const
|
|
147
|
+
const a11y = resolveIconA11y({
|
|
148
|
+
...ariaLabel !== void 0 ? { ariaLabel } : {},
|
|
149
|
+
...decorative !== void 0 ? { decorative } : {}
|
|
150
|
+
});
|
|
58
151
|
return /* @__PURE__ */ jsx(
|
|
59
152
|
"svg",
|
|
60
153
|
{
|
|
@@ -67,9 +160,9 @@ function Icon({
|
|
|
67
160
|
strokeLinecap: "round",
|
|
68
161
|
strokeLinejoin: "round",
|
|
69
162
|
className,
|
|
70
|
-
"aria-hidden":
|
|
71
|
-
"aria-label": ariaLabel,
|
|
72
|
-
role:
|
|
163
|
+
"aria-hidden": a11y.ariaHidden ? "true" : void 0,
|
|
164
|
+
"aria-label": a11y.ariaLabel,
|
|
165
|
+
role: a11y.role,
|
|
73
166
|
focusable: "false",
|
|
74
167
|
children: def.nodes.map((iconNode, nodeIndex) => {
|
|
75
168
|
const TagName = iconNode.tag;
|
|
@@ -78,15 +171,118 @@ function Icon({
|
|
|
78
171
|
}
|
|
79
172
|
);
|
|
80
173
|
}
|
|
174
|
+
function renderSpinnerSvgNode(spinnerSvgNode, nodeIndex) {
|
|
175
|
+
const TagName = spinnerSvgNode.tag;
|
|
176
|
+
return /* @__PURE__ */ jsx(TagName, { ...spinnerSvgNode.attrs }, nodeIndex);
|
|
177
|
+
}
|
|
178
|
+
function Spinner(props) {
|
|
179
|
+
const {
|
|
180
|
+
className,
|
|
181
|
+
style,
|
|
182
|
+
dataAttributes,
|
|
183
|
+
variant,
|
|
184
|
+
size,
|
|
185
|
+
decorative,
|
|
186
|
+
ariaLabel,
|
|
187
|
+
id,
|
|
188
|
+
...nativeSpanProps
|
|
189
|
+
} = props;
|
|
190
|
+
const resolvedAriaLabel = ariaLabel ?? (typeof nativeSpanProps["aria-label"] === "string" ? nativeSpanProps["aria-label"] : void 0);
|
|
191
|
+
const spinnerOptions = {
|
|
192
|
+
...variant !== void 0 ? { variant } : {},
|
|
193
|
+
...size !== void 0 ? { size } : {},
|
|
194
|
+
...decorative !== void 0 ? { decorative } : {},
|
|
195
|
+
...resolvedAriaLabel !== void 0 ? { ariaLabel: resolvedAriaLabel } : {},
|
|
196
|
+
...id !== void 0 ? { id } : {}
|
|
197
|
+
};
|
|
198
|
+
const renderKit = createSpinnerRecipe(spinnerOptions);
|
|
199
|
+
const mergedClassName = [renderKit.className, className].filter(Boolean).join(" ");
|
|
200
|
+
const mergedStyle = { ...renderKit.vars, ...style };
|
|
201
|
+
return /* @__PURE__ */ jsx(
|
|
202
|
+
"span",
|
|
203
|
+
{
|
|
204
|
+
...nativeSpanProps,
|
|
205
|
+
...renderKit.dataAttributes,
|
|
206
|
+
...dataAttributes,
|
|
207
|
+
className: mergedClassName,
|
|
208
|
+
style: mergedStyle,
|
|
209
|
+
role: renderKit.a11y.role,
|
|
210
|
+
id: renderKit.a11y.id,
|
|
211
|
+
"aria-hidden": renderKit.a11y.ariaHidden ? "true" : void 0,
|
|
212
|
+
"aria-label": renderKit.a11y.ariaLabel,
|
|
213
|
+
"aria-live": renderKit.a11y.ariaLive,
|
|
214
|
+
children: /* @__PURE__ */ jsx(
|
|
215
|
+
"svg",
|
|
216
|
+
{
|
|
217
|
+
className: "mw-spinner__svg",
|
|
218
|
+
viewBox: renderKit.svg.viewBox,
|
|
219
|
+
"aria-hidden": "true",
|
|
220
|
+
focusable: "false",
|
|
221
|
+
children: renderKit.svg.nodes.map(renderSpinnerSvgNode)
|
|
222
|
+
}
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
function ButtonSpinner(props) {
|
|
228
|
+
const { inverted = false, style, dataAttributes, ...spinnerProps } = props;
|
|
229
|
+
const spinnerStyle = {
|
|
230
|
+
"--mw-spinner-track-color": inverted ? "color-mix(in srgb, currentColor 80%, transparent)" : "color-mix(in srgb, currentColor 35%, transparent)",
|
|
231
|
+
"--mw-spinner-indicator-color": "currentColor",
|
|
232
|
+
...style
|
|
233
|
+
};
|
|
234
|
+
return /* @__PURE__ */ jsx(
|
|
235
|
+
Spinner,
|
|
236
|
+
{
|
|
237
|
+
...spinnerProps,
|
|
238
|
+
variant: props.variant ?? "classic",
|
|
239
|
+
size: props.size ?? "xs",
|
|
240
|
+
decorative: props.decorative ?? true,
|
|
241
|
+
style: spinnerStyle,
|
|
242
|
+
dataAttributes: {
|
|
243
|
+
...dataAttributes,
|
|
244
|
+
"data-purpose": "button-loading",
|
|
245
|
+
"data-context": "button-loading"
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
function EmptyStateSpinner(props) {
|
|
251
|
+
return /* @__PURE__ */ jsx(
|
|
252
|
+
Spinner,
|
|
253
|
+
{
|
|
254
|
+
...props,
|
|
255
|
+
variant: props.variant ?? "dots-round",
|
|
256
|
+
size: props.size ?? "lg",
|
|
257
|
+
decorative: props.decorative ?? true,
|
|
258
|
+
dataAttributes: {
|
|
259
|
+
...props.dataAttributes,
|
|
260
|
+
"data-purpose": "empty-state",
|
|
261
|
+
"data-context": "empty-state"
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
function isFilledButtonVariant(variant) {
|
|
267
|
+
return variant === "primary" || variant === "success";
|
|
268
|
+
}
|
|
81
269
|
function Button(props) {
|
|
82
|
-
const
|
|
83
|
-
const kit = createButtonRecipe(theme, props);
|
|
270
|
+
const kit = createButtonRecipe(props);
|
|
84
271
|
const style = kit.vars;
|
|
85
272
|
const className = props.className ? `${kit.className} ${props.className}` : kit.className;
|
|
273
|
+
const resolvedVariant = props.variant ?? "primary";
|
|
274
|
+
const resolvedLoading = kit.loading;
|
|
275
|
+
const visibleLabel = resolvedLoading.isLoading && resolvedLoading.loadingLabel !== void 0 ? resolvedLoading.loadingLabel : props.children;
|
|
86
276
|
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
277
|
+
resolvedLoading.isLoading ? /* @__PURE__ */ jsx(
|
|
278
|
+
ButtonSpinner,
|
|
279
|
+
{
|
|
280
|
+
variant: resolvedLoading.spinnerVariant,
|
|
281
|
+
inverted: isFilledButtonVariant(resolvedVariant)
|
|
282
|
+
}
|
|
283
|
+
) : props.iconLeft ? /* @__PURE__ */ jsx(Icon, { name: props.iconLeft, size: "xs", strokeWidth: "sm", decorative: true }) : null,
|
|
284
|
+
visibleLabel,
|
|
285
|
+
!resolvedLoading.isLoading && props.iconRight ? /* @__PURE__ */ jsx(Icon, { name: props.iconRight, size: "xs", strokeWidth: "sm", decorative: true }) : null
|
|
90
286
|
] });
|
|
91
287
|
if (kit.tag === "button") {
|
|
92
288
|
return /* @__PURE__ */ jsx(
|
|
@@ -136,77 +332,357 @@ function Button(props) {
|
|
|
136
332
|
}
|
|
137
333
|
);
|
|
138
334
|
}
|
|
139
|
-
function
|
|
140
|
-
const
|
|
335
|
+
function isDevelopmentEnvironment() {
|
|
336
|
+
const nodeProcess = globalThis.process;
|
|
337
|
+
const nodeEnv = nodeProcess?.env?.NODE_ENV;
|
|
338
|
+
if (nodeEnv) {
|
|
339
|
+
return nodeEnv !== "production";
|
|
340
|
+
}
|
|
341
|
+
const meta = import.meta;
|
|
342
|
+
if (typeof meta.env?.PROD === "boolean") {
|
|
343
|
+
return !meta.env.PROD;
|
|
344
|
+
}
|
|
345
|
+
if (meta.env?.MODE) {
|
|
346
|
+
return meta.env.MODE !== "production";
|
|
347
|
+
}
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
function warnForForbiddenPurposeProps(componentName, rawProps, forbiddenProps) {
|
|
351
|
+
if (!isDevelopmentEnvironment()) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const warningByProp = {
|
|
355
|
+
variant: "Use Button if you need a custom visual treatment.",
|
|
356
|
+
action: "Use Button if you need a custom semantic action.",
|
|
357
|
+
as: "Use Button if you need a custom element mode."
|
|
358
|
+
};
|
|
359
|
+
for (const forbiddenProp of forbiddenProps) {
|
|
360
|
+
if (!Object.prototype.hasOwnProperty.call(rawProps, forbiddenProp)) {
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
console.warn(
|
|
364
|
+
`[marwes] ${componentName} does not support \`${forbiddenProp}\`. ${warningByProp[forbiddenProp]}`
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function omitButtonProps(rawProps, omittedKeys) {
|
|
369
|
+
const forwardedProps = { ...rawProps };
|
|
370
|
+
for (const omittedKey of omittedKeys) {
|
|
371
|
+
delete forwardedProps[omittedKey];
|
|
372
|
+
}
|
|
373
|
+
return forwardedProps;
|
|
374
|
+
}
|
|
375
|
+
function createPurposeButtonDataAttributes(purpose, existingDataAttributes, localDataAttributes = {}) {
|
|
376
|
+
return {
|
|
377
|
+
...existingDataAttributes,
|
|
378
|
+
...createPurposeSemanticAttributes(purpose),
|
|
379
|
+
...localDataAttributes
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function DestructiveButton(props) {
|
|
383
|
+
const rawProps = props;
|
|
384
|
+
warnForForbiddenPurposeProps("DestructiveButton", rawProps, ["variant", "action", "as"]);
|
|
385
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action", "as", "href"]);
|
|
386
|
+
const confirmation = props.confirmation ?? true;
|
|
141
387
|
return /* @__PURE__ */ jsx(
|
|
142
388
|
Button,
|
|
143
389
|
{
|
|
144
|
-
...
|
|
390
|
+
...forwardedProps,
|
|
391
|
+
as: "button",
|
|
145
392
|
variant: ButtonVariant.primary,
|
|
146
393
|
action: ButtonAction.delete,
|
|
147
|
-
|
|
394
|
+
error: true,
|
|
148
395
|
confirmation,
|
|
149
|
-
dataAttributes:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
396
|
+
dataAttributes: createPurposeButtonDataAttributes(
|
|
397
|
+
"destructive",
|
|
398
|
+
forwardedProps.dataAttributes,
|
|
399
|
+
{
|
|
400
|
+
"data-confirmation-required": confirmation ? "true" : "false"
|
|
401
|
+
}
|
|
402
|
+
)
|
|
154
403
|
}
|
|
155
404
|
);
|
|
156
405
|
}
|
|
157
406
|
function CreateButton(props) {
|
|
407
|
+
const rawProps = props;
|
|
408
|
+
warnForForbiddenPurposeProps("CreateButton", rawProps, ["variant", "action"]);
|
|
409
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action"]);
|
|
158
410
|
return /* @__PURE__ */ jsx(
|
|
159
411
|
Button,
|
|
160
412
|
{
|
|
161
|
-
...
|
|
162
|
-
action:
|
|
163
|
-
variant:
|
|
164
|
-
dataAttributes: {
|
|
165
|
-
...props.dataAttributes,
|
|
413
|
+
...forwardedProps,
|
|
414
|
+
action: ButtonAction.create,
|
|
415
|
+
variant: ButtonVariant.primary,
|
|
416
|
+
dataAttributes: createPurposeButtonDataAttributes("create", forwardedProps.dataAttributes, {
|
|
166
417
|
"data-creative": "true"
|
|
167
|
-
}
|
|
418
|
+
})
|
|
168
419
|
}
|
|
169
420
|
);
|
|
170
421
|
}
|
|
171
422
|
function SubmitButton(props) {
|
|
423
|
+
const rawProps = props;
|
|
424
|
+
warnForForbiddenPurposeProps("SubmitButton", rawProps, ["variant", "action", "as"]);
|
|
425
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action", "as", "href"]);
|
|
172
426
|
return /* @__PURE__ */ jsx(
|
|
173
427
|
Button,
|
|
174
428
|
{
|
|
175
|
-
...
|
|
429
|
+
...forwardedProps,
|
|
176
430
|
as: "button",
|
|
177
|
-
action:
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
...props.dataAttributes
|
|
181
|
-
}
|
|
431
|
+
action: ButtonAction.submit,
|
|
432
|
+
variant: ButtonVariant.primary,
|
|
433
|
+
dataAttributes: createPurposeButtonDataAttributes("submit", forwardedProps.dataAttributes)
|
|
182
434
|
}
|
|
183
435
|
);
|
|
184
436
|
}
|
|
185
437
|
function CancelButton(props) {
|
|
438
|
+
const rawProps = props;
|
|
439
|
+
warnForForbiddenPurposeProps("CancelButton", rawProps, ["variant", "action"]);
|
|
440
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action"]);
|
|
186
441
|
return /* @__PURE__ */ jsx(
|
|
187
442
|
Button,
|
|
188
443
|
{
|
|
189
|
-
...
|
|
190
|
-
action:
|
|
191
|
-
variant:
|
|
192
|
-
dataAttributes: {
|
|
193
|
-
...props.dataAttributes,
|
|
444
|
+
...forwardedProps,
|
|
445
|
+
action: ButtonAction.cancel,
|
|
446
|
+
variant: ButtonVariant.neutral,
|
|
447
|
+
dataAttributes: createPurposeButtonDataAttributes("cancel", forwardedProps.dataAttributes, {
|
|
194
448
|
"data-cancel": "true"
|
|
195
|
-
}
|
|
449
|
+
})
|
|
196
450
|
}
|
|
197
451
|
);
|
|
198
452
|
}
|
|
199
453
|
function LinkButton(props) {
|
|
454
|
+
const rawProps = props;
|
|
455
|
+
warnForForbiddenPurposeProps("LinkButton", rawProps, ["variant", "action", "as"]);
|
|
456
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action", "as"]);
|
|
200
457
|
return /* @__PURE__ */ jsx(
|
|
201
458
|
Button,
|
|
202
459
|
{
|
|
203
|
-
...
|
|
460
|
+
...forwardedProps,
|
|
204
461
|
as: "a",
|
|
205
|
-
action:
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
"
|
|
209
|
-
|
|
462
|
+
action: ButtonAction.navigate,
|
|
463
|
+
variant: ButtonVariant.text,
|
|
464
|
+
dataAttributes: createPurposeButtonDataAttributes(
|
|
465
|
+
"navigation",
|
|
466
|
+
forwardedProps.dataAttributes,
|
|
467
|
+
{
|
|
468
|
+
"data-navigation": "true"
|
|
469
|
+
}
|
|
470
|
+
)
|
|
471
|
+
}
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
function SaveButton(props) {
|
|
475
|
+
const rawProps = props;
|
|
476
|
+
warnForForbiddenPurposeProps("SaveButton", rawProps, ["variant", "action"]);
|
|
477
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action"]);
|
|
478
|
+
return /* @__PURE__ */ jsx(
|
|
479
|
+
Button,
|
|
480
|
+
{
|
|
481
|
+
...forwardedProps,
|
|
482
|
+
action: ButtonAction.submit,
|
|
483
|
+
variant: ButtonVariant.primary,
|
|
484
|
+
dataAttributes: createPurposeButtonDataAttributes("save", forwardedProps.dataAttributes, {
|
|
485
|
+
"data-persist": "true"
|
|
486
|
+
})
|
|
487
|
+
}
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
function ConfirmButton(props) {
|
|
491
|
+
const rawProps = props;
|
|
492
|
+
warnForForbiddenPurposeProps("ConfirmButton", rawProps, ["variant", "action", "as"]);
|
|
493
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action", "as", "href"]);
|
|
494
|
+
return /* @__PURE__ */ jsx(
|
|
495
|
+
Button,
|
|
496
|
+
{
|
|
497
|
+
...forwardedProps,
|
|
498
|
+
as: "button",
|
|
499
|
+
action: ButtonAction.button,
|
|
500
|
+
variant: ButtonVariant.success,
|
|
501
|
+
dataAttributes: createPurposeButtonDataAttributes("confirm", forwardedProps.dataAttributes)
|
|
502
|
+
}
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
function VerifyButton(props) {
|
|
506
|
+
const rawProps = props;
|
|
507
|
+
warnForForbiddenPurposeProps("VerifyButton", rawProps, ["variant", "action", "as"]);
|
|
508
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action", "as", "href"]);
|
|
509
|
+
return /* @__PURE__ */ jsx(
|
|
510
|
+
Button,
|
|
511
|
+
{
|
|
512
|
+
...forwardedProps,
|
|
513
|
+
as: "button",
|
|
514
|
+
action: ButtonAction.button,
|
|
515
|
+
variant: ButtonVariant.secondary,
|
|
516
|
+
iconRight: forwardedProps.iconRight ?? IconName.CheckCircle,
|
|
517
|
+
dataAttributes: createPurposeButtonDataAttributes("verify", forwardedProps.dataAttributes, {
|
|
518
|
+
"data-verification": "true"
|
|
519
|
+
})
|
|
520
|
+
}
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
function EditButton(props) {
|
|
524
|
+
const rawProps = props;
|
|
525
|
+
warnForForbiddenPurposeProps("EditButton", rawProps, ["variant", "action"]);
|
|
526
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action"]);
|
|
527
|
+
return /* @__PURE__ */ jsx(
|
|
528
|
+
Button,
|
|
529
|
+
{
|
|
530
|
+
...forwardedProps,
|
|
531
|
+
action: ButtonAction.edit,
|
|
532
|
+
variant: ButtonVariant.secondary,
|
|
533
|
+
iconRight: forwardedProps.iconRight ?? IconName.Edit,
|
|
534
|
+
dataAttributes: createPurposeButtonDataAttributes("edit", forwardedProps.dataAttributes, {
|
|
535
|
+
"data-edit": "true"
|
|
536
|
+
})
|
|
537
|
+
}
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
function CloseButton(props) {
|
|
541
|
+
const rawProps = props;
|
|
542
|
+
warnForForbiddenPurposeProps("CloseButton", rawProps, ["variant", "action"]);
|
|
543
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action"]);
|
|
544
|
+
return /* @__PURE__ */ jsx(
|
|
545
|
+
Button,
|
|
546
|
+
{
|
|
547
|
+
...forwardedProps,
|
|
548
|
+
action: ButtonAction.cancel,
|
|
549
|
+
variant: ButtonVariant.neutral,
|
|
550
|
+
dataAttributes: createPurposeButtonDataAttributes("close", forwardedProps.dataAttributes, {
|
|
551
|
+
"data-close": "true"
|
|
552
|
+
})
|
|
553
|
+
}
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
function RefreshButton(props) {
|
|
557
|
+
const rawProps = props;
|
|
558
|
+
warnForForbiddenPurposeProps("RefreshButton", rawProps, ["variant", "action"]);
|
|
559
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action"]);
|
|
560
|
+
return /* @__PURE__ */ jsx(
|
|
561
|
+
Button,
|
|
562
|
+
{
|
|
563
|
+
...forwardedProps,
|
|
564
|
+
action: ButtonAction.button,
|
|
565
|
+
variant: ButtonVariant.neutral,
|
|
566
|
+
iconRight: forwardedProps.iconRight ?? IconName.RefreshCw,
|
|
567
|
+
dataAttributes: createPurposeButtonDataAttributes("refresh", forwardedProps.dataAttributes, {
|
|
568
|
+
"data-refresh": "true"
|
|
569
|
+
})
|
|
570
|
+
}
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
function UploadButton(props) {
|
|
574
|
+
const rawProps = props;
|
|
575
|
+
warnForForbiddenPurposeProps("UploadButton", rawProps, ["variant", "action"]);
|
|
576
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action"]);
|
|
577
|
+
return /* @__PURE__ */ jsx(
|
|
578
|
+
Button,
|
|
579
|
+
{
|
|
580
|
+
...forwardedProps,
|
|
581
|
+
action: ButtonAction.button,
|
|
582
|
+
variant: ButtonVariant.secondary,
|
|
583
|
+
iconRight: forwardedProps.iconRight ?? IconName.Upload,
|
|
584
|
+
dataAttributes: createPurposeButtonDataAttributes("upload", forwardedProps.dataAttributes, {
|
|
585
|
+
"data-transfer": "upload"
|
|
586
|
+
})
|
|
587
|
+
}
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
function DownloadButton(props) {
|
|
591
|
+
const rawProps = props;
|
|
592
|
+
warnForForbiddenPurposeProps("DownloadButton", rawProps, ["variant", "action"]);
|
|
593
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action"]);
|
|
594
|
+
return /* @__PURE__ */ jsx(
|
|
595
|
+
Button,
|
|
596
|
+
{
|
|
597
|
+
...forwardedProps,
|
|
598
|
+
action: ButtonAction.button,
|
|
599
|
+
variant: ButtonVariant.secondary,
|
|
600
|
+
iconRight: forwardedProps.iconRight ?? IconName.Download,
|
|
601
|
+
dataAttributes: createPurposeButtonDataAttributes("download", forwardedProps.dataAttributes, {
|
|
602
|
+
"data-transfer": "download"
|
|
603
|
+
})
|
|
604
|
+
}
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
function CopyButton(props) {
|
|
608
|
+
const rawProps = props;
|
|
609
|
+
warnForForbiddenPurposeProps("CopyButton", rawProps, ["variant", "action"]);
|
|
610
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action"]);
|
|
611
|
+
return /* @__PURE__ */ jsx(
|
|
612
|
+
Button,
|
|
613
|
+
{
|
|
614
|
+
...forwardedProps,
|
|
615
|
+
action: ButtonAction.button,
|
|
616
|
+
variant: ButtonVariant.neutral,
|
|
617
|
+
dataAttributes: createPurposeButtonDataAttributes("copy", forwardedProps.dataAttributes, {
|
|
618
|
+
"data-copy": "true"
|
|
619
|
+
})
|
|
620
|
+
}
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
function SearchButton(props) {
|
|
624
|
+
const rawProps = props;
|
|
625
|
+
warnForForbiddenPurposeProps("SearchButton", rawProps, ["variant", "action"]);
|
|
626
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action"]);
|
|
627
|
+
return /* @__PURE__ */ jsx(
|
|
628
|
+
Button,
|
|
629
|
+
{
|
|
630
|
+
...forwardedProps,
|
|
631
|
+
action: ButtonAction.button,
|
|
632
|
+
variant: ButtonVariant.primary,
|
|
633
|
+
iconRight: forwardedProps.iconRight ?? IconName.Search,
|
|
634
|
+
dataAttributes: createPurposeButtonDataAttributes("search", forwardedProps.dataAttributes, {
|
|
635
|
+
"data-search": "true"
|
|
636
|
+
})
|
|
637
|
+
}
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
function FilterButton(props) {
|
|
641
|
+
const rawProps = props;
|
|
642
|
+
warnForForbiddenPurposeProps("FilterButton", rawProps, ["variant", "action"]);
|
|
643
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action"]);
|
|
644
|
+
return /* @__PURE__ */ jsx(
|
|
645
|
+
Button,
|
|
646
|
+
{
|
|
647
|
+
...forwardedProps,
|
|
648
|
+
action: ButtonAction.button,
|
|
649
|
+
variant: ButtonVariant.neutral,
|
|
650
|
+
dataAttributes: createPurposeButtonDataAttributes("filter", forwardedProps.dataAttributes, {
|
|
651
|
+
"data-filter": "true"
|
|
652
|
+
})
|
|
653
|
+
}
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
function SortButton(props) {
|
|
657
|
+
const rawProps = props;
|
|
658
|
+
warnForForbiddenPurposeProps("SortButton", rawProps, ["variant", "action"]);
|
|
659
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action"]);
|
|
660
|
+
return /* @__PURE__ */ jsx(
|
|
661
|
+
Button,
|
|
662
|
+
{
|
|
663
|
+
...forwardedProps,
|
|
664
|
+
action: ButtonAction.button,
|
|
665
|
+
variant: ButtonVariant.neutral,
|
|
666
|
+
dataAttributes: createPurposeButtonDataAttributes("sort", forwardedProps.dataAttributes, {
|
|
667
|
+
"data-sort": "true"
|
|
668
|
+
})
|
|
669
|
+
}
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
function DropdownButton(props) {
|
|
673
|
+
const rawProps = props;
|
|
674
|
+
warnForForbiddenPurposeProps("DropdownButton", rawProps, ["variant", "action"]);
|
|
675
|
+
const forwardedProps = omitButtonProps(rawProps, ["variant", "action"]);
|
|
676
|
+
return /* @__PURE__ */ jsx(
|
|
677
|
+
Button,
|
|
678
|
+
{
|
|
679
|
+
...forwardedProps,
|
|
680
|
+
action: ButtonAction.button,
|
|
681
|
+
variant: ButtonVariant.secondary,
|
|
682
|
+
iconRight: forwardedProps.iconRight ?? IconName.ChevronDown,
|
|
683
|
+
dataAttributes: createPurposeButtonDataAttributes("dropdown", forwardedProps.dataAttributes, {
|
|
684
|
+
"data-dropdown": "true"
|
|
685
|
+
})
|
|
210
686
|
}
|
|
211
687
|
);
|
|
212
688
|
}
|
|
@@ -219,24 +695,42 @@ function SecondaryButton(props) {
|
|
|
219
695
|
function TextButton(props) {
|
|
220
696
|
return /* @__PURE__ */ jsx(Button, { ...props, variant: "text", as: "button" });
|
|
221
697
|
}
|
|
698
|
+
function SuccessButton(props) {
|
|
699
|
+
return /* @__PURE__ */ jsx(
|
|
700
|
+
Button,
|
|
701
|
+
{
|
|
702
|
+
...props,
|
|
703
|
+
variant: "success",
|
|
704
|
+
as: "button",
|
|
705
|
+
dataAttributes: createPurposeButtonDataAttributes("success", props.dataAttributes)
|
|
706
|
+
}
|
|
707
|
+
);
|
|
708
|
+
}
|
|
222
709
|
var RENDERKIT_EVENT = "marwes/renderkit/renderkit-update";
|
|
710
|
+
var RENDERKIT_DEBUG_FLAG = "__MARWES_RENDERKIT_DEBUG__";
|
|
711
|
+
function isRenderKitDebugEnabled() {
|
|
712
|
+
if (typeof window === "undefined") {
|
|
713
|
+
return false;
|
|
714
|
+
}
|
|
715
|
+
const renderKitDebugWindow = window;
|
|
716
|
+
return renderKitDebugWindow[RENDERKIT_DEBUG_FLAG] === true;
|
|
717
|
+
}
|
|
223
718
|
function useRenderKitDebug(renderKit, componentName) {
|
|
224
719
|
useEffect(() => {
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
const event = new CustomEvent(RENDERKIT_EVENT, {
|
|
228
|
-
detail: {
|
|
229
|
-
...renderKit,
|
|
230
|
-
_meta: { component: componentName }
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
window.dispatchEvent(event);
|
|
720
|
+
if (!isRenderKitDebugEnabled()) {
|
|
721
|
+
return;
|
|
234
722
|
}
|
|
723
|
+
const event = new CustomEvent(RENDERKIT_EVENT, {
|
|
724
|
+
detail: {
|
|
725
|
+
...renderKit,
|
|
726
|
+
_meta: { component: componentName }
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
window.dispatchEvent(event);
|
|
235
730
|
}, [renderKit, componentName]);
|
|
236
731
|
}
|
|
237
732
|
function Input(props) {
|
|
238
|
-
const
|
|
239
|
-
const kit = createInputRecipe(theme, props);
|
|
733
|
+
const kit = createInputRecipe(props);
|
|
240
734
|
useRenderKitDebug(kit, "Input");
|
|
241
735
|
const style = kit.vars;
|
|
242
736
|
const className = props.className ? `${kit.className} ${props.className}` : kit.className;
|
|
@@ -266,77 +760,443 @@ function Input(props) {
|
|
|
266
760
|
}
|
|
267
761
|
);
|
|
268
762
|
}
|
|
269
|
-
function
|
|
270
|
-
const { onCheckedChange, onChange, ...coreProps } = props;
|
|
271
|
-
const theme = useTheme();
|
|
272
|
-
const kit = checkboxRecipe({ ...coreProps, theme });
|
|
273
|
-
const inputRef = React7.useRef(null);
|
|
274
|
-
React7.useLayoutEffect(() => {
|
|
275
|
-
const el = inputRef.current;
|
|
276
|
-
if (!el) return;
|
|
277
|
-
el.indeterminate = kit.indeterminate;
|
|
278
|
-
}, [kit.indeterminate]);
|
|
279
|
-
const handleChange = (e) => {
|
|
280
|
-
onChange?.(e);
|
|
281
|
-
onCheckedChange?.(e.currentTarget.checked);
|
|
282
|
-
};
|
|
283
|
-
const { a11y } = kit;
|
|
763
|
+
function SelectArrowIcon(props) {
|
|
284
764
|
return /* @__PURE__ */ jsx(
|
|
285
|
-
"
|
|
765
|
+
"svg",
|
|
286
766
|
{
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
defaultChecked: kit.defaultChecked,
|
|
303
|
-
onChange: handleChange
|
|
767
|
+
width: "16",
|
|
768
|
+
height: "16",
|
|
769
|
+
viewBox: "0 0 16 16",
|
|
770
|
+
fill: "none",
|
|
771
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
772
|
+
className: props.className,
|
|
773
|
+
"aria-hidden": "true",
|
|
774
|
+
focusable: "false",
|
|
775
|
+
children: /* @__PURE__ */ jsx(
|
|
776
|
+
"path",
|
|
777
|
+
{
|
|
778
|
+
d: "M11.5288 5.52876C11.7891 5.26841 12.2111 5.26841 12.4715 5.52876C12.7318 5.78911 12.7318 6.21114 12.4715 6.47147L8.47148 10.4715C8.21115 10.7318 7.78912 10.7318 7.52877 10.4715L3.52876 6.47147C3.26841 6.21112 3.26841 5.78911 3.52876 5.52876C3.78911 5.26841 4.21112 5.26841 4.47147 5.52876L6.58591 7.6432C7.36696 8.42425 8.63329 8.42425 9.41434 7.6432L11.5288 5.52876Z",
|
|
779
|
+
fill: "currentColor"
|
|
780
|
+
}
|
|
781
|
+
)
|
|
304
782
|
}
|
|
305
783
|
);
|
|
306
784
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const theme = useTheme();
|
|
319
|
-
const kit = headingRecipe({ ...opts, level: 1 }, theme);
|
|
320
|
-
const style = { ...kit.vars, ...customStyle };
|
|
321
|
-
const className = customClassName ? `${kit.className} ${customClassName}` : kit.className;
|
|
322
|
-
return /* @__PURE__ */ jsx("h1", { id: kit.a11y.id, "aria-label": kit.a11y.ariaLabel, className, style, children });
|
|
785
|
+
function getInitialSelectValue(props) {
|
|
786
|
+
if (props.value !== void 0) {
|
|
787
|
+
return props.value;
|
|
788
|
+
}
|
|
789
|
+
if (props.defaultValue !== void 0) {
|
|
790
|
+
return props.defaultValue;
|
|
791
|
+
}
|
|
792
|
+
if (props.placeholder !== void 0) {
|
|
793
|
+
return "";
|
|
794
|
+
}
|
|
795
|
+
return props.options[0]?.value ?? "";
|
|
323
796
|
}
|
|
324
|
-
function
|
|
325
|
-
const
|
|
326
|
-
const
|
|
327
|
-
const
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
797
|
+
function Select(props) {
|
|
798
|
+
const kit = createSelectRecipe(props);
|
|
799
|
+
const mode = resolveSelectMode(props);
|
|
800
|
+
const isControlled = props.value !== void 0;
|
|
801
|
+
const [uncontrolledValue, setUncontrolledValue] = React6.useState(
|
|
802
|
+
() => getInitialSelectValue(props)
|
|
803
|
+
);
|
|
804
|
+
useRenderKitDebug(kit, "Select");
|
|
805
|
+
const style = kit.vars;
|
|
806
|
+
const className = props.className ? `${kit.className} ${props.className}` : kit.className;
|
|
807
|
+
const value = isControlled ? props.value ?? "" : uncontrolledValue;
|
|
808
|
+
const hasPlaceholder = props.placeholder !== void 0;
|
|
809
|
+
const placeholderSelected = hasPlaceholder && value === "";
|
|
810
|
+
const handleChange = (e) => {
|
|
811
|
+
const nextValue = e.target.value;
|
|
812
|
+
if (!isControlled) {
|
|
813
|
+
setUncontrolledValue(nextValue);
|
|
814
|
+
}
|
|
815
|
+
props.onValueChange?.(nextValue);
|
|
816
|
+
};
|
|
817
|
+
const selectElement = /* @__PURE__ */ jsxs(
|
|
818
|
+
"select",
|
|
819
|
+
{
|
|
820
|
+
className,
|
|
821
|
+
style,
|
|
822
|
+
"data-placeholder-selected": placeholderSelected ? "true" : void 0,
|
|
823
|
+
id: kit.a11y.id,
|
|
824
|
+
name: kit.a11y.name,
|
|
825
|
+
disabled: kit.a11y.disabled,
|
|
826
|
+
required: kit.a11y.required,
|
|
827
|
+
"aria-label": kit.a11y.ariaLabel,
|
|
828
|
+
"aria-invalid": kit.a11y.ariaInvalid,
|
|
829
|
+
"aria-describedby": kit.a11y.ariaDescribedBy,
|
|
830
|
+
value,
|
|
831
|
+
onChange: handleChange,
|
|
832
|
+
children: [
|
|
833
|
+
props.placeholder ? /* @__PURE__ */ jsx("option", { value: "", disabled: props.required ? true : void 0, children: props.placeholder }) : null,
|
|
834
|
+
props.options.map((option) => /* @__PURE__ */ jsx(
|
|
835
|
+
"option",
|
|
836
|
+
{
|
|
837
|
+
value: option.value,
|
|
838
|
+
disabled: option.disabled ? true : void 0,
|
|
839
|
+
children: option.label
|
|
840
|
+
},
|
|
841
|
+
option.value
|
|
842
|
+
))
|
|
843
|
+
]
|
|
844
|
+
}
|
|
845
|
+
);
|
|
846
|
+
if (mode === "native") {
|
|
847
|
+
return selectElement;
|
|
848
|
+
}
|
|
849
|
+
return /* @__PURE__ */ jsxs("span", { className: "mw-select__control", children: [
|
|
850
|
+
selectElement,
|
|
851
|
+
/* @__PURE__ */ jsx(SelectArrowIcon, { className: "mw-select__control-icon" })
|
|
852
|
+
] });
|
|
331
853
|
}
|
|
332
|
-
function
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
const
|
|
336
|
-
const
|
|
337
|
-
const
|
|
338
|
-
|
|
854
|
+
function Textarea(props) {
|
|
855
|
+
const kit = createTextareaRecipe(props);
|
|
856
|
+
useRenderKitDebug(kit, "Textarea");
|
|
857
|
+
const style = kit.vars;
|
|
858
|
+
const className = props.className ? `${kit.className} ${props.className}` : kit.className;
|
|
859
|
+
const handleChange = (e) => {
|
|
860
|
+
props.onValueChange?.(e.target.value);
|
|
861
|
+
};
|
|
862
|
+
return /* @__PURE__ */ jsx(
|
|
863
|
+
"textarea",
|
|
864
|
+
{
|
|
865
|
+
className,
|
|
866
|
+
style,
|
|
867
|
+
id: kit.a11y.id,
|
|
868
|
+
name: kit.a11y.name,
|
|
869
|
+
inputMode: kit.a11y.inputMode,
|
|
870
|
+
autoComplete: kit.a11y.autoComplete,
|
|
871
|
+
placeholder: kit.a11y.placeholder,
|
|
872
|
+
disabled: kit.a11y.disabled,
|
|
873
|
+
readOnly: kit.a11y.readOnly,
|
|
874
|
+
required: kit.a11y.required,
|
|
875
|
+
rows: kit.a11y.rows,
|
|
876
|
+
cols: kit.a11y.cols,
|
|
877
|
+
"aria-label": kit.a11y.ariaLabel,
|
|
878
|
+
"aria-invalid": kit.a11y.ariaInvalid,
|
|
879
|
+
"aria-describedby": kit.a11y.ariaDescribedBy,
|
|
880
|
+
value: props.value,
|
|
881
|
+
defaultValue: props.defaultValue,
|
|
882
|
+
onChange: handleChange
|
|
883
|
+
}
|
|
884
|
+
);
|
|
885
|
+
}
|
|
886
|
+
var formatLabels = {
|
|
887
|
+
bold: "Bold",
|
|
888
|
+
italic: "Italic",
|
|
889
|
+
underline: "Underline"
|
|
890
|
+
};
|
|
891
|
+
function getRichTextCommandDocument() {
|
|
892
|
+
return document;
|
|
893
|
+
}
|
|
894
|
+
function mergeRefs(...refs) {
|
|
895
|
+
return (value) => {
|
|
896
|
+
for (const ref of refs) {
|
|
897
|
+
if (!ref) continue;
|
|
898
|
+
if (typeof ref === "function") {
|
|
899
|
+
ref(value);
|
|
900
|
+
continue;
|
|
901
|
+
}
|
|
902
|
+
ref.current = value;
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
function isNodeWithinEditor(node, editorElement) {
|
|
907
|
+
if (!node || !editorElement) {
|
|
908
|
+
return false;
|
|
909
|
+
}
|
|
910
|
+
return editorElement.contains(node.nodeType === Node.TEXT_NODE ? node.parentNode : node);
|
|
911
|
+
}
|
|
912
|
+
function getActiveFormatsFromSelection(editorElement) {
|
|
913
|
+
if (!editorElement || typeof window === "undefined" || typeof document === "undefined") {
|
|
914
|
+
return [];
|
|
915
|
+
}
|
|
916
|
+
const commandDocument = getRichTextCommandDocument();
|
|
917
|
+
const selection = window.getSelection();
|
|
918
|
+
const anchorNode = selection?.anchorNode ?? null;
|
|
919
|
+
if (!anchorNode || !isNodeWithinEditor(anchorNode, editorElement)) {
|
|
920
|
+
return [];
|
|
921
|
+
}
|
|
922
|
+
const activeFormats = /* @__PURE__ */ new Set();
|
|
923
|
+
if (typeof commandDocument.queryCommandState === "function") {
|
|
924
|
+
for (const format of Object.keys(richTextCommandByFormat)) {
|
|
925
|
+
try {
|
|
926
|
+
if (commandDocument.queryCommandState(richTextCommandByFormat[format])) {
|
|
927
|
+
activeFormats.add(format);
|
|
928
|
+
}
|
|
929
|
+
} catch {
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
if (activeFormats.size > 0) {
|
|
934
|
+
return Array.from(activeFormats);
|
|
935
|
+
}
|
|
936
|
+
let currentNode = anchorNode.nodeType === Node.TEXT_NODE ? anchorNode.parentNode : anchorNode;
|
|
937
|
+
while (currentNode && currentNode !== editorElement) {
|
|
938
|
+
if (!(currentNode instanceof HTMLElement)) {
|
|
939
|
+
currentNode = currentNode.parentNode;
|
|
940
|
+
continue;
|
|
941
|
+
}
|
|
942
|
+
const tagName = currentNode.tagName.toLowerCase();
|
|
943
|
+
if (tagName === "strong" || tagName === "b") activeFormats.add("bold");
|
|
944
|
+
if (tagName === "em" || tagName === "i") activeFormats.add("italic");
|
|
945
|
+
if (tagName === "u") activeFormats.add("underline");
|
|
946
|
+
currentNode = currentNode.parentNode;
|
|
947
|
+
}
|
|
948
|
+
return Array.from(activeFormats);
|
|
949
|
+
}
|
|
950
|
+
function ensureEditorSelection(editorElement) {
|
|
951
|
+
if (typeof window === "undefined") {
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
editorElement.focus();
|
|
955
|
+
const selection = window.getSelection();
|
|
956
|
+
const anchorNode = selection?.anchorNode ?? null;
|
|
957
|
+
if (anchorNode && isNodeWithinEditor(anchorNode, editorElement)) {
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
const range = document.createRange();
|
|
961
|
+
range.selectNodeContents(editorElement);
|
|
962
|
+
range.collapse(false);
|
|
963
|
+
selection?.removeAllRanges();
|
|
964
|
+
selection?.addRange(range);
|
|
965
|
+
}
|
|
966
|
+
function getFormatTagNames(format) {
|
|
967
|
+
if (format === "bold") return ["strong", "b"];
|
|
968
|
+
if (format === "italic") return ["em", "i"];
|
|
969
|
+
return ["u"];
|
|
970
|
+
}
|
|
971
|
+
function findNearestFormatElement(node, editorElement, format) {
|
|
972
|
+
const tagNames = getFormatTagNames(format);
|
|
973
|
+
let currentNode = node?.nodeType === Node.TEXT_NODE ? node.parentNode : node;
|
|
974
|
+
while (currentNode && currentNode !== editorElement) {
|
|
975
|
+
if (currentNode instanceof HTMLElement && tagNames.includes(currentNode.tagName.toLowerCase())) {
|
|
976
|
+
return currentNode;
|
|
977
|
+
}
|
|
978
|
+
currentNode = currentNode.parentNode;
|
|
979
|
+
}
|
|
980
|
+
return null;
|
|
339
981
|
}
|
|
982
|
+
function exitActiveFormatAtCaret(editorElement, format) {
|
|
983
|
+
if (typeof window === "undefined") {
|
|
984
|
+
return false;
|
|
985
|
+
}
|
|
986
|
+
const selection = window.getSelection();
|
|
987
|
+
if (!selection || selection.rangeCount === 0) {
|
|
988
|
+
return false;
|
|
989
|
+
}
|
|
990
|
+
const range = selection.getRangeAt(0);
|
|
991
|
+
const anchorNode = selection.anchorNode;
|
|
992
|
+
if (!range.collapsed || !anchorNode || !isNodeWithinEditor(anchorNode, editorElement)) {
|
|
993
|
+
return false;
|
|
994
|
+
}
|
|
995
|
+
const formatElement = findNearestFormatElement(anchorNode, editorElement, format);
|
|
996
|
+
if (!formatElement || !formatElement.parentNode) {
|
|
997
|
+
return false;
|
|
998
|
+
}
|
|
999
|
+
const trailingRange = document.createRange();
|
|
1000
|
+
trailingRange.setStart(range.startContainer, range.startOffset);
|
|
1001
|
+
trailingRange.setEndAfter(formatElement);
|
|
1002
|
+
const trailingFragment = trailingRange.extractContents();
|
|
1003
|
+
const caretTextNode = document.createTextNode("\u200B");
|
|
1004
|
+
const parentNode = formatElement.parentNode;
|
|
1005
|
+
parentNode.insertBefore(caretTextNode, formatElement.nextSibling);
|
|
1006
|
+
parentNode.insertBefore(trailingFragment, caretTextNode.nextSibling);
|
|
1007
|
+
if (formatElement.textContent?.replaceAll("\u200B", "").trim().length === 0) {
|
|
1008
|
+
formatElement.remove();
|
|
1009
|
+
}
|
|
1010
|
+
const nextRange = document.createRange();
|
|
1011
|
+
nextRange.setStart(caretTextNode, 1);
|
|
1012
|
+
nextRange.collapse(true);
|
|
1013
|
+
selection.removeAllRanges();
|
|
1014
|
+
selection.addRange(nextRange);
|
|
1015
|
+
return true;
|
|
1016
|
+
}
|
|
1017
|
+
var RichText = React6.forwardRef((props, forwardedRef) => {
|
|
1018
|
+
const kit = createRichTextRecipe(props);
|
|
1019
|
+
const allowedFormats = React6.useMemo(
|
|
1020
|
+
() => resolveRichTextAllowedFormats(props.allowedFormats),
|
|
1021
|
+
[props.allowedFormats]
|
|
1022
|
+
);
|
|
1023
|
+
const normalizedControlledValue = React6.useMemo(
|
|
1024
|
+
() => normalizeRichTextHtml(props.value),
|
|
1025
|
+
[props.value]
|
|
1026
|
+
);
|
|
1027
|
+
const initialUncontrolledValue = React6.useMemo(
|
|
1028
|
+
() => normalizeRichTextHtml(props.defaultValue),
|
|
1029
|
+
[props.defaultValue]
|
|
1030
|
+
);
|
|
1031
|
+
const isControlled = props.value !== void 0;
|
|
1032
|
+
const [uncontrolledHtml, setUncontrolledHtml] = React6.useState(initialUncontrolledValue);
|
|
1033
|
+
const [isEditorEmpty, setIsEditorEmpty] = React6.useState(
|
|
1034
|
+
isRichTextHtmlEmpty(isControlled ? normalizedControlledValue : initialUncontrolledValue)
|
|
1035
|
+
);
|
|
1036
|
+
const [activeFormats, setActiveFormats] = React6.useState([]);
|
|
1037
|
+
const editorElementRef = React6.useRef(null);
|
|
1038
|
+
useRenderKitDebug(kit, "RichText");
|
|
1039
|
+
const editorHtml = isControlled ? normalizedControlledValue : uncontrolledHtml;
|
|
1040
|
+
const style = kit.vars;
|
|
1041
|
+
const className = props.className ? `${kit.className} ${props.className}` : kit.className;
|
|
1042
|
+
const showToolbar = !props.readOnly;
|
|
1043
|
+
const syncEditorState = React6.useCallback(
|
|
1044
|
+
(nextHtml) => {
|
|
1045
|
+
const normalizedHtml = normalizeRichTextHtml(nextHtml);
|
|
1046
|
+
const emptyState = isRichTextHtmlEmpty(normalizedHtml);
|
|
1047
|
+
if (!isControlled) {
|
|
1048
|
+
setUncontrolledHtml(normalizedHtml);
|
|
1049
|
+
}
|
|
1050
|
+
setIsEditorEmpty(emptyState);
|
|
1051
|
+
props.onValueChange?.(normalizedHtml);
|
|
1052
|
+
return normalizedHtml;
|
|
1053
|
+
},
|
|
1054
|
+
[isControlled, props]
|
|
1055
|
+
);
|
|
1056
|
+
const refreshActiveFormats = React6.useCallback(() => {
|
|
1057
|
+
setActiveFormats(getActiveFormatsFromSelection(editorElementRef.current));
|
|
1058
|
+
}, []);
|
|
1059
|
+
React6.useLayoutEffect(() => {
|
|
1060
|
+
const editorElement = editorElementRef.current;
|
|
1061
|
+
if (!editorElement) {
|
|
1062
|
+
return;
|
|
1063
|
+
}
|
|
1064
|
+
const normalizedDomHtml = normalizeRichTextHtml(editorElement.innerHTML);
|
|
1065
|
+
if (normalizedDomHtml !== editorHtml) {
|
|
1066
|
+
editorElement.innerHTML = editorHtml;
|
|
1067
|
+
}
|
|
1068
|
+
setIsEditorEmpty(isRichTextHtmlEmpty(editorHtml));
|
|
1069
|
+
}, [editorHtml]);
|
|
1070
|
+
React6.useEffect(() => {
|
|
1071
|
+
if (typeof document === "undefined") {
|
|
1072
|
+
return void 0;
|
|
1073
|
+
}
|
|
1074
|
+
const handleSelectionChange = () => {
|
|
1075
|
+
refreshActiveFormats();
|
|
1076
|
+
};
|
|
1077
|
+
document.addEventListener("selectionchange", handleSelectionChange);
|
|
1078
|
+
return () => {
|
|
1079
|
+
document.removeEventListener("selectionchange", handleSelectionChange);
|
|
1080
|
+
};
|
|
1081
|
+
}, [refreshActiveFormats]);
|
|
1082
|
+
const handleInput = () => {
|
|
1083
|
+
const editorElement = editorElementRef.current;
|
|
1084
|
+
if (!editorElement || props.disabled || props.readOnly) {
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
syncEditorState(editorElement.innerHTML);
|
|
1088
|
+
refreshActiveFormats();
|
|
1089
|
+
};
|
|
1090
|
+
const toggleFormat = (format) => {
|
|
1091
|
+
if (props.disabled || props.readOnly || typeof document === "undefined") {
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
const commandDocument = getRichTextCommandDocument();
|
|
1095
|
+
const editorElement = editorElementRef.current;
|
|
1096
|
+
if (!editorElement) {
|
|
1097
|
+
return;
|
|
1098
|
+
}
|
|
1099
|
+
ensureEditorSelection(editorElement);
|
|
1100
|
+
const activeFormatsBeforeToggle = getActiveFormatsFromSelection(editorElement);
|
|
1101
|
+
if (exitActiveFormatAtCaret(editorElement, format)) {
|
|
1102
|
+
if (typeof commandDocument.queryCommandState === "function" && commandDocument.queryCommandState(richTextCommandByFormat[format]) && typeof commandDocument.execCommand === "function") {
|
|
1103
|
+
commandDocument.execCommand(richTextCommandByFormat[format]);
|
|
1104
|
+
}
|
|
1105
|
+
if (typeof commandDocument.queryCommandState === "function" && typeof commandDocument.execCommand === "function") {
|
|
1106
|
+
for (const activeFormat of activeFormatsBeforeToggle) {
|
|
1107
|
+
if (activeFormat === format) {
|
|
1108
|
+
continue;
|
|
1109
|
+
}
|
|
1110
|
+
if (!commandDocument.queryCommandState(richTextCommandByFormat[activeFormat])) {
|
|
1111
|
+
commandDocument.execCommand(richTextCommandByFormat[activeFormat]);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
syncEditorState(editorElement.innerHTML);
|
|
1116
|
+
refreshActiveFormats();
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
if (typeof commandDocument.execCommand === "function") {
|
|
1120
|
+
commandDocument.execCommand(richTextCommandByFormat[format]);
|
|
1121
|
+
}
|
|
1122
|
+
syncEditorState(editorElement.innerHTML);
|
|
1123
|
+
refreshActiveFormats();
|
|
1124
|
+
};
|
|
1125
|
+
const handleKeyDown = (event) => {
|
|
1126
|
+
if (!(event.metaKey || event.ctrlKey) || event.altKey) {
|
|
1127
|
+
return;
|
|
1128
|
+
}
|
|
1129
|
+
const formatByKey = {
|
|
1130
|
+
b: "bold",
|
|
1131
|
+
i: "italic",
|
|
1132
|
+
u: "underline"
|
|
1133
|
+
};
|
|
1134
|
+
const requestedFormat = formatByKey[event.key.toLowerCase()];
|
|
1135
|
+
if (!requestedFormat || !allowedFormats.includes(requestedFormat)) {
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
event.preventDefault();
|
|
1139
|
+
toggleFormat(requestedFormat);
|
|
1140
|
+
};
|
|
1141
|
+
return /* @__PURE__ */ jsxs("div", { className, style, ...kit.dataAttributes, children: [
|
|
1142
|
+
showToolbar && /* @__PURE__ */ jsx("div", { className: "mw-rich-text__toolbar", "data-rich-text-toolbar": true, children: allowedFormats.map((format) => {
|
|
1143
|
+
const isActive = activeFormats.includes(format);
|
|
1144
|
+
const iconName = format === "bold" ? "bold" : format === "italic" ? "italic" : "underline";
|
|
1145
|
+
return /* @__PURE__ */ jsx(
|
|
1146
|
+
"button",
|
|
1147
|
+
{
|
|
1148
|
+
type: "button",
|
|
1149
|
+
className: "mw-rich-text__toolbar-button",
|
|
1150
|
+
"data-format": format,
|
|
1151
|
+
"data-active": isActive ? "true" : void 0,
|
|
1152
|
+
"aria-label": formatLabels[format],
|
|
1153
|
+
"aria-pressed": isActive,
|
|
1154
|
+
disabled: props.disabled,
|
|
1155
|
+
onMouseDown: (event) => {
|
|
1156
|
+
event.preventDefault();
|
|
1157
|
+
},
|
|
1158
|
+
onClick: () => {
|
|
1159
|
+
toggleFormat(format);
|
|
1160
|
+
},
|
|
1161
|
+
children: /* @__PURE__ */ jsx(Icon, { name: iconName, size: "xs", decorative: true })
|
|
1162
|
+
},
|
|
1163
|
+
format
|
|
1164
|
+
);
|
|
1165
|
+
}) }),
|
|
1166
|
+
/* @__PURE__ */ jsx(
|
|
1167
|
+
"div",
|
|
1168
|
+
{
|
|
1169
|
+
ref: mergeRefs(editorElementRef, forwardedRef),
|
|
1170
|
+
className: "mw-rich-text__editor",
|
|
1171
|
+
"data-rich-text-editor": true,
|
|
1172
|
+
"data-empty": isEditorEmpty ? "true" : void 0,
|
|
1173
|
+
"data-placeholder": props.placeholder,
|
|
1174
|
+
id: kit.a11y.id,
|
|
1175
|
+
role: kit.a11y.role,
|
|
1176
|
+
tabIndex: kit.a11y.tabIndex,
|
|
1177
|
+
"aria-label": kit.a11y.ariaLabel,
|
|
1178
|
+
"aria-labelledby": kit.a11y.ariaLabelledBy,
|
|
1179
|
+
"aria-describedby": kit.a11y.ariaDescribedBy,
|
|
1180
|
+
"aria-invalid": kit.a11y.ariaInvalid,
|
|
1181
|
+
"aria-disabled": kit.a11y.ariaDisabled,
|
|
1182
|
+
"aria-readonly": kit.a11y.ariaReadOnly,
|
|
1183
|
+
"aria-required": kit.a11y.ariaRequired,
|
|
1184
|
+
"aria-multiline": kit.a11y.ariaMultiline,
|
|
1185
|
+
contentEditable: !props.disabled && !props.readOnly,
|
|
1186
|
+
suppressContentEditableWarning: true,
|
|
1187
|
+
onInput: handleInput,
|
|
1188
|
+
onKeyDown: handleKeyDown,
|
|
1189
|
+
onFocus: refreshActiveFormats,
|
|
1190
|
+
onBlur: () => {
|
|
1191
|
+
syncEditorState(editorElementRef.current?.innerHTML ?? "");
|
|
1192
|
+
setActiveFormats([]);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
),
|
|
1196
|
+
props.name && /* @__PURE__ */ jsx("input", { type: "hidden", name: props.name, value: editorHtml, disabled: props.disabled })
|
|
1197
|
+
] });
|
|
1198
|
+
});
|
|
1199
|
+
RichText.displayName = "RichText";
|
|
340
1200
|
function Paragraph(props) {
|
|
341
1201
|
const { children, className: customClassName, style: customStyle, ...opts } = props;
|
|
342
1202
|
const theme = useTheme();
|
|
@@ -348,62 +1208,37 @@ function Paragraph(props) {
|
|
|
348
1208
|
function cx(...parts) {
|
|
349
1209
|
return parts.filter(Boolean).join(" ");
|
|
350
1210
|
}
|
|
351
|
-
function
|
|
352
|
-
|
|
353
|
-
const id = props.id ?? `mw-checkbox-${reactId}`;
|
|
354
|
-
const hasDescription = props.description !== void 0;
|
|
355
|
-
const hasError = props.error !== void 0;
|
|
356
|
-
const descId = hasDescription ? `${id}-desc` : void 0;
|
|
357
|
-
const errorId = hasError ? `${id}-error` : void 0;
|
|
358
|
-
const describedByParts = [props.ariaDescribedBy, descId, errorId].filter(Boolean);
|
|
359
|
-
const mergedDescribedBy = describedByParts.length > 0 ? describedByParts.join(" ") : void 0;
|
|
360
|
-
const disabled = props.checkbox.disabled || false;
|
|
361
|
-
const invalid = hasError || props.checkbox.invalid || false;
|
|
362
|
-
const wrapperClass = cx(
|
|
363
|
-
"mw-checkbox-field",
|
|
364
|
-
disabled && "mw-checkbox-field--disabled",
|
|
365
|
-
invalid && "mw-checkbox-field--invalid"
|
|
366
|
-
);
|
|
367
|
-
const checkboxProps = {
|
|
368
|
-
...props.checkbox,
|
|
369
|
-
id,
|
|
370
|
-
invalid
|
|
371
|
-
};
|
|
372
|
-
if (mergedDescribedBy) {
|
|
373
|
-
checkboxProps.ariaDescribedBy = mergedDescribedBy;
|
|
374
|
-
}
|
|
375
|
-
return /* @__PURE__ */ jsxs("div", { className: wrapperClass, children: [
|
|
376
|
-
/* @__PURE__ */ jsxs("div", { className: "mw-checkbox-field__row", children: [
|
|
377
|
-
/* @__PURE__ */ jsx(Checkbox, { ...checkboxProps }),
|
|
378
|
-
/* @__PURE__ */ jsx("label", { className: "mw-checkbox-field__label", htmlFor: id, children: /* @__PURE__ */ jsx(Paragraph, { size: "md", children: props.label }) })
|
|
379
|
-
] }),
|
|
380
|
-
hasDescription && /* @__PURE__ */ jsx("div", { className: "mw-checkbox-field__description", id: descId, children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.description }) }),
|
|
381
|
-
hasError && /* @__PURE__ */ jsx("div", { className: "mw-checkbox-field__error", id: errorId, "aria-live": "polite", children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.error }) })
|
|
382
|
-
] });
|
|
383
|
-
}
|
|
384
|
-
function cx2(...parts) {
|
|
385
|
-
return parts.filter(Boolean).join(" ");
|
|
1211
|
+
function hasTextContent(value) {
|
|
1212
|
+
return value !== void 0 && value.trim().length > 0;
|
|
386
1213
|
}
|
|
387
1214
|
function InputField(props) {
|
|
388
|
-
const reactId =
|
|
1215
|
+
const reactId = React6.useId();
|
|
389
1216
|
const id = props.id ?? `mw-input-${reactId}`;
|
|
390
1217
|
const isPasswordField = props.input.type === "password";
|
|
391
|
-
const [showPassword, setShowPassword] =
|
|
1218
|
+
const [showPassword, setShowPassword] = React6.useState(false);
|
|
392
1219
|
const isSearchField = props.input.type === "search";
|
|
393
|
-
const [searchValue, setSearchValue] =
|
|
1220
|
+
const [searchValue, setSearchValue] = React6.useState(
|
|
394
1221
|
props.input.value || props.input.defaultValue || ""
|
|
395
1222
|
);
|
|
396
1223
|
const hasSearchValue = isSearchField && (props.input.value !== void 0 ? String(props.input.value).length > 0 : String(searchValue).length > 0);
|
|
397
|
-
const hasHelperText = props.helperText
|
|
398
|
-
const hasError = props.error
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
1224
|
+
const hasHelperText = hasTextContent(props.helperText);
|
|
1225
|
+
const hasError = hasTextContent(props.error);
|
|
1226
|
+
const {
|
|
1227
|
+
helperTextId,
|
|
1228
|
+
errorId,
|
|
1229
|
+
describedBy: mergedDescribedBy
|
|
1230
|
+
} = buildInputFieldA11yIds({
|
|
1231
|
+
id,
|
|
1232
|
+
hasHelperText,
|
|
1233
|
+
hasError,
|
|
1234
|
+
externalDescribedBy: props.ariaDescribedBy
|
|
1235
|
+
});
|
|
403
1236
|
const disabled = props.input.disabled || false;
|
|
404
1237
|
const readOnly = props.input.readOnly || false;
|
|
405
1238
|
const invalid = hasError || props.input.invalid || false;
|
|
406
|
-
const
|
|
1239
|
+
const showSearchClearButton = hasSearchValue && !disabled && !readOnly;
|
|
1240
|
+
const showSearchIcon = isSearchField && !showSearchClearButton;
|
|
1241
|
+
const wrapperClass = cx(
|
|
407
1242
|
"mw-input-field",
|
|
408
1243
|
disabled && "mw-input-field--disabled",
|
|
409
1244
|
invalid && "mw-input-field--invalid",
|
|
@@ -440,8 +1275,9 @@ function InputField(props) {
|
|
|
440
1275
|
return /* @__PURE__ */ jsxs("div", { className: wrapperClass, children: [
|
|
441
1276
|
/* @__PURE__ */ jsx("label", { className: "mw-input-field__label", htmlFor: id, children: /* @__PURE__ */ jsx(Paragraph, { size: "md", children: props.label }) }),
|
|
442
1277
|
/* @__PURE__ */ jsxs("div", { className: "mw-input-field__input-wrapper", children: [
|
|
1278
|
+
props.leadingSymbol && /* @__PURE__ */ jsx("span", { className: "mw-input-field__leading-symbol", "aria-hidden": "true", children: props.leadingSymbol }),
|
|
443
1279
|
/* @__PURE__ */ jsx(Input, { ...inputProps }),
|
|
444
|
-
isPasswordField && /* @__PURE__ */ jsx(
|
|
1280
|
+
isPasswordField && !disabled && /* @__PURE__ */ jsx(
|
|
445
1281
|
"button",
|
|
446
1282
|
{
|
|
447
1283
|
type: "button",
|
|
@@ -452,7 +1288,8 @@ function InputField(props) {
|
|
|
452
1288
|
children: /* @__PURE__ */ jsx(Icon, { name: showPassword ? "eyeOff" : "eye", size: "xs", decorative: true })
|
|
453
1289
|
}
|
|
454
1290
|
),
|
|
455
|
-
|
|
1291
|
+
showSearchIcon && /* @__PURE__ */ jsx("span", { className: "mw-input-field__search-icon", "aria-hidden": "true", children: /* @__PURE__ */ jsx(Icon, { name: "search", size: "xs", decorative: true }) }),
|
|
1292
|
+
showSearchClearButton && /* @__PURE__ */ jsx(
|
|
456
1293
|
"button",
|
|
457
1294
|
{
|
|
458
1295
|
type: "button",
|
|
@@ -468,61 +1305,2956 @@ function InputField(props) {
|
|
|
468
1305
|
hasError && /* @__PURE__ */ jsx("div", { className: "mw-input-field__error", id: errorId, "aria-live": "polite", children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.error }) })
|
|
469
1306
|
] });
|
|
470
1307
|
}
|
|
471
|
-
function
|
|
472
|
-
|
|
473
|
-
...props.input,
|
|
474
|
-
type: "search",
|
|
475
|
-
inputMode: "search"
|
|
476
|
-
};
|
|
477
|
-
return /* @__PURE__ */ jsx("div", { "data-purpose": "search", children: /* @__PURE__ */ jsx(InputField, { ...props, input: enhancedInput }) });
|
|
1308
|
+
function cx2(...parts) {
|
|
1309
|
+
return parts.filter(Boolean).join(" ");
|
|
478
1310
|
}
|
|
479
|
-
function
|
|
480
|
-
|
|
481
|
-
const enhancedInput = {
|
|
482
|
-
...props.input,
|
|
483
|
-
type: "password",
|
|
484
|
-
autoComplete
|
|
485
|
-
};
|
|
486
|
-
return /* @__PURE__ */ jsx("div", { "data-purpose": "password", children: /* @__PURE__ */ jsx(InputField, { ...restProps, input: enhancedInput }) });
|
|
1311
|
+
function hasTextContent2(value) {
|
|
1312
|
+
return value !== void 0 && value.trim().length > 0;
|
|
487
1313
|
}
|
|
488
|
-
function
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
1314
|
+
function InputOtp(props) {
|
|
1315
|
+
const reactId = React6.useId();
|
|
1316
|
+
const id = props.id ?? `mw-input-otp-${reactId}`;
|
|
1317
|
+
const otpLength = Math.max(1, props.length ?? 6);
|
|
1318
|
+
const hasHelperText = hasTextContent2(props.helperText);
|
|
1319
|
+
const hasError = hasTextContent2(props.error);
|
|
1320
|
+
const invalid = hasError || props.invalid === true;
|
|
1321
|
+
const isControlled = props.value !== void 0;
|
|
1322
|
+
const [uncontrolledValue, setUncontrolledValue] = React6.useState(() => {
|
|
1323
|
+
return sanitizeInputOtpValue(props.defaultValue, otpLength);
|
|
1324
|
+
});
|
|
1325
|
+
const currentValue = sanitizeInputOtpValue(
|
|
1326
|
+
isControlled ? props.value : uncontrolledValue,
|
|
1327
|
+
otpLength
|
|
1328
|
+
);
|
|
1329
|
+
const {
|
|
1330
|
+
helperTextId,
|
|
1331
|
+
errorId,
|
|
1332
|
+
describedBy: mergedDescribedBy
|
|
1333
|
+
} = buildInputFieldA11yIds({
|
|
1334
|
+
id,
|
|
1335
|
+
hasHelperText,
|
|
1336
|
+
hasError,
|
|
1337
|
+
externalDescribedBy: props.ariaDescribedBy
|
|
1338
|
+
});
|
|
1339
|
+
const recipeOptions = {
|
|
1340
|
+
id,
|
|
1341
|
+
value: currentValue,
|
|
1342
|
+
length: otpLength,
|
|
1343
|
+
invalid
|
|
494
1344
|
};
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
1345
|
+
if (props.name) {
|
|
1346
|
+
recipeOptions.name = props.name;
|
|
1347
|
+
}
|
|
1348
|
+
if (props.placeholderCharacter) {
|
|
1349
|
+
recipeOptions.placeholderCharacter = props.placeholderCharacter;
|
|
1350
|
+
}
|
|
1351
|
+
if (props.disabled) {
|
|
1352
|
+
recipeOptions.disabled = true;
|
|
1353
|
+
}
|
|
1354
|
+
if (props.readOnly) {
|
|
1355
|
+
recipeOptions.readOnly = true;
|
|
1356
|
+
}
|
|
1357
|
+
if (props.required) {
|
|
1358
|
+
recipeOptions.required = true;
|
|
1359
|
+
}
|
|
1360
|
+
if (mergedDescribedBy) {
|
|
1361
|
+
recipeOptions.describedBy = mergedDescribedBy;
|
|
1362
|
+
}
|
|
1363
|
+
if (props.ariaLabel) {
|
|
1364
|
+
recipeOptions.ariaLabel = props.ariaLabel;
|
|
1365
|
+
}
|
|
1366
|
+
const kit = createInputOtpRecipe(recipeOptions);
|
|
1367
|
+
const className = cx2(kit.className, props.className);
|
|
1368
|
+
const style = kit.vars;
|
|
1369
|
+
const handleChange = (event) => {
|
|
1370
|
+
const nextValue = sanitizeInputOtpValue(event.target.value, otpLength);
|
|
1371
|
+
if (!isControlled) {
|
|
1372
|
+
setUncontrolledValue(nextValue);
|
|
1373
|
+
}
|
|
1374
|
+
props.onValueChange?.(nextValue);
|
|
503
1375
|
};
|
|
504
|
-
return /* @__PURE__ */
|
|
1376
|
+
return /* @__PURE__ */ jsxs(
|
|
1377
|
+
"div",
|
|
1378
|
+
{
|
|
1379
|
+
className,
|
|
1380
|
+
style,
|
|
1381
|
+
"data-component": "input-otp",
|
|
1382
|
+
"data-invalid": invalid ? "true" : void 0,
|
|
1383
|
+
"data-disabled": props.disabled ? "true" : void 0,
|
|
1384
|
+
children: [
|
|
1385
|
+
/* @__PURE__ */ jsx("label", { className: "mw-input-otp__label", htmlFor: id, children: /* @__PURE__ */ jsx(Paragraph, { size: "md", children: props.label }) }),
|
|
1386
|
+
/* @__PURE__ */ jsxs("div", { className: "mw-input-otp__cells", children: [
|
|
1387
|
+
kit.displayCells.map((displayCell) => /* @__PURE__ */ jsx(
|
|
1388
|
+
"span",
|
|
1389
|
+
{
|
|
1390
|
+
className: cx2("mw-input-otp__cell", displayCell.filled && "mw-input-otp__cell--filled"),
|
|
1391
|
+
"aria-hidden": "true",
|
|
1392
|
+
children: displayCell.character
|
|
1393
|
+
},
|
|
1394
|
+
displayCell.key
|
|
1395
|
+
)),
|
|
1396
|
+
/* @__PURE__ */ jsx(
|
|
1397
|
+
"input",
|
|
1398
|
+
{
|
|
1399
|
+
id: kit.a11y.id,
|
|
1400
|
+
className: "mw-input-otp__input",
|
|
1401
|
+
type: "text",
|
|
1402
|
+
name: kit.a11y.name,
|
|
1403
|
+
inputMode: kit.a11y.inputMode,
|
|
1404
|
+
autoComplete: kit.a11y.autoComplete,
|
|
1405
|
+
maxLength: kit.a11y.maxLength,
|
|
1406
|
+
pattern: kit.a11y.pattern,
|
|
1407
|
+
disabled: kit.a11y.disabled,
|
|
1408
|
+
readOnly: kit.a11y.readOnly,
|
|
1409
|
+
required: kit.a11y.required,
|
|
1410
|
+
"aria-label": kit.a11y.ariaLabel,
|
|
1411
|
+
"aria-invalid": kit.a11y.ariaInvalid,
|
|
1412
|
+
"aria-describedby": kit.a11y.ariaDescribedBy,
|
|
1413
|
+
value: kit.displayValue,
|
|
1414
|
+
onChange: handleChange
|
|
1415
|
+
}
|
|
1416
|
+
)
|
|
1417
|
+
] }),
|
|
1418
|
+
hasError ? /* @__PURE__ */ jsx("div", { className: "mw-input-otp__error", id: errorId, "aria-live": "polite", children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.error }) }) : hasHelperText ? /* @__PURE__ */ jsx("div", { className: "mw-input-otp__helper", id: helperTextId, children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.helperText }) }) : null
|
|
1419
|
+
]
|
|
1420
|
+
}
|
|
1421
|
+
);
|
|
505
1422
|
}
|
|
506
|
-
function
|
|
507
|
-
|
|
508
|
-
...props.input,
|
|
509
|
-
type: "url",
|
|
510
|
-
inputMode: "url",
|
|
511
|
-
autoComplete: "url"
|
|
512
|
-
};
|
|
513
|
-
return /* @__PURE__ */ jsx("div", { "data-purpose": "url", children: /* @__PURE__ */ jsx(InputField, { ...props, input: enhancedInput }) });
|
|
1423
|
+
function cx3(...parts) {
|
|
1424
|
+
return parts.filter(Boolean).join(" ");
|
|
514
1425
|
}
|
|
515
|
-
function
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
|
|
1426
|
+
function hasTextContent3(value) {
|
|
1427
|
+
return value !== void 0 && value.trim().length > 0;
|
|
1428
|
+
}
|
|
1429
|
+
function getInitialSelectValue2(props) {
|
|
1430
|
+
if (props.value !== void 0) {
|
|
1431
|
+
return props.value;
|
|
1432
|
+
}
|
|
1433
|
+
if (props.defaultValue !== void 0) {
|
|
1434
|
+
return props.defaultValue;
|
|
1435
|
+
}
|
|
1436
|
+
if (props.placeholder !== void 0) {
|
|
1437
|
+
return "";
|
|
1438
|
+
}
|
|
1439
|
+
return props.options[0]?.value ?? "";
|
|
1440
|
+
}
|
|
1441
|
+
function getFirstEnabledOptionIndex(options) {
|
|
1442
|
+
return options.findIndex((option) => !option.disabled);
|
|
1443
|
+
}
|
|
1444
|
+
function getLastEnabledOptionIndex(options) {
|
|
1445
|
+
for (let index = options.length - 1; index >= 0; index -= 1) {
|
|
1446
|
+
if (!options[index]?.disabled) {
|
|
1447
|
+
return index;
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
return -1;
|
|
1451
|
+
}
|
|
1452
|
+
function getSelectedOptionIndex(options, value) {
|
|
1453
|
+
return options.findIndex((option) => option.value === value && !option.disabled);
|
|
1454
|
+
}
|
|
1455
|
+
function getInitialActiveOptionIndex(options, value) {
|
|
1456
|
+
const selectedIndex = getSelectedOptionIndex(options, value);
|
|
1457
|
+
if (selectedIndex !== -1) {
|
|
1458
|
+
return selectedIndex;
|
|
1459
|
+
}
|
|
1460
|
+
return getFirstEnabledOptionIndex(options);
|
|
1461
|
+
}
|
|
1462
|
+
function getNextEnabledOptionIndex(options, currentIndex, direction) {
|
|
1463
|
+
if (options.length === 0) {
|
|
1464
|
+
return -1;
|
|
1465
|
+
}
|
|
1466
|
+
let nextIndex = currentIndex;
|
|
1467
|
+
for (let attempts = 0; attempts < options.length; attempts += 1) {
|
|
1468
|
+
nextIndex = (nextIndex + direction + options.length) % options.length;
|
|
1469
|
+
if (!options[nextIndex]?.disabled) {
|
|
1470
|
+
return nextIndex;
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
return currentIndex;
|
|
1474
|
+
}
|
|
1475
|
+
function MarwesSelectFieldControl(props) {
|
|
1476
|
+
const { id, select } = props;
|
|
1477
|
+
const listboxId = `${id}-listbox`;
|
|
1478
|
+
const isControlled = select.value !== void 0;
|
|
1479
|
+
const [internalValue, setInternalValue] = React6.useState(() => getInitialSelectValue2(select));
|
|
1480
|
+
const value = isControlled ? select.value ?? "" : internalValue;
|
|
1481
|
+
const [open, setOpen] = React6.useState(false);
|
|
1482
|
+
const [activeIndex, setActiveIndex] = React6.useState(
|
|
1483
|
+
() => getInitialActiveOptionIndex(select.options, value)
|
|
1484
|
+
);
|
|
1485
|
+
const rootRef = React6.useRef(null);
|
|
1486
|
+
const buttonRef = React6.useRef(null);
|
|
1487
|
+
const selectedOption = select.options.find((option) => option.value === value) ?? (select.placeholder === void 0 ? select.options[0] : void 0);
|
|
1488
|
+
const placeholderSelected = select.placeholder !== void 0 && value === "";
|
|
1489
|
+
const displayText = placeholderSelected ? select.placeholder : selectedOption?.label ?? "";
|
|
1490
|
+
React6.useEffect(() => {
|
|
1491
|
+
if (!open) {
|
|
1492
|
+
return;
|
|
1493
|
+
}
|
|
1494
|
+
function handlePointerDown(event) {
|
|
1495
|
+
if (rootRef.current?.contains(event.target)) {
|
|
1496
|
+
return;
|
|
1497
|
+
}
|
|
1498
|
+
setOpen(false);
|
|
1499
|
+
}
|
|
1500
|
+
document.addEventListener("pointerdown", handlePointerDown);
|
|
1501
|
+
return () => {
|
|
1502
|
+
document.removeEventListener("pointerdown", handlePointerDown);
|
|
1503
|
+
};
|
|
1504
|
+
}, [open]);
|
|
1505
|
+
React6.useEffect(() => {
|
|
1506
|
+
if (!open) {
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
setActiveIndex(getInitialActiveOptionIndex(select.options, value));
|
|
1510
|
+
}, [open, select.options, value]);
|
|
1511
|
+
React6.useEffect(() => {
|
|
1512
|
+
if (!select.disabled) {
|
|
1513
|
+
return;
|
|
1514
|
+
}
|
|
1515
|
+
setOpen(false);
|
|
1516
|
+
}, [select.disabled]);
|
|
1517
|
+
const commitValue = (nextValue) => {
|
|
1518
|
+
if (!isControlled) {
|
|
1519
|
+
setInternalValue(nextValue);
|
|
1520
|
+
}
|
|
1521
|
+
select.onValueChange?.(nextValue);
|
|
1522
|
+
};
|
|
1523
|
+
const selectOptionAtIndex = (index) => {
|
|
1524
|
+
const option = select.options[index];
|
|
1525
|
+
if (!option || option.disabled) {
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
commitValue(option.value);
|
|
1529
|
+
setOpen(false);
|
|
1530
|
+
buttonRef.current?.focus();
|
|
1531
|
+
};
|
|
1532
|
+
const handleKeyDown = (event) => {
|
|
1533
|
+
if (select.disabled) {
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1536
|
+
switch (event.key) {
|
|
1537
|
+
case "ArrowDown": {
|
|
1538
|
+
event.preventDefault();
|
|
1539
|
+
if (!open) {
|
|
1540
|
+
setOpen(true);
|
|
1541
|
+
setActiveIndex(getInitialActiveOptionIndex(select.options, value));
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1544
|
+
setActiveIndex((currentIndex) => getNextEnabledOptionIndex(select.options, currentIndex, 1));
|
|
1545
|
+
return;
|
|
1546
|
+
}
|
|
1547
|
+
case "ArrowUp": {
|
|
1548
|
+
event.preventDefault();
|
|
1549
|
+
if (!open) {
|
|
1550
|
+
setOpen(true);
|
|
1551
|
+
setActiveIndex(getInitialActiveOptionIndex(select.options, value));
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
setActiveIndex(
|
|
1555
|
+
(currentIndex) => getNextEnabledOptionIndex(select.options, currentIndex, -1)
|
|
1556
|
+
);
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
case "Home": {
|
|
1560
|
+
if (!open) {
|
|
1561
|
+
return;
|
|
1562
|
+
}
|
|
1563
|
+
event.preventDefault();
|
|
1564
|
+
setActiveIndex(getFirstEnabledOptionIndex(select.options));
|
|
1565
|
+
return;
|
|
1566
|
+
}
|
|
1567
|
+
case "End": {
|
|
1568
|
+
if (!open) {
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
event.preventDefault();
|
|
1572
|
+
setActiveIndex(getLastEnabledOptionIndex(select.options));
|
|
1573
|
+
return;
|
|
1574
|
+
}
|
|
1575
|
+
case "Enter":
|
|
1576
|
+
case " ": {
|
|
1577
|
+
event.preventDefault();
|
|
1578
|
+
if (!open) {
|
|
1579
|
+
setOpen(true);
|
|
1580
|
+
setActiveIndex(getInitialActiveOptionIndex(select.options, value));
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
if (activeIndex !== -1) {
|
|
1584
|
+
selectOptionAtIndex(activeIndex);
|
|
1585
|
+
}
|
|
1586
|
+
return;
|
|
1587
|
+
}
|
|
1588
|
+
case "Escape": {
|
|
1589
|
+
if (!open) {
|
|
1590
|
+
return;
|
|
1591
|
+
}
|
|
1592
|
+
event.preventDefault();
|
|
1593
|
+
setOpen(false);
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
case "Tab": {
|
|
1597
|
+
setOpen(false);
|
|
1598
|
+
return;
|
|
1599
|
+
}
|
|
1600
|
+
default:
|
|
1601
|
+
return;
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1604
|
+
return /* @__PURE__ */ jsxs(
|
|
1605
|
+
"div",
|
|
1606
|
+
{
|
|
1607
|
+
ref: rootRef,
|
|
1608
|
+
className: cx3("mw-select-field__control", open && "mw-select-field__control--open"),
|
|
1609
|
+
children: [
|
|
1610
|
+
/* @__PURE__ */ jsxs(
|
|
1611
|
+
"button",
|
|
1612
|
+
{
|
|
1613
|
+
ref: buttonRef,
|
|
1614
|
+
id,
|
|
1615
|
+
type: "button",
|
|
1616
|
+
className: cx3(
|
|
1617
|
+
"mw-select-field__trigger",
|
|
1618
|
+
placeholderSelected && "mw-select-field__trigger--placeholder",
|
|
1619
|
+
select.invalid && "is-invalid",
|
|
1620
|
+
open && "mw-select-field__trigger--open"
|
|
1621
|
+
),
|
|
1622
|
+
role: "combobox",
|
|
1623
|
+
"aria-controls": listboxId,
|
|
1624
|
+
"aria-expanded": open,
|
|
1625
|
+
"aria-haspopup": "listbox",
|
|
1626
|
+
"aria-describedby": select.describedBy,
|
|
1627
|
+
"aria-invalid": select.invalid ? "true" : void 0,
|
|
1628
|
+
"aria-required": select.required ? "true" : void 0,
|
|
1629
|
+
"aria-activedescendant": open && activeIndex !== -1 ? `${id}-option-${activeIndex}` : void 0,
|
|
1630
|
+
disabled: select.disabled,
|
|
1631
|
+
"data-placeholder-selected": placeholderSelected ? "true" : void 0,
|
|
1632
|
+
onClick: () => {
|
|
1633
|
+
if (select.disabled) {
|
|
1634
|
+
return;
|
|
1635
|
+
}
|
|
1636
|
+
setOpen((currentOpen) => !currentOpen);
|
|
1637
|
+
},
|
|
1638
|
+
onKeyDown: handleKeyDown,
|
|
1639
|
+
children: [
|
|
1640
|
+
/* @__PURE__ */ jsx("span", { className: "mw-select-field__trigger-text", children: displayText }),
|
|
1641
|
+
/* @__PURE__ */ jsx(SelectArrowIcon, { className: "mw-select-field__trigger-icon" })
|
|
1642
|
+
]
|
|
1643
|
+
}
|
|
1644
|
+
),
|
|
1645
|
+
select.name ? /* @__PURE__ */ jsx(
|
|
1646
|
+
"input",
|
|
1647
|
+
{
|
|
1648
|
+
"aria-hidden": "true",
|
|
1649
|
+
className: "mw-select-field__proxy-input",
|
|
1650
|
+
name: select.name,
|
|
1651
|
+
type: "hidden",
|
|
1652
|
+
value,
|
|
1653
|
+
readOnly: true
|
|
1654
|
+
}
|
|
1655
|
+
) : null,
|
|
1656
|
+
open ? /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("div", { className: "mw-select-field__list", id: listboxId, role: "listbox", tabIndex: -1, children: select.options.map((option, optionIndex) => {
|
|
1657
|
+
const selected = option.value === value;
|
|
1658
|
+
const active = optionIndex === activeIndex;
|
|
1659
|
+
return /* @__PURE__ */ jsxs(
|
|
1660
|
+
"div",
|
|
1661
|
+
{
|
|
1662
|
+
id: `${id}-option-${optionIndex}`,
|
|
1663
|
+
className: cx3(
|
|
1664
|
+
"mw-select-field__option",
|
|
1665
|
+
active && "mw-select-field__option--active",
|
|
1666
|
+
selected && "mw-select-field__option--selected",
|
|
1667
|
+
option.disabled && "mw-select-field__option--disabled"
|
|
1668
|
+
),
|
|
1669
|
+
role: "option",
|
|
1670
|
+
"aria-selected": selected,
|
|
1671
|
+
"aria-disabled": option.disabled ? "true" : void 0,
|
|
1672
|
+
tabIndex: -1,
|
|
1673
|
+
onClick: () => selectOptionAtIndex(optionIndex),
|
|
1674
|
+
onKeyDown: (event) => {
|
|
1675
|
+
if (option.disabled) {
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1678
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
1679
|
+
event.preventDefault();
|
|
1680
|
+
selectOptionAtIndex(optionIndex);
|
|
1681
|
+
}
|
|
1682
|
+
},
|
|
1683
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
1684
|
+
onMouseEnter: () => {
|
|
1685
|
+
if (!option.disabled) {
|
|
1686
|
+
setActiveIndex(optionIndex);
|
|
1687
|
+
}
|
|
1688
|
+
},
|
|
1689
|
+
children: [
|
|
1690
|
+
/* @__PURE__ */ jsx("span", { className: "mw-select-field__option-label", children: option.label }),
|
|
1691
|
+
selected ? /* @__PURE__ */ jsx(
|
|
1692
|
+
Icon,
|
|
1693
|
+
{
|
|
1694
|
+
className: "mw-select-field__option-check",
|
|
1695
|
+
name: IconName.Check,
|
|
1696
|
+
size: "xs",
|
|
1697
|
+
decorative: true
|
|
1698
|
+
}
|
|
1699
|
+
) : null
|
|
1700
|
+
]
|
|
1701
|
+
},
|
|
1702
|
+
option.value
|
|
1703
|
+
);
|
|
1704
|
+
}) }) }) : null
|
|
1705
|
+
]
|
|
1706
|
+
}
|
|
1707
|
+
);
|
|
1708
|
+
}
|
|
1709
|
+
function SelectField(props) {
|
|
1710
|
+
const reactId = React6.useId();
|
|
1711
|
+
const id = props.id ?? `mw-select-${reactId}`;
|
|
1712
|
+
const mode = resolveSelectMode(props.select);
|
|
1713
|
+
const hasHelperText = hasTextContent3(props.helperText);
|
|
1714
|
+
const hasError = hasTextContent3(props.error);
|
|
1715
|
+
const {
|
|
1716
|
+
helperTextId,
|
|
1717
|
+
errorId,
|
|
1718
|
+
describedBy: mergedDescribedBy
|
|
1719
|
+
} = buildInputFieldA11yIds({
|
|
1720
|
+
id,
|
|
1721
|
+
hasHelperText,
|
|
1722
|
+
hasError,
|
|
1723
|
+
externalDescribedBy: props.ariaDescribedBy
|
|
1724
|
+
});
|
|
1725
|
+
const disabled = props.select.disabled || false;
|
|
1726
|
+
const invalid = hasError || props.select.invalid || false;
|
|
1727
|
+
const wrapperClass = cx3(
|
|
1728
|
+
"mw-input-field",
|
|
1729
|
+
"mw-input-field--select",
|
|
1730
|
+
mode === "marwes" && "mw-input-field--select-marwes",
|
|
1731
|
+
disabled && "mw-input-field--disabled",
|
|
1732
|
+
invalid && "mw-input-field--invalid"
|
|
1733
|
+
);
|
|
1734
|
+
const selectProps = {
|
|
1735
|
+
...props.select,
|
|
1736
|
+
id,
|
|
1737
|
+
invalid
|
|
1738
|
+
};
|
|
1739
|
+
if (mergedDescribedBy) {
|
|
1740
|
+
selectProps.describedBy = mergedDescribedBy;
|
|
1741
|
+
}
|
|
1742
|
+
return /* @__PURE__ */ jsxs("div", { className: wrapperClass, children: [
|
|
1743
|
+
/* @__PURE__ */ jsx("label", { className: "mw-input-field__label", htmlFor: id, children: /* @__PURE__ */ jsx(Paragraph, { size: "md", children: props.label }) }),
|
|
1744
|
+
/* @__PURE__ */ jsx("div", { className: "mw-input-field__input-wrapper", children: mode === "native" ? /* @__PURE__ */ jsx(Select, { ...selectProps, native: true }) : /* @__PURE__ */ jsx(MarwesSelectFieldControl, { id, select: selectProps }) }),
|
|
1745
|
+
hasHelperText && !hasError && /* @__PURE__ */ jsx("div", { className: "mw-input-field__helper", id: helperTextId, children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.helperText }) }),
|
|
1746
|
+
hasError && /* @__PURE__ */ jsx("div", { className: "mw-input-field__error", id: errorId, "aria-live": "polite", children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.error }) })
|
|
1747
|
+
] });
|
|
1748
|
+
}
|
|
1749
|
+
function cx4(...parts) {
|
|
1750
|
+
return parts.filter(Boolean).join(" ");
|
|
1751
|
+
}
|
|
1752
|
+
function hasTextContent4(value) {
|
|
1753
|
+
return value !== void 0 && value.trim().length > 0;
|
|
1754
|
+
}
|
|
1755
|
+
function TextareaField(props) {
|
|
1756
|
+
const reactId = React6.useId();
|
|
1757
|
+
const id = props.id ?? `mw-textarea-${reactId}`;
|
|
1758
|
+
const hasHelperText = hasTextContent4(props.helperText);
|
|
1759
|
+
const hasError = hasTextContent4(props.error);
|
|
1760
|
+
const {
|
|
1761
|
+
helperTextId,
|
|
1762
|
+
errorId,
|
|
1763
|
+
describedBy: mergedDescribedBy
|
|
1764
|
+
} = buildInputFieldA11yIds({
|
|
1765
|
+
id,
|
|
1766
|
+
hasHelperText,
|
|
1767
|
+
hasError,
|
|
1768
|
+
externalDescribedBy: props.ariaDescribedBy
|
|
1769
|
+
});
|
|
1770
|
+
const disabled = props.textarea.disabled || false;
|
|
1771
|
+
const readOnly = props.textarea.readOnly || false;
|
|
1772
|
+
const invalid = hasError || props.textarea.invalid || false;
|
|
1773
|
+
const wrapperClass = cx4(
|
|
1774
|
+
"mw-input-field",
|
|
1775
|
+
"mw-input-field--textarea",
|
|
1776
|
+
disabled && "mw-input-field--disabled",
|
|
1777
|
+
invalid && "mw-input-field--invalid",
|
|
1778
|
+
readOnly && "mw-input-field--readonly"
|
|
1779
|
+
);
|
|
1780
|
+
const textareaProps = {
|
|
1781
|
+
...props.textarea,
|
|
1782
|
+
id,
|
|
1783
|
+
invalid
|
|
1784
|
+
};
|
|
1785
|
+
if (mergedDescribedBy) {
|
|
1786
|
+
textareaProps.describedBy = mergedDescribedBy;
|
|
1787
|
+
}
|
|
1788
|
+
return /* @__PURE__ */ jsxs("div", { className: wrapperClass, children: [
|
|
1789
|
+
/* @__PURE__ */ jsx("label", { className: "mw-input-field__label", htmlFor: id, children: /* @__PURE__ */ jsx(Paragraph, { size: "md", children: props.label }) }),
|
|
1790
|
+
/* @__PURE__ */ jsx("div", { className: "mw-input-field__input-wrapper", children: /* @__PURE__ */ jsx(Textarea, { ...textareaProps }) }),
|
|
1791
|
+
hasHelperText && !hasError && /* @__PURE__ */ jsx("div", { className: "mw-input-field__helper", id: helperTextId, children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.helperText }) }),
|
|
1792
|
+
hasError && /* @__PURE__ */ jsx("div", { className: "mw-input-field__error", id: errorId, "aria-live": "polite", children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.error }) })
|
|
1793
|
+
] });
|
|
1794
|
+
}
|
|
1795
|
+
function cx5(...parts) {
|
|
1796
|
+
return parts.filter(Boolean).join(" ");
|
|
1797
|
+
}
|
|
1798
|
+
function hasTextContent5(value) {
|
|
1799
|
+
return value !== void 0 && value.trim().length > 0;
|
|
1800
|
+
}
|
|
1801
|
+
function RichTextField(props) {
|
|
1802
|
+
const reactId = React6.useId();
|
|
1803
|
+
const id = props.id ?? `mw-rich-text-${reactId}`;
|
|
1804
|
+
const editorRef = React6.useRef(null);
|
|
1805
|
+
const hasHelperText = hasTextContent5(props.helperText);
|
|
1806
|
+
const hasError = hasTextContent5(props.error);
|
|
1807
|
+
const { labelId, helperTextId, errorId, describedBy } = buildRichTextFieldA11yIds({
|
|
1808
|
+
id,
|
|
1809
|
+
hasHelperText,
|
|
1810
|
+
hasError,
|
|
1811
|
+
externalDescribedBy: props.ariaDescribedBy
|
|
1812
|
+
});
|
|
1813
|
+
const disabled = props.editor.disabled || false;
|
|
1814
|
+
const readOnly = props.editor.readOnly || false;
|
|
1815
|
+
const invalid = hasError || props.editor.invalid || false;
|
|
1816
|
+
const wrapperClass = cx5(
|
|
1817
|
+
"mw-input-field",
|
|
1818
|
+
"mw-input-field--rich-text",
|
|
1819
|
+
disabled && "mw-input-field--disabled",
|
|
1820
|
+
invalid && "mw-input-field--invalid",
|
|
1821
|
+
readOnly && "mw-input-field--readonly"
|
|
1822
|
+
);
|
|
1823
|
+
const editorProps = {
|
|
1824
|
+
...props.editor,
|
|
1825
|
+
id,
|
|
1826
|
+
invalid,
|
|
1827
|
+
labelledBy: labelId
|
|
1828
|
+
};
|
|
1829
|
+
if (describedBy) {
|
|
1830
|
+
editorProps.describedBy = describedBy;
|
|
1831
|
+
}
|
|
1832
|
+
return /* @__PURE__ */ jsxs("div", { className: wrapperClass, children: [
|
|
1833
|
+
/* @__PURE__ */ jsx(
|
|
1834
|
+
"button",
|
|
1835
|
+
{
|
|
1836
|
+
type: "button",
|
|
1837
|
+
className: "mw-input-field__label",
|
|
1838
|
+
id: labelId,
|
|
1839
|
+
onClick: () => {
|
|
1840
|
+
editorRef.current?.focus();
|
|
1841
|
+
},
|
|
1842
|
+
children: /* @__PURE__ */ jsx(Paragraph, { size: "md", children: props.label })
|
|
1843
|
+
}
|
|
1844
|
+
),
|
|
1845
|
+
/* @__PURE__ */ jsx("div", { className: "mw-input-field__input-wrapper", children: /* @__PURE__ */ jsx(RichText, { ref: editorRef, ...editorProps }) }),
|
|
1846
|
+
hasHelperText && !hasError && /* @__PURE__ */ jsx("div", { className: "mw-input-field__helper", id: helperTextId, children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.helperText }) }),
|
|
1847
|
+
hasError && /* @__PURE__ */ jsx("div", { className: "mw-input-field__error", id: errorId, "aria-live": "polite", children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.error }) })
|
|
1848
|
+
] });
|
|
1849
|
+
}
|
|
1850
|
+
function DropdownField(props) {
|
|
1851
|
+
return /* @__PURE__ */ jsx("div", { "data-purpose": "dropdown", children: /* @__PURE__ */ jsx(
|
|
1852
|
+
SelectField,
|
|
1853
|
+
{
|
|
1854
|
+
...props,
|
|
1855
|
+
select: {
|
|
1856
|
+
...props.select,
|
|
1857
|
+
native: props.select.native ?? false
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
) });
|
|
1861
|
+
}
|
|
1862
|
+
function SearchField(props) {
|
|
1863
|
+
const enhancedInput = {
|
|
1864
|
+
...props.input,
|
|
1865
|
+
type: "search",
|
|
1866
|
+
inputMode: "search"
|
|
1867
|
+
};
|
|
1868
|
+
return /* @__PURE__ */ jsx("div", { "data-purpose": "search", children: /* @__PURE__ */ jsx(InputField, { ...props, input: enhancedInput }) });
|
|
1869
|
+
}
|
|
1870
|
+
function PasswordField(props) {
|
|
1871
|
+
const { autoComplete = "current-password", ...restProps } = props;
|
|
1872
|
+
const enhancedInput = {
|
|
1873
|
+
...props.input,
|
|
1874
|
+
type: "password",
|
|
1875
|
+
autoComplete
|
|
1876
|
+
};
|
|
1877
|
+
return /* @__PURE__ */ jsx("div", { "data-purpose": "password", children: /* @__PURE__ */ jsx(InputField, { ...restProps, input: enhancedInput }) });
|
|
1878
|
+
}
|
|
1879
|
+
function EmailField(props) {
|
|
1880
|
+
const enhancedInput = {
|
|
1881
|
+
...props.input,
|
|
1882
|
+
type: "email",
|
|
1883
|
+
inputMode: "email",
|
|
1884
|
+
autoComplete: "email"
|
|
1885
|
+
};
|
|
1886
|
+
return /* @__PURE__ */ jsx("div", { "data-purpose": "email", children: /* @__PURE__ */ jsx(InputField, { ...props, input: enhancedInput }) });
|
|
1887
|
+
}
|
|
1888
|
+
function DateOfBirthField(props) {
|
|
1889
|
+
const enhancedInput = {
|
|
1890
|
+
...props.input,
|
|
1891
|
+
type: "date",
|
|
1892
|
+
autoComplete: "bday"
|
|
1893
|
+
};
|
|
1894
|
+
return /* @__PURE__ */ jsx("div", { "data-purpose": "date-of-birth", children: /* @__PURE__ */ jsx(InputField, { ...props, input: enhancedInput }) });
|
|
1895
|
+
}
|
|
1896
|
+
function ZipCodeField(props) {
|
|
1897
|
+
const enhancedInput = {
|
|
1898
|
+
...props.input,
|
|
1899
|
+
type: "text",
|
|
1900
|
+
inputMode: "numeric",
|
|
1901
|
+
autoComplete: "postal-code"
|
|
1902
|
+
};
|
|
1903
|
+
return /* @__PURE__ */ jsx("div", { "data-purpose": "zip-code", children: /* @__PURE__ */ jsx(InputField, { ...props, input: enhancedInput }) });
|
|
1904
|
+
}
|
|
1905
|
+
function PhoneField(props) {
|
|
1906
|
+
const enhancedInput = {
|
|
1907
|
+
...props.input,
|
|
1908
|
+
type: "tel",
|
|
1909
|
+
inputMode: "tel",
|
|
1910
|
+
autoComplete: "tel"
|
|
1911
|
+
};
|
|
1912
|
+
return /* @__PURE__ */ jsx("div", { "data-purpose": "phone", children: /* @__PURE__ */ jsx(InputField, { ...props, input: enhancedInput }) });
|
|
1913
|
+
}
|
|
1914
|
+
function URLField(props) {
|
|
1915
|
+
const enhancedInput = {
|
|
1916
|
+
...props.input,
|
|
1917
|
+
type: "url",
|
|
1918
|
+
inputMode: "url",
|
|
1919
|
+
autoComplete: "url"
|
|
1920
|
+
};
|
|
1921
|
+
return /* @__PURE__ */ jsx("div", { "data-purpose": "url", children: /* @__PURE__ */ jsx(InputField, { ...props, input: enhancedInput }) });
|
|
1922
|
+
}
|
|
1923
|
+
function CurrencyField(props) {
|
|
1924
|
+
const { currency, ...restProps } = props;
|
|
1925
|
+
const enhancedInput = {
|
|
1926
|
+
...props.input,
|
|
1927
|
+
type: "text",
|
|
1928
|
+
inputMode: "decimal",
|
|
1929
|
+
onValueChange: (rawValue) => {
|
|
1930
|
+
const sanitizedValue = sanitizeCurrencyValue(rawValue);
|
|
1931
|
+
props.input?.onValueChange?.(sanitizedValue);
|
|
1932
|
+
}
|
|
1933
|
+
};
|
|
1934
|
+
const helperText = buildCurrencyHelperText(props.helperText, currency);
|
|
1935
|
+
const leadingSymbol = getCurrencySymbol(currency);
|
|
1936
|
+
return /* @__PURE__ */ jsx("div", { "data-purpose": "currency", "data-currency": currency, children: /* @__PURE__ */ jsx(
|
|
1937
|
+
InputField,
|
|
1938
|
+
{
|
|
1939
|
+
...restProps,
|
|
1940
|
+
input: enhancedInput,
|
|
1941
|
+
helperText: helperText || "",
|
|
1942
|
+
...leadingSymbol ? { leadingSymbol } : {}
|
|
1943
|
+
}
|
|
1944
|
+
) });
|
|
1945
|
+
}
|
|
1946
|
+
function renderAvatarContent(content, isOuterShellAccessible, isDecorative) {
|
|
1947
|
+
if (content.type === "image") {
|
|
1948
|
+
return /* @__PURE__ */ jsx(
|
|
1949
|
+
"img",
|
|
1950
|
+
{
|
|
1951
|
+
className: "mw-avatar__image",
|
|
1952
|
+
src: content.src,
|
|
1953
|
+
alt: isDecorative ? "" : content.alt ?? ""
|
|
1954
|
+
}
|
|
1955
|
+
);
|
|
1956
|
+
}
|
|
1957
|
+
if (content.type === "initials") {
|
|
1958
|
+
return /* @__PURE__ */ jsx(
|
|
1959
|
+
"span",
|
|
1960
|
+
{
|
|
1961
|
+
"aria-hidden": isOuterShellAccessible ? "true" : void 0,
|
|
1962
|
+
className: "mw-avatar__initials",
|
|
1963
|
+
children: content.initials
|
|
1964
|
+
}
|
|
1965
|
+
);
|
|
1966
|
+
}
|
|
1967
|
+
return /* @__PURE__ */ jsx(Icon, { name: content.iconName ?? "user", className: "mw-avatar__icon", decorative: true });
|
|
1968
|
+
}
|
|
1969
|
+
function Avatar(props) {
|
|
1970
|
+
const {
|
|
1971
|
+
className,
|
|
1972
|
+
style,
|
|
1973
|
+
dataAttributes,
|
|
1974
|
+
size,
|
|
1975
|
+
type,
|
|
1976
|
+
initials,
|
|
1977
|
+
src,
|
|
1978
|
+
alt,
|
|
1979
|
+
iconName,
|
|
1980
|
+
decorative,
|
|
1981
|
+
ariaLabel,
|
|
1982
|
+
...nativeSpanProps
|
|
1983
|
+
} = props;
|
|
1984
|
+
const ariaLabelFromNativeProps = typeof nativeSpanProps["aria-label"] === "string" ? nativeSpanProps["aria-label"] : void 0;
|
|
1985
|
+
const avatarOptions = {};
|
|
1986
|
+
if (size !== void 0) avatarOptions.size = size;
|
|
1987
|
+
if (type !== void 0) avatarOptions.type = type;
|
|
1988
|
+
if (initials !== void 0) avatarOptions.initials = initials;
|
|
1989
|
+
if (src !== void 0) avatarOptions.src = src;
|
|
1990
|
+
if (alt !== void 0) avatarOptions.alt = alt;
|
|
1991
|
+
if (iconName !== void 0) avatarOptions.iconName = iconName;
|
|
1992
|
+
if (decorative !== void 0) avatarOptions.decorative = decorative;
|
|
1993
|
+
const resolvedAriaLabel = ariaLabel ?? ariaLabelFromNativeProps;
|
|
1994
|
+
if (resolvedAriaLabel !== void 0) {
|
|
1995
|
+
avatarOptions.ariaLabel = resolvedAriaLabel;
|
|
1996
|
+
}
|
|
1997
|
+
const kit = createAvatarRecipe(avatarOptions);
|
|
1998
|
+
const mergedClassName = [kit.className, className].filter(Boolean).join(" ");
|
|
1999
|
+
const mergedStyle = { ...kit.vars, ...style };
|
|
2000
|
+
const isOuterShellAccessible = kit.a11y.role === "img";
|
|
2001
|
+
const isDecorative = kit.a11y.ariaHidden === true;
|
|
2002
|
+
return /* @__PURE__ */ jsx(
|
|
2003
|
+
"span",
|
|
2004
|
+
{
|
|
2005
|
+
...nativeSpanProps,
|
|
2006
|
+
...kit.dataAttributes,
|
|
2007
|
+
...dataAttributes,
|
|
2008
|
+
className: mergedClassName,
|
|
2009
|
+
style: mergedStyle,
|
|
2010
|
+
role: kit.a11y.role,
|
|
2011
|
+
"aria-hidden": isDecorative ? "true" : void 0,
|
|
2012
|
+
"aria-label": kit.a11y.ariaLabel,
|
|
2013
|
+
children: renderAvatarContent(kit.content, isOuterShellAccessible, isDecorative)
|
|
2014
|
+
}
|
|
2015
|
+
);
|
|
2016
|
+
}
|
|
2017
|
+
function buildAvatarOptions(props) {
|
|
2018
|
+
const avatarOptions = {};
|
|
2019
|
+
if (props.size !== void 0) avatarOptions.size = props.size;
|
|
2020
|
+
if (props.type !== void 0) avatarOptions.type = props.type;
|
|
2021
|
+
if (props.initials !== void 0) avatarOptions.initials = props.initials;
|
|
2022
|
+
if (props.src !== void 0) avatarOptions.src = props.src;
|
|
2023
|
+
if (props.alt !== void 0) avatarOptions.alt = props.alt;
|
|
2024
|
+
if (props.iconName !== void 0) avatarOptions.iconName = props.iconName;
|
|
2025
|
+
if (props.decorative !== void 0) avatarOptions.decorative = props.decorative;
|
|
2026
|
+
const nativeAriaLabel = typeof props["aria-label"] === "string" ? props["aria-label"] : void 0;
|
|
2027
|
+
const resolvedAriaLabel = props.ariaLabel ?? nativeAriaLabel;
|
|
2028
|
+
if (resolvedAriaLabel !== void 0) {
|
|
2029
|
+
avatarOptions.ariaLabel = resolvedAriaLabel;
|
|
2030
|
+
}
|
|
2031
|
+
return avatarOptions;
|
|
2032
|
+
}
|
|
2033
|
+
function resolveAvatarBadgeLabel(avatarOptions, statusLabel) {
|
|
2034
|
+
const avatarKit = createAvatarRecipe(avatarOptions);
|
|
2035
|
+
if (avatarKit.a11y.ariaHidden) {
|
|
2036
|
+
return void 0;
|
|
2037
|
+
}
|
|
2038
|
+
if (avatarKit.content.type === "image") {
|
|
2039
|
+
return avatarKit.content.alt ? `${avatarKit.content.alt}, ${statusLabel}` : statusLabel;
|
|
2040
|
+
}
|
|
2041
|
+
return avatarKit.a11y.ariaLabel ? `${avatarKit.a11y.ariaLabel}, ${statusLabel}` : statusLabel;
|
|
2042
|
+
}
|
|
2043
|
+
function AvatarBadge(props) {
|
|
2044
|
+
const {
|
|
2045
|
+
className,
|
|
2046
|
+
dataAttributes,
|
|
2047
|
+
statusLabel = "Online",
|
|
2048
|
+
decorative,
|
|
2049
|
+
style,
|
|
2050
|
+
size,
|
|
2051
|
+
type,
|
|
2052
|
+
initials,
|
|
2053
|
+
src,
|
|
2054
|
+
alt,
|
|
2055
|
+
iconName,
|
|
2056
|
+
ariaLabel,
|
|
2057
|
+
...nativeSpanProps
|
|
2058
|
+
} = props;
|
|
2059
|
+
const avatarOptions = buildAvatarOptions(props);
|
|
2060
|
+
const avatarKit = createAvatarRecipe(avatarOptions);
|
|
2061
|
+
const accessibleLabel = resolveAvatarBadgeLabel(avatarOptions, statusLabel);
|
|
2062
|
+
const resolvedSize = avatarKit.dataAttributes["data-size"];
|
|
2063
|
+
const mergedClassName = ["mw-avatar-badge", `mw-avatar-badge--${resolvedSize}`, className].filter(Boolean).join(" ");
|
|
2064
|
+
const innerAvatarProps = { decorative: true };
|
|
2065
|
+
if (size !== void 0) innerAvatarProps.size = size;
|
|
2066
|
+
if (type !== void 0) innerAvatarProps.type = type;
|
|
2067
|
+
if (initials !== void 0) innerAvatarProps.initials = initials;
|
|
2068
|
+
if (src !== void 0) innerAvatarProps.src = src;
|
|
2069
|
+
if (alt !== void 0) innerAvatarProps.alt = alt;
|
|
2070
|
+
if (iconName !== void 0) innerAvatarProps.iconName = iconName;
|
|
2071
|
+
if (ariaLabel !== void 0) innerAvatarProps.ariaLabel = ariaLabel;
|
|
2072
|
+
return /* @__PURE__ */ jsxs(
|
|
2073
|
+
"span",
|
|
2074
|
+
{
|
|
2075
|
+
...nativeSpanProps,
|
|
2076
|
+
...dataAttributes,
|
|
2077
|
+
className: mergedClassName,
|
|
2078
|
+
style,
|
|
2079
|
+
"data-component": "avatar-badge",
|
|
2080
|
+
"data-size": resolvedSize,
|
|
2081
|
+
"data-status": "online",
|
|
2082
|
+
role: decorative ? void 0 : "img",
|
|
2083
|
+
"aria-hidden": decorative ? "true" : void 0,
|
|
2084
|
+
"aria-label": decorative ? void 0 : accessibleLabel,
|
|
2085
|
+
children: [
|
|
2086
|
+
/* @__PURE__ */ jsx(Avatar, { ...innerAvatarProps }),
|
|
2087
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "mw-avatar-badge__indicator" })
|
|
2088
|
+
]
|
|
2089
|
+
}
|
|
2090
|
+
);
|
|
2091
|
+
}
|
|
2092
|
+
function AvatarGroup(props) {
|
|
2093
|
+
const {
|
|
2094
|
+
items,
|
|
2095
|
+
overflowCount,
|
|
2096
|
+
overflowLabel,
|
|
2097
|
+
ariaLabel,
|
|
2098
|
+
className,
|
|
2099
|
+
dataAttributes,
|
|
2100
|
+
...nativeFieldsetProps
|
|
2101
|
+
} = props;
|
|
2102
|
+
const nativeAriaLabel = typeof nativeFieldsetProps["aria-label"] === "string" ? nativeFieldsetProps["aria-label"] : void 0;
|
|
2103
|
+
const groupLabel = ariaLabel ?? nativeAriaLabel ?? "Avatar group";
|
|
2104
|
+
const mergedClassName = ["mw-avatar-group", className].filter(Boolean).join(" ");
|
|
2105
|
+
const shouldRenderOverflowCounter = overflowCount !== void 0 && overflowCount > 0;
|
|
2106
|
+
const resolvedOverflowLabel = overflowLabel ?? `${overflowCount} more people`;
|
|
2107
|
+
return /* @__PURE__ */ jsxs(
|
|
2108
|
+
"fieldset",
|
|
2109
|
+
{
|
|
2110
|
+
...nativeFieldsetProps,
|
|
2111
|
+
...dataAttributes,
|
|
2112
|
+
className: mergedClassName,
|
|
2113
|
+
"data-component": "avatar-group",
|
|
2114
|
+
"aria-label": groupLabel,
|
|
2115
|
+
children: [
|
|
2116
|
+
items.map((item, itemIndex) => /* @__PURE__ */ jsx(
|
|
2117
|
+
"span",
|
|
2118
|
+
{
|
|
2119
|
+
className: "mw-avatar-group__item",
|
|
2120
|
+
children: /* @__PURE__ */ jsx(Avatar, { ...item, size: "medium" })
|
|
2121
|
+
},
|
|
2122
|
+
item.id ?? `${itemIndex}-${item.initials ?? item.alt ?? "avatar"}`
|
|
2123
|
+
)),
|
|
2124
|
+
shouldRenderOverflowCounter ? /* @__PURE__ */ jsxs("span", { "aria-label": resolvedOverflowLabel, className: "mw-avatar-group__counter", role: "img", children: [
|
|
2125
|
+
"+",
|
|
2126
|
+
overflowCount
|
|
2127
|
+
] }) : null
|
|
2128
|
+
]
|
|
2129
|
+
}
|
|
2130
|
+
);
|
|
2131
|
+
}
|
|
2132
|
+
function ProfileAvatar(props) {
|
|
2133
|
+
return /* @__PURE__ */ jsx(
|
|
2134
|
+
Avatar,
|
|
2135
|
+
{
|
|
2136
|
+
...props,
|
|
2137
|
+
dataAttributes: {
|
|
2138
|
+
...props.dataAttributes,
|
|
2139
|
+
...createPurposeSemanticAttributes("profile")
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
);
|
|
2143
|
+
}
|
|
2144
|
+
function PresenceAvatar(props) {
|
|
2145
|
+
return /* @__PURE__ */ jsx(
|
|
2146
|
+
AvatarBadge,
|
|
2147
|
+
{
|
|
2148
|
+
...props,
|
|
2149
|
+
dataAttributes: {
|
|
2150
|
+
...props.dataAttributes,
|
|
2151
|
+
...createPurposeSemanticAttributes("presence")
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
);
|
|
2155
|
+
}
|
|
2156
|
+
function TeamAvatarGroup(props) {
|
|
2157
|
+
return /* @__PURE__ */ jsx(
|
|
2158
|
+
AvatarGroup,
|
|
2159
|
+
{
|
|
2160
|
+
...props,
|
|
2161
|
+
dataAttributes: {
|
|
2162
|
+
...props.dataAttributes,
|
|
2163
|
+
...createPurposeSemanticAttributes("team")
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
);
|
|
2167
|
+
}
|
|
2168
|
+
function Checkbox(props) {
|
|
2169
|
+
const { onCheckedChange, onChange, ...coreProps } = props;
|
|
2170
|
+
const kit = checkboxRecipe({ ...coreProps });
|
|
2171
|
+
const inputRef = React6.useRef(null);
|
|
2172
|
+
React6.useLayoutEffect(() => {
|
|
2173
|
+
const el = inputRef.current;
|
|
2174
|
+
if (!el) return;
|
|
2175
|
+
el.indeterminate = kit.indeterminate;
|
|
2176
|
+
}, [kit.indeterminate]);
|
|
2177
|
+
const handleChange = (e) => {
|
|
2178
|
+
onChange?.(e);
|
|
2179
|
+
onCheckedChange?.(e.currentTarget.checked);
|
|
2180
|
+
};
|
|
2181
|
+
const { a11y } = kit;
|
|
2182
|
+
return /* @__PURE__ */ jsx(
|
|
2183
|
+
"input",
|
|
2184
|
+
{
|
|
2185
|
+
ref: inputRef,
|
|
2186
|
+
type: "checkbox",
|
|
2187
|
+
className: kit.className,
|
|
2188
|
+
style: kit.vars,
|
|
2189
|
+
id: a11y.id,
|
|
2190
|
+
name: a11y.name,
|
|
2191
|
+
value: a11y.value,
|
|
2192
|
+
disabled: a11y.disabled === true,
|
|
2193
|
+
required: a11y.required === true,
|
|
2194
|
+
"aria-label": a11y.ariaLabel,
|
|
2195
|
+
"aria-labelledby": a11y.ariaLabelledBy,
|
|
2196
|
+
"aria-describedby": a11y.ariaDescribedBy,
|
|
2197
|
+
"aria-checked": a11y.ariaChecked,
|
|
2198
|
+
"aria-invalid": a11y.ariaInvalid === true ? true : void 0,
|
|
2199
|
+
checked: kit.checked,
|
|
2200
|
+
defaultChecked: kit.defaultChecked,
|
|
2201
|
+
onChange: handleChange
|
|
2202
|
+
}
|
|
2203
|
+
);
|
|
2204
|
+
}
|
|
2205
|
+
function cx6(...parts) {
|
|
2206
|
+
return parts.filter(Boolean).join(" ");
|
|
2207
|
+
}
|
|
2208
|
+
function hasContent(value) {
|
|
2209
|
+
if (value === void 0 || value === null || value === false) {
|
|
2210
|
+
return false;
|
|
2211
|
+
}
|
|
2212
|
+
if (typeof value === "string") {
|
|
2213
|
+
return value.trim().length > 0;
|
|
2214
|
+
}
|
|
2215
|
+
return true;
|
|
2216
|
+
}
|
|
2217
|
+
function CheckboxField(props) {
|
|
2218
|
+
const reactId = React6.useId();
|
|
2219
|
+
const id = props.id ?? `mw-checkbox-${reactId}`;
|
|
2220
|
+
const hasDescription = hasContent(props.description);
|
|
2221
|
+
const hasError = hasContent(props.error);
|
|
2222
|
+
const {
|
|
2223
|
+
descriptionId: descId,
|
|
2224
|
+
errorId,
|
|
2225
|
+
describedBy: mergedDescribedBy
|
|
2226
|
+
} = buildCheckboxFieldA11yIds({
|
|
2227
|
+
id,
|
|
2228
|
+
hasDescription,
|
|
2229
|
+
hasError,
|
|
2230
|
+
externalDescribedBy: props.ariaDescribedBy
|
|
2231
|
+
});
|
|
2232
|
+
const disabled = props.checkbox.disabled || false;
|
|
2233
|
+
const invalid = hasError || props.checkbox.invalid || false;
|
|
2234
|
+
const wrapperClass = cx6(
|
|
2235
|
+
"mw-checkbox-field",
|
|
2236
|
+
disabled && "mw-checkbox-field--disabled",
|
|
2237
|
+
invalid && "mw-checkbox-field--invalid"
|
|
2238
|
+
);
|
|
2239
|
+
const checkboxProps = {
|
|
2240
|
+
...props.checkbox,
|
|
2241
|
+
id,
|
|
2242
|
+
invalid
|
|
2243
|
+
};
|
|
2244
|
+
if (mergedDescribedBy) {
|
|
2245
|
+
checkboxProps.ariaDescribedBy = mergedDescribedBy;
|
|
2246
|
+
}
|
|
2247
|
+
return /* @__PURE__ */ jsxs("div", { className: wrapperClass, children: [
|
|
2248
|
+
/* @__PURE__ */ jsxs("div", { className: "mw-checkbox-field__row", children: [
|
|
2249
|
+
/* @__PURE__ */ jsx(Checkbox, { ...checkboxProps }),
|
|
2250
|
+
/* @__PURE__ */ jsx("label", { className: "mw-checkbox-field__label", htmlFor: id, children: /* @__PURE__ */ jsx(Paragraph, { size: "md", children: props.label }) })
|
|
2251
|
+
] }),
|
|
2252
|
+
hasDescription && /* @__PURE__ */ jsx("div", { className: "mw-checkbox-field__description", id: descId, children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.description }) }),
|
|
2253
|
+
hasError && /* @__PURE__ */ jsx("div", { className: "mw-checkbox-field__error", id: errorId, "aria-live": "polite", children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.error }) })
|
|
2254
|
+
] });
|
|
2255
|
+
}
|
|
2256
|
+
function hasContent2(value) {
|
|
2257
|
+
if (value === void 0 || value === null || value === false) return false;
|
|
2258
|
+
if (typeof value === "string") return value.trim().length > 0;
|
|
2259
|
+
return true;
|
|
2260
|
+
}
|
|
2261
|
+
function cx7(...parts) {
|
|
2262
|
+
return parts.filter(Boolean).join(" ");
|
|
2263
|
+
}
|
|
2264
|
+
function orderSelectedValues(values, options) {
|
|
2265
|
+
const optionValues = new Set(options.map((option) => option.value));
|
|
2266
|
+
const selectedValues = new Set(values);
|
|
2267
|
+
const knownValues = options.map((option) => option.value).filter((value) => selectedValues.has(value));
|
|
2268
|
+
const unknownValues = values.filter((value) => !optionValues.has(value));
|
|
2269
|
+
return [...knownValues, ...unknownValues];
|
|
2270
|
+
}
|
|
2271
|
+
function CheckboxGroupField(props) {
|
|
2272
|
+
const reactId = React6.useId();
|
|
2273
|
+
const id = props.id ?? `mw-checkbox-group-${reactId}`;
|
|
2274
|
+
const hasDescription = hasContent2(props.description);
|
|
2275
|
+
const hasError = hasContent2(props.error);
|
|
2276
|
+
const isInvalid = hasError;
|
|
2277
|
+
const { labelId, descriptionId, errorId, describedBy } = buildCheckboxGroupFieldA11yIds({
|
|
2278
|
+
id,
|
|
2279
|
+
hasDescription,
|
|
2280
|
+
hasError,
|
|
2281
|
+
externalDescribedBy: props.ariaDescribedBy
|
|
2282
|
+
});
|
|
2283
|
+
const isControlled = props.value !== void 0;
|
|
2284
|
+
const [internalValue, setInternalValue] = React6.useState(
|
|
2285
|
+
orderSelectedValues(props.defaultValue ?? [], props.options)
|
|
2286
|
+
);
|
|
2287
|
+
const selectedValues = orderSelectedValues(
|
|
2288
|
+
isControlled ? props.value ?? [] : internalValue,
|
|
2289
|
+
props.options
|
|
2290
|
+
);
|
|
2291
|
+
const selectedValueSet = new Set(selectedValues);
|
|
2292
|
+
const handleToggle = (nextValue) => {
|
|
2293
|
+
const rawNextValue = selectedValueSet.has(nextValue) ? selectedValues.filter((value) => value !== nextValue) : [...selectedValues, nextValue];
|
|
2294
|
+
const orderedNextValue = orderSelectedValues(rawNextValue, props.options);
|
|
2295
|
+
if (!isControlled) {
|
|
2296
|
+
setInternalValue(orderedNextValue);
|
|
2297
|
+
}
|
|
2298
|
+
props.onChange?.(orderedNextValue);
|
|
2299
|
+
};
|
|
2300
|
+
const wrapperClass = cx7(
|
|
2301
|
+
"mw-checkbox-group-field",
|
|
2302
|
+
props.disabled && "mw-checkbox-group-field--disabled",
|
|
2303
|
+
isInvalid && "mw-checkbox-group-field--invalid"
|
|
2304
|
+
);
|
|
2305
|
+
return /* @__PURE__ */ jsxs(
|
|
2306
|
+
"fieldset",
|
|
2307
|
+
{
|
|
2308
|
+
className: wrapperClass,
|
|
2309
|
+
"aria-labelledby": labelId,
|
|
2310
|
+
"aria-describedby": describedBy,
|
|
2311
|
+
"aria-invalid": isInvalid ? true : void 0,
|
|
2312
|
+
"aria-required": props.required ? true : void 0,
|
|
2313
|
+
disabled: props.disabled ? true : void 0,
|
|
2314
|
+
...props.dataAttributes,
|
|
2315
|
+
children: [
|
|
2316
|
+
/* @__PURE__ */ jsx("legend", { className: "mw-checkbox-group-field__label", id: labelId, children: /* @__PURE__ */ jsx(Paragraph, { size: "md", children: props.label }) }),
|
|
2317
|
+
hasDescription && /* @__PURE__ */ jsx("div", { className: "mw-checkbox-group-field__description", id: descriptionId, children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.description }) }),
|
|
2318
|
+
/* @__PURE__ */ jsx("div", { className: "mw-checkbox-group-field__options", children: props.options.map((option, index) => {
|
|
2319
|
+
const optionId = `${id}-option-${index}`;
|
|
2320
|
+
const isOptionDisabled = props.disabled || option.disabled || false;
|
|
2321
|
+
const checkboxProps = {
|
|
2322
|
+
...props.checkbox ?? {},
|
|
2323
|
+
id: optionId,
|
|
2324
|
+
value: option.value,
|
|
2325
|
+
checked: selectedValueSet.has(option.value),
|
|
2326
|
+
disabled: isOptionDisabled,
|
|
2327
|
+
invalid: isInvalid,
|
|
2328
|
+
onCheckedChange: () => handleToggle(option.value)
|
|
2329
|
+
};
|
|
2330
|
+
if (props.name !== void 0) {
|
|
2331
|
+
checkboxProps.name = props.name;
|
|
2332
|
+
}
|
|
2333
|
+
if (option.indeterminate !== void 0) {
|
|
2334
|
+
checkboxProps.indeterminate = option.indeterminate;
|
|
2335
|
+
}
|
|
2336
|
+
return /* @__PURE__ */ jsxs(
|
|
2337
|
+
"label",
|
|
2338
|
+
{
|
|
2339
|
+
className: "mw-checkbox-group-field__option",
|
|
2340
|
+
htmlFor: optionId,
|
|
2341
|
+
children: [
|
|
2342
|
+
/* @__PURE__ */ jsx(Checkbox, { ...checkboxProps }),
|
|
2343
|
+
/* @__PURE__ */ jsx(Paragraph, { size: "md", children: option.label })
|
|
2344
|
+
]
|
|
2345
|
+
},
|
|
2346
|
+
option.value
|
|
2347
|
+
);
|
|
2348
|
+
}) }),
|
|
2349
|
+
hasError && /* @__PURE__ */ jsx("div", { className: "mw-checkbox-group-field__error", id: errorId, "aria-live": "polite", children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.error }) })
|
|
2350
|
+
]
|
|
2351
|
+
}
|
|
2352
|
+
);
|
|
2353
|
+
}
|
|
2354
|
+
var Divider = React6.forwardRef((props, ref) => {
|
|
2355
|
+
const { className: customClassName, style: customStyle, ...opts } = props;
|
|
2356
|
+
const kit = createDividerRecipe(opts);
|
|
2357
|
+
const style = { ...kit.vars, ...customStyle };
|
|
2358
|
+
const className = customClassName ? `${kit.className} ${customClassName}` : kit.className;
|
|
2359
|
+
return /* @__PURE__ */ jsx("hr", { ref, ...kit.a11y, ...kit.dataAttributes, className, style });
|
|
2360
|
+
});
|
|
2361
|
+
Divider.displayName = "Divider";
|
|
2362
|
+
var Spacing = React6.forwardRef((props, ref) => {
|
|
2363
|
+
const { className: customClassName, scale, size, spacing, style: customStyle } = props;
|
|
2364
|
+
const resolvedSize = spacing ?? size;
|
|
2365
|
+
const kit = createSpacingRecipe({
|
|
2366
|
+
...resolvedSize !== void 0 ? { size: resolvedSize } : {},
|
|
2367
|
+
...scale !== void 0 ? { scale } : {}
|
|
2368
|
+
});
|
|
2369
|
+
const style = { ...kit.vars, ...customStyle };
|
|
2370
|
+
const className = customClassName ? `${kit.className} ${customClassName}` : kit.className;
|
|
2371
|
+
return /* @__PURE__ */ jsx("div", { ref, ...kit.a11y, ...kit.dataAttributes, className, style });
|
|
2372
|
+
});
|
|
2373
|
+
Spacing.displayName = "Spacing";
|
|
2374
|
+
var Spacer = Spacing;
|
|
2375
|
+
function H1(props) {
|
|
2376
|
+
const { children, className: customClassName, style: customStyle, ...opts } = props;
|
|
2377
|
+
const theme = useTheme();
|
|
2378
|
+
const kit = headingRecipe({ ...opts, level: 1 }, theme);
|
|
2379
|
+
const style = { ...kit.vars, ...customStyle };
|
|
2380
|
+
const className = customClassName ? `${kit.className} ${customClassName}` : kit.className;
|
|
2381
|
+
return /* @__PURE__ */ jsx("h1", { id: kit.a11y.id, "aria-label": kit.a11y.ariaLabel, className, style, children });
|
|
2382
|
+
}
|
|
2383
|
+
function H2(props) {
|
|
2384
|
+
const { children, className: customClassName, style: customStyle, ...opts } = props;
|
|
2385
|
+
const theme = useTheme();
|
|
2386
|
+
const kit = headingRecipe({ ...opts, level: 2 }, theme);
|
|
2387
|
+
const style = { ...kit.vars, ...customStyle };
|
|
2388
|
+
const className = customClassName ? `${kit.className} ${customClassName}` : kit.className;
|
|
2389
|
+
return /* @__PURE__ */ jsx("h2", { id: kit.a11y.id, "aria-label": kit.a11y.ariaLabel, className, style, children });
|
|
2390
|
+
}
|
|
2391
|
+
function H3(props) {
|
|
2392
|
+
const { children, className: customClassName, style: customStyle, ...opts } = props;
|
|
2393
|
+
const theme = useTheme();
|
|
2394
|
+
const kit = headingRecipe({ ...opts, level: 3 }, theme);
|
|
2395
|
+
const style = { ...kit.vars, ...customStyle };
|
|
2396
|
+
const className = customClassName ? `${kit.className} ${customClassName}` : kit.className;
|
|
2397
|
+
return /* @__PURE__ */ jsx("h3", { id: kit.a11y.id, "aria-label": kit.a11y.ariaLabel, className, style, children });
|
|
2398
|
+
}
|
|
2399
|
+
function Card(props) {
|
|
2400
|
+
const { title, children, className, dataAttributes, ...nativeDivProps } = props;
|
|
2401
|
+
const kit = createCardRecipe(dataAttributes ? { dataAttributes } : {});
|
|
2402
|
+
return /* @__PURE__ */ jsxs(
|
|
2403
|
+
"div",
|
|
2404
|
+
{
|
|
2405
|
+
...nativeDivProps,
|
|
2406
|
+
...kit.dataAttributes,
|
|
2407
|
+
className: [kit.className, className].filter(Boolean).join(" "),
|
|
2408
|
+
children: [
|
|
2409
|
+
title ? /* @__PURE__ */ jsx("div", { className: "mw-card__header", children: /* @__PURE__ */ jsx("span", { className: "mw-card__title", children: title }) }) : null,
|
|
2410
|
+
/* @__PURE__ */ jsx("div", { className: "mw-card__body", children })
|
|
2411
|
+
]
|
|
2412
|
+
}
|
|
2413
|
+
);
|
|
2414
|
+
}
|
|
2415
|
+
function ProductCard(props) {
|
|
2416
|
+
return /* @__PURE__ */ jsx(
|
|
2417
|
+
Card,
|
|
2418
|
+
{
|
|
2419
|
+
...props,
|
|
2420
|
+
dataAttributes: {
|
|
2421
|
+
...props.dataAttributes,
|
|
2422
|
+
"data-purpose": "product-card"
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
);
|
|
2426
|
+
}
|
|
2427
|
+
function ProfileCard(props) {
|
|
2428
|
+
return /* @__PURE__ */ jsx(
|
|
2429
|
+
Card,
|
|
2430
|
+
{
|
|
2431
|
+
...props,
|
|
2432
|
+
dataAttributes: {
|
|
2433
|
+
...props.dataAttributes,
|
|
2434
|
+
"data-purpose": "profile-card"
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
);
|
|
2438
|
+
}
|
|
2439
|
+
function StatCard(props) {
|
|
2440
|
+
return /* @__PURE__ */ jsx(
|
|
2441
|
+
Card,
|
|
2442
|
+
{
|
|
2443
|
+
...props,
|
|
2444
|
+
dataAttributes: {
|
|
2445
|
+
...props.dataAttributes,
|
|
2446
|
+
"data-purpose": "stat-card"
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
);
|
|
2450
|
+
}
|
|
2451
|
+
function cx8(...parts) {
|
|
2452
|
+
return parts.filter(Boolean).join(" ");
|
|
2453
|
+
}
|
|
2454
|
+
function Toast(props) {
|
|
2455
|
+
const { children, icon, action, onDismiss, className, id, dataAttributes, ...coreProps } = props;
|
|
2456
|
+
const kit = createToastRecipe(coreProps);
|
|
2457
|
+
const { a11y } = kit;
|
|
2458
|
+
return /* @__PURE__ */ jsxs(
|
|
2459
|
+
"div",
|
|
2460
|
+
{
|
|
2461
|
+
id,
|
|
2462
|
+
className: cx8(kit.className, className),
|
|
2463
|
+
role: a11y.role,
|
|
2464
|
+
"aria-live": a11y.ariaLive,
|
|
2465
|
+
"aria-atomic": "true",
|
|
2466
|
+
...kit.dataAttributes,
|
|
2467
|
+
...dataAttributes,
|
|
2468
|
+
children: [
|
|
2469
|
+
icon && /* @__PURE__ */ jsx("span", { className: "mw-toast__icon", "aria-hidden": "true", children: icon }),
|
|
2470
|
+
/* @__PURE__ */ jsxs("div", { className: "mw-toast__body", children: [
|
|
2471
|
+
/* @__PURE__ */ jsx("span", { className: "mw-toast__text", children }),
|
|
2472
|
+
action && /* @__PURE__ */ jsx("span", { className: "mw-toast__action", children: action })
|
|
2473
|
+
] }),
|
|
2474
|
+
onDismiss && /* @__PURE__ */ jsx(
|
|
2475
|
+
"button",
|
|
2476
|
+
{
|
|
2477
|
+
type: "button",
|
|
2478
|
+
className: "mw-toast__dismiss",
|
|
2479
|
+
"aria-label": "Dismiss",
|
|
2480
|
+
onClick: onDismiss
|
|
2481
|
+
}
|
|
2482
|
+
)
|
|
2483
|
+
]
|
|
2484
|
+
}
|
|
2485
|
+
);
|
|
2486
|
+
}
|
|
2487
|
+
function getDefaultIcon(iconName) {
|
|
2488
|
+
return /* @__PURE__ */ jsx(Icon, { name: iconName, decorative: true });
|
|
2489
|
+
}
|
|
2490
|
+
function SuccessToast(props) {
|
|
2491
|
+
return /* @__PURE__ */ jsx(
|
|
2492
|
+
Toast,
|
|
2493
|
+
{
|
|
2494
|
+
...props,
|
|
2495
|
+
variant: props.variant ?? "outline",
|
|
2496
|
+
ariaLive: props.ariaLive ?? "polite",
|
|
2497
|
+
icon: props.icon ?? getDefaultIcon(IconName.Check),
|
|
2498
|
+
dataAttributes: {
|
|
2499
|
+
...props.dataAttributes,
|
|
2500
|
+
...createPurposeSemanticAttributes("success-toast")
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
);
|
|
2504
|
+
}
|
|
2505
|
+
function ErrorToast(props) {
|
|
2506
|
+
return /* @__PURE__ */ jsx(
|
|
2507
|
+
Toast,
|
|
2508
|
+
{
|
|
2509
|
+
...props,
|
|
2510
|
+
variant: props.variant ?? "outline",
|
|
2511
|
+
ariaLive: props.ariaLive ?? "assertive",
|
|
2512
|
+
icon: props.icon ?? getDefaultIcon(IconName.XCircle),
|
|
2513
|
+
dataAttributes: {
|
|
2514
|
+
...props.dataAttributes,
|
|
2515
|
+
...createPurposeSemanticAttributes("error-toast")
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2518
|
+
);
|
|
2519
|
+
}
|
|
2520
|
+
function WarningToast(props) {
|
|
2521
|
+
return /* @__PURE__ */ jsx(
|
|
2522
|
+
Toast,
|
|
2523
|
+
{
|
|
2524
|
+
...props,
|
|
2525
|
+
variant: props.variant ?? "outline",
|
|
2526
|
+
ariaLive: props.ariaLive ?? "polite",
|
|
2527
|
+
icon: props.icon ?? getDefaultIcon(IconName.AlertTriangle),
|
|
2528
|
+
dataAttributes: {
|
|
2529
|
+
...props.dataAttributes,
|
|
2530
|
+
...createPurposeSemanticAttributes("warning-toast")
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
);
|
|
2534
|
+
}
|
|
2535
|
+
function InfoToast(props) {
|
|
2536
|
+
return /* @__PURE__ */ jsx(
|
|
2537
|
+
Toast,
|
|
2538
|
+
{
|
|
2539
|
+
...props,
|
|
2540
|
+
variant: props.variant ?? "outline",
|
|
2541
|
+
ariaLive: props.ariaLive ?? "polite",
|
|
2542
|
+
icon: props.icon ?? getDefaultIcon(IconName.Info),
|
|
2543
|
+
dataAttributes: {
|
|
2544
|
+
...props.dataAttributes,
|
|
2545
|
+
...createPurposeSemanticAttributes("info-toast")
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
);
|
|
2549
|
+
}
|
|
2550
|
+
function cx9(...parts) {
|
|
2551
|
+
return parts.filter(Boolean).join(" ");
|
|
2552
|
+
}
|
|
2553
|
+
function renderToastByIntent(toast, onDismiss) {
|
|
2554
|
+
const sharedProps = {
|
|
2555
|
+
id: toast.id,
|
|
2556
|
+
children: toast.children
|
|
2557
|
+
};
|
|
2558
|
+
const dismissHandler = onDismiss ? () => onDismiss(toast.id) : void 0;
|
|
2559
|
+
if (toast.icon !== void 0) {
|
|
2560
|
+
sharedProps.icon = toast.icon;
|
|
2561
|
+
}
|
|
2562
|
+
if (toast.action !== void 0) {
|
|
2563
|
+
sharedProps.action = toast.action;
|
|
2564
|
+
}
|
|
2565
|
+
if (dismissHandler) {
|
|
2566
|
+
sharedProps.onDismiss = dismissHandler;
|
|
2567
|
+
}
|
|
2568
|
+
if (toast.className !== void 0) {
|
|
2569
|
+
sharedProps.className = toast.className;
|
|
2570
|
+
}
|
|
2571
|
+
if (toast.variant !== void 0) {
|
|
2572
|
+
sharedProps.variant = toast.variant;
|
|
2573
|
+
}
|
|
2574
|
+
if (toast.ariaLive !== void 0) {
|
|
2575
|
+
sharedProps.ariaLive = toast.ariaLive;
|
|
2576
|
+
}
|
|
2577
|
+
if (toast.dataAttributes !== void 0 || toast.intent !== void 0) {
|
|
2578
|
+
sharedProps.dataAttributes = {
|
|
2579
|
+
...toast.dataAttributes ?? {},
|
|
2580
|
+
...toast.intent !== void 0 ? { "data-intent": toast.intent } : {}
|
|
2581
|
+
};
|
|
2582
|
+
}
|
|
2583
|
+
switch (toast.intent) {
|
|
2584
|
+
case "success":
|
|
2585
|
+
return /* @__PURE__ */ jsx(SuccessToast, { ...sharedProps });
|
|
2586
|
+
case "error":
|
|
2587
|
+
return /* @__PURE__ */ jsx(ErrorToast, { ...sharedProps });
|
|
2588
|
+
case "warning":
|
|
2589
|
+
return /* @__PURE__ */ jsx(WarningToast, { ...sharedProps });
|
|
2590
|
+
case "info":
|
|
2591
|
+
return /* @__PURE__ */ jsx(InfoToast, { ...sharedProps });
|
|
2592
|
+
default:
|
|
2593
|
+
return /* @__PURE__ */ jsx(Toast, { ...sharedProps });
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
function ToastViewportItem(props) {
|
|
2597
|
+
const timerHandleRef = React6.useRef(null);
|
|
2598
|
+
const timerStartedAtRef = React6.useRef(null);
|
|
2599
|
+
const remainingDurationRef = React6.useRef(null);
|
|
2600
|
+
const pointerInsideRef = React6.useRef(false);
|
|
2601
|
+
const focusInsideRef = React6.useRef(false);
|
|
2602
|
+
const clearDismissTimer = React6.useCallback(() => {
|
|
2603
|
+
if (timerHandleRef.current === null) {
|
|
2604
|
+
return;
|
|
2605
|
+
}
|
|
2606
|
+
window.clearTimeout(timerHandleRef.current);
|
|
2607
|
+
timerHandleRef.current = null;
|
|
2608
|
+
timerStartedAtRef.current = null;
|
|
2609
|
+
}, []);
|
|
2610
|
+
const scheduleDismissTimer = React6.useCallback(
|
|
2611
|
+
(delay) => {
|
|
2612
|
+
if (!props.onDismiss || delay <= 0 || pointerInsideRef.current || focusInsideRef.current || timerHandleRef.current !== null) {
|
|
2613
|
+
return;
|
|
2614
|
+
}
|
|
2615
|
+
timerStartedAtRef.current = Date.now();
|
|
2616
|
+
timerHandleRef.current = window.setTimeout(() => {
|
|
2617
|
+
timerHandleRef.current = null;
|
|
2618
|
+
timerStartedAtRef.current = null;
|
|
2619
|
+
remainingDurationRef.current = 0;
|
|
2620
|
+
props.onDismiss?.(props.toast.id);
|
|
2621
|
+
}, delay);
|
|
2622
|
+
},
|
|
2623
|
+
[props.onDismiss, props.toast.id]
|
|
2624
|
+
);
|
|
2625
|
+
const pauseDismissTimer = React6.useCallback(() => {
|
|
2626
|
+
if (timerHandleRef.current === null || timerStartedAtRef.current === null) {
|
|
2627
|
+
return;
|
|
2628
|
+
}
|
|
2629
|
+
const elapsed = Date.now() - timerStartedAtRef.current;
|
|
2630
|
+
const remainingDuration = remainingDurationRef.current ?? 0;
|
|
2631
|
+
remainingDurationRef.current = Math.max(remainingDuration - elapsed, 0);
|
|
2632
|
+
clearDismissTimer();
|
|
2633
|
+
}, [clearDismissTimer]);
|
|
2634
|
+
const resumeDismissTimer = React6.useCallback(() => {
|
|
2635
|
+
if (pointerInsideRef.current || focusInsideRef.current) {
|
|
2636
|
+
return;
|
|
2637
|
+
}
|
|
2638
|
+
const remainingDuration = remainingDurationRef.current;
|
|
2639
|
+
if (remainingDuration === null || remainingDuration === void 0 || remainingDuration <= 0) {
|
|
2640
|
+
return;
|
|
2641
|
+
}
|
|
2642
|
+
scheduleDismissTimer(remainingDuration);
|
|
2643
|
+
}, [scheduleDismissTimer]);
|
|
2644
|
+
React6.useEffect(() => {
|
|
2645
|
+
clearDismissTimer();
|
|
2646
|
+
pointerInsideRef.current = false;
|
|
2647
|
+
focusInsideRef.current = false;
|
|
2648
|
+
if (!props.onDismiss || props.toast.duration === void 0 || props.toast.duration === null) {
|
|
2649
|
+
remainingDurationRef.current = null;
|
|
2650
|
+
return;
|
|
2651
|
+
}
|
|
2652
|
+
if (props.toast.duration <= 0) {
|
|
2653
|
+
remainingDurationRef.current = 0;
|
|
2654
|
+
return;
|
|
2655
|
+
}
|
|
2656
|
+
remainingDurationRef.current = props.toast.duration;
|
|
2657
|
+
scheduleDismissTimer(props.toast.duration);
|
|
2658
|
+
return () => {
|
|
2659
|
+
clearDismissTimer();
|
|
2660
|
+
};
|
|
2661
|
+
}, [clearDismissTimer, props.onDismiss, props.toast.duration, scheduleDismissTimer]);
|
|
2662
|
+
return /* @__PURE__ */ jsx(
|
|
2663
|
+
"div",
|
|
2664
|
+
{
|
|
2665
|
+
className: "mw-toast-container__item",
|
|
2666
|
+
onMouseEnter: () => {
|
|
2667
|
+
pointerInsideRef.current = true;
|
|
2668
|
+
pauseDismissTimer();
|
|
2669
|
+
},
|
|
2670
|
+
onMouseLeave: () => {
|
|
2671
|
+
pointerInsideRef.current = false;
|
|
2672
|
+
resumeDismissTimer();
|
|
2673
|
+
},
|
|
2674
|
+
onFocusCapture: () => {
|
|
2675
|
+
focusInsideRef.current = true;
|
|
2676
|
+
pauseDismissTimer();
|
|
2677
|
+
},
|
|
2678
|
+
onBlurCapture: (event) => {
|
|
2679
|
+
if (event.currentTarget.contains(event.relatedTarget)) {
|
|
2680
|
+
return;
|
|
2681
|
+
}
|
|
2682
|
+
focusInsideRef.current = false;
|
|
2683
|
+
resumeDismissTimer();
|
|
2684
|
+
},
|
|
2685
|
+
children: renderToastByIntent(props.toast, props.onDismiss)
|
|
2686
|
+
}
|
|
2687
|
+
);
|
|
2688
|
+
}
|
|
2689
|
+
function ToastContainer(props) {
|
|
2690
|
+
const placement = props.placement ?? "top-right";
|
|
2691
|
+
const visibleToasts = props.maxVisible && props.maxVisible > 0 ? props.toasts.slice(-props.maxVisible) : props.toasts;
|
|
2692
|
+
return /* @__PURE__ */ jsx("div", { className: cx9("mw-toast-container", `mw-toast-container--${placement}`, props.className), children: visibleToasts.map((toast) => /* @__PURE__ */ jsx(
|
|
2693
|
+
ToastViewportItem,
|
|
2694
|
+
{
|
|
2695
|
+
toast,
|
|
2696
|
+
...props.onDismiss ? { onDismiss: props.onDismiss } : {}
|
|
2697
|
+
},
|
|
2698
|
+
toast.id
|
|
2699
|
+
)) });
|
|
2700
|
+
}
|
|
2701
|
+
var ToastContext = React6.createContext(null);
|
|
2702
|
+
function ToastProvider(props) {
|
|
2703
|
+
const [toasts, setToasts] = React6.useState([]);
|
|
2704
|
+
const idRef = React6.useRef(0);
|
|
2705
|
+
const dismiss = React6.useCallback((id) => {
|
|
2706
|
+
setToasts((currentToasts) => {
|
|
2707
|
+
const toast = currentToasts.find((item) => item.id === id);
|
|
2708
|
+
toast?.onDismiss?.();
|
|
2709
|
+
return currentToasts.filter((item) => item.id !== id);
|
|
2710
|
+
});
|
|
2711
|
+
}, []);
|
|
2712
|
+
const clear = React6.useCallback(() => {
|
|
2713
|
+
setToasts((currentToasts) => {
|
|
2714
|
+
for (const toast of currentToasts) {
|
|
2715
|
+
toast.onDismiss?.();
|
|
2716
|
+
}
|
|
2717
|
+
return [];
|
|
2718
|
+
});
|
|
2719
|
+
}, []);
|
|
2720
|
+
const show = React6.useCallback(
|
|
2721
|
+
(toast) => {
|
|
2722
|
+
idRef.current += 1;
|
|
2723
|
+
const id = `mw-toast-${idRef.current}`;
|
|
2724
|
+
setToasts((currentToasts) => [
|
|
2725
|
+
...currentToasts,
|
|
2726
|
+
{
|
|
2727
|
+
...toast,
|
|
2728
|
+
id,
|
|
2729
|
+
duration: toast.duration === void 0 ? props.defaultDuration === void 0 ? 4e3 : props.defaultDuration : toast.duration
|
|
2730
|
+
}
|
|
2731
|
+
]);
|
|
2732
|
+
return id;
|
|
2733
|
+
},
|
|
2734
|
+
[props.defaultDuration]
|
|
2735
|
+
);
|
|
2736
|
+
const value = React6.useMemo(
|
|
2737
|
+
() => ({
|
|
2738
|
+
show,
|
|
2739
|
+
dismiss,
|
|
2740
|
+
clear
|
|
2741
|
+
}),
|
|
2742
|
+
[clear, dismiss, show]
|
|
2743
|
+
);
|
|
2744
|
+
return /* @__PURE__ */ jsxs(ToastContext.Provider, { value, children: [
|
|
2745
|
+
props.children,
|
|
2746
|
+
/* @__PURE__ */ jsx(
|
|
2747
|
+
ToastContainer,
|
|
2748
|
+
{
|
|
2749
|
+
toasts,
|
|
2750
|
+
onDismiss: dismiss,
|
|
2751
|
+
...props.placement ? { placement: props.placement } : {},
|
|
2752
|
+
...props.maxVisible !== void 0 ? { maxVisible: props.maxVisible } : {},
|
|
2753
|
+
...props.className ? { className: props.className } : {}
|
|
2754
|
+
}
|
|
2755
|
+
)
|
|
2756
|
+
] });
|
|
2757
|
+
}
|
|
2758
|
+
function useToast() {
|
|
2759
|
+
const context = React6.useContext(ToastContext);
|
|
2760
|
+
if (!context) {
|
|
2761
|
+
throw new Error("ToastProvider is missing. Wrap your app in <ToastProvider />.");
|
|
2762
|
+
}
|
|
2763
|
+
return context;
|
|
2764
|
+
}
|
|
2765
|
+
function Tooltip(props) {
|
|
2766
|
+
const { children, className, style, dataAttributes, id, ...nativeSpanProps } = props;
|
|
2767
|
+
const tooltipOptions = {};
|
|
2768
|
+
if (id !== void 0) {
|
|
2769
|
+
tooltipOptions.id = id;
|
|
2770
|
+
}
|
|
2771
|
+
const kit = createTooltipRecipe(tooltipOptions);
|
|
2772
|
+
const mergedClassName = [kit.className, className].filter(Boolean).join(" ");
|
|
2773
|
+
const mergedStyle = { ...kit.vars, ...style };
|
|
2774
|
+
return /* @__PURE__ */ jsx(
|
|
2775
|
+
"span",
|
|
2776
|
+
{
|
|
2777
|
+
...nativeSpanProps,
|
|
2778
|
+
...kit.dataAttributes,
|
|
2779
|
+
...dataAttributes,
|
|
2780
|
+
id: kit.a11y.id,
|
|
2781
|
+
className: mergedClassName,
|
|
2782
|
+
style: mergedStyle,
|
|
2783
|
+
role: kit.a11y.role,
|
|
2784
|
+
children
|
|
2785
|
+
}
|
|
2786
|
+
);
|
|
2787
|
+
}
|
|
2788
|
+
var TOOLTIP_EXIT_DURATION_MS = 160;
|
|
2789
|
+
function cx10(...parts) {
|
|
2790
|
+
return parts.filter(Boolean).join(" ");
|
|
2791
|
+
}
|
|
2792
|
+
function TooltipGroup(props) {
|
|
2793
|
+
const reactId = React6.useId();
|
|
2794
|
+
const {
|
|
2795
|
+
content,
|
|
2796
|
+
icon = IconName.HelpCircle,
|
|
2797
|
+
triggerLabel = "Show tooltip",
|
|
2798
|
+
open,
|
|
2799
|
+
defaultOpen = false,
|
|
2800
|
+
onOpenChange,
|
|
2801
|
+
tooltipId,
|
|
2802
|
+
tooltipClassName,
|
|
2803
|
+
triggerClassName,
|
|
2804
|
+
dataAttributes,
|
|
2805
|
+
className,
|
|
2806
|
+
id,
|
|
2807
|
+
onMouseEnter,
|
|
2808
|
+
onMouseLeave,
|
|
2809
|
+
onFocus,
|
|
2810
|
+
onBlur,
|
|
2811
|
+
onKeyDown,
|
|
2812
|
+
...nativeSpanProps
|
|
2813
|
+
} = props;
|
|
2814
|
+
const [internalOpen, setInternalOpen] = React6.useState(defaultOpen);
|
|
2815
|
+
const isControlled = open !== void 0;
|
|
2816
|
+
const resolvedOpen = isControlled ? open : internalOpen;
|
|
2817
|
+
const [isTooltipMounted, setIsTooltipMounted] = React6.useState(resolvedOpen);
|
|
2818
|
+
const resolvedTooltipId = tooltipId ?? `${id ?? `mw-tooltip-group-${reactId}`}-tooltip`;
|
|
2819
|
+
React6.useEffect(() => {
|
|
2820
|
+
if (resolvedOpen) {
|
|
2821
|
+
setIsTooltipMounted(true);
|
|
2822
|
+
return;
|
|
2823
|
+
}
|
|
2824
|
+
const timeoutId = window.setTimeout(() => {
|
|
2825
|
+
setIsTooltipMounted(false);
|
|
2826
|
+
}, TOOLTIP_EXIT_DURATION_MS);
|
|
2827
|
+
return () => {
|
|
2828
|
+
window.clearTimeout(timeoutId);
|
|
2829
|
+
};
|
|
2830
|
+
}, [resolvedOpen]);
|
|
2831
|
+
const updateOpen = React6.useCallback(
|
|
2832
|
+
(nextOpen) => {
|
|
2833
|
+
if (resolvedOpen === nextOpen) {
|
|
2834
|
+
return;
|
|
2835
|
+
}
|
|
2836
|
+
if (!isControlled) {
|
|
2837
|
+
setInternalOpen(nextOpen);
|
|
2838
|
+
}
|
|
2839
|
+
onOpenChange?.(nextOpen);
|
|
2840
|
+
},
|
|
2841
|
+
[isControlled, onOpenChange, resolvedOpen]
|
|
2842
|
+
);
|
|
2843
|
+
return /* @__PURE__ */ jsxs(
|
|
2844
|
+
"span",
|
|
2845
|
+
{
|
|
2846
|
+
...nativeSpanProps,
|
|
2847
|
+
...dataAttributes,
|
|
2848
|
+
id,
|
|
2849
|
+
className: cx10("mw-tooltip-group", className),
|
|
2850
|
+
"data-component": "tooltip-group",
|
|
2851
|
+
"data-open": resolvedOpen ? "true" : void 0,
|
|
2852
|
+
onMouseEnter: (event) => {
|
|
2853
|
+
onMouseEnter?.(event);
|
|
2854
|
+
updateOpen(true);
|
|
2855
|
+
},
|
|
2856
|
+
onMouseLeave: (event) => {
|
|
2857
|
+
onMouseLeave?.(event);
|
|
2858
|
+
updateOpen(false);
|
|
2859
|
+
},
|
|
2860
|
+
onFocus: (event) => {
|
|
2861
|
+
onFocus?.(event);
|
|
2862
|
+
updateOpen(true);
|
|
2863
|
+
},
|
|
2864
|
+
onBlur: (event) => {
|
|
2865
|
+
onBlur?.(event);
|
|
2866
|
+
const nextFocusedElement = event.relatedTarget;
|
|
2867
|
+
if (nextFocusedElement instanceof Node && event.currentTarget.contains(nextFocusedElement)) {
|
|
2868
|
+
return;
|
|
2869
|
+
}
|
|
2870
|
+
updateOpen(false);
|
|
2871
|
+
},
|
|
2872
|
+
onKeyDown: (event) => {
|
|
2873
|
+
onKeyDown?.(event);
|
|
2874
|
+
if (event.key === "Escape") {
|
|
2875
|
+
updateOpen(false);
|
|
2876
|
+
}
|
|
2877
|
+
},
|
|
2878
|
+
children: [
|
|
2879
|
+
isTooltipMounted ? /* @__PURE__ */ jsx(
|
|
2880
|
+
Tooltip,
|
|
2881
|
+
{
|
|
2882
|
+
id: resolvedTooltipId,
|
|
2883
|
+
className: tooltipClassName,
|
|
2884
|
+
"data-state": resolvedOpen ? "open" : "closed",
|
|
2885
|
+
"aria-hidden": resolvedOpen ? void 0 : "true",
|
|
2886
|
+
children: content
|
|
2887
|
+
}
|
|
2888
|
+
) : null,
|
|
2889
|
+
/* @__PURE__ */ jsx(
|
|
2890
|
+
"button",
|
|
2891
|
+
{
|
|
2892
|
+
type: "button",
|
|
2893
|
+
className: cx10("mw-tooltip-group__trigger", triggerClassName),
|
|
2894
|
+
"aria-label": triggerLabel,
|
|
2895
|
+
"aria-describedby": resolvedOpen ? resolvedTooltipId : void 0,
|
|
2896
|
+
children: /* @__PURE__ */ jsx(Icon, { name: icon, decorative: true })
|
|
2897
|
+
}
|
|
2898
|
+
)
|
|
2899
|
+
]
|
|
2900
|
+
}
|
|
2901
|
+
);
|
|
2902
|
+
}
|
|
2903
|
+
function Accordion(props) {
|
|
2904
|
+
const { title, children, className, onToggle, id: idProp, open, disabled } = props;
|
|
2905
|
+
const autoId = React6.useId();
|
|
2906
|
+
const resolvedId = idProp ?? autoId.replace(/:/g, "");
|
|
2907
|
+
const opts = { id: resolvedId };
|
|
2908
|
+
if (open !== void 0) opts.open = open;
|
|
2909
|
+
if (disabled !== void 0) opts.disabled = disabled;
|
|
2910
|
+
const kit = createAccordionRecipe(opts);
|
|
2911
|
+
const { a11y } = kit;
|
|
2912
|
+
function handleTriggerClick() {
|
|
2913
|
+
if (disabled) return;
|
|
2914
|
+
onToggle?.();
|
|
2915
|
+
}
|
|
2916
|
+
return /* @__PURE__ */ jsxs("div", { className: [kit.className, className].filter(Boolean).join(" "), children: [
|
|
2917
|
+
/* @__PURE__ */ jsxs(
|
|
2918
|
+
"button",
|
|
2919
|
+
{
|
|
2920
|
+
id: a11y.triggerId,
|
|
2921
|
+
type: "button",
|
|
2922
|
+
className: "mw-accordion__trigger",
|
|
2923
|
+
"aria-expanded": a11y.ariaExpanded,
|
|
2924
|
+
"aria-controls": a11y.panelId,
|
|
2925
|
+
"aria-disabled": a11y.ariaDisabled,
|
|
2926
|
+
disabled,
|
|
2927
|
+
onClick: handleTriggerClick,
|
|
2928
|
+
children: [
|
|
2929
|
+
/* @__PURE__ */ jsx("span", { className: "mw-accordion__title", children: title }),
|
|
2930
|
+
/* @__PURE__ */ jsx("span", { className: "mw-accordion__icon", "aria-hidden": "true" })
|
|
2931
|
+
]
|
|
2932
|
+
}
|
|
2933
|
+
),
|
|
2934
|
+
/* @__PURE__ */ jsx(
|
|
2935
|
+
"section",
|
|
2936
|
+
{
|
|
2937
|
+
id: a11y.panelId,
|
|
2938
|
+
"aria-labelledby": a11y.triggerId,
|
|
2939
|
+
className: "mw-accordion__panel",
|
|
2940
|
+
hidden: !open,
|
|
2941
|
+
children: /* @__PURE__ */ jsx("div", { className: "mw-accordion__content", children })
|
|
2942
|
+
}
|
|
2943
|
+
)
|
|
2944
|
+
] });
|
|
2945
|
+
}
|
|
2946
|
+
function hasContent3(value) {
|
|
2947
|
+
if (value === void 0 || value === null || value === false) return false;
|
|
2948
|
+
if (typeof value === "string") return value.trim().length > 0;
|
|
2949
|
+
return true;
|
|
2950
|
+
}
|
|
2951
|
+
function cx11(...parts) {
|
|
2952
|
+
return parts.filter(Boolean).join(" ");
|
|
2953
|
+
}
|
|
2954
|
+
function resolveAccordionItemContent(item) {
|
|
2955
|
+
return item.content ?? item.children;
|
|
2956
|
+
}
|
|
2957
|
+
function AccordionField(props) {
|
|
2958
|
+
const reactId = React6.useId();
|
|
2959
|
+
const id = props.id ?? `mw-accordion-field-${reactId}`;
|
|
2960
|
+
const multipleAllowed = props.multiple ?? true;
|
|
2961
|
+
const hasDescription = hasContent3(props.description);
|
|
2962
|
+
const hasError = hasContent3(props.error);
|
|
2963
|
+
const isInvalid = hasError || false;
|
|
2964
|
+
const { labelId, descriptionId, errorId, describedBy } = buildAccordionFieldA11yIds({
|
|
2965
|
+
id,
|
|
2966
|
+
hasDescription,
|
|
2967
|
+
hasError,
|
|
2968
|
+
externalDescribedBy: props.ariaDescribedBy
|
|
2969
|
+
});
|
|
2970
|
+
const isControlled = props.openItems !== void 0;
|
|
2971
|
+
const [internalOpenItems, setInternalOpenItems] = React6.useState(
|
|
2972
|
+
props.defaultOpenItems ?? []
|
|
2973
|
+
);
|
|
2974
|
+
const openItems = isControlled ? props.openItems ?? [] : internalOpenItems;
|
|
2975
|
+
const handleToggle = (itemValue) => {
|
|
2976
|
+
const isCurrentlyOpen = openItems.includes(itemValue);
|
|
2977
|
+
let nextOpenItems;
|
|
2978
|
+
if (isCurrentlyOpen) {
|
|
2979
|
+
nextOpenItems = openItems.filter((v) => v !== itemValue);
|
|
2980
|
+
} else if (multipleAllowed) {
|
|
2981
|
+
nextOpenItems = [...openItems, itemValue];
|
|
2982
|
+
} else {
|
|
2983
|
+
nextOpenItems = [itemValue];
|
|
2984
|
+
}
|
|
2985
|
+
if (!isControlled) {
|
|
2986
|
+
setInternalOpenItems(nextOpenItems);
|
|
2987
|
+
}
|
|
2988
|
+
props.onOpenItemsChange?.(nextOpenItems);
|
|
2989
|
+
};
|
|
2990
|
+
const wrapperClass = cx11(
|
|
2991
|
+
"mw-accordion-field",
|
|
2992
|
+
props.disabled && "mw-accordion-field--disabled",
|
|
2993
|
+
isInvalid && "mw-accordion-field--invalid"
|
|
2994
|
+
);
|
|
2995
|
+
return /* @__PURE__ */ jsxs(
|
|
2996
|
+
"fieldset",
|
|
2997
|
+
{
|
|
2998
|
+
className: wrapperClass,
|
|
2999
|
+
"aria-labelledby": labelId,
|
|
3000
|
+
"aria-describedby": describedBy,
|
|
3001
|
+
"aria-invalid": isInvalid ? true : void 0,
|
|
3002
|
+
...props.dataAttributes,
|
|
3003
|
+
children: [
|
|
3004
|
+
/* @__PURE__ */ jsx("legend", { className: "mw-accordion-field__label", id: labelId, children: /* @__PURE__ */ jsx(Paragraph, { size: "md", children: props.label }) }),
|
|
3005
|
+
/* @__PURE__ */ jsx("div", { className: "mw-accordion-field__items", children: props.items.map((item) => {
|
|
3006
|
+
const isDisabled = props.disabled || item.disabled || false;
|
|
3007
|
+
const isOpen = openItems.includes(item.value);
|
|
3008
|
+
return /* @__PURE__ */ jsx(
|
|
3009
|
+
Accordion,
|
|
3010
|
+
{
|
|
3011
|
+
id: `${id}-item-${item.value}`,
|
|
3012
|
+
title: item.title,
|
|
3013
|
+
open: isOpen,
|
|
3014
|
+
disabled: isDisabled,
|
|
3015
|
+
onToggle: () => handleToggle(item.value),
|
|
3016
|
+
children: resolveAccordionItemContent(item)
|
|
3017
|
+
},
|
|
3018
|
+
item.value
|
|
3019
|
+
);
|
|
3020
|
+
}) }),
|
|
3021
|
+
hasDescription && /* @__PURE__ */ jsx("div", { className: "mw-accordion-field__description", id: descriptionId, children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.description }) }),
|
|
3022
|
+
hasError && /* @__PURE__ */ jsx("div", { className: "mw-accordion-field__error", id: errorId, "aria-live": "polite", children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.error }) })
|
|
3023
|
+
]
|
|
3024
|
+
}
|
|
3025
|
+
);
|
|
3026
|
+
}
|
|
3027
|
+
function FAQAccordion(props) {
|
|
3028
|
+
return /* @__PURE__ */ jsx(
|
|
3029
|
+
AccordionField,
|
|
3030
|
+
{
|
|
3031
|
+
...props,
|
|
3032
|
+
multiple: false,
|
|
3033
|
+
dataAttributes: {
|
|
3034
|
+
...props.dataAttributes,
|
|
3035
|
+
"data-purpose": "faq"
|
|
3036
|
+
}
|
|
3037
|
+
}
|
|
3038
|
+
);
|
|
3039
|
+
}
|
|
3040
|
+
function SettingsAccordion(props) {
|
|
3041
|
+
return /* @__PURE__ */ jsx(
|
|
3042
|
+
AccordionField,
|
|
3043
|
+
{
|
|
3044
|
+
...props,
|
|
3045
|
+
multiple: true,
|
|
3046
|
+
dataAttributes: {
|
|
3047
|
+
...props.dataAttributes,
|
|
3048
|
+
"data-purpose": "settings"
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
);
|
|
3052
|
+
}
|
|
3053
|
+
function SectionsAccordion(props) {
|
|
3054
|
+
return /* @__PURE__ */ jsx(
|
|
3055
|
+
AccordionField,
|
|
3056
|
+
{
|
|
3057
|
+
...props,
|
|
3058
|
+
dataAttributes: {
|
|
3059
|
+
...props.dataAttributes,
|
|
3060
|
+
"data-purpose": "sections"
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
);
|
|
3064
|
+
}
|
|
3065
|
+
function Radio(props) {
|
|
3066
|
+
const { onCheckedChange, onChange, ...coreProps } = props;
|
|
3067
|
+
const kit = radioRecipe(coreProps);
|
|
3068
|
+
const { a11y } = kit;
|
|
3069
|
+
const handleChange = (e) => {
|
|
3070
|
+
onChange?.(e);
|
|
3071
|
+
onCheckedChange?.(e.currentTarget.checked);
|
|
3072
|
+
};
|
|
3073
|
+
return /* @__PURE__ */ jsx(
|
|
3074
|
+
"input",
|
|
3075
|
+
{
|
|
3076
|
+
type: "radio",
|
|
3077
|
+
className: kit.className,
|
|
3078
|
+
id: a11y.id,
|
|
3079
|
+
name: a11y.name,
|
|
3080
|
+
value: a11y.value,
|
|
3081
|
+
disabled: a11y.disabled === true,
|
|
3082
|
+
required: a11y.required === true,
|
|
3083
|
+
"aria-label": a11y.ariaLabel,
|
|
3084
|
+
"aria-labelledby": a11y.ariaLabelledBy,
|
|
3085
|
+
"aria-describedby": a11y.ariaDescribedBy,
|
|
3086
|
+
"aria-invalid": a11y.ariaInvalid === true ? true : void 0,
|
|
3087
|
+
checked: kit.checked,
|
|
3088
|
+
defaultChecked: kit.defaultChecked,
|
|
3089
|
+
onChange: handleChange
|
|
3090
|
+
}
|
|
3091
|
+
);
|
|
3092
|
+
}
|
|
3093
|
+
function hasContent4(value) {
|
|
3094
|
+
if (value === void 0 || value === null || value === false) return false;
|
|
3095
|
+
if (typeof value === "string") return value.trim().length > 0;
|
|
3096
|
+
return true;
|
|
3097
|
+
}
|
|
3098
|
+
function cx12(...parts) {
|
|
3099
|
+
return parts.filter(Boolean).join(" ");
|
|
3100
|
+
}
|
|
3101
|
+
function RadioGroupField(props) {
|
|
3102
|
+
const reactId = React6.useId();
|
|
3103
|
+
const id = props.id ?? `mw-radio-group-${reactId}`;
|
|
3104
|
+
const hasDescription = hasContent4(props.description);
|
|
3105
|
+
const hasError = hasContent4(props.error);
|
|
3106
|
+
const isInvalid = hasError || false;
|
|
3107
|
+
const { labelId, descriptionId, errorId, describedBy } = buildRadioGroupFieldA11yIds({
|
|
3108
|
+
id,
|
|
3109
|
+
hasDescription,
|
|
3110
|
+
hasError,
|
|
3111
|
+
externalDescribedBy: props.ariaDescribedBy
|
|
3112
|
+
});
|
|
3113
|
+
const isControlled = props.value !== void 0;
|
|
3114
|
+
const [internalValue, setInternalValue] = React6.useState(props.defaultValue);
|
|
3115
|
+
const selectedValue = isControlled ? props.value : internalValue;
|
|
3116
|
+
const handleSelect = (optionValue) => {
|
|
3117
|
+
if (!isControlled) {
|
|
3118
|
+
setInternalValue(optionValue);
|
|
3119
|
+
}
|
|
3120
|
+
props.onChange?.(optionValue);
|
|
3121
|
+
};
|
|
3122
|
+
const wrapperClass = cx12(
|
|
3123
|
+
"mw-radio-group-field",
|
|
3124
|
+
props.disabled && "mw-radio-group-field--disabled",
|
|
3125
|
+
isInvalid && "mw-radio-group-field--invalid"
|
|
3126
|
+
);
|
|
3127
|
+
return /* @__PURE__ */ jsxs("div", { className: wrapperClass, ...props.dataAttributes, children: [
|
|
3128
|
+
/* @__PURE__ */ jsx("div", { className: "mw-radio-group-field__label", id: labelId, children: /* @__PURE__ */ jsx(Paragraph, { size: "md", children: props.label }) }),
|
|
3129
|
+
hasDescription && /* @__PURE__ */ jsx("div", { className: "mw-radio-group-field__description", id: descriptionId, children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.description }) }),
|
|
3130
|
+
/* @__PURE__ */ jsx(
|
|
3131
|
+
"div",
|
|
3132
|
+
{
|
|
3133
|
+
role: "radiogroup",
|
|
3134
|
+
"aria-labelledby": labelId,
|
|
3135
|
+
"aria-describedby": describedBy,
|
|
3136
|
+
"aria-invalid": isInvalid ? true : void 0,
|
|
3137
|
+
"aria-required": props.required ? true : void 0,
|
|
3138
|
+
className: "mw-radio-group-field__options",
|
|
3139
|
+
children: props.options.map(({ value, label, disabled: optionDisabled }) => {
|
|
3140
|
+
const optionId = `${id}-option-${value}`;
|
|
3141
|
+
const isDisabled = props.disabled || optionDisabled || false;
|
|
3142
|
+
return /* @__PURE__ */ jsxs("label", { className: "mw-radio-group-field__option", htmlFor: optionId, children: [
|
|
3143
|
+
/* @__PURE__ */ jsx(
|
|
3144
|
+
Radio,
|
|
3145
|
+
{
|
|
3146
|
+
id: optionId,
|
|
3147
|
+
name: props.name,
|
|
3148
|
+
value,
|
|
3149
|
+
checked: selectedValue === value,
|
|
3150
|
+
disabled: isDisabled,
|
|
3151
|
+
invalid: isInvalid,
|
|
3152
|
+
...props.required ? { required: true } : {},
|
|
3153
|
+
onCheckedChange: (checked) => {
|
|
3154
|
+
if (checked) handleSelect(value);
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
),
|
|
3158
|
+
/* @__PURE__ */ jsx(Paragraph, { size: "sm", children: label })
|
|
3159
|
+
] }, value);
|
|
3160
|
+
})
|
|
3161
|
+
}
|
|
3162
|
+
),
|
|
3163
|
+
hasError && /* @__PURE__ */ jsx("div", { className: "mw-radio-group-field__error", id: errorId, "aria-live": "polite", children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.error }) })
|
|
3164
|
+
] });
|
|
3165
|
+
}
|
|
3166
|
+
function YesNoRadioGroup(props) {
|
|
3167
|
+
const { yesLabel = "Yes", noLabel = "No", ...restProps } = props;
|
|
3168
|
+
const options = [
|
|
3169
|
+
{ value: "yes", label: yesLabel },
|
|
3170
|
+
{ value: "no", label: noLabel }
|
|
3171
|
+
];
|
|
3172
|
+
return /* @__PURE__ */ jsx(
|
|
3173
|
+
RadioGroupField,
|
|
3174
|
+
{
|
|
3175
|
+
...restProps,
|
|
3176
|
+
options,
|
|
3177
|
+
dataAttributes: {
|
|
3178
|
+
...props.dataAttributes,
|
|
3179
|
+
"data-purpose": "binary-choice"
|
|
3180
|
+
}
|
|
3181
|
+
}
|
|
3182
|
+
);
|
|
3183
|
+
}
|
|
3184
|
+
function RatingRadioGroup(props) {
|
|
3185
|
+
const { min = 1, max = 5, labelFn = String, ...restProps } = props;
|
|
3186
|
+
const options = Array.from({ length: max - min + 1 }, (_, i) => {
|
|
3187
|
+
const value = min + i;
|
|
3188
|
+
return { value: String(value), label: labelFn(value) };
|
|
3189
|
+
});
|
|
3190
|
+
return /* @__PURE__ */ jsx(
|
|
3191
|
+
RadioGroupField,
|
|
3192
|
+
{
|
|
3193
|
+
...restProps,
|
|
3194
|
+
options,
|
|
3195
|
+
dataAttributes: {
|
|
3196
|
+
...props.dataAttributes,
|
|
3197
|
+
"data-purpose": "rating"
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
);
|
|
3201
|
+
}
|
|
3202
|
+
function OptionRadioGroup(props) {
|
|
3203
|
+
return /* @__PURE__ */ jsx(
|
|
3204
|
+
RadioGroupField,
|
|
3205
|
+
{
|
|
3206
|
+
...props,
|
|
3207
|
+
dataAttributes: {
|
|
3208
|
+
...props.dataAttributes,
|
|
3209
|
+
"data-purpose": "selection"
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
);
|
|
3213
|
+
}
|
|
3214
|
+
function Badge(props) {
|
|
3215
|
+
const { children, className, id, dataAttributes, ...coreProps } = props;
|
|
3216
|
+
const kit = createBadgeRecipe(coreProps);
|
|
3217
|
+
return /* @__PURE__ */ jsx(
|
|
3218
|
+
"span",
|
|
3219
|
+
{
|
|
3220
|
+
id,
|
|
3221
|
+
className: [kit.className, className].filter(Boolean).join(" "),
|
|
3222
|
+
"aria-label": kit.a11y.ariaLabel,
|
|
3223
|
+
...kit.dataAttributes,
|
|
3224
|
+
...dataAttributes,
|
|
3225
|
+
children
|
|
3226
|
+
}
|
|
3227
|
+
);
|
|
3228
|
+
}
|
|
3229
|
+
function cx13(...parts) {
|
|
3230
|
+
return parts.filter(Boolean).join(" ");
|
|
3231
|
+
}
|
|
3232
|
+
function BadgeGroup(props) {
|
|
3233
|
+
const reactId = React6.useId();
|
|
3234
|
+
const id = props.id ?? `mw-badge-group-${reactId}`;
|
|
3235
|
+
const labelId = `${id}-label`;
|
|
3236
|
+
const className = cx13("mw-badge-group", props.className);
|
|
3237
|
+
return /* @__PURE__ */ jsxs("fieldset", { className, "aria-labelledby": labelId, ...props.dataAttributes, children: [
|
|
3238
|
+
/* @__PURE__ */ jsx("legend", { className: "mw-badge-group__label", id: labelId, children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.label }) }),
|
|
3239
|
+
/* @__PURE__ */ jsx("div", { className: "mw-badge-group__items", children: props.children })
|
|
3240
|
+
] });
|
|
3241
|
+
}
|
|
3242
|
+
function StatusBadge(props) {
|
|
3243
|
+
return /* @__PURE__ */ jsx(
|
|
3244
|
+
Badge,
|
|
3245
|
+
{
|
|
3246
|
+
...props,
|
|
3247
|
+
dataAttributes: {
|
|
3248
|
+
...props.dataAttributes,
|
|
3249
|
+
...createPurposeSemanticAttributes("status")
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
);
|
|
3253
|
+
}
|
|
3254
|
+
function PriorityBadge(props) {
|
|
3255
|
+
return /* @__PURE__ */ jsx(
|
|
3256
|
+
Badge,
|
|
3257
|
+
{
|
|
3258
|
+
...props,
|
|
3259
|
+
dataAttributes: {
|
|
3260
|
+
...props.dataAttributes,
|
|
3261
|
+
...createPurposeSemanticAttributes("priority")
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
);
|
|
3265
|
+
}
|
|
3266
|
+
function NotificationBadge(props) {
|
|
3267
|
+
return /* @__PURE__ */ jsx(
|
|
3268
|
+
Badge,
|
|
3269
|
+
{
|
|
3270
|
+
...props,
|
|
3271
|
+
dataAttributes: {
|
|
3272
|
+
...props.dataAttributes,
|
|
3273
|
+
...createPurposeSemanticAttributes("notification")
|
|
3274
|
+
}
|
|
3275
|
+
}
|
|
3276
|
+
);
|
|
3277
|
+
}
|
|
3278
|
+
function Switch(props) {
|
|
3279
|
+
const { children, className, id, onCheckedChange, onClick, ...coreProps } = props;
|
|
3280
|
+
const kit = createSwitchRecipe(coreProps);
|
|
3281
|
+
const { a11y } = kit;
|
|
3282
|
+
const isDisabled = a11y.ariaDisabled === true;
|
|
3283
|
+
const handleClick = (event) => {
|
|
3284
|
+
onClick?.(event);
|
|
3285
|
+
if (isDisabled || event.defaultPrevented) {
|
|
3286
|
+
return;
|
|
3287
|
+
}
|
|
3288
|
+
onCheckedChange?.(!a11y.ariaChecked);
|
|
3289
|
+
};
|
|
3290
|
+
return /* @__PURE__ */ jsxs(
|
|
3291
|
+
"button",
|
|
3292
|
+
{
|
|
3293
|
+
id,
|
|
3294
|
+
type: "button",
|
|
3295
|
+
role: a11y.role,
|
|
3296
|
+
disabled: isDisabled,
|
|
3297
|
+
"aria-checked": a11y.ariaChecked,
|
|
3298
|
+
"aria-disabled": a11y.ariaDisabled,
|
|
3299
|
+
"aria-label": a11y.ariaLabel,
|
|
3300
|
+
"aria-labelledby": a11y.ariaLabelledby,
|
|
3301
|
+
"aria-describedby": a11y.ariaDescribedBy,
|
|
3302
|
+
className: [kit.className, className].filter(Boolean).join(" "),
|
|
3303
|
+
style: kit.vars,
|
|
3304
|
+
onClick: handleClick,
|
|
3305
|
+
children: [
|
|
3306
|
+
/* @__PURE__ */ jsx("span", { className: "mw-switch__track", children: /* @__PURE__ */ jsx("span", { className: "mw-switch__thumb" }) }),
|
|
3307
|
+
children
|
|
3308
|
+
]
|
|
3309
|
+
}
|
|
3310
|
+
);
|
|
3311
|
+
}
|
|
3312
|
+
function cx14(...parts) {
|
|
3313
|
+
return parts.filter(Boolean).join(" ");
|
|
3314
|
+
}
|
|
3315
|
+
function hasContent5(value) {
|
|
3316
|
+
if (value === void 0 || value === null || value === false) {
|
|
3317
|
+
return false;
|
|
3318
|
+
}
|
|
3319
|
+
if (typeof value === "string") {
|
|
3320
|
+
return value.trim().length > 0;
|
|
3321
|
+
}
|
|
3322
|
+
return true;
|
|
3323
|
+
}
|
|
3324
|
+
function SwitchField(props) {
|
|
3325
|
+
const reactId = React6.useId();
|
|
3326
|
+
const id = props.id ?? `mw-switch-${reactId}`;
|
|
3327
|
+
const hasDescription = hasContent5(props.description);
|
|
3328
|
+
const hasError = hasContent5(props.error);
|
|
3329
|
+
const { labelId, descriptionId, errorId, describedBy } = buildSwitchFieldA11yIds({
|
|
3330
|
+
id,
|
|
3331
|
+
hasDescription,
|
|
3332
|
+
hasError,
|
|
3333
|
+
externalDescribedBy: props.ariaDescribedBy
|
|
3334
|
+
});
|
|
3335
|
+
const disabled = props.switch.disabled || false;
|
|
3336
|
+
const invalid = hasError;
|
|
3337
|
+
const wrapperClass = cx14(
|
|
3338
|
+
"mw-switch-field",
|
|
3339
|
+
disabled && "mw-switch-field--disabled",
|
|
3340
|
+
invalid && "mw-switch-field--invalid"
|
|
3341
|
+
);
|
|
3342
|
+
const {
|
|
3343
|
+
ariaLabel: _ignoredAriaLabel,
|
|
3344
|
+
ariaLabelledby: _ignoredAriaLabelledby,
|
|
3345
|
+
ariaDescribedBy: _ignoredAriaDescribedBy,
|
|
3346
|
+
children: _ignoredChildren,
|
|
3347
|
+
...switchProps
|
|
3348
|
+
} = props.switch;
|
|
3349
|
+
return /* @__PURE__ */ jsxs("div", { className: wrapperClass, ...props.dataAttributes, children: [
|
|
3350
|
+
/* @__PURE__ */ jsxs("div", { className: "mw-switch-field__row", children: [
|
|
3351
|
+
/* @__PURE__ */ jsx(
|
|
3352
|
+
Switch,
|
|
3353
|
+
{
|
|
3354
|
+
...switchProps,
|
|
3355
|
+
id,
|
|
3356
|
+
ariaLabelledby: labelId,
|
|
3357
|
+
...describedBy ? { ariaDescribedBy: describedBy } : {}
|
|
3358
|
+
}
|
|
3359
|
+
),
|
|
3360
|
+
/* @__PURE__ */ jsx("span", { className: "mw-switch-field__label", id: labelId, children: /* @__PURE__ */ jsx(Paragraph, { size: "md", children: props.label }) })
|
|
3361
|
+
] }),
|
|
3362
|
+
hasDescription && /* @__PURE__ */ jsx("div", { className: "mw-switch-field__description", id: descriptionId, children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.description }) }),
|
|
3363
|
+
hasError && /* @__PURE__ */ jsx("div", { className: "mw-switch-field__error", id: errorId, "aria-live": "polite", children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.error }) })
|
|
3364
|
+
] });
|
|
3365
|
+
}
|
|
3366
|
+
function FeatureToggle(props) {
|
|
3367
|
+
return /* @__PURE__ */ jsx(
|
|
3368
|
+
SwitchField,
|
|
3369
|
+
{
|
|
3370
|
+
...props,
|
|
3371
|
+
dataAttributes: {
|
|
3372
|
+
...props.dataAttributes,
|
|
3373
|
+
"data-purpose": "feature-toggle"
|
|
3374
|
+
}
|
|
3375
|
+
}
|
|
3376
|
+
);
|
|
3377
|
+
}
|
|
3378
|
+
function PreferenceSwitch(props) {
|
|
3379
|
+
return /* @__PURE__ */ jsx(
|
|
3380
|
+
SwitchField,
|
|
3381
|
+
{
|
|
3382
|
+
...props,
|
|
3383
|
+
dataAttributes: {
|
|
3384
|
+
...props.dataAttributes,
|
|
3385
|
+
"data-purpose": "preference"
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3388
|
+
);
|
|
3389
|
+
}
|
|
3390
|
+
function PermissionSwitch(props) {
|
|
3391
|
+
return /* @__PURE__ */ jsx(
|
|
3392
|
+
SwitchField,
|
|
3393
|
+
{
|
|
3394
|
+
...props,
|
|
3395
|
+
dataAttributes: {
|
|
3396
|
+
...props.dataAttributes,
|
|
3397
|
+
"data-purpose": "permission"
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
);
|
|
3401
|
+
}
|
|
3402
|
+
function buildSliderOptions(options) {
|
|
3403
|
+
const sliderOptions = {};
|
|
3404
|
+
if (options.id !== void 0) sliderOptions.id = options.id;
|
|
3405
|
+
if (options.name !== void 0) sliderOptions.name = options.name;
|
|
3406
|
+
if (options.min !== void 0) sliderOptions.min = options.min;
|
|
3407
|
+
if (options.max !== void 0) sliderOptions.max = options.max;
|
|
3408
|
+
if (options.step !== void 0) sliderOptions.step = options.step;
|
|
3409
|
+
if (options.value !== void 0) sliderOptions.value = options.value;
|
|
3410
|
+
if (options.defaultValue !== void 0) sliderOptions.defaultValue = options.defaultValue;
|
|
3411
|
+
if (options.disabled !== void 0) sliderOptions.disabled = options.disabled;
|
|
3412
|
+
if (options.required !== void 0) sliderOptions.required = options.required;
|
|
3413
|
+
if (options.showTooltip !== void 0) sliderOptions.showTooltip = options.showTooltip;
|
|
3414
|
+
if (options.showTouchArea !== void 0) sliderOptions.showTouchArea = options.showTouchArea;
|
|
3415
|
+
if (options.orientation !== void 0) sliderOptions.orientation = options.orientation;
|
|
3416
|
+
if (options.ariaLabel !== void 0) sliderOptions.ariaLabel = options.ariaLabel;
|
|
3417
|
+
if (options.ariaLabelledBy !== void 0) sliderOptions.ariaLabelledBy = options.ariaLabelledBy;
|
|
3418
|
+
if (options.ariaDescribedBy !== void 0) sliderOptions.ariaDescribedBy = options.ariaDescribedBy;
|
|
3419
|
+
if (options.ariaValueText !== void 0) sliderOptions.ariaValueText = options.ariaValueText;
|
|
3420
|
+
return sliderOptions;
|
|
3421
|
+
}
|
|
3422
|
+
function resolveSliderValue(options) {
|
|
3423
|
+
return createSliderRecipe(buildSliderOptions(options)).value;
|
|
3424
|
+
}
|
|
3425
|
+
var Slider = React6.forwardRef((props, ref) => {
|
|
3426
|
+
const {
|
|
3427
|
+
id,
|
|
3428
|
+
name,
|
|
3429
|
+
min,
|
|
3430
|
+
max,
|
|
3431
|
+
step,
|
|
3432
|
+
value,
|
|
3433
|
+
defaultValue,
|
|
3434
|
+
disabled,
|
|
3435
|
+
required,
|
|
3436
|
+
showTooltip,
|
|
3437
|
+
showTouchArea,
|
|
3438
|
+
orientation,
|
|
3439
|
+
ariaLabel,
|
|
3440
|
+
ariaLabelledBy,
|
|
3441
|
+
ariaDescribedBy,
|
|
3442
|
+
ariaValueText,
|
|
3443
|
+
className: customClassName,
|
|
3444
|
+
style: customStyle,
|
|
3445
|
+
onValueChange,
|
|
3446
|
+
onChange,
|
|
3447
|
+
...inputProps
|
|
3448
|
+
} = props;
|
|
3449
|
+
const isControlled = value !== void 0;
|
|
3450
|
+
const [uncontrolledValue, setUncontrolledValue] = React6.useState(
|
|
3451
|
+
() => resolveSliderValue({ min, max, step, value, defaultValue })
|
|
3452
|
+
);
|
|
3453
|
+
React6.useEffect(() => {
|
|
3454
|
+
if (!isControlled) {
|
|
3455
|
+
setUncontrolledValue(resolveSliderValue({ min, max, step, defaultValue }));
|
|
3456
|
+
}
|
|
3457
|
+
}, [defaultValue, isControlled, max, min, step]);
|
|
3458
|
+
const currentValue = isControlled ? resolveSliderValue({ min, max, step, value }) : uncontrolledValue;
|
|
3459
|
+
const kit = createSliderRecipe(
|
|
3460
|
+
buildSliderOptions({
|
|
3461
|
+
id,
|
|
3462
|
+
name,
|
|
3463
|
+
min,
|
|
3464
|
+
max,
|
|
3465
|
+
step,
|
|
3466
|
+
value: currentValue,
|
|
3467
|
+
disabled,
|
|
3468
|
+
required,
|
|
3469
|
+
showTooltip,
|
|
3470
|
+
showTouchArea,
|
|
3471
|
+
orientation,
|
|
3472
|
+
ariaLabel,
|
|
3473
|
+
ariaLabelledBy,
|
|
3474
|
+
ariaDescribedBy,
|
|
3475
|
+
ariaValueText
|
|
3476
|
+
})
|
|
3477
|
+
);
|
|
3478
|
+
useRenderKitDebug(kit, "Slider");
|
|
3479
|
+
const className = customClassName ? `${kit.className} ${customClassName}` : kit.className;
|
|
3480
|
+
const style = { ...kit.vars, ...customStyle };
|
|
3481
|
+
const handleChange = (event) => {
|
|
3482
|
+
const nextValue = Number(event.currentTarget.value);
|
|
3483
|
+
if (!isControlled) {
|
|
3484
|
+
setUncontrolledValue(nextValue);
|
|
3485
|
+
}
|
|
3486
|
+
onChange?.(event);
|
|
3487
|
+
onValueChange?.(nextValue);
|
|
3488
|
+
};
|
|
3489
|
+
return /* @__PURE__ */ jsx("div", { className, style, ...kit.dataAttributes, children: /* @__PURE__ */ jsxs("div", { className: "mw-slider__control", children: [
|
|
3490
|
+
/* @__PURE__ */ jsx(
|
|
3491
|
+
"input",
|
|
3492
|
+
{
|
|
3493
|
+
...inputProps,
|
|
3494
|
+
ref,
|
|
3495
|
+
type: kit.a11y.type,
|
|
3496
|
+
id: kit.a11y.id,
|
|
3497
|
+
name: kit.a11y.name,
|
|
3498
|
+
min: kit.a11y.min,
|
|
3499
|
+
max: kit.a11y.max,
|
|
3500
|
+
step: kit.a11y.step,
|
|
3501
|
+
disabled: kit.a11y.disabled === true,
|
|
3502
|
+
required: kit.a11y.required === true,
|
|
3503
|
+
"aria-label": kit.a11y.ariaLabel,
|
|
3504
|
+
"aria-labelledby": kit.a11y.ariaLabelledBy,
|
|
3505
|
+
"aria-describedby": kit.a11y.ariaDescribedBy,
|
|
3506
|
+
"aria-valuetext": kit.a11y.ariaValueText,
|
|
3507
|
+
"aria-orientation": kit.a11y.ariaOrientation,
|
|
3508
|
+
className: kit.inputClassName,
|
|
3509
|
+
value: currentValue,
|
|
3510
|
+
onChange: handleChange
|
|
3511
|
+
}
|
|
3512
|
+
),
|
|
3513
|
+
/* @__PURE__ */ jsxs("div", { className: "mw-slider__visual", "aria-hidden": "true", children: [
|
|
3514
|
+
/* @__PURE__ */ jsx("span", { className: "mw-slider__track" }),
|
|
3515
|
+
/* @__PURE__ */ jsx("span", { className: "mw-slider__fill" }),
|
|
3516
|
+
/* @__PURE__ */ jsx("span", { className: "mw-slider__touch-area" }),
|
|
3517
|
+
/* @__PURE__ */ jsx("span", { className: "mw-slider__thumb" })
|
|
3518
|
+
] }),
|
|
3519
|
+
kit.showTooltip ? /* @__PURE__ */ jsx("span", { className: "mw-slider__tooltip", "aria-hidden": "true", children: currentValue }) : null
|
|
3520
|
+
] }) });
|
|
3521
|
+
});
|
|
3522
|
+
Slider.displayName = "Slider";
|
|
3523
|
+
function cx15(...parts) {
|
|
3524
|
+
return parts.filter(Boolean).join(" ");
|
|
3525
|
+
}
|
|
3526
|
+
function hasContent6(value) {
|
|
3527
|
+
if (value === void 0 || value === null || value === false) {
|
|
3528
|
+
return false;
|
|
3529
|
+
}
|
|
3530
|
+
if (typeof value === "string") {
|
|
3531
|
+
return value.trim().length > 0;
|
|
3532
|
+
}
|
|
3533
|
+
return true;
|
|
3534
|
+
}
|
|
3535
|
+
function resolveEdgeValueLabel(value, fallback) {
|
|
3536
|
+
return value ?? `${fallback}`;
|
|
3537
|
+
}
|
|
3538
|
+
function SliderField(props) {
|
|
3539
|
+
const reactId = React6.useId();
|
|
3540
|
+
const id = props.id ?? `mw-slider-${reactId}`;
|
|
3541
|
+
const hasDescription = hasContent6(props.description);
|
|
3542
|
+
const hasError = hasContent6(props.error);
|
|
3543
|
+
const { labelId, descriptionId, errorId, describedBy } = buildSliderFieldA11yIds({
|
|
3544
|
+
id,
|
|
3545
|
+
hasDescription,
|
|
3546
|
+
hasError,
|
|
3547
|
+
externalDescribedBy: props.ariaDescribedBy
|
|
3548
|
+
});
|
|
3549
|
+
const disabled = props.slider.disabled || false;
|
|
3550
|
+
const labelPosition = props.labelPosition ?? "top";
|
|
3551
|
+
const showEdgeValues = props.showEdgeValues !== false;
|
|
3552
|
+
const minValue = props.slider.min ?? 0;
|
|
3553
|
+
const maxValue = props.slider.max ?? 100;
|
|
3554
|
+
const minValueLabel = resolveEdgeValueLabel(props.minValueLabel, minValue);
|
|
3555
|
+
const maxValueLabel = resolveEdgeValueLabel(props.maxValueLabel, maxValue);
|
|
3556
|
+
const wrapperClass = cx15(
|
|
3557
|
+
"mw-slider-field",
|
|
3558
|
+
labelPosition === "top" && "mw-slider-field--label-top",
|
|
3559
|
+
labelPosition === "inline" && "mw-slider-field--label-inline",
|
|
3560
|
+
disabled && "mw-slider-field--disabled",
|
|
3561
|
+
hasError && "mw-slider-field--invalid"
|
|
3562
|
+
);
|
|
3563
|
+
const {
|
|
3564
|
+
ariaLabel: _ignoredAriaLabel,
|
|
3565
|
+
ariaLabelledBy: _ignoredAriaLabelledBy,
|
|
3566
|
+
ariaDescribedBy: _ignoredAriaDescribedBy,
|
|
3567
|
+
style: sliderStyle,
|
|
3568
|
+
...sliderProps
|
|
3569
|
+
} = props.slider;
|
|
3570
|
+
const renderEdgeValue = (position, value) => /* @__PURE__ */ jsx("span", { className: `mw-slider-field__edge-value mw-slider-field__edge-value--${position}`, children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: value }) });
|
|
3571
|
+
return /* @__PURE__ */ jsxs("div", { className: wrapperClass, "data-label-position": labelPosition, ...props.dataAttributes, children: [
|
|
3572
|
+
/* @__PURE__ */ jsx("div", { className: "mw-slider-field__header", children: /* @__PURE__ */ jsx("div", { className: "mw-slider-field__label", id: labelId, children: /* @__PURE__ */ jsx(Paragraph, { size: "md", children: props.label }) }) }),
|
|
3573
|
+
hasDescription && /* @__PURE__ */ jsx("div", { className: "mw-slider-field__description", id: descriptionId, children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.description }) }),
|
|
3574
|
+
labelPosition === "top" && showEdgeValues ? /* @__PURE__ */ jsxs("div", { className: "mw-slider-field__values-row", children: [
|
|
3575
|
+
renderEdgeValue("min", minValueLabel),
|
|
3576
|
+
renderEdgeValue("max", maxValueLabel)
|
|
3577
|
+
] }) : null,
|
|
3578
|
+
/* @__PURE__ */ jsxs("div", { className: "mw-slider-field__control-row", children: [
|
|
3579
|
+
labelPosition === "inline" && showEdgeValues ? renderEdgeValue("min", minValueLabel) : null,
|
|
3580
|
+
/* @__PURE__ */ jsx("div", { className: "mw-slider-field__slider", children: /* @__PURE__ */ jsx(
|
|
3581
|
+
Slider,
|
|
3582
|
+
{
|
|
3583
|
+
...sliderProps,
|
|
3584
|
+
id,
|
|
3585
|
+
ariaLabelledBy: labelId,
|
|
3586
|
+
...describedBy ? { ariaDescribedBy: describedBy } : {},
|
|
3587
|
+
"aria-invalid": hasError ? true : void 0,
|
|
3588
|
+
style: { width: "100%", ...sliderStyle ?? {} }
|
|
3589
|
+
}
|
|
3590
|
+
) }),
|
|
3591
|
+
labelPosition === "inline" && showEdgeValues ? renderEdgeValue("max", maxValueLabel) : null
|
|
3592
|
+
] }),
|
|
3593
|
+
hasError && /* @__PURE__ */ jsx("div", { className: "mw-slider-field__error", id: errorId, "aria-live": "polite", children: /* @__PURE__ */ jsx(Paragraph, { size: "sm", children: props.error }) })
|
|
3594
|
+
] });
|
|
3595
|
+
}
|
|
3596
|
+
function VolumeSlider(props) {
|
|
3597
|
+
const { orientation, slider, ...fieldProps } = props;
|
|
3598
|
+
return /* @__PURE__ */ jsx(
|
|
3599
|
+
SliderField,
|
|
3600
|
+
{
|
|
3601
|
+
...fieldProps,
|
|
3602
|
+
label: props.label ?? "Volume",
|
|
3603
|
+
minValueLabel: props.minValueLabel ?? "0",
|
|
3604
|
+
maxValueLabel: props.maxValueLabel ?? "100",
|
|
3605
|
+
slider: {
|
|
3606
|
+
min: 0,
|
|
3607
|
+
max: 100,
|
|
3608
|
+
step: 1,
|
|
3609
|
+
showTooltip: true,
|
|
3610
|
+
...orientation !== void 0 ? { orientation } : {},
|
|
3611
|
+
...slider
|
|
3612
|
+
},
|
|
3613
|
+
dataAttributes: {
|
|
3614
|
+
...props.dataAttributes,
|
|
3615
|
+
"data-purpose": "volume"
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3618
|
+
);
|
|
3619
|
+
}
|
|
3620
|
+
function BrightnessSlider(props) {
|
|
3621
|
+
const { orientation, slider, ...fieldProps } = props;
|
|
3622
|
+
return /* @__PURE__ */ jsx(
|
|
3623
|
+
SliderField,
|
|
3624
|
+
{
|
|
3625
|
+
...fieldProps,
|
|
3626
|
+
label: props.label ?? "Brightness",
|
|
3627
|
+
minValueLabel: props.minValueLabel ?? "0",
|
|
3628
|
+
maxValueLabel: props.maxValueLabel ?? "100",
|
|
3629
|
+
slider: {
|
|
3630
|
+
min: 0,
|
|
3631
|
+
max: 100,
|
|
3632
|
+
step: 1,
|
|
3633
|
+
showTooltip: true,
|
|
3634
|
+
...orientation !== void 0 ? { orientation } : {},
|
|
3635
|
+
...slider
|
|
3636
|
+
},
|
|
3637
|
+
dataAttributes: {
|
|
3638
|
+
...props.dataAttributes,
|
|
3639
|
+
"data-purpose": "brightness"
|
|
3640
|
+
}
|
|
3641
|
+
}
|
|
3642
|
+
);
|
|
3643
|
+
}
|
|
3644
|
+
function RadiusSlider(props) {
|
|
3645
|
+
const { orientation, slider, ...fieldProps } = props;
|
|
3646
|
+
return /* @__PURE__ */ jsx(
|
|
3647
|
+
SliderField,
|
|
3648
|
+
{
|
|
3649
|
+
...fieldProps,
|
|
3650
|
+
label: props.label ?? "Radius",
|
|
3651
|
+
minValueLabel: props.minValueLabel ?? "0px",
|
|
3652
|
+
maxValueLabel: props.maxValueLabel ?? "48px",
|
|
3653
|
+
slider: {
|
|
3654
|
+
min: 0,
|
|
3655
|
+
max: 48,
|
|
3656
|
+
step: 2,
|
|
3657
|
+
showTooltip: true,
|
|
3658
|
+
...orientation !== void 0 ? { orientation } : {},
|
|
3659
|
+
...slider
|
|
3660
|
+
},
|
|
3661
|
+
dataAttributes: {
|
|
3662
|
+
...props.dataAttributes,
|
|
3663
|
+
"data-purpose": "radius"
|
|
3664
|
+
}
|
|
3665
|
+
}
|
|
3666
|
+
);
|
|
3667
|
+
}
|
|
3668
|
+
function Tab(props) {
|
|
3669
|
+
const { children, className, onClick, id, ...coreProps } = props;
|
|
3670
|
+
const kit = createTabRecipe(coreProps);
|
|
3671
|
+
const { a11y } = kit;
|
|
3672
|
+
return /* @__PURE__ */ jsx(
|
|
3673
|
+
"button",
|
|
3674
|
+
{
|
|
3675
|
+
id,
|
|
3676
|
+
className: [kit.className, className].filter(Boolean).join(" "),
|
|
3677
|
+
style: Object.keys(kit.vars).length > 0 ? kit.vars : void 0,
|
|
3678
|
+
role: a11y.role,
|
|
3679
|
+
"aria-selected": a11y.ariaSelected,
|
|
3680
|
+
"aria-disabled": a11y.ariaDisabled,
|
|
3681
|
+
"aria-label": a11y.ariaLabel,
|
|
3682
|
+
"aria-controls": a11y.ariaControls,
|
|
3683
|
+
tabIndex: a11y.tabIndex,
|
|
3684
|
+
disabled: coreProps.disabled,
|
|
3685
|
+
onClick,
|
|
3686
|
+
type: "button",
|
|
3687
|
+
children
|
|
3688
|
+
}
|
|
3689
|
+
);
|
|
3690
|
+
}
|
|
3691
|
+
function cx16(...parts) {
|
|
3692
|
+
return parts.filter(Boolean).join(" ");
|
|
3693
|
+
}
|
|
3694
|
+
function hasContent7(value) {
|
|
3695
|
+
if (value === void 0 || value === null || value === false) {
|
|
3696
|
+
return false;
|
|
3697
|
+
}
|
|
3698
|
+
if (typeof value === "string") {
|
|
3699
|
+
return value.trim().length > 0;
|
|
3700
|
+
}
|
|
3701
|
+
return true;
|
|
3702
|
+
}
|
|
3703
|
+
function focusTab(tabId) {
|
|
3704
|
+
if (typeof document === "undefined") {
|
|
3705
|
+
return;
|
|
3706
|
+
}
|
|
3707
|
+
const tab = document.getElementById(tabId);
|
|
3708
|
+
if (tab instanceof HTMLButtonElement) {
|
|
3709
|
+
tab.focus();
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
function toItemState(tab) {
|
|
3713
|
+
const itemState = { value: tab.value };
|
|
3714
|
+
if (tab.disabled) {
|
|
3715
|
+
itemState.disabled = true;
|
|
3716
|
+
}
|
|
3717
|
+
return itemState;
|
|
3718
|
+
}
|
|
3719
|
+
function renderPanelContent(children) {
|
|
3720
|
+
if (typeof children === "string" || typeof children === "number") {
|
|
3721
|
+
return /* @__PURE__ */ jsx(Paragraph, { size: "md", children });
|
|
3722
|
+
}
|
|
3723
|
+
return children;
|
|
3724
|
+
}
|
|
3725
|
+
function TabPanel(props) {
|
|
3726
|
+
return /* @__PURE__ */ jsx(
|
|
3727
|
+
"div",
|
|
3728
|
+
{
|
|
3729
|
+
id: props.id,
|
|
3730
|
+
role: "tabpanel",
|
|
3731
|
+
"aria-labelledby": props.tabId,
|
|
3732
|
+
className: cx16("mw-tab-group__panel", props.className),
|
|
3733
|
+
hidden: props.hidden,
|
|
3734
|
+
tabIndex: props.hidden ? void 0 : 0,
|
|
3735
|
+
children: renderPanelContent(props.children)
|
|
3736
|
+
}
|
|
3737
|
+
);
|
|
3738
|
+
}
|
|
3739
|
+
function TabGroup(props) {
|
|
3740
|
+
const reactId = React6.useId();
|
|
3741
|
+
const id = props.id ?? `mw-tab-group-${reactId}`;
|
|
3742
|
+
const hasLabel = hasContent7(props.label);
|
|
3743
|
+
const itemStates = React6.useMemo(
|
|
3744
|
+
() => props.tabs.map((tab) => toItemState(tab)),
|
|
3745
|
+
[props.tabs]
|
|
3746
|
+
);
|
|
3747
|
+
const isControlled = props.activeTab !== void 0;
|
|
3748
|
+
const [internalActiveTab, setInternalActiveTab] = React6.useState(
|
|
3749
|
+
() => resolveTabValue(itemStates, props.defaultActiveTab)
|
|
3750
|
+
);
|
|
3751
|
+
const resolvedActiveTab = React6.useMemo(
|
|
3752
|
+
() => resolveTabValue(itemStates, isControlled ? props.activeTab : internalActiveTab),
|
|
3753
|
+
[internalActiveTab, isControlled, itemStates, props.activeTab]
|
|
3754
|
+
);
|
|
3755
|
+
React6.useEffect(() => {
|
|
3756
|
+
if (!isControlled) {
|
|
3757
|
+
setInternalActiveTab(
|
|
3758
|
+
(currentValue) => resolveTabValue(itemStates, currentValue ?? props.defaultActiveTab)
|
|
3759
|
+
);
|
|
3760
|
+
}
|
|
3761
|
+
}, [isControlled, itemStates, props.defaultActiveTab]);
|
|
3762
|
+
const a11yIds = React6.useMemo(
|
|
3763
|
+
() => buildTabGroupA11yIds({
|
|
3764
|
+
id,
|
|
3765
|
+
itemValues: props.tabs.map((tab) => tab.value),
|
|
3766
|
+
hasLabel
|
|
3767
|
+
}),
|
|
3768
|
+
[hasLabel, id, props.tabs]
|
|
3769
|
+
);
|
|
3770
|
+
const selectTab = React6.useCallback(
|
|
3771
|
+
(nextValue) => {
|
|
3772
|
+
const resolvedValue = resolveTabValue(itemStates, nextValue);
|
|
3773
|
+
if (!resolvedValue) {
|
|
3774
|
+
return;
|
|
3775
|
+
}
|
|
3776
|
+
if (!isControlled) {
|
|
3777
|
+
setInternalActiveTab(resolvedValue);
|
|
3778
|
+
}
|
|
3779
|
+
if (resolvedValue !== resolvedActiveTab) {
|
|
3780
|
+
props.onActiveTabChange?.(resolvedValue);
|
|
3781
|
+
}
|
|
3782
|
+
},
|
|
3783
|
+
[isControlled, itemStates, props.onActiveTabChange, resolvedActiveTab]
|
|
3784
|
+
);
|
|
3785
|
+
const handleKeyDown = React6.useCallback(
|
|
3786
|
+
(event) => {
|
|
3787
|
+
let direction;
|
|
3788
|
+
switch (event.key) {
|
|
3789
|
+
case "ArrowRight":
|
|
3790
|
+
direction = "next";
|
|
3791
|
+
break;
|
|
3792
|
+
case "ArrowLeft":
|
|
3793
|
+
direction = "previous";
|
|
3794
|
+
break;
|
|
3795
|
+
case "Home":
|
|
3796
|
+
direction = "start";
|
|
3797
|
+
break;
|
|
3798
|
+
case "End":
|
|
3799
|
+
direction = "end";
|
|
3800
|
+
break;
|
|
3801
|
+
default:
|
|
3802
|
+
return;
|
|
3803
|
+
}
|
|
3804
|
+
event.preventDefault();
|
|
3805
|
+
const nextValue = moveTabSelection(itemStates, resolvedActiveTab, direction);
|
|
3806
|
+
if (!nextValue) {
|
|
3807
|
+
return;
|
|
3808
|
+
}
|
|
3809
|
+
selectTab(nextValue);
|
|
3810
|
+
const nextTabId = a11yIds.tabIds[nextValue];
|
|
3811
|
+
if (nextTabId) {
|
|
3812
|
+
focusTab(nextTabId);
|
|
3813
|
+
}
|
|
3814
|
+
},
|
|
3815
|
+
[a11yIds.tabIds, itemStates, resolvedActiveTab, selectTab]
|
|
3816
|
+
);
|
|
3817
|
+
return /* @__PURE__ */ jsxs("section", { className: cx16("mw-tab-group", props.className), ...props.dataAttributes, children: [
|
|
3818
|
+
hasLabel && /* @__PURE__ */ jsx("div", { className: "mw-tab-group__header", children: /* @__PURE__ */ jsx(Paragraph, { size: "md", id: a11yIds.labelId ?? `${id}-label`, children: props.label }) }),
|
|
3819
|
+
/* @__PURE__ */ jsx(
|
|
3820
|
+
"div",
|
|
3821
|
+
{
|
|
3822
|
+
id: a11yIds.tabListId,
|
|
3823
|
+
className: "mw-tab-group__list",
|
|
3824
|
+
role: "tablist",
|
|
3825
|
+
"aria-label": hasLabel ? void 0 : props.ariaLabel ?? "Tabs",
|
|
3826
|
+
"aria-labelledby": hasLabel ? a11yIds.labelId : void 0,
|
|
3827
|
+
onKeyDown: handleKeyDown,
|
|
3828
|
+
children: props.tabs.map((tab) => {
|
|
3829
|
+
const tabId = a11yIds.tabIds[tab.value] ?? `${id}-tab-${tab.value}`;
|
|
3830
|
+
const panelId = a11yIds.panelIds[tab.value] ?? `${id}-panel-${tab.value}`;
|
|
3831
|
+
const tabProps = {
|
|
3832
|
+
id: tabId,
|
|
3833
|
+
selected: tab.value === resolvedActiveTab,
|
|
3834
|
+
ariaControls: panelId,
|
|
3835
|
+
onClick: () => selectTab(tab.value)
|
|
3836
|
+
};
|
|
3837
|
+
if (tab.disabled) {
|
|
3838
|
+
tabProps.disabled = true;
|
|
3839
|
+
}
|
|
3840
|
+
if (tab.ariaLabel) {
|
|
3841
|
+
tabProps.ariaLabel = tab.ariaLabel;
|
|
3842
|
+
}
|
|
3843
|
+
return /* @__PURE__ */ jsx(Tab, { ...tabProps, children: tab.label }, tab.value);
|
|
3844
|
+
})
|
|
3845
|
+
}
|
|
3846
|
+
),
|
|
3847
|
+
/* @__PURE__ */ jsx("div", { className: "mw-tab-group__panels", children: props.tabs.map((tab) => {
|
|
3848
|
+
const panelId = a11yIds.panelIds[tab.value] ?? `${id}-panel-${tab.value}`;
|
|
3849
|
+
const tabId = a11yIds.tabIds[tab.value] ?? `${id}-tab-${tab.value}`;
|
|
3850
|
+
return /* @__PURE__ */ jsx(
|
|
3851
|
+
TabPanel,
|
|
3852
|
+
{
|
|
3853
|
+
id: panelId,
|
|
3854
|
+
tabId,
|
|
3855
|
+
hidden: tab.value !== resolvedActiveTab,
|
|
3856
|
+
children: tab.panel
|
|
3857
|
+
},
|
|
3858
|
+
tab.value
|
|
3859
|
+
);
|
|
3860
|
+
}) })
|
|
3861
|
+
] });
|
|
3862
|
+
}
|
|
3863
|
+
function NavigationTabs(props) {
|
|
3864
|
+
return /* @__PURE__ */ jsx(
|
|
3865
|
+
TabGroup,
|
|
3866
|
+
{
|
|
3867
|
+
...props,
|
|
3868
|
+
ariaLabel: props.ariaLabel ?? "Navigation tabs",
|
|
3869
|
+
dataAttributes: {
|
|
3870
|
+
...props.dataAttributes,
|
|
3871
|
+
"data-purpose": "navigation-tabs"
|
|
3872
|
+
}
|
|
3873
|
+
}
|
|
3874
|
+
);
|
|
3875
|
+
}
|
|
3876
|
+
function ContentTabs(props) {
|
|
3877
|
+
return /* @__PURE__ */ jsx(
|
|
3878
|
+
TabGroup,
|
|
3879
|
+
{
|
|
3880
|
+
...props,
|
|
3881
|
+
ariaLabel: props.ariaLabel ?? "Content tabs",
|
|
3882
|
+
dataAttributes: {
|
|
3883
|
+
...props.dataAttributes,
|
|
3884
|
+
"data-purpose": "content-tabs"
|
|
3885
|
+
}
|
|
3886
|
+
}
|
|
3887
|
+
);
|
|
3888
|
+
}
|
|
3889
|
+
function SettingsTabs(props) {
|
|
3890
|
+
return /* @__PURE__ */ jsx(
|
|
3891
|
+
TabGroup,
|
|
3892
|
+
{
|
|
3893
|
+
...props,
|
|
3894
|
+
ariaLabel: props.ariaLabel ?? "Settings tabs",
|
|
3895
|
+
dataAttributes: {
|
|
3896
|
+
...props.dataAttributes,
|
|
3897
|
+
"data-purpose": "settings-tabs"
|
|
3898
|
+
}
|
|
3899
|
+
}
|
|
3900
|
+
);
|
|
3901
|
+
}
|
|
3902
|
+
function cx17(...parts) {
|
|
3903
|
+
return parts.filter(Boolean).join(" ");
|
|
3904
|
+
}
|
|
3905
|
+
function hasContent8(value) {
|
|
3906
|
+
if (value === void 0 || value === null || value === false) {
|
|
3907
|
+
return false;
|
|
3908
|
+
}
|
|
3909
|
+
if (typeof value === "string") {
|
|
3910
|
+
return value.trim().length > 0;
|
|
3911
|
+
}
|
|
3912
|
+
return true;
|
|
3913
|
+
}
|
|
3914
|
+
function Dialog(props) {
|
|
3915
|
+
const reactId = React6.useId();
|
|
3916
|
+
const id = props.id ?? `mw-dialog-${reactId}`;
|
|
3917
|
+
const titleId = `${id}-title`;
|
|
3918
|
+
const descriptionId = `${id}-description`;
|
|
3919
|
+
const hasTitle = hasContent8(props.title);
|
|
3920
|
+
const hasDescription = hasContent8(props.description);
|
|
3921
|
+
const hasFooter = hasContent8(props.footer) && (props.showFooter ?? true);
|
|
3922
|
+
const dismissible = (props.dismissible ?? true) && props.onClose !== void 0;
|
|
3923
|
+
const dialogOptions = {
|
|
3924
|
+
showFooter: hasFooter,
|
|
3925
|
+
dismissible,
|
|
3926
|
+
...props.modal !== void 0 ? { modal: props.modal } : {}
|
|
3927
|
+
};
|
|
3928
|
+
if (props.dataAttributes) {
|
|
3929
|
+
dialogOptions.dataAttributes = props.dataAttributes;
|
|
3930
|
+
}
|
|
3931
|
+
if (props.size) {
|
|
3932
|
+
dialogOptions.size = props.size;
|
|
3933
|
+
}
|
|
3934
|
+
if (props.ariaLabel) {
|
|
3935
|
+
dialogOptions.ariaLabel = props.ariaLabel;
|
|
3936
|
+
}
|
|
3937
|
+
if (props.ariaLabelledBy) {
|
|
3938
|
+
dialogOptions.ariaLabelledBy = props.ariaLabelledBy;
|
|
3939
|
+
} else if (props.ariaLabel === void 0 && hasTitle) {
|
|
3940
|
+
dialogOptions.ariaLabelledBy = titleId;
|
|
3941
|
+
}
|
|
3942
|
+
if (props.ariaDescribedBy) {
|
|
3943
|
+
dialogOptions.ariaDescribedBy = props.ariaDescribedBy;
|
|
3944
|
+
} else if (hasDescription) {
|
|
3945
|
+
dialogOptions.ariaDescribedBy = descriptionId;
|
|
3946
|
+
}
|
|
3947
|
+
const kit = createDialogRecipe(dialogOptions);
|
|
3948
|
+
return /* @__PURE__ */ jsxs(
|
|
3949
|
+
"section",
|
|
3950
|
+
{
|
|
3951
|
+
id,
|
|
3952
|
+
className: cx17(kit.className, props.className),
|
|
3953
|
+
role: kit.a11y.role,
|
|
3954
|
+
...kit.a11y.ariaModal ? { "aria-modal": "true" } : {},
|
|
3955
|
+
...kit.a11y.ariaLabel ? { "aria-label": kit.a11y.ariaLabel } : {},
|
|
3956
|
+
...kit.a11y.ariaLabelledBy ? { "aria-labelledby": kit.a11y.ariaLabelledBy } : {},
|
|
3957
|
+
...kit.a11y.ariaDescribedBy ? { "aria-describedby": kit.a11y.ariaDescribedBy } : {},
|
|
3958
|
+
tabIndex: -1,
|
|
3959
|
+
...kit.dataAttributes,
|
|
3960
|
+
children: [
|
|
3961
|
+
(hasTitle || kit.showCloseButton) && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3962
|
+
/* @__PURE__ */ jsxs("header", { className: "mw-dialog__header", children: [
|
|
3963
|
+
hasTitle ? /* @__PURE__ */ jsx("div", { className: "mw-dialog__heading-group", children: /* @__PURE__ */ jsx("h2", { className: "mw-dialog__title", id: titleId, children: props.title }) }) : /* @__PURE__ */ jsx("span", { className: "mw-dialog__spacer", "aria-hidden": "true" }),
|
|
3964
|
+
kit.showCloseButton && props.onClose && /* @__PURE__ */ jsx(
|
|
3965
|
+
"button",
|
|
3966
|
+
{
|
|
3967
|
+
type: "button",
|
|
3968
|
+
className: "mw-dialog__close",
|
|
3969
|
+
"aria-label": "Close dialog",
|
|
3970
|
+
onClick: props.onClose,
|
|
3971
|
+
children: /* @__PURE__ */ jsx(Icon, { name: IconName.X, decorative: true })
|
|
3972
|
+
}
|
|
3973
|
+
)
|
|
3974
|
+
] }),
|
|
3975
|
+
/* @__PURE__ */ jsx("div", { className: "mw-dialog__header-divider", "aria-hidden": "true" })
|
|
3976
|
+
] }),
|
|
3977
|
+
/* @__PURE__ */ jsxs("div", { className: "mw-dialog__content", children: [
|
|
3978
|
+
hasDescription && /* @__PURE__ */ jsx("p", { className: "mw-dialog__description", id: descriptionId, children: props.description }),
|
|
3979
|
+
props.children
|
|
3980
|
+
] }),
|
|
3981
|
+
hasFooter && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3982
|
+
/* @__PURE__ */ jsx("div", { className: "mw-dialog__footer-divider", "aria-hidden": "true" }),
|
|
3983
|
+
/* @__PURE__ */ jsx("footer", { className: "mw-dialog__footer", children: props.footer })
|
|
3984
|
+
] })
|
|
3985
|
+
]
|
|
3986
|
+
}
|
|
3987
|
+
);
|
|
3988
|
+
}
|
|
3989
|
+
function cx18(...parts) {
|
|
3990
|
+
return parts.filter(Boolean).join(" ");
|
|
3991
|
+
}
|
|
3992
|
+
function getFocusableElements(container) {
|
|
3993
|
+
if (!container) {
|
|
3994
|
+
return [];
|
|
3995
|
+
}
|
|
3996
|
+
return Array.from(
|
|
3997
|
+
container.querySelectorAll(
|
|
3998
|
+
[
|
|
3999
|
+
"button:not([disabled])",
|
|
4000
|
+
"[href]",
|
|
4001
|
+
"input:not([disabled])",
|
|
4002
|
+
"select:not([disabled])",
|
|
4003
|
+
"textarea:not([disabled])",
|
|
4004
|
+
"[tabindex]:not([tabindex='-1'])"
|
|
4005
|
+
].join(",")
|
|
4006
|
+
)
|
|
4007
|
+
).filter(
|
|
4008
|
+
(element) => !element.hasAttribute("hidden") && element.getAttribute("aria-hidden") !== "true"
|
|
4009
|
+
);
|
|
4010
|
+
}
|
|
4011
|
+
function focusFirstElement(container) {
|
|
4012
|
+
const focusableElements = getFocusableElements(container);
|
|
4013
|
+
const firstFocusable = focusableElements[0];
|
|
4014
|
+
if (firstFocusable) {
|
|
4015
|
+
firstFocusable.focus();
|
|
4016
|
+
return;
|
|
4017
|
+
}
|
|
4018
|
+
container?.focus();
|
|
4019
|
+
}
|
|
4020
|
+
function DialogModal(props) {
|
|
4021
|
+
const {
|
|
4022
|
+
open,
|
|
4023
|
+
defaultOpen = false,
|
|
4024
|
+
onOpenChange,
|
|
4025
|
+
closeOnEscape = true,
|
|
4026
|
+
closeOnScrimClick = true,
|
|
4027
|
+
restoreFocus = true,
|
|
4028
|
+
portalTarget,
|
|
4029
|
+
overlayClassName,
|
|
4030
|
+
footer,
|
|
4031
|
+
...dialogProps
|
|
4032
|
+
} = props;
|
|
4033
|
+
const isControlled = open !== void 0;
|
|
4034
|
+
const [internalOpen, setInternalOpen] = React6.useState(defaultOpen);
|
|
4035
|
+
const resolvedOpen = isControlled ? open : internalOpen;
|
|
4036
|
+
const overlayRef = React6.useRef(null);
|
|
4037
|
+
const surfaceRef = React6.useRef(null);
|
|
4038
|
+
const lastFocusedElementRef = React6.useRef(null);
|
|
4039
|
+
const close = React6.useCallback(() => {
|
|
4040
|
+
if (!resolvedOpen) {
|
|
4041
|
+
return;
|
|
4042
|
+
}
|
|
4043
|
+
if (!isControlled) {
|
|
4044
|
+
setInternalOpen(false);
|
|
4045
|
+
}
|
|
4046
|
+
onOpenChange?.(false);
|
|
4047
|
+
}, [isControlled, onOpenChange, resolvedOpen]);
|
|
4048
|
+
React6.useEffect(() => {
|
|
4049
|
+
if (!resolvedOpen || typeof document === "undefined") {
|
|
4050
|
+
return;
|
|
4051
|
+
}
|
|
4052
|
+
const previousOverflow = document.body.style.overflow;
|
|
4053
|
+
lastFocusedElementRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
4054
|
+
document.body.style.overflow = "hidden";
|
|
4055
|
+
const frameId = window.requestAnimationFrame(() => {
|
|
4056
|
+
const dialogElement = overlayRef.current?.querySelector(".mw-dialog") ?? null;
|
|
4057
|
+
focusFirstElement(dialogElement);
|
|
4058
|
+
});
|
|
4059
|
+
return () => {
|
|
4060
|
+
window.cancelAnimationFrame(frameId);
|
|
4061
|
+
document.body.style.overflow = previousOverflow;
|
|
4062
|
+
if (restoreFocus) {
|
|
4063
|
+
lastFocusedElementRef.current?.focus();
|
|
4064
|
+
}
|
|
4065
|
+
};
|
|
4066
|
+
}, [resolvedOpen, restoreFocus]);
|
|
4067
|
+
React6.useEffect(() => {
|
|
4068
|
+
if (!resolvedOpen || !closeOnEscape || typeof document === "undefined") {
|
|
4069
|
+
return;
|
|
4070
|
+
}
|
|
4071
|
+
const handleKeyDown2 = (event) => {
|
|
4072
|
+
if (event.key === "Escape") {
|
|
4073
|
+
event.preventDefault();
|
|
4074
|
+
close();
|
|
4075
|
+
}
|
|
4076
|
+
};
|
|
4077
|
+
document.addEventListener("keydown", handleKeyDown2);
|
|
4078
|
+
return () => {
|
|
4079
|
+
document.removeEventListener("keydown", handleKeyDown2);
|
|
4080
|
+
};
|
|
4081
|
+
}, [close, closeOnEscape, resolvedOpen]);
|
|
4082
|
+
const handleKeyDown = React6.useCallback(
|
|
4083
|
+
(event) => {
|
|
4084
|
+
if (event.key === "Escape" && closeOnEscape) {
|
|
4085
|
+
event.preventDefault();
|
|
4086
|
+
event.stopPropagation();
|
|
4087
|
+
close();
|
|
4088
|
+
return;
|
|
4089
|
+
}
|
|
4090
|
+
if (event.key !== "Tab") {
|
|
4091
|
+
return;
|
|
4092
|
+
}
|
|
4093
|
+
const dialogElement = overlayRef.current?.querySelector(".mw-dialog") ?? null;
|
|
4094
|
+
const focusableElements = getFocusableElements(dialogElement);
|
|
4095
|
+
if (focusableElements.length === 0) {
|
|
4096
|
+
event.preventDefault();
|
|
4097
|
+
dialogElement?.focus();
|
|
4098
|
+
return;
|
|
4099
|
+
}
|
|
4100
|
+
const firstFocusable = focusableElements[0];
|
|
4101
|
+
const lastFocusable = focusableElements[focusableElements.length - 1];
|
|
4102
|
+
const activeElement = document.activeElement;
|
|
4103
|
+
if (event.shiftKey && activeElement === firstFocusable) {
|
|
4104
|
+
event.preventDefault();
|
|
4105
|
+
lastFocusable?.focus();
|
|
4106
|
+
} else if (!event.shiftKey && activeElement === lastFocusable) {
|
|
4107
|
+
event.preventDefault();
|
|
4108
|
+
firstFocusable?.focus();
|
|
4109
|
+
}
|
|
4110
|
+
},
|
|
4111
|
+
[close, closeOnEscape]
|
|
4112
|
+
);
|
|
4113
|
+
const renderedFooter = React6.useMemo(
|
|
4114
|
+
() => typeof footer === "function" ? footer({ close }) : footer,
|
|
4115
|
+
[close, footer]
|
|
4116
|
+
);
|
|
4117
|
+
if (!resolvedOpen || typeof document === "undefined") {
|
|
4118
|
+
return null;
|
|
4119
|
+
}
|
|
4120
|
+
const modalMarkup = /* @__PURE__ */ jsxs(
|
|
4121
|
+
"div",
|
|
4122
|
+
{
|
|
4123
|
+
ref: overlayRef,
|
|
4124
|
+
className: cx18("mw-dialog-modal", overlayClassName),
|
|
4125
|
+
onClick: (event) => {
|
|
4126
|
+
if (!closeOnScrimClick) {
|
|
4127
|
+
return;
|
|
4128
|
+
}
|
|
4129
|
+
const clickTarget = event.target;
|
|
4130
|
+
if (!(clickTarget instanceof Node)) {
|
|
4131
|
+
return;
|
|
4132
|
+
}
|
|
4133
|
+
if (surfaceRef.current?.contains(clickTarget)) {
|
|
4134
|
+
return;
|
|
4135
|
+
}
|
|
4136
|
+
close();
|
|
4137
|
+
},
|
|
4138
|
+
onKeyDown: handleKeyDown,
|
|
4139
|
+
children: [
|
|
4140
|
+
/* @__PURE__ */ jsx("div", { className: "mw-dialog-modal__scrim", "aria-hidden": "true" }),
|
|
4141
|
+
/* @__PURE__ */ jsx("div", { ref: surfaceRef, className: "mw-dialog-modal__surface", children: /* @__PURE__ */ jsx(Dialog, { ...dialogProps, modal: true, footer: renderedFooter, onClose: close }) })
|
|
4142
|
+
]
|
|
4143
|
+
}
|
|
4144
|
+
);
|
|
4145
|
+
if (portalTarget === null) {
|
|
4146
|
+
return modalMarkup;
|
|
4147
|
+
}
|
|
4148
|
+
return createPortal(modalMarkup, portalTarget ?? document.body);
|
|
4149
|
+
}
|
|
4150
|
+
function ConfirmDialog(props) {
|
|
4151
|
+
const {
|
|
4152
|
+
confirmLabel = "Confirm",
|
|
4153
|
+
cancelLabel = "Cancel",
|
|
4154
|
+
onConfirm,
|
|
4155
|
+
onCancel,
|
|
4156
|
+
dataAttributes,
|
|
4157
|
+
...dialogProps
|
|
4158
|
+
} = props;
|
|
4159
|
+
return /* @__PURE__ */ jsx(
|
|
4160
|
+
DialogModal,
|
|
4161
|
+
{
|
|
4162
|
+
...dialogProps,
|
|
4163
|
+
dataAttributes: {
|
|
4164
|
+
...dataAttributes,
|
|
4165
|
+
...createPurposeSemanticAttributes("confirm-dialog")
|
|
4166
|
+
},
|
|
4167
|
+
footer: ({ close }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4168
|
+
/* @__PURE__ */ jsx(
|
|
4169
|
+
CancelButton,
|
|
4170
|
+
{
|
|
4171
|
+
onClick: () => {
|
|
4172
|
+
onCancel?.();
|
|
4173
|
+
close();
|
|
4174
|
+
},
|
|
4175
|
+
children: cancelLabel
|
|
4176
|
+
}
|
|
4177
|
+
),
|
|
4178
|
+
/* @__PURE__ */ jsx(
|
|
4179
|
+
ConfirmButton,
|
|
4180
|
+
{
|
|
4181
|
+
onClick: () => {
|
|
4182
|
+
onConfirm?.();
|
|
4183
|
+
close();
|
|
4184
|
+
},
|
|
4185
|
+
children: confirmLabel
|
|
4186
|
+
}
|
|
4187
|
+
)
|
|
4188
|
+
] })
|
|
4189
|
+
}
|
|
4190
|
+
);
|
|
4191
|
+
}
|
|
4192
|
+
function DestructiveDialog(props) {
|
|
4193
|
+
const {
|
|
4194
|
+
confirmLabel = "Delete",
|
|
4195
|
+
cancelLabel = "Cancel",
|
|
4196
|
+
onConfirm,
|
|
4197
|
+
onCancel,
|
|
4198
|
+
dataAttributes,
|
|
4199
|
+
...dialogProps
|
|
4200
|
+
} = props;
|
|
4201
|
+
return /* @__PURE__ */ jsx(
|
|
4202
|
+
DialogModal,
|
|
4203
|
+
{
|
|
4204
|
+
...dialogProps,
|
|
4205
|
+
dataAttributes: {
|
|
4206
|
+
...dataAttributes,
|
|
4207
|
+
...createPurposeSemanticAttributes("destructive-dialog")
|
|
4208
|
+
},
|
|
4209
|
+
footer: ({ close }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4210
|
+
/* @__PURE__ */ jsx(
|
|
4211
|
+
CancelButton,
|
|
4212
|
+
{
|
|
4213
|
+
onClick: () => {
|
|
4214
|
+
onCancel?.();
|
|
4215
|
+
close();
|
|
4216
|
+
},
|
|
4217
|
+
children: cancelLabel
|
|
4218
|
+
}
|
|
4219
|
+
),
|
|
4220
|
+
/* @__PURE__ */ jsx(
|
|
4221
|
+
DestructiveButton,
|
|
4222
|
+
{
|
|
4223
|
+
onClick: () => {
|
|
4224
|
+
onConfirm?.();
|
|
4225
|
+
close();
|
|
4226
|
+
},
|
|
4227
|
+
children: confirmLabel
|
|
4228
|
+
}
|
|
4229
|
+
)
|
|
4230
|
+
] })
|
|
4231
|
+
}
|
|
4232
|
+
);
|
|
4233
|
+
}
|
|
4234
|
+
function InfoDialog(props) {
|
|
4235
|
+
const { acknowledgeLabel = "Okay", onAcknowledge, dataAttributes, ...dialogProps } = props;
|
|
4236
|
+
return /* @__PURE__ */ jsx(
|
|
4237
|
+
DialogModal,
|
|
4238
|
+
{
|
|
4239
|
+
...dialogProps,
|
|
4240
|
+
dataAttributes: {
|
|
4241
|
+
...dataAttributes,
|
|
4242
|
+
...createPurposeSemanticAttributes("info-dialog")
|
|
4243
|
+
},
|
|
4244
|
+
footer: ({ close }) => /* @__PURE__ */ jsx(
|
|
4245
|
+
ConfirmButton,
|
|
4246
|
+
{
|
|
4247
|
+
onClick: () => {
|
|
4248
|
+
onAcknowledge?.();
|
|
4249
|
+
close();
|
|
4250
|
+
},
|
|
4251
|
+
children: acknowledgeLabel
|
|
4252
|
+
}
|
|
4253
|
+
)
|
|
4254
|
+
}
|
|
4255
|
+
);
|
|
524
4256
|
}
|
|
525
4257
|
|
|
526
|
-
export { Button, CancelButton, Checkbox, CheckboxField, CreateButton, CurrencyField,
|
|
4258
|
+
export { Accordion, AccordionField, Avatar, AvatarBadge, AvatarGroup, Badge, BadgeGroup, BrightnessSlider, Button, ButtonSpinner, CancelButton, Card, Checkbox, CheckboxField, CheckboxGroupField, CloseButton, ConfirmButton, ConfirmDialog, ContentTabs, CopyButton, CreateButton, CurrencyField, DateOfBirthField, DestructiveButton, DestructiveDialog, Dialog, DialogModal, Divider, DownloadButton, DropdownButton, DropdownField, EditButton, EmailField, EmptyStateSpinner, ErrorToast, FAQAccordion, FeatureToggle, FilterButton, H1, H2, H3, Icon, InfoDialog, InfoToast, Input, InputField, InputOtp, LinkButton, MarwesProvider, NavigationTabs, NotificationBadge, OptionRadioGroup, Paragraph, PasswordField, PermissionSwitch, PhoneField, PreferenceSwitch, PresenceAvatar, PrimaryButton, PriorityBadge, ProductCard, ProfileAvatar, ProfileCard, Radio, RadioGroupField, RadiusSlider, RatingRadioGroup, RefreshButton, RichText, RichTextField, SaveButton, SearchButton, SearchField, SecondaryButton, SectionsAccordion, Select, SelectField, SettingsAccordion, SettingsTabs, Slider, SliderField, SortButton, Spacer, Spacing, Spinner, StatCard, StatusBadge, SubmitButton, SuccessButton, SuccessToast, Switch, SwitchField, Tab, TabGroup, TabPanel, TeamAvatarGroup, TextButton, Textarea, TextareaField, Toast, ToastContainer, ToastProvider, Tooltip, TooltipGroup, URLField, UploadButton, VerifyButton, VolumeSlider, WarningToast, YesNoRadioGroup, ZipCodeField, useTheme, useThemeMode, useToast };
|
|
527
4259
|
//# sourceMappingURL=index.js.map
|
|
528
4260
|
//# sourceMappingURL=index.js.map
|