Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Move SwitchUnstyled docs to the Base space #31964

Merged
merged 6 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/data/base/components/switch/switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
product: base
title: React Switch component
components: SwitchUnstyled
githubLabel: 'component: switch'
waiAria: https://www.w3.org/TR/wai-aria-practices/#switch
packageName: '@mui/base'
---

# Switch

<p class="description">Switches toggle the state of a single setting on or off.</p>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add the features list?!

Copy link
Member

@mnajdova mnajdova Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should add it in all components. The Switch is a rather simple component, not sure it deserves a features list :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, yeah... it's a valid point. Though I confess I like the consistency of having in all of them, even in simpler ones like the Switch. I appreciate the Radix team for doing that, it's easy to scan through!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, from their list, I would expect all components to support those features of hey are input components :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revisit this for all components and make sure we at least don't miss it on the more complex ones.

Switches are the preferred way to adjust settings on mobile.
The option that the switch controls, as well as the state it's in, should be made clear from the corresponding inline label.

{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}

## SwitchUnstyled

```jsx
import SwitchUnstyled from '@mui/base/SwitchUnstyled';
```

The `SwitchUnstyled` component provides default components and assigns CSS classes you can style entirely on your own.
You are free to choose any styling solution - plain CSS classes, a CSS framework, Emotion, etc.
It is also possible to replace these default components by other HTML elements or custom components.

There are three components you can override by the `components` prop: `Root`, `Thumb` and `Input`. Each one's props can be set using the `componentsProps` object.

{{"demo": "UnstyledSwitches.js"}}

## useSwitch

For the ultimate customizability, a `useSwitch` hook is available.
It accepts almost the same options as the SwitchUnstyled component minus the `component`, `components`, and `componentsProps` props.

```jsx
import { useSwitch } from '@mui/base/SwitchUnstyled';
```

### Basic example

{{"demo": "UseSwitchesBasic.js"}}

### Customized look and feel

{{"demo": "UseSwitchesCustom.js"}}
1 change: 1 addition & 0 deletions docs/data/base/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const pages = [
children: [
{ pathname: '/base/react-button', title: 'Button' },
{ pathname: '/base/react-input', title: 'Input' },
{ pathname: '/base/react-switch', title: 'Switch' },
],
},
{
Expand Down
38 changes: 2 additions & 36 deletions docs/data/material/components/switches/switches.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
product: material-ui
title: React Switch component
components: Switch, FormControl, FormGroup, FormLabel, FormControlLabel, SwitchUnstyled
components: Switch, FormControl, FormGroup, FormLabel, FormControlLabel
githubLabel: 'component: switch'
materialDesign: https://material.io/components/selection-controls#switches
unstyled: /base/react-switch
---

# Switch
Expand Down Expand Up @@ -58,41 +59,6 @@ You can learn more about this in the [overrides documentation page](/customizati

🎨 If you are looking for inspiration, you can check [MUI Treasury's customization examples](https://mui-treasury.com/styles/switch/).

## Unstyled

The switch also comes with an unstyled version. It's ideal for doing heavy customizations and minimizing bundle size.

### Unstyled component

```jsx
import SwitchUnstyled from '@mui/base/SwitchUnstyled';
```

The `SwitchUnstyled` component provides default components and assigns CSS classes you can style entirely on your own.
You are free to choose any styling solution - plain CSS classes, a CSS framework, Emotion, etc.
It is also possible to replace these default components by other HTML elements or custom components.

There are three components you can override by the `components` prop: `Root`, `Thumb` and `Input`. Each one's props can be set using the `componentsProps` object.

{{"demo": "UnstyledSwitches.js"}}

### useSwitch hook

For the ultimate customizability, a `useSwitch` hook is available.
It accepts almost the same options as the SwitchUnstyled component minus the `component`, `components`, and `componentsProps` props.

```jsx
import { useSwitch } from '@mui/base/SwitchUnstyled';
```

#### Basic example

{{"demo": "UseSwitchesBasic.js"}}

#### Customized look and feel

{{"demo": "UseSwitchesCustom.js"}}

## Label placement

You can change the placement of the label:
Expand Down
23 changes: 0 additions & 23 deletions docs/pages/api-docs/switch-unstyled.js

This file was deleted.

34 changes: 0 additions & 34 deletions docs/pages/api-docs/switch-unstyled.json

This file was deleted.

2 changes: 1 addition & 1 deletion docs/pages/base/api/switch-unstyled.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"forwardsRefTo": "HTMLSpanElement",
"filename": "/packages/mui-base/src/SwitchUnstyled/SwitchUnstyled.tsx",
"inheritance": null,
"demos": "<ul><li><a href=\"/material-ui/react-switch/\">Switches</a></li></ul>",
"demos": "<ul><li><a href=\"/base/react-switch/\">Switch</a></li></ul>",
"cssComponent": false
}
11 changes: 11 additions & 0 deletions docs/pages/base/react-switch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import {
demos,
docs,
demoComponents,
} from 'docs/data/base/components/switch/switch.md?@mui/markdown';

export default function Page() {
return <MarkdownDocs demos={demos} docs={docs} demoComponents={demoComponents} />;
}
3 changes: 2 additions & 1 deletion docs/scripts/buildApiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ const migratedBaseComponents = [
'ButtonUnstyled',
'ClickAwayListener',
'InputUnstyled',
'MenuUnstyled',
'MenuItemUnstyled',
'MenuUnstyled',
'ModalUnstyled',
'Portal',
'SwitchUnstyled',
];

export const getGenericComponentInfo = (filename: string): ComponentInfo => {
Expand Down
1 change: 0 additions & 1 deletion docs/src/pagesApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ module.exports = [
{ pathname: '/api-docs/svg-icon' },
{ pathname: '/api-docs/swipeable-drawer' },
{ pathname: '/api-docs/switch' },
{ pathname: '/api-docs/switch-unstyled' },
{ pathname: '/api-docs/tab' },
{ pathname: '/api-docs/tab-context' },
{ pathname: '/api-docs/table' },
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-base/src/SwitchUnstyled/SwitchUnstyled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ export interface SwitchUnstyledProps extends UseSwitchProps {
*
* Demos:
*
* - [Switches](https://mui.com/components/switches/)
* - [Switch](https://mui.com/base/react-switch/)
*
* API:
*
* - [SwitchUnstyled API](https://mui.com/api/switch-unstyled/)
* - [SwitchUnstyled API](https://mui.com/base/api/switch-unstyled/)
*/
const SwitchUnstyled = React.forwardRef(function SwitchUnstyled(
props: SwitchUnstyledProps,
Expand Down