Skip to content

Commit

Permalink
NEW Add VersionedBadge for displaying versioning states in the CMS
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Apr 17, 2019
1 parent e46e0fb commit d3a9ffe
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions client/src/boot/registerComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Preview from 'components/Preview/Preview';
import ReduxForm from 'containers/Form/Form';
import UsedOnTable from 'components/UsedOnTable/UsedOnTable';
import Loading from 'components/Loading/Loading';
import VersionedBadge from 'components/VersionedBadge/VersionedBadge';
import ViewModeToggle from 'components/ViewModeToggle/ViewModeToggle';
import ResizeAware from 'components/ResizeAware/ResizeAware';
import Tag from 'components/Tag/Tag';
Expand Down Expand Up @@ -80,6 +81,7 @@ export default () => {
NotFoundComponent,
UsedOnTable,
Loading,
VersionedBadge,
ViewModeToggle,
ResizeAware,
Tag,
Expand Down
19 changes: 19 additions & 0 deletions client/src/components/VersionedBadge/README.md
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.
53 changes: 53 additions & 0 deletions client/src/components/VersionedBadge/VersionedBadge.js
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;
13 changes: 13 additions & 0 deletions client/src/components/VersionedBadge/VersionedBadge.scss
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 client/src/components/VersionedBadge/tests/VersionedBadge-story.js
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>
));
1 change: 1 addition & 0 deletions client/src/styles/bundle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
@import "../components/Toolbar/Toolbar";
@import "../components/TreeDropdownField/TreeDropdownField";
@import "../components/UsedOnTable/UsedOnTable";
@import "../components/VersionedBadge/VersionedBadge";
@import "../components/ViewModeToggle/ViewModeToggle";
@import "../components/PopoverOptionSet/PopoverOptionSet";

Expand Down

0 comments on commit d3a9ffe

Please sign in to comment.