diff --git a/lib/components/src/blocks/ColorPalette.stories.tsx b/lib/components/src/blocks/ColorPalette.stories.tsx
index e09e42c91f02..f5a12b214aad 100644
--- a/lib/components/src/blocks/ColorPalette.stories.tsx
+++ b/lib/components/src/blocks/ColorPalette.stories.tsx
@@ -27,3 +27,29 @@ export const defaultStyle = () => (
/>
);
+
+export const NamedColors = () => (
+
+
+
+
+
+
+);
diff --git a/lib/components/src/blocks/ColorPalette.tsx b/lib/components/src/blocks/ColorPalette.tsx
index e4deaaef8fa2..246c0133fbb4 100644
--- a/lib/components/src/blocks/ColorPalette.tsx
+++ b/lib/components/src/blocks/ColorPalette.tsx
@@ -35,10 +35,8 @@ const SwatchLabel = styled.div(({ theme }) => ({
? transparentize(0.4, theme.color.defaultText)
: transparentize(0.6, theme.color.defaultText),
- '> div': {
- display: 'inline-block',
- overflow: 'hidden',
- maxWidth: '100%',
+ small: {
+ display: 'block',
},
}));
@@ -107,10 +105,52 @@ const List = styled.div(({ theme }) => ({
flexDirection: 'column',
}));
+type Colors = string[] | { [key: string]: string };
+
interface ColorProps {
title: string;
subtitle: string;
- colors: string[];
+ colors: Colors;
+}
+
+function renderSwatch(color: string) {
+ return (
+
+ );
+}
+
+function renderSwatchLabel(color: string, colorDescription?: string) {
+ return (
+
+ {color}
+ {colorDescription && {colorDescription}}
+
+ );
+}
+
+function renderSwatchSpecimen(colors: Colors) {
+ if (Array.isArray(colors)) {
+ return (
+
+ {colors.map(color => renderSwatch(color))}
+ {colors.map(color => renderSwatchLabel(color))}
+
+ );
+ }
+ return (
+
+ {Object.values(colors).map(color => renderSwatch(color))}
+
+ {Object.keys(colors).map(color => renderSwatchLabel(color, colors[color]))}
+
+
+ );
}
/**
@@ -124,29 +164,7 @@ export const ColorItem: FunctionComponent = ({ title, subtitle, colo
{title}
{subtitle}
-
-
-
-
- {colors.map(color => (
-
- ))}
-
-
- {colors.map(color => (
-
- {color}
-
- ))}
-
-
-
+ {renderSwatchSpecimen(colors)}
);
};