Code Block

Bloc de code en lecture seule, copiable, avec indicateur de langue, sur surface sombre tokenisée. Bouton copier accessible (annonce aux lecteurs d'écran). Présent sur presque chaque page du système. Read-only, copyable code block with a language indicator on a tokenized dark surface. Accessible copy button (announced to screen readers). Present on nearly every page of the system.

AperçuPreview

Ce bloc ci-dessous est un pre.code-block réel — label de langue en haut à gauche, bouton « Copier » accessible en haut à droite. The block below is a real pre.code-block — language label top-left, accessible "Copy" button top-right.

<agtc-code-block language="html" filename="exemple.html">
  <code><agtc-badge variant="success">Validé</agtc-badge></code>
</agtc-code-block>

Règles absoluesAbsolute rules

Tokens de composantComponent tokens

Token CSSRéférenceReferenceValeurValue
--agtc-component-code-block-default-backgroundprimitive.color.gray.12#202020
--agtc-component-code-block-default-textprimitive.color.gray.4#e8e8e8
--agtc-component-code-block-default-meta-textprimitive.color.gray.8#bbbbbb
--agtc-component-code-block-default-copy-backgroundprimitive.color.gray.11#646464
--agtc-component-code-block-default-copy-textprimitive.color.gray.1#fcfcfc
--agtc-component-code-block-default-border-focussemantic.color.border.focus#007a68
--agtc-component-code-block-default-font-sizesemantic.typography.label.size0.875rem
--agtc-component-code-block-default-padding-xprimitive.space.520px
--agtc-component-code-block-default-padding-yprimitive.space.416px

AccessibilitéAccessibility

ImplémentationImplementation

<!-- Composant slotté -->
<agtc-code-block language="javascript" filename="agtc-badge.js">
  <code>import { LitElement } from 'lit';</code>
</agtc-code-block>

<!-- Classe sur HTML statique (site) -->
<pre class="code-block"><code class="lang-html">&lt;agtc-badge&gt;Validé&lt;/agtc-badge&gt;</code></pre>

DOs et DON'TsDOs and DON'Ts

À faireDo

  • Indiquer la langue (language ou class="lang-…")Indicate the language (language or class="lang-…")
  • Laisser les lignes longues défiler horizontalementLet long lines scroll horizontally
  • Garder le code échappé et sélectionnableKeep code escaped and selectable

À éviterDon't

  • Un bouton copier sans aria-label ni feedback annoncéA copy button without aria-label or announced feedback
  • Attendre une coloration syntaxique — différée v1 (porte ouverte)Expecting syntax highlighting — deferred v1 (door open)
  • Des <div> stylés en code<div>s styled as code

UX Patterns Reference

Patterns approved via the ux-pattern-review workflow (ADR-036/041). Decision: CD1–CD9 all approved.

PatternSourceAppliedJustification
Semantic <pre><code> + language classDEV — copy code buttonSlot for the code
Copy button + text feedbackrobolearyCopyCopied!
Accessible copy button (aria-label, focus-visible)Sara SoueidanFixes the site's previous unlabeled, French-only button
Success announced to AT (role="status" / aria-live)Sara SoueidanPolite live region
Language indicatorDEVlanguage attribute
Horizontal scroll for long linesNN/goverflow-x:auto
Syntax highlighting (WCAG contrast)NN/g✅ (deferred)Out of v1 scope: high-contrast plain text with no dependency; API ready for future highlighting
Header (file name / title)DEVOptional filename attribute
Line numbersNN/gOut of v1 scope — visual noise; may be added later if needed
Contribuer à ce projet Contribute to this project

Ce système est ouvert aux contributions — tokens, composants, décisions architecturales, corrections d'accessibilité ou documentation. Toute amélioration est bienvenue. This system welcomes contributions — tokens, components, architectural decisions, accessibility fixes, or documentation. Every improvement counts.

Voir sur GitHub View on GitHub