Skip to content

Commit

Permalink
feat(card): remove deprecated props
Browse files Browse the repository at this point in the history
- remove className and pass all props to safeRest
  • Loading branch information
ryanoglesby08 authored and theetrain committed Oct 18, 2017
1 parent dcc8dba commit 398cfc7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 46 deletions.
35 changes: 7 additions & 28 deletions src/components/Card/Card.jsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
import React from 'react'
import PropTypes from 'prop-types'

import { deprecate } from '../../utils/warn'
import safeRest from '../../utils/safeRest'

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

/**
* A container that serves as an entry point to more detailed information.
*/
const Card = ({ className, children, ...rest }) => {
if (className) {
deprecate(
'Card',
'Custom CSS classes are deprecated. This component does not support custom styling.'
)
}

if (rest.style) {
deprecate(
'Card',
'Inline styles are deprecated. This component does not support custom styling.'
)
}

return (
<div {...rest} className={styles.card}>
{children}
</div>
)
}
const Card = ({ children, ...rest }) => (
<div {...safeRest(rest)} className={styles.card}>
{children}
</div>
)

Card.propTypes = {
/**
* One or more CSS class names separated by spaces to append onto the container.
* @deprecated since v0.18.0. Card will no longer support custom styling.
*/
className: PropTypes.string, // eslint-disable-line react/require-default-props
/**
* The Card's content. Can be text, any HTML element, or any component.
* The content. Can be text, any HTML element, or any component.
*/
children: PropTypes.node.isRequired,
}
Expand Down
29 changes: 11 additions & 18 deletions src/components/Card/__tests__/Card.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,28 @@ import React from 'react'
import { shallow } from 'enzyme'
import toJson from 'enzyme-to-json'

import { deprecate } from '../../../utils/warn'

import Card from '../Card'

jest.mock('../../../utils/warn')

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

it('renders', () => {
const card = shallow(<Card>Some content</Card>)
const card = doShallow()

expect(toJson(card)).toMatchSnapshot()
})

it('passes attributes to DOM node', () => {
const card = shallow(
<Card id="hello" title="my title">
Some content
</Card>
)
it('passes additional attributes to the input element', () => {
const card = doShallow({ role: 'some-role', 'data-some-value': 'some value' })

expect(card).toHaveProp('id', 'hello')
expect(card).toHaveProp('title', 'my title')
expect(card).toHaveProp('role', 'some-role')
expect(card).toHaveProp('data-some-value', 'some value')
})

it('accepts but deprecates inline styles', () => {
const styles = { color: 'blue' }
const card = shallow(<Card style={styles}>Some content</Card>)
it('does not allow custom CSS', () => {
const card = doShallow({ className: 'my-custom-class', style: { color: 'hotpink' } })

expect(card).toHaveProp('style', styles)
expect(deprecate).toHaveBeenCalled()
expect(card).not.toHaveProp('className', 'my-custom-class')
expect(card).not.toHaveProp('style')
})
})

0 comments on commit 398cfc7

Please sign in to comment.