Skip to content

Commit

Permalink
feat(icon): Change size prop values to numbers only
Browse files Browse the repository at this point in the history
Deprecate children prop
  • Loading branch information
lzcabrera committed Sep 22, 2017
1 parent d0c9248 commit 1c64c04
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
15 changes: 9 additions & 6 deletions src/components/Icon/Icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const Icon = ({ glyph, variant, fixedWidth, size, className, children, ...rest }
deprecate('Icon', '\'fixedWidth\' prop is deprecated.')
}

if (children) {
deprecate('Icon', '\'children\' prop is deprecated.')
}

const classes = [
`${styles[`iconCore${capitalize(glyph)}`]}`,
`${variant ? styles[variant] : ''}`,
Expand All @@ -37,8 +41,7 @@ const Icon = ({ glyph, variant, fixedWidth, size, className, children, ...rest }
className={classes}
aria-label={rest['aria-label']}
aria-hidden={rest['aria-label'] ? undefined : 'true'}
>
{children}
>{children}
</i>
)
}
Expand Down Expand Up @@ -86,9 +89,9 @@ Icon.propTypes = {
*/
fixedWidth: PropTypes.bool,
/**
*
* The icon size in pixels.
*/
size: PropTypes.oneOf(['16px', '24px', '48px']),
size: PropTypes.oneOf(['16', '24', '48']),
/**
* One or more CSS class names separated by spaces to append onto the icon.
* Don't advertise as we plan on removing this feature soon.
Expand All @@ -97,14 +100,14 @@ Icon.propTypes = {
*/
className: PropTypes.string,
/**
* @ignore
* @deprecated since v0.23.0
*/
children: PropTypes.node
}
Icon.defaultProps = {
variant: 'inherit',
fixedWidth: false,
size: '24px',
size: '24',
className: '',
children: null
}
Expand Down
19 changes: 13 additions & 6 deletions src/components/Icon/__tests__/Icon.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ describe('<Icon />', () => {
})

it('can be sized', () => {
const icon = doShallow({ size: '16px' })
const icon = doShallow({ size: '16' })

expect(icon).toHaveClassName('size16px')
expect(icon).toHaveClassName('size16')
})

it('supports custom CSS classes', () => {
Expand All @@ -60,37 +60,44 @@ describe('<Icon />', () => {
})

describe('deprecated props', () => {
it('deprecates className', () => {
afterEach(() => {
jest.clearAllMocks()
})

it('deprecates className', () => {
const icon = doShallow({ className: 'my-custom-class' })

expect(icon).toHaveProp('className')
expect(deprecate).toHaveBeenCalled()
})

it('deprecates style', () => {
jest.clearAllMocks()
const icon = doShallow({ style: 'color: hotpink' })

expect(icon).toHaveProp('style')
expect(deprecate).toHaveBeenCalled()
})

it('deprecates disabled variant', () => {
jest.clearAllMocks()
const icon = doShallow({ variant: 'disabled' })

expect(icon).toHaveClassName('disabled')
expect(deprecate).toHaveBeenCalled()
})

it('deprecates fixedWidth prop', () => {
jest.clearAllMocks()
const icon = doShallow({ fixedWidth: true })

expect(icon).toHaveClassName('fw')
expect(deprecate).toHaveBeenCalled()
})

// it('deprecates children prop', () => {
// const defaultChildren = '<span>Some content</span>'
// const icon = doShallow({ children: defaultChildren })
//
// expect(deprecate).toHaveBeenCalled()
// })
})

it('provides a label to specific glyphs', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
exports[`<Icon /> renders 1`] = `
<i
aria-hidden="true"
className="iconCoreCheckmark inherit size24px "
className="iconCoreCheckmark inherit size24 "
/>
`;

0 comments on commit 1c64c04

Please sign in to comment.