Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon-docs: Add transparency support to color swatch #14439

Merged
32 changes: 21 additions & 11 deletions lib/components/src/blocks/ColorPalette.tsx
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'
}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add background-clip: padding-box; to prevent the background from showing under the transparent border.


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