-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9686c24
commit 13d1a6c
Showing
8 changed files
with
2,755 additions
and
5,239 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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,64 @@ | ||
/* | ||
Many thanks to Cole Bemis | ||
for https://medium.com/@colebemis/building-a-checkbox-component-with-react-and-styled-components-8d3aa1d826dd | ||
*/ | ||
import * as React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
const _CheckboxContainer = styled.div` | ||
display: inline-block; | ||
vertical-align: middle; | ||
`; | ||
|
||
const _Icon = styled.svg` | ||
fill: none; | ||
stroke: white; | ||
stroke-width: 2px; | ||
`; | ||
// Hide checkbox visually but remain accessible to screen readers. | ||
// Source: https://polished.js.org/docs/#hidevisually | ||
const _HiddenCheckbox = styled.input.attrs({ type: 'checkbox' })` | ||
border: 0; | ||
clip: rect(0 0 0 0); | ||
clippath: inset(50%); | ||
height: 1px; | ||
margin: -1px; | ||
overflow: hidden; | ||
padding: 0; | ||
position: absolute; | ||
white-space: nowrap; | ||
width: 1px; | ||
`; | ||
|
||
|
||
const _StyledCheckbox = styled.div` | ||
display: inline-block; | ||
width: 16px; | ||
height: 16px; | ||
background: ${(props: any) => (props.checked ? 'salmon' : 'papayawhip')}; | ||
border-radius: 3px; | ||
transition: all 150ms; | ||
${_HiddenCheckbox}:focus + & { | ||
box-shadow: 0 0 0 3px pink; | ||
} | ||
${_Icon} { | ||
visibility: ${(props: any) => (props.checked ? 'visible' : 'hidden')}; | ||
} | ||
` as any; // because of property CHECKED | ||
|
||
|
||
export default function ({ checked, onChange, ...props }: | ||
{ checked: boolean, onChange: () => void }) { | ||
return ( | ||
<_CheckboxContainer> | ||
<_HiddenCheckbox checked={checked} onChange={onChange} {...props} /> | ||
<_StyledCheckbox checked={checked} > | ||
<_Icon viewBox='0 0 24 24'> | ||
<polyline points='20 6 9 17 4 12' /> | ||
</_Icon> | ||
</_StyledCheckbox> | ||
</_CheckboxContainer> | ||
); | ||
} |
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 @@ | ||
export { default as Checkbox } from './Checkbox'; |
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