-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #282 from Availity/feat/switch-component
feat(mui-form-utils): add switch
- Loading branch information
Showing
7 changed files
with
170 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Each exported component in the package should have its own stories file | ||
|
||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { FormControlLabel, Switch, SwitchProps } from '..'; | ||
|
||
const meta: Meta<typeof Switch> = { | ||
title: 'Components/FormUtils/Switch', | ||
component: Switch, | ||
tags: ['autodocs'], | ||
parameters: { | ||
controls: { | ||
exclude: [ | ||
'action', | ||
'autoFocus', | ||
'className', | ||
'component', | ||
'onChange', | ||
'onFocusVisible', | ||
'readOnly', | ||
'ref', | ||
'required', | ||
'style', | ||
'tabIndex', | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const _Switch: StoryObj<typeof Switch> = { | ||
render: (args: SwitchProps) => <Switch inputProps={{ 'aria-label': 'example' }} {...args} />, | ||
}; | ||
|
||
export const _WithLabel: StoryObj<typeof Switch> = { | ||
render: () => ( | ||
<> | ||
<FormControlLabel control={<Switch />} label="Form Control Label" /> | ||
<FormControlLabel control={<Switch />} label="Form Control Label" labelPlacement='start'/> | ||
</> | ||
), | ||
}; | ||
|
||
export const _Sizes: StoryObj<typeof Switch> = { | ||
render: () => ( | ||
<> | ||
<FormControlLabel control={<Switch />} label="small" /> | ||
<FormControlLabel control={<Switch size="medium"/>} label="medium"/> | ||
</> | ||
), | ||
}; | ||
|
||
export const _States: StoryObj<typeof Switch> = { | ||
render: () => ( | ||
<> | ||
<FormControlLabel control={<Switch />} label="unchecked" /> | ||
<FormControlLabel control={<Switch defaultChecked={true} />} label="checked" /> | ||
<FormControlLabel control={<Switch />} label="disabled unchecked" disabled /> | ||
<FormControlLabel control={<Switch defaultChecked={true} />} label="disabled checked" disabled /> | ||
</> | ||
), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { render } from '@testing-library/react'; | ||
import { Switch } from './Switch'; | ||
|
||
describe('Switch', () => { | ||
test('should render successfully', () => { | ||
const { getByRole } = render(<Switch />); | ||
expect(getByRole('checkbox')).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import MuiSwitch, { SwitchProps as MuiSwitchProps } from '@mui/material/Switch'; | ||
|
||
export type SwitchProps = Omit< | ||
MuiSwitchProps, | ||
| 'centerRipple' | ||
| 'disableFocusRipple' | ||
| 'disableRipple' | ||
| 'disableTouchRipple' | ||
| 'focusRipple' | ||
| 'focusVisibleClassName' | ||
| 'TouchRippleProps' | ||
| 'touchRippleRef' | ||
>; | ||
|
||
export const Switch = (args: SwitchProps): JSX.Element => { | ||
return <MuiSwitch {...args} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters