-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(checkbox): Initial commit to reset globally scoped CSS styles
- Loading branch information
Showing
7 changed files
with
138 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import safeRest from '../../utils/safeRest' | ||
import generateId from '../../utils/generateId' | ||
|
||
import Text from '../Typography/Text/Text' | ||
|
||
// import styles from './Checkbox.modules.scss' | ||
|
||
const Checkbox = ({ label, ...rest }) => { | ||
const checkboxId = generateId(rest.id, rest.name, label) | ||
|
||
return ( | ||
<label data-no-global-styles htmlFor={checkboxId.identity()}> | ||
<input {...safeRest(rest)} type="checkbox" data-no-global-styles id={checkboxId.identity()} /> | ||
<Text size="medium">{label}</Text> | ||
</label> | ||
) | ||
} | ||
|
||
Checkbox.propTypes = { | ||
label: PropTypes.string.isRequired, | ||
} | ||
|
||
Checkbox.defaultProps = {} | ||
|
||
export default 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
``` | ||
<Checkbox label="Choice A one two three four five six seven eight nine ten eleven twelve" /> | ||
``` |
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,28 @@ | ||
@import '../../scss/settings/variables'; | ||
@import '../../scss/utility/mixins'; | ||
|
||
/* FIXME: resetting globally scoped styles in form.scss | ||
because of input:not(type='radio') | ||
*/ | ||
input[data-no-global-styles] { | ||
border: none; | ||
border-radius: 0; | ||
box-shadow: none; | ||
color: transparent; | ||
font-size: inherit; | ||
line-height: inherit; | ||
outline: inherit; | ||
padding: 0; | ||
width: auto; | ||
transition: none; | ||
font-family: inherit; | ||
|
||
&:focus { | ||
box-shadow: none; | ||
border-color: inherit; | ||
} | ||
|
||
@include from-breakpoint(medium) { | ||
letter-spacing: inherit; | ||
} | ||
} |
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,43 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import Checkbox from '../Checkbox' | ||
|
||
describe('Checkbox', () => { | ||
const defaultProps = { | ||
label: 'The input', | ||
} | ||
const doShallow = (overrides = {}) => shallow(<Checkbox {...defaultProps} {...overrides} />) | ||
const findInputElement = input => input.find('input') | ||
|
||
it('renders', () => { | ||
const checkbox = doShallow() | ||
|
||
expect(checkbox).toMatchSnapshot() | ||
}) | ||
|
||
it('does other things', () => { | ||
const checkbox = doShallow() | ||
|
||
expect(checkbox).toBePresent() | ||
}) | ||
|
||
it('passes additional attributes to the element', () => { | ||
const checkbox = doShallow({ | ||
disabled: 'true', | ||
'data-some-attr': 'some value', | ||
}) | ||
expect(findInputElement(checkbox)).toHaveProp('disabled', 'true') | ||
expect(findInputElement(checkbox)).toHaveProp('data-some-attr', 'some value') | ||
}) | ||
|
||
it('does not allow custom CSS', () => { | ||
const checkbox = doShallow({ | ||
className: 'my-custom-class', | ||
style: { color: 'hotpink' }, | ||
}) | ||
|
||
expect(findInputElement(checkbox)).not.toHaveProp('className', 'my-custom-class') | ||
expect(findInputElement(checkbox)).not.toHaveProp('style') | ||
}) | ||
}) |
22 changes: 22 additions & 0 deletions
22
src/components/Checkbox/__tests__/__snapshots__/Checkbox.spec.jsx.snap
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,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Checkbox renders 1`] = ` | ||
<label | ||
data-no-global-styles={true} | ||
htmlFor="the-input" | ||
> | ||
<input | ||
data-no-global-styles={true} | ||
id="the-input" | ||
type="checkbox" | ||
/> | ||
<Text | ||
block={false} | ||
bold={false} | ||
invert={false} | ||
size="medium" | ||
> | ||
The input | ||
</Text> | ||
</label> | ||
`; |
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