Skip to content

Commit

Permalink
feat(text): Add ability to render a block element
Browse files Browse the repository at this point in the history
  • Loading branch information
lzcabrera committed Sep 28, 2017
1 parent 05100fa commit c823ae8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
19 changes: 14 additions & 5 deletions src/components/Typography/Text/Text.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import styles from './Text.modules.scss'
*
* <span class="docs--badge__new">new!</span> <span class="docs--badge__version">v0.22.0</span>
*/
const Text = ({ bold, size, invert, children, ...rest }, context) => {
const Text = ({ block, bold, size, invert, children, ...rest }, context) => {
const textColor = invert ? styles.invertedColor : styles.color

const classes = joinClassNames(
Expand All @@ -23,14 +23,22 @@ const Text = ({ bold, size, invert, children, ...rest }, context) => {
context.inheritColor ? styles.inheritColor : textColor
)

return (
<span {...safeRest(rest)} className={classes}>
{children}
</span>
return React.createElement(
block ? 'div' : 'span',
{
...safeRest(rest),
className: classes
},
children
)
}

Text.propTypes = {
/**
* If true, renders a block level element.
* Otherwise, renders an inline element.
*/
block: PropTypes.bool,
/**
* Embolden text without conveying any special importance or relevance.
*/
Expand All @@ -55,6 +63,7 @@ Text.propTypes = {
}

Text.defaultProps = {
block: false,
bold: false,
size: 'base',
invert: false
Expand Down
8 changes: 5 additions & 3 deletions src/components/Typography/Text/__tests__/Text.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ describe('Text', () => {
expect(toJson(text)).toMatchSnapshot()
})

it('renders an HTML span tag', () => {
const text = doShallow()

it('renders an HTML span or div tag', () => {
let text = doShallow()
expect(text).toHaveTagName('span')

text = doShallow({ block: true })
expect(text).toHaveTagName('div')
})

it('can be bold', () => {
Expand Down

0 comments on commit c823ae8

Please sign in to comment.