-
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.
Merge pull request #861 from creative-commoners/pulls/1.4/versioned-s…
…tate-badge NEW Add VersionedBadge for displaying versioning states in the CMS
- Loading branch information
Showing
12 changed files
with
107 additions
and
4 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.
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
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,17 @@ | ||
# Versioned Badge Component | ||
|
||
Badge component for displaying versioning states in a Bootstrap "badge" based style. | ||
|
||
## Example | ||
```js | ||
const props = { | ||
status: 'draft', | ||
className: 'my-custom-class', | ||
}; | ||
<VersionedBadge {...props} /> | ||
``` | ||
|
||
## Properties | ||
|
||
* `status` (string): The status for the badge, takes versioning states e.g. `draft`, `modified`, `live`, `archived`. | ||
* `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,42 @@ | ||
import React from 'react'; | ||
import classnames from 'classnames'; | ||
import PropTypes from 'prop-types'; | ||
import Badge from 'components/Badge/Badge'; | ||
import i18n from 'i18n'; | ||
|
||
/** | ||
* List of valid versioned statuses for a Badge | ||
* @type {string[]} | ||
*/ | ||
export const statuses = [ | ||
'draft', | ||
'modified', | ||
'live', | ||
'archived', | ||
]; | ||
|
||
/** | ||
* Capitalise the first letter | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
const toTitleCase = (str) => str.replace(/^\w/, c => c.toUpperCase()); | ||
|
||
const VersionedBadge = ({ status, className }) => { | ||
const props = { | ||
className: classnames(className, 'versioned-badge', `versioned-badge--${status}`), | ||
message: i18n._t(`ADMIN.${status.toUpperCase()}`, toTitleCase(status)), | ||
status: 'default', | ||
}; | ||
|
||
return ( | ||
<Badge {...props} /> | ||
); | ||
}; | ||
|
||
VersionedBadge.propTypes = { | ||
status: PropTypes.oneOf(statuses).isRequired, | ||
className: PropTypes.string, | ||
}; | ||
|
||
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,20 @@ | ||
.versioned-badge { | ||
padding-left: 0; | ||
padding-right: 0; | ||
|
||
&--draft { | ||
color: $state-draft; | ||
} | ||
|
||
&--modified { | ||
color: $state-modified; | ||
} | ||
|
||
&--live { | ||
color: $state-live; | ||
} | ||
|
||
&--archived { | ||
color: $state-archived; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
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 status="draft" /></p> | ||
<p>Contact Us <VersionedBadge status="modified" /></p> | ||
<p>About Us <VersionedBadge status="live" /></p> | ||
<p>Old Page <VersionedBadge status="archived" /></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
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