Skip to content

Commit

Permalink
[docs][base] Move styles to the bottom of demos code for `SwitchUnst…
Browse files Browse the repository at this point in the history
…yled` (mui#36720)

Co-authored-by: Michał Dudak <[email protected]>
  • Loading branch information
2 people authored and binh1298 committed May 17, 2023
1 parent d3daa86 commit f64e0e9
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 154 deletions.
25 changes: 12 additions & 13 deletions docs/data/base/components/switch/UnstyledSwitchIntroduction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ import * as React from 'react';
import { styled } from '@mui/system';
import Switch, { switchClasses } from '@mui/base/Switch';

export default function UnstyledSwitches() {
const label = { slotProps: { input: { 'aria-label': 'Demo switch' } } };

return (
<div>
<Switch component={Root} {...label} defaultChecked />
<Switch component={Root} {...label} />
<Switch component={Root} {...label} defaultChecked disabled />
<Switch component={Root} {...label} disabled />
</div>
);
}
const blue = {
500: '#007FFF',
};
Expand Down Expand Up @@ -81,16 +93,3 @@ const Root = styled('span')(
}
`,
);

export default function UnstyledSwitches() {
const label = { slotProps: { input: { 'aria-label': 'Demo switch' } } };

return (
<div>
<Switch component={Root} {...label} defaultChecked />
<Switch component={Root} {...label} />
<Switch component={Root} {...label} defaultChecked disabled />
<Switch component={Root} {...label} disabled />
</div>
);
}
25 changes: 12 additions & 13 deletions docs/data/base/components/switch/UnstyledSwitchIntroduction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ import * as React from 'react';
import { styled } from '@mui/system';
import Switch, { switchClasses } from '@mui/base/Switch';

export default function UnstyledSwitches() {
const label = { slotProps: { input: { 'aria-label': 'Demo switch' } } };

return (
<div>
<Switch component={Root} {...label} defaultChecked />
<Switch component={Root} {...label} />
<Switch component={Root} {...label} defaultChecked disabled />
<Switch component={Root} {...label} disabled />
</div>
);
}
const blue = {
500: '#007FFF',
};
Expand Down Expand Up @@ -81,16 +93,3 @@ const Root = styled('span')(
}
`,
);

export default function UnstyledSwitches() {
const label = { slotProps: { input: { 'aria-label': 'Demo switch' } } };

return (
<div>
<Switch component={Root} {...label} defaultChecked />
<Switch component={Root} {...label} />
<Switch component={Root} {...label} defaultChecked disabled />
<Switch component={Root} {...label} disabled />
</div>
);
}
25 changes: 12 additions & 13 deletions docs/data/base/components/switch/UnstyledSwitches.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ import * as React from 'react';
import { styled } from '@mui/system';
import Switch, { switchClasses } from '@mui/base/Switch';

export default function UnstyledSwitches() {
const label = { slotProps: { input: { 'aria-label': 'Demo switch' } } };

return (
<div>
<Switch component={Root} {...label} defaultChecked />
<Switch component={Root} {...label} />
<Switch component={Root} {...label} defaultChecked disabled />
<Switch component={Root} {...label} disabled />
</div>
);
}
const blue = {
500: '#007FFF',
};
Expand Down Expand Up @@ -81,16 +93,3 @@ const Root = styled('span')(
}
`,
);

export default function UnstyledSwitches() {
const label = { slotProps: { input: { 'aria-label': 'Demo switch' } } };

return (
<div>
<Switch component={Root} {...label} defaultChecked />
<Switch component={Root} {...label} />
<Switch component={Root} {...label} defaultChecked disabled />
<Switch component={Root} {...label} disabled />
</div>
);
}
25 changes: 12 additions & 13 deletions docs/data/base/components/switch/UnstyledSwitches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ import * as React from 'react';
import { styled } from '@mui/system';
import Switch, { switchClasses } from '@mui/base/Switch';

export default function UnstyledSwitches() {
const label = { slotProps: { input: { 'aria-label': 'Demo switch' } } };

return (
<div>
<Switch component={Root} {...label} defaultChecked />
<Switch component={Root} {...label} />
<Switch component={Root} {...label} defaultChecked disabled />
<Switch component={Root} {...label} disabled />
</div>
);
}
const blue = {
500: '#007FFF',
};
Expand Down Expand Up @@ -81,16 +93,3 @@ const Root = styled('span')(
}
`,
);

