From bd874c63c96dbccbd6c6e4e00c93d23e646477c4 Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Wed, 6 Apr 2022 10:47:09 +0100 Subject: [PATCH] Implement colors palette visualisation with contrast grid link --- client/src/tokens/colors.stories.tsx | 93 +++++++++++++++++++ .../wagtailadmin/shared/icons.stories.tsx | 16 +++- 2 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 client/src/tokens/colors.stories.tsx diff --git a/client/src/tokens/colors.stories.tsx b/client/src/tokens/colors.stories.tsx new file mode 100644 index 0000000000..e0e76b91d7 --- /dev/null +++ b/client/src/tokens/colors.stories.tsx @@ -0,0 +1,93 @@ +import React from 'react'; +import colors, { Hues, Shade } from './colors'; + +const description = ` +Wagtail’s color palette is structured as design tokens, available as CSS classes. +`; + +interface PaletteProps { + color: string; + hues: Hues; +} + +/** + * Generates a contrast grid URL from our color palette. + */ +const getContrastGridLink = () => { + const url = 'https://contrast-grid.eightshapes.com/'; + const parameters = + '?version=1.1.0&es-color-form__tile-size=compact&es-color-form__show-contrast=aaa&es-color-form__show-contrast=aa&es-color-form__show-contrast=aa18'; + const bg = []; + const fg = []; + Object.values(colors).forEach((hues: Hues) => { + Object.values(hues).forEach((shade: Shade) => { + const color = `${shade.hex}, ${shade.textUtility.replace('w-text-', '')}`; + bg.push(color); + + if (!shade.usage.toLowerCase().includes('background only')) { + fg.push(color); + } + }); + }); + + return `${url}${parameters}&background-colors=${encodeURIComponent( + bg.join('\r\n'), + )}&foreground-colors=${encodeURIComponent(fg.join('\r\n'))}`; +}; + +const Palette = ({ color, hues }: PaletteProps) => ( +
+ {Object.entries(hues).map(([name, shade]) => ( +
+

{`${color} ${name === 'DEFAULT' ? '' : name}`}

+
+ {shade.textUtility} + {shade.bgUtility} + {shade.hex} +
+

{shade.usage}

+
+ ))} +
+); + +/** + * Displays all icons within our sprite. + */ +const ColorPalette = () => ( + <> +

+ View Contrast Grid +

+ {Object.entries(colors).map(([color, hues]) => ( +
+

{color}

+ +
+ ))} + +); + +export default { + title: 'Foundation / Colors', + parameters: { + docs: { + extractComponentDescription: () => description, + }, + }, + // argTypes: { + // color: { + // description: 'Only intended for demo purposes', + // }, + // }, +}; + +export const AllColors = (args) => ; + +AllColors.args = {}; diff --git a/wagtail/admin/templates/wagtailadmin/shared/icons.stories.tsx b/wagtail/admin/templates/wagtailadmin/shared/icons.stories.tsx index c5837762d7..e66546154c 100644 --- a/wagtail/admin/templates/wagtailadmin/shared/icons.stories.tsx +++ b/wagtail/admin/templates/wagtailadmin/shared/icons.stories.tsx @@ -1,6 +1,12 @@ import React, { useState, useEffect } from 'react'; import { getTemplatePattern } from 'storybook-django/src/react'; +const description = ` +Wagtail comes with a base icon set, which can be extended by site implementers. + +Here is a list of all available icons, auto-generated from our SVG sprite. +`; + /** * Displays all icons within our sprite. */ @@ -48,6 +54,12 @@ const IconsTable = ({ color }: { color: string }) => { }; export default { + title: 'Foundation / Icons', + parameters: { + docs: { + extractComponentDescription: () => description, + }, + }, argTypes: { color: { description: 'Only intended for demo purposes', @@ -55,8 +67,8 @@ export default { }, }; -export const Icons = (args) => ; +export const AllIcons = (args) => ; -Icons.args = { +AllIcons.args = { color: 'currentColor', };