Files
ipal-kit/docs/accessibility.md
T
Radosław SmolińskiandClaude Opus 5.5 2d9f3e15d4 Docs in English (part 1), seeding guide, Coolify deployment
- Translate to English every doc the code branches did not touch: AGENT.md,
  developer guide, vibe, CHANGELOG, docs index, module pages, all skills
  except ipal-seo-check (14 pages follow after the security/SEO merge).
  Placeholder marker is now [TO FILL: …]; skill resources renamed to
  section-code.md / nav-code.md. AGENT.md and the ipal-skills pointer
  block say the docs are in English.
- docs/seeding.md: create-only, natural keys, never delete, no users or
  secrets, empty-field globals, fallbackLocale: false, dry run, backup and
  restore, production update guard, seeds vs migrations, Coolify Terminal.
  Seed templates gain --dry-run, the SEED_UPDATE production guard
  (IPAL_SEED_ALLOW_PROD_UPDATE), skip of edited records and a summary.
  "Seeding on production" rule block in AGENT.md.
- Coolify is the single deployment path (deployment, env, developer guide,
  ipal-setup): build vs runtime env, migrations on container start
  (prodMigrations), health check and rolling updates, rollback, backups and
  restore, DNS/Let's Encrypt/CAA. R2: custom domain needs a Cloudflare zone;
  default is media served by the app (R2_PUBLIC_URL empty).
- docsConsistency: no Polish prose outside code/quoted data (pending pages
  listed); IPAL_* names may also be read by shipped skill templates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-22 17:39:03 +02:00

