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

Add Flag component #322

Merged
merged 5 commits into from
Jul 5, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 30 additions & 0 deletions src/elements/Flag/Flag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { PropTypes } from 'react'
import cx from 'classnames'
import META from '../../utils/Meta'

function Flag(props) {
const { className, name, ...rest } = props
const classes = cx(
name,
className,
'flag',
)

return (<i className={classes} {...rest} />)
Copy link
Member

Choose a reason for hiding this comment

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

Parens are only required for multi line JSX. They can be removed here.

}

Flag._meta = {
library: META.library.semanticUI,
name: 'Flag',
type: META.type.element,
}

Flag.propTypes = {
/** Classes to add to the Flag className. */
className: PropTypes.string,

/** Name for element, can use the two digit country code, the full name, or a common alias */
Copy link
Member

Choose a reason for hiding this comment

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

Name of element seems like it should be Flag name.

name: PropTypes.string.isRequired,
}

export default Flag
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export Button from './elements/Button/Button'
export Buttons from './elements/Button/Buttons'
export Container from './elements/Container/Container'
export Divider from './elements/Divider/Divider'
export Flag from './elements/Flag/Flag'
export Header from './elements/Header/Header'
export Icon from './elements/Icon/Icon'
export Image from './elements/Image/Image'
Expand Down
23 changes: 23 additions & 0 deletions test/specs/elements/Flag/Flag-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react'

import Flag from 'src/elements/Flag/Flag'
import * as common from 'test/specs/commonTests'

describe('Flag', () => {
common.isConformant(Flag)

it('renders an <i /> element', () => {
shallow(<Flag />)
.should.have.tagName('i')
})

it('adds the "flag" class', () => {
Copy link
Member

Choose a reason for hiding this comment

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

This test is covered by the isConformant() test. The isConformant() test ensures the className includes has the component name.

shallow(<Flag />)
.should.have.className('flag')
})

it('passes property "name" to class', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry I missed this earlier, this test should be replaced with the common tests for "value only" props:

common.propValueOnlyToClassName(Flag, 'name')

This test ensures the prop is defined in _meta, is added to className when it should be, and is not added when it shouldn't be.

shallow(<Flag name='ru' />)
.should.have.className('ru')
})
})