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

[Switch] Implement the component-per-node API #135

Merged
merged 32 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1c24889
Component-per-node API
michaldudak Feb 29, 2024
ca2d62a
Fix TS errors
michaldudak Feb 29, 2024
251b384
Abstract the style hooks generation
michaldudak Feb 29, 2024
cb57671
Update the System intro demo
michaldudak Feb 29, 2024
8976d8a
Update the CSS intro demo
michaldudak Feb 29, 2024
5cb76ee
Update the Tailwind intro demo
michaldudak Feb 29, 2024
4ac24bd
Proptypes, API docs
michaldudak Feb 29, 2024
ffd137b
Docs
michaldudak Feb 29, 2024
79e7a4a
Tests
michaldudak Feb 29, 2024
9958224
Tests and fixes
michaldudak Mar 1, 2024
54805b5
Do not render hidden input if name isn't provided
michaldudak Mar 1, 2024
bd8d651
Update the landing page theme preview
michaldudak Mar 1, 2024
27f0b7e
Rewrite the Switch on Badge demos
michaldudak Mar 1, 2024
ea04785
Clear the customization page
michaldudak Mar 1, 2024
6ab2ae4
Prettier
michaldudak Mar 1, 2024
f29123c
Update the customization demo on the landing page
michaldudak Mar 1, 2024
656d1c2
Remove failing useButton test
michaldudak Mar 1, 2024
99a2090
proptypes
michaldudak Mar 1, 2024
1520866
Extract style hooks to a separate file
michaldudak Mar 13, 2024
ede63ad
Use the visuallyHidden utility
michaldudak Mar 13, 2024
1a99d14
Cleaning up
michaldudak Mar 13, 2024
0677034
Update Switch styles in Badge demo
michaldudak Mar 13, 2024
8fc2017
API docs
michaldudak Mar 13, 2024
eeb9d3c
Update the tests
michaldudak Mar 15, 2024
5a29a5a
JSDoc
michaldudak Mar 18, 2024
47dbeb8
James' review
michaldudak Mar 19, 2024
3e3b15c
Memoize event handler creators
michaldudak Mar 19, 2024
83b67c0
Update the API docs
michaldudak Mar 20, 2024
277bff8
Rename slot to element
michaldudak Mar 21, 2024
165ab0e
Inline event handlers
michaldudak Mar 21, 2024
9ffee33
Reorganize tests
michaldudak Mar 21, 2024
07798cd
API docs
michaldudak Mar 21, 2024
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
102 changes: 53 additions & 49 deletions docs/data/base/components/badge/BadgeVisibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Badge as BaseBadge, badgeClasses } from '@mui/base/Badge';
// Auxiliary demo components
import { styled, Stack } from '@mui/system';
import { Button, buttonClasses } from '@mui/base/Button';
import { Switch, switchClasses } from '@mui/base/Switch';
import { Switch as BaseSwitch } from '@mui/base/Switch';
import Divider from '@mui/material/Divider';
// Icons
import AddIcon from '@mui/icons-material/Add';
Expand All @@ -13,6 +13,7 @@ import MailIcon from '@mui/icons-material/Mail';
const blue = {
200: '#99CCF3',
500: '#007FFF',
700: '#0059B2',
};

const grey = {
Expand Down Expand Up @@ -95,66 +96,73 @@ const StyledButton = styled(Button)(
`,
);

const Root = styled('span')(
const Switch = styled(BaseSwitch)(
({ theme }) => `
position: relative;
display: inline-block;
width: 32px;
height: 20px;
cursor: pointer;
padding: 0;
box-sizing: border-box;
background: ${theme.palette.mode === 'dark' ? grey[600] : grey[400]};
border-radius: 16px;
border: none;
display: inline-flex;
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
box-shadow: inset 0px 1px 1px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(0, 0, 0, 0.05)'
};

&[data-disabled] {
opacity: 0.4;
cursor: not-allowed;
}

& .${switchClasses.track} {
background: ${theme.palette.mode === 'dark' ? grey[600] : grey[400]};
border-radius: 16px;
display: block;
height: 100%;
width: 100%;
position: absolute;
&:hover:not([data-disabled]) {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
}

& .${switchClasses.thumb} {
position: relative;
&:focus-visible {
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}

&[data-state="checked"] {
border: none;
background: ${blue[500]};
}

&[data-state="checked"]:not([data-disabled]):hover {
background: ${blue[700]};
}
`,
);

const Thumb = styled(BaseSwitch.Thumb)(
({ theme }) => `
box-sizing: border-box;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
display: block;
width: 14px;
height: 14px;
top: 3px;
left: 3px;
top: 3px;
border-radius: 16px;
background-color: #fff;
background-color: #FFF;
position: relative;
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
}

&.${switchClasses.focusVisible} .${switchClasses.track} {
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? grey[700] : blue[200]};
}
box-shadow: 0px 1px 2px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.25)' : 'rgba(0, 0, 0, 0.1)'
};

