Skip to content

Commit

Permalink
Fix some types issues in storybook (#1539)
Browse files Browse the repository at this point in the history
  • Loading branch information
sndrs authored Jun 13, 2024
1 parent b0d59ba commit efb0bc6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 45 deletions.
2 changes: 0 additions & 2 deletions libs/@guardian/source/src/foundations/colour/palette.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Meta, Story } from '@storybook/blocks';
import { palette as colours } from './palette';
import { ColorPalette, ColorItem } from './storybookColorPalette';
import * as PaletteStories from './palette.stories';

<Meta of={PaletteStories} />
Expand Down
48 changes: 17 additions & 31 deletions libs/@guardian/source/src/foundations/colour/palette.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,25 @@ export const Palette = {
render: () => (
<ColorPalette>
{Object.entries(colours).map(([category, shades]) => {
/* Storybook is adding displayName and __docgenInfo to exported TS enum:
https://github.com/storybookjs/storybook/issues/9832 */
// These colours have been deprecated and should not be used.
// Skip deprecated colours
if (category !== '__docgenInfo' && category !== 'displayName') {
const deprecatedColours = {
opinion: ['300'],
culture: ['350'],
};
const usableShades = { ...shades };

const shadesWithoutDeprecated = {};

for (const shade in shades) {
const isShadeDeprecated =
deprecatedColours[category]?.includes(shade);

if (isShadeDeprecated) {
continue;
} else {
shadesWithoutDeprecated[shade] = shades[shade];
}
}

return (
<ColorItem
key={category}
title={category}
colors={{
...shadesWithoutDeprecated,
}}
/>
);
// These colours have been deprecated and should not be documented.
if (category === 'opinion') {
delete usableShades['300' as keyof typeof usableShades];
}
if (category === 'culture') {
delete usableShades['350' as keyof typeof usableShades];
}

return (
<ColorItem
key={category}
title={category}
colors={{
...usableShades,
}}
/>
);
})}
</ColorPalette>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ const ItemTitleStyles = css`
font-size: 14px;
`;

const ItemSubtitleStyles = css`
color: grey;
`;

const ItemDescriptionStyles = css`
flex: 0 0 30%;
line-height: 1;
Expand Down Expand Up @@ -127,12 +123,6 @@ const ListStyles = css`

type Colors = string[] | Record<string, string>;

interface ColorItemProps {
title: string;
subtitle: string;
colors: Colors;
}

const renderSwatch = (color: string, index: number) => (
<div css={SwatchStyles(color)} key={`${color} -${index} `} title={color} />
);
Expand Down Expand Up @@ -176,12 +166,17 @@ const 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 = ({ title, subtitle, colors }: ColorItemProps) => {
export const ColorItem = ({
title,
colors,
}: {
title: string;
colors: Colors;
}) => {
return (
<div css={ItemStyles}>
<div css={ItemDescriptionStyles}>
<div css={ItemTitleStyles}>{title}</div>
<div css={ItemSubtitleStyles}>{subtitle}</div>
</div>
<div css={SwatchesStyles}>{renderSwatchSpecimen(colors)}</div>
</div>
Expand Down

0 comments on commit efb0bc6

Please sign in to comment.