Skip to content

Commit

Permalink
fix: change pattern in the background and examples examples of usage
Browse files Browse the repository at this point in the history
  • Loading branch information
bart-krakowski committed Jul 8, 2021
1 parent 310f9e6 commit 726b124
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ import { Meta, ColorPalette, ColorItem } from '@storybook/addon-docs';
Apple60: 'rgba(102,191,60,.6)',
Apple30: 'rgba(102,191,60,.3)',
}}
isTransparent
/>
</ColorPalette>
10 changes: 8 additions & 2 deletions lib/components/src/Colors/colorpalette.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Dark theme Colors
<ColorPalette>
{Object.entries(convert(themes.dark).color).map(([k, v]) => {
if (typeof v === 'string' && (v.match(/^#/) || v.match(/^rgb/) || k.match(/color/i))) {
return <ColorItem key={k} title={k} colors={{ [k]: v }} />;
return <ColorItem key={k} title={k} colors={{ [k]: v }} isTransparent />;
} else if (typeof v === 'object') {
return (
<ColorItem
Expand All @@ -29,6 +29,7 @@ Dark theme Colors
: acc,
{}
)}
isTransparent
/>
);
}
Expand All @@ -49,6 +50,7 @@ Dark theme Backgrounds
key={k}
title={k}
colors={{ [k]: v }}
isTransparent
/>
);
} else if (typeof v === 'object') {
Expand All @@ -58,6 +60,7 @@ Dark theme Backgrounds
key={k}
title={k}
colors={colors}
isTransparent
/>
);
}
Expand All @@ -72,7 +75,7 @@ Light theme Colors
<ColorPalette>
{Object.entries(convert(themes.light).color).map(([k, v]) => {
if (typeof v === 'string' && (v.match(/^#/) || v.match(/^rgb/) || k.match(/color/i))) {
return <ColorItem key={k} title={k} colors={{ [k]: v }} />;
return <ColorItem key={k} title={k} colors={{ [k]: v }} isTransparent/>;
} else if (typeof v === 'object') {
return (
<ColorItem
Expand All @@ -86,6 +89,7 @@ Light theme Colors
: acc,
{}
)}
isTransparent
/>
);
}
Expand All @@ -106,6 +110,7 @@ Light theme Backgrounds
key={k}
title={k}
colors={{ [k]: v }}
isTransparent
/>
);
} else if (typeof v === 'object') {
Expand All @@ -115,6 +120,7 @@ Light theme Backgrounds
key={k}
title={k}
colors={colors}
isTransparent
/>
);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/components/src/blocks/ColorPalette.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const defaultStyle = () => (
'rgba(102,191,60,.6)',
'rgba(102,191,60,.3)',
]}
isTransparent
/>
<ColorItem
title="gradient"
Expand Down Expand Up @@ -55,6 +56,7 @@ export const NamedColors = () => (
Apple60: 'rgba(102,191,60,.6)',
Apple30: 'rgba(102,191,60,.3)',
}}
isTransparent
/>
<ColorItem
title="gradient"
Expand Down
65 changes: 39 additions & 26 deletions lib/components/src/blocks/ColorPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,27 @@ const SwatchLabels = styled.div({

interface SwatchProps {
background: string;
isTransparent?: boolean;
}

const Swatch = styled.div<SwatchProps>(({ background }) => ({
const Swatch = styled.div<SwatchProps>(({ background, isTransparent }) => ({
position: 'relative',
flex: 1,
backgroundColor: 'white',
backgroundImage: `
linear-gradient(45deg, #ccc 25%, transparent 25%),
linear-gradient(-45deg, #ccc 25%, transparent 25%),
linear-gradient(45deg, transparent 75%, #ccc 75%),
linear-gradient(-45deg, transparent 75%, #ccc 75%)`,
backgroundSize: '20px 20px',
backgroundPosition: '0 0, 0 10px, 10px -10px, -10px 0',

'&::before': {
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
background,
content: '""',
},

...(isTransparent && {
backgroundColor: 'white',
backgroundImage: `repeating-linear-gradient(-45deg, #ccc, #ccc 1px, #fff 1px, #fff 16px)`,

'&::before': {
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
background,
content: '""',
},
}),
}));

const SwatchColors = styled.div(({ theme }) => ({
Expand Down Expand Up @@ -142,10 +140,18 @@ interface ColorProps {
title: string;
subtitle: string;
colors: Colors;
isTransparent?: boolean;
}

function renderSwatch(color: string, index: number) {
return <Swatch key={`${color}-${index}`} title={color} background={color} />;
function renderSwatch(color: string, index: number, isTransparent: boolean) {
return (
<Swatch
key={`${color}-${index}`}
title={color}
background={color}
isTransparent={isTransparent}
/>
);
}

function renderSwatchLabel(color: string, index: number, colorDescription?: string) {
Expand All @@ -159,19 +165,21 @@ function renderSwatchLabel(color: string, index: number, colorDescription?: stri
);
}

function renderSwatchSpecimen(colors: Colors) {
function renderSwatchSpecimen(colors: Colors, isTransparent: boolean) {
if (Array.isArray(colors)) {
return (
<SwatchSpecimen>
<SwatchColors>{colors.map((color, index) => renderSwatch(color, index))}</SwatchColors>
<SwatchColors>
{colors.map((color, index) => renderSwatch(color, index, isTransparent))}
</SwatchColors>
<SwatchLabels>{colors.map((color, index) => renderSwatchLabel(color, index))}</SwatchLabels>
</SwatchSpecimen>
);
}
return (
<SwatchSpecimen>
<SwatchColors>
{Object.values(colors).map((color, index) => renderSwatch(color, index))}
{Object.values(colors).map((color, index) => renderSwatch(color, index, isTransparent))}
</SwatchColors>
<SwatchLabels>
{Object.keys(colors).map((color, index) => renderSwatchLabel(color, index, colors[color]))}
Expand All @@ -184,14 +192,19 @@ function renderSwatchSpecimen(colors: Colors) {
* A single color row your styleguide showing title, subtitle and one or more colors, used
* as a child of `ColorPalette`.
*/
export const ColorItem: FunctionComponent<ColorProps> = ({ title, subtitle, colors }) => {
export const ColorItem: FunctionComponent<ColorProps> = ({
title,
subtitle,
colors,
isTransparent = false,
}) => {
return (
<Item>
<ItemDescription>
<ItemTitle>{title}</ItemTitle>
<ItemSubtitle>{subtitle}</ItemSubtitle>
</ItemDescription>
<Swatches>{renderSwatchSpecimen(colors)}</Swatches>
<Swatches>{renderSwatchSpecimen(colors, isTransparent)}</Swatches>
</Item>
);
};
Expand Down

0 comments on commit 726b124

Please sign in to comment.