import React, { Fragment } from 'react'; import { staticColors, Hues, Shade } from './colors'; import colorThemes, { ThemeCategory } from './colorThemes'; import { generateColorVariables, generateThemeColorVariables, } from './colorVariables'; const description = ` Wagtail’s typographic styles are made available as separate design tokens, but in most scenarios it’s better to use one of the predefined text styles. `; 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: string[] = []; const fg: string[] = []; Object.values(staticColors).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.cssVariable} {shade.hsl} {shade.hex}

{shade.usage}

))}
); export default { title: 'Foundation / Colors', parameters: { docs: { extractComponentDescription: () => description, }, }, }; export const ColorPalette = () => ( <>

View Contrast Grid. Here is our full color palette, with contrasting text chosen for readability of this example only.

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

{color}

))} ); const TokenSwatch = ({ name, token }: { name: string; token: Token }) => (

{name}

{token.value.replace('var(--w-color-', '').replace(')', '')}

); const CategorySwatches = ({ category }: { category: ThemeCategory }) => (

{category.label}

{Object.entries(category.tokens).map(([name, token]) => ( ))}
); export const ColorThemes = () => ( <>

Light

{colorThemes.light.map((category: ThemeCategory) => ( ))}

Dark

{colorThemes.dark.map((category: ThemeCategory) => ( ))}
); const rootVariablesMap = [ ...Object.entries(generateColorVariables(staticColors)), ...Object.entries(generateThemeColorVariables(colorThemes.light)), ] .map(([cssVar, val]) => `${cssVar}: ${val};`) .join(''); const darkVariablesMap = Object.entries( generateThemeColorVariables(colorThemes.dark), ) .map(([cssVar, val]) => `${cssVar}: ${val};`) .join(''); const secondaryHSL = staticColors.secondary.DEFAULT.hsl.match( /\d+(\.\d+)?/g, ) as string[]; // Make sure this contains no empty lines, otherwise Sphinx docs will treat this as paragraphs. const liveEditorCustomisations = `:root { --w-color-primary: ${staticColors.primary.DEFAULT.hex}; /* Any valid CSS format is supported. */ --w-color-primary-200: ${staticColors.primary[200].hsl}; /* Set each HSL component separately to change all hues at once. */ --w-color-secondary-hue: ${secondaryHSL[0]}; --w-color-secondary-saturation: ${secondaryHSL[1]}%; --w-color-secondary-lightness: ${secondaryHSL[2]}%; }`; // Story using inline styles only so it can be copy-pasted into the Wagtail documentation for color customisations. const demoStyles = ` :root {${rootVariablesMap}} .w-theme-dark {${darkVariablesMap}} .wagtail-color-swatch { border-collapse: separate; border-spacing: 4px; } .wagtail-color-swatch td:first-child, .wagtail-color-swatch .w-theme-dark { height: 1.5rem; width: 1.5rem; border: 1px solid #333; forced-color-adjust: none; } `; const warningComment = ''; const colorCustomisationsDemo = (

Make sure to test any customisations against our{' '} Contrast Grid. Try out your own customisations with this interactive style editor:

{/* Required styles are in a separate tag so they can’t be overridden, compressed to a single line for ease of copy-pasting. */}
      {/* contentEditable style element so it can be edited directly in the browser. */}
      
    

Static colours

{Object.values(staticColors).map((hues) => Object.entries(hues) // Show DEFAULT shades first, then in numerical order. .sort(([nameA], [nameB]) => nameA === 'DEFAULT' ? -1 : Number(nameB) - Number(nameA), ) .map(([name, shade]) => ( )), )}
Variable Usage
{shade.cssVariable} {shade.usage}

Light & dark theme colours

{colorThemes.light.map((category) => ( {Object.values(category.tokens).map((token) => ( ))} ))}
Light Dark Variable
{category.label}
{token.cssVariable}
); export const ColorCustomisations = () => ( <>

Use this story to test customising colors. The section below is also copied in the Wagtail docs so implementers know which colors are customisable in a given release.


{colorCustomisationsDemo} );