-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW Add VersionedBadge for displaying versioning states in the CMS
- Loading branch information
1 parent
e46e0fb
commit d3a9ffe
Showing
8 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,19 @@ | ||
# Versioned Badge Component | ||
|
||
Badge component for displaying versioning states in a Bootstrap "badge" based style. | ||
|
||
## Example | ||
```js | ||
const props = { | ||
status: 'draft', | ||
message: 'Draft', | ||
className: 'my-custom-class', | ||
}; | ||
<VersionedBadge {...props} /> | ||
``` | ||
|
||
## Properties | ||
|
||
* `status` (string): The status for the badge, takes versioning states e.g. `draft`, `modified`, `live`. | ||
* `message` (string): The string to display in the badge. Usually would be "Draft", "Published", etc. | ||
* `className` (string): Any extra classes to apply for the badge. |
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,53 @@ | ||
import React, { PureComponent } from 'react'; | ||
import classnames from 'classnames'; | ||
import PropTypes from 'prop-types'; | ||
import Badge from 'components/Badge/Badge'; | ||
|
||
/** | ||
* List of valid versioned statuses for a Badge | ||
* @type {string[]} | ||
*/ | ||
export const statuses = [ | ||
'draft', | ||
'modified', | ||
'live' | ||
]; | ||
|
||
class VersionedBadge extends PureComponent { | ||
render() { | ||
const { status, className } = this.props; | ||
if (!status) { | ||
return null; | ||
} | ||
|
||
const compiledClassNames = classnames( | ||
className, | ||
'versioned-badge', | ||
`versioned-badge--${status}`, | ||
); | ||
|
||
const props = { | ||
...this.props, | ||
className: compiledClassNames, | ||
status: 'default', | ||
inverted: false, | ||
}; | ||
|
||
return ( | ||
<Badge {...props} /> | ||
); | ||
} | ||
} | ||
|
||
VersionedBadge.propTypes = { | ||
message: PropTypes.node, | ||
status: PropTypes.oneOf(statuses), | ||
className: PropTypes.string, | ||
}; | ||
|
||
VersionedBadge.defaultProps = { | ||
status: 'default', | ||
className: '', | ||
}; | ||
|
||
export default VersionedBadge; |
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,13 @@ | ||
.versioned-badge { | ||
padding-left: 0; | ||
padding-right: 0; | ||
|
||
&--draft, | ||
&--modified { | ||
color: $orange; | ||
} | ||
|
||
&--live { | ||
color: $green; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
client/src/components/VersionedBadge/tests/VersionedBadge-story.js
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,13 @@ | ||
import React from 'react'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { storiesOf } from '@storybook/react'; | ||
import VersionedBadge from 'components/VersionedBadge/VersionedBadge'; | ||
|
||
storiesOf('Admin/Badges', module) | ||
.add('Versioned badge', () => ( | ||
<div> | ||
<p>My Page Name <VersionedBadge message="Draft" status="draft" /></p> | ||
<p>Contact Us <VersionedBadge message="Modified" status="modified" /></p> | ||
<p>About Us <VersionedBadge message="Live" status="live" /></p> | ||
</div> | ||
)); |
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