-
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(display-heading): add sup/sub components
- Loading branch information
Showing
11 changed files
with
174 additions
and
0 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
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
18 changes: 18 additions & 0 deletions
18
src/components/Typography/DisplayHeading/DisplayHeadingSub/DisplayHeadingSub.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,18 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import safeRest from '../../../../safeRest' | ||
|
||
import styles from '../DisplayHeading.modules.scss' | ||
|
||
/** | ||
* Subscript text for headings. | ||
*/ | ||
const DisplayHeadingSub = ({ children, ...rest }) => ( | ||
<sub {...safeRest(rest)} className={styles.sub}>{children}</sub> | ||
) | ||
|
||
DisplayHeadingSub.propTypes = { | ||
children: PropTypes.string.isRequired | ||
} | ||
|
||
export default DisplayHeadingSub |
5 changes: 5 additions & 0 deletions
5
src/components/Typography/DisplayHeading/DisplayHeadingSub/DisplayHeadingSub.md
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,5 @@ | ||
``` | ||
<div> | ||
<DisplayHeading>Great Deals<DisplayHeading.Sub>1</DisplayHeading.Sub></DisplayHeading> | ||
</div> | ||
``` |
36 changes: 36 additions & 0 deletions
36
...mponents/Typography/DisplayHeading/DisplayHeadingSub/__tests__/DisplayHeadingSub.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,36 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import toJson from 'enzyme-to-json' | ||
|
||
import DisplayHeadingSub from '../DisplayHeadingSub' | ||
|
||
describe('DisplayHeadingSub', () => { | ||
const doShallow = props => ( | ||
shallow(<DisplayHeadingSub {...props}>Some content</DisplayHeadingSub>) | ||
) | ||
|
||
it('renders', () => { | ||
const displayHeadingSub = doShallow() | ||
|
||
expect(toJson(displayHeadingSub)).toMatchSnapshot() | ||
}) | ||
|
||
it('renders an HTML sub tag', () => { | ||
const displayHeadingSub = doShallow() | ||
|
||
expect(displayHeadingSub).toHaveTagName('sub') | ||
}) | ||
|
||
it('passes additional attributes to the sup element', () => { | ||
const displayHeadingSub = doShallow({ id: 'the-sub-text' }) | ||
|
||
expect(displayHeadingSub).toHaveProp('id', 'the-sub-text') | ||
}) | ||
|
||
it('does not allow custom CSS', () => { | ||
const displayHeadingSub = doShallow({ className: 'my-custom-class', style: { color: 'hotpink' } }) | ||
|
||
expect(displayHeadingSub).not.toHaveProp('className', 'my-custom-class') | ||
expect(displayHeadingSub).not.toHaveProp('style') | ||
}) | ||
}) |
9 changes: 9 additions & 0 deletions
9
.../DisplayHeading/DisplayHeadingSub/__tests__/__snapshots__/DisplayHeadingSub.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[`DisplayHeadingSub renders 1`] = ` | ||
<sub | ||
className="sub" | ||
> | ||
Some content | ||
</sub> | ||
`; |
18 changes: 18 additions & 0 deletions
18
src/components/Typography/DisplayHeading/DisplayHeadingSup/DisplayHeadingSup.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,18 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import safeRest from '../../../../safeRest' | ||
|
||
import styles from '../DisplayHeading.modules.scss' | ||
|
||
/** | ||
* Superscript text for headings. | ||
*/ | ||
const DisplayHeadingSup = ({ children, ...rest }) => ( | ||
<sup {...safeRest(rest)} className={styles.sup}>{children}</sup> | ||
) | ||
|
||
DisplayHeadingSup.propTypes = { | ||
children: PropTypes.string.isRequired | ||
} | ||
|
||
export default DisplayHeadingSup |
5 changes: 5 additions & 0 deletions
5
src/components/Typography/DisplayHeading/DisplayHeadingSup/DisplayHeadingSup.md
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,5 @@ | ||
``` | ||
<div> | ||
<DisplayHeading>Great Deals<DisplayHeading.Sup>1</DisplayHeading.Sup></DisplayHeading> | ||
</div> | ||
``` |
36 changes: 36 additions & 0 deletions
36
src/components/Typography/DisplayHeading/DisplayHeadingSup/__tests__/HeadingSup.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,36 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import toJson from 'enzyme-to-json' | ||
|
||
import DisplayHeadingSup from '../DisplayHeadingSup' | ||
|
||
describe('DisplayHeadingSup', () => { | ||
const doShallow = props => ( | ||
shallow(<DisplayHeadingSup {...props}>Some content</DisplayHeadingSup>) | ||
) | ||
|
||
it('renders', () => { | ||
const displayHeadingSup = doShallow() | ||
|
||
expect(toJson(displayHeadingSup)).toMatchSnapshot() | ||
}) | ||
|
||
it('renders an HTML sub tag', () => { | ||
const displayHeadingSup = doShallow() | ||
|
||
expect(displayHeadingSup).toHaveTagName('sup') | ||
}) | ||
|
||
it('passes additional attributes to the sup element', () => { | ||
const displayHeadingSup = doShallow({ id: 'the-sup-text' }) | ||
|
||
expect(displayHeadingSup).toHaveProp('id', 'the-sup-text') | ||
}) | ||
|
||
it('does not allow custom CSS', () => { | ||
const displayHeadingSup = doShallow({ className: 'my-custom-class', style: { color: 'hotpink' } }) | ||
|
||
expect(displayHeadingSup).not.toHaveProp('className', 'my-custom-class') | ||
expect(displayHeadingSup).not.toHaveProp('style') | ||
}) | ||
}) |
9 changes: 9 additions & 0 deletions
9
...ography/DisplayHeading/DisplayHeadingSup/__tests__/__snapshots__/HeadingSup.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[`DisplayHeadingSup renders 1`] = ` | ||
<sup | ||
className="sup" | ||
> | ||
Some content | ||
</sup> | ||
`; |