-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chao Liang
committed
Mar 29, 2019
1 parent
ba3c2f2
commit c64867b
Showing
9 changed files
with
239 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React from 'react'; | ||
import Example from '../components/Example'; | ||
import { StatusPill } from '../../src'; | ||
|
||
class StatusPillExample extends React.PureComponent { | ||
render() { | ||
return ( | ||
<> | ||
<label>Status pills</label> | ||
<div> | ||
<StatusPill status="Primary" /> | ||
<StatusPill status="Success" displayStyle="success" /> | ||
<StatusPill status="Warning" displayStyle="warning" /> | ||
<StatusPill status="Error" displayStyle="error" /> | ||
<StatusPill status="Light" displayStyle="light" /> | ||
</div> | ||
<br /> | ||
<label>Inverse status pills</label> | ||
<div> | ||
<StatusPill status="Primary" inverse /> | ||
<StatusPill status="Success" displayStyle="success" inverse /> | ||
<StatusPill status="Warning" displayStyle="warning" inverse /> | ||
<StatusPill status="Error" displayStyle="error" inverse /> | ||
<StatusPill status="Light" displayStyle="light" inverse /> | ||
</div> | ||
</> | ||
); | ||
} | ||
} | ||
|
||
const exampleProps = { | ||
componentName: 'Status Pill', | ||
notes: '', | ||
exampleCodeSnippet: ` | ||
<label>Status pills</label> | ||
<StatusPill status='Primary' /> | ||
<StatusPill status='Success' displayStyle='success' /> | ||
<StatusPill status='Warning' displayStyle='warning' /> | ||
<StatusPill status='Error' displayStyle='error' /> | ||
<StatusPill status='Light' displayStyle='light' /> | ||
<label>Inverse status pills</label> | ||
<StatusPill status='Primary' inverse /> | ||
<StatusPill status='Success' displayStyle='success' inverse /> | ||
<StatusPill status='Warning' displayStyle='warning' inverse /> | ||
<StatusPill status='Error' displayStyle='error' inverse /> | ||
<StatusPill status='Light' displayStyle='light' inverse /> | ||
`, | ||
propTypeSectionArray: [ | ||
{ | ||
propTypes: [ | ||
{ | ||
propType: 'status', | ||
type: 'string', | ||
note: 'Text inside status pill', | ||
}, | ||
{ | ||
propType: 'displayStyle', | ||
type: 'string', | ||
note: 'one of ["primary", "success", "warning", "error", "light"]', | ||
defaultValue: 'primary', | ||
}, | ||
{ | ||
propType: 'inverse', | ||
type: 'boolean', | ||
note: 'Status pill with inverse style', | ||
defaultValue: 'false', | ||
}, | ||
{ | ||
propType: 'dts', | ||
type: 'string', | ||
note: 'Generate "data-test-selector" on the status pill', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
export default () => ( | ||
<Example {...exampleProps}> | ||
<StatusPillExample /> | ||
</Example> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classnames from 'classnames'; | ||
import { expandDts } from 'lib/utils'; | ||
|
||
import './styles.scss'; | ||
|
||
const styles = ['primary', 'success', 'warning', 'error', 'light']; | ||
|
||
const StatusPill = ({ displayStyle, status, inverse, dts }) => ( | ||
<div | ||
className={classnames([ | ||
'aui--status-pill', | ||
`aui--status-pill-${displayStyle}`, | ||
{ 'aui--status-pill-inverse': inverse }, | ||
])} | ||
{...expandDts(dts)} | ||
> | ||
{status} | ||
</div> | ||
); | ||
|
||
StatusPill.defaultProps = { | ||
displayStyle: styles[0], | ||
inverse: false, | ||
}; | ||
|
||
StatusPill.propTypes = { | ||
status: PropTypes.string.isRequired, | ||
displayStyle: PropTypes.oneOf(styles), | ||
inverse: PropTypes.bool, | ||
dts: PropTypes.string, | ||
}; | ||
|
||
export default StatusPill; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import StatusPill from '.'; | ||
|
||
describe('<StatusPill />', () => { | ||
it('should have default style', () => { | ||
const wrapper = shallow(<StatusPill status="test" />); | ||
expect(wrapper.props().className).to.equal('aui--status-pill aui--status-pill-primary'); | ||
}); | ||
|
||
it('should allow style prop', () => { | ||
const wrapper = shallow(<StatusPill status="test" displayStyle="success" />); | ||
expect(wrapper.props().className).to.equal('aui--status-pill aui--status-pill-success'); | ||
}); | ||
|
||
it('should allow inverse prop', () => { | ||
const wrapper = shallow(<StatusPill status="test" displayStyle="success" inverse />); | ||
expect(wrapper.props().className).to.equal('aui--status-pill aui--status-pill-success aui--status-pill-inverse'); | ||
}); | ||
|
||
it('should support custom dts', () => { | ||
const wrapper = shallow(<StatusPill status="test" dts="test-dts" />); | ||
expect(wrapper.props()['data-test-selector']).to.equal('test-dts'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
@import '~styles/variable'; | ||
|
||
$color-primary: $color-status-blue; | ||
$color-primary-background: rgba($color-primary, .35); | ||
$color-success: $color-status-green; | ||
$color-success-background: rgba($color-success, .35); | ||
$color-warning: $color-status-orange; | ||
$color-warning-background: rgba($color-warning, .35); | ||
$color-error: $color-status-red; | ||
$color-error-background: rgba($color-error, .35); | ||
$color-light: $color-status-light; | ||
$color-inverse-border: $color-status-light; | ||
|
||
.aui--status-pill { | ||
font-size: $font-size-base; | ||
display: inline-block; | ||
align-items: center; | ||
justify-content: center; | ||
height: 24px; | ||
padding: 5px 12px; | ||
border: 1px solid transparent; | ||
border-radius: 12px; | ||
user-select: none; | ||
font-weight: $font-weight-bold; | ||
line-height: 1; | ||
color: $color-gray-darker; | ||
|
||
&.aui--status-pill-primary { | ||
background-color: $color-primary-background; | ||
|
||
&.aui--status-pill-inverse { | ||
background-color: $color-background; | ||
border-color: $color-inverse-border; | ||
color: $color-primary; | ||
} | ||
} | ||
|
||
&.aui--status-pill-success { | ||
background-color: $color-success-background; | ||
|
||
&.aui--status-pill-inverse { | ||
background-color: $color-background; | ||
border-color: $color-inverse-border; | ||
color: $color-success; | ||
} | ||
} | ||
|
||
&.aui--status-pill-warning { | ||
background-color: $color-warning-background; | ||
|
||
&.aui--status-pill-inverse { | ||
background-color: $color-background; | ||
border-color: $color-inverse-border; | ||
color: $color-warning; | ||
} | ||
} | ||
|
||
&.aui--status-pill-error { | ||
background-color: $color-error-background; | ||
|
||
&.aui--status-pill-inverse { | ||
background-color: $color-background; | ||
border-color: $color-inverse-border; | ||
color: $color-error; | ||
} | ||
} | ||
|
||
&.aui--status-pill-light { | ||
background-color: $color-light; | ||
|
||
&.aui--status-pill-inverse { | ||
background-color: $color-background; | ||
border-color: $color-inverse-border; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters