Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CounterLabel to use Styled System & Emotion #196

Merged
merged 4 commits into from
Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/CounterLabel.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import {mapWhitespaceProps} from './props'
import {withSystemProps, COMMON} from './system-props'

export default function CounterLabel({theme, children, ...rest}) {
const {className} = mapWhitespaceProps(rest)
return <span className={classnames(className, 'Counter', theme && `Counter--${theme}`)}>{children}</span>
function CounterLabel({scheme, children, className}) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theme needed to be changed to scheme to get it to work, must be conflicting with emotion 🤷‍♀️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, works for me! We should start a draft of the release notes and add this to the breaking changes.

return <span className={classnames(className, 'Counter', scheme && `Counter--${scheme}`)}>{children}</span>
}

CounterLabel.propTypes = {
children: PropTypes.node,
theme: PropTypes.oneOf(['gray', 'gray-light'])
scheme: PropTypes.oneOf(['gray', 'gray-light'])
}

export default withSystemProps(CounterLabel, COMMON)
18 changes: 8 additions & 10 deletions src/__tests__/CounterLabel.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import React from 'react'
import CounterLabel from '../CounterLabel'
import {render, renderClasses, rendersClass} from '../utils/testing'
import {render} from '../utils/testing'
import {COMMON} from '../system-props'

describe('CounterLabel', () => {
xit('is a system component', () => {
expect(CounterLabel.systemComponent).toEqual(true)
})

it('renders a <span> with the "Counter" class', () => {
expect(render(<CounterLabel />)).toEqual(render(<span className="Counter" />))
expect(render(<CounterLabel />).type).toEqual('span')
expect(render(<CounterLabel />).props.className).toContain('Counter')
})

it('respects the "theme" prop', () => {
expect(renderClasses(<CounterLabel theme="gray" />)).toEqual(['Counter', 'Counter--gray'])
expect(renderClasses(<CounterLabel theme="gray-light" />)).toEqual(['Counter', 'Counter--gray-light'])
expect(render(<CounterLabel scheme="gray" />).props.className).toContain('Counter--gray')
expect(render(<CounterLabel scheme="gray-light" />).props.className).toContain('Counter--gray-light')
// FIXME: should we test invalid values like this?
// expect(renderClasses(<CounterLabel theme="red" />)).toEqual(['Counter', 'Counter--red'])
})

it('respects margin utility prop', () => {
expect(rendersClass(<CounterLabel m={4} />, 'm-4')).toEqual(true)
})

it('respects padding utility prop', () => {
expect(rendersClass(<CounterLabel p={4} />, 'p-4')).toEqual(true)
it('implements layout system props', () => {
expect(CounterLabel).toImplementSystemProps(COMMON)
})
})