From 782def032190875cf65cf3b46ba813ed2474e3f8 Mon Sep 17 00:00:00 2001
From: Chris Swithinbank
Date: Wed, 4 Sep 2024 23:51:56 +0200
Subject: Add WCAG AAA colour contrast option to theme editor (#2282)
Co-authored-by: HiDeoo <494699+HiDeoo@users.noreply.github.com>
---
docs/package.json | 4 +-
docs/src/components/theme-designer.astro | 17 ++-
docs/src/components/theme-designer/atom.ts | 4 +
docs/src/components/theme-designer/color-lib.ts | 120 ++++++++++++++++-----
.../components/theme-designer/contrast-level.astro | 86 +++++++++++++++
docs/src/components/theme-designer/presets.astro | 4 +
docs/src/components/theme-designer/store.ts | 3 +-
docs/src/content/docs/guides/css-and-tailwind.mdx | 5 +
pnpm-lock.yaml | 16 +--
9 files changed, 217 insertions(+), 42 deletions(-)
create mode 100644 docs/src/components/theme-designer/contrast-level.astro
diff --git a/docs/package.json b/docs/package.json
index 7eafbf4a..acd93203 100644
--- a/docs/package.json
+++ b/docs/package.json
@@ -17,9 +17,9 @@
"@astro-community/astro-embed-youtube": "^0.5.2",
"@astrojs/starlight": "workspace:*",
"@lunariajs/core": "^0.1.1",
- "@types/culori": "^2.0.0",
+ "@types/culori": "^2.1.1",
"astro": "^4.10.2",
- "culori": "^3.2.0",
+ "culori": "^4.0.1",
"sharp": "^0.32.5"
},
"devDependencies": {
diff --git a/docs/src/components/theme-designer.astro b/docs/src/components/theme-designer.astro
index 4138dcaa..286b2075 100644
--- a/docs/src/components/theme-designer.astro
+++ b/docs/src/components/theme-designer.astro
@@ -1,12 +1,16 @@
---
import { TabItem, Tabs } from '@astrojs/starlight/components';
import ColorEditor, { type Props as EditorProps } from './theme-designer/color-editor.astro';
+import ContrastLevel, {
+ type Props as ContrastLevelProps,
+} from './theme-designer/contrast-level.astro';
import Presets, { type Props as PresetsProps } from './theme-designer/presets.astro';
import Preview from './theme-designer/preview.astro';
interface Props {
labels: {
presets: PresetsProps['labels'];
+ contrast: ContrastLevelProps['labels'];
editor: EditorProps['labels'] & { accentColor: string; grayColor: string };
preview: Record<
'darkMode' | 'lightMode' | 'bodyText' | 'linkText' | 'dimText' | 'inlineCode',
@@ -15,12 +19,14 @@ interface Props {
};
}
const {
- labels: { presets, editor, preview },
+ labels: { presets, contrast, editor, preview },
} = Astro.props;
---
+
+
@@ -52,7 +58,7 @@ const {
+
+
diff --git a/docs/src/components/theme-designer/presets.astro b/docs/src/components/theme-designer/presets.astro
index 140cf1ae..b0c8d73d 100644
--- a/docs/src/components/theme-designer/presets.astro
+++ b/docs/src/components/theme-designer/presets.astro
@@ -64,6 +64,10 @@ const resolvedPresets = Object.entries(presets).map(([key, preset]) => {
font-size: var(--sl-text-xs);
cursor: pointer;
}
+ button:focus-visible {
+ outline: 2px solid;
+ outline-offset: -4px;
+ }
:global([data-theme='light']) [data-preset] {
background-color: var(--light-bg);
color: var(--light-text);
diff --git a/docs/src/components/theme-designer/store.ts b/docs/src/components/theme-designer/store.ts
index 6eb1aa82..6466a845 100644
--- a/docs/src/components/theme-designer/store.ts
+++ b/docs/src/components/theme-designer/store.ts
@@ -1,4 +1,4 @@
-import { map } from './atom';
+import { atom, map } from './atom';
export const presets = {
ocean: {
@@ -27,6 +27,7 @@ export const store = {
accent: map(presets.default.accent),
gray: map(presets.default.gray),
};
+export const minimumContrast = atom(4.5);
export const usePreset = (name: string) => {
if (name in presets) {
diff --git a/docs/src/content/docs/guides/css-and-tailwind.mdx b/docs/src/content/docs/guides/css-and-tailwind.mdx
index 45c88e65..405b8e27 100644
--- a/docs/src/content/docs/guides/css-and-tailwind.mdx
+++ b/docs/src/content/docs/guides/css-and-tailwind.mdx
@@ -251,6 +251,8 @@ These variables are used throughout the UI with a range of gray shades used for
Use the sliders below to modify Starlight’s accent and gray color palettes.
The dark and light preview areas will show the resulting colors, and the whole page will also update to preview your changes.
+Use the Contrast Level option to specify which of the Web Content Accessibility Guideline [colour contrast standards](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable/Color_contrast) to meet.
+
When you’re happy with your changes, copy the CSS or Tailwind code below and use it in your project.
import ThemeDesigner from '~/components/theme-designer.astro';
@@ -266,6 +268,9 @@ import ThemeDesigner from '~/components/theme-designer.astro';
default: 'Default',
random: 'Random',
},
+ contrast: {
+ label: 'Contrast Level',
+ },
editor: {
accentColor: 'Accent',
grayColor: 'Gray',
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 4253d88d..4fb4f8fb 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -48,14 +48,14 @@ importers:
specifier: ^0.1.1
version: 0.1.1
'@types/culori':
- specifier: ^2.0.0
- version: 2.0.0
+ specifier: ^2.1.1
+ version: 2.1.1
astro:
specifier: ^4.10.2
version: 4.10.2(@types/node@18.16.19)(typescript@5.4.5)
culori:
- specifier: ^3.2.0
- version: 3.2.0
+ specifier: ^4.0.1
+ version: 4.0.1
sharp:
specifier: ^0.32.5
version: 0.32.6
@@ -2088,8 +2088,8 @@ packages:
/@types/cookie@0.6.0:
resolution: {integrity: sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==}
- /@types/culori@2.0.0:
- resolution: {integrity: sha512-bKpEra39sQS9UZ+1JoWhuGJEzwKS0dUkNCohVYmn6CAEBkqyIXimKiPDRZWtiOB7sKgkWMaTUpHFimygRoGIlg==}
+ /@types/culori@2.1.1:
+ resolution: {integrity: sha512-NzLYD0vNHLxTdPp8+RlvGbR2NfOZkwxcYGFwxNtm+WH2NuUNV8785zv1h0sulFQ5aFQ9n/jNDUuJeo3Bh7+oFA==}
dev: false
/@types/debug@4.1.12:
@@ -3093,8 +3093,8 @@ packages:
stream-transform: 2.1.3
dev: true
- /culori@3.2.0:
- resolution: {integrity: sha512-HIEbTSP7vs1mPq/2P9In6QyFE0Tkpevh0k9a+FkjhD+cwsYm9WRSbn4uMdW9O0yXlNYC3ppxL3gWWPOcvEl57w==}
+ /culori@4.0.1:
+ resolution: {integrity: sha512-LSnjA6HuIUOlkfKVbzi2OlToZE8OjFi667JWN9qNymXVXzGDmvuP60SSgC+e92sd7B7158f7Fy3Mb6rXS5EDPw==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dev: false
--
cgit