Skip to content

Commit

Permalink
feat(text): Create Text component for rendering inline text blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
lzcabrera committed Aug 22, 2017
1 parent e7e7980 commit 18e7274
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ module.exports = {
components() {
return compact([
path.resolve('src/old-components/Card/Card.jsx'),
toggle(path.resolve('src/components/Typography/Paragraph/Paragraph.jsx'))
toggle(path.resolve('src/components/Typography/Paragraph/Paragraph.jsx')),
toggle(path.resolve('src/components/Typography/Text/Text.jsx'))
])
},
sections: [
Expand Down
41 changes: 41 additions & 0 deletions src/components/Typography/Text/Text.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'

import safeRest from '../../../safeRest'

import styles from '../Paragraph/Paragraph.modules.scss'


const Text = ({ bold, size, children, ...rest }) => {
const classes = classnames(
styles.color,
styles[size],
{
[styles.bold]: bold
}
)

return (
<span {...safeRest(rest)} className={classes}>
{children}
</span>
)
}

Text.propTypes = {
bold: PropTypes.bool,
size: PropTypes.oneOf([
'small',
'medium',
'large'
]),
children: PropTypes.node.isRequired
}

Text.defaultProps = {
bold: false,
size: 'medium'
}

export default Text
3 changes: 3 additions & 0 deletions src/components/Typography/Text/Text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```
<Text>I am some text</Text>
```
52 changes: 52 additions & 0 deletions src/components/Typography/Text/__tests__/Text.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react'
import { shallow } from 'enzyme'
import toJson from 'enzyme-to-json'

import Text from '../Text'

describe('Text', () => {
const doShallow = props => (
shallow(<Text {...props}>Some content</Text>)
)

it('renders', () => {
const text = doShallow()

expect(toJson(text)).toMatchSnapshot()
})

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

expect(text).toHaveTagName('span')
})

it('can be bold', () => {
let text = doShallow()
expect(text).not.toHaveClassName('bold')

text = doShallow({ bold: true })
expect(text).toHaveClassName('bold')
})

it('can be sized', () => {
let text = doShallow()
expect(text).toHaveClassName('medium')

text = doShallow({ size: 'small' })
expect(text).toHaveClassName('small')
})

it('passes additional attributes to the span element', () => {
const text = doShallow({ id: 'the-text' })

expect(text).toHaveProp('id', 'the-text')
})

it('does not allow custom CSS', () => {
const text = doShallow({ className: 'my-custom-class', style: { color: 'hotpink' } })

expect(text).not.toHaveProp('className', 'my-custom-class')
expect(text).not.toHaveProp('style')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Text renders 1`] = `
<span
className="color medium"
>
Some content
</span>
`;

0 comments on commit 18e7274

Please sign in to comment.