&.${switchClasses.checked} {
.${switchClasses.thumb} {
&[data-state="checked"] {
left: 15px;
top: 3px;
background-color: #fff;
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3);
}

.${switchClasses.track} {
background: ${blue[500]};
}
}

& .${switchClasses.input} {
cursor: inherit;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0;
z-index: 1;
margin: 0;
}
`,
`,
);

const StyledLabel = styled('label')(
Expand Down Expand Up @@ -205,13 +213,9 @@ export default function BadgeVisibility() {
<Divider orientation="vertical" />
<Stack direction="row" spacing={1} useFlexGap>
<StyledLabel>Show badge</StyledLabel>
<Switch
slots={{
root: Root,
}}
checked={!invisible}
onChange={handleBadgeVisibility}
/>
<Switch checked={!invisible} onChange={handleBadgeVisibility}>
<Thumb />
</Switch>
</Stack>
</Stack>
</Stack>
Expand Down
102 changes: 53 additions & 49 deletions docs/data/base/components/badge/BadgeVisibility.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Badge as BaseBadge, badgeClasses } from '@mui/base/Badge';
// Auxiliary demo components
import { styled, Stack } from '@mui/system';
import { Button, buttonClasses } from '@mui/base/Button';
import { Switch, switchClasses } from '@mui/base/Switch';
import { Switch as BaseSwitch } from '@mui/base/Switch';
import Divider from '@mui/material/Divider';
// Icons
import AddIcon from '@mui/icons-material/Add';
Expand All @@ -13,6 +13,7 @@ import MailIcon from '@mui/icons-material/Mail';
const blue = {
200: '#99CCF3',
500: '#007FFF',
700: '#0059B2',
};

const grey = {
Expand Down Expand Up @@ -95,66 +96,73 @@ const StyledButton = styled(Button)(
`,
);

const Root = styled('span')(
const Switch = styled(BaseSwitch)(
({ theme }) => `
position: relative;
display: inline-block;
width: 32px;
height: 20px;
cursor: pointer;
padding: 0;
box-sizing: border-box;
background: ${theme.palette.mode === 'dark' ? grey[600] : grey[400]};
border-radius: 16px;
border: none;
display: inline-flex;
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
box-shadow: inset 0px 1px 1px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(0, 0, 0, 0.05)'
};

&[data-disabled] {
opacity: 0.4;
cursor: not-allowed;
}

& .${switchClasses.track} {
background: ${theme.palette.mode === 'dark' ? grey[600] : grey[400]};
border-radius: 16px;
display: block;
height: 100%;
width: 100%;
position: absolute;
&:hover:not([data-disabled]) {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
}

& .${switchClasses.thumb} {
position: relative;
&:focus-visible {
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}

&[data-state="checked"] {
border: none;
background: ${blue[500]};
}

&[data-state="checked"]:not([data-disabled]):hover {
background: ${blue[700]};
}
`,
);

const Thumb = styled(BaseSwitch.Thumb)(
({ theme }) => `
box-sizing: border-box;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
display: block;
width: 14px;
height: 14px;
top: 3px;
left: 3px;
top: 3px;
border-radius: 16px;
background-color: #fff;
background-color: #FFF;
position: relative;
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
}

&.${switchClasses.focusVisible} .${switchClasses.track} {
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? grey[700] : blue[200]};
}
box-shadow: 0px 1px 2px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.25)' : 'rgba(0, 0, 0, 0.1)'
};

&.${switchClasses.checked} {
.${switchClasses.thumb} {
&[data-state="checked"] {
left: 15px;
top: 3px;
background-color: #fff;
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3);
}

.${switchClasses.track} {
background: ${blue[500]};
}
}

& .${switchClasses.input} {
cursor: inherit;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0;
z-index: 1;
margin: 0;
}
`,
`,
);

const StyledLabel = styled('label')(
Expand Down Expand Up @@ -205,13 +213,9 @@ export default function BadgeVisibility() {
<Divider orientation="vertical" />
<Stack direction="row" spacing={1} useFlexGap>
<StyledLabel>Show badge</StyledLabel>
<Switch
slots={{
root: Root,
}}
checked={!invisible}
onChange={handleBadgeVisibility}
/>
<Switch checked={!invisible} onChange={handleBadgeVisibility}>
<Thumb />
</Switch>
</Stack>
</Stack>
</Stack>
Expand Down
Loading
Loading