Skip to content

Commit

Permalink
Update Swatch component to use Specimen component
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Palmer committed Sep 14, 2017
1 parent 4d25d56 commit 73b9903
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 118 deletions.
1 change: 0 additions & 1 deletion globals/breakpoints.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

/* style-guide */
@custom-media --colors-3up (min-width: 50rem);
@custom-media --colors-4up (min-width: 64rem);
@custom-media --iconography-3up (min-width: 25rem);
@custom-media --iconography-4up (min-width: 50rem);
@custom-media --iconography-5up (min-width: 64rem);
Expand Down
40 changes: 1 addition & 39 deletions styleguide/components/Swatch/Swatch.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,9 @@
text-align: center;
}

.colorContainer {
.color {
width: 100%;
height: 0;
padding-bottom: 100%;
/**
* Deviates from our colour palette to ensure there is constrast between
* each colour and the background. Specifically required rendering
* our greys with this component
*/
background-color: #f8f8f8;
position: relative;
}

.color {
width: var(--size-lg-iii);
height: var(--size-lg-iii);
border-radius: 100%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

.attributes {
text-align: left;
margin-left: 0;
padding: 0;
margin-top: var(--size-regular);
list-style-type: none;
}

.attribute {
composes: fontRegular from '../../../globals/typography.css';
color: var(--color-grey);
}

.attribute + .attribute {
margin-top: var(--size-sm-iii);
}

.name {
font-weight: var(--fontweight-demi);
color: var(--color-black);
}
62 changes: 16 additions & 46 deletions styleguide/components/Swatch/Swatch.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,26 @@
import React, { PropTypes } from 'react';
import cx from 'classnames';

import Specimen from '../Specimen/Specimen';
import css from './Swatch.css';

const Swatch = ({ name, hex, rgb, variable }) => (
<div className={ css.root }>
<div className={ css.colorContainer }>
<div
className={ css.color }
style={ {
backgroundColor: rgb,
} }
/>
</div>
<ul className={ css.attributes }>
<li
className={ cx(
css.attribute,
css.name
) }
>
{ name }
</li>
<li
className={ cx(
css.attribute,
css.hex
) }
>
{ hex }
</li>
<li
className={ cx(
css.attribute,
css.rgb
) }
>
{ rgb }
</li>
<li
className={ cx(
css.attribute,
css.variable
) }
>
{ variable }
</li>
</ul>
</div>
const Swatch = ({ className, name, hex, rgb, variable }) => (
<Specimen
classNames={ {
root: className,
} }
attributes={ [
name,
hex,
rgb,
variable,
] }
>
<div className={ css.color } style={ { backgroundColor: rgb } } />
</Specimen>
);

Swatch.propTypes = {
className: PropTypes.string,
name: PropTypes.string,
hex: PropTypes.string,
rgb: PropTypes.string,
Expand Down
12 changes: 4 additions & 8 deletions styleguide/screens/Design/Colors.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
@lost gutter 1rem;
@lost flexbox flex;

.colorGroup {
lost-utility: clearfix;
margin-top: 0;
display: flex;
flex-wrap: wrap;
align-content: stretch;
}

.color {
display: inline-block;
lost-column: 1/2;
margin-top: var(--size-lg-i);
}
Expand All @@ -16,9 +18,3 @@
lost-column: 1/3;
}
}

@media(--colors-4up) {
.color {
lost-column: 1/4;
}
}
48 changes: 24 additions & 24 deletions styleguide/screens/Design/Colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,40 @@ const Colors = () => (
<h2 className={ type.h2 }>Brand</h2>
<div className={ css.colorGroup }>
{ brand.map(color => (
<div key={ color.id } className={ css.color }>
<Swatch
name={ color.name }
hex={ color.hex }
rgb={ color.rgb }
variable={ color.variable }
/>
</div>
<Swatch
key={ color.id }
className={ css.color }
name={ color.name }
hex={ color.hex }
rgb={ color.rgb }
variable={ color.variable }
/>
)) }
</div>
<h2 className={ type.h2 }>Greys</h2>
<div className={ css.colorGroup }>
{ greys.map(color => (
<div key={ color.id } className={ css.color }>
<Swatch
name={ color.name }
hex={ color.hex }
rgb={ color.rgb }
variable={ color.variable }
/>
</div>
<Swatch
key={ color.id }
className={ css.color }
name={ color.name }
hex={ color.hex }
rgb={ color.rgb }
variable={ color.variable }
/>
)) }
</div>
<h2 className={ type.h2 }>UI</h2>
<div className={ css.colorGroup }>
{ ui.map(color => (
<div key={ color.id } className={ css.color }>
<Swatch
name={ color.name }
hex={ color.hex }
rgb={ color.rgb }
variable={ color.variable }
/>
</div>
<Swatch
key={ color.id }
className={ css.color }
name={ color.name }
hex={ color.hex }
rgb={ color.rgb }
variable={ color.variable }
/>
)) }
</div>
</div>
Expand Down

0 comments on commit 73b9903

Please sign in to comment.