-
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.
Showing
11 changed files
with
399 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,87 @@ | ||
import React, { useState, ChangeEventHandler } from 'react' | ||
import { Story, Meta } from '@storybook/react' | ||
import { action } from '@storybook/addon-actions' | ||
import { Checkbox } from '.' | ||
import { Variants } from '../../docs/util' | ||
import { Flex } from '../' | ||
|
||
export default { | ||
title: 'Components/Checkbox', | ||
component: Checkbox, | ||
} as Meta | ||
const click = action('clicked') | ||
|
||
export const Default = () => <Checkbox onCheckedChange={action('checked')} /> | ||
|
||
/** | ||
* A primary version for if the check is the main action. | ||
* (This probably doesn't happen very often.) | ||
* | ||
* Example with state - __Note__ the use of `onCheckedChange` to get the change notification from all triggering actions. | ||
*/ | ||
export const Primary = () => { | ||
const [checked, setChecked] = useState(false) | ||
return ( | ||
<Checkbox | ||
css={{ m: '$3' }} | ||
checked={checked} | ||
variant="primary" | ||
onCheckedChange={(event) => { | ||
click(event) | ||
setChecked(!checked) | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
export const Destructive = () => { | ||
return ( | ||
<Flex> | ||
<Checkbox css={{ m: '$3' }} variant="primary" destructive /> | ||
<Checkbox css={{ m: '$3' }} destructive /> | ||
</Flex> | ||
) | ||
} | ||
|
||
/** | ||
* Checkbox also support a `indeterminate` checked state. | ||
* This can only be used in a controlled behaviour. | ||
*/ | ||
export const Indeterminate = () => { | ||
const [checked, setChecked] = useState<boolean | 'indeterminate'>( | ||
'indeterminate' | ||
) | ||
|
||
const rotate: ChangeEventHandler<HTMLInputElement> = (e) => { | ||
click(e) | ||
if (checked === 'indeterminate') { | ||
setChecked(true) | ||
} else if (checked) { | ||
setChecked(false) | ||
} else { | ||
setChecked('indeterminate') | ||
} | ||
} | ||
return ( | ||
<Flex> | ||
<Checkbox | ||
css={{ m: '$3' }} | ||
checked={checked} | ||
variant="primary" | ||
onCheckedChange={rotate} | ||
/> | ||
<Checkbox css={{ m: '$3' }} checked={checked} onCheckedChange={rotate} /> | ||
</Flex> | ||
) | ||
} | ||
|
||
export const All = () => ( | ||
<Variants | ||
component={Checkbox} | ||
css={{ m: '$3' }} | ||
variant={['primary', 'secondary']} | ||
destructive={[false, true]} | ||
disabled={[false, true]} | ||
checked={[false, true, 'indeterminate']} | ||
/> | ||
) |
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,13 @@ | ||
import React from 'react' | ||
import { renderLight, renderDark } from 'test-utils' | ||
import { Default } from './Checkbox.stories' | ||
|
||
it('renders light without error', () => { | ||
const { asFragment } = renderLight(<Default />) | ||
expect(asFragment()).toBeDefined() | ||
}) | ||
|
||
it('renders dark without error', () => { | ||
const { asFragment } = renderDark(<Default />) | ||
expect(asFragment()).toBeDefined() | ||
}) |
Oops, something went wrong.