Skip to content

Commit

Permalink
Merge pull request storybookjs#14439 from bart-krakowski/colorpalette…
Browse files Browse the repository at this point in the history
…_transparency_grid

Addon-docs: Add transparency support to color swatch
  • Loading branch information
shilman authored Jul 14, 2021
2 parents 6846b64 + f5295a2 commit dc390b8
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions lib/components/src/blocks/ColorPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,24 @@ const SwatchLabels = styled.div({
flexDirection: 'row',
});

const Swatch = styled.div({
interface SwatchProps {
background: string;
}

const Swatch = styled.div<SwatchProps>(({ background }) => ({
position: 'relative',
flex: 1,
});

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

const SwatchColors = styled.div(({ theme }) => ({
...getBlockBackgroundStyle(theme),
Expand All @@ -64,6 +79,9 @@ const SwatchColors = styled.div(({ theme }) => ({
height: 50,
marginBottom: 5,
overflow: 'hidden',
backgroundColor: 'white',
backgroundImage: `repeating-linear-gradient(-45deg, #ccc, #ccc 1px, #fff 1px, #fff 16px)`,
backgroundClip: 'padding-box'
}));

const SwatchSpecimen = styled.div({
Expand Down Expand Up @@ -122,15 +140,7 @@ interface ColorProps {
}

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

function renderSwatchLabel(color: string, index: number, colorDescription?: string) {
Expand Down

0 comments on commit dc390b8

Please sign in to comment.