@mui/material 7.0.0-beta.4 → 7.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/InputBase/InputBase.js +2 -2
  3. package/Select/SelectInput.js +2 -2
  4. package/StepLabel/StepLabel.d.ts +19 -1
  5. package/StepLabel/StepLabel.js +14 -5
  6. package/Switch/Switch.d.ts +62 -1
  7. package/Switch/Switch.js +71 -9
  8. package/TextField/TextField.d.ts +30 -0
  9. package/TextField/TextField.js +22 -11
  10. package/esm/InputBase/InputBase.js +2 -2
  11. package/esm/Select/SelectInput.js +2 -2
  12. package/esm/StepLabel/StepLabel.d.ts +19 -1
  13. package/esm/StepLabel/StepLabel.js +14 -5
  14. package/esm/Switch/Switch.d.ts +62 -1
  15. package/esm/Switch/Switch.js +71 -9
  16. package/esm/TextField/TextField.d.ts +30 -0
  17. package/esm/TextField/TextField.js +22 -11
  18. package/esm/index.js +1 -1
  19. package/esm/styles/createPalette.js +3 -3
  20. package/esm/styles/createThemeNoVars.js +2 -2
  21. package/esm/styles/createThemeWithVars.js +2 -2
  22. package/esm/styles/index.js +2 -2
  23. package/esm/styles/makeStyles.js +2 -2
  24. package/esm/styles/responsiveFontSizes.js +2 -2
  25. package/esm/styles/withStyles.js +2 -2
  26. package/esm/styles/withTheme.js +2 -2
  27. package/esm/utils/mergeSlotProps.js +25 -0
  28. package/esm/version/index.js +2 -2
  29. package/index.js +1 -1
  30. package/modern/InputBase/InputBase.js +2 -2
  31. package/modern/Select/SelectInput.js +2 -2
  32. package/modern/StepLabel/StepLabel.d.ts +19 -1
  33. package/modern/StepLabel/StepLabel.js +14 -5
  34. package/modern/Switch/Switch.d.ts +62 -1
  35. package/modern/Switch/Switch.js +71 -9
  36. package/modern/TextField/TextField.d.ts +30 -0
  37. package/modern/TextField/TextField.js +22 -11
  38. package/modern/index.js +1 -1
  39. package/modern/styles/createPalette.js +3 -3
  40. package/modern/styles/createThemeNoVars.js +2 -2
  41. package/modern/styles/createThemeWithVars.js +2 -2
  42. package/modern/styles/index.js +2 -2
  43. package/modern/styles/makeStyles.js +2 -2
  44. package/modern/styles/responsiveFontSizes.js +2 -2
  45. package/modern/styles/withStyles.js +2 -2
  46. package/modern/styles/withTheme.js +2 -2
  47. package/modern/utils/mergeSlotProps.js +25 -0
  48. package/modern/version/index.js +2 -2
  49. package/package.json +7 -7
  50. package/styles/createPalette.js +3 -3
  51. package/styles/createThemeNoVars.js +2 -2
  52. package/styles/createThemeWithVars.js +2 -2
  53. package/styles/index.js +2 -2
  54. package/styles/makeStyles.js +2 -2
  55. package/styles/responsiveFontSizes.js +2 -2
  56. package/styles/withStyles.js +2 -2
  57. package/styles/withTheme.js +2 -2
  58. package/tsconfig.build.tsbuildinfo +1 -1
  59. package/utils/mergeSlotProps.js +24 -0
  60. package/version/index.js +2 -2
@@ -14,6 +14,7 @@ import { styled } from "../zero-styled/index.js";
14
14
  import memoTheme from "../utils/memoTheme.js";
15
15
  import { useDefaultProps } from "../DefaultPropsProvider/index.js";
16
16
  import switchClasses, { getSwitchUtilityClass } from "./switchClasses.js";
