Skip to content

Commit

Permalink
[base] components -> slots API rename (#34693)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak authored Oct 19, 2022
1 parent 95d1707 commit 9f2711b
Show file tree
Hide file tree
Showing 235 changed files with 2,235 additions and 1,748 deletions.
14 changes: 5 additions & 9 deletions docs/data/base/components/badge/badge.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,23 @@ Use the `component` prop to override the root slot with a custom element:
<BadgeUnstyled component="div" />
```

Use the `components` prop to override any interior slots in addition to the root:
Use the `slots` prop to override any interior slots in addition to the root:

```jsx
<BadgeUnstyled components={{ Root: 'div', Badge: 'div' }} />
<BadgeUnstyled slots={{ root: 'div', badge: 'div' }} />
```

:::warning
If the root element is customized with both the `component` and `components` props, then `component` will take precedence.
If the root element is customized with both the `component` and `slots` props, then `component` will take precedence.
:::

Use the `componentsProps` prop to pass custom props to internal slots.
Use the `slotProps` prop to pass custom props to internal slots.
The following code snippet applies a CSS class called `my-badge` to the badge slot:

```jsx
<BadgeUnstyled componentsProps={{ badge: { className: 'my-badge' } }} />
<BadgeUnstyled slotProps={{ badge: { className: 'my-badge' } }} />
```

:::warning
Note that `componentsProps` slot names are written in lowercase (`root`) while `components` slot names are capitalized (`Root`).
:::

## Hook

```jsx
Expand Down
14 changes: 5 additions & 9 deletions docs/data/base/components/button/button.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,23 @@ Use the `component` prop to override the root slot with a custom element:

If you provide a non-interactive element such as a `<span>`, the `ButtonUnstyled` component will automatically add the necessary accessibility attributes.

Use the `components` prop to override any interior slots in addition to the root:
Use the `slots` prop to override any interior slots in addition to the root:

```jsx
<ButtonUnstyled components={{ Root: 'div' }} />
<ButtonUnstyled slots={{ root: 'div' }} />
```

:::warning
If the root element is customized with both the `component` and `components` props, then `component` will take precedence.
If the root element is customized with both the `component` and `slots` props, then `component` will take precedence.
:::

Use the `componentsProps` prop to pass custom props to internal slots.
Use the `slotProps` prop to pass custom props to internal slots.
The following code snippet applies a CSS class called `my-button` to the root slot:

```jsx
<ButtonUnstyled componentsProps={{ root: { className: 'my-button' } }} />
<ButtonUnstyled slotProps={{ root: { className: 'my-button' } }} />
```

:::warning
Note that `componentsProps` slot names are written in lowercase (`root`) while `components` slot names are capitalized (`Root`).
:::

Compare the attributes on the `<span>` in this demo with the `ButtonUnstyled` from the previous demo:

{{"demo": "UnstyledButtonsSpan.js"}}
Expand Down
18 changes: 9 additions & 9 deletions docs/data/base/components/input/InputAdornments.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ const InputAdornment = styled('div')`
`;

const CustomInput = React.forwardRef(function CustomInput(props, ref) {
const { components, ...other } = props;
const { slots, ...other } = props;
return (
<InputUnstyled
components={{
Root: StyledInputRoot,
Input: StyledInputElement,
...components,
slots={{
root: StyledInputRoot,
input: StyledInputElement,
...slots,
}}
{...other}
ref={ref}
Expand All @@ -109,10 +109,10 @@ CustomInput.propTypes = {
* Either a string to use a HTML element or a component.
* @default {}
*/
components: PropTypes.shape({
Input: PropTypes.elementType,
Root: PropTypes.elementType,
Textarea: PropTypes.elementType,
slots: PropTypes.shape({
input: PropTypes.elementType,
root: PropTypes.elementType,
textarea: PropTypes.elementType,
}),
};

Expand Down
10 changes: 5 additions & 5 deletions docs/data/base/components/input/InputAdornments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ const CustomInput = React.forwardRef(function CustomInput(
props: InputUnstyledProps,
ref: React.ForwardedRef<HTMLDivElement>,
) {
const { components, ...other } = props;
const { slots, ...other } = props;
return (
<InputUnstyled
components={{
Root: StyledInputRoot,
Input: StyledInputElement,
...components,
slots={{
root: StyledInputRoot,
input: StyledInputElement,
...slots,
}}
{...other}
ref={ref}
Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/components/input/InputMultiline.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const StyledTextareaElement = styled('textarea', {
const CustomInput = React.forwardRef(function CustomInput(props, ref) {
return (
<InputUnstyled
components={{ Input: StyledInputElement, Textarea: StyledTextareaElement }}
slots={{ input: StyledInputElement, textarea: StyledTextareaElement }}
{...props}
ref={ref}
/>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/components/input/InputMultiline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const CustomInput = React.forwardRef(function CustomInput(
) {
return (
<InputUnstyled
components={{ Input: StyledInputElement, Textarea: StyledTextareaElement }}
slots={{ input: StyledInputElement, textarea: StyledTextareaElement }}
{...props}
ref={ref}
/>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/components/input/InputMultilineAutosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const StyledTextareaElement = styled(TextareaAutosize)(
const CustomInput = React.forwardRef(function CustomInput(props, ref) {
return (
<InputUnstyled
components={{ Input: StyledInputElement, Textarea: StyledTextareaElement }}
slots={{ input: StyledInputElement, textarea: StyledTextareaElement }}
{...props}
ref={ref}
/>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/components/input/InputMultilineAutosize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const CustomInput = React.forwardRef(function CustomInput(
) {
return (
<InputUnstyled
components={{ Input: StyledInputElement, Textarea: StyledTextareaElement }}
slots={{ input: StyledInputElement, textarea: StyledTextareaElement }}
{...props}
ref={ref}
/>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/components/input/UnstyledInputBasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const StyledInputElement = styled('input')(

const CustomInput = React.forwardRef(function CustomInput(props, ref) {
return (
<InputUnstyled components={{ Input: StyledInputElement }} {...props} ref={ref} />
<InputUnstyled slots={{ input: StyledInputElement }} {...props} ref={ref} />
);
});

Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/components/input/UnstyledInputBasic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const CustomInput = React.forwardRef(function CustomInput(
ref: React.ForwardedRef<HTMLDivElement>,
) {
return (
<InputUnstyled components={{ Input: StyledInputElement }} {...props} ref={ref} />
<InputUnstyled slots={{ input: StyledInputElement }} {...props} ref={ref} />
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const StyledInputElement = styled('input')(

const CustomInput = React.forwardRef(function CustomInput(props, ref) {
return (
<InputUnstyled components={{ Input: StyledInputElement }} {...props} ref={ref} />
<InputUnstyled slots={{ input: StyledInputElement }} {...props} ref={ref} />
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const CustomInput = React.forwardRef(function CustomInput(
ref: React.ForwardedRef<HTMLDivElement>,
) {
return (
<InputUnstyled components={{ Input: StyledInputElement }} {...props} ref={ref} />
<InputUnstyled slots={{ input: StyledInputElement }} {...props} ref={ref} />
);
});

Expand Down
14 changes: 5 additions & 9 deletions docs/data/base/components/input/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,23 @@ Use the `component` prop to override the root slot with a custom element:
<InputUnstyled component="aside" />
```

Use the `components` prop to override any interior slots in addition to the root:
Use the `slots` prop to override any interior slots in addition to the root:

```jsx
<InputUnstyled components={{ Root: 'aside' }} />
<InputUnstyled slots={{ root: 'aside' }} />
```

:::warning
If the root element is customized with both the `component` and `components` props, then `component` will take precedence.
If the root element is customized with both the `component` and `slots` props, then `component` will take precedence.
:::

Use the `componentsProps` prop to pass custom props to internal slots.
Use the `slotProps` prop to pass custom props to internal slots.
The following code snippet applies a CSS class called `my-input` to the input slot:

```jsx
<InputUnstyled componentsProps={{ input: { className: 'my-input' } }} />
<InputUnstyled slotProps={{ input: { className: 'my-input' } }} />
```

:::warning
Note that `componentsProps` slot names are written in lowercase (`root`) while `components` slot names are capitalized (`Root`).
:::

## Hook

```js
Expand Down
4 changes: 2 additions & 2 deletions docs/data/base/components/menu/MenuSimple.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ export default function UnstyledMenuSimple() {
open={isOpen}
onClose={close}
anchorEl={anchorEl}
components={{ Root: Popper, Listbox: StyledListbox }}
componentsProps={{ listbox: { id: 'simple-menu' } }}
slots={{ root: Popper, listbox: StyledListbox }}
slotProps={{ listbox: { id: 'simple-menu' } }}
>
<StyledMenuItem onClick={createHandleMenuClick('Profile')}>
Profile
Expand Down
4 changes: 2 additions & 2 deletions docs/data/base/components/menu/MenuSimple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ export default function UnstyledMenuSimple() {
open={isOpen}
onClose={close}
anchorEl={anchorEl}
components={{ Root: Popper, Listbox: StyledListbox }}
componentsProps={{ listbox: { id: 'simple-menu' } }}
slots={{ root: Popper, listbox: StyledListbox }}
slotProps={{ listbox: { id: 'simple-menu' } }}
>
<StyledMenuItem onClick={createHandleMenuClick('Profile')}>
Profile
Expand Down
4 changes: 2 additions & 2 deletions docs/data/base/components/menu/UnstyledMenuIntroduction.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ export default function UnstyledMenuIntroduction() {
open={isOpen}
onClose={close}
anchorEl={anchorEl}
components={{ Root: Popper, Listbox: StyledListbox }}
componentsProps={{ listbox: { id: 'simple-menu' } }}
slots={{ root: Popper, listbox: StyledListbox }}
slotProps={{ listbox: { id: 'simple-menu' } }}
>
<StyledMenuItem onClick={createHandleMenuClick('Profile')}>
Profile
Expand Down
4 changes: 2 additions & 2 deletions docs/data/base/components/menu/UnstyledMenuIntroduction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ export default function UnstyledMenuIntroduction() {
open={isOpen}
onClose={close}
anchorEl={anchorEl}
components={{ Root: Popper, Listbox: StyledListbox }}
componentsProps={{ listbox: { id: 'simple-menu' } }}
slots={{ root: Popper, listbox: StyledListbox }}
slotProps={{ listbox: { id: 'simple-menu' } }}
>
<StyledMenuItem onClick={createHandleMenuClick('Profile')}>
Profile
Expand Down
4 changes: 2 additions & 2 deletions docs/data/base/components/menu/WrappedMenuItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ export default function WrappedMenuItems() {
open={isOpen}
onClose={close}
anchorEl={anchorEl}
components={{ Root: Popper, Listbox: StyledListbox }}
componentsProps={{ listbox: { id: 'simple-menu' } }}
slots={{ root: Popper, listbox: StyledListbox }}
slotProps={{ listbox: { id: 'simple-menu' } }}
>
<MenuSection label="Navigation">
<StyledMenuItem onClick={createHandleMenuClick('Back')}>
Expand Down
4 changes: 2 additions & 2 deletions docs/data/base/components/menu/WrappedMenuItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ export default function WrappedMenuItems() {
open={isOpen}
onClose={close}
anchorEl={anchorEl}
components={{ Root: Popper, Listbox: StyledListbox }}
componentsProps={{ listbox: { id: 'simple-menu' } }}
slots={{ root: Popper, listbox: StyledListbox }}
slotProps={{ listbox: { id: 'simple-menu' } }}
>
<MenuSection label="Navigation">
<StyledMenuItem onClick={createHandleMenuClick('Back')}>
Expand Down
14 changes: 5 additions & 9 deletions docs/data/base/components/menu/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,23 @@ Use the `component` prop to override the root slot with a custom element:
<MenuItemUnstyled component="span" />
```

Use the `components` prop to override any interior slots in addition to the root:
Use the `slots` prop to override any interior slots in addition to the root:

```jsx
<MenuUnstyled components={{ Root: 'nav', Listbox: 'ol' }} />
<MenuUnstyled slots={{ root: 'nav', listbox: 'ol' }} />
```

:::warning
If the root element is customized with both the `component` and `components` props, then `component` will take precedence.
If the root element is customized with both the `component` and `slots` props, then `component` will take precedence.
:::

Use the `componentsProps` prop to pass custom props to internal slots.
Use the `slotProps` prop to pass custom props to internal slots.
The following code snippet applies a CSS class called `my-listbox` to the listbox slot:

```jsx
<MenuUnstyled componentsProps={{ listbox: { className: 'my-listbox' } }} />
<MenuUnstyled slotProps={{ listbox: { className: 'my-listbox' } }} />
```

:::warning
Note that `componentsProps` slot names are written in lowercase (`root`) while `components` slot names are capitalized (`Root`).
:::

### CSS classes

`MenuUnstyled` can set the following class:
Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/components/modal/KeepMountedModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function ModalUnstyledDemo() {
aria-describedby="keep-mounted-modal-description"
open={open}
onClose={handleClose}
components={{ Backdrop }}
slots={{ backdrop: Backdrop }}
keepMounted
>
<Box sx={style}>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/components/modal/KeepMountedModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function ModalUnstyledDemo() {
aria-describedby="keep-mounted-modal-description"
open={open}
onClose={handleClose}
components={{ Backdrop }}
slots={{ backdrop: Backdrop }}
keepMounted
>
<Box sx={style}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
aria-describedby="keep-mounted-modal-description"
open={open}
onClose={handleClose}
components={{ Backdrop }}
slots={{ backdrop: Backdrop }}
keepMounted
>
<Box sx={style}>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/components/modal/ModalUnstyled.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function ModalUnstyledDemo() {
aria-describedby="unstyled-modal-description"
open={open}
onClose={handleClose}
components={{ Backdrop }}
slots={{ backdrop: Backdrop }}
>
<Box sx={style}>
<h2 id="unstyled-modal-title">Text in a modal</h2>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/components/modal/ModalUnstyled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function ModalUnstyledDemo() {
aria-describedby="unstyled-modal-description"
open={open}
onClose={handleClose}
components={{ Backdrop }}
slots={{ backdrop: Backdrop }}
>
<Box sx={style}>
<h2 id="unstyled-modal-title">Text in a modal</h2>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/components/modal/ModalUnstyled.tsx.preview
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
aria-describedby="unstyled-modal-description"
open={open}
onClose={handleClose}
components={{ Backdrop }}
slots={{ backdrop: Backdrop }}
>
<Box sx={style}>
<h2 id="unstyled-modal-title">Text in a modal</h2>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/components/modal/NestedModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default function NestedModal() {
onClose={handleClose}
aria-labelledby="parent-modal-title"
aria-describedby="parent-modal-description"
components={{ Backdrop }}
slots={{ backdrop: Backdrop }}
>
<Box sx={style}>
<h2 id="parent-modal-title">Text in a modal</h2>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/components/modal/NestedModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function NestedModal() {
onClose={handleClose}
aria-labelledby="parent-modal-title"
aria-describedby="parent-modal-description"
components={{ Backdrop }}
slots={{ backdrop: Backdrop }}
>
<Box sx={style}>
<h2 id="parent-modal-title">Text in a modal</h2>
Expand Down
Loading

0 comments on commit 9f2711b

Please sign in to comment.