-
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(sup): Add Sup component as a dependent on Text
- Loading branch information
Showing
8 changed files
with
146 additions
and
3 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,30 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import safeRest from '../../../safeRest' | ||
|
||
import textStyles from '../Text/Text.modules.scss' | ||
|
||
const Sup = ({ children, size, ...rest }) => { | ||
return ( | ||
<sup {...safeRest(rest)} className={textStyles[`${size}Sup`]} > | ||
{children} | ||
</sup> | ||
) | ||
} | ||
|
||
|
||
Sup.propTypes = { | ||
children: PropTypes.string.isRequired, | ||
size: PropTypes.oneOf([ | ||
'small', | ||
'medium', | ||
'large' | ||
]) | ||
} | ||
|
||
Sup.defaultProps = { | ||
size: 'medium' | ||
} | ||
|
||
export default Sup |
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,8 @@ | ||
``` | ||
<div> | ||
<Paragraph><Text sup={String.fromCharCode(8482)}>Lorem</Text></Paragraph> | ||
<Paragraph size="small"><Text size="small" sup="Ipsum">Lorem</Text> dolor sit amet.</Paragraph> | ||
<Paragraph size="medium"><Text size="medium" sup="Ipsum">Lorem</Text> dolor sit amet.</Paragraph> | ||
<Paragraph size="large"><Text size="large" sup={String.fromCharCode(169)}>Lorem</Text> dolor sit amet.</Paragraph> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.base { | ||
font-size: 0.28rem; | ||
} | ||
|
||
.sup, .sub { | ||
font-size: .875rem; | ||
color: orange; | ||
} | ||
|
||
.sup { | ||
top: -.5em; | ||
} | ||
|
||
.sub { | ||
bottom: -.5em; | ||
} |
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 Sup from '../Sup' | ||
|
||
describe('Sup', () => { | ||
const doShallow = props => ( | ||
shallow(<Sup {...props}>Some content</Sup>) | ||
) | ||
|
||
it('renders', () => { | ||
const sup = doShallow() | ||
|
||
expect(toJson(sup)).toMatchSnapshot() | ||
}) | ||
|
||
it('renders an HTML sup tag', () => { | ||
const sup = doShallow() | ||
|
||
expect(sup).toHaveTagName('sup') | ||
}) | ||
|
||
it('passes additional attributes to the sup element', () => { | ||
const sup = doShallow({ id: 'the-id' }) | ||
|
||
expect(sup).toHaveProp('id', 'the-id') | ||
}) | ||
|
||
it('does not allow custom CSS', () => { | ||
const sup = doShallow({ className: 'my-custom-class', style: { color: 'hotpink' } }) | ||
|
||
expect(sup).not.toHaveProp('className', 'my-custom-class') | ||
expect(sup).not.toHaveProp('style') | ||
}) | ||
}) |
9 changes: 9 additions & 0 deletions
9
src/components/Typography/Sup/__tests__/__snapshots__/Sup.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[`Sup renders 1`] = ` | ||
<sup | ||
className="mediumSup" | ||
> | ||
Some content | ||
</sup> | ||
`; |
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