-
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(dividers): Add hairline divider
- Loading branch information
1 parent
f346cdb
commit 3cff4d3
Showing
7 changed files
with
129 additions
and
2 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
33 changes: 33 additions & 0 deletions
33
src/components/Dividers/HairlineDivider/HairlineDivider.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,33 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import safeRest from '../../../utils/safeRest' | ||
|
||
import joinClassNames from '../../../utils/joinClassNames' | ||
import styles from './HairlineDivider.modules.scss' | ||
|
||
/** | ||
* Separate content. | ||
*/ | ||
const HairlineDivider = ({ vertical, gradient, ...rest }) => { | ||
const classes = joinClassNames( | ||
vertical ? styles.vertical : styles.horizontal, | ||
gradient ? styles.gradient : styles.thin | ||
) | ||
|
||
return ( | ||
<hr {...safeRest(rest)} className={classes} /> | ||
) | ||
} | ||
|
||
HairlineDivider.propTypes = { | ||
vertical: PropTypes.bool, | ||
gradient: PropTypes.bool | ||
} | ||
|
||
HairlineDivider.defaultProps = { | ||
vertical: false, | ||
gradient: false | ||
} | ||
|
||
export default HairlineDivider |
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 @@ | ||
``` | ||
<HairlineDivider /> | ||
``` |
32 changes: 32 additions & 0 deletions
32
src/components/Dividers/HairlineDivider/HairlineDivider.modules.scss
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,32 @@ | ||
@import '../../../scss/settings/colours'; | ||
|
||
.horizontal { | ||
|
||
composes: noSpacing from '../../Spacing/Spacing.modules.scss'; | ||
} | ||
|
||
.vertical { | ||
composes: noSpacing from '../../Spacing/Spacing.modules.scss'; | ||
|
||
width: 1px; | ||
height: 100%; | ||
|
||
border: none; | ||
|
||
border-left: 1px solid; | ||
border-color: $color-gainsboro; | ||
} | ||
|
||
.thin { | ||
border: none; | ||
|
||
border-top: 1px solid; | ||
border-color: $color-gainsboro; | ||
} | ||
|
||
.gradient { | ||
border: none; | ||
height: 1px; | ||
|
||
background-image: linear-gradient(90deg, rgba(216, 216, 216, 0) 0%, $color-gainsboro 2%, $color-gainsboro 98%, rgba(216, 216, 216, 0) 100%); | ||
} |
51 changes: 51 additions & 0 deletions
51
src/components/Dividers/HairlineDivider/__tests__/HairlineDivider.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,51 @@ | ||
import React from 'react' | ||
import { shallow, render } from 'enzyme' | ||
import toJson from 'enzyme-to-json' | ||
|
||
import HairlineDivider from '../HairlineDivider' | ||
|
||
describe('HairlineDivider', () => { | ||
const doShallow = (props = {}) => shallow(<HairlineDivider {...props} />) | ||
|
||
it('renders', () => { | ||
const hairlineDivider = render(<HairlineDivider />) | ||
|
||
expect(toJson(hairlineDivider)).toMatchSnapshot() | ||
}) | ||
|
||
it('is an HTMl hr element', () => { | ||
const hairlineDivider = doShallow() | ||
|
||
expect(hairlineDivider).toHaveTagName('hr') | ||
}) | ||
|
||
it('can be horizontal or vertical', () => { | ||
let hairlineDivider = doShallow() | ||
expect(hairlineDivider).toHaveClassName('horizontal') | ||
|
||
hairlineDivider = doShallow({ vertical: true }) | ||
expect(hairlineDivider).toHaveClassName('vertical') | ||
}) | ||
|
||
it('can have a gradient', () => { | ||
let hairlineDivider = doShallow() | ||
expect(hairlineDivider).toHaveClassName('thin') | ||
|
||
hairlineDivider = doShallow({ gradient: true }) | ||
expect(hairlineDivider).toHaveClassName('gradient') | ||
}) | ||
|
||
it('passes additional attributes to the element', () => { | ||
const hairlineDivider = doShallow({ id: 'the-id', 'data-some-attr': 'some value' }) | ||
|
||
expect(hairlineDivider).toHaveProp('id', 'the-id') | ||
expect(hairlineDivider).toHaveProp('data-some-attr', 'some value') | ||
}) | ||
|
||
it('does not allow custom CSS', () => { | ||
const hairlineDivider = doShallow({ className: 'my-custom-class', style: { color: 'hotpink' } }) | ||
|
||
expect(hairlineDivider).not.toHaveProp('className', 'my-custom-class') | ||
expect(hairlineDivider).not.toHaveProp('style') | ||
}) | ||
}) |
7 changes: 7 additions & 0 deletions
7
...components/Dividers/HairlineDivider/__tests__/__snapshots__/HairlineDivider.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,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`HairlineDivider renders 1`] = ` | ||
<hr | ||
class="horizontal thin" | ||
/> | ||
`; |