-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Add Flag component #322
Changes from 1 commit
4e078f7
d010679
72c36f8
88ce254
69d4214
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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} />) | ||
} | ||
|
||
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 */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
name: PropTypes.string.isRequired, | ||
} | ||
|
||
export default Flag |
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', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is covered by the |
||
shallow(<Flag />) | ||
.should.have.className('flag') | ||
}) | ||
|
||
it('passes property "name" to class', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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') | ||
}) | ||
}) |
There was a problem hiding this comment.
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.