Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit dfd26e5

Browse files
authored
feat(Checkbox): add component (#1405)
* feat(Checkbox): add component * add checkmark icon * add behaviour import * rename files * revert change in example * remove custom icon, use `accept` * add changelog entry * and conformance test and `onChange` handler * add onFocus handler * update variables
1 parent 882f293 commit dfd26e5

File tree

27 files changed

+521
-1
lines changed

27 files changed

+521
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
4141
- Add 'lightning' icon to Teams theme @notandrew ([#1385](https://github.com/stardust-ui/react/pull/1385))
4242
- Add automatic positioning inside viewport for `Menu` with submenus @Bugaa92 ([#1384](https://github.com/stardust-ui/react/pull/1384))
4343
- Add `align`, `position`, `offset` props for `Dropdown` component @Bugaa92 ([#1312](https://github.com/stardust-ui/react/pull/1312))
44+
- Add `Checkbox` component and `toggle` prop for it @layershifter ([#1405](https://github.com/stardust-ui/react/pull/1405))
4445

4546
### Documentation
4647
- Accessibility: improve introduction section @jurokapsiar ([#1368](https://github.com/stardust-ui/react/pull/1368))

docs/src/components/ExampleSnippet/renderElementToJSX.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const renderElementToJSX = (element: React.ReactNode, triggerErrorOnRenderFn: bo
1414
(typeof element.type === 'function' ? 'NoDisplayName' : element.type),
1515
showDefaultProps: false,
1616
showFunctions: true,
17-
filterProps: ['accessibility'],
17+
filterProps: ['accessibility', 'onClick', 'onChange'],
1818
functionValue: () => (renderHasFunction = true),
1919
})
2020

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { useBooleanKnob, useStringKnob } from '@stardust-ui/docs-components'
2+
import { Checkbox } from '@stardust-ui/react'
3+
import * as React from 'react'
4+
5+
const CheckboxPlayground: React.FunctionComponent = () => {
6+
const [checked, setChecked] = useBooleanKnob({ name: 'checked' })
7+
const [disabled] = useBooleanKnob({ name: 'disabled' })
8+
const [toggle] = useBooleanKnob({ name: 'toggle' })
9+
10+
const [label] = useStringKnob({
11+
name: 'label',
12+
initialValue: 'Make profile visible',
13+
})
14+
15+
return (
16+
<Checkbox
17+
checked={checked}
18+
disabled={disabled}
19+
label={label}
20+
toggle={toggle}
21+
onChange={(e, data) => setChecked(data.checked)}
22+
/>
23+
)
24+
}
25+
26+
export default CheckboxPlayground
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Checkbox } from '@stardust-ui/react'
2+
3+
export const config: ScreenerTestsConfig = {
4+
themes: ['base', 'teams'],
5+
steps: [builder => builder.click(`.${Checkbox.className}`).snapshot('Can be checked')],
6+
}
7+
8+
export default config
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Checkbox } from '@stardust-ui/react'
2+
import * as React from 'react'
3+
4+
const CheckboxExample = () => <Checkbox label="Make my profile visible" />
5+
6+
export default CheckboxExample
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Checkbox } from '@stardust-ui/react'
2+
import * as React from 'react'
3+
4+
const CheckboxExampleDisabled = () => (
5+
<>
6+
<Checkbox disabled label="Disabled" />
7+
<Checkbox disabled checked label="Disabled & Checked" />
8+
</>
9+
)
10+
11+
export default CheckboxExampleDisabled
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Checkbox } from '@stardust-ui/react'
2+
3+
export const config: ScreenerTestsConfig = {
4+
themes: ['base', 'teams'],
5+
steps: [builder => builder.click(`.${Checkbox.className}`).snapshot('Can be checked')],
6+
}
7+
8+
export default config
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Checkbox } from '@stardust-ui/react'
2+
import * as React from 'react'
3+
4+
const CheckboxExampleToggle = () => (
5+
<>
6+
<Checkbox label="Subscribe to weekly newsletter" toggle />
7+
<Checkbox disabled checked label="Subscribe to weekly newsletter" toggle />
8+
</>
9+
)
10+
11+
export default CheckboxExampleToggle
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as React from 'react'
2+
3+
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample'
4+
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'
5+
6+
const Types = () => (
7+
<ExampleSection title="Types">
8+
<ComponentExample
9+
title="Checkbox"
10+
description="A standard checkbox."
11+
examplePath="components/Checkbox/Types/CheckboxExample"
12+
/>
13+
<ComponentExample
14+
title="Disabled"
15+
description="A checkbox can be read-only and unable to change states."
16+
examplePath="components/Checkbox/Types/CheckboxExampleDisabled"
17+
/>
18+
<ComponentExample
19+
title="Toggle"
20+
description="A checkbox can be formatted to show an on or off choice."
21+
examplePath="components/Checkbox/Types/CheckboxExampleToggle"
22+
/>
23+
</ExampleSection>
24+
)
25+
26+
export default Types
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react'
2+
import Types from './Types'
3+
4+
const CheckboxExamples = () => (
5+
<>
6+
<Types />
7+
</>
8+
)
9+
10+
export default CheckboxExamples

0 commit comments

Comments
 (0)