export default function UnstyledSwitches() {
const label = { slotProps: { input: { 'aria-label': 'Demo switch' } } };

return (
<div>
<Switch component={Root} {...label} defaultChecked />
<Switch component={Root} {...label} />
<Switch component={Root} {...label} defaultChecked disabled />
<Switch component={Root} {...label} disabled />
</div>
);
}
56 changes: 28 additions & 28 deletions docs/data/base/components/switch/UseSwitchesBasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,34 @@ import clsx from 'clsx';
import { styled } from '@mui/system';
import useSwitch from '@mui/base/useSwitch';

export default function UseSwitchesBasic() {
return (
<div>
<BasicSwitch defaultChecked />
<BasicSwitch />
<BasicSwitch defaultChecked disabled />
<BasicSwitch disabled />
</div>
);
}

function BasicSwitch(props) {
const { getInputProps, checked, disabled, focusVisible } = useSwitch(props);

const stateClasses = {
'Switch-checked': checked,
'Switch-disabled': disabled,
'Switch-focusVisible': focusVisible,
};

return (
<BasicSwitchRoot className={clsx(stateClasses)}>
<BasicSwitchThumb className={clsx(stateClasses)} />
<BasicSwitchInput {...getInputProps()} aria-label="Demo switch" />
</BasicSwitchRoot>
);
}

const blue = {
500: '#007FFF',
};
Expand Down Expand Up @@ -72,31 +100,3 @@ const BasicSwitchThumb = styled('span')`
background-color: #fff;
}
`;

function BasicSwitch(props) {
const { getInputProps, checked, disabled, focusVisible } = useSwitch(props);

const stateClasses = {
'Switch-checked': checked,
'Switch-disabled': disabled,
'Switch-focusVisible': focusVisible,
};

return (
<BasicSwitchRoot className={clsx(stateClasses)}>
<BasicSwitchThumb className={clsx(stateClasses)} />
<BasicSwitchInput {...getInputProps()} aria-label="Demo switch" />
</BasicSwitchRoot>
);
}

export default function UseSwitchesBasic() {
return (
<div>
<BasicSwitch defaultChecked />
<BasicSwitch />
<BasicSwitch defaultChecked disabled />
<BasicSwitch disabled />
</div>
);
}
56 changes: 28 additions & 28 deletions docs/data/base/components/switch/UseSwitchesBasic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,34 @@ import clsx from 'clsx';
import { styled } from '@mui/system';
import useSwitch, { UseSwitchParameters } from '@mui/base/useSwitch';

export default function UseSwitchesBasic() {
return (
<div>
<BasicSwitch defaultChecked />
<BasicSwitch />
<BasicSwitch defaultChecked disabled />
<BasicSwitch disabled />
</div>
);
}

function BasicSwitch(props: UseSwitchParameters) {
const { getInputProps, checked, disabled, focusVisible } = useSwitch(props);

const stateClasses = {
'Switch-checked': checked,
'Switch-disabled': disabled,
'Switch-focusVisible': focusVisible,
};

return (
<BasicSwitchRoot className={clsx(stateClasses)}>
<BasicSwitchThumb className={clsx(stateClasses)} />
<BasicSwitchInput {...getInputProps()} aria-label="Demo switch" />
</BasicSwitchRoot>
);
}

const blue = {
500: '#007FFF',
};
Expand Down Expand Up @@ -72,31 +100,3 @@ const BasicSwitchThumb = styled('span')`
background-color: #fff;
}
`;

