@sia-ui/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +51 -0
- package/dist/diff.mjs +91 -0
- package/dist/index.js +325 -0
- package/dist/lifecycle.mjs +242 -0
- package/dist/lock.mjs +92 -0
- package/dist/registry/package/components/Accordion/index.tsx +172 -0
- package/dist/registry/package/components/Accordion/styles.css +97 -0
- package/dist/registry/package/components/Alert/index.tsx +31 -0
- package/dist/registry/package/components/Alert/styles.css +12 -0
- package/dist/registry/package/components/AmountDisplay/index.tsx +11 -0
- package/dist/registry/package/components/AmountDisplay/styles.css +9 -0
- package/dist/registry/package/components/AppShell/index.tsx +6 -0
- package/dist/registry/package/components/AppShell/styles.css +7 -0
- package/dist/registry/package/components/AspectRatio/index.tsx +29 -0
- package/dist/registry/package/components/AspectRatio/styles.css +15 -0
- package/dist/registry/package/components/AsyncState/index.tsx +22 -0
- package/dist/registry/package/components/AsyncState/styles.css +1 -0
- package/dist/registry/package/components/AuditMeta/index.tsx +44 -0
- package/dist/registry/package/components/AuditMeta/styles.css +12 -0
- package/dist/registry/package/components/AuthLayout/index.tsx +39 -0
- package/dist/registry/package/components/AuthLayout/styles.css +6 -0
- package/dist/registry/package/components/Autocomplete/index.tsx +8 -0
- package/dist/registry/package/components/Avatar/index.tsx +23 -0
- package/dist/registry/package/components/Avatar/styles.css +5 -0
- package/dist/registry/package/components/Badge/index.tsx +62 -0
- package/dist/registry/package/components/Badge/styles.css +26 -0
- package/dist/registry/package/components/Breadcrumb/index.tsx +131 -0
- package/dist/registry/package/components/Breadcrumb/styles.css +76 -0
- package/dist/registry/package/components/Button/index.tsx +91 -0
- package/dist/registry/package/components/Button/styles.css +111 -0
- package/dist/registry/package/components/Calendar/index.tsx +192 -0
- package/dist/registry/package/components/Card/index.tsx +8 -0
- package/dist/registry/package/components/Card/styles.css +4 -0
- package/dist/registry/package/components/Chart/index.tsx +437 -0
- package/dist/registry/package/components/Chart/styles.css +182 -0
- package/dist/registry/package/components/Checkbox/index.tsx +193 -0
- package/dist/registry/package/components/Checkbox/styles.css +39 -0
- package/dist/registry/package/components/ColorPicker/index.tsx +6 -0
- package/dist/registry/package/components/ColorPicker/styles.css +2 -0
- package/dist/registry/package/components/CommandPalette/index.tsx +7 -0
- package/dist/registry/package/components/CommandPalette/styles.css +8 -0
- package/dist/registry/package/components/ConfirmDialog/index.tsx +24 -0
- package/dist/registry/package/components/Container/index.tsx +11 -0
- package/dist/registry/package/components/Container/styles.css +1 -0
- package/dist/registry/package/components/Countdown/index.tsx +3 -0
- package/dist/registry/package/components/CrudPage/index.tsx +9 -0
- package/dist/registry/package/components/CrudPage/styles.css +1 -0
- package/dist/registry/package/components/CurrencyInput/index.tsx +15 -0
- package/dist/registry/package/components/CurrencyInput/styles.css +1 -0
- package/dist/registry/package/components/DataTable/index.tsx +240 -0
- package/dist/registry/package/components/DataTable/styles.css +98 -0
- package/dist/registry/package/components/DatePicker/index.tsx +102 -0
- package/dist/registry/package/components/DateRangeFilter/index.tsx +8 -0
- package/dist/registry/package/components/DateRangeFilter/styles.css +4 -0
- package/dist/registry/package/components/DateRangePicker/index.tsx +36 -0
- package/dist/registry/package/components/DateTimePicker/index.tsx +32 -0
- package/dist/registry/package/components/Descriptions/index.tsx +7 -0
- package/dist/registry/package/components/Descriptions/styles.css +8 -0
- package/dist/registry/package/components/Divider/index.tsx +12 -0
- package/dist/registry/package/components/Divider/styles.css +3 -0
- package/dist/registry/package/components/Drawer/context.ts +14 -0
- package/dist/registry/package/components/Drawer/index.tsx +209 -0
- package/dist/registry/package/components/Drawer/styles.css +151 -0
- package/dist/registry/package/components/DropdownMenu/index.tsx +350 -0
- package/dist/registry/package/components/DropdownMenu/styles.css +100 -0
- package/dist/registry/package/components/DurationDisplay/index.tsx +3 -0
- package/dist/registry/package/components/EmptyState/index.tsx +23 -0
- package/dist/registry/package/components/EmptyState/styles.css +6 -0
- package/dist/registry/package/components/EntityMeta/index.tsx +65 -0
- package/dist/registry/package/components/EntityMeta/styles.css +9 -0
- package/dist/registry/package/components/ErrorState/index.tsx +30 -0
- package/dist/registry/package/components/ErrorState/styles.css +6 -0
- package/dist/registry/package/components/EventCalendar/index.tsx +8 -0
- package/dist/registry/package/components/EventCalendar/styles.css +8 -0
- package/dist/registry/package/components/Field/index.tsx +664 -0
- package/dist/registry/package/components/Field/styles.css +14 -0
- package/dist/registry/package/components/FileUpload/index.tsx +68 -0
- package/dist/registry/package/components/FileUpload/styles.css +4 -0
- package/dist/registry/package/components/FiltersBar/index.tsx +20 -0
- package/dist/registry/package/components/FiltersBar/styles.css +6 -0
- package/dist/registry/package/components/Form/index.tsx +211 -0
- package/dist/registry/package/components/Form/styles.css +80 -0
- package/dist/registry/package/components/FormField/index.tsx +2 -0
- package/dist/registry/package/components/HoverCard/index.tsx +121 -0
- package/dist/registry/package/components/HoverCard/styles.css +26 -0
- package/dist/registry/package/components/IconButton/index.tsx +27 -0
- package/dist/registry/package/components/IconButton/styles.css +7 -0
- package/dist/registry/package/components/Icons/index.tsx +185 -0
- package/dist/registry/package/components/ImageUpload/index.tsx +6 -0
- package/dist/registry/package/components/ImageUpload/styles.css +4 -0
- package/dist/registry/package/components/Input/index.tsx +103 -0
- package/dist/registry/package/components/Input/styles.css +8 -0
- package/dist/registry/package/components/InputNumber/index.tsx +196 -0
- package/dist/registry/package/components/InputNumber/styles.css +54 -0
- package/dist/registry/package/components/JsonEditor/index.tsx +6 -0
- package/dist/registry/package/components/JsonEditor/styles.css +2 -0
- package/dist/registry/package/components/KpiGrid/index.tsx +11 -0
- package/dist/registry/package/components/KpiGrid/styles.css +5 -0
- package/dist/registry/package/components/Label/index.tsx +43 -0
- package/dist/registry/package/components/Label/styles.css +25 -0
- package/dist/registry/package/components/MarkdownEditor/index.tsx +5 -0
- package/dist/registry/package/components/MiniCalendar/index.tsx +3 -0
- package/dist/registry/package/components/Modal/index.tsx +104 -0
- package/dist/registry/package/components/Modal/styles.css +20 -0
- package/dist/registry/package/components/MonthPicker/index.tsx +5 -0
- package/dist/registry/package/components/MultiSelect/index.tsx +133 -0
- package/dist/registry/package/components/MultiSelect/styles.css +3 -0
- package/dist/registry/package/components/OtpInput/index.tsx +5 -0
- package/dist/registry/package/components/OtpInput/styles.css +2 -0
- package/dist/registry/package/components/Overlay/index.tsx +140 -0
- package/dist/registry/package/components/Overlay/styles.css +1 -0
- package/dist/registry/package/components/PageHeader/index.tsx +24 -0
- package/dist/registry/package/components/PageHeader/styles.css +5 -0
- package/dist/registry/package/components/Pagination/index.tsx +155 -0
- package/dist/registry/package/components/Pagination/styles.css +103 -0
- package/dist/registry/package/components/PasswordInput/index.tsx +125 -0
- package/dist/registry/package/components/PasswordInput/styles.css +58 -0
- package/dist/registry/package/components/PermissionGate/index.tsx +3 -0
- package/dist/registry/package/components/PhoneInput/index.tsx +189 -0
- package/dist/registry/package/components/PhoneInput/styles.css +35 -0
- package/dist/registry/package/components/Popover/index.tsx +12 -0
- package/dist/registry/package/components/Popover/styles.css +12 -0
- package/dist/registry/package/components/Progress/index.tsx +149 -0
- package/dist/registry/package/components/Progress/styles.css +101 -0
- package/dist/registry/package/components/QrCode/index.tsx +6 -0
- package/dist/registry/package/components/QrCode/styles.css +5 -0
- package/dist/registry/package/components/RadioGroup/index.tsx +29 -0
- package/dist/registry/package/components/RadioGroup/styles.css +20 -0
- package/dist/registry/package/components/Rating/index.tsx +82 -0
- package/dist/registry/package/components/Rating/styles.css +41 -0
- package/dist/registry/package/components/ReferenceSelect/index.tsx +7 -0
- package/dist/registry/package/components/ReferenceSelect/styles.css +2 -0
- package/dist/registry/package/components/RelativeTime/index.tsx +22 -0
- package/dist/registry/package/components/RelativeTime/styles.css +1 -0
- package/dist/registry/package/components/RequireSession/index.tsx +127 -0
- package/dist/registry/package/components/RequireSession/styles.css +13 -0
- package/dist/registry/package/components/ResizablePanel/index.tsx +6 -0
- package/dist/registry/package/components/ResizablePanel/styles.css +5 -0
- package/dist/registry/package/components/RichTextEditor/index.tsx +5 -0
- package/dist/registry/package/components/RichTextEditor/styles.css +2 -0
- package/dist/registry/package/components/ScrollArea/index.tsx +114 -0
- package/dist/registry/package/components/ScrollArea/styles.css +74 -0
- package/dist/registry/package/components/SearchInput/index.tsx +121 -0
- package/dist/registry/package/components/SearchInput/styles.css +6 -0
- package/dist/registry/package/components/Select/index.tsx +324 -0
- package/dist/registry/package/components/Select/styles.css +58 -0
- package/dist/registry/package/components/Sidebar/index.tsx +232 -0
- package/dist/registry/package/components/Sidebar/styles.css +140 -0
- package/dist/registry/package/components/Skeleton/index.tsx +21 -0
- package/dist/registry/package/components/Skeleton/styles.css +2 -0
- package/dist/registry/package/components/Slider/index.tsx +193 -0
- package/dist/registry/package/components/Slider/styles.css +53 -0
- package/dist/registry/package/components/Spinner/index.tsx +28 -0
- package/dist/registry/package/components/Spinner/styles.css +8 -0
- package/dist/registry/package/components/StatCard/index.tsx +15 -0
- package/dist/registry/package/components/StatCard/styles.css +3 -0
- package/dist/registry/package/components/Statistic/index.tsx +23 -0
- package/dist/registry/package/components/Statistic/styles.css +6 -0
- package/dist/registry/package/components/Steps/index.tsx +108 -0
- package/dist/registry/package/components/Steps/styles.css +138 -0
- package/dist/registry/package/components/Switch/index.tsx +46 -0
- package/dist/registry/package/components/Switch/styles.css +26 -0
- package/dist/registry/package/components/Tabs/index.tsx +44 -0
- package/dist/registry/package/components/Tabs/styles.css +41 -0
- package/dist/registry/package/components/TagsInput/index.tsx +6 -0
- package/dist/registry/package/components/TagsInput/styles.css +2 -0
- package/dist/registry/package/components/Textarea/index.tsx +21 -0
- package/dist/registry/package/components/Textarea/styles.css +7 -0
- package/dist/registry/package/components/TimePicker/index.tsx +76 -0
- package/dist/registry/package/components/TimePicker/styles.css +13 -0
- package/dist/registry/package/components/TimeRangePicker/index.tsx +32 -0
- package/dist/registry/package/components/TimeRangePicker/styles.css +1 -0
- package/dist/registry/package/components/Timeline/index.tsx +8 -0
- package/dist/registry/package/components/Timeline/styles.css +12 -0
- package/dist/registry/package/components/Timer/index.tsx +9 -0
- package/dist/registry/package/components/Toast/index.tsx +426 -0
- package/dist/registry/package/components/Toast/styles.css +175 -0
- package/dist/registry/package/components/Toggle/index.tsx +181 -0
- package/dist/registry/package/components/Toggle/styles.css +124 -0
- package/dist/registry/package/components/Tooltip/index.tsx +163 -0
- package/dist/registry/package/components/Tooltip/styles.css +57 -0
- package/dist/registry/package/components/Tour/index.tsx +8 -0
- package/dist/registry/package/components/Tour/styles.css +6 -0
- package/dist/registry/package/components/Transfer/index.tsx +7 -0
- package/dist/registry/package/components/Transfer/styles.css +6 -0
- package/dist/registry/package/components/Tree/index.tsx +8 -0
- package/dist/registry/package/components/Tree/styles.css +6 -0
- package/dist/registry/package/components/TreeSelect/index.tsx +10 -0
- package/dist/registry/package/components/TreeSelect/styles.css +3 -0
- package/dist/registry/package/components/Typography/index.tsx +27 -0
- package/dist/registry/package/components/Typography/styles.css +16 -0
- package/dist/registry/package/components/UnsavedChangesGuard/index.tsx +4 -0
- package/dist/registry/package/components/WeekPicker/index.tsx +5 -0
- package/dist/registry/package/components/YearPicker/index.tsx +3 -0
- package/dist/registry/package/lib/form-adapter-rhf.tsx +141 -0
- package/dist/registry/registry.json +1780 -0
- package/dist/registry/styles/sia-ui.css +361 -0
- package/dist/source.mjs +93 -0
- package/package.json +55 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type HTMLAttributes } from "react";
|
|
2
|
+
import { cn } from "@sia-ui/utils";
|
|
3
|
+
import type { ComponentTone } from "@sia-ui/tokens";
|
|
4
|
+
import { useComponentDefaults } from "@sia-ui/headless";
|
|
5
|
+
import "./styles.css";
|
|
6
|
+
|
|
7
|
+
export interface SpinnerProps extends HTMLAttributes<HTMLSpanElement> {
|
|
8
|
+
label?: string;
|
|
9
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl";
|
|
10
|
+
variant?: "dots" | "ring" | "double-ring";
|
|
11
|
+
tone?: ComponentTone | "current";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function Spinner({ label: labelProp, size: sizeProp, variant: variantProp, tone: toneProp, className, ...props }: SpinnerProps) {
|
|
15
|
+
const defaults = useComponentDefaults<SpinnerProps>("spinner");
|
|
16
|
+
const label = labelProp ?? defaults.label ?? "Chargement";
|
|
17
|
+
const size = sizeProp ?? defaults.size ?? "md";
|
|
18
|
+
const variant = variantProp ?? defaults.variant ?? "ring";
|
|
19
|
+
const tone = toneProp ?? defaults.tone ?? "current";
|
|
20
|
+
return (
|
|
21
|
+
<span className={cn("sia-spinner-wrap", `sia-spinner-wrap--${tone}`, className)} role="status" {...props}>
|
|
22
|
+
<span className={cn("sia-spinner", `sia-spinner--${size}`, `sia-spinner--${variant}`)} aria-hidden="true">
|
|
23
|
+
{variant === "dots" && <span />}
|
|
24
|
+
</span>
|
|
25
|
+
<span className="sia-visually-hidden">{label}</span>
|
|
26
|
+
</span>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
.sia-spinner-wrap { display:inline-flex; align-items:center; justify-content:center; }
|
|
2
|
+
.sia-spinner-wrap--current { color:currentColor; }
|
|
3
|
+
.sia-spinner-wrap--primary { color:var(--sia-primary); }
|
|
4
|
+
.sia-spinner-wrap--neutral { color:var(--sia-muted); }
|
|
5
|
+
.sia-spinner-wrap--info { color:var(--sia-primary); }
|
|
6
|
+
.sia-spinner-wrap--success { color:var(--sia-success); }
|
|
7
|
+
.sia-spinner-wrap--warning { color:var(--sia-warning); }
|
|
8
|
+
.sia-spinner-wrap--danger { color:var(--sia-danger); }
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { cn } from "@sia-ui/utils";
|
|
3
|
+
import { Card, CardBody } from "../Card";
|
|
4
|
+
import { Statistic, type StatisticProps } from "../Statistic";
|
|
5
|
+
import "./styles.css";
|
|
6
|
+
|
|
7
|
+
export interface StatCardProps extends StatisticProps {
|
|
8
|
+
icon?: ReactNode;
|
|
9
|
+
description?: ReactNode;
|
|
10
|
+
action?: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function StatCard({ icon, description, action, className, ...statisticProps }: StatCardProps) {
|
|
14
|
+
return <Card className={cn("sia-stat-card", className)}><CardBody><div className="sia-stat-card__top">{icon && <span className="sia-stat-card__icon" aria-hidden="true">{icon}</span>}{action}</div><Statistic {...statisticProps} />{description && <div className="sia-stat-card__description">{description}</div>}</CardBody></Card>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
.sia-stat-card__top { display:flex; align-items:center; justify-content:space-between; min-height:2rem; margin-bottom:.75rem; }
|
|
2
|
+
.sia-stat-card__icon { display:grid; place-items:center; width:2rem; height:2rem; border-radius:.5rem; color:var(--sia-primary); background:color-mix(in srgb,var(--sia-primary) 10%,transparent); }
|
|
3
|
+
.sia-stat-card__description { margin-top:.75rem; color:var(--sia-muted); font-size:.82rem; line-height:1.45; }
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { cn, formatCurrency } from "@sia-ui/utils";
|
|
3
|
+
import "./styles.css";
|
|
4
|
+
|
|
5
|
+
export interface StatisticProps {
|
|
6
|
+
value: number;
|
|
7
|
+
label?: ReactNode;
|
|
8
|
+
format?: "number" | "currency" | "percent";
|
|
9
|
+
locale?: string;
|
|
10
|
+
currency?: string;
|
|
11
|
+
precision?: number;
|
|
12
|
+
prefix?: ReactNode;
|
|
13
|
+
suffix?: ReactNode;
|
|
14
|
+
trend?: number;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function Statistic({ value, label, format = "number", locale = "fr-FR", currency = "XAF", precision, prefix, suffix, trend, className }: StatisticProps) {
|
|
19
|
+
const formatted = format === "currency"
|
|
20
|
+
? formatCurrency(value, { locale, currency, ...(precision !== undefined ? { minimumFractionDigits: precision, maximumFractionDigits: precision } : {}) })
|
|
21
|
+
: new Intl.NumberFormat(locale, format === "percent" ? { style: "percent", ...(precision !== undefined ? { minimumFractionDigits: precision, maximumFractionDigits: precision } : {}) } : { ...(precision !== undefined ? { minimumFractionDigits: precision, maximumFractionDigits: precision } : {}) }).format(value);
|
|
22
|
+
return <div className={cn("sia-statistic", className)}>{label && <span className="sia-statistic__label">{label}</span>}<div className="sia-statistic__value">{prefix}<span>{formatted}</span>{suffix}</div>{trend !== undefined && <span className={cn("sia-statistic__trend", trend > 0 && "sia-statistic__trend--up", trend < 0 && "sia-statistic__trend--down")}>{trend > 0 ? "+" : ""}{new Intl.NumberFormat(locale, { style:"percent", maximumFractionDigits:1 }).format(trend)}</span>}</div>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
.sia-statistic { display:grid; gap:.35rem; }
|
|
2
|
+
.sia-statistic__label { color:var(--sia-muted); font-size:.82rem; font-weight:650; }
|
|
3
|
+
.sia-statistic__value { display:flex; align-items:baseline; gap:.3rem; color:var(--sia-foreground); font-size:clamp(1.5rem,3vw,2rem); font-weight:780; letter-spacing:-.03em; }
|
|
4
|
+
.sia-statistic__trend { width:max-content; color:var(--sia-muted); font-size:.8rem; font-weight:700; }
|
|
5
|
+
.sia-statistic__trend--up { color:var(--sia-success); }
|
|
6
|
+
.sia-statistic__trend--down { color:var(--sia-danger); }
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { cn } from "@sia-ui/utils";
|
|
3
|
+
import { AlertCircleIcon, CheckIcon } from "../Icons";
|
|
4
|
+
import "./styles.css";
|
|
5
|
+
|
|
6
|
+
export type StepStatus = "done" | "current" | "upcoming" | "error";
|
|
7
|
+
|
|
8
|
+
export interface StepItem {
|
|
9
|
+
key: string;
|
|
10
|
+
title: ReactNode;
|
|
11
|
+
description?: ReactNode;
|
|
12
|
+
icon?: ReactNode;
|
|
13
|
+
/** Forcé au besoin; sinon déduit de `current`. */
|
|
14
|
+
status?: StepStatus;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface StepsProps {
|
|
19
|
+
items: StepItem[];
|
|
20
|
+
/** Index de l'étape en cours. Ce qui précède est fait, ce qui suit à venir. */
|
|
21
|
+
current?: number;
|
|
22
|
+
orientation?: "horizontal" | "vertical";
|
|
23
|
+
size?: "sm" | "md";
|
|
24
|
+
/** Rend les étapes cliquables — pour revenir en arrière dans un tunnel. */
|
|
25
|
+
onStepClick?: (item: StepItem, index: number) => void;
|
|
26
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function statusOf(item: StepItem, index: number, current: number): StepStatus {
|
|
30
|
+
if (item.status) return item.status;
|
|
31
|
+
if (index < current) return "done";
|
|
32
|
+
if (index === current) return "current";
|
|
33
|
+
return "upcoming";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Une progression en étapes.
|
|
38
|
+
*
|
|
39
|
+
* Le trait entre deux étapes se remplit plutôt que de changer de couleur d'un
|
|
40
|
+
* coup : c'est ce qui donne le sens de la marche, vers l'avant.
|
|
41
|
+
*/
|
|
42
|
+
export function Steps({
|
|
43
|
+
items,
|
|
44
|
+
current = 0,
|
|
45
|
+
orientation = "horizontal",
|
|
46
|
+
size = "md",
|
|
47
|
+
onStepClick,
|
|
48
|
+
className,
|
|
49
|
+
}: StepsProps) {
|
|
50
|
+
return (
|
|
51
|
+
<ol
|
|
52
|
+
className={cn(
|
|
53
|
+
"sia-steps",
|
|
54
|
+
`sia-steps--${orientation}`,
|
|
55
|
+
`sia-steps--${size}`,
|
|
56
|
+
className,
|
|
57
|
+
)}
|
|
58
|
+
>
|
|
59
|
+
{items.map((item, index) => {
|
|
60
|
+
const status = statusOf(item, index, current);
|
|
61
|
+
const clickable = Boolean(onStepClick) && !item.disabled;
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<li
|
|
65
|
+
key={item.key}
|
|
66
|
+
className="sia-steps__item"
|
|
67
|
+
data-status={status}
|
|
68
|
+
{...(status === "current" ? { "aria-current": "step" as const } : {})}
|
|
69
|
+
>
|
|
70
|
+
<div className="sia-steps__marker">
|
|
71
|
+
<span className="sia-steps__bullet">
|
|
72
|
+
{status === "done" ? (
|
|
73
|
+
<CheckIcon />
|
|
74
|
+
) : status === "error" ? (
|
|
75
|
+
<AlertCircleIcon />
|
|
76
|
+
) : (
|
|
77
|
+
(item.icon ?? <span className="sia-steps__number">{index + 1}</span>)
|
|
78
|
+
)}
|
|
79
|
+
</span>
|
|
80
|
+
{index < items.length - 1 && (
|
|
81
|
+
<span className="sia-steps__connector" aria-hidden="true">
|
|
82
|
+
<span className="sia-steps__connector-fill" />
|
|
83
|
+
</span>
|
|
84
|
+
)}
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
<div className="sia-steps__body">
|
|
88
|
+
{clickable ? (
|
|
89
|
+
<button
|
|
90
|
+
type="button"
|
|
91
|
+
className="sia-steps__title sia-steps__title--button"
|
|
92
|
+
onClick={() => onStepClick?.(item, index)}
|
|
93
|
+
>
|
|
94
|
+
{item.title}
|
|
95
|
+
</button>
|
|
96
|
+
) : (
|
|
97
|
+
<span className="sia-steps__title">{item.title}</span>
|
|
98
|
+
)}
|
|
99
|
+
{item.description && (
|
|
100
|
+
<span className="sia-steps__description">{item.description}</span>
|
|
101
|
+
)}
|
|
102
|
+
</div>
|
|
103
|
+
</li>
|
|
104
|
+
);
|
|
105
|
+
})}
|
|
106
|
+
</ol>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
.sia-steps {
|
|
2
|
+
--sia-step-size: 2rem;
|
|
3
|
+
display: flex;
|
|
4
|
+
margin: 0;
|
|
5
|
+
padding: 0;
|
|
6
|
+
list-style: none;
|
|
7
|
+
counter-reset: sia-step;
|
|
8
|
+
}
|
|
9
|
+
.sia-steps--sm { --sia-step-size: 1.5rem; font-size: .8rem; }
|
|
10
|
+
|
|
11
|
+
.sia-steps__item { display: flex; min-width: 0; }
|
|
12
|
+
.sia-steps__marker { position: relative; display: flex; flex: none; }
|
|
13
|
+
|
|
14
|
+
.sia-steps__bullet {
|
|
15
|
+
position: relative;
|
|
16
|
+
display: grid;
|
|
17
|
+
place-items: center;
|
|
18
|
+
flex: none;
|
|
19
|
+
width: var(--sia-step-size);
|
|
20
|
+
height: var(--sia-step-size);
|
|
21
|
+
border: 2px solid var(--sia-border-strong);
|
|
22
|
+
border-radius: 999px;
|
|
23
|
+
background: var(--sia-surface-raised);
|
|
24
|
+
color: var(--sia-muted);
|
|
25
|
+
font-size: .8rem;
|
|
26
|
+
font-weight: 600;
|
|
27
|
+
transition:
|
|
28
|
+
border-color var(--sia-duration-base) var(--sia-easing-standard),
|
|
29
|
+
background-color var(--sia-duration-base) var(--sia-easing-standard),
|
|
30
|
+
color var(--sia-duration-base) var(--sia-easing-standard);
|
|
31
|
+
}
|
|
32
|
+
.sia-steps__number { font-variant-numeric: tabular-nums; line-height: 1; }
|
|
33
|
+
|
|
34
|
+
.sia-steps__item[data-status="done"] .sia-steps__bullet {
|
|
35
|
+
border-color: var(--sia-success);
|
|
36
|
+
background: var(--sia-success);
|
|
37
|
+
color: #fff;
|
|
38
|
+
/* La coche tombe avec un léger rebond quand l'étape bascule. */
|
|
39
|
+
animation: sia-step-done var(--sia-duration-slow) var(--sia-easing-spring);
|
|
40
|
+
}
|
|
41
|
+
@keyframes sia-step-done {
|
|
42
|
+
0% { transform: scale(.7); }
|
|
43
|
+
60% { transform: scale(1.12); }
|
|
44
|
+
100% { transform: scale(1); }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.sia-steps__item[data-status="current"] .sia-steps__bullet {
|
|
48
|
+
border-color: var(--sia-primary);
|
|
49
|
+
color: var(--sia-primary);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* Le halo de l'étape en cours : lent, discret, il ne fait que signaler « on
|
|
53
|
+
est ici ». Il s'arrête sous préférence de mouvement réduit, comme le reste. */
|
|
54
|
+
.sia-steps__item[data-status="current"] .sia-steps__bullet::after {
|
|
55
|
+
content: "";
|
|
56
|
+
position: absolute;
|
|
57
|
+
width: var(--sia-step-size);
|
|
58
|
+
height: var(--sia-step-size);
|
|
59
|
+
border-radius: 999px;
|
|
60
|
+
border: 2px solid var(--sia-primary);
|
|
61
|
+
animation: sia-step-pulse 2s var(--sia-easing-standard) infinite;
|
|
62
|
+
}
|
|
63
|
+
@keyframes sia-step-pulse {
|
|
64
|
+
0% { opacity: .5; transform: scale(1); }
|
|
65
|
+
70%, 100% { opacity: 0; transform: scale(1.5); }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.sia-steps__item[data-status="error"] .sia-steps__bullet {
|
|
69
|
+
border-color: var(--sia-danger);
|
|
70
|
+
background: var(--sia-danger);
|
|
71
|
+
color: #fff;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.sia-steps__connector { position: relative; overflow: hidden; background: var(--sia-border); }
|
|
75
|
+
.sia-steps__connector-fill {
|
|
76
|
+
position: absolute;
|
|
77
|
+
inset: 0;
|
|
78
|
+
transform-origin: left;
|
|
79
|
+
background: var(--sia-success);
|
|
80
|
+
transform: scaleX(0);
|
|
81
|
+
transition: transform var(--sia-duration-slow) var(--sia-easing-standard);
|
|
82
|
+
}
|
|
83
|
+
.sia-steps__item[data-status="done"] .sia-steps__connector-fill { transform: scaleX(1); }
|
|
84
|
+
|
|
85
|
+
.sia-steps__body { display: grid; gap: .15rem; min-width: 0; }
|
|
86
|
+
.sia-steps__title { color: var(--sia-foreground); font-weight: 600; font-size: .875rem; }
|
|
87
|
+
.sia-steps__item[data-status="upcoming"] .sia-steps__title { color: var(--sia-muted); font-weight: 500; }
|
|
88
|
+
.sia-steps__item[data-status="error"] .sia-steps__title { color: var(--sia-danger); }
|
|
89
|
+
.sia-steps__description { color: var(--sia-muted); font-size: .8rem; line-height: 1.45; }
|
|
90
|
+
|
|
91
|
+
.sia-steps__title--button {
|
|
92
|
+
padding: 0;
|
|
93
|
+
border: 0;
|
|
94
|
+
background: transparent;
|
|
95
|
+
color: inherit;
|
|
96
|
+
font: inherit;
|
|
97
|
+
text-align: left;
|
|
98
|
+
cursor: pointer;
|
|
99
|
+
transition: color var(--sia-duration-fast) var(--sia-easing-standard);
|
|
100
|
+
}
|
|
101
|
+
.sia-steps__title--button:hover { color: var(--sia-primary); }
|
|
102
|
+
|
|
103
|
+
/* ── Horizontal ────────────────────────────────────────────────────────── */
|
|
104
|
+
|
|
105
|
+
.sia-steps--horizontal { align-items: flex-start; gap: 0; }
|
|
106
|
+
.sia-steps--horizontal .sia-steps__item { flex: 1; flex-direction: column; gap: .5rem; }
|
|
107
|
+
.sia-steps--horizontal .sia-steps__marker { align-items: center; width: 100%; }
|
|
108
|
+
.sia-steps--horizontal .sia-steps__connector { flex: 1; height: 2px; margin: 0 .5rem; }
|
|
109
|
+
.sia-steps--horizontal .sia-steps__item:last-child { flex: none; }
|
|
110
|
+
.sia-steps--horizontal .sia-steps__body { padding-right: 1rem; }
|
|
111
|
+
|
|
112
|
+
/* ── Vertical ──────────────────────────────────────────────────────────── */
|
|
113
|
+
|
|
114
|
+
.sia-steps--vertical { flex-direction: column; }
|
|
115
|
+
.sia-steps--vertical .sia-steps__item { gap: .875rem; padding-bottom: 1.25rem; }
|
|
116
|
+
.sia-steps--vertical .sia-steps__item:last-child { padding-bottom: 0; }
|
|
117
|
+
.sia-steps--vertical .sia-steps__marker { flex-direction: column; align-items: center; }
|
|
118
|
+
.sia-steps--vertical .sia-steps__connector {
|
|
119
|
+
flex: 1;
|
|
120
|
+
width: 2px;
|
|
121
|
+
min-height: 1rem;
|
|
122
|
+
margin: .375rem 0 -1.25rem;
|
|
123
|
+
}
|
|
124
|
+
.sia-steps--vertical .sia-steps__connector-fill { transform-origin: top; transform: scaleY(0); }
|
|
125
|
+
.sia-steps--vertical .sia-steps__item[data-status="done"] .sia-steps__connector-fill { transform: scaleY(1); }
|
|
126
|
+
.sia-steps--vertical .sia-steps__body { padding-top: .25rem; }
|
|
127
|
+
|
|
128
|
+
/* Sous 640 px l'horizontal ne tient plus : cinq étapes côte à côte tronquent
|
|
129
|
+
tous les libellés. Il bascule en vertical, qui n'a pas cette limite. */
|
|
130
|
+
@media (max-width: 640px) {
|
|
131
|
+
.sia-steps--horizontal { flex-direction: column; }
|
|
132
|
+
.sia-steps--horizontal .sia-steps__item { flex-direction: row; gap: .875rem; padding-bottom: 1rem; }
|
|
133
|
+
.sia-steps--horizontal .sia-steps__marker { flex-direction: column; width: auto; }
|
|
134
|
+
.sia-steps--horizontal .sia-steps__connector { width: 2px; height: auto; flex: 1; min-height: .75rem; margin: .375rem 0 -1rem; }
|
|
135
|
+
.sia-steps--horizontal .sia-steps__connector-fill { transform-origin: top; transform: scaleY(0); }
|
|
136
|
+
.sia-steps--horizontal .sia-steps__item[data-status="done"] .sia-steps__connector-fill { transform: scaleY(1); }
|
|
137
|
+
.sia-steps--horizontal .sia-steps__body { padding: .25rem 0 0; }
|
|
138
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { forwardRef, useId, useState, type ButtonHTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
import { cn } from "@sia-ui/utils";
|
|
3
|
+
import "./styles.css";
|
|
4
|
+
|
|
5
|
+
export interface SwitchProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onChange"> {
|
|
6
|
+
checked?: boolean;
|
|
7
|
+
defaultChecked?: boolean;
|
|
8
|
+
label?: ReactNode;
|
|
9
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const Switch = forwardRef<HTMLButtonElement, SwitchProps>(
|
|
13
|
+
({ className, checked, defaultChecked = false, label, disabled, onCheckedChange, onClick, ...props }, ref) => {
|
|
14
|
+
const [internalChecked, setInternalChecked] = useState(defaultChecked);
|
|
15
|
+
const labelId = useId();
|
|
16
|
+
const isControlled = checked !== undefined;
|
|
17
|
+
const current = isControlled ? checked : internalChecked;
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<span className={cn("sia-switch-field", disabled && "sia-switch-field--disabled", className)}>
|
|
21
|
+
<button
|
|
22
|
+
ref={ref}
|
|
23
|
+
type="button"
|
|
24
|
+
role="switch"
|
|
25
|
+
aria-checked={current}
|
|
26
|
+
aria-labelledby={label ? labelId : undefined}
|
|
27
|
+
className="sia-switch"
|
|
28
|
+
disabled={disabled}
|
|
29
|
+
onClick={(event) => {
|
|
30
|
+
onClick?.(event);
|
|
31
|
+
if (!event.defaultPrevented) {
|
|
32
|
+
if (!isControlled) setInternalChecked(!current);
|
|
33
|
+
onCheckedChange?.(!current);
|
|
34
|
+
}
|
|
35
|
+
}}
|
|
36
|
+
{...props}
|
|
37
|
+
>
|
|
38
|
+
<span className="sia-switch__thumb" />
|
|
39
|
+
</button>
|
|
40
|
+
{label && <span id={labelId} className="sia-switch-field__label">{label}</span>}
|
|
41
|
+
</span>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
Switch.displayName = "Switch";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
.sia-switch-field { display:inline-flex; align-items:center; gap:.65rem; cursor:pointer; }
|
|
2
|
+
.sia-switch-field--disabled { cursor:not-allowed; opacity:.55; }
|
|
3
|
+
.sia-switch-field__label { font-weight:600; }
|
|
4
|
+
.sia-switch { position:relative; width:2.5rem; height:1.4rem; padding:0; border:0; border-radius:9999px; background:var(--sia-border); cursor:pointer; transition:background-color .15s; }
|
|
5
|
+
.sia-switch[aria-checked="true"] { background:var(--sia-primary); }
|
|
6
|
+
.sia-switch:disabled { cursor:not-allowed; }
|
|
7
|
+
.sia-switch__thumb { position:absolute; top:.2rem; left:.2rem; width:1rem; height:1rem; border-radius:50%; background:#fff; box-shadow:0 1px 3px rgb(15 23 42 / .3); transition:transform .15s; }
|
|
8
|
+
.sia-switch[aria-checked="true"] .sia-switch__thumb { transform:translateX(1.1rem); }
|
|
9
|
+
|
|
10
|
+
/* Le pouce rebondit légèrement : c'est ce qui distingue une bascule d'un
|
|
11
|
+
changement de couleur. `easing.spring` dépasse puis revient. */
|
|
12
|
+
.sia-switch {
|
|
13
|
+
transition: background-color var(--sia-duration-fast) var(--sia-easing-standard);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.sia-switch__thumb {
|
|
17
|
+
transition:
|
|
18
|
+
transform var(--sia-duration-base) var(--sia-easing-spring),
|
|
19
|
+
box-shadow var(--sia-duration-fast) var(--sia-easing-standard);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.sia-switch:active:not(:disabled) .sia-switch__thumb {
|
|
23
|
+
/* Le pouce s'étire sous le doigt, comme un vrai interrupteur. */
|
|
24
|
+
width: 1.25rem;
|
|
25
|
+
transition-duration: var(--sia-duration-instant);
|
|
26
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createContext, useContext, useId, useState, type KeyboardEvent, type ReactNode } from "react";
|
|
2
|
+
import { cn } from "@sia-ui/utils";
|
|
3
|
+
import "./styles.css";
|
|
4
|
+
|
|
5
|
+
type TabsContextValue = { value: string; setValue: (value: string) => void; baseId: string };
|
|
6
|
+
const TabsContext = createContext<TabsContextValue | null>(null);
|
|
7
|
+
|
|
8
|
+
export interface TabsProps { value?: string; defaultValue: string; onValueChange?: (value: string) => void; className?: string; children: ReactNode; }
|
|
9
|
+
|
|
10
|
+
export function Tabs({ value, defaultValue, onValueChange, className, children }: TabsProps) {
|
|
11
|
+
const [internal, setInternal] = useState(defaultValue);
|
|
12
|
+
const baseId = useId();
|
|
13
|
+
const current = value ?? internal;
|
|
14
|
+
const setValue = (next: string) => { if (value === undefined) setInternal(next); onValueChange?.(next); };
|
|
15
|
+
return <TabsContext.Provider value={{ value: current, setValue, baseId }}><div className={cn("sia-tabs", className)}>{children}</div></TabsContext.Provider>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function TabsList({ className, children }: { className?: string; children: ReactNode }) {
|
|
19
|
+
const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
20
|
+
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
21
|
+
const tabs = Array.from(event.currentTarget.querySelectorAll<HTMLButtonElement>("[role='tab']:not(:disabled)"));
|
|
22
|
+
const currentIndex = tabs.indexOf(document.activeElement as HTMLButtonElement);
|
|
23
|
+
if (currentIndex < 0 || tabs.length === 0) return;
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
const index = event.key === "Home" ? 0 : event.key === "End" ? tabs.length - 1 : event.key === "ArrowRight" ? (currentIndex + 1) % tabs.length : (currentIndex - 1 + tabs.length) % tabs.length;
|
|
26
|
+
tabs[index]?.focus();
|
|
27
|
+
tabs[index]?.click();
|
|
28
|
+
};
|
|
29
|
+
return <div role="tablist" className={cn("sia-tabs__list", className)} onKeyDown={onKeyDown}>{children}</div>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function TabsTrigger({ value, disabled, children }: { value: string; disabled?: boolean; children: ReactNode }) {
|
|
33
|
+
const context = useContext(TabsContext);
|
|
34
|
+
if (!context) throw new Error("TabsTrigger must be used inside Tabs.");
|
|
35
|
+
const active = context.value === value;
|
|
36
|
+
return <button type="button" role="tab" id={`${context.baseId}-tab-${value}`} aria-selected={active} aria-controls={`${context.baseId}-panel-${value}`} tabIndex={active ? 0 : -1} disabled={disabled} className="sia-tabs__trigger" onClick={() => context.setValue(value)}>{children}</button>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function TabsContent({ value, className, children }: { value: string; className?: string; children: ReactNode }) {
|
|
40
|
+
const context = useContext(TabsContext);
|
|
41
|
+
if (!context) throw new Error("TabsContent must be used inside Tabs.");
|
|
42
|
+
if (context.value !== value) return null;
|
|
43
|
+
return <div role="tabpanel" id={`${context.baseId}-panel-${value}`} aria-labelledby={`${context.baseId}-tab-${value}`} tabIndex={0} className={cn("sia-tabs__content", className)}>{children}</div>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
.sia-tabs { display:grid; gap:1rem; }
|
|
2
|
+
.sia-tabs__list { display:flex; gap:.25rem; overflow:auto; border-bottom:1px solid var(--sia-border); }
|
|
3
|
+
.sia-tabs__trigger { position:relative; padding:.65rem .85rem; border:0; color:var(--sia-muted); background:transparent; font:inherit; font-weight:650; cursor:pointer; white-space:nowrap; }
|
|
4
|
+
.sia-tabs__trigger[aria-selected="true"] { color:var(--sia-primary); }
|
|
5
|
+
.sia-tabs__trigger[aria-selected="true"]::after { content:""; position:absolute; right:.5rem; bottom:-1px; left:.5rem; height:2px; background:var(--sia-primary); }
|
|
6
|
+
.sia-tabs__trigger:focus-visible,.sia-tabs__content:focus-visible { outline:3px solid color-mix(in srgb,var(--sia-primary) 30%,transparent); outline-offset:2px; }
|
|
7
|
+
.sia-tabs__content { min-width:0; }
|
|
8
|
+
|
|
9
|
+
/* L'onglet actif glisse : la barre se déplace plutôt que de sauter. */
|
|
10
|
+
.sia-tabs__list {
|
|
11
|
+
position: relative;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.sia-tabs__trigger {
|
|
15
|
+
transition:
|
|
16
|
+
color var(--sia-duration-fast) var(--sia-easing-standard),
|
|
17
|
+
background-color var(--sia-duration-fast) var(--sia-easing-standard);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.sia-tabs__trigger[aria-selected="true"] {
|
|
21
|
+
color: var(--sia-primary);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.sia-tabs__trigger::after {
|
|
25
|
+
content: "";
|
|
26
|
+
position: absolute;
|
|
27
|
+
inset: auto 0 0 0;
|
|
28
|
+
height: 2px;
|
|
29
|
+
background: var(--sia-primary);
|
|
30
|
+
transform: scaleX(0);
|
|
31
|
+
transform-origin: center;
|
|
32
|
+
transition: transform var(--sia-duration-base) var(--sia-easing-standard);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.sia-tabs__trigger[aria-selected="true"]::after {
|
|
36
|
+
transform: scaleX(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.sia-tabs__panel {
|
|
40
|
+
animation: sia-slide-up var(--sia-duration-base) var(--sia-easing-entrance);
|
|
41
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useState, type KeyboardEvent } from "react";
|
|
2
|
+
import { cn } from "@sia-ui/utils";
|
|
3
|
+
import { XIcon } from "../Icons";
|
|
4
|
+
import "./styles.css";
|
|
5
|
+
export interface TagsInputProps { id?: string; value?: string[]; defaultValue?: string[]; onValueChange?: (value: string[]) => void; placeholder?: string; separators?: string[]; maxTags?: number; disabled?: boolean; className?: string; "aria-describedby"?: string; "aria-labelledby"?: string; "aria-invalid"?: boolean; "aria-required"?: boolean; }
|
|
6
|
+
export function TagsInput({ id, value, defaultValue = [], onValueChange, placeholder = "Ajouter un tag", separators = ["Enter", ","], maxTags, disabled, className, ...ariaProps }: TagsInputProps) { const [internal, setInternal] = useState(defaultValue); const [draft, setDraft] = useState(""); const current = value ?? internal; const update = (next: string[]) => { if (value === undefined) setInternal(next); onValueChange?.(next); }; const add = () => { const tag = draft.trim().replace(/,$/, ""); if (!tag || current.includes(tag) || (maxTags !== undefined && current.length >= maxTags)) return; update([...current, tag]); setDraft(""); }; return <div id={id} className={cn("sia-tags-input", className)} {...ariaProps}>{current.map((tag) => <span key={tag}>{tag}<button type="button" disabled={disabled} aria-label={`Retirer ${tag}`} onClick={() => update(current.filter((item) => item !== tag))}><XIcon /></button></span>)}<input value={draft} disabled={disabled} placeholder={placeholder} onChange={(event) => setDraft(event.target.value)} onBlur={add} onKeyDown={(event: KeyboardEvent<HTMLInputElement>) => { if (separators.includes(event.key)) { event.preventDefault(); add(); } if (event.key === "Backspace" && !draft && current.length) update(current.slice(0, -1)); }} /></div>; }
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
.sia-tags-input { display:flex; align-items:center; gap:.35rem; min-height:2.5rem; padding:.35rem .5rem; border:1px solid var(--sia-border); border-radius:var(--sia-radius); background:var(--sia-background); flex-wrap:wrap; }
|
|
2
|
+
.sia-tags-input > input { flex:1; min-width:8rem; border:0; outline:0; background:transparent; font:inherit; }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { forwardRef, type TextareaHTMLAttributes } from "react";
|
|
2
|
+
import { cn } from "@sia-ui/utils";
|
|
3
|
+
import "./styles.css";
|
|
4
|
+
|
|
5
|
+
export interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
|
|
6
|
+
invalid?: boolean;
|
|
7
|
+
resize?: "none" | "vertical" | "horizontal" | "both";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
11
|
+
({ className, invalid, resize = "vertical", ...props }, ref) => (
|
|
12
|
+
<textarea
|
|
13
|
+
ref={ref}
|
|
14
|
+
className={cn("sia-textarea", invalid && "sia-textarea--invalid", `sia-textarea--resize-${resize}`, className)}
|
|
15
|
+
aria-invalid={invalid || undefined}
|
|
16
|
+
{...props}
|
|
17
|
+
/>
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
Textarea.displayName = "Textarea";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
.sia-textarea { width:100%; min-height:2.5rem; padding:.65rem .75rem; color:var(--sia-foreground); background:var(--sia-background); border:1px solid var(--sia-border); border-radius:var(--sia-radius); font:inherit; }
|
|
2
|
+
.sia-textarea { min-height:6rem; line-height:1.5; }
|
|
3
|
+
.sia-textarea--resize-none { resize:none; }
|
|
4
|
+
.sia-textarea--resize-vertical { resize:vertical; }
|
|
5
|
+
.sia-textarea--resize-horizontal { resize:horizontal; }
|
|
6
|
+
.sia-textarea--resize-both { resize:both; }
|
|
7
|
+
.sia-textarea--invalid { border-color:var(--sia-danger); }
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { forwardRef, useId, useMemo, useRef, useState, type ReactNode } from "react";
|
|
2
|
+
import { cn, toneClass } from "@sia-ui/utils";
|
|
3
|
+
import type { ComponentTone } from "@sia-ui/tokens";
|
|
4
|
+
import { CheckIcon, ChevronDownIcon, ClockIcon, XIcon } from "../Icons";
|
|
5
|
+
import { Overlay, type OverlayPlacement } from "../Overlay";
|
|
6
|
+
import { formatTimeValue, parseTimeValue, type TimeParts } from "../Timer";
|
|
7
|
+
import "./styles.css";
|
|
8
|
+
|
|
9
|
+
export interface TimePickerProps {
|
|
10
|
+
id?: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
value?: string;
|
|
13
|
+
defaultValue?: string;
|
|
14
|
+
min?: string;
|
|
15
|
+
max?: string;
|
|
16
|
+
showSeconds?: boolean;
|
|
17
|
+
minuteStep?: number;
|
|
18
|
+
secondStep?: number;
|
|
19
|
+
hourFormat?: 12 | 24;
|
|
20
|
+
needConfirm?: boolean;
|
|
21
|
+
allowClear?: boolean;
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
disabledTime?: (value: TimeParts) => boolean;
|
|
24
|
+
renderExtraFooter?: () => ReactNode;
|
|
25
|
+
onValueChange?: (value: string) => void;
|
|
26
|
+
onOpenChange?: (open: boolean) => void;
|
|
27
|
+
open?: boolean;
|
|
28
|
+
placement?: OverlayPlacement;
|
|
29
|
+
tone?: ComponentTone;
|
|
30
|
+
invalid?: boolean;
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
required?: boolean;
|
|
33
|
+
className?: string;
|
|
34
|
+
"aria-label"?: string;
|
|
35
|
+
"aria-describedby"?: string;
|
|
36
|
+
"aria-labelledby"?: string;
|
|
37
|
+
"aria-invalid"?: boolean;
|
|
38
|
+
"aria-required"?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function steppedValues(limit: number, step: number) {
|
|
42
|
+
return Array.from({ length: Math.ceil(limit / Math.max(step, 1)) }, (_, index) => index * Math.max(step, 1)).filter((value) => value < limit);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const TimePicker = forwardRef<HTMLButtonElement, TimePickerProps>(function TimePicker({
|
|
46
|
+
id, name, value, defaultValue = "", min, max, showSeconds = false, minuteStep = 1, secondStep = 1, hourFormat = 24, needConfirm = false, allowClear = true, placeholder = "Sélectionner une heure", disabledTime, renderExtraFooter, onValueChange, onOpenChange, open: openProp, placement = "bottom-start", tone = "primary", invalid = false, disabled = false, required = false, className, "aria-invalid": ariaInvalid, "aria-required": ariaRequired, ...ariaProps
|
|
47
|
+
}, forwardedRef) {
|
|
48
|
+
const generatedId = useId();
|
|
49
|
+
const controlId = id ?? `sia-time-picker-${generatedId.replace(/:/g, "")}`;
|
|
50
|
+
const anchorRef = useRef<HTMLButtonElement>(null);
|
|
51
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
52
|
+
const [internalOpen, setInternalOpen] = useState(false);
|
|
53
|
+
const current = value ?? internalValue;
|
|
54
|
+
const [draft, setDraft] = useState<TimeParts>(() => parseTimeValue(current));
|
|
55
|
+
const open = openProp ?? internalOpen;
|
|
56
|
+
const setOpen = (next: boolean) => { if (next) setDraft(parseTimeValue(current)); if (openProp === undefined) setInternalOpen(next); onOpenChange?.(next); };
|
|
57
|
+
const update = (next: string) => { if (value === undefined) setInternalValue(next); onValueChange?.(next); };
|
|
58
|
+
const setRef = (node: HTMLButtonElement | null) => { anchorRef.current = node; if (typeof forwardedRef === "function") forwardedRef(node); else if (forwardedRef) forwardedRef.current = node; };
|
|
59
|
+
const hours = useMemo(() => steppedValues(24, 1), []);
|
|
60
|
+
const minutes = useMemo(() => steppedValues(60, minuteStep), [minuteStep]);
|
|
61
|
+
const seconds = useMemo(() => steppedValues(60, secondStep), [secondStep]);
|
|
62
|
+
const select = (partial: Partial<TimeParts>) => {
|
|
63
|
+
const next = { ...draft, ...partial };
|
|
64
|
+
setDraft(next);
|
|
65
|
+
const serialized = formatTimeValue(next, showSeconds);
|
|
66
|
+
if (!needConfirm && (!min || serialized >= min) && (!max || serialized <= max) && !disabledTime?.(next)) update(serialized);
|
|
67
|
+
};
|
|
68
|
+
const confirm = () => { const serialized = formatTimeValue(draft, showSeconds); if ((!min || serialized >= min) && (!max || serialized <= max) && !disabledTime?.(draft)) { update(serialized); setOpen(false); } };
|
|
69
|
+
const renderColumn = (label: string, values: number[], selected: number, key: keyof TimeParts) => <div className="sia-time-panel__column" role="listbox" aria-label={label}>{values.map((option) => { const candidate = { ...draft, [key]: option }; const serialized = formatTimeValue(candidate, showSeconds); const optionDisabled = Boolean((min && serialized < min) || (max && serialized > max) || disabledTime?.(candidate)); const display = key === "hours" && hourFormat === 12 ? ((option + 11) % 12) + 1 : option; return <button type="button" role="option" aria-selected={selected === option} disabled={optionDisabled} key={option} onClick={() => select({ [key]: option })}><span>{String(display).padStart(2, "0")}</span>{selected === option && <CheckIcon />}</button>; })}</div>;
|
|
70
|
+
return <div className={cn("sia-picker", "sia-time-picker", toneClass("sia-tone", tone), invalid && "sia-picker--invalid", disabled && "sia-picker--disabled", className)}>
|
|
71
|
+
{name && <input type="hidden" name={name} value={current} />}
|
|
72
|
+
<button ref={setRef} id={controlId} type="button" className="sia-picker__trigger" disabled={disabled} aria-haspopup="dialog" aria-expanded={open} aria-invalid={ariaInvalid ?? (invalid || undefined)} aria-required={ariaRequired ?? (required || undefined)} onClick={() => setOpen(!open)} {...ariaProps}><ClockIcon className="sia-picker__icon" /><span className={cn("sia-picker__value", !current && "sia-picker__placeholder")}>{current || placeholder}</span><span className="sia-picker__actions">{allowClear && current && <span className="sia-picker__clear" title="Effacer" aria-hidden="true" onClick={(event) => { event.stopPropagation(); update(""); }}><XIcon /></span>}<ChevronDownIcon /></span></button>
|
|
73
|
+
<Overlay open={open} anchorRef={anchorRef} onOpenChange={setOpen} placement={placement} className="sia-picker__overlay"><div className={cn("sia-time-panel", toneClass("sia-tone", tone))}><div className="sia-time-panel__columns">{renderColumn("Heures", hours, draft.hours, "hours")}{renderColumn("Minutes", minutes, draft.minutes, "minutes")}{showSeconds && renderColumn("Secondes", seconds, draft.seconds, "seconds")}</div><footer className="sia-time-panel__footer">{renderExtraFooter?.()}<button type="button" className="sia-time-panel__now" onClick={() => setDraft(parseTimeValue(new Date().toTimeString().slice(0, 8)))}>Maintenant</button>{needConfirm && <button type="button" className="sia-time-panel__confirm" onClick={confirm}>OK</button>}</footer></div></Overlay>
|
|
74
|
+
</div>;
|
|
75
|
+
});
|
|
76
|
+
TimePicker.displayName = "TimePicker";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
.sia-time-panel { --sia-accent:var(--sia-primary); --sia-accent-foreground:var(--sia-primary-foreground); min-width:15rem; }
|
|
2
|
+
.sia-time-panel__columns { display:grid; grid-auto-flow:column; grid-auto-columns:minmax(4.5rem,1fr); height:16rem; }
|
|
3
|
+
.sia-time-panel__column { overflow-y:auto; padding:.35rem; border-right:1px solid var(--sia-border); scrollbar-width:thin; }
|
|
4
|
+
.sia-time-panel__column:last-child { border-right:0; }
|
|
5
|
+
.sia-time-panel__column button { display:flex; align-items:center; justify-content:space-between; width:100%; min-height:2.15rem; padding:.35rem .55rem; border:0; border-radius:.45rem; color:var(--sia-foreground); background:transparent; font:inherit; font-variant-numeric:tabular-nums; cursor:pointer; }
|
|
6
|
+
.sia-time-panel__column button:hover:not(:disabled) { background:var(--sia-surface); }
|
|
7
|
+
.sia-time-panel__column button[aria-selected="true"] { color:var(--sia-accent); background:color-mix(in srgb,var(--sia-accent) 11%,transparent); font-weight:750; }
|
|
8
|
+
.sia-time-panel__column button svg { width:.85rem; height:.85rem; }
|
|
9
|
+
.sia-time-panel__column button:disabled { opacity:.3; cursor:not-allowed; }
|
|
10
|
+
.sia-time-panel__footer { display:flex; align-items:center; justify-content:flex-end; gap:.4rem; padding:.55rem; border-top:1px solid var(--sia-border); }
|
|
11
|
+
.sia-time-panel__footer button { min-height:2rem; padding:0 .65rem; border:0; border-radius:.45rem; font:inherit; font-weight:650; cursor:pointer; }
|
|
12
|
+
.sia-time-panel__now { color:var(--sia-accent); background:transparent; }
|
|
13
|
+
.sia-time-panel__confirm { color:var(--sia-accent-foreground); background:var(--sia-accent); }
|