@marwes-ui/react 1.0.1 → 1.0.3
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/README.md +67 -1
- package/dist/index.d.ts +18 -3
- package/dist/index.js +260 -112
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
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';
|
|
2
|
+
import { createRichTextRecipe, resolveRichTextAllowedFormats, normalizeRichTextHtml, isRichTextHtmlEmpty, createDividerRecipe, createSpacingRecipe, createSliderRecipe, richTextCommandByFormat, resolveIconSize, resolveIconStrokeWidth, iconRegistry, resolveIconA11y, ThemeMode, resolveThemePreference, nextThemeMode, 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, isThemePreference, themeToCSSVars, extractUsedWeights, extractFontFamilyName, shouldLoadGoogleFont, buildGoogleFontsUrl } from '@marwes-ui/core';
|
|
3
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
|
|
4
|
+
import * as React2 from 'react';
|
|
5
5
|
import { useEffect } from 'react';
|
|
6
6
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
7
7
|
import { createPortal } from 'react-dom';
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
|
-
var MarwesContext =
|
|
10
|
+
var MarwesContext = React2.createContext(null);
|
|
11
11
|
var loadedFonts = /* @__PURE__ */ new Set();
|
|
12
12
|
var preconnected = false;
|
|
13
13
|
function themeToRootStyle(theme) {
|
|
@@ -62,47 +62,191 @@ function loadThemeFonts(theme, config = "auto") {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
+
var mediaQuery = "(prefers-color-scheme: dark)";
|
|
66
|
+
function getSystemThemeMode() {
|
|
67
|
+
if (typeof window === "undefined") return ThemeMode.light;
|
|
68
|
+
return window.matchMedia?.(mediaQuery).matches ? ThemeMode.dark : ThemeMode.light;
|
|
69
|
+
}
|
|
70
|
+
function subscribeToSystemThemeMode(onChange) {
|
|
71
|
+
if (typeof window === "undefined" || !window.matchMedia) return () => {
|
|
72
|
+
};
|
|
73
|
+
const media = window.matchMedia(mediaQuery);
|
|
74
|
+
const listener = (event) => {
|
|
75
|
+
onChange(event.matches ? ThemeMode.dark : ThemeMode.light);
|
|
76
|
+
};
|
|
77
|
+
if (media.addEventListener) {
|
|
78
|
+
media.addEventListener("change", listener);
|
|
79
|
+
} else {
|
|
80
|
+
media.addListener?.(listener);
|
|
81
|
+
}
|
|
82
|
+
return () => {
|
|
83
|
+
if (media.removeEventListener) {
|
|
84
|
+
media.removeEventListener("change", listener);
|
|
85
|
+
} else {
|
|
86
|
+
media.removeListener?.(listener);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function readStoredThemePreference(storageKey) {
|
|
91
|
+
if (!storageKey || typeof window === "undefined") return void 0;
|
|
92
|
+
try {
|
|
93
|
+
const value = window.localStorage.getItem(storageKey);
|
|
94
|
+
return isThemePreference(value) ? value : void 0;
|
|
95
|
+
} catch {
|
|
96
|
+
return void 0;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function writeStoredThemePreference(storageKey, preference) {
|
|
100
|
+
if (!storageKey || typeof window === "undefined") return;
|
|
101
|
+
try {
|
|
102
|
+
window.localStorage.setItem(storageKey, preference);
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function applyModeAttribute({
|
|
107
|
+
target,
|
|
108
|
+
providerElement,
|
|
109
|
+
mode,
|
|
110
|
+
attribute
|
|
111
|
+
}) {
|
|
112
|
+
const element = getTargetElement(target, providerElement);
|
|
113
|
+
if (!element) return;
|
|
114
|
+
if (attribute === "class") {
|
|
115
|
+
const oppositeMode = mode === ThemeMode.dark ? ThemeMode.light : ThemeMode.dark;
|
|
116
|
+
element.classList.remove(oppositeMode);
|
|
117
|
+
element.classList.add(mode);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
element.setAttribute(attribute, mode);
|
|
121
|
+
}
|
|
122
|
+
function withoutModeTransitions(callback) {
|
|
123
|
+
if (typeof document === "undefined" || typeof window === "undefined") {
|
|
124
|
+
callback();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const style = document.createElement("style");
|
|
128
|
+
style.dataset.marwesDisableTransitions = "true";
|
|
129
|
+
style.textContent = "* { transition: none !important; }";
|
|
130
|
+
document.head.appendChild(style);
|
|
131
|
+
callback();
|
|
132
|
+
window.getComputedStyle(document.body);
|
|
133
|
+
window.requestAnimationFrame(() => {
|
|
134
|
+
style.remove();
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function getTargetElement(target, providerElement) {
|
|
138
|
+
if (target === "provider") return providerElement;
|
|
139
|
+
if (typeof document === "undefined") return null;
|
|
140
|
+
return target === "html" ? document.documentElement : document.body;
|
|
141
|
+
}
|
|
65
142
|
function MarwesProvider({
|
|
66
143
|
theme,
|
|
67
|
-
|
|
144
|
+
defaultPreference,
|
|
145
|
+
preference: controlledPreference,
|
|
146
|
+
defaultMode,
|
|
68
147
|
mode: controlledMode,
|
|
69
148
|
fontLoading = "auto",
|
|
149
|
+
onPreferenceChange,
|
|
70
150
|
onModeChange,
|
|
151
|
+
storageKey = false,
|
|
152
|
+
enableSystem = true,
|
|
153
|
+
target = "provider",
|
|
154
|
+
attribute = "class",
|
|
155
|
+
disableTransitionOnChange = false,
|
|
71
156
|
children
|
|
72
157
|
}) {
|
|
73
|
-
const rootRef =
|
|
74
|
-
const [
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
(
|
|
79
|
-
|
|
80
|
-
|
|
158
|
+
const rootRef = React2.useRef(null);
|
|
159
|
+
const [internalPreference, setInternalPreference] = React2.useState(
|
|
160
|
+
defaultPreference ?? defaultMode ?? ThemeMode.light
|
|
161
|
+
);
|
|
162
|
+
const [systemMode, setSystemMode] = React2.useState(
|
|
163
|
+
() => enableSystem ? getSystemThemeMode() : ThemeMode.light
|
|
164
|
+
);
|
|
165
|
+
const activePreference = controlledPreference ?? controlledMode ?? theme?.mode ?? internalPreference;
|
|
166
|
+
const activeMode = resolveThemePreference(activePreference, systemMode);
|
|
167
|
+
const isPreferenceControlled = controlledPreference !== void 0 || controlledMode !== void 0 || theme?.mode !== void 0;
|
|
168
|
+
React2.useEffect(() => {
|
|
169
|
+
const storedPreference = readStoredThemePreference(storageKey);
|
|
170
|
+
if (storedPreference !== void 0 && !isPreferenceControlled) {
|
|
171
|
+
setInternalPreference(storedPreference);
|
|
172
|
+
}
|
|
173
|
+
}, [isPreferenceControlled, storageKey]);
|
|
174
|
+
React2.useEffect(() => {
|
|
175
|
+
if (!enableSystem) {
|
|
176
|
+
setSystemMode(ThemeMode.light);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
setSystemMode(getSystemThemeMode());
|
|
180
|
+
if (activePreference !== "system") {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
return subscribeToSystemThemeMode(setSystemMode);
|
|
184
|
+
}, [activePreference, enableSystem]);
|
|
185
|
+
const setPreference = React2.useCallback(
|
|
186
|
+
(nextPreference) => {
|
|
187
|
+
if (!isPreferenceControlled) {
|
|
188
|
+
setInternalPreference(nextPreference);
|
|
81
189
|
}
|
|
190
|
+
writeStoredThemePreference(storageKey, nextPreference);
|
|
191
|
+
onPreferenceChange?.(nextPreference);
|
|
192
|
+
},
|
|
193
|
+
[isPreferenceControlled, onPreferenceChange, storageKey]
|
|
194
|
+
);
|
|
195
|
+
const setMode = React2.useCallback(
|
|
196
|
+
(nextMode) => {
|
|
197
|
+
setPreference(nextMode);
|
|
82
198
|
onModeChange?.(nextMode);
|
|
83
199
|
},
|
|
84
|
-
[
|
|
200
|
+
[onModeChange, setPreference]
|
|
85
201
|
);
|
|
86
|
-
const toggleMode =
|
|
87
|
-
setMode(activeMode
|
|
202
|
+
const toggleMode = React2.useCallback(() => {
|
|
203
|
+
setMode(nextThemeMode(activeMode));
|
|
88
204
|
}, [activeMode, setMode]);
|
|
89
|
-
const resolved =
|
|
205
|
+
const resolved = React2.useMemo(
|
|
90
206
|
() => resolveThemeInput({ ...theme ?? {}, mode: activeMode }),
|
|
91
207
|
[activeMode, theme]
|
|
92
208
|
);
|
|
93
|
-
const rootStyle =
|
|
209
|
+
const rootStyle = React2.useMemo(
|
|
94
210
|
() => themeToRootStyle(resolved),
|
|
95
211
|
[resolved]
|
|
96
212
|
);
|
|
97
|
-
|
|
213
|
+
React2.useEffect(() => {
|
|
98
214
|
if (rootRef.current) {
|
|
99
215
|
applyThemeToElement(rootRef.current, resolved);
|
|
100
216
|
}
|
|
101
217
|
}, [resolved]);
|
|
102
|
-
|
|
218
|
+
React2.useEffect(() => {
|
|
219
|
+
if (target === "provider") return;
|
|
220
|
+
const apply = () => {
|
|
221
|
+
applyModeAttribute({
|
|
222
|
+
target,
|
|
223
|
+
providerElement: rootRef.current,
|
|
224
|
+
mode: activeMode,
|
|
225
|
+
attribute
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
if (disableTransitionOnChange) {
|
|
229
|
+
withoutModeTransitions(apply);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
apply();
|
|
233
|
+
}, [activeMode, attribute, disableTransitionOnChange, target]);
|
|
234
|
+
React2.useEffect(() => {
|
|
103
235
|
loadThemeFonts(resolved, fontLoading);
|
|
104
236
|
}, [resolved, fontLoading]);
|
|
105
|
-
|
|
237
|
+
const contextValue = React2.useMemo(
|
|
238
|
+
() => ({
|
|
239
|
+
theme: resolved,
|
|
240
|
+
mode: activeMode,
|
|
241
|
+
preference: activePreference,
|
|
242
|
+
systemMode,
|
|
243
|
+
setMode,
|
|
244
|
+
setPreference,
|
|
245
|
+
toggleMode
|
|
246
|
+
}),
|
|
247
|
+
[activeMode, activePreference, resolved, setMode, setPreference, systemMode, toggleMode]
|
|
248
|
+
);
|
|
249
|
+
return /* @__PURE__ */ jsx(MarwesContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
|
|
106
250
|
"div",
|
|
107
251
|
{
|
|
108
252
|
ref: rootRef,
|
|
@@ -114,23 +258,27 @@ function MarwesProvider({
|
|
|
114
258
|
) });
|
|
115
259
|
}
|
|
116
260
|
function useTheme() {
|
|
117
|
-
const ctx =
|
|
261
|
+
const ctx = React2.useContext(MarwesContext);
|
|
118
262
|
if (!ctx) {
|
|
119
263
|
throw new Error("MarwesProvider is missing. Wrap your app in <MarwesProvider />.");
|
|
120
264
|
}
|
|
121
265
|
return ctx.theme;
|
|
122
266
|
}
|
|
123
267
|
function useThemeMode() {
|
|
124
|
-
const ctx =
|
|
268
|
+
const ctx = React2.useContext(MarwesContext);
|
|
125
269
|
if (!ctx) {
|
|
126
270
|
throw new Error("MarwesProvider is missing. Wrap your app in <MarwesProvider />.");
|
|
127
271
|
}
|
|
128
272
|
return {
|
|
129
273
|
mode: ctx.mode,
|
|
274
|
+
preference: ctx.preference,
|
|
275
|
+
systemMode: ctx.systemMode,
|
|
130
276
|
setMode: ctx.setMode,
|
|
277
|
+
setPreference: ctx.setPreference,
|
|
131
278
|
toggleMode: ctx.toggleMode,
|
|
132
279
|
isDark: ctx.mode === ThemeMode.dark,
|
|
133
|
-
isLight: ctx.mode === ThemeMode.light
|
|
280
|
+
isLight: ctx.mode === ThemeMode.light,
|
|
281
|
+
isSystem: ctx.preference === "system"
|
|
134
282
|
};
|
|
135
283
|
}
|
|
136
284
|
function Icon({
|
|
@@ -798,7 +946,7 @@ function Select(props) {
|
|
|
798
946
|
const kit = createSelectRecipe(props);
|
|
799
947
|
const mode = resolveSelectMode(props);
|
|
800
948
|
const isControlled = props.value !== void 0;
|
|
801
|
-
const [uncontrolledValue, setUncontrolledValue] =
|
|
949
|
+
const [uncontrolledValue, setUncontrolledValue] = React2.useState(
|
|
802
950
|
() => getInitialSelectValue(props)
|
|
803
951
|
);
|
|
804
952
|
useRenderKitDebug(kit, "Select");
|
|
@@ -1014,33 +1162,33 @@ function exitActiveFormatAtCaret(editorElement, format) {
|
|
|
1014
1162
|
selection.addRange(nextRange);
|
|
1015
1163
|
return true;
|
|
1016
1164
|
}
|
|
1017
|
-
var RichText =
|
|
1165
|
+
var RichText = React2.forwardRef((props, forwardedRef) => {
|
|
1018
1166
|
const kit = createRichTextRecipe(props);
|
|
1019
|
-
const allowedFormats =
|
|
1167
|
+
const allowedFormats = React2.useMemo(
|
|
1020
1168
|
() => resolveRichTextAllowedFormats(props.allowedFormats),
|
|
1021
1169
|
[props.allowedFormats]
|
|
1022
1170
|
);
|
|
1023
|
-
const normalizedControlledValue =
|
|
1171
|
+
const normalizedControlledValue = React2.useMemo(
|
|
1024
1172
|
() => normalizeRichTextHtml(props.value),
|
|
1025
1173
|
[props.value]
|
|
1026
1174
|
);
|
|
1027
|
-
const initialUncontrolledValue =
|
|
1175
|
+
const initialUncontrolledValue = React2.useMemo(
|
|
1028
1176
|
() => normalizeRichTextHtml(props.defaultValue),
|
|
1029
1177
|
[props.defaultValue]
|
|
1030
1178
|
);
|
|
1031
1179
|
const isControlled = props.value !== void 0;
|
|
1032
|
-
const [uncontrolledHtml, setUncontrolledHtml] =
|
|
1033
|
-
const [isEditorEmpty, setIsEditorEmpty] =
|
|
1180
|
+
const [uncontrolledHtml, setUncontrolledHtml] = React2.useState(initialUncontrolledValue);
|
|
1181
|
+
const [isEditorEmpty, setIsEditorEmpty] = React2.useState(
|
|
1034
1182
|
isRichTextHtmlEmpty(isControlled ? normalizedControlledValue : initialUncontrolledValue)
|
|
1035
1183
|
);
|
|
1036
|
-
const [activeFormats, setActiveFormats] =
|
|
1037
|
-
const editorElementRef =
|
|
1184
|
+
const [activeFormats, setActiveFormats] = React2.useState([]);
|
|
1185
|
+
const editorElementRef = React2.useRef(null);
|
|
1038
1186
|
useRenderKitDebug(kit, "RichText");
|
|
1039
1187
|
const editorHtml = isControlled ? normalizedControlledValue : uncontrolledHtml;
|
|
1040
1188
|
const style = kit.vars;
|
|
1041
1189
|
const className = props.className ? `${kit.className} ${props.className}` : kit.className;
|
|
1042
1190
|
const showToolbar = !props.readOnly;
|
|
1043
|
-
const syncEditorState =
|
|
1191
|
+
const syncEditorState = React2.useCallback(
|
|
1044
1192
|
(nextHtml) => {
|
|
1045
1193
|
const normalizedHtml = normalizeRichTextHtml(nextHtml);
|
|
1046
1194
|
const emptyState = isRichTextHtmlEmpty(normalizedHtml);
|
|
@@ -1053,10 +1201,10 @@ var RichText = React6.forwardRef((props, forwardedRef) => {
|
|
|
1053
1201
|
},
|
|
1054
1202
|
[isControlled, props]
|
|
1055
1203
|
);
|
|
1056
|
-
const refreshActiveFormats =
|
|
1204
|
+
const refreshActiveFormats = React2.useCallback(() => {
|
|
1057
1205
|
setActiveFormats(getActiveFormatsFromSelection(editorElementRef.current));
|
|
1058
1206
|
}, []);
|
|
1059
|
-
|
|
1207
|
+
React2.useLayoutEffect(() => {
|
|
1060
1208
|
const editorElement = editorElementRef.current;
|
|
1061
1209
|
if (!editorElement) {
|
|
1062
1210
|
return;
|
|
@@ -1067,7 +1215,7 @@ var RichText = React6.forwardRef((props, forwardedRef) => {
|
|
|
1067
1215
|
}
|
|
1068
1216
|
setIsEditorEmpty(isRichTextHtmlEmpty(editorHtml));
|
|
1069
1217
|
}, [editorHtml]);
|
|
1070
|
-
|
|
1218
|
+
React2.useEffect(() => {
|
|
1071
1219
|
if (typeof document === "undefined") {
|
|
1072
1220
|
return void 0;
|
|
1073
1221
|
}
|
|
@@ -1212,12 +1360,12 @@ function hasTextContent(value) {
|
|
|
1212
1360
|
return value !== void 0 && value.trim().length > 0;
|
|
1213
1361
|
}
|
|
1214
1362
|
function InputField(props) {
|
|
1215
|
-
const reactId =
|
|
1363
|
+
const reactId = React2.useId();
|
|
1216
1364
|
const id = props.id ?? `mw-input-${reactId}`;
|
|
1217
1365
|
const isPasswordField = props.input.type === "password";
|
|
1218
|
-
const [showPassword, setShowPassword] =
|
|
1366
|
+
const [showPassword, setShowPassword] = React2.useState(false);
|
|
1219
1367
|
const isSearchField = props.input.type === "search";
|
|
1220
|
-
const [searchValue, setSearchValue] =
|
|
1368
|
+
const [searchValue, setSearchValue] = React2.useState(
|
|
1221
1369
|
props.input.value || props.input.defaultValue || ""
|
|
1222
1370
|
);
|
|
1223
1371
|
const hasSearchValue = isSearchField && (props.input.value !== void 0 ? String(props.input.value).length > 0 : String(searchValue).length > 0);
|
|
@@ -1312,14 +1460,14 @@ function hasTextContent2(value) {
|
|
|
1312
1460
|
return value !== void 0 && value.trim().length > 0;
|
|
1313
1461
|
}
|
|
1314
1462
|
function InputOtp(props) {
|
|
1315
|
-
const reactId =
|
|
1463
|
+
const reactId = React2.useId();
|
|
1316
1464
|
const id = props.id ?? `mw-input-otp-${reactId}`;
|
|
1317
1465
|
const otpLength = Math.max(1, props.length ?? 6);
|
|
1318
1466
|
const hasHelperText = hasTextContent2(props.helperText);
|
|
1319
1467
|
const hasError = hasTextContent2(props.error);
|
|
1320
1468
|
const invalid = hasError || props.invalid === true;
|
|
1321
1469
|
const isControlled = props.value !== void 0;
|
|
1322
|
-
const [uncontrolledValue, setUncontrolledValue] =
|
|
1470
|
+
const [uncontrolledValue, setUncontrolledValue] = React2.useState(() => {
|
|
1323
1471
|
return sanitizeInputOtpValue(props.defaultValue, otpLength);
|
|
1324
1472
|
});
|
|
1325
1473
|
const currentValue = sanitizeInputOtpValue(
|
|
@@ -1476,18 +1624,18 @@ function MarwesSelectFieldControl(props) {
|
|
|
1476
1624
|
const { id, select } = props;
|
|
1477
1625
|
const listboxId = `${id}-listbox`;
|
|
1478
1626
|
const isControlled = select.value !== void 0;
|
|
1479
|
-
const [internalValue, setInternalValue] =
|
|
1627
|
+
const [internalValue, setInternalValue] = React2.useState(() => getInitialSelectValue2(select));
|
|
1480
1628
|
const value = isControlled ? select.value ?? "" : internalValue;
|
|
1481
|
-
const [open, setOpen] =
|
|
1482
|
-
const [activeIndex, setActiveIndex] =
|
|
1629
|
+
const [open, setOpen] = React2.useState(false);
|
|
1630
|
+
const [activeIndex, setActiveIndex] = React2.useState(
|
|
1483
1631
|
() => getInitialActiveOptionIndex(select.options, value)
|
|
1484
1632
|
);
|
|
1485
|
-
const rootRef =
|
|
1486
|
-
const buttonRef =
|
|
1633
|
+
const rootRef = React2.useRef(null);
|
|
1634
|
+
const buttonRef = React2.useRef(null);
|
|
1487
1635
|
const selectedOption = select.options.find((option) => option.value === value) ?? (select.placeholder === void 0 ? select.options[0] : void 0);
|
|
1488
1636
|
const placeholderSelected = select.placeholder !== void 0 && value === "";
|
|
1489
1637
|
const displayText = placeholderSelected ? select.placeholder : selectedOption?.label ?? "";
|
|
1490
|
-
|
|
1638
|
+
React2.useEffect(() => {
|
|
1491
1639
|
if (!open) {
|
|
1492
1640
|
return;
|
|
1493
1641
|
}
|
|
@@ -1502,13 +1650,13 @@ function MarwesSelectFieldControl(props) {
|
|
|
1502
1650
|
document.removeEventListener("pointerdown", handlePointerDown);
|
|
1503
1651
|
};
|
|
1504
1652
|
}, [open]);
|
|
1505
|
-
|
|
1653
|
+
React2.useEffect(() => {
|
|
1506
1654
|
if (!open) {
|
|
1507
1655
|
return;
|
|
1508
1656
|
}
|
|
1509
1657
|
setActiveIndex(getInitialActiveOptionIndex(select.options, value));
|
|
1510
1658
|
}, [open, select.options, value]);
|
|
1511
|
-
|
|
1659
|
+
React2.useEffect(() => {
|
|
1512
1660
|
if (!select.disabled) {
|
|
1513
1661
|
return;
|
|
1514
1662
|
}
|
|
@@ -1707,7 +1855,7 @@ function MarwesSelectFieldControl(props) {
|
|
|
1707
1855
|
);
|
|
1708
1856
|
}
|
|
1709
1857
|
function SelectField(props) {
|
|
1710
|
-
const reactId =
|
|
1858
|
+
const reactId = React2.useId();
|
|
1711
1859
|
const id = props.id ?? `mw-select-${reactId}`;
|
|
1712
1860
|
const mode = resolveSelectMode(props.select);
|
|
1713
1861
|
const hasHelperText = hasTextContent3(props.helperText);
|
|
@@ -1753,7 +1901,7 @@ function hasTextContent4(value) {
|
|
|
1753
1901
|
return value !== void 0 && value.trim().length > 0;
|
|
1754
1902
|
}
|
|
1755
1903
|
function TextareaField(props) {
|
|
1756
|
-
const reactId =
|
|
1904
|
+
const reactId = React2.useId();
|
|
1757
1905
|
const id = props.id ?? `mw-textarea-${reactId}`;
|
|
1758
1906
|
const hasHelperText = hasTextContent4(props.helperText);
|
|
1759
1907
|
const hasError = hasTextContent4(props.error);
|
|
@@ -1799,9 +1947,9 @@ function hasTextContent5(value) {
|
|
|
1799
1947
|
return value !== void 0 && value.trim().length > 0;
|
|
1800
1948
|
}
|
|
1801
1949
|
function RichTextField(props) {
|
|
1802
|
-
const reactId =
|
|
1950
|
+
const reactId = React2.useId();
|
|
1803
1951
|
const id = props.id ?? `mw-rich-text-${reactId}`;
|
|
1804
|
-
const editorRef =
|
|
1952
|
+
const editorRef = React2.useRef(null);
|
|
1805
1953
|
const hasHelperText = hasTextContent5(props.helperText);
|
|
1806
1954
|
const hasError = hasTextContent5(props.error);
|
|
1807
1955
|
const { labelId, helperTextId, errorId, describedBy } = buildRichTextFieldA11yIds({
|
|
@@ -2168,8 +2316,8 @@ function TeamAvatarGroup(props) {
|
|
|
2168
2316
|
function Checkbox(props) {
|
|
2169
2317
|
const { onCheckedChange, onChange, ...coreProps } = props;
|
|
2170
2318
|
const kit = checkboxRecipe({ ...coreProps });
|
|
2171
|
-
const inputRef =
|
|
2172
|
-
|
|
2319
|
+
const inputRef = React2.useRef(null);
|
|
2320
|
+
React2.useLayoutEffect(() => {
|
|
2173
2321
|
const el = inputRef.current;
|
|
2174
2322
|
if (!el) return;
|
|
2175
2323
|
el.indeterminate = kit.indeterminate;
|
|
@@ -2215,7 +2363,7 @@ function hasContent(value) {
|
|
|
2215
2363
|
return true;
|
|
2216
2364
|
}
|
|
2217
2365
|
function CheckboxField(props) {
|
|
2218
|
-
const reactId =
|
|
2366
|
+
const reactId = React2.useId();
|
|
2219
2367
|
const id = props.id ?? `mw-checkbox-${reactId}`;
|
|
2220
2368
|
const hasDescription = hasContent(props.description);
|
|
2221
2369
|
const hasError = hasContent(props.error);
|
|
@@ -2269,7 +2417,7 @@ function orderSelectedValues(values, options) {
|
|
|
2269
2417
|
return [...knownValues, ...unknownValues];
|
|
2270
2418
|
}
|
|
2271
2419
|
function CheckboxGroupField(props) {
|
|
2272
|
-
const reactId =
|
|
2420
|
+
const reactId = React2.useId();
|
|
2273
2421
|
const id = props.id ?? `mw-checkbox-group-${reactId}`;
|
|
2274
2422
|
const hasDescription = hasContent2(props.description);
|
|
2275
2423
|
const hasError = hasContent2(props.error);
|
|
@@ -2281,7 +2429,7 @@ function CheckboxGroupField(props) {
|
|
|
2281
2429
|
externalDescribedBy: props.ariaDescribedBy
|
|
2282
2430
|
});
|
|
2283
2431
|
const isControlled = props.value !== void 0;
|
|
2284
|
-
const [internalValue, setInternalValue] =
|
|
2432
|
+
const [internalValue, setInternalValue] = React2.useState(
|
|
2285
2433
|
orderSelectedValues(props.defaultValue ?? [], props.options)
|
|
2286
2434
|
);
|
|
2287
2435
|
const selectedValues = orderSelectedValues(
|
|
@@ -2351,7 +2499,7 @@ function CheckboxGroupField(props) {
|
|
|
2351
2499
|
}
|
|
2352
2500
|
);
|
|
2353
2501
|
}
|
|
2354
|
-
var Divider =
|
|
2502
|
+
var Divider = React2.forwardRef((props, ref) => {
|
|
2355
2503
|
const { className: customClassName, style: customStyle, ...opts } = props;
|
|
2356
2504
|
const kit = createDividerRecipe(opts);
|
|
2357
2505
|
const style = { ...kit.vars, ...customStyle };
|
|
@@ -2359,7 +2507,7 @@ var Divider = React6.forwardRef((props, ref) => {
|
|
|
2359
2507
|
return /* @__PURE__ */ jsx("hr", { ref, ...kit.a11y, ...kit.dataAttributes, className, style });
|
|
2360
2508
|
});
|
|
2361
2509
|
Divider.displayName = "Divider";
|
|
2362
|
-
var Spacing =
|
|
2510
|
+
var Spacing = React2.forwardRef((props, ref) => {
|
|
2363
2511
|
const { className: customClassName, scale, size, spacing, style: customStyle } = props;
|
|
2364
2512
|
const resolvedSize = spacing ?? size;
|
|
2365
2513
|
const kit = createSpacingRecipe({
|
|
@@ -2594,12 +2742,12 @@ function renderToastByIntent(toast, onDismiss) {
|
|
|
2594
2742
|
}
|
|
2595
2743
|
}
|
|
2596
2744
|
function ToastViewportItem(props) {
|
|
2597
|
-
const timerHandleRef =
|
|
2598
|
-
const timerStartedAtRef =
|
|
2599
|
-
const remainingDurationRef =
|
|
2600
|
-
const pointerInsideRef =
|
|
2601
|
-
const focusInsideRef =
|
|
2602
|
-
const clearDismissTimer =
|
|
2745
|
+
const timerHandleRef = React2.useRef(null);
|
|
2746
|
+
const timerStartedAtRef = React2.useRef(null);
|
|
2747
|
+
const remainingDurationRef = React2.useRef(null);
|
|
2748
|
+
const pointerInsideRef = React2.useRef(false);
|
|
2749
|
+
const focusInsideRef = React2.useRef(false);
|
|
2750
|
+
const clearDismissTimer = React2.useCallback(() => {
|
|
2603
2751
|
if (timerHandleRef.current === null) {
|
|
2604
2752
|
return;
|
|
2605
2753
|
}
|
|
@@ -2607,7 +2755,7 @@ function ToastViewportItem(props) {
|
|
|
2607
2755
|
timerHandleRef.current = null;
|
|
2608
2756
|
timerStartedAtRef.current = null;
|
|
2609
2757
|
}, []);
|
|
2610
|
-
const scheduleDismissTimer =
|
|
2758
|
+
const scheduleDismissTimer = React2.useCallback(
|
|
2611
2759
|
(delay) => {
|
|
2612
2760
|
if (!props.onDismiss || delay <= 0 || pointerInsideRef.current || focusInsideRef.current || timerHandleRef.current !== null) {
|
|
2613
2761
|
return;
|
|
@@ -2622,7 +2770,7 @@ function ToastViewportItem(props) {
|
|
|
2622
2770
|
},
|
|
2623
2771
|
[props.onDismiss, props.toast.id]
|
|
2624
2772
|
);
|
|
2625
|
-
const pauseDismissTimer =
|
|
2773
|
+
const pauseDismissTimer = React2.useCallback(() => {
|
|
2626
2774
|
if (timerHandleRef.current === null || timerStartedAtRef.current === null) {
|
|
2627
2775
|
return;
|
|
2628
2776
|
}
|
|
@@ -2631,7 +2779,7 @@ function ToastViewportItem(props) {
|
|
|
2631
2779
|
remainingDurationRef.current = Math.max(remainingDuration - elapsed, 0);
|
|
2632
2780
|
clearDismissTimer();
|
|
2633
2781
|
}, [clearDismissTimer]);
|
|
2634
|
-
const resumeDismissTimer =
|
|
2782
|
+
const resumeDismissTimer = React2.useCallback(() => {
|
|
2635
2783
|
if (pointerInsideRef.current || focusInsideRef.current) {
|
|
2636
2784
|
return;
|
|
2637
2785
|
}
|
|
@@ -2641,7 +2789,7 @@ function ToastViewportItem(props) {
|
|
|
2641
2789
|
}
|
|
2642
2790
|
scheduleDismissTimer(remainingDuration);
|
|
2643
2791
|
}, [scheduleDismissTimer]);
|
|
2644
|
-
|
|
2792
|
+
React2.useEffect(() => {
|
|
2645
2793
|
clearDismissTimer();
|
|
2646
2794
|
pointerInsideRef.current = false;
|
|
2647
2795
|
focusInsideRef.current = false;
|
|
@@ -2698,18 +2846,18 @@ function ToastContainer(props) {
|
|
|
2698
2846
|
toast.id
|
|
2699
2847
|
)) });
|
|
2700
2848
|
}
|
|
2701
|
-
var ToastContext =
|
|
2849
|
+
var ToastContext = React2.createContext(null);
|
|
2702
2850
|
function ToastProvider(props) {
|
|
2703
|
-
const [toasts, setToasts] =
|
|
2704
|
-
const idRef =
|
|
2705
|
-
const dismiss =
|
|
2851
|
+
const [toasts, setToasts] = React2.useState([]);
|
|
2852
|
+
const idRef = React2.useRef(0);
|
|
2853
|
+
const dismiss = React2.useCallback((id) => {
|
|
2706
2854
|
setToasts((currentToasts) => {
|
|
2707
2855
|
const toast = currentToasts.find((item) => item.id === id);
|
|
2708
2856
|
toast?.onDismiss?.();
|
|
2709
2857
|
return currentToasts.filter((item) => item.id !== id);
|
|
2710
2858
|
});
|
|
2711
2859
|
}, []);
|
|
2712
|
-
const clear =
|
|
2860
|
+
const clear = React2.useCallback(() => {
|
|
2713
2861
|
setToasts((currentToasts) => {
|
|
2714
2862
|
for (const toast of currentToasts) {
|
|
2715
2863
|
toast.onDismiss?.();
|
|
@@ -2717,7 +2865,7 @@ function ToastProvider(props) {
|
|
|
2717
2865
|
return [];
|
|
2718
2866
|
});
|
|
2719
2867
|
}, []);
|
|
2720
|
-
const show =
|
|
2868
|
+
const show = React2.useCallback(
|
|
2721
2869
|
(toast) => {
|
|
2722
2870
|
idRef.current += 1;
|
|
2723
2871
|
const id = `mw-toast-${idRef.current}`;
|
|
@@ -2733,7 +2881,7 @@ function ToastProvider(props) {
|
|
|
2733
2881
|
},
|
|
2734
2882
|
[props.defaultDuration]
|
|
2735
2883
|
);
|
|
2736
|
-
const value =
|
|
2884
|
+
const value = React2.useMemo(
|
|
2737
2885
|
() => ({
|
|
2738
2886
|
show,
|
|
2739
2887
|
dismiss,
|
|
@@ -2756,7 +2904,7 @@ function ToastProvider(props) {
|
|
|
2756
2904
|
] });
|
|
2757
2905
|
}
|
|
2758
2906
|
function useToast() {
|
|
2759
|
-
const context =
|
|
2907
|
+
const context = React2.useContext(ToastContext);
|
|
2760
2908
|
if (!context) {
|
|
2761
2909
|
throw new Error("ToastProvider is missing. Wrap your app in <ToastProvider />.");
|
|
2762
2910
|
}
|
|
@@ -2790,7 +2938,7 @@ function cx10(...parts) {
|
|
|
2790
2938
|
return parts.filter(Boolean).join(" ");
|
|
2791
2939
|
}
|
|
2792
2940
|
function TooltipGroup(props) {
|
|
2793
|
-
const reactId =
|
|
2941
|
+
const reactId = React2.useId();
|
|
2794
2942
|
const {
|
|
2795
2943
|
content,
|
|
2796
2944
|
icon = IconName.HelpCircle,
|
|
@@ -2811,12 +2959,12 @@ function TooltipGroup(props) {
|
|
|
2811
2959
|
onKeyDown,
|
|
2812
2960
|
...nativeSpanProps
|
|
2813
2961
|
} = props;
|
|
2814
|
-
const [internalOpen, setInternalOpen] =
|
|
2962
|
+
const [internalOpen, setInternalOpen] = React2.useState(defaultOpen);
|
|
2815
2963
|
const isControlled = open !== void 0;
|
|
2816
2964
|
const resolvedOpen = isControlled ? open : internalOpen;
|
|
2817
|
-
const [isTooltipMounted, setIsTooltipMounted] =
|
|
2965
|
+
const [isTooltipMounted, setIsTooltipMounted] = React2.useState(resolvedOpen);
|
|
2818
2966
|
const resolvedTooltipId = tooltipId ?? `${id ?? `mw-tooltip-group-${reactId}`}-tooltip`;
|
|
2819
|
-
|
|
2967
|
+
React2.useEffect(() => {
|
|
2820
2968
|
if (resolvedOpen) {
|
|
2821
2969
|
setIsTooltipMounted(true);
|
|
2822
2970
|
return;
|
|
@@ -2828,7 +2976,7 @@ function TooltipGroup(props) {
|
|
|
2828
2976
|
window.clearTimeout(timeoutId);
|
|
2829
2977
|
};
|
|
2830
2978
|
}, [resolvedOpen]);
|
|
2831
|
-
const updateOpen =
|
|
2979
|
+
const updateOpen = React2.useCallback(
|
|
2832
2980
|
(nextOpen) => {
|
|
2833
2981
|
if (resolvedOpen === nextOpen) {
|
|
2834
2982
|
return;
|
|
@@ -2902,7 +3050,7 @@ function TooltipGroup(props) {
|
|
|
2902
3050
|
}
|
|
2903
3051
|
function Accordion(props) {
|
|
2904
3052
|
const { title, children, className, onToggle, id: idProp, open, disabled } = props;
|
|
2905
|
-
const autoId =
|
|
3053
|
+
const autoId = React2.useId();
|
|
2906
3054
|
const resolvedId = idProp ?? autoId.replace(/:/g, "");
|
|
2907
3055
|
const opts = { id: resolvedId };
|
|
2908
3056
|
if (open !== void 0) opts.open = open;
|
|
@@ -2955,7 +3103,7 @@ function resolveAccordionItemContent(item) {
|
|
|
2955
3103
|
return item.content ?? item.children;
|
|
2956
3104
|
}
|
|
2957
3105
|
function AccordionField(props) {
|
|
2958
|
-
const reactId =
|
|
3106
|
+
const reactId = React2.useId();
|
|
2959
3107
|
const id = props.id ?? `mw-accordion-field-${reactId}`;
|
|
2960
3108
|
const multipleAllowed = props.multiple ?? true;
|
|
2961
3109
|
const hasDescription = hasContent3(props.description);
|
|
@@ -2968,7 +3116,7 @@ function AccordionField(props) {
|
|
|
2968
3116
|
externalDescribedBy: props.ariaDescribedBy
|
|
2969
3117
|
});
|
|
2970
3118
|
const isControlled = props.openItems !== void 0;
|
|
2971
|
-
const [internalOpenItems, setInternalOpenItems] =
|
|
3119
|
+
const [internalOpenItems, setInternalOpenItems] = React2.useState(
|
|
2972
3120
|
props.defaultOpenItems ?? []
|
|
2973
3121
|
);
|
|
2974
3122
|
const openItems = isControlled ? props.openItems ?? [] : internalOpenItems;
|
|
@@ -3099,7 +3247,7 @@ function cx12(...parts) {
|
|
|
3099
3247
|
return parts.filter(Boolean).join(" ");
|
|
3100
3248
|
}
|
|
3101
3249
|
function RadioGroupField(props) {
|
|
3102
|
-
const reactId =
|
|
3250
|
+
const reactId = React2.useId();
|
|
3103
3251
|
const id = props.id ?? `mw-radio-group-${reactId}`;
|
|
3104
3252
|
const hasDescription = hasContent4(props.description);
|
|
3105
3253
|
const hasError = hasContent4(props.error);
|
|
@@ -3111,7 +3259,7 @@ function RadioGroupField(props) {
|
|
|
3111
3259
|
externalDescribedBy: props.ariaDescribedBy
|
|
3112
3260
|
});
|
|
3113
3261
|
const isControlled = props.value !== void 0;
|
|
3114
|
-
const [internalValue, setInternalValue] =
|
|
3262
|
+
const [internalValue, setInternalValue] = React2.useState(props.defaultValue);
|
|
3115
3263
|
const selectedValue = isControlled ? props.value : internalValue;
|
|
3116
3264
|
const handleSelect = (optionValue) => {
|
|
3117
3265
|
if (!isControlled) {
|
|
@@ -3230,7 +3378,7 @@ function cx13(...parts) {
|
|
|
3230
3378
|
return parts.filter(Boolean).join(" ");
|
|
3231
3379
|
}
|
|
3232
3380
|
function BadgeGroup(props) {
|
|
3233
|
-
const reactId =
|
|
3381
|
+
const reactId = React2.useId();
|
|
3234
3382
|
const id = props.id ?? `mw-badge-group-${reactId}`;
|
|
3235
3383
|
const labelId = `${id}-label`;
|
|
3236
3384
|
const className = cx13("mw-badge-group", props.className);
|
|
@@ -3322,7 +3470,7 @@ function hasContent5(value) {
|
|
|
3322
3470
|
return true;
|
|
3323
3471
|
}
|
|
3324
3472
|
function SwitchField(props) {
|
|
3325
|
-
const reactId =
|
|
3473
|
+
const reactId = React2.useId();
|
|
3326
3474
|
const id = props.id ?? `mw-switch-${reactId}`;
|
|
3327
3475
|
const hasDescription = hasContent5(props.description);
|
|
3328
3476
|
const hasError = hasContent5(props.error);
|
|
@@ -3422,7 +3570,7 @@ function buildSliderOptions(options) {
|
|
|
3422
3570
|
function resolveSliderValue(options) {
|
|
3423
3571
|
return createSliderRecipe(buildSliderOptions(options)).value;
|
|
3424
3572
|
}
|
|
3425
|
-
var Slider =
|
|
3573
|
+
var Slider = React2.forwardRef((props, ref) => {
|
|
3426
3574
|
const {
|
|
3427
3575
|
id,
|
|
3428
3576
|
name,
|
|
@@ -3447,10 +3595,10 @@ var Slider = React6.forwardRef((props, ref) => {
|
|
|
3447
3595
|
...inputProps
|
|
3448
3596
|
} = props;
|
|
3449
3597
|
const isControlled = value !== void 0;
|
|
3450
|
-
const [uncontrolledValue, setUncontrolledValue] =
|
|
3598
|
+
const [uncontrolledValue, setUncontrolledValue] = React2.useState(
|
|
3451
3599
|
() => resolveSliderValue({ min, max, step, value, defaultValue })
|
|
3452
3600
|
);
|
|
3453
|
-
|
|
3601
|
+
React2.useEffect(() => {
|
|
3454
3602
|
if (!isControlled) {
|
|
3455
3603
|
setUncontrolledValue(resolveSliderValue({ min, max, step, defaultValue }));
|
|
3456
3604
|
}
|
|
@@ -3536,7 +3684,7 @@ function resolveEdgeValueLabel(value, fallback) {
|
|
|
3536
3684
|
return value ?? `${fallback}`;
|
|
3537
3685
|
}
|
|
3538
3686
|
function SliderField(props) {
|
|
3539
|
-
const reactId =
|
|
3687
|
+
const reactId = React2.useId();
|
|
3540
3688
|
const id = props.id ?? `mw-slider-${reactId}`;
|
|
3541
3689
|
const hasDescription = hasContent6(props.description);
|
|
3542
3690
|
const hasError = hasContent6(props.error);
|
|
@@ -3737,29 +3885,29 @@ function TabPanel(props) {
|
|
|
3737
3885
|
);
|
|
3738
3886
|
}
|
|
3739
3887
|
function TabGroup(props) {
|
|
3740
|
-
const reactId =
|
|
3888
|
+
const reactId = React2.useId();
|
|
3741
3889
|
const id = props.id ?? `mw-tab-group-${reactId}`;
|
|
3742
3890
|
const hasLabel = hasContent7(props.label);
|
|
3743
|
-
const itemStates =
|
|
3891
|
+
const itemStates = React2.useMemo(
|
|
3744
3892
|
() => props.tabs.map((tab) => toItemState(tab)),
|
|
3745
3893
|
[props.tabs]
|
|
3746
3894
|
);
|
|
3747
3895
|
const isControlled = props.activeTab !== void 0;
|
|
3748
|
-
const [internalActiveTab, setInternalActiveTab] =
|
|
3896
|
+
const [internalActiveTab, setInternalActiveTab] = React2.useState(
|
|
3749
3897
|
() => resolveTabValue(itemStates, props.defaultActiveTab)
|
|
3750
3898
|
);
|
|
3751
|
-
const resolvedActiveTab =
|
|
3899
|
+
const resolvedActiveTab = React2.useMemo(
|
|
3752
3900
|
() => resolveTabValue(itemStates, isControlled ? props.activeTab : internalActiveTab),
|
|
3753
3901
|
[internalActiveTab, isControlled, itemStates, props.activeTab]
|
|
3754
3902
|
);
|
|
3755
|
-
|
|
3903
|
+
React2.useEffect(() => {
|
|
3756
3904
|
if (!isControlled) {
|
|
3757
3905
|
setInternalActiveTab(
|
|
3758
3906
|
(currentValue) => resolveTabValue(itemStates, currentValue ?? props.defaultActiveTab)
|
|
3759
3907
|
);
|
|
3760
3908
|
}
|
|
3761
3909
|
}, [isControlled, itemStates, props.defaultActiveTab]);
|
|
3762
|
-
const a11yIds =
|
|
3910
|
+
const a11yIds = React2.useMemo(
|
|
3763
3911
|
() => buildTabGroupA11yIds({
|
|
3764
3912
|
id,
|
|
3765
3913
|
itemValues: props.tabs.map((tab) => tab.value),
|
|
@@ -3767,7 +3915,7 @@ function TabGroup(props) {
|
|
|
3767
3915
|
}),
|
|
3768
3916
|
[hasLabel, id, props.tabs]
|
|
3769
3917
|
);
|
|
3770
|
-
const selectTab =
|
|
3918
|
+
const selectTab = React2.useCallback(
|
|
3771
3919
|
(nextValue) => {
|
|
3772
3920
|
const resolvedValue = resolveTabValue(itemStates, nextValue);
|
|
3773
3921
|
if (!resolvedValue) {
|
|
@@ -3782,7 +3930,7 @@ function TabGroup(props) {
|
|
|
3782
3930
|
},
|
|
3783
3931
|
[isControlled, itemStates, props.onActiveTabChange, resolvedActiveTab]
|
|
3784
3932
|
);
|
|
3785
|
-
const handleKeyDown =
|
|
3933
|
+
const handleKeyDown = React2.useCallback(
|
|
3786
3934
|
(event) => {
|
|
3787
3935
|
let direction;
|
|
3788
3936
|
switch (event.key) {
|
|
@@ -3912,7 +4060,7 @@ function hasContent8(value) {
|
|
|
3912
4060
|
return true;
|
|
3913
4061
|
}
|
|
3914
4062
|
function Dialog(props) {
|
|
3915
|
-
const reactId =
|
|
4063
|
+
const reactId = React2.useId();
|
|
3916
4064
|
const id = props.id ?? `mw-dialog-${reactId}`;
|
|
3917
4065
|
const titleId = `${id}-title`;
|
|
3918
4066
|
const descriptionId = `${id}-description`;
|
|
@@ -4031,12 +4179,12 @@ function DialogModal(props) {
|
|
|
4031
4179
|
...dialogProps
|
|
4032
4180
|
} = props;
|
|
4033
4181
|
const isControlled = open !== void 0;
|
|
4034
|
-
const [internalOpen, setInternalOpen] =
|
|
4182
|
+
const [internalOpen, setInternalOpen] = React2.useState(defaultOpen);
|
|
4035
4183
|
const resolvedOpen = isControlled ? open : internalOpen;
|
|
4036
|
-
const overlayRef =
|
|
4037
|
-
const surfaceRef =
|
|
4038
|
-
const lastFocusedElementRef =
|
|
4039
|
-
const close =
|
|
4184
|
+
const overlayRef = React2.useRef(null);
|
|
4185
|
+
const surfaceRef = React2.useRef(null);
|
|
4186
|
+
const lastFocusedElementRef = React2.useRef(null);
|
|
4187
|
+
const close = React2.useCallback(() => {
|
|
4040
4188
|
if (!resolvedOpen) {
|
|
4041
4189
|
return;
|
|
4042
4190
|
}
|
|
@@ -4045,7 +4193,7 @@ function DialogModal(props) {
|
|
|
4045
4193
|
}
|
|
4046
4194
|
onOpenChange?.(false);
|
|
4047
4195
|
}, [isControlled, onOpenChange, resolvedOpen]);
|
|
4048
|
-
|
|
4196
|
+
React2.useEffect(() => {
|
|
4049
4197
|
if (!resolvedOpen || typeof document === "undefined") {
|
|
4050
4198
|
return;
|
|
4051
4199
|
}
|
|
@@ -4064,7 +4212,7 @@ function DialogModal(props) {
|
|
|
4064
4212
|
}
|
|
4065
4213
|
};
|
|
4066
4214
|
}, [resolvedOpen, restoreFocus]);
|
|
4067
|
-
|
|
4215
|
+
React2.useEffect(() => {
|
|
4068
4216
|
if (!resolvedOpen || !closeOnEscape || typeof document === "undefined") {
|
|
4069
4217
|
return;
|
|
4070
4218
|
}
|
|
@@ -4079,7 +4227,7 @@ function DialogModal(props) {
|
|
|
4079
4227
|
document.removeEventListener("keydown", handleKeyDown2);
|
|
4080
4228
|
};
|
|
4081
4229
|
}, [close, closeOnEscape, resolvedOpen]);
|
|
4082
|
-
const handleKeyDown =
|
|
4230
|
+
const handleKeyDown = React2.useCallback(
|
|
4083
4231
|
(event) => {
|
|
4084
4232
|
if (event.key === "Escape" && closeOnEscape) {
|
|
4085
4233
|
event.preventDefault();
|
|
@@ -4110,7 +4258,7 @@ function DialogModal(props) {
|
|
|
4110
4258
|
},
|
|
4111
4259
|
[close, closeOnEscape]
|
|
4112
4260
|
);
|
|
4113
|
-
const renderedFooter =
|
|
4261
|
+
const renderedFooter = React2.useMemo(
|
|
4114
4262
|
() => typeof footer === "function" ? footer({ close }) : footer,
|
|
4115
4263
|
[close, footer]
|
|
4116
4264
|
);
|