function BasicSwitch(props: UseSwitchParameters) {
const { getInputProps, checked, disabled, focusVisible } = useSwitch(props);

const stateClasses = {
'Switch-checked': checked,
'Switch-disabled': disabled,
'Switch-focusVisible': focusVisible,
};

return (
<BasicSwitchRoot className={clsx(stateClasses)}>
<BasicSwitchThumb className={clsx(stateClasses)} />
<BasicSwitchInput {...getInputProps()} aria-label="Demo switch" />
</BasicSwitchRoot>
);
}

export default function UseSwitchesBasic() {
return (
<div>
<BasicSwitch defaultChecked />
<BasicSwitch />
<BasicSwitch defaultChecked disabled />
<BasicSwitch disabled />
</div>
);
}
46 changes: 23 additions & 23 deletions docs/data/base/components/switch/UseSwitchesCustom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ import clsx from 'clsx';
import { styled } from '@mui/system';
import useSwitch from '@mui/base/useSwitch';

export default function UseSwitchesCustom() {
return <MUISwitch defaultChecked />;
}

function MUISwitch(props) {
const { getInputProps, checked, disabled, focusVisible } = useSwitch(props);

const stateClasses = {
checked,
disabled,
focusVisible,
};

return (
<SwitchRoot className={clsx(stateClasses)}>
<SwitchTrack>
<SwitchThumb className={clsx(stateClasses)} />
</SwitchTrack>
<SwitchInput {...getInputProps()} aria-label="Demo switch" />
</SwitchRoot>
);
}

const blue = {
700: '#0059B2',
};
Expand Down Expand Up @@ -78,26 +101,3 @@ const SwitchTrack = styled('span')(
display: block;
`,
);

function MUISwitch(props) {
const { getInputProps, checked, disabled, focusVisible } = useSwitch(props);

const stateClasses = {
checked,
disabled,
focusVisible,
};

return (
<SwitchRoot className={clsx(stateClasses)}>
<SwitchTrack>
<SwitchThumb className={clsx(stateClasses)} />
</SwitchTrack>
<SwitchInput {...getInputProps()} aria-label="Demo switch" />
</SwitchRoot>
);
}

export default function UseSwitchesCustom() {
return <MUISwitch defaultChecked />;
}
46 changes: 23 additions & 23 deletions docs/data/base/components/switch/UseSwitchesCustom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ import clsx from 'clsx';
import { styled } from '@mui/system';
import useSwitch, { UseSwitchParameters } from '@mui/base/useSwitch';

export default function UseSwitchesCustom() {
return <MUISwitch defaultChecked />;
}

function MUISwitch(props: UseSwitchParameters) {
const { getInputProps, checked, disabled, focusVisible } = useSwitch(props);

const stateClasses = {
checked,
disabled,
focusVisible,
};

return (
<SwitchRoot className={clsx(stateClasses)}>
<SwitchTrack>
<SwitchThumb className={clsx(stateClasses)} />
</SwitchTrack>
<SwitchInput {...getInputProps()} aria-label="Demo switch" />
</SwitchRoot>
);
}

const blue = {
700: '#0059B2',
};
Expand Down Expand Up @@ -78,26 +101,3 @@ const SwitchTrack = styled('span')(
display: block;
`,
);

function MUISwitch(props: UseSwitchParameters) {
const { getInputProps, checked, disabled, focusVisible } = useSwitch(props);

const stateClasses = {
checked,
disabled,
focusVisible,
};

return (
<SwitchRoot className={clsx(stateClasses)}>
<SwitchTrack>
<SwitchThumb className={clsx(stateClasses)} />
</SwitchTrack>
<SwitchInput {...getInputProps()} aria-label="Demo switch" />
</SwitchRoot>
);
}

export default function UseSwitchesCustom() {
return <MUISwitch defaultChecked />;
}

0 comments on commit f64e0e9

Please sign in to comment.