Étoffer la bibliothèque : Card, Badge, formulaires avancés, feedback, navigation

Ajoute Card, Badge, Checkbox, Radio, Select, Spinner, EmptyState, Dialog,
TabBar et Toolbar au package @napps/design-system, tous construits à partir
des tokens existants (fills, labels par opacité, deux familles de matière) —
aucune valeur ad hoc introduite.
This commit is contained in:
2026-09-17 12:33:01 +02:00
parent af9f2d92ba
commit 5faf478c1e
43 changed files with 590 additions and 0 deletions
Generated Regular → Executable
View File
View File
@@ -0,0 +1,20 @@
import { HTMLAttributes, ReactNode } from 'react';
export type BadgeTone = 'neutral' | 'accent' | 'success' | 'warning' | 'error';
export interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {
tone?: BadgeTone;
children: ReactNode;
}
/**
* Jamais un signal seul : toujours accompagné d'un texte explicite (jamais
* une pastille de couleur nue) — principe vérifié dans l'audit du kit Apple.
*/
export function Badge({ tone = 'neutral', className, children, ...props }: BadgeProps) {
return (
<span className={['badge', `badge--${tone}`, className].filter(Boolean).join(' ')} {...props}>
{children}
</span>
);
}
View File
@@ -0,0 +1,14 @@
import { HTMLAttributes, ReactNode } from 'react';
export interface CardProps extends HTMLAttributes<HTMLDivElement> {
children: ReactNode;
}
/** Surface groupée standard (voir Surface pour les autres niveaux/matières). */
export function Card({ className, children, ...props }: CardProps) {
return (
<div className={['card', className].filter(Boolean).join(' ')} {...props}>
{children}
</div>
);
}
@@ -0,0 +1,26 @@
export interface CheckboxProps {
checked: boolean;
onChange: (checked: boolean) => void;
disabled?: boolean;
'aria-label': string;
}
export function Checkbox({ checked, onChange, disabled, ...props }: CheckboxProps) {
return (
<button
type="button"
role="checkbox"
aria-checked={checked}
aria-label={props['aria-label']}
disabled={disabled}
onClick={() => onChange(!checked)}
className={['checkbox', checked && 'checkbox--checked'].filter(Boolean).join(' ')}
>
{checked && (
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M4 12.5L9.5 18L20 6" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" />
</svg>
)}
</button>
);
}
@@ -0,0 +1,66 @@
import { ReactNode, useEffect } from 'react';
export type DialogActionRole = 'default' | 'cancel' | 'destructive';
export interface DialogAction {
label: string;
role?: DialogActionRole;
onClick: () => void;
}
export interface DialogProps {
open: boolean;
title: ReactNode;
message?: ReactNode;
actions: DialogAction[];
onDismiss?: () => void;
}
/**
* Verre de panneau (.material-panel) — pas la même recette que les boutons
* flottants. Rôles d'action calqués sur Alert/Action Sheet du kit : Default
* = accent plein, Cancel/None = fill-secondary + texte noir, Destructive =
* fill-secondary + texte rouge (jamais de bouton rouge plein).
*
* Implémentation volontairement minimale : pas de portail ni de focus trap.
* À renforcer avant un usage en production si l'accessibilité au clavier
* complète est requise.
*/
export function Dialog({ open, title, message, actions, onDismiss }: DialogProps) {
useEffect(() => {
if (!open || !onDismiss) return;
const handler = (event: KeyboardEvent) => {
if (event.key === 'Escape') onDismiss();
};
document.addEventListener('keydown', handler);
return () => document.removeEventListener('keydown', handler);
}, [open, onDismiss]);
if (!open) return null;
return (
<div
className="dialog-overlay"
onClick={(e) => {
if (e.target === e.currentTarget) onDismiss?.();
}}
>
<div className="dialog material-panel" role="alertdialog" aria-modal="true" aria-labelledby="napps-dialog-title">
<h2 id="napps-dialog-title" className="dialog__title">{title}</h2>
{message && <p className="dialog__message">{message}</p>}
<div className="dialog__actions">
{actions.map((action, i) => (
<button
key={i}
type="button"
className={`dialog__action dialog__action--${action.role ?? 'default'}`}
onClick={action.onClick}
>
{action.label}
</button>
))}
</div>
</div>
</div>
);
}
@@ -0,0 +1,32 @@
import { ReactNode } from 'react';
import { IconBadge } from './IconBadge';
import { Text } from './Text';
export interface EmptyStateProps {
icon?: ReactNode;
title: ReactNode;
description?: ReactNode;
action?: ReactNode;
}
/**
* Reprend le pattern "Symbol in Circle" du kit : badge circulaire teinté
* accent, titre, description, puis une action (généralement un Button
* primary) — jamais de remplissage gratuit si l'un des champs est vide.
*/
export function EmptyState({ icon, title, description, action }: EmptyStateProps) {
return (
<div className="empty-state">
{icon && <IconBadge tone="accent">{icon}</IconBadge>}
<div>
<Text variant="title3" as="p">{title}</Text>
{description && (
<Text variant="subheadline" color="secondary" as="p">
{description}
</Text>
)}
</div>
{action}
</div>
);
}
View File
View File
@@ -0,0 +1,26 @@
export interface RadioProps {
checked: boolean;
onChange: () => void;
disabled?: boolean;
'aria-label': string;
}
export function Radio({ checked, onChange, disabled, ...props }: RadioProps) {
return (
<button
type="button"
role="radio"
aria-checked={checked}
aria-label={props['aria-label']}
disabled={disabled}
onClick={onChange}
className={['radio', checked && 'radio--checked'].filter(Boolean).join(' ')}
>
{checked && (
<svg width="8" height="8" viewBox="0 0 8 8" fill="none" aria-hidden="true">
<circle cx="4" cy="4" r="4" fill="currentColor" />
</svg>
)}
</button>
);
}
View File
@@ -0,0 +1,20 @@
import { SelectHTMLAttributes, forwardRef } from 'react';
export type SelectProps = SelectHTMLAttributes<HTMLSelectElement>;
export const Select = forwardRef<HTMLSelectElement, SelectProps>(
({ className, ...props }, ref) => {
return (
<div className="select-wrapper">
<select ref={ref} className={['select', className].filter(Boolean).join(' ')} {...props} />
<span className="select-chevron" aria-hidden="true">
<svg width="10" height="10" viewBox="0 0 10 10" fill="none">
<path d="M1 3.5L5 7.5L9 3.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
</svg>
</span>
</div>
);
}
);
Select.displayName = 'Select';
@@ -0,0 +1,19 @@
import { HTMLAttributes } from 'react';
export type SpinnerSize = 'small' | 'regular' | 'large';
export interface SpinnerProps extends HTMLAttributes<HTMLSpanElement> {
size?: SpinnerSize;
'aria-label'?: string;
}
export function Spinner({ size = 'regular', className, ...props }: SpinnerProps) {
return (
<span
role="status"
aria-label={props['aria-label'] ?? 'Chargement'}
className={['spinner', `spinner--${size}`, className].filter(Boolean).join(' ')}
{...props}
/>
);
}
View File
@@ -0,0 +1,37 @@
import { ReactNode } from 'react';
export interface TabBarItem {
value: string;
label: string;
icon?: ReactNode;
}
export interface TabBarProps {
items: TabBarItem[];
value: string;
onChange: (value: string) => void;
'aria-label': string;
}
/** Barre d'onglets flottante en verre de contrôle — jamais en aplat de couleur. */
export function TabBar({ items, value, onChange, ...props }: TabBarProps) {
return (
<nav className="tab-bar material-control" aria-label={props['aria-label']}>
{items.map((item) => {
const active = item.value === value;
return (
<button
key={item.value}
type="button"
className={['tab-bar__item', active && 'tab-bar__item--active'].filter(Boolean).join(' ')}
aria-current={active ? 'page' : undefined}
onClick={() => onChange(item.value)}
>
{item.icon}
<span>{item.label}</span>
</button>
);
})}
</nav>
);
}
View File
View File
View File
@@ -0,0 +1,18 @@
import { ReactNode } from 'react';
export interface ToolbarProps {
title?: ReactNode;
leading?: ReactNode;
trailing?: ReactNode;
}
/** Barre d'outils en verre de contrôle — mêmes recettes que les boutons flottants. */
export function Toolbar({ title, leading, trailing }: ToolbarProps) {
return (
<div className="toolbar material-control">
<div className="toolbar__actions">{leading}</div>
{title && <div className="toolbar__title">{title}</div>}
<div className="toolbar__actions">{trailing}</div>
</div>
);
}
+30
View File
@@ -23,3 +23,33 @@ export type { TextProps, TextVariant, TextColor } from './components/Text';
export { Surface } from './components/Surface';
export type { SurfaceProps, SurfaceLevel, MaterialVariant } from './components/Surface';
export { Card } from './components/Card';
export type { CardProps } from './components/Card';
export { Badge } from './components/Badge';
export type { BadgeProps, BadgeTone } from './components/Badge';
export { Checkbox } from './components/Checkbox';
export type { CheckboxProps } from './components/Checkbox';
export { Radio } from './components/Radio';
export type { RadioProps } from './components/Radio';
export { Select } from './components/Select';
export type { SelectProps } from './components/Select';
export { Spinner } from './components/Spinner';
export type { SpinnerProps, SpinnerSize } from './components/Spinner';
export { EmptyState } from './components/EmptyState';
export type { EmptyStateProps } from './components/EmptyState';
export { Dialog } from './components/Dialog';
export type { DialogProps, DialogAction, DialogActionRole } from './components/Dialog';
export { TabBar } from './components/TabBar';
export type { TabBarProps, TabBarItem } from './components/TabBar';
export { Toolbar } from './components/Toolbar';
export type { ToolbarProps } from './components/Toolbar';
+141
View File
@@ -259,3 +259,144 @@
.text-secondary { color: var(--label-secondary); }
.text-tertiary { color: var(--label-tertiary); }
.text-quaternary { color: var(--label-quaternary); }
/* ============================================================
CARD — surface groupée standard, contenu libre.
============================================================ */
.card {
background: var(--bg-grouped);
border-radius: var(--radius-card-lg);
padding: 18px;
}
/* ============================================================
BADGE — pastille de statut, jamais seul signal (toujours du texte).
============================================================ */
.badge {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 3px 9px;
border-radius: 8px;
font-size: var(--text-caption1-size);
font-weight: 600;
white-space: nowrap;
}
.badge--neutral { background: var(--fill-tertiary); color: var(--label-primary); }
.badge--accent { background: color-mix(in srgb, var(--napps-accent) 12%, transparent); color: var(--napps-accent); }
.badge--success { background: color-mix(in srgb, var(--napps-success) 15%, transparent); color: var(--napps-success); }
.badge--warning { background: color-mix(in srgb, var(--napps-warning) 15%, transparent); color: var(--napps-warning); }
.badge--error { background: color-mix(in srgb, var(--napps-error) 15%, transparent); color: var(--napps-error); }
/* ============================================================
FORMULAIRES AVANCÉS — checkbox, radio, select.
Même échelle de fill que le reste (fill-tertiary au repos).
============================================================ */
.checkbox, .radio {
width: 22px; height: 22px;
flex-shrink: 0;
display: inline-flex; align-items: center; justify-content: center;
border: none; cursor: pointer; padding: 0;
background: var(--fill-tertiary);
color: transparent;
}
.checkbox { border-radius: 6px; }
.radio { border-radius: var(--radius-pill); }
.checkbox--checked, .radio--checked { background: var(--napps-accent); color: #FFFFFF; }
.checkbox:disabled, .radio:disabled { opacity: 0.5; cursor: default; }
.select-wrapper { position: relative; }
.select {
appearance: none; -webkit-appearance: none;
width: 100%;
border: none;
border-top: 1px solid var(--separator);
background: transparent;
padding: 16px 32px 16px 0;
font: var(--text-body-weight) var(--text-body-size)/var(--text-body-line) var(--font-family);
color: var(--label-primary);
cursor: pointer;
}
.select-chevron {
position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
pointer-events: none;
color: var(--label-tertiary);
font-size: 12px;
}
/* ============================================================
FEEDBACK — spinner, empty state, dialog (verre de panneau).
============================================================ */
.spinner {
border-radius: var(--radius-pill);
border: 2px solid var(--fill-tertiary);
border-top-color: var(--label-secondary);
animation: napps-spin 0.7s linear infinite;
display: inline-block;
}
.spinner--small { width: 14px; height: 14px; border-width: 2px; }
.spinner--regular { width: 20px; height: 20px; border-width: 2px; }
.spinner--large { width: 35px; height: 35px; border-width: 3px; }
@keyframes napps-spin { to { transform: rotate(360deg); } }
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
gap: 12px;
padding: 48px 24px;
}
.dialog-overlay {
position: fixed; inset: 0;
background: rgba(0, 0, 0, 0.4);
display: flex; align-items: center; justify-content: center;
padding: 20px;
z-index: 1000;
}
.dialog {
width: 100%; max-width: 270px;
border-radius: 20px;
padding: 14px;
display: flex; flex-direction: column; gap: 12px;
text-align: center;
}
.dialog__title { font: var(--text-headline-weight) var(--text-headline-size)/var(--text-headline-line) var(--font-family); color: var(--label-primary); margin: 0; }
.dialog__message { font: var(--text-body-weight) var(--text-body-size)/var(--text-body-line) var(--font-family); color: var(--label-primary); margin: 0; }
.dialog__actions { display: flex; flex-direction: column; gap: 8px; }
.dialog__action {
border: none;
border-radius: var(--radius-pill);
min-height: var(--tap-target-min);
font: 600 var(--text-body-size)/var(--text-body-line) var(--font-family);
cursor: pointer;
}
.dialog__action--default { background: var(--napps-accent); color: #FFFFFF; }
.dialog__action--cancel { background: var(--fill-secondary); color: var(--label-primary); }
.dialog__action--destructive { background: var(--fill-secondary); color: var(--napps-error); }
/* ============================================================
NAVIGATION — tab bar flottante et toolbar, toutes deux en
"verre de contrôle" (.material-control), jamais en aplat.
============================================================ */
.tab-bar { display: inline-flex; gap: 4px; padding: 6px; }
.tab-bar__item {
display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
min-width: 56px; min-height: var(--tap-target-min);
border-radius: var(--radius-pill);
font-size: var(--text-caption2-size);
font-weight: 600;
color: var(--label-secondary);
background: none; border: none; cursor: pointer;
}
.tab-bar__item--active { color: var(--napps-accent); }
.toolbar {
display: flex; align-items: center; justify-content: space-between; gap: 12px;
padding: 0 6px 0 16px;
min-height: 52px;
border-radius: var(--radius-pill);
}
.toolbar__title { font: var(--text-headline-weight) var(--text-headline-size)/var(--text-headline-line) var(--font-family); color: var(--label-primary); }
.toolbar__actions { display: flex; align-items: center; gap: 4px; }
View File
View File