-
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(input): Adjust spacing of label, helper, and field to follow spa…
…cing system. Also add an initial Flexbox component and WithSpacing component to help describe layout and spacing.
- Loading branch information
1 parent
b9bd3f8
commit fabe775
Showing
17 changed files
with
236 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import safeRest from '../../safeRest' | ||
|
||
import styles from './Flexbox.modules.scss' | ||
|
||
const Flexbox = ({ direction, children, ...rest }) => ( | ||
<div {...safeRest(rest)} className={styles[direction]}> | ||
{children} | ||
</div> | ||
) | ||
|
||
Flexbox.propTypes = { | ||
direction: PropTypes.oneOf(['column', 'row']).isRequired, | ||
children: PropTypes.node.isRequired | ||
} | ||
|
||
export default Flexbox |
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 @@ | ||
.column { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.row { | ||
display: flex; | ||
flex-direction: row; | ||
} |
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,46 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import toJson from 'enzyme-to-json' | ||
|
||
import Flexbox from '../Flexbox' | ||
|
||
describe('Flexbox', () => { | ||
const defaultProps = { | ||
direction: 'row' | ||
} | ||
const doShallow = (props = {}) => ( | ||
shallow(<Flexbox {...defaultProps} {...props}>Some content</Flexbox>) | ||
) | ||
|
||
it('renders', () => { | ||
const flexbox = doShallow() | ||
|
||
expect(toJson(flexbox)).toMatchSnapshot() | ||
}) | ||
|
||
it('can be a flex column', () => { | ||
const flexbox = doShallow({ direction: 'column' }) | ||
|
||
expect(flexbox).toHaveClassName('column') | ||
}) | ||
|
||
it('can be a flex row', () => { | ||
const flexbox = doShallow({ direction: 'row' }) | ||
|
||
expect(flexbox).toHaveClassName('row') | ||
}) | ||
|
||
it('passes additional attributes to the HTML element', () => { | ||
const flexbox = doShallow({ id: 'the-id', 'data-some-property': 'a value' }) | ||
|
||
expect(flexbox).toHaveProp('id', 'the-id') | ||
expect(flexbox).toHaveProp('data-some-property', 'a value') | ||
}) | ||
|
||
it('does not allow custom CSS', () => { | ||
const flexbox = doShallow({ className: 'my-custom-class', style: { color: 'hotpink' } }) | ||
|
||
expect(flexbox).not.toHaveProp('className', 'my-custom-class') | ||
expect(flexbox).not.toHaveProp('style') | ||
}) | ||
}) |
9 changes: 9 additions & 0 deletions
9
src/components/Flexbox/__tests__/__snapshots__/Flexbox.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,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Flexbox renders 1`] = ` | ||
<div | ||
className="row" | ||
> | ||
Some content | ||
</div> | ||
`; |
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 was deleted.
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
File renamed without changes.
8 changes: 5 additions & 3 deletions
8
...ponents/Input/WithSpacing/WithSpacing.jsx → ...nents/Spacing/WithSpacing/WithSpacing.jsx
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,9 @@ | ||
@import '../../../scss/settings/spacing'; | ||
|
||
.marginBottom-2 { | ||
margin-bottom: $spacing-tight; | ||
} | ||
|
||
.marginBottom-3 { | ||
margin-bottom: $spacing-base; | ||
} |
40 changes: 40 additions & 0 deletions
40
src/components/Spacing/WithSpacing/__tests__/WithSpacing.spec.jsx
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,40 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import toJson from 'enzyme-to-json' | ||
|
||
import WithSpacing from '../WithSpacing' | ||
|
||
describe('WithSpacing', () => { | ||
const defaultProps = { | ||
amount: 2 | ||
} | ||
const doShallow = (props = {}) => ( | ||
shallow(<WithSpacing {...defaultProps} {...props}>Some content</WithSpacing>) | ||
) | ||
|
||
it('renders', () => { | ||
const flexbox = doShallow() | ||
|
||
expect(toJson(flexbox)).toMatchSnapshot() | ||
}) | ||
|
||
it('applies margin bottom', () => { | ||
const flexbox = doShallow({ amount: 3 }) | ||
|
||
expect(flexbox).toHaveClassName('marginBottom-3') | ||
}) | ||
|
||
it('passes additional attributes to the HTML element', () => { | ||
const flexbox = doShallow({ id: 'the-id', 'data-some-property': 'a value' }) | ||
|
||
expect(flexbox).toHaveProp('id', 'the-id') | ||
expect(flexbox).toHaveProp('data-some-property', 'a value') | ||
}) | ||
|
||
it('does not allow custom CSS', () => { | ||
const flexbox = doShallow({ className: 'my-custom-class', style: { color: 'hotpink' } }) | ||
|
||
expect(flexbox).not.toHaveProp('className', 'my-custom-class') | ||
expect(flexbox).not.toHaveProp('style') | ||
}) | ||
}) |
9 changes: 9 additions & 0 deletions
9
src/components/Spacing/WithSpacing/__tests__/__snapshots__/WithSpacing.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,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`WithSpacing renders 1`] = ` | ||
<div | ||
className="marginBottom-2" | ||
> | ||
Some content | ||
</div> | ||
`; |
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
Oops, something went wrong.