17
+ import useSlot from "../utils/useSlot.js";
17
18
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
19
  const useUtilityClasses = ownerState => {
19
20
  const {
@@ -212,6 +213,8 @@ const Switch = /*#__PURE__*/React.forwardRef(function Switch(inProps, ref) {
212
213
  edge = false,
213
214
  size = 'medium',
214
215
  sx,
216
+ slots = {},
217
+ slotProps = {},
215
218
  ...other
216
219
  } = props;
217
220
  const ownerState = {
@@ -221,14 +224,36 @@ const Switch = /*#__PURE__*/React.forwardRef(function Switch(inProps, ref) {
221
224
  size
222
225
  };
223
226
  const classes = useUtilityClasses(ownerState);
224
- const icon = /*#__PURE__*/_jsx(SwitchThumb, {
227
+ const externalForwardedProps = {
228
+ slots,
229
+ slotProps
230
+ };
231
+ const [RootSlot, rootSlotProps] = useSlot('root', {
232
+ className: clsx(classes.root, className),
233
+ elementType: SwitchRoot,
234
+ externalForwardedProps,
235
+ ownerState,
236
+ additionalProps: {
237
+ sx
238
+ }
239
+ });
240
+ const [ThumbSlot, thumbSlotProps] = useSlot('thumb', {
225
241
  className: classes.thumb,
226
- ownerState: ownerState
242
+ elementType: SwitchThumb,
243
+ externalForwardedProps,
244
+ ownerState
227
245
  });
228
- return /*#__PURE__*/_jsxs(SwitchRoot, {
229
- className: clsx(classes.root, className),
230
- sx: sx,
231
- ownerState: ownerState,
246
+ const icon = /*#__PURE__*/_jsx(ThumbSlot, {
247
+ ...thumbSlotProps
248
+ });
249
+ const [TrackSlot, trackSlotProps] = useSlot('track', {
250
+ className: classes.track,
251
+ elementType: SwitchTrack,
252
+ externalForwardedProps,
253
+ ownerState
254
+ });
255
+ return /*#__PURE__*/_jsxs(RootSlot, {
256
+ ...rootSlotProps,
232
257
  children: [/*#__PURE__*/_jsx(SwitchSwitchBase, {
233
258
  type: "checkbox",
234
259
  icon: icon,
@@ -239,10 +264,25 @@ const Switch = /*#__PURE__*/React.forwardRef(function Switch(inProps, ref) {
239
264
  classes: {
240
265
  ...classes,
241
266
  root: classes.switchBase
267
+ },
268
+ slots: {
269
+ ...(slots.switchBase && {
270
+ root: slots.switchBase
271
+ }),
272
+ ...(slots.input && {
273
+ input: slots.input
274
+ })
275
+ },
276
+ slotProps: {
277
+ ...(slotProps.switchBase && {
278
+ root: typeof slotProps.switchBase === 'function' ? slotProps.switchBase(ownerState) : slotProps.switchBase
279
+ }),
280
+ ...(slotProps.input && {
281
+ input: typeof slotProps.input === 'function' ? slotProps.input(ownerState) : slotProps.input
282
+ })
242
283
  }
243
- }), /*#__PURE__*/_jsx(SwitchTrack, {
244
- className: classes.track,
245
- ownerState: ownerState
284
+ }), /*#__PURE__*/_jsx(TrackSlot, {
285
+ ...trackSlotProps
246
286
  })]
247
287
  });
248
288
  });
@@ -332,6 +372,28 @@ process.env.NODE_ENV !== "production" ? Switch.propTypes /* remove-proptypes */
332
372
  * @default 'medium'
333
373
  */
334
374
  size: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['medium', 'small']), PropTypes.string]),
375
+ /**
376
+ * The props used for each slot inside.
377
+ * @default {}
378
+ */
379
+ slotProps: PropTypes.shape({
380
+ input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
381
+ root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
382
+ switchBase: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
383
+ thumb: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
384
+ track: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
385
+ }),
386
+ /**
387
+ * The components used for each slot inside.
388
+ * @default {}
389
+ */
390
+ slots: PropTypes.shape({
391
+ input: PropTypes.elementType,
392
+ root: PropTypes.elementType,
393
+ switchBase: PropTypes.elementType,
394
+ thumb: PropTypes.elementType,
395
+ track: PropTypes.elementType
396
+ }),
335
397
  /**
336
398
  * The system prop that allows defining system overrides as well as additional CSS styles.
337
399
  */
@@ -16,6 +16,11 @@ import { CreateSlotsAndSlotProps, SlotProps } from "../utils/types.js";
16
16
  export interface TextFieldPropsColorOverrides {}
17
17
  export interface TextFieldPropsSizeOverrides {}
18
18
  export interface TextFieldSlots {
19
+ /**
20
+ * The component that renders the root.
21
+ * @default FormControl
22
+ */
23
+ root: React.ElementType;
19
24
  /**
20
25
  * The component that renders the input.
21
26
  * @default OutlinedInput
@@ -43,10 +48,35 @@ export interface TextFieldSlots {
43
48
  select: React.ElementType;
44
49
  }
45
50
  export type TextFieldSlotsAndSlotProps<InputPropsType> = CreateSlotsAndSlotProps<TextFieldSlots, {
51
+ /**
52
+ * Props forwarded to the root slot.
53
+ * By default, the avaible props are based on the [FormControl](https://mui.com/material-ui/api/form-control/#props) component.
54
+ */
55
+ root: SlotProps<React.ElementType<FormControlProps>, {}, TextFieldOwnerState>;
56
+ /**
57
+ * Props forwarded to the input slot.
58
+ * By default, the avaible props are based on the [Input](https://mui.com/material-ui/api/input/#props) component.
59
+ */
46
60
  input: SlotProps<React.ElementType<InputPropsType>, {}, TextFieldOwnerState>;
61
+ /**
62
+ * Props forwarded to the input label slot.
63
+ * By default, the avaible props are based on the [InputLabel](https://mui.com/material-ui/api/input-label/#props) component.
64
+ */
47
65
  inputLabel: SlotProps<React.ElementType<InputLabelProps>, {}, TextFieldOwnerState>;
66
+ /**
67
+ * Props forwarded to the html input slot.
68
+ * By default, the avaible props are based on the html input element.
69
+ */
48
70
  htmlInput: SlotProps<React.ElementType<InputBaseProps['inputProps']>, {}, TextFieldOwnerState>;
71
+ /**
72
+ * Props forwarded to the form helper text slot.
73
+ * By default, the avaible props are based on the [FormHelperText](https://mui.com/material-ui/api/form-helper-text/#props) component.
74
+ */
49
75
  formHelperText: SlotProps<React.ElementType<FormHelperTextProps>, {}, TextFieldOwnerState>;
76
+ /**
77
+ * Props forwarded to the select slot.
78
+ * By default, the avaible props are based on the [Select](https://mui.com/material-ui/api/select/#props) component.
79
+ */
50
80
  select: SlotProps<React.ElementType<SelectProps>, {}, TextFieldOwnerState>;
51
81
  }>;
52
82
  export interface BaseTextFieldProps extends StandardProps<FormControlProps,
@@ -160,6 +160,25 @@ const TextField = /*#__PURE__*/React.forwardRef(function TextField(inProps, ref)
160
160
  }
161
161
  inputAdditionalProps['aria-describedby'] = undefined;
162
162
  }
163
+ const [RootSlot, rootProps] = useSlot('root', {
164
+ elementType: TextFieldRoot,
165
+ shouldForwardComponentProp: true,
166
+ externalForwardedProps: {
167
+ ...externalForwardedProps,
168
+ ...other
169
+ },
170
+ ownerState,
171
+ className: clsx(classes.root, className),
172
+ ref,
173
+ additionalProps: {
174
+ disabled,
175
+ error,
176
+ fullWidth,
177
+ required,
178
+ color,
179
+ variant
180
+ }
181
+ });
163
182
  const [InputSlot, inputProps] = useSlot('input', {
164
183
  elementType: InputComponent,
165
184
  externalForwardedProps,
@@ -211,17 +230,8 @@ const TextField = /*#__PURE__*/React.forwardRef(function TextField(inProps, ref)
211
230
  },
212
231
  ...inputProps
213
232
  });
214
- return /*#__PURE__*/_jsxs(TextFieldRoot, {
215
- className: clsx(classes.root, className),
216
- disabled: disabled,
217
- error: error,
218
- fullWidth: fullWidth,
219
- ref: ref,
220
- required: required,
221
- color: color,
222
- variant: variant,
223
- ownerState: ownerState,
224
- ...other,
233
+ return /*#__PURE__*/_jsxs(RootSlot, {
234
+ ...rootProps,
225
235
  children: [label != null && label !== '' && /*#__PURE__*/_jsx(InputLabelSlot, {
226
236
  htmlFor: id,
227
237
  id: inputLabelId,
@@ -423,6 +433,7 @@ process.env.NODE_ENV !== "production" ? TextField.propTypes /* remove-proptypes
423
433
  htmlInput: PropTypes.elementType,
424
434
  input: PropTypes.elementType,
425
435
  inputLabel: PropTypes.elementType,
436
+ root: PropTypes.elementType,
426
437
  select: PropTypes.elementType
427
438
  }),
428
439
  /**
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/material v7.0.0-beta.4
2
+ * @mui/material v7.0.0-rc.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,4 +1,4 @@
1
- import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
1
+ import _formatErrorMessage from "@mui/utils/formatMuiErrorMessage";
2
2
  import deepmerge from '@mui/utils/deepmerge';
3
3
  import { darken, getContrastRatio, lighten } from '@mui/system/colorManipulator';
4
4
  import common from "../colors/common.js";
@@ -218,10 +218,10 @@ export default function createPalette(palette) {
218
218
  color.main = color[mainShade];
219
219
  }
220
220
  if (!color.hasOwnProperty('main')) {
221
- throw new Error(process.env.NODE_ENV !== "production" ? `MUI: The color${name ? ` (${name})` : ''} provided to augmentColor(color) is invalid.\n` + `The color object needs to have a \`main\` property or a \`${mainShade}\` property.` : _formatMuiErrorMessage(11, name ? ` (${name})` : '', mainShade));
221
+ throw new Error(process.env.NODE_ENV !== "production" ? `MUI: The color${name ? ` (${name})` : ''} provided to augmentColor(color) is invalid.\n` + `The color object needs to have a \`main\` property or a \`${mainShade}\` property.` : _formatErrorMessage(11, name ? ` (${name})` : '', mainShade));
222
222
  }
223
223
  if (typeof color.main !== 'string') {
224
- throw new Error(process.env.NODE_ENV !== "production" ? `MUI: The color${name ? ` (${name})` : ''} provided to augmentColor(color) is invalid.\n` + `\`color.main\` should be a string, but \`${JSON.stringify(color.main)}\` was provided instead.\n` + '\n' + 'Did you intend to use one of the following approaches?\n' + '\n' + 'import { green } from "@mui/material/colors";\n' + '\n' + 'const theme1 = createTheme({ palette: {\n' + ' primary: green,\n' + '} });\n' + '\n' + 'const theme2 = createTheme({ palette: {\n' + ' primary: { main: green[500] },\n' + '} });' : _formatMuiErrorMessage(12, name ? ` (${name})` : '', JSON.stringify(color.main)));
224
+ throw new Error(process.env.NODE_ENV !== "production" ? `MUI: The color${name ? ` (${name})` : ''} provided to augmentColor(color) is invalid.\n` + `\`color.main\` should be a string, but \`${JSON.stringify(color.main)}\` was provided instead.\n` + '\n' + 'Did you intend to use one of the following approaches?\n' + '\n' + 'import { green } from "@mui/material/colors";\n' + '\n' + 'const theme1 = createTheme({ palette: {\n' + ' primary: green,\n' + '} });\n' + '\n' + 'const theme2 = createTheme({ palette: {\n' + ' primary: { main: green[500] },\n' + '} });' : _formatErrorMessage(12, name ? ` (${name})` : '', JSON.stringify(color.main)));
225
225
  }
226
226
  addLightOrDark(color, 'light', lightShade, tonalOffset);
227
227
  addLightOrDark(color, 'dark', darkShade, tonalOffset);
@@ -1,4 +1,4 @@
1
- import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
1
+ import _formatErrorMessage from "@mui/utils/formatMuiErrorMessage";
2
2
  import deepmerge from '@mui/utils/deepmerge';
3
3
  import styleFunctionSx, { unstable_defaultSxConfig as defaultSxConfig } from '@mui/system/styleFunctionSx';
4
4
  import systemCreateTheme from '@mui/system/createTheme';
@@ -27,7 +27,7 @@ function createThemeNoVars(options = {}, ...args) {
27
27
  options.generateThemeVars === undefined) {
28
28
  throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: `vars` is a private field used for CSS variables support.\n' +
29
29
  // #host-reference
30
- 'Please use another name or follow the [docs](https://mui.com/material-ui/customization/css-theme-variables/usage/) to enable the feature.' : _formatMuiErrorMessage(20));
30
+ 'Please use another name or follow the [docs](https://mui.com/material-ui/customization/css-theme-variables/usage/) to enable the feature.' : _formatErrorMessage(20));
31
31
  }
32
32
  const palette = createPalette(paletteInput);
33
33
  const systemTheme = systemCreateTheme(options);
@@ -1,4 +1,4 @@
1
- import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
1
+ import _formatErrorMessage from "@mui/utils/formatMuiErrorMessage";
2
2
  import deepmerge from '@mui/utils/deepmerge';
3
3
  import { unstable_createGetCssVar as systemCreateGetCssVar, createSpacing } from '@mui/system';
4
4
  import { createUnarySpacing } from '@mui/system/spacing';
@@ -131,7 +131,7 @@ export default function createThemeWithVars(options = {}, ...args) {
131
131
  defaultScheme = true;
132
132
  }
133
133
  if (!defaultScheme) {
134
- throw new Error(process.env.NODE_ENV !== "production" ? `MUI: The \`colorSchemes.${defaultColorScheme}\` option is either missing or invalid.` : _formatMuiErrorMessage(21, defaultColorScheme));
134
+ throw new Error(process.env.NODE_ENV !== "production" ? `MUI: The \`colorSchemes.${defaultColorScheme}\` option is either missing or invalid.` : _formatErrorMessage(21, defaultColorScheme));
135
135
  }
136
136
 
137
137
  // Create the palette for the default color scheme, either `light`, `dark`, or custom color scheme.
@@ -1,4 +1,4 @@
1
- import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
1
+ import _formatErrorMessage from "@mui/utils/formatMuiErrorMessage";
2
2
  export { default as THEME_ID } from "./identifier.js";
3
3
  export { default as adaptV4Theme } from "./adaptV4Theme.js";
4
4
  export { hexToRgb, rgbToHex, hslToRgb, decomposeColor, recomposeColor, getContrastRatio, getLuminance, emphasize, alpha, darken, lighten, css, keyframes } from '@mui/system';
@@ -6,7 +6,7 @@ export { unstable_createBreakpoints } from '@mui/system/createBreakpoints';
6
6
  // TODO: Remove this function in v6.
7
7
  // eslint-disable-next-line @typescript-eslint/naming-convention
8
8
  export function experimental_sx() {
9
- throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: The `experimental_sx` has been moved to `theme.unstable_sx`.' + 'For more details, see https://github.com/mui/material-ui/pull/35150.' : _formatMuiErrorMessage(19));
9
+ throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: The `experimental_sx` has been moved to `theme.unstable_sx`.' + 'For more details, see https://github.com/mui/material-ui/pull/35150.' : _formatErrorMessage(19));
10
10
  }
11
11
  export { default as createTheme } from "./createTheme.js";
12
12
  export { default as unstable_createMuiStrictModeTheme } from "./createMuiStrictModeTheme.js";
@@ -1,4 +1,4 @@
1
- import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
1
+ import _formatErrorMessage from "@mui/utils/formatMuiErrorMessage";
2
2
  export default function makeStyles() {
3
- throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: makeStyles is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.' : _formatMuiErrorMessage(14));
3
+ throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: makeStyles is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.' : _formatErrorMessage(14));
4
4
  }
@@ -1,4 +1,4 @@
1
- import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
1
+ import _formatErrorMessage from "@mui/utils/formatMuiErrorMessage";
2
2
  import { isUnitless, convertLength, responsiveProperty, alignProperty, fontGrid } from "./cssUtils.js";
3
3
  export default function responsiveFontSizes(themeInput, options = {}) {
4
4
  const {
@@ -34,7 +34,7 @@ export default function responsiveFontSizes(themeInput, options = {}) {
34
34
  lineHeight
35
35
  } = style;
36
36
  if (!isUnitless(lineHeight) && !disableAlign) {
37
- throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: Unsupported non-unitless line height with grid alignment.\n' + 'Use unitless line heights instead.' : _formatMuiErrorMessage(6));
37
+ throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: Unsupported non-unitless line height with grid alignment.\n' + 'Use unitless line heights instead.' : _formatErrorMessage(6));
38
38
  }
39
39
  if (!isUnitless(lineHeight)) {
40
40
  // make it unitless
@@ -1,4 +1,4 @@
1
- import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
1
+ import _formatErrorMessage from "@mui/utils/formatMuiErrorMessage";
2
2
  export default function withStyles() {
3
- throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: withStyles is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.' : _formatMuiErrorMessage(15));
3
+ throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: withStyles is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.' : _formatErrorMessage(15));
4
4
  }
@@ -1,4 +1,4 @@
1
- import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
1
+ import _formatErrorMessage from "@mui/utils/formatMuiErrorMessage";
2
2
  export default function withTheme() {
3
- throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: withTheme is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.' : _formatMuiErrorMessage(16));
3
+ throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: withTheme is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.' : _formatErrorMessage(16));
4
4
  }
@@ -1,8 +1,29 @@
1
1
  import clsx from 'clsx';
2
+
3
+ // Brought from [Base UI](https://github.com/mui/base-ui/blob/master/packages/react/src/merge-props/mergeProps.ts#L119)
4
+ // Use it directly from Base UI once it's a package dependency.
5
+ function isEventHandler(key, value) {
6
+ // This approach is more efficient than using a regex.
7
+ const thirdCharCode = key.charCodeAt(2);
8
+ return key[0] === 'o' && key[1] === 'n' && thirdCharCode >= 65 /* A */ && thirdCharCode <= 90 /* Z */ && typeof value === 'function';
9
+ }
2
10
  export default function mergeSlotProps(externalSlotProps, defaultSlotProps) {
3
11
  if (!externalSlotProps) {
4
12
  return defaultSlotProps;
5
13
  }
14
+ function extractHandlers(externalSlotPropsValue, defaultSlotPropsValue) {
15
+ const handlers = {};
16
+ Object.keys(defaultSlotPropsValue).forEach(key => {
17
+ if (isEventHandler(key, defaultSlotPropsValue[key]) && typeof externalSlotPropsValue[key] === 'function') {
18
+ // only compose the handlers if both default and external slot props match the event handler
19
+ handlers[key] = (...args) => {
20
+ externalSlotPropsValue[key](...args);
21
+ defaultSlotPropsValue[key](...args);
22
+ };
23
+ }
24
+ });
25
+ return handlers;
26
+ }
6
27
  if (typeof externalSlotProps === 'function' || typeof defaultSlotProps === 'function') {
7
28
  return ownerState => {
8
29
  const defaultSlotPropsValue = typeof defaultSlotProps === 'function' ? defaultSlotProps(ownerState) : defaultSlotProps;
@@ -11,9 +32,11 @@ export default function mergeSlotProps(externalSlotProps, defaultSlotProps) {
11
32
  ...defaultSlotPropsValue
12
33
  }) : externalSlotProps;
13
34
  const className = clsx(ownerState?.className, defaultSlotPropsValue?.className, externalSlotPropsValue?.className);
35
+ const handlers = extractHandlers(externalSlotPropsValue, defaultSlotPropsValue);
14
36
  return {
15
37
  ...defaultSlotPropsValue,
16
38
  ...externalSlotPropsValue,
39
+ ...handlers,
17
40
  ...(!!className && {
18
41
  className
19
42
  }),
@@ -30,10 +53,12 @@ export default function mergeSlotProps(externalSlotProps, defaultSlotProps) {
30
53
  };
31
54
  }
32
55
  const typedDefaultSlotProps = defaultSlotProps;
56
+ const handlers = extractHandlers(externalSlotProps, typedDefaultSlotProps);
33
57
  const className = clsx(typedDefaultSlotProps?.className, externalSlotProps?.className);
34
58
  return {
35
59
  ...defaultSlotProps,
36
60
  ...externalSlotProps,
61
+ ...handlers,
37
62
  ...(!!className && {
38
63
  className
39
64
  }),
@@ -1,6 +1,6 @@
1
- export const version = "7.0.0-beta.4";
1
+ export const version = "7.0.0-rc.0";
2
2
  export const major = Number("7");
3
3
  export const minor = Number("0");
4
4
  export const patch = Number("0");
5
- export const prerelease = "beta.4";
5
+ export const prerelease = "rc.0";
6
6
  export default version;
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/material v7.0.0-beta.4
2
+ * @mui/material v7.0.0-rc.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
3
+ import _formatErrorMessage from "@mui/utils/formatMuiErrorMessage";
4
4
  var _InputGlobalStyles;
5
5
  import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
@@ -372,7 +372,7 @@ const InputBase = /*#__PURE__*/React.forwardRef(function InputBase(inProps, ref)
372
372
  if (!isControlled) {
373
373
  const element = event.target || inputRef.current;
374
374
  if (element == null) {
375
- throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: Expected valid input target. ' + 'Did you use a custom `inputComponent` and forget to forward refs? ' + 'See https://mui.com/r/input-component-ref-interface for more info.' : _formatMuiErrorMessage(1));
375
+ throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: Expected valid input target. ' + 'Did you use a custom `inputComponent` and forget to forward refs? ' + 'See https://mui.com/r/input-component-ref-interface for more info.' : _formatErrorMessage(1));
376
376
  }
377
377
  checkDirty({
378
378
  value: element.value
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
3
+ import _formatErrorMessage from "@mui/utils/formatMuiErrorMessage";
4
4
  var _span;
5
5
  import * as React from 'react';
6
6
  import { isFragment } from 'react-is';
@@ -348,7 +348,7 @@ const SelectInput = /*#__PURE__*/React.forwardRef(function SelectInput(props, re
348
348
  let selected;
349
349
  if (multiple) {
350
350
  if (!Array.isArray(value)) {
351
- throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: The `value` prop must be an array ' + 'when using the `Select` component with `multiple`.' : _formatMuiErrorMessage(2));
351
+ throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: The `value` prop must be an array ' + 'when using the `Select` component with `multiple`.' : _formatErrorMessage(2));
352
352
  }
353
353
  selected = value.some(v => areEqualValues(v, child.props.value));
354
354
  if (selected && computeDisplay) {
@@ -6,6 +6,11 @@ import { Theme } from "../styles/index.js";
6
6
  import { StepLabelClasses } from "./stepLabelClasses.js";
7
7
  import { CreateSlotsAndSlotProps, SlotProps } from "../utils/types.js";
8
8
  export interface StepLabelSlots {
9
+ /**
10
+ * The component that renders the root.
11
+ * @default span
12
+ */
13
+ root: React.ElementType;
9
14
  /**
10
15
  * The component that renders the label.
11
16
  * @default span
@@ -17,7 +22,20 @@ export interface StepLabelSlots {
17
22
  stepIcon: React.ElementType;
18
23
  }
19
24
  export type StepLabelSlotsAndSlotProps = CreateSlotsAndSlotProps<StepLabelSlots, {
20
- label: SlotProps<React.ElementType<React.HTMLProps<HTMLSpanElement>>, {}, StepLabelOwnerState>;
25
+ /**
26
+ * Props forwarded to the root slot.
27
+ * By default, the avaible props are based on the span element.
28
+ */
29
+ root: SlotProps<'span', {}, StepLabelOwnerState>;
30
+ /**
31
+ * Props forwarded to the label slot.
32
+ * By default, the avaible props are based on the span element.
33
+ */
34
+ label: SlotProps<'span', {}, StepLabelOwnerState>;
35
+ /**
36
+ * Props forwarded to the stepIcon slot.
37
+ * By default, the avaible props are based on the div element.
38
+ */
21
39
  stepIcon: SlotProps<React.ElementType<StepIconProps>, {}, StepLabelOwnerState>;
22
40
  }>;
23
41
  export interface StepLabelOwnerState extends StepLabelProps {}
@@ -162,6 +162,16 @@ const StepLabel = /*#__PURE__*/React.forwardRef(function StepLabel(inProps, ref)
162
162
  ...slotProps
163
163
  }
164
164
  };
165
+ const [RootSlot, rootProps] = useSlot('root', {
166
+ elementType: StepLabelRoot,
167
+ externalForwardedProps: {
168
+ ...externalForwardedProps,
169
+ ...other
170
+ },
171
+ ownerState,
172
+ ref,
173
+ className: clsx(classes.root, className)
174
+ });
165
175
  const [LabelSlot, labelProps] = useSlot('label', {
166
176
  elementType: StepLabelLabel,
167
177
  externalForwardedProps,
@@ -172,11 +182,8 @@ const StepLabel = /*#__PURE__*/React.forwardRef(function StepLabel(inProps, ref)
172
182
  externalForwardedProps,
173
183
  ownerState
174
184
  });
175
- return /*#__PURE__*/_jsxs(StepLabelRoot, {
176
- className: clsx(classes.root, className),
177
- ref: ref,
178
- ownerState: ownerState,
179
- ...other,
185
+ return /*#__PURE__*/_jsxs(RootSlot, {
186
+ ...rootProps,
180
187
  children: [icon || StepIconSlot ? /*#__PURE__*/_jsx(StepLabelIconContainer, {
181
188
  className: classes.iconContainer,
182
189
  ownerState: ownerState,
@@ -242,6 +249,7 @@ process.env.NODE_ENV !== "production" ? StepLabel.propTypes /* remove-proptypes
242
249
  */
243
250
  slotProps: PropTypes.shape({
244
251
  label: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
252
+ root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
245
253
  stepIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
246
254
  }),
247
255
  /**
@@ -250,6 +258,7 @@ process.env.NODE_ENV !== "production" ? StepLabel.propTypes /* remove-proptypes
250
258
  */
251
259
  slots: PropTypes.shape({
252
260
  label: PropTypes.elementType,
261
+ root: PropTypes.elementType,
253
262
  stepIcon: PropTypes.elementType
254
263
  }),
255
264
  /**
@@ -2,11 +2,72 @@ import * as React from 'react';
2
2
  import { SxProps } from '@mui/system';
3
3
  import { OverridableStringUnion } from '@mui/types';
4
4
  import { InternalStandardProps as StandardProps, Theme } from "../index.js";
5
+ import { CreateSlotsAndSlotProps, SlotProps } from "../utils/types.js";
5
6
  import { SwitchBaseProps } from "../internal/SwitchBase.js";
6
7
  import { SwitchClasses } from "./switchClasses.js";
7
8
  export interface SwitchPropsSizeOverrides {}
8
9
  export interface SwitchPropsColorOverrides {}
9
- export interface SwitchProps extends StandardProps<SwitchBaseProps, 'checkedIcon' | 'color' | 'icon'> {
10
+ export interface SwitchRootSlotPropsOverrides {}
11
+ export interface SwitchTrackSlotPropsOverrides {}
12
+ export interface SwitchThumbSlotPropsOverrides {}
13
+ export interface SwitchSwitchBaseSlotPropsOverrides {}
14
+ export interface SwitchInputSlotPropsOverrides {}
15
+ export interface SwitchSlots {
16
+ /**
17
+ * The component that renders the root slot.
18
+ * @default 'span'
19
+ */
20
+ root: React.ElementType;
21
+ /**
22
+ * The component that renders the track slot.
23
+ * @default 'span'
24
+ */
25
+ track: React.ElementType;
26
+ /**
27
+ * The component that renders the thumb slot.
28
+ * @default 'span'
29
+ */
30
+ thumb: React.ElementType;
31
+ /**
32
+ * The component that renders the switchBase slot.
33
+ * @default SwitchBase
34
+ */
35
+ switchBase: React.ElementType;
36
+ /**
37
+ * The component that renders the switchBase's input slot.
38
+ * @default SwitchBaseInput
39
+ */
40
+ input: React.ElementType;
41
+ }
42
+ export type SwitchSlotsAndSlotProps = CreateSlotsAndSlotProps<SwitchSlots, {
43
+ /**
44
+ * Props forwarded to the root slot.
45
+ * By default, the avaible props are based on the span element.
46
+ */
47
+ root: SlotProps<'span', SwitchRootSlotPropsOverrides, SwitchOwnerState>;
48
+ /**
49
+ * Props forwarded to the track slot.
50
+ * By default, the avaible props are based on the span element.
51
+ */
52
+ track: SlotProps<'span', SwitchTrackSlotPropsOverrides, SwitchOwnerState>;
53
+ /**
54
+ * Props forwarded to the thumb slot.
55
+ * By default, the avaible props are based on the span element.
56
+ */
57
+ thumb: SlotProps<'span', SwitchThumbSlotPropsOverrides, SwitchOwnerState>;
58
+ /**
59
+ * Props forwarded to the switchBase slot.
60
+ * By default, the avaible props are based on the internal SwitchBase component.
61
+ */
62
+ switchBase: SlotProps<React.ElementType<SwitchBaseProps>, SwitchSwitchBaseSlotPropsOverrides, SwitchOwnerState>;
63
+ /**
64
+ * Props forwarded to the input slot.
65
+ * By default, the avaible props are based on the input element.
66
+ */
67
+ input: SlotProps<'input', SwitchInputSlotPropsOverrides, SwitchOwnerState>;
68
+ }>;
69
+ export interface SwitchOwnerState extends Omit<SwitchProps, 'slots' | 'slotProps'> {}
70
+ export interface SwitchProps extends StandardProps<SwitchBaseProps, 'checkedIcon' | 'color' | 'icon' | 'slots' | 'slotProps'>, SwitchSlotsAndSlotProps {
10
71
  /**
11
72
  * The icon to display when the component is checked.
12
73
  */