222 lines
8.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Accessibility — a11y widget (WCAG)
Accessibility widget: a floating button that opens a panel with options for people
with disabilities (text size, contrast, grayscale, underlined links, readable font,
no animations, big cursor).
> **OPTIONAL — do not add by default.** The a11y widget is legally required
> ONLY for some sites (public bodies, some e-commerce/services covered by the
> European Accessibility Act). For most commercial sites it is an OPTION, not a
> duty. Add it WHEN the client/project requires it — not on every site
> automatically. If in doubt: ask whether the site falls under accessibility rules.
Same pattern as CookieBanner: provider + widget, wired once. Preferences live in a
cookie (no flash) and are applied as `data-a11y-*` attributes on `<html>`.
> **Plugin/project boundary:** the plugin provides the MECHANISM (widget, state,
> cookie, attributes on html). The project provides the CSS that reacts to the
> attributes — because styles depend on the project design (colors, fonts,
> Tailwind). The plugin does NOT impose styles, so nothing clashes. Ready-to-copy
> CSS is below.
---
## 1. Wiring — Provider + Widget
```tsx
// app/(frontend)/[locale]/layout.tsx
import { AccessibilityProvider, AccessibilityWidget } from '@intecion/ipal-kit/client'
<AccessibilityProvider>
<body>
{children}
<AccessibilityWidget
classNames={{
button: 'a11y-button',
panel: 'a11y-panel',
row: 'a11y-row',
label: 'a11y-label',
control: 'a11y-control',
active: 'a11y-active',
resetButton: 'a11y-reset',
closeButton: 'a11y-close',
}}
texts={A11Y[locale]} // labels per locale; ENGLISH by default
/>
</body>
</AccessibilityProvider>
```
The widget is unstyled (like CookieBanner) — match the classNames to your design.
## Labels — English by default, configured per locale
Default labels are **English** (the plugin is multilingual, neutral at its base).
Keep translations in the project and pass the set for the active language through
`texts` (`A11yTexts`). The plugin stays content-agnostic:
```tsx
import type { A11yTexts } from '@intecion/ipal-kit/client'
const A11Y: Record<string, A11yTexts> = {
pl: { title: 'Dostępność', textSize: 'Rozmiar tekstu', reset: 'Resetuj', /* … */ },
de: { title: 'Barrierefreiheit', textSize: 'Textgröße', /* … */ },
}
<AccessibilityWidget texts={A11Y[locale]} classNames={{ /* … */ }} />
```
Pass only the keys you want to override — the rest falls back to the English
default. You can also keep the labels in a localized global and read them from the
panel (consistent with "managed from the panel"), but that is a project decision —
the plugin only needs `A11yTexts` for the current locale.
---
## 2. CSS that reacts to the attributes (MANDATORY — project)
The widget sets attributes on `<html>`. Without this CSS nothing happens. Copy it
into the project's global CSS (adapt it to the design):
```css
/* Text size */
html[data-a11y-text="1"] { font-size: 112.5%; }
html[data-a11y-text="2"] { font-size: 125%; }
html[data-a11y-text="3"] { font-size: 150%; }
/* Line spacing */
html[data-a11y-line="1"] * { line-height: 1.8 !important; }
html[data-a11y-line="2"] * { line-height: 2.2 !important; }
/* High contrast */
html[data-a11y-contrast="high"] {
filter: contrast(1.4);
}
/* Inverted contrast */
html[data-a11y-contrast="inverted"] {
filter: invert(1) hue-rotate(180deg);
}
html[data-a11y-contrast="inverted"] img,
html[data-a11y-contrast="inverted"] video {
filter: invert(1) hue-rotate(180deg); /* restore media */
}
/* Grayscale */
html[data-a11y-grayscale="on"] { filter: grayscale(1); }
/* Note: filter on html does not stack — if you combine contrast+grayscale,
apply it on body or merge it into one rule. */
/* Underlined links */
html[data-a11y-underline="on"] a { text-decoration: underline !important; }
/* Readable font (swap in your own dyslexia-friendly / simple font) */
html[data-a11y-font="readable"] * {
font-family: Verdana, Tahoma, sans-serif !important;
letter-spacing: 0.02em;
}
/* No animations */
html[data-a11y-motion="reduce"] *,
html[data-a11y-motion="reduce"] *::before,
html[data-a11y-motion="reduce"] *::after {
animation-duration: 0.001ms !important;
transition-duration: 0.001ms !important;
scroll-behavior: auto !important;
}
/* Big cursor */
html[data-a11y-cursor="big"] * {
cursor: url('/cursors/big.svg') 4 4, auto !important;
}
```
Adapt the values to the project (contrast colors, font, cursor). This is your CSS —
the plugin only sets the attributes.
> **Contrast + filter:** several options use `filter` on `<html>`. CSS `filter` on
> one element does NOT stack values from different rules — the last one wins.
> If you want to combine them (e.g. grayscale + contrast), apply the filters on
> `body` with the full value, or build combined rules. Single options work
> without issues.
---
## 3. No flash (SSR) — optional
By default the widget applies the attributes after hydration (a short flash on load
if the user had settings). To avoid it, read the cookie server-side and set the
attributes on `<html>` during SSR:
```tsx
// layout.tsx (server) — read the cookie and set the attributes right away
import { cookies } from 'next/headers'
import { A11Y_COOKIE, parseA11y, a11yAttributes } from '@intecion/ipal-kit'
const raw = (await cookies()).get(A11Y_COOKIE)?.value
const attrs = a11yAttributes(parseA11y(raw))
const htmlAttrs = Object.fromEntries(
Object.entries(attrs).filter(([, v]) => v !== null),
)
return <html lang={locale} {...htmlAttrs}>...</html>
```
The provider re-applies and syncs on the client anyway. This only removes the flash.
### State and attributes (`A11yState`)
Cookie `a11y-prefs` (`A11Y_COOKIE`, JSON, `path=/`, `max-age` 1 year, `samesite=lax`).
The helpers `A11Y_COOKIE`, `A11Y_DEFAULT`, `parseA11y`, `serializeA11y`, `a11yAttributes`
are in `@intecion/ipal-kit` (not in `/client`). The `A11yState` type is in both entries.
| State key | Values | Attribute on `<html>` (none = default) |
|---|---|---|
| `textSize` | `0`–`3` | `data-a11y-text="1..3"` |
| `lineHeight` | `0`–`2` | `data-a11y-line="1..2"` |
| `contrast` | `'default' \| 'high' \| 'inverted'` | `data-a11y-contrast="high\|inverted"` |
| `grayscale` | boolean | `data-a11y-grayscale="on"` |
| `underlineLinks` | boolean | `data-a11y-underline="on"` |
| `readableFont` | boolean | `data-a11y-font="readable"` |
| `reduceMotion` | boolean | `data-a11y-motion="reduce"` |
| `bigCursor` | boolean | `data-a11y-cursor="big"` |
---
## 4. Separate open button (optional)
The widget has a built-in floating button. If you want to open the panel from
somewhere else (e.g. an "Accessibility" link in the footer), use the hook:
```tsx
'use client'
import { useAccessibility } from '@intecion/ipal-kit/client'
// keep the open state yourself, or extend the widget — the hook gives state/set/reset
```
---
## 5. Compliance — when accessibility is required
Accessibility (WCAG) is legally required ONLY for some sites:
- **Public bodies** (government offices, schools, institutions) — the Polish digital accessibility act
- **Large e-commerce / services** covered by the European Accessibility Act (2019/882, from 2025)
- Sites where the client requires it (company policy, public tender)
For **most commercial sites** (business card site, small company, catalog) the a11y
widget is **an option, not a duty** — add it when the client requires it, not
automatically.
When you add it: the widget by itself does NOT make the site fully accessible — it
helps the user. Full accessibility also means semantic HTML, alt texts, keyboard
navigation, baseline contrast. The widget complements, it does not replace. Do not
sell the client "we have a widget = we are WCAG compliant". See [dev/PROGRAMISTA.md](dev/PROGRAMISTA.md) §5.
## Turn off, override, extend
- **Turn off:** the module is opt-in — without `AccessibilityProvider` / `AccessibilityWidget` nothing happens
(no option in `ipalKit`, no fields in the panel).
- **Override:** the widget's `classNames` and `texts`; the whole look of the effects is project CSS.
- **Extend:** your own UI on `useAccessibility()` (`state`, `set`, `reset`); SSR helpers
`parseA11y` / `a11yAttributes` / `serializeA11y` / `A11Y_DEFAULT`. The option set (`A11yState`) currently
cannot be extended without changes in the plugin.