@marwes-ui/react 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -1
- package/dist/index.d.ts +12 -3
- package/dist/index.js +205 -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,136 @@ 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
|
+
}
|
|
65
106
|
function MarwesProvider({
|
|
66
107
|
theme,
|
|
67
|
-
|
|
108
|
+
defaultPreference,
|
|
109
|
+
preference: controlledPreference,
|
|
110
|
+
defaultMode,
|
|
68
111
|
mode: controlledMode,
|
|
69
112
|
fontLoading = "auto",
|
|
113
|
+
onPreferenceChange,
|
|
70
114
|
onModeChange,
|
|
115
|
+
storageKey = false,
|
|
116
|
+
enableSystem = true,
|
|
71
117
|
children
|
|
72
118
|
}) {
|
|
73
|
-
const rootRef =
|
|
74
|
-
const [
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
(
|
|
79
|
-
|
|
80
|
-
|
|
119
|
+
const rootRef = React2.useRef(null);
|
|
120
|
+
const [internalPreference, setInternalPreference] = React2.useState(
|
|
121
|
+
defaultPreference ?? defaultMode ?? ThemeMode.light
|
|
122
|
+
);
|
|
123
|
+
const [systemMode, setSystemMode] = React2.useState(
|
|
124
|
+
() => enableSystem ? getSystemThemeMode() : ThemeMode.light
|
|
125
|
+
);
|
|
126
|
+
const activePreference = controlledPreference ?? controlledMode ?? theme?.mode ?? internalPreference;
|
|
127
|
+
const activeMode = resolveThemePreference(activePreference, systemMode);
|
|
128
|
+
const isPreferenceControlled = controlledPreference !== void 0 || controlledMode !== void 0 || theme?.mode !== void 0;
|
|
129
|
+
React2.useEffect(() => {
|
|
130
|
+
const storedPreference = readStoredThemePreference(storageKey);
|
|
131
|
+
if (storedPreference !== void 0 && !isPreferenceControlled) {
|
|
132
|
+
setInternalPreference(storedPreference);
|
|
133
|
+
}
|
|
134
|
+
}, [isPreferenceControlled, storageKey]);
|
|
135
|
+
React2.useEffect(() => {
|
|
136
|
+
if (!enableSystem) {
|
|
137
|
+
setSystemMode(ThemeMode.light);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
setSystemMode(getSystemThemeMode());
|
|
141
|
+
if (activePreference !== "system") {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
return subscribeToSystemThemeMode(setSystemMode);
|
|
145
|
+
}, [activePreference, enableSystem]);
|
|
146
|
+
const setPreference = React2.useCallback(
|
|
147
|
+
(nextPreference) => {
|
|
148
|
+
if (!isPreferenceControlled) {
|
|
149
|
+
setInternalPreference(nextPreference);
|
|
81
150
|
}
|
|
151
|
+
writeStoredThemePreference(storageKey, nextPreference);
|
|
152
|
+
onPreferenceChange?.(nextPreference);
|
|
153
|
+
},
|
|
154
|
+
[isPreferenceControlled, onPreferenceChange, storageKey]
|
|
155
|
+
);
|
|
156
|
+
const setMode = React2.useCallback(
|
|
157
|
+
(nextMode) => {
|
|
158
|
+
setPreference(nextMode);
|
|
82
159
|
onModeChange?.(nextMode);
|
|
83
160
|
},
|
|
84
|
-
[
|
|
161
|
+
[onModeChange, setPreference]
|
|
85
162
|
);
|
|
86
|
-
const toggleMode =
|
|
87
|
-
setMode(activeMode
|
|
163
|
+
const toggleMode = React2.useCallback(() => {
|
|
164
|
+
setMode(nextThemeMode(activeMode));
|
|
88
165
|
}, [activeMode, setMode]);
|
|
89
|
-
const resolved =
|
|
166
|
+
const resolved = React2.useMemo(
|
|
90
167
|
() => resolveThemeInput({ ...theme ?? {}, mode: activeMode }),
|
|
91
168
|
[activeMode, theme]
|
|
92
169
|
);
|
|
93
|
-
const rootStyle =
|
|
170
|
+
const rootStyle = React2.useMemo(
|
|
94
171
|
() => themeToRootStyle(resolved),
|
|
95
172
|
[resolved]
|
|
96
173
|
);
|
|
97
|
-
|
|
174
|
+
React2.useEffect(() => {
|
|
98
175
|
if (rootRef.current) {
|
|
99
176
|
applyThemeToElement(rootRef.current, resolved);
|
|
100
177
|
}
|
|
101
178
|
}, [resolved]);
|
|
102
|
-
|
|
179
|
+
React2.useEffect(() => {
|
|
103
180
|
loadThemeFonts(resolved, fontLoading);
|
|
104
181
|
}, [resolved, fontLoading]);
|
|
105
|
-
|
|
182
|
+
const contextValue = React2.useMemo(
|
|
183
|
+
() => ({
|
|
184
|
+
theme: resolved,
|
|
185
|
+
mode: activeMode,
|
|
186
|
+
preference: activePreference,
|
|
187
|
+
systemMode,
|
|
188
|
+
setMode,
|
|
189
|
+
setPreference,
|
|
190
|
+
toggleMode
|
|
191
|
+
}),
|
|
192
|
+
[activeMode, activePreference, resolved, setMode, setPreference, systemMode, toggleMode]
|
|
193
|
+
);
|
|
194
|
+
return /* @__PURE__ */ jsx(MarwesContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
|
|
106
195
|
"div",
|
|
107
196
|
{
|
|
108
197
|
ref: rootRef,
|
|
@@ -114,23 +203,27 @@ function MarwesProvider({
|
|
|
114
203
|
) });
|
|
115
204
|
}
|
|
116
205
|
function useTheme() {
|
|
117
|
-
const ctx =
|
|
206
|
+
const ctx = React2.useContext(MarwesContext);
|
|
118
207
|
if (!ctx) {
|
|
119
208
|
throw new Error("MarwesProvider is missing. Wrap your app in <MarwesProvider />.");
|
|
120
209
|
}
|
|
121
210
|
return ctx.theme;
|
|
122
211
|
}
|
|
123
212
|
function useThemeMode() {
|
|
124
|
-
const ctx =
|
|
213
|
+
const ctx = React2.useContext(MarwesContext);
|
|
125
214
|
if (!ctx) {
|
|
126
215
|
throw new Error("MarwesProvider is missing. Wrap your app in <MarwesProvider />.");
|
|
127
216
|
}
|
|
128
217
|
return {
|
|
129
218
|
mode: ctx.mode,
|
|
219
|
+
preference: ctx.preference,
|
|
220
|
+
systemMode: ctx.systemMode,
|
|
130
221
|
setMode: ctx.setMode,
|
|
222
|
+
setPreference: ctx.setPreference,
|
|
131
223
|
toggleMode: ctx.toggleMode,
|
|
132
224
|
isDark: ctx.mode === ThemeMode.dark,
|
|
133
|
-
isLight: ctx.mode === ThemeMode.light
|
|
225
|
+
isLight: ctx.mode === ThemeMode.light,
|
|
226
|
+
isSystem: ctx.preference === "system"
|
|
134
227
|
};
|
|
135
228
|
}
|
|
136
229
|
function Icon({
|
|
@@ -798,7 +891,7 @@ function Select(props) {
|
|
|
798
891
|
const kit = createSelectRecipe(props);
|
|
799
892
|
const mode = resolveSelectMode(props);
|
|
800
893
|
const isControlled = props.value !== void 0;
|
|
801
|
-
const [uncontrolledValue, setUncontrolledValue] =
|
|
894
|
+
const [uncontrolledValue, setUncontrolledValue] = React2.useState(
|
|
802
895
|
() => getInitialSelectValue(props)
|
|
803
896
|
);
|
|
804
897
|
useRenderKitDebug(kit, "Select");
|
|
@@ -1014,33 +1107,33 @@ function exitActiveFormatAtCaret(editorElement, format) {
|
|
|
1014
1107
|
selection.addRange(nextRange);
|
|
1015
1108
|
return true;
|
|
1016
1109
|
}
|
|
1017
|
-
var RichText =
|
|
1110
|
+
var RichText = React2.forwardRef((props, forwardedRef) => {
|
|
1018
1111
|
const kit = createRichTextRecipe(props);
|
|
1019
|
-
const allowedFormats =
|
|
1112
|
+
const allowedFormats = React2.useMemo(
|
|
1020
1113
|
() => resolveRichTextAllowedFormats(props.allowedFormats),
|
|
1021
1114
|
[props.allowedFormats]
|
|
1022
1115
|
);
|
|
1023
|
-
const normalizedControlledValue =
|
|
1116
|
+
const normalizedControlledValue = React2.useMemo(
|
|
1024
1117
|
() => normalizeRichTextHtml(props.value),
|
|
1025
1118
|
[props.value]
|
|
1026
1119
|
);
|
|
1027
|
-
const initialUncontrolledValue =
|
|
1120
|
+
const initialUncontrolledValue = React2.useMemo(
|
|
1028
1121
|
() => normalizeRichTextHtml(props.defaultValue),
|
|
1029
1122
|
[props.defaultValue]
|
|
1030
1123
|
);
|
|
1031
1124
|
const isControlled = props.value !== void 0;
|
|
1032
|
-
const [uncontrolledHtml, setUncontrolledHtml] =
|
|
1033
|
-
const [isEditorEmpty, setIsEditorEmpty] =
|
|
1125
|
+
const [uncontrolledHtml, setUncontrolledHtml] = React2.useState(initialUncontrolledValue);
|
|
1126
|
+
const [isEditorEmpty, setIsEditorEmpty] = React2.useState(
|
|
1034
1127
|
isRichTextHtmlEmpty(isControlled ? normalizedControlledValue : initialUncontrolledValue)
|
|
1035
1128
|
);
|
|
1036
|
-
const [activeFormats, setActiveFormats] =
|
|
1037
|
-
const editorElementRef =
|
|
1129
|
+
const [activeFormats, setActiveFormats] = React2.useState([]);
|
|
1130
|
+
const editorElementRef = React2.useRef(null);
|
|
1038
1131
|
useRenderKitDebug(kit, "RichText");
|
|
1039
1132
|
const editorHtml = isControlled ? normalizedControlledValue : uncontrolledHtml;
|
|
1040
1133
|
const style = kit.vars;
|
|
1041
1134
|
const className = props.className ? `${kit.className} ${props.className}` : kit.className;
|
|
1042
1135
|
const showToolbar = !props.readOnly;
|
|
1043
|
-
const syncEditorState =
|
|
1136
|
+
const syncEditorState = React2.useCallback(
|
|
1044
1137
|
(nextHtml) => {
|
|
1045
1138
|
const normalizedHtml = normalizeRichTextHtml(nextHtml);
|
|
1046
1139
|
const emptyState = isRichTextHtmlEmpty(normalizedHtml);
|
|
@@ -1053,10 +1146,10 @@ var RichText = React6.forwardRef((props, forwardedRef) => {
|
|
|
1053
1146
|
},
|
|
1054
1147
|
[isControlled, props]
|
|
1055
1148
|
);
|
|
1056
|
-
const refreshActiveFormats =
|
|
1149
|
+
const refreshActiveFormats = React2.useCallback(() => {
|
|
1057
1150
|
setActiveFormats(getActiveFormatsFromSelection(editorElementRef.current));
|
|
1058
1151
|
}, []);
|
|
1059
|
-
|
|
1152
|
+
React2.useLayoutEffect(() => {
|
|
1060
1153
|
const editorElement = editorElementRef.current;
|
|
1061
1154
|
if (!editorElement) {
|
|
1062
1155
|
return;
|
|
@@ -1067,7 +1160,7 @@ var RichText = React6.forwardRef((props, forwardedRef) => {
|
|
|
1067
1160
|
}
|
|
1068
1161
|
setIsEditorEmpty(isRichTextHtmlEmpty(editorHtml));
|
|
1069
1162
|
}, [editorHtml]);
|
|
1070
|
-
|
|
1163
|
+
React2.useEffect(() => {
|
|
1071
1164
|
if (typeof document === "undefined") {
|
|
1072
1165
|
return void 0;
|
|
1073
1166
|
}
|
|
@@ -1212,12 +1305,12 @@ function hasTextContent(value) {
|
|
|
1212
1305
|
return value !== void 0 && value.trim().length > 0;
|
|
1213
1306
|
}
|
|
1214
1307
|
function InputField(props) {
|
|
1215
|
-
const reactId =
|
|
1308
|
+
const reactId = React2.useId();
|
|
1216
1309
|
const id = props.id ?? `mw-input-${reactId}`;
|
|
1217
1310
|
const isPasswordField = props.input.type === "password";
|
|
1218
|
-
const [showPassword, setShowPassword] =
|
|
1311
|
+
const [showPassword, setShowPassword] = React2.useState(false);
|
|
1219
1312
|
const isSearchField = props.input.type === "search";
|
|
1220
|
-
const [searchValue, setSearchValue] =
|
|
1313
|
+
const [searchValue, setSearchValue] = React2.useState(
|
|
1221
1314
|
props.input.value || props.input.defaultValue || ""
|
|
1222
1315
|
);
|
|
1223
1316
|
const hasSearchValue = isSearchField && (props.input.value !== void 0 ? String(props.input.value).length > 0 : String(searchValue).length > 0);
|
|
@@ -1312,14 +1405,14 @@ function hasTextContent2(value) {
|
|
|
1312
1405
|
return value !== void 0 && value.trim().length > 0;
|
|
1313
1406
|
}
|
|
1314
1407
|
function InputOtp(props) {
|
|
1315
|
-
const reactId =
|
|
1408
|
+
const reactId = React2.useId();
|
|
1316
1409
|
const id = props.id ?? `mw-input-otp-${reactId}`;
|
|
1317
1410
|
const otpLength = Math.max(1, props.length ?? 6);
|
|
1318
1411
|
const hasHelperText = hasTextContent2(props.helperText);
|
|
1319
1412
|
const hasError = hasTextContent2(props.error);
|
|
1320
1413
|
const invalid = hasError || props.invalid === true;
|
|
1321
1414
|
const isControlled = props.value !== void 0;
|
|
1322
|
-
const [uncontrolledValue, setUncontrolledValue] =
|
|
1415
|
+
const [uncontrolledValue, setUncontrolledValue] = React2.useState(() => {
|
|
1323
1416
|
return sanitizeInputOtpValue(props.defaultValue, otpLength);
|
|
1324
1417
|
});
|
|
1325
1418
|
const currentValue = sanitizeInputOtpValue(
|
|
@@ -1476,18 +1569,18 @@ function MarwesSelectFieldControl(props) {
|
|
|
1476
1569
|
const { id, select } = props;
|
|
1477
1570
|
const listboxId = `${id}-listbox`;
|
|
1478
1571
|
const isControlled = select.value !== void 0;
|
|
1479
|
-
const [internalValue, setInternalValue] =
|
|
1572
|
+
const [internalValue, setInternalValue] = React2.useState(() => getInitialSelectValue2(select));
|
|
1480
1573
|
const value = isControlled ? select.value ?? "" : internalValue;
|
|
1481
|
-
const [open, setOpen] =
|
|
1482
|
-
const [activeIndex, setActiveIndex] =
|
|
1574
|
+
const [open, setOpen] = React2.useState(false);
|
|
1575
|
+
const [activeIndex, setActiveIndex] = React2.useState(
|
|
1483
1576
|
() => getInitialActiveOptionIndex(select.options, value)
|
|
1484
1577
|
);
|
|
1485
|
-
const rootRef =
|
|
1486
|
-
const buttonRef =
|
|
1578
|
+
const rootRef = React2.useRef(null);
|
|
1579
|
+
const buttonRef = React2.useRef(null);
|
|
1487
1580
|
const selectedOption = select.options.find((option) => option.value === value) ?? (select.placeholder === void 0 ? select.options[0] : void 0);
|
|
1488
1581
|
const placeholderSelected = select.placeholder !== void 0 && value === "";
|
|
1489
1582
|
const displayText = placeholderSelected ? select.placeholder : selectedOption?.label ?? "";
|
|
1490
|
-
|
|
1583
|
+
React2.useEffect(() => {
|
|
1491
1584
|
if (!open) {
|
|
1492
1585
|
return;
|
|
1493
1586
|
}
|
|
@@ -1502,13 +1595,13 @@ function MarwesSelectFieldControl(props) {
|
|
|
1502
1595
|
document.removeEventListener("pointerdown", handlePointerDown);
|
|
1503
1596
|
};
|
|
1504
1597
|
}, [open]);
|
|
1505
|
-
|
|
1598
|
+
React2.useEffect(() => {
|
|
1506
1599
|
if (!open) {
|
|
1507
1600
|
return;
|
|
1508
1601
|
}
|
|
1509
1602
|
setActiveIndex(getInitialActiveOptionIndex(select.options, value));
|
|
1510
1603
|
}, [open, select.options, value]);
|
|
1511
|
-
|
|
1604
|
+
React2.useEffect(() => {
|
|
1512
1605
|
if (!select.disabled) {
|
|
1513
1606
|
return;
|
|
1514
1607
|
}
|
|
@@ -1707,7 +1800,7 @@ function MarwesSelectFieldControl(props) {
|
|
|
1707
1800
|
);
|
|
1708
1801
|
}
|
|
1709
1802
|
function SelectField(props) {
|
|
1710
|
-
const reactId =
|
|
1803
|
+
const reactId = React2.useId();
|
|
1711
1804
|
const id = props.id ?? `mw-select-${reactId}`;
|
|
1712
1805
|
const mode = resolveSelectMode(props.select);
|
|
1713
1806
|
const hasHelperText = hasTextContent3(props.helperText);
|
|
@@ -1753,7 +1846,7 @@ function hasTextContent4(value) {
|
|
|
1753
1846
|
return value !== void 0 && value.trim().length > 0;
|
|
1754
1847
|
}
|
|
1755
1848
|
function TextareaField(props) {
|
|
1756
|
-
const reactId =
|
|
1849
|
+
const reactId = React2.useId();
|
|
1757
1850
|
const id = props.id ?? `mw-textarea-${reactId}`;
|
|
1758
1851
|
const hasHelperText = hasTextContent4(props.helperText);
|
|
1759
1852
|
const hasError = hasTextContent4(props.error);
|
|
@@ -1799,9 +1892,9 @@ function hasTextContent5(value) {
|
|
|
1799
1892
|
return value !== void 0 && value.trim().length > 0;
|
|
1800
1893
|
}
|
|
1801
1894
|
function RichTextField(props) {
|
|
1802
|
-
const reactId =
|
|
1895
|
+
const reactId = React2.useId();
|
|
1803
1896
|
const id = props.id ?? `mw-rich-text-${reactId}`;
|
|
1804
|
-
const editorRef =
|
|
1897
|
+
const editorRef = React2.useRef(null);
|
|
1805
1898
|
const hasHelperText = hasTextContent5(props.helperText);
|
|
1806
1899
|
const hasError = hasTextContent5(props.error);
|
|
1807
1900
|
const { labelId, helperTextId, errorId, describedBy } = buildRichTextFieldA11yIds({
|
|
@@ -2168,8 +2261,8 @@ function TeamAvatarGroup(props) {
|
|
|
2168
2261
|
function Checkbox(props) {
|
|
2169
2262
|
const { onCheckedChange, onChange, ...coreProps } = props;
|
|
2170
2263
|
const kit = checkboxRecipe({ ...coreProps });
|
|
2171
|
-
const inputRef =
|
|
2172
|
-
|
|
2264
|
+
const inputRef = React2.useRef(null);
|
|
2265
|
+
React2.useLayoutEffect(() => {
|
|
2173
2266
|
const el = inputRef.current;
|
|
2174
2267
|
if (!el) return;
|
|
2175
2268
|
el.indeterminate = kit.indeterminate;
|
|
@@ -2215,7 +2308,7 @@ function hasContent(value) {
|
|
|
2215
2308
|
return true;
|
|
2216
2309
|
}
|
|
2217
2310
|
function CheckboxField(props) {
|
|
2218
|
-
const reactId =
|
|
2311
|
+
const reactId = React2.useId();
|
|
2219
2312
|
const id = props.id ?? `mw-checkbox-${reactId}`;
|
|
2220
2313
|
const hasDescription = hasContent(props.description);
|
|
2221
2314
|
const hasError = hasContent(props.error);
|
|
@@ -2269,7 +2362,7 @@ function orderSelectedValues(values, options) {
|
|
|
2269
2362
|
return [...knownValues, ...unknownValues];
|
|
2270
2363
|
}
|
|
2271
2364
|
function CheckboxGroupField(props) {
|
|
2272
|
-
const reactId =
|
|
2365
|
+
const reactId = React2.useId();
|
|
2273
2366
|
const id = props.id ?? `mw-checkbox-group-${reactId}`;
|
|
2274
2367
|
const hasDescription = hasContent2(props.description);
|
|
2275
2368
|
const hasError = hasContent2(props.error);
|
|
@@ -2281,7 +2374,7 @@ function CheckboxGroupField(props) {
|
|
|
2281
2374
|
externalDescribedBy: props.ariaDescribedBy
|
|
2282
2375
|
});
|
|
2283
2376
|
const isControlled = props.value !== void 0;
|
|
2284
|
-
const [internalValue, setInternalValue] =
|
|
2377
|
+
const [internalValue, setInternalValue] = React2.useState(
|
|
2285
2378
|
orderSelectedValues(props.defaultValue ?? [], props.options)
|
|
2286
2379
|
);
|
|
2287
2380
|
const selectedValues = orderSelectedValues(
|
|
@@ -2351,7 +2444,7 @@ function CheckboxGroupField(props) {
|
|
|
2351
2444
|
}
|
|
2352
2445
|
);
|
|
2353
2446
|
}
|
|
2354
|
-
var Divider =
|
|
2447
|
+
var Divider = React2.forwardRef((props, ref) => {
|
|
2355
2448
|
const { className: customClassName, style: customStyle, ...opts } = props;
|
|
2356
2449
|
const kit = createDividerRecipe(opts);
|
|
2357
2450
|
const style = { ...kit.vars, ...customStyle };
|
|
@@ -2359,7 +2452,7 @@ var Divider = React6.forwardRef((props, ref) => {
|
|
|
2359
2452
|
return /* @__PURE__ */ jsx("hr", { ref, ...kit.a11y, ...kit.dataAttributes, className, style });
|
|
2360
2453
|
});
|
|
2361
2454
|
Divider.displayName = "Divider";
|
|
2362
|
-
var Spacing =
|
|
2455
|
+
var Spacing = React2.forwardRef((props, ref) => {
|
|
2363
2456
|
const { className: customClassName, scale, size, spacing, style: customStyle } = props;
|
|
2364
2457
|
const resolvedSize = spacing ?? size;
|
|
2365
2458
|
const kit = createSpacingRecipe({
|
|
@@ -2594,12 +2687,12 @@ function renderToastByIntent(toast, onDismiss) {
|
|
|
2594
2687
|
}
|
|
2595
2688
|
}
|
|
2596
2689
|
function ToastViewportItem(props) {
|
|
2597
|
-
const timerHandleRef =
|
|
2598
|
-
const timerStartedAtRef =
|
|
2599
|
-
const remainingDurationRef =
|
|
2600
|
-
const pointerInsideRef =
|
|
2601
|
-
const focusInsideRef =
|
|
2602
|
-
const clearDismissTimer =
|
|
2690
|
+
const timerHandleRef = React2.useRef(null);
|
|
2691
|
+
const timerStartedAtRef = React2.useRef(null);
|
|
2692
|
+
const remainingDurationRef = React2.useRef(null);
|
|
2693
|
+
const pointerInsideRef = React2.useRef(false);
|
|
2694
|
+
const focusInsideRef = React2.useRef(false);
|
|
2695
|
+
const clearDismissTimer = React2.useCallback(() => {
|
|
2603
2696
|
if (timerHandleRef.current === null) {
|
|
2604
2697
|
return;
|
|
2605
2698
|
}
|
|
@@ -2607,7 +2700,7 @@ function ToastViewportItem(props) {
|
|
|
2607
2700
|
timerHandleRef.current = null;
|
|
2608
2701
|
timerStartedAtRef.current = null;
|
|
2609
2702
|
}, []);
|
|
2610
|
-
const scheduleDismissTimer =
|
|
2703
|
+
const scheduleDismissTimer = React2.useCallback(
|
|
2611
2704
|
(delay) => {
|
|
2612
2705
|
if (!props.onDismiss || delay <= 0 || pointerInsideRef.current || focusInsideRef.current || timerHandleRef.current !== null) {
|
|
2613
2706
|
return;
|
|
@@ -2622,7 +2715,7 @@ function ToastViewportItem(props) {
|
|
|
2622
2715
|
},
|
|
2623
2716
|
[props.onDismiss, props.toast.id]
|
|
2624
2717
|
);
|
|
2625
|
-
const pauseDismissTimer =
|
|
2718
|
+
const pauseDismissTimer = React2.useCallback(() => {
|
|
2626
2719
|
if (timerHandleRef.current === null || timerStartedAtRef.current === null) {
|
|
2627
2720
|
return;
|
|
2628
2721
|
}
|
|
@@ -2631,7 +2724,7 @@ function ToastViewportItem(props) {
|
|
|
2631
2724
|
remainingDurationRef.current = Math.max(remainingDuration - elapsed, 0);
|
|
2632
2725
|
clearDismissTimer();
|
|
2633
2726
|
}, [clearDismissTimer]);
|
|
2634
|
-
const resumeDismissTimer =
|
|
2727
|
+
const resumeDismissTimer = React2.useCallback(() => {
|
|
2635
2728
|
if (pointerInsideRef.current || focusInsideRef.current) {
|
|
2636
2729
|
return;
|
|
2637
2730
|
}
|
|
@@ -2641,7 +2734,7 @@ function ToastViewportItem(props) {
|
|
|
2641
2734
|
}
|
|
2642
2735
|
scheduleDismissTimer(remainingDuration);
|
|
2643
2736
|
}, [scheduleDismissTimer]);
|
|
2644
|
-
|
|
2737
|
+
React2.useEffect(() => {
|
|
2645
2738
|
clearDismissTimer();
|
|
2646
2739
|
pointerInsideRef.current = false;
|
|
2647
2740
|
focusInsideRef.current = false;
|
|
@@ -2698,18 +2791,18 @@ function ToastContainer(props) {
|
|
|
2698
2791
|
toast.id
|
|
2699
2792
|
)) });
|
|
2700
2793
|
}
|
|
2701
|
-
var ToastContext =
|
|
2794
|
+
var ToastContext = React2.createContext(null);
|
|
2702
2795
|
function ToastProvider(props) {
|
|
2703
|
-
const [toasts, setToasts] =
|
|
2704
|
-
const idRef =
|
|
2705
|
-
const dismiss =
|
|
2796
|
+
const [toasts, setToasts] = React2.useState([]);
|
|
2797
|
+
const idRef = React2.useRef(0);
|
|
2798
|
+
const dismiss = React2.useCallback((id) => {
|
|
2706
2799
|
setToasts((currentToasts) => {
|
|
2707
2800
|
const toast = currentToasts.find((item) => item.id === id);
|
|
2708
2801
|
toast?.onDismiss?.();
|
|
2709
2802
|
return currentToasts.filter((item) => item.id !== id);
|
|
2710
2803
|
});
|
|
2711
2804
|
}, []);
|
|
2712
|
-
const clear =
|
|
2805
|
+
const clear = React2.useCallback(() => {
|
|
2713
2806
|
setToasts((currentToasts) => {
|
|
2714
2807
|
for (const toast of currentToasts) {
|
|
2715
2808
|
toast.onDismiss?.();
|
|
@@ -2717,7 +2810,7 @@ function ToastProvider(props) {
|
|
|
2717
2810
|
return [];
|
|
2718
2811
|
});
|
|
2719
2812
|
}, []);
|
|
2720
|
-
const show =
|
|
2813
|
+
const show = React2.useCallback(
|
|
2721
2814
|
(toast) => {
|
|
2722
2815
|
idRef.current += 1;
|
|
2723
2816
|
const id = `mw-toast-${idRef.current}`;
|
|
@@ -2733,7 +2826,7 @@ function ToastProvider(props) {
|
|
|
2733
2826
|
},
|
|
2734
2827
|
[props.defaultDuration]
|
|
2735
2828
|
);
|
|
2736
|
-
const value =
|
|
2829
|
+
const value = React2.useMemo(
|
|
2737
2830
|
() => ({
|
|
2738
2831
|
show,
|
|
2739
2832
|
dismiss,
|
|
@@ -2756,7 +2849,7 @@ function ToastProvider(props) {
|
|
|
2756
2849
|
] });
|
|
2757
2850
|
}
|
|
2758
2851
|
function useToast() {
|
|
2759
|
-
const context =
|
|
2852
|
+
const context = React2.useContext(ToastContext);
|
|
2760
2853
|
if (!context) {
|
|
2761
2854
|
throw new Error("ToastProvider is missing. Wrap your app in <ToastProvider />.");
|
|
2762
2855
|
}
|
|
@@ -2790,7 +2883,7 @@ function cx10(...parts) {
|
|
|
2790
2883
|
return parts.filter(Boolean).join(" ");
|
|
2791
2884
|
}
|
|
2792
2885
|
function TooltipGroup(props) {
|
|
2793
|
-
const reactId =
|
|
2886
|
+
const reactId = React2.useId();
|
|
2794
2887
|
const {
|
|
2795
2888
|
content,
|
|
2796
2889
|
icon = IconName.HelpCircle,
|
|
@@ -2811,12 +2904,12 @@ function TooltipGroup(props) {
|
|
|
2811
2904
|
onKeyDown,
|
|
2812
2905
|
...nativeSpanProps
|
|
2813
2906
|
} = props;
|
|
2814
|
-
const [internalOpen, setInternalOpen] =
|
|
2907
|
+
const [internalOpen, setInternalOpen] = React2.useState(defaultOpen);
|
|
2815
2908
|
const isControlled = open !== void 0;
|
|
2816
2909
|
const resolvedOpen = isControlled ? open : internalOpen;
|
|
2817
|
-
const [isTooltipMounted, setIsTooltipMounted] =
|
|
2910
|
+
const [isTooltipMounted, setIsTooltipMounted] = React2.useState(resolvedOpen);
|
|
2818
2911
|
const resolvedTooltipId = tooltipId ?? `${id ?? `mw-tooltip-group-${reactId}`}-tooltip`;
|
|
2819
|
-
|
|
2912
|
+
React2.useEffect(() => {
|
|
2820
2913
|
if (resolvedOpen) {
|
|
2821
2914
|
setIsTooltipMounted(true);
|
|
2822
2915
|
return;
|
|
@@ -2828,7 +2921,7 @@ function TooltipGroup(props) {
|
|
|
2828
2921
|
window.clearTimeout(timeoutId);
|
|
2829
2922
|
};
|
|
2830
2923
|
}, [resolvedOpen]);
|
|
2831
|
-
const updateOpen =
|
|
2924
|
+
const updateOpen = React2.useCallback(
|
|
2832
2925
|
(nextOpen) => {
|
|
2833
2926
|
if (resolvedOpen === nextOpen) {
|
|
2834
2927
|
return;
|
|
@@ -2902,7 +2995,7 @@ function TooltipGroup(props) {
|
|
|
2902
2995
|
}
|
|
2903
2996
|
function Accordion(props) {
|
|
2904
2997
|
const { title, children, className, onToggle, id: idProp, open, disabled } = props;
|
|
2905
|
-
const autoId =
|
|
2998
|
+
const autoId = React2.useId();
|
|
2906
2999
|
const resolvedId = idProp ?? autoId.replace(/:/g, "");
|
|
2907
3000
|
const opts = { id: resolvedId };
|
|
2908
3001
|
if (open !== void 0) opts.open = open;
|
|
@@ -2955,7 +3048,7 @@ function resolveAccordionItemContent(item) {
|
|
|
2955
3048
|
return item.content ?? item.children;
|
|
2956
3049
|
}
|
|
2957
3050
|
function AccordionField(props) {
|
|
2958
|
-
const reactId =
|
|
3051
|
+
const reactId = React2.useId();
|
|
2959
3052
|
const id = props.id ?? `mw-accordion-field-${reactId}`;
|
|
2960
3053
|
const multipleAllowed = props.multiple ?? true;
|
|
2961
3054
|
const hasDescription = hasContent3(props.description);
|
|
@@ -2968,7 +3061,7 @@ function AccordionField(props) {
|
|
|
2968
3061
|
externalDescribedBy: props.ariaDescribedBy
|
|
2969
3062
|
});
|
|
2970
3063
|
const isControlled = props.openItems !== void 0;
|
|
2971
|
-
const [internalOpenItems, setInternalOpenItems] =
|
|
3064
|
+
const [internalOpenItems, setInternalOpenItems] = React2.useState(
|
|
2972
3065
|
props.defaultOpenItems ?? []
|
|
2973
3066
|
);
|
|
2974
3067
|
const openItems = isControlled ? props.openItems ?? [] : internalOpenItems;
|
|
@@ -3099,7 +3192,7 @@ function cx12(...parts) {
|
|
|
3099
3192
|
return parts.filter(Boolean).join(" ");
|
|
3100
3193
|
}
|
|
3101
3194
|
function RadioGroupField(props) {
|
|
3102
|
-
const reactId =
|
|
3195
|
+
const reactId = React2.useId();
|
|
3103
3196
|
const id = props.id ?? `mw-radio-group-${reactId}`;
|
|
3104
3197
|
const hasDescription = hasContent4(props.description);
|
|
3105
3198
|
const hasError = hasContent4(props.error);
|
|
@@ -3111,7 +3204,7 @@ function RadioGroupField(props) {
|
|
|
3111
3204
|
externalDescribedBy: props.ariaDescribedBy
|
|
3112
3205
|
});
|
|
3113
3206
|
const isControlled = props.value !== void 0;
|
|
3114
|
-
const [internalValue, setInternalValue] =
|
|
3207
|
+
const [internalValue, setInternalValue] = React2.useState(props.defaultValue);
|
|
3115
3208
|
const selectedValue = isControlled ? props.value : internalValue;
|
|
3116
3209
|
const handleSelect = (optionValue) => {
|
|
3117
3210
|
if (!isControlled) {
|
|
@@ -3230,7 +3323,7 @@ function cx13(...parts) {
|
|
|
3230
3323
|
return parts.filter(Boolean).join(" ");
|
|
3231
3324
|
}
|
|
3232
3325
|
function BadgeGroup(props) {
|
|
3233
|
-
const reactId =
|
|
3326
|
+
const reactId = React2.useId();
|
|
3234
3327
|
const id = props.id ?? `mw-badge-group-${reactId}`;
|
|
3235
3328
|
const labelId = `${id}-label`;
|
|
3236
3329
|
const className = cx13("mw-badge-group", props.className);
|
|
@@ -3322,7 +3415,7 @@ function hasContent5(value) {
|
|
|
3322
3415
|
return true;
|
|
3323
3416
|
}
|
|
3324
3417
|
function SwitchField(props) {
|
|
3325
|
-
const reactId =
|
|
3418
|
+
const reactId = React2.useId();
|
|
3326
3419
|
const id = props.id ?? `mw-switch-${reactId}`;
|
|
3327
3420
|
const hasDescription = hasContent5(props.description);
|
|
3328
3421
|
const hasError = hasContent5(props.error);
|
|
@@ -3422,7 +3515,7 @@ function buildSliderOptions(options) {
|
|
|
3422
3515
|
function resolveSliderValue(options) {
|
|
3423
3516
|
return createSliderRecipe(buildSliderOptions(options)).value;
|
|
3424
3517
|
}
|
|
3425
|
-
var Slider =
|
|
3518
|
+
var Slider = React2.forwardRef((props, ref) => {
|
|
3426
3519
|
const {
|
|
3427
3520
|
id,
|
|
3428
3521
|
name,
|
|
@@ -3447,10 +3540,10 @@ var Slider = React6.forwardRef((props, ref) => {
|
|
|
3447
3540
|
...inputProps
|
|
3448
3541
|
} = props;
|
|
3449
3542
|
const isControlled = value !== void 0;
|
|
3450
|
-
const [uncontrolledValue, setUncontrolledValue] =
|
|
3543
|
+
const [uncontrolledValue, setUncontrolledValue] = React2.useState(
|
|
3451
3544
|
() => resolveSliderValue({ min, max, step, value, defaultValue })
|
|
3452
3545
|
);
|
|
3453
|
-
|
|
3546
|
+
React2.useEffect(() => {
|
|
3454
3547
|
if (!isControlled) {
|
|
3455
3548
|
setUncontrolledValue(resolveSliderValue({ min, max, step, defaultValue }));
|
|
3456
3549
|
}
|
|
@@ -3536,7 +3629,7 @@ function resolveEdgeValueLabel(value, fallback) {
|
|
|
3536
3629
|
return value ?? `${fallback}`;
|
|
3537
3630
|
}
|
|
3538
3631
|
function SliderField(props) {
|
|
3539
|
-
const reactId =
|
|
3632
|
+
const reactId = React2.useId();
|
|
3540
3633
|
const id = props.id ?? `mw-slider-${reactId}`;
|
|
3541
3634
|
const hasDescription = hasContent6(props.description);
|
|
3542
3635
|
const hasError = hasContent6(props.error);
|
|
@@ -3737,29 +3830,29 @@ function TabPanel(props) {
|
|
|
3737
3830
|
);
|
|
3738
3831
|
}
|
|
3739
3832
|
function TabGroup(props) {
|
|
3740
|
-
const reactId =
|
|
3833
|
+
const reactId = React2.useId();
|
|
3741
3834
|
const id = props.id ?? `mw-tab-group-${reactId}`;
|
|
3742
3835
|
const hasLabel = hasContent7(props.label);
|
|
3743
|
-
const itemStates =
|
|
3836
|
+
const itemStates = React2.useMemo(
|
|
3744
3837
|
() => props.tabs.map((tab) => toItemState(tab)),
|
|
3745
3838
|
[props.tabs]
|
|
3746
3839
|
);
|
|
3747
3840
|
const isControlled = props.activeTab !== void 0;
|
|
3748
|
-
const [internalActiveTab, setInternalActiveTab] =
|
|
3841
|
+
const [internalActiveTab, setInternalActiveTab] = React2.useState(
|
|
3749
3842
|
() => resolveTabValue(itemStates, props.defaultActiveTab)
|
|
3750
3843
|
);
|
|
3751
|
-
const resolvedActiveTab =
|
|
3844
|
+
const resolvedActiveTab = React2.useMemo(
|
|
3752
3845
|
() => resolveTabValue(itemStates, isControlled ? props.activeTab : internalActiveTab),
|
|
3753
3846
|
[internalActiveTab, isControlled, itemStates, props.activeTab]
|
|
3754
3847
|
);
|
|
3755
|
-
|
|
3848
|
+
React2.useEffect(() => {
|
|
3756
3849
|
if (!isControlled) {
|
|
3757
3850
|
setInternalActiveTab(
|
|
3758
3851
|
(currentValue) => resolveTabValue(itemStates, currentValue ?? props.defaultActiveTab)
|
|
3759
3852
|
);
|
|
3760
3853
|
}
|
|
3761
3854
|
}, [isControlled, itemStates, props.defaultActiveTab]);
|
|
3762
|
-
const a11yIds =
|
|
3855
|
+
const a11yIds = React2.useMemo(
|
|
3763
3856
|
() => buildTabGroupA11yIds({
|
|
3764
3857
|
id,
|
|
3765
3858
|
itemValues: props.tabs.map((tab) => tab.value),
|
|
@@ -3767,7 +3860,7 @@ function TabGroup(props) {
|
|
|
3767
3860
|
}),
|
|
3768
3861
|
[hasLabel, id, props.tabs]
|
|
3769
3862
|
);
|
|
3770
|
-
const selectTab =
|
|
3863
|
+
const selectTab = React2.useCallback(
|
|
3771
3864
|
(nextValue) => {
|
|
3772
3865
|
const resolvedValue = resolveTabValue(itemStates, nextValue);
|
|
3773
3866
|
if (!resolvedValue) {
|
|
@@ -3782,7 +3875,7 @@ function TabGroup(props) {
|
|
|
3782
3875
|
},
|
|
3783
3876
|
[isControlled, itemStates, props.onActiveTabChange, resolvedActiveTab]
|
|
3784
3877
|
);
|
|
3785
|
-
const handleKeyDown =
|
|
3878
|
+
const handleKeyDown = React2.useCallback(
|
|
3786
3879
|
(event) => {
|
|
3787
3880
|
let direction;
|
|
3788
3881
|
switch (event.key) {
|
|
@@ -3912,7 +4005,7 @@ function hasContent8(value) {
|
|
|
3912
4005
|
return true;
|
|
3913
4006
|
}
|
|
3914
4007
|
function Dialog(props) {
|
|
3915
|
-
const reactId =
|
|
4008
|
+
const reactId = React2.useId();
|
|
3916
4009
|
const id = props.id ?? `mw-dialog-${reactId}`;
|
|
3917
4010
|
const titleId = `${id}-title`;
|
|
3918
4011
|
const descriptionId = `${id}-description`;
|
|
@@ -4031,12 +4124,12 @@ function DialogModal(props) {
|
|
|
4031
4124
|
...dialogProps
|
|
4032
4125
|
} = props;
|
|
4033
4126
|
const isControlled = open !== void 0;
|
|
4034
|
-
const [internalOpen, setInternalOpen] =
|
|
4127
|
+
const [internalOpen, setInternalOpen] = React2.useState(defaultOpen);
|
|
4035
4128
|
const resolvedOpen = isControlled ? open : internalOpen;
|
|
4036
|
-
const overlayRef =
|
|
4037
|
-
const surfaceRef =
|
|
4038
|
-
const lastFocusedElementRef =
|
|
4039
|
-
const close =
|
|
4129
|
+
const overlayRef = React2.useRef(null);
|
|
4130
|
+
const surfaceRef = React2.useRef(null);
|
|
4131
|
+
const lastFocusedElementRef = React2.useRef(null);
|
|
4132
|
+
const close = React2.useCallback(() => {
|
|
4040
4133
|
if (!resolvedOpen) {
|
|
4041
4134
|
return;
|
|
4042
4135
|
}
|
|
@@ -4045,7 +4138,7 @@ function DialogModal(props) {
|
|
|
4045
4138
|
}
|
|
4046
4139
|
onOpenChange?.(false);
|
|
4047
4140
|
}, [isControlled, onOpenChange, resolvedOpen]);
|
|
4048
|
-
|
|
4141
|
+
React2.useEffect(() => {
|
|
4049
4142
|
if (!resolvedOpen || typeof document === "undefined") {
|
|
4050
4143
|
return;
|
|
4051
4144
|
}
|
|
@@ -4064,7 +4157,7 @@ function DialogModal(props) {
|
|
|
4064
4157
|
}
|
|
4065
4158
|
};
|
|
4066
4159
|
}, [resolvedOpen, restoreFocus]);
|
|
4067
|
-
|
|
4160
|
+
React2.useEffect(() => {
|
|
4068
4161
|
if (!resolvedOpen || !closeOnEscape || typeof document === "undefined") {
|
|
4069
4162
|
return;
|
|
4070
4163
|
}
|
|
@@ -4079,7 +4172,7 @@ function DialogModal(props) {
|
|
|
4079
4172
|
document.removeEventListener("keydown", handleKeyDown2);
|
|
4080
4173
|
};
|
|
4081
4174
|
}, [close, closeOnEscape, resolvedOpen]);
|
|
4082
|
-
const handleKeyDown =
|
|
4175
|
+
const handleKeyDown = React2.useCallback(
|
|
4083
4176
|
(event) => {
|
|
4084
4177
|
if (event.key === "Escape" && closeOnEscape) {
|
|
4085
4178
|
event.preventDefault();
|
|
@@ -4110,7 +4203,7 @@ function DialogModal(props) {
|
|
|
4110
4203
|
},
|
|
4111
4204
|
[close, closeOnEscape]
|
|
4112
4205
|
);
|
|
4113
|
-
const renderedFooter =
|
|
4206
|
+
const renderedFooter = React2.useMemo(
|
|
4114
4207
|
() => typeof footer === "function" ? footer({ close }) : footer,
|
|
4115
4208
|
[close, footer]
|
|
4116
4209
|
);
|