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] Create SwitchUnstyled and useSwitch #26688

Merged
merged 69 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
30852a2
Add initial implementation of useSwitch and SwitchUnstyled
michaldudak Jun 7, 2021
9b9c56e
Use checkbox to handle switch state
michaldudak Jun 7, 2021
fe11962
Add `ButtonUnstyled` and use it in `SwitchUnstyled`
michaldudak Jun 9, 2021
62dc051
Working on the API
michaldudak Jun 9, 2021
512757e
Prettier
michaldudak Jun 9, 2021
903b934
Add type checks for components and componentsProps
michaldudak Jun 10, 2021
b5e8d04
Fix forwardRef type definition
michaldudak Jun 11, 2021
69a2519
Include tsx files in unstyled tsconfig
michaldudak Jun 11, 2021
7ed4a3e
Lint, prettier
michaldudak Jun 11, 2021
6b18590
PropTypes
michaldudak Jun 11, 2021
cbf19d8
Implement the `Switch` using `useSwitch`
michaldudak Jun 11, 2021
9ca3348
Handle ripple effect
michaldudak Jun 15, 2021
6129be7
Fix failing test
michaldudak Jun 15, 2021
f97f16a
Fix forwardRef return type
michaldudak Jun 16, 2021
19f8774
Remove ButtonUnstyled
michaldudak Jun 16, 2021
3523f7a
- add UseSwitches ts demo
mnajdova Jun 17, 2021
2ce1829
Merge branch 'next' into feat/unstyled-switch
mnajdova Jun 17, 2021
234cebf
reverted SwitchUnstyled changes
mnajdova Jun 17, 2021
0d5cb08
Update demos to use CSS as strings
michaldudak Jun 17, 2021
324a2bc
Add JSDoc for SwitchUnstyled
michaldudak Jun 17, 2021
184d283
Remove type annotations from SwitchUnstyled slots
michaldudak Jun 17, 2021
03584de
Fix regression tests
michaldudak Jun 17, 2021
6bdebbb
Fixing test_static
michaldudak Jun 18, 2021
46d1fe9
Fix warnings in demos
michaldudak Jun 18, 2021
d4f2c5c
Restore icon and checkedIcon support
michaldudak Jun 18, 2021
fdd51c2
Add `component` prop
michaldudak Jun 18, 2021
c396d2a
Update babel-plugin-optimize-clsx
michaldudak Jun 18, 2021
0016828
Docs, demos and more consistent API
michaldudak Jun 18, 2021
0d91268
Format demo
michaldudak Jun 18, 2021
e475d78
Update docs/src/pages/components/switches/switches.md
michaldudak Jun 21, 2021
19790ff
Improve code style
michaldudak Jun 21, 2021
d2a3f28
Restore the Switch
michaldudak Jun 21, 2021
44ee5ce
Merge branch 'next' into feat/unstyled-switch
michaldudak Jun 21, 2021
4dbb907
Fix the build
michaldudak Jun 21, 2021
6070249
Recreate MUI Core Switches using unstyled in demos
michaldudak Jun 22, 2021
1cbb1ee
Revert older Switch demos change
michaldudak Jun 22, 2021
af736d7
Merge branch 'next' into feat/unstyled-switch
michaldudak Jun 22, 2021
daddaab
Fix incorrect and redundant class names
michaldudak Jun 22, 2021
fdad70c
Rename SwitchUnstyled in useControlled
michaldudak Jun 22, 2021
1c80c58
Test SwitchUnstyled
michaldudak Jun 22, 2021
a433b13
Merge branch 'next' into feat/unstyled-switch
michaldudak Jun 23, 2021
6f16b8e
More tests and fixes
michaldudak Jun 23, 2021
837b650
Add DescribeConformanceUnstyled tests
michaldudak Jun 23, 2021
7eee9c2
Merge remote-tracking branch 'upstream/next' into feat/unstyled-switch
michaldudak Jun 24, 2021
62f8f44
Use DescribeConformanceUnstyled to build API docs
michaldudak Jun 24, 2021
a2f7fd2
Update demos and docs
michaldudak Jun 25, 2021
e4ab6db
Merge branch 'next' into feat/unstyled-switch
michaldudak Jun 25, 2021
ee37264
Update demos and add docs
michaldudak Jun 25, 2021
87eb0f9
Apply suggestions from code review
michaldudak Jun 27, 2021
b87d7e8
Simplify demos
michaldudak Jun 28, 2021
6168641
Fix MUI Switch recreation demo
michaldudak Jun 28, 2021
c40aa81
Merge branch 'next' into feat/unstyled-switch
michaldudak Jun 28, 2021
29e8b54
Merge branch 'next' into feat/unstyled-switch
michaldudak Jun 29, 2021
fd88570
Remove unnecessary CSS class
michaldudak Jun 29, 2021
305df4a
Polish the demos
michaldudak Jun 29, 2021
b98cafb
Code style
michaldudak Jun 29, 2021
abb7ca8
Merge branch 'next' into feat/unstyled-switch
michaldudak Jul 1, 2021
3ad767a
Apply suggestions from code review
michaldudak Jul 2, 2021
00fedfa
Apply suggestions from CR
michaldudak Jul 2, 2021
6ba8485
Merge branch 'next' into feat/unstyled-switch
michaldudak Jul 2, 2021
43451ad
Make the demos consistent
michaldudak Jul 2, 2021
692013b
Add JSDoc to useSwitch
michaldudak Jul 2, 2021
c2cb70c
Merge className applied on host with the one from componentsProps
michaldudak Jul 2, 2021
98b0582
remove blank space convention
oliviertassinari Jul 5, 2021
37309ca
leading dot
oliviertassinari Jul 5, 2021
eb31636
sort props asc
oliviertassinari Jul 5, 2021
05bd709
Forward all host props to the root component
michaldudak Jul 7, 2021
2fe768d
Merge branch 'next' into feat/unstyled-switch
michaldudak Jul 7, 2021
530e91e
Use less components in UnstyledSwitchesMaterial
michaldudak Jul 7, 2021
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
23 changes: 23 additions & 0 deletions docs/pages/api-docs/switch-unstyled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react';
import ApiPage from 'docs/src/modules/components/ApiPage';
import mapApiPageTranslations from 'docs/src/modules/utils/mapApiPageTranslations';
import jsonPageContent from './switch-unstyled.json';

export default function Page(props) {
const { descriptions, pageContent } = props;
return <ApiPage descriptions={descriptions} pageContent={pageContent} />;
}

Page.getInitialProps = () => {
const req = require.context(
'docs/translations/api-docs/switch-unstyled',
false,
/switch-unstyled.*.json$/,
);
const descriptions = mapApiPageTranslations(req);

return {
descriptions,
pageContent: jsonPageContent,
};
};
29 changes: 29 additions & 0 deletions docs/pages/api-docs/switch-unstyled.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"props": {
"checked": { "type": { "name": "bool" } },
"className": { "type": { "name": "string" } },
"component": { "type": { "name": "elementType" } },
"components": {
"type": {
"name": "shape",
"description": "{ Input?: elementType, Root?: elementType, Thumb?: elementType }"
},
"default": "{}"
},
"componentsProps": { "type": { "name": "object" }, "default": "{}" },
"defaultChecked": { "type": { "name": "bool" } },
"disabled": { "type": { "name": "bool" } },
"onChange": { "type": { "name": "func" } },
"readOnly": { "type": { "name": "bool" } },
"required": { "type": { "name": "bool" } }
},
"name": "SwitchUnstyled",
"styles": { "classes": [], "globalClasses": {}, "name": null },
"spread": true,
"forwardsRefTo": "HTMLSpanElement",
"filename": "/packages/material-ui-unstyled/src/SwitchUnstyled/SwitchUnstyled.tsx",
"inheritance": null,
"demos": "<ul><li><a href=\"/components/switches/\">Switches</a></li></ul>",
"styledComponent": true,
"cssComponent": false
}
5 changes: 1 addition & 4 deletions docs/src/modules/utils/parseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ function findConformanceDescriptor(file: babel.ParseResult): babel.types.ObjectE
CallExpression(babelPath) {
const { node: callExpression } = babelPath;
const { callee } = callExpression;
if (
t.isIdentifier(callee) &&
(callee.name === 'describeConformance' || callee.name === 'describeConformanceV5')
) {
if (t.isIdentifier(callee) && callee.name.startsWith('describeConformance')) {
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
const [, optionsFactory] = callExpression.arguments;
if (
t.isArrowFunctionExpression(optionsFactory) &&
Expand Down
73 changes: 73 additions & 0 deletions docs/src/pages/components/switches/UnstyledSwitches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import * as React from 'react';
import { styled } from '@material-ui/system';
import SwitchUnstyled, {
switchUnstyledClasses,
} from '@material-ui/unstyled/SwitchUnstyled';

const Root = styled('span')(`
font-size: 0;
position: relative;
display: inline-block;
width: 32px;
height: 20px;
background: #B3C3D3;
border-radius: 10px;
margin: 10px;
cursor: pointer;

&.${switchUnstyledClasses.disabled} {
opacity: 0.4;
cursor: not-allowed;
}

&.${switchUnstyledClasses.checked} {
background: #007FFF;
}

& .${switchUnstyledClasses.thumb} {
display: block;
width: 14px;
height: 14px;
top: 3px;
left: 3px;
border-radius: 16px;
background-color: #FFF;
position: relative;
transition: all 200ms ease;
}

&.${switchUnstyledClasses.focusVisible} .${switchUnstyledClasses.thumb} {
background-color: rgba(255,255,255,1);
box-shadow: 0 0 1px 8px rgba(0,0,0,0.25);
}

&.${switchUnstyledClasses.checked} .${switchUnstyledClasses.thumb} {
left: 14px;
top: 3px;
background-color: #FFF;
}

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

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

return (
<div>
<SwitchUnstyled component={Root} {...label} defaultChecked />
<SwitchUnstyled component={Root} {...label} />
<SwitchUnstyled component={Root} {...label} defaultChecked disabled />
<SwitchUnstyled component={Root} {...label} disabled />
</div>
);
}
73 changes: 73 additions & 0 deletions docs/src/pages/components/switches/UnstyledSwitches.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import * as React from 'react';
import { styled } from '@material-ui/system';
import SwitchUnstyled, {
switchUnstyledClasses,
} from '@material-ui/unstyled/SwitchUnstyled';

const Root = styled('span')(`
font-size: 0;
position: relative;
display: inline-block;
width: 32px;
height: 20px;
background: #B3C3D3;
border-radius: 10px;
margin: 10px;
cursor: pointer;

&.${switchUnstyledClasses.disabled} {
opacity: 0.4;
cursor: not-allowed;
}

&.${switchUnstyledClasses.checked} {
background: #007FFF;
}

& .${switchUnstyledClasses.thumb} {
display: block;
width: 14px;
height: 14px;
top: 3px;
left: 3px;
border-radius: 16px;
background-color: #FFF;
position: relative;
transition: all 200ms ease;
}

&.${switchUnstyledClasses.focusVisible} .${switchUnstyledClasses.thumb} {
background-color: rgba(255,255,255,1);
box-shadow: 0 0 1px 8px rgba(0,0,0,0.25);
}

&.${switchUnstyledClasses.checked} .${switchUnstyledClasses.thumb} {
left: 14px;
top: 3px;
background-color: #FFF;
}

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

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

return (
<div>
<SwitchUnstyled component={Root} {...label} defaultChecked />
<SwitchUnstyled component={Root} {...label} />
<SwitchUnstyled component={Root} {...label} defaultChecked disabled />
<SwitchUnstyled component={Root} {...label} disabled />
</div>
);
}
Loading