@synertech/ui 0.54.0 → 0.56.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/.claude/skills/use-synertech-ui/SKILL.md +320 -5
- package/README.md +1 -1
- package/dist/components/accordion/Accordion.cjs +1 -1
- package/dist/components/accordion/Accordion.js +1 -1
- package/dist/components/area-chart/AreaChart.cjs +1 -1
- package/dist/components/area-chart/AreaChart.js +1 -1
- package/dist/components/chart/ChartContainer.cjs +1 -1
- package/dist/components/chart/ChartContainer.js +1 -1
- package/dist/components/chart/ChartExportButton.cjs +1 -1
- package/dist/components/chart/ChartExportButton.js +1 -1
- package/dist/components/command-palette/CommandGroup.cjs +1 -0
- package/dist/components/command-palette/CommandGroup.js +1 -0
- package/dist/components/command-palette/CommandItem.cjs +1 -0
- package/dist/components/command-palette/CommandItem.js +1 -0
- package/dist/components/command-palette/CommandPalette.cjs +1 -0
- package/dist/components/command-palette/CommandPalette.js +1 -0
- package/dist/components/command-palette/context.cjs +1 -0
- package/dist/components/command-palette/context.js +1 -0
- package/dist/components/command-palette/index.cjs +1 -0
- package/dist/components/command-palette/index.js +1 -0
- package/dist/components/command-palette/kbd.cjs +1 -0
- package/dist/components/command-palette/kbd.js +1 -0
- package/dist/components/command-palette/match.cjs +1 -0
- package/dist/components/command-palette/match.js +1 -0
- package/dist/components/datagrid/ActiveFilters.cjs +1 -0
- package/dist/components/datagrid/ActiveFilters.js +1 -0
- package/dist/components/datagrid/BulkActionsBar.cjs +1 -0
- package/dist/components/datagrid/BulkActionsBar.js +1 -0
- package/dist/components/datagrid/ColumnToggle.cjs +1 -0
- package/dist/components/datagrid/ColumnToggle.js +1 -0
- package/dist/components/datagrid/DataGrid.cjs +1 -1
- package/dist/components/datagrid/DataGrid.js +1 -1
- package/dist/components/datagrid/DataGridPagination.cjs +1 -0
- package/dist/components/datagrid/DataGridPagination.js +1 -0
- package/dist/components/datagrid/EditableCell.cjs +1 -0
- package/dist/components/datagrid/EditableCell.js +1 -0
- package/dist/components/datagrid/FilterPopover.cjs +1 -0
- package/dist/components/datagrid/FilterPopover.js +1 -0
- package/dist/components/datagrid/export.cjs +1 -0
- package/dist/components/datagrid/export.js +1 -0
- package/dist/components/datagrid/icons.cjs +1 -0
- package/dist/components/datagrid/icons.js +1 -0
- package/dist/components/datagrid/index.cjs +1 -1
- package/dist/components/datagrid/types.cjs +1 -0
- package/dist/components/datagrid/types.js +0 -0
- package/dist/components/datagrid/utils.cjs +1 -0
- package/dist/components/datagrid/utils.js +1 -0
- package/dist/components/dropdown/DropdownContent.cjs +1 -1
- package/dist/components/dropdown/DropdownContent.js +1 -1
- package/dist/components/dropdown/DropdownSubMenu.cjs +1 -1
- package/dist/components/dropdown/DropdownSubMenu.js +1 -1
- package/dist/components/dropdown/hooks/usePositioning.cjs +1 -1
- package/dist/components/dropdown/hooks/usePositioning.js +1 -1
- package/dist/components/empty-state/EmptyState.cjs +1 -0
- package/dist/components/empty-state/EmptyState.js +1 -0
- package/dist/components/empty-state/index.cjs +1 -0
- package/dist/components/empty-state/index.js +1 -0
- package/dist/components/form/mention-input/MentionInput.cjs +5 -5
- package/dist/components/form/mention-input/MentionInput.js +5 -5
- package/dist/components/help-button/HelpButton.cjs +2 -2
- package/dist/components/help-button/HelpButton.js +2 -2
- package/dist/components/index.cjs +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/line-chart/LineChart.cjs +1 -1
- package/dist/components/line-chart/LineChart.js +1 -1
- package/dist/components/schema-editor/SchemaEditor.cjs +1 -1
- package/dist/components/schema-editor/SchemaEditor.js +1 -1
- package/dist/components/select/Select.cjs +1 -1
- package/dist/components/select/Select.js +1 -1
- package/dist/components/skeleton/Skeleton.cjs +1 -1
- package/dist/components/skeleton/Skeleton.js +1 -1
- package/dist/components/timeline/Timeline.cjs +1 -0
- package/dist/components/timeline/Timeline.js +1 -0
- package/dist/components/timeline/index.cjs +1 -0
- package/dist/components/timeline/index.js +1 -0
- package/dist/components/tree-view/TreeView.cjs +1 -0
- package/dist/components/tree-view/TreeView.js +1 -0
- package/dist/components/tree-view/index.cjs +1 -0
- package/dist/components/tree-view/index.js +1 -0
- package/dist/components/tree-view/tree-model.cjs +1 -0
- package/dist/components/tree-view/tree-model.js +1 -0
- package/dist/components/workflow-editor/WorkflowEditor.cjs +1 -1
- package/dist/components/workflow-editor/WorkflowEditor.js +1 -1
- package/dist/index.d.cts +601 -10
- package/dist/index.d.ts +601 -10
- package/dist/lib/ui-labels.cjs +1 -1
- package/dist/lib/ui-labels.js +1 -1
- package/dist/styles-no-preflight.css +1321 -843
- package/dist/styles.css +1319 -843
- package/package.json +10 -4
|
@@ -267,6 +267,7 @@ import { cn } from "@synertech/ui";
|
|
|
267
267
|
|-----------|-------------|:-:|
|
|
268
268
|
| `Avatar` | Photo de profil avec fallback texte | Oui |
|
|
269
269
|
| `Skeleton` | Placeholder de chargement (pulse/wave) | Oui |
|
|
270
|
+
| `EmptyState` | Ce qu'une liste, un tableau, un graphique ou une page montre quand il n'y a rien : icône, titre, description, actions | Oui |
|
|
270
271
|
| `Indicator` | Badge de notification (dot/count/status/legend) | Oui |
|
|
271
272
|
|
|
272
273
|
### Navigation & Actions
|
|
@@ -278,6 +279,7 @@ import { cn } from "@synertech/ui";
|
|
|
278
279
|
| `Breadcrumb` | Fil d'Ariane | Oui |
|
|
279
280
|
| `Pagination` | Navigation par pages | Non |
|
|
280
281
|
| `Dropdown` | Menu déroulant composable | Non |
|
|
282
|
+
| `CommandPalette` | Palette de commandes (⌘K) : chercher une action et la lancer au clavier | Non |
|
|
281
283
|
| `Tabs` | Interface à onglets composable | Non |
|
|
282
284
|
|
|
283
285
|
### Forms & Input
|
|
@@ -311,8 +313,10 @@ import { cn } from "@synertech/ui";
|
|
|
311
313
|
| Composant | Description | Server-compatible |
|
|
312
314
|
|-----------|-------------|:-:|
|
|
313
315
|
| `Table` | Tableau composable (Header, Body, Row, Cell) | Oui |
|
|
314
|
-
| `DataGrid` | Tableau avancé data-driven (tri, pagination, filtres, sélection, export) | Non |
|
|
316
|
+
| `DataGrid` | Tableau avancé data-driven (tri, pagination, filtres, sélection, actions groupées, vues enregistrées, export) | Non |
|
|
317
|
+
| `TreeView` | Arborescence : dossiers et fichiers, catégories ; sélection simple ou multiple, cases à trois états, enfants chargés à la demande | Non |
|
|
315
318
|
| `Chip` | Tag/badge | Oui |
|
|
319
|
+
| `Timeline` / `TimelineItem` | Frise de ce qui s'est passé : historique d'un dossier, journal d'audit, suivi d'une commande | Oui |
|
|
316
320
|
| `Label` | Étiquette de formulaire | Oui |
|
|
317
321
|
| `Banner` | Bannière notification/hero/promotion | Non |
|
|
318
322
|
|
|
@@ -435,6 +439,46 @@ import { Skeleton } from "@synertech/ui";
|
|
|
435
439
|
/>
|
|
436
440
|
```
|
|
437
441
|
|
|
442
|
+
### EmptyState
|
|
443
|
+
|
|
444
|
+
```tsx
|
|
445
|
+
import { EmptyState, Button } from "@synertech/ui";
|
|
446
|
+
|
|
447
|
+
<EmptyState
|
|
448
|
+
icon={<InboxIcon />} // décoratif, dans un disque ; un <svg> prend la taille de `size`
|
|
449
|
+
title="Aucune facture pour l'instant" // ce qu'il n'y a pas, en une ligne
|
|
450
|
+
description="Créez la première ou importez un fichier CSV."
|
|
451
|
+
action={<Button label="Créer une facture" />} // une seule action principale
|
|
452
|
+
secondaryAction={<Button label="Importer un CSV" bgColor="bg-white hover:bg-gray-50 border border-gray-300" textColor="text-gray-700" />}
|
|
453
|
+
size="md" // "sm" (tableau, graphique, carte) | "md" (panneau) | "lg" (page)
|
|
454
|
+
headingLevel={2} // optionnel : un titre de section ; sans lui, un paragraphe
|
|
455
|
+
/>
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
Sans hook ni texte à lui : il se rend dans un Server Component. `DataGrid` et
|
|
459
|
+
les graphiques dessinent avec lui leurs propres « aucune donnée » et
|
|
460
|
+
« chargement impossible » ; leur `emptyState` en prend un pour dire pourquoi
|
|
461
|
+
c'est vide, et quoi faire :
|
|
462
|
+
|
|
463
|
+
```tsx
|
|
464
|
+
<DataGrid
|
|
465
|
+
columns={columns}
|
|
466
|
+
data={rows}
|
|
467
|
+
rowKey="id"
|
|
468
|
+
emptyState={
|
|
469
|
+
<EmptyState
|
|
470
|
+
size="sm"
|
|
471
|
+
title={`Aucun client ne correspond à « ${query} »`}
|
|
472
|
+
description="Vérifiez l'orthographe, ou cherchez un autre nom."
|
|
473
|
+
action={<Button size="sm" label="Effacer la recherche" onClick={() => setQuery("")} />}
|
|
474
|
+
/>
|
|
475
|
+
}
|
|
476
|
+
/>
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
`headingLevel` seulement quand l'état tient lieu de section de la page : dans
|
|
480
|
+
un tableau, un graphique ou une carte, un titre couperait le plan de la page.
|
|
481
|
+
|
|
438
482
|
### Indicator
|
|
439
483
|
|
|
440
484
|
```tsx
|
|
@@ -587,6 +631,60 @@ import { Tabs, TabsList, TabsTrigger, TabsContent } from "@synertech/ui";
|
|
|
587
631
|
- Renseignez `defaultValue` (ou `value`) : sans lui aucun panneau n'est affiché au départ ; le premier onglet reste atteignable au clavier
|
|
588
632
|
- Chaque `TabsContent` est nommé par son onglet (`aria-labelledby`) : pas besoin d'`aria-label`
|
|
589
633
|
|
|
634
|
+
### CommandPalette (⌘K)
|
|
635
|
+
|
|
636
|
+
Une boîte de dialogue pour atteindre n'importe quelle action au clavier : un
|
|
637
|
+
champ de recherche au-dessus des entrées que l'application déclare, ouverte de
|
|
638
|
+
partout par ⌘K (Ctrl K hors des systèmes Apple). Montez-en **une** par
|
|
639
|
+
application, près de la racine : chaque palette écoute son raccourci.
|
|
640
|
+
|
|
641
|
+
```tsx
|
|
642
|
+
"use client";
|
|
643
|
+
import { CommandGroup, CommandItem, CommandPalette } from "@synertech/ui";
|
|
644
|
+
|
|
645
|
+
<CommandPalette> {/* non contrôlée : ⌘K l'ouvre et la ferme */}
|
|
646
|
+
<CommandGroup label="Actions">
|
|
647
|
+
<CommandItem icon={<FileIcon />} shortcut="N" keywords={["bill"]} onSelect={createInvoice}>
|
|
648
|
+
Créer une facture
|
|
649
|
+
</CommandItem>
|
|
650
|
+
<CommandItem disabled>Créer un avoir</CommandItem>
|
|
651
|
+
</CommandGroup>
|
|
652
|
+
<CommandGroup label="Navigation">
|
|
653
|
+
<CommandItem shortcut={["G", "R"]} onSelect={() => router.push("/rapports")}>
|
|
654
|
+
Aller aux rapports
|
|
655
|
+
</CommandItem>
|
|
656
|
+
</CommandGroup>
|
|
657
|
+
</CommandPalette>
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
- **État** : non contrôlée (`defaultOpen`), ou contrôlée (`open` +
|
|
661
|
+
`onOpenChange`) pour l'ouvrir aussi depuis un bouton — qui n'a pas de clavier
|
|
662
|
+
doit pouvoir l'atteindre. `hotkey` (`"mod+k"` par défaut, `mod` = ⌘ ou Ctrl)
|
|
663
|
+
change la combinaison, `false` la retire. Une touche déjà traitée
|
|
664
|
+
(`preventDefault()`, un éditeur de texte) est laissée de côté.
|
|
665
|
+
- **Recherche** : chaque mot tapé doit se trouver dans le texte de l'entrée
|
|
666
|
+
(ou son `textValue`) ou ses `keywords`, sans tenir compte des accents ni de
|
|
667
|
+
la casse ; ce qui correspond est en gras quand `children` est une chaîne. Un
|
|
668
|
+
groupe sans entrée disparaît avec son intitulé. `description` (seconde
|
|
669
|
+
ligne) n'est pas cherchée.
|
|
670
|
+
- **Clavier** : le focus reste dans le champ ; ↑ ↓ parcourent les entrées (en
|
|
671
|
+
sautant les désactivées, en bouclant), Entrée choisit, Échap ferme et rend le
|
|
672
|
+
focus. Une entrée choisie appelle `onSelect` puis ferme la palette, sauf
|
|
673
|
+
`closeOnSelect={false}` (sur la palette ou l'entrée).
|
|
674
|
+
- **Raccourcis** : `shortcut` est **affiché** seulement. Liez la touche
|
|
675
|
+
vous-même, et passez `aria-keyshortcuts` à l'entrée si vous le faites.
|
|
676
|
+
- **Recherche serveur** : `filter={false}` (sur la palette ou un
|
|
677
|
+
`CommandGroup`) laisse le tri à l'application, `query` + `onQueryChange` lui
|
|
678
|
+
donnent la saisie, `loading` affiche l'attente — jamais « Aucun résultat »
|
|
679
|
+
pendant qu'elle dure. Un groupe `filter` garde ses actions filtrées sur place.
|
|
680
|
+
- **Vide** : `emptyState` remplace « Aucun résultat » (un `EmptyState`
|
|
681
|
+
`size="sm"`) ; `footer` remplace l'aide des touches, `null` la retire.
|
|
682
|
+
- **Accessibilité** : le contrat de `Modal` (focus gardé, Échap, focus rendu,
|
|
683
|
+
page derrière inerte), le champ en `combobox` sur une `listbox`, et une
|
|
684
|
+
région polie qui dit combien d'entrées correspondent. Libellés traduits par
|
|
685
|
+
`UILabelsProvider` (`commandPalette…`), `label` et `placeholder` par
|
|
686
|
+
instance.
|
|
687
|
+
|
|
590
688
|
### Input (Form)
|
|
591
689
|
|
|
592
690
|
```tsx
|
|
@@ -1393,6 +1491,112 @@ import { Chip } from "@synertech/ui";
|
|
|
1393
1491
|
/>
|
|
1394
1492
|
```
|
|
1395
1493
|
|
|
1494
|
+
### Timeline
|
|
1495
|
+
|
|
1496
|
+
```tsx
|
|
1497
|
+
import { Timeline, TimelineItem, Avatar } from "@synertech/ui";
|
|
1498
|
+
|
|
1499
|
+
<Timeline aria-label="Historique du dossier"> {/* orientation : "vertical" (défaut) | "horizontal" */}
|
|
1500
|
+
<TimelineItem
|
|
1501
|
+
title="Facture nº 2026-114 payée" // ce qui s'est passé, en une ligne
|
|
1502
|
+
time="Il y a 12 min" // écrit par l'application : la frise ne formate rien
|
|
1503
|
+
dateTime="2026-12-02T14:12" // ISO 8601 : `time` passe dans un <time>
|
|
1504
|
+
icon={<CheckIcon />} // dans un disque, décoratif ; un <svg> à 16 px
|
|
1505
|
+
color="success" // "neutral" | "primary" | "success" | "warning" | "error" | "info"
|
|
1506
|
+
>
|
|
1507
|
+
Paiement par carte. {/* le détail, sous le titre et la date */}
|
|
1508
|
+
</TimelineItem>
|
|
1509
|
+
<TimelineItem
|
|
1510
|
+
avatar={<Avatar size="sm" alt="Camille Roy" fallback="CR" />} // remplit la place (32 px), l'emporte sur `icon`
|
|
1511
|
+
title="Commentaire de Camille Roy"
|
|
1512
|
+
time="Hier, 16 h 40"
|
|
1513
|
+
>
|
|
1514
|
+
<p>On peut l'envoyer vendredi.</p>
|
|
1515
|
+
</TimelineItem>
|
|
1516
|
+
<TimelineItem time="3 nov. 2026">Dossier créé</TimelineItem> {/* sans `title`, les enfants prennent sa place */}
|
|
1517
|
+
</Timeline>
|
|
1518
|
+
```
|
|
1519
|
+
|
|
1520
|
+
`status` dit où en est un élément : `"completed"` (défaut), `"current"` (repère
|
|
1521
|
+
cerclé, couleur de la marque par défaut, `aria-current="step"`) ou `"upcoming"`
|
|
1522
|
+
(point creux, ligne en pointillés qui y mène, titre grisé). La frise n'écrit
|
|
1523
|
+
aucun mot : « Prévue le 4 déc. » se passe dans `time`.
|
|
1524
|
+
|
|
1525
|
+
```tsx
|
|
1526
|
+
<Timeline orientation="horizontal" aria-label="Suivi de la commande">
|
|
1527
|
+
<TimelineItem title="Reçue" time="28 nov." />
|
|
1528
|
+
<TimelineItem status="current" title="En transit" time="1er déc." />
|
|
1529
|
+
<TimelineItem status="upcoming" title="Livrée" time="Prévue le 4 déc." />
|
|
1530
|
+
</Timeline>
|
|
1531
|
+
```
|
|
1532
|
+
|
|
1533
|
+
Horizontale pour quelques étapes (chaque élément a la même largeur) ; un long
|
|
1534
|
+
historique reste vertical. Sans hook : elle se rend dans un Server Component.
|
|
1535
|
+
La couleur s'ajoute au titre, elle ne le remplace pas : « Paiement refusé »
|
|
1536
|
+
s'écrit, en plus d'être rouge.
|
|
1537
|
+
|
|
1538
|
+
### TreeView
|
|
1539
|
+
|
|
1540
|
+
```tsx
|
|
1541
|
+
import { useState } from "react";
|
|
1542
|
+
import { TreeView, type TreeNode } from "@synertech/ui";
|
|
1543
|
+
|
|
1544
|
+
const tree: TreeNode[] = [
|
|
1545
|
+
{
|
|
1546
|
+
id: "src", // unique dans l'arbre : c'est par lui que l'état est tenu
|
|
1547
|
+
label: "src",
|
|
1548
|
+
icon: <FolderIcon />, // décoratif ; `expandedIcon` le remplace branche ouverte
|
|
1549
|
+
expandedIcon: <FolderOpenIcon />,
|
|
1550
|
+
children: [{ id: "src/index.ts", label: "index.ts", icon: <FileIcon /> }],
|
|
1551
|
+
},
|
|
1552
|
+
{ id: "docs", label: "docs", hasChildren: true }, // enfants demandés à loadChildren à la 1re ouverture
|
|
1553
|
+
{ id: "legacy", label: "legacy", disabled: true }, // affiché et ouvert, ni sélectionné ni coché
|
|
1554
|
+
];
|
|
1555
|
+
|
|
1556
|
+
const [expanded, setExpanded] = useState<string[]>(["src"]);
|
|
1557
|
+
const [selected, setSelected] = useState<string[]>([]);
|
|
1558
|
+
|
|
1559
|
+
<TreeView
|
|
1560
|
+
aria-label="Fichiers du projet" // un arbre se nomme
|
|
1561
|
+
items={tree}
|
|
1562
|
+
expanded={expanded} // ou defaultExpanded : l'arbre le tient lui-même
|
|
1563
|
+
onExpandedChange={setExpanded}
|
|
1564
|
+
selectionMode="single" // "single" (défaut) | "multiple" | "none"
|
|
1565
|
+
selected={selected} // toujours un tableau d'identifiants, dans l'ordre de l'arbre
|
|
1566
|
+
onSelectionChange={setSelected}
|
|
1567
|
+
loadChildren={(node) => fetchChildren(node.id)} // Promise<TreeNode[]>
|
|
1568
|
+
onLoadError={(error, node) => report(error)} // sinon, l'erreur va dans la console
|
|
1569
|
+
/>
|
|
1570
|
+
```
|
|
1571
|
+
|
|
1572
|
+
Le clavier est celui du motif ARIA `tree` : un seul nœud dans l'ordre de
|
|
1573
|
+
tabulation, ↑ ↓ parcourent les nœuds affichés, → ouvre une branche puis y entre,
|
|
1574
|
+
← la ferme puis remonte au parent, Début / Fin, `*` ouvre les branches voisines,
|
|
1575
|
+
et les premières lettres d'un nom y amènent le focus (accents et casse ignorés ;
|
|
1576
|
+
`textValue` quand le libellé n'est pas du texte). En `multiple` : Ctrl / ⌘ + clic,
|
|
1577
|
+
Maj + clic, Espace, Maj + flèches, Ctrl / ⌘ + A. Un clic sur une branche l'ouvre
|
|
1578
|
+
aussi, sauf avec `expandOnClick={false}` (la flèche devant elle s'en charge).
|
|
1579
|
+
|
|
1580
|
+
Un chargement qui échoue referme le nœud et l'écrit sous son nom ; le rouvrir
|
|
1581
|
+
réessaie. Une branche chargée vide devient une feuille.
|
|
1582
|
+
|
|
1583
|
+
```tsx
|
|
1584
|
+
<TreeView
|
|
1585
|
+
aria-label="Permissions du rôle"
|
|
1586
|
+
items={permissions}
|
|
1587
|
+
selectionMode="none" // un clic coche, Espace aussi
|
|
1588
|
+
checkable // cases à trois états
|
|
1589
|
+
checked={checked} // une branche dont tous les enfants sont cochés y figure aussi
|
|
1590
|
+
onCheckedChange={setChecked}
|
|
1591
|
+
renderLabel={(node, state) => <>{node.label} {state.checked === "mixed" && "(partiel)"}</>}
|
|
1592
|
+
/>
|
|
1593
|
+
```
|
|
1594
|
+
|
|
1595
|
+
Cocher une branche coche ce qu'elle contient ; une branche en partie cochée est
|
|
1596
|
+
mixte. Un nœud désactivé garde son état : une branche qu'il empêche d'être
|
|
1597
|
+
entièrement cochée se décoche au clic suivant. `emptyState` remplace l'arbre
|
|
1598
|
+
quand `items` est vide (un `EmptyState` de taille `sm`).
|
|
1599
|
+
|
|
1396
1600
|
### Label
|
|
1397
1601
|
|
|
1398
1602
|
```tsx
|
|
@@ -1988,7 +2192,7 @@ import { FileSelector } from "@synertech/ui";
|
|
|
1988
2192
|
|
|
1989
2193
|
```tsx
|
|
1990
2194
|
import { DataGrid } from "@synertech/ui";
|
|
1991
|
-
import type { ColumnDef, SortState, DataGridRef } from "@synertech/ui";
|
|
2195
|
+
import type { ColumnDef, SortState, DataGridRef, DataGridView } from "@synertech/ui";
|
|
1992
2196
|
import { useRef } from "react";
|
|
1993
2197
|
|
|
1994
2198
|
const ref = useRef<DataGridRef>(null);
|
|
@@ -2037,10 +2241,29 @@ const columns: ColumnDef<User>[] = [
|
|
|
2037
2241
|
selectionMode="multiple" // "single" | "multiple"
|
|
2038
2242
|
onSelectionChange={(keys) => console.log(keys)}
|
|
2039
2243
|
|
|
2244
|
+
// Actions groupées : une barre au-dessus de la grille tant que des lignes sont
|
|
2245
|
+
// cochées (leur nombre, vos actions, « Effacer la sélection »). En fonction, elle
|
|
2246
|
+
// reçoit les clés et les lignes de `data` de toutes les pages, et clear()
|
|
2247
|
+
bulkActions={({ keys, rows, clear }) => (
|
|
2248
|
+
<Button size="sm" onClick={async () => { await archive(keys); clear(); }}>
|
|
2249
|
+
Archiver {rows.length}
|
|
2250
|
+
</Button>
|
|
2251
|
+
)}
|
|
2252
|
+
|
|
2040
2253
|
// Recherche & Filtres
|
|
2041
2254
|
searchable
|
|
2042
2255
|
searchPlaceholder="Rechercher..."
|
|
2043
2256
|
onSearch={(q) => console.log(q)}
|
|
2257
|
+
// Les filtres en vigueur sont écrits au-dessus de la grille, un chip retirable
|
|
2258
|
+
// chacun (« Rôle : Admin », « Âge : ≥ 30 »), dans la `locale` de la grille
|
|
2259
|
+
showActiveFilters // par défaut ; false pour les taire
|
|
2260
|
+
|
|
2261
|
+
// Vue : chaque partie contrôlée par sa prop, ou tenue par la grille
|
|
2262
|
+
defaultView={savedView} // lue au montage seulement, entière ou en partie
|
|
2263
|
+
onViewChange={(view) => save(view)} // la vue entière, à chaque changement
|
|
2264
|
+
pageSize={pageSize} // + onPageSizeChange
|
|
2265
|
+
columnOrder={order} // + onColumnOrderChange (toutes les clés, masquées comprises)
|
|
2266
|
+
columnWidths={widths} // + onColumnWidthsChange, appelée une fois au relâcher
|
|
2044
2267
|
|
|
2045
2268
|
// Lignes expandables
|
|
2046
2269
|
expandable
|
|
@@ -2078,7 +2301,7 @@ const columns: ColumnDef<User>[] = [
|
|
|
2078
2301
|
maxHeight="600px"
|
|
2079
2302
|
loading={false}
|
|
2080
2303
|
loadingRows={5}
|
|
2081
|
-
emptyState={<
|
|
2304
|
+
emptyState={<EmptyState size="sm" title="Aucun utilisateur trouvé" />}
|
|
2082
2305
|
|
|
2083
2306
|
// Événements
|
|
2084
2307
|
onRowClick={(row, index) => console.log(row)}
|
|
@@ -2097,6 +2320,32 @@ ref.current?.deselectAll(); // vide la sélection, toutes pages confondues
|
|
|
2097
2320
|
ref.current?.exportData("csv");
|
|
2098
2321
|
ref.current?.scrollToRow(50);
|
|
2099
2322
|
ref.current?.getVisibleData();
|
|
2323
|
+
const view = ref.current?.getView(); // tri, filtres, recherche, colonnes, taille de page
|
|
2324
|
+
ref.current?.setView(view); // revient à la page 1 ; ignore les champs inconnus
|
|
2325
|
+
```
|
|
2326
|
+
|
|
2327
|
+
**Vues enregistrées :** une `DataGridView` est un objet JSON (tri, filtres,
|
|
2328
|
+
recherche, colonnes masquées, ordre et largeurs des colonnes, taille de page).
|
|
2329
|
+
Enregistrez-la dans `onViewChange` ; remettez-la par `defaultView` si elle est
|
|
2330
|
+
connue avant le rendu, sinon par `setView` dans un effet. Ne lisez jamais
|
|
2331
|
+
`localStorage` pendant le rendu : le serveur ne l'a pas, et le HTML ne correspond
|
|
2332
|
+
plus à l'hydratation.
|
|
2333
|
+
|
|
2334
|
+
```tsx
|
|
2335
|
+
"use client";
|
|
2336
|
+
const ref = useRef<DataGridRef>(null);
|
|
2337
|
+
useEffect(() => {
|
|
2338
|
+
const saved = localStorage.getItem("clients:view");
|
|
2339
|
+
if (saved) ref.current?.setView(JSON.parse(saved) as Partial<DataGridView>);
|
|
2340
|
+
}, []);
|
|
2341
|
+
|
|
2342
|
+
<DataGrid
|
|
2343
|
+
ref={ref}
|
|
2344
|
+
columns={columns}
|
|
2345
|
+
data={clients}
|
|
2346
|
+
rowKey="id"
|
|
2347
|
+
onViewChange={(view) => localStorage.setItem("clients:view", JSON.stringify(view))}
|
|
2348
|
+
/>
|
|
2100
2349
|
```
|
|
2101
2350
|
|
|
2102
2351
|
**Quand utiliser DataGrid vs Table :**
|
|
@@ -2250,7 +2499,7 @@ librairie porte elle-même ses directives `"use client"` : l'application n'a pas
|
|
|
2250
2499
|
Next.js.
|
|
2251
2500
|
|
|
2252
2501
|
Les composants **d'affichage** (`Card`, `Button`, `Avatar`, `Badge`, `Divider`,
|
|
2253
|
-
`Skeleton`, `Table`, `StatCard`, `Sparkline`...) n'ont pas de directive : ils
|
|
2502
|
+
`Skeleton`, `EmptyState`, `Table`, `Timeline`, `StatCard`, `Sparkline`...) n'ont pas de directive : ils
|
|
2254
2503
|
sont rendus sur le serveur et n'envoient aucun JavaScript au navigateur.
|
|
2255
2504
|
|
|
2256
2505
|
```tsx
|
|
@@ -2552,7 +2801,7 @@ d'écrire les nombres et les dates. Le provider prend les deux :
|
|
|
2552
2801
|
```
|
|
2553
2802
|
|
|
2554
2803
|
- La lisent : les treize graphiques, `Calendar`, `ChartPeriodPicker`,
|
|
2555
|
-
`NumberInput
|
|
2804
|
+
`NumberInput`, les agrégats du pied et les filtres actifs de `DataGrid`. La prop `locale` d'une
|
|
2556
2805
|
instance gagne ; un provider imbriqué sans `locale` garde celle du parent ;
|
|
2557
2806
|
`useUILocale()` la lit pour vos propres composants (à passer à `Intl`).
|
|
2558
2807
|
- Sans prop ni provider, ces composants suivent la langue de l'environnement :
|
|
@@ -2640,6 +2889,72 @@ import { Card, CardBody } from "@synertech/ui";
|
|
|
2640
2889
|
<Indicator variant="status" color="success" label="En ligne" />
|
|
2641
2890
|
```
|
|
2642
2891
|
|
|
2892
|
+
```tsx
|
|
2893
|
+
// MAUVAIS - un état vide dessiné à la main, différent sur chaque écran
|
|
2894
|
+
<div className="flex flex-col items-center py-8 text-gray-400">
|
|
2895
|
+
<InboxIcon />
|
|
2896
|
+
<p>Aucune facture</p>
|
|
2897
|
+
</div>
|
|
2898
|
+
|
|
2899
|
+
// BON - le même visage que l'état vide de DataGrid et des graphiques
|
|
2900
|
+
<EmptyState icon={<InboxIcon />} title="Aucune facture" action={<Button label="Créer une facture" />} />
|
|
2901
|
+
```
|
|
2902
|
+
|
|
2903
|
+
```tsx
|
|
2904
|
+
// MAUVAIS - un historique fait de séparateurs et d'une liste, ou un GanttChart
|
|
2905
|
+
// pour raconter ce qui a eu lieu (il planifie ce qui vient)
|
|
2906
|
+
<ul>
|
|
2907
|
+
<li>12 nov. — Devis envoyé</li>
|
|
2908
|
+
<Divider />
|
|
2909
|
+
<li>3 nov. — Dossier créé</li>
|
|
2910
|
+
</ul>
|
|
2911
|
+
|
|
2912
|
+
// BON
|
|
2913
|
+
<Timeline aria-label="Historique">
|
|
2914
|
+
<TimelineItem title="Devis envoyé" time="12 nov." dateTime="2026-11-12" />
|
|
2915
|
+
<TimelineItem title="Dossier créé" time="3 nov." dateTime="2026-11-03" />
|
|
2916
|
+
</Timeline>
|
|
2917
|
+
```
|
|
2918
|
+
|
|
2919
|
+
```tsx
|
|
2920
|
+
// MAUVAIS - une palette faite d'une Modal et d'un Select, et ⌘K écouté à la main :
|
|
2921
|
+
// la liste se ferme à chaque choix, les accents comptent, Ctrl K ne marche pas hors Mac
|
|
2922
|
+
useEffect(() => {
|
|
2923
|
+
const onKey = (e) => e.metaKey && e.key === "k" && setOpen(true);
|
|
2924
|
+
window.addEventListener("keydown", onKey);
|
|
2925
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
2926
|
+
}, []);
|
|
2927
|
+
<Modal isOpen={open} onClose={() => setOpen(false)}>
|
|
2928
|
+
<Select searchable options={actions} onChange={run} />
|
|
2929
|
+
</Modal>
|
|
2930
|
+
|
|
2931
|
+
// BON
|
|
2932
|
+
<CommandPalette>
|
|
2933
|
+
<CommandGroup label="Actions">
|
|
2934
|
+
<CommandItem onSelect={createInvoice}>Créer une facture</CommandItem>
|
|
2935
|
+
</CommandGroup>
|
|
2936
|
+
</CommandPalette>
|
|
2937
|
+
```
|
|
2938
|
+
|
|
2939
|
+
```tsx
|
|
2940
|
+
// MAUVAIS - une hiérarchie faite de listes imbriquées et de boutons : chaque
|
|
2941
|
+
// bouton est un arrêt de Tab, les flèches ne font rien, et un lecteur d'écran
|
|
2942
|
+
// ne sait ni le niveau d'un nœud ni si son dossier est ouvert
|
|
2943
|
+
<ul>
|
|
2944
|
+
<li>
|
|
2945
|
+
<button onClick={() => toggle("src")}>src</button>
|
|
2946
|
+
{open.has("src") && (
|
|
2947
|
+
<ul>
|
|
2948
|
+
<li><button onClick={() => select("src/index.ts")}>index.ts</button></li>
|
|
2949
|
+
</ul>
|
|
2950
|
+
)}
|
|
2951
|
+
</li>
|
|
2952
|
+
</ul>
|
|
2953
|
+
|
|
2954
|
+
// BON
|
|
2955
|
+
<TreeView aria-label="Fichiers" items={tree} onSelectionChange={setSelected} />
|
|
2956
|
+
```
|
|
2957
|
+
|
|
2643
2958
|
### 5. Ne pas oublier le pattern controlled pour les formulaires
|
|
2644
2959
|
|
|
2645
2960
|
```tsx
|
package/README.md
CHANGED
|
@@ -287,7 +287,7 @@ written, and the provider takes both:
|
|
|
287
287
|
```
|
|
288
288
|
|
|
289
289
|
- The charts, `Calendar`, `ChartPeriodPicker`, `NumberInput` and the footer
|
|
290
|
-
aggregates of `DataGrid` read it. A `locale` prop on one instance wins, and
|
|
290
|
+
aggregates and active filters of `DataGrid` read it. A `locale` prop on one instance wins, and
|
|
291
291
|
`useUILocale()` reads it for your own components.
|
|
292
292
|
- Without either, they follow the language of the runtime — the server's on the
|
|
293
293
|
server, the reader's in the browser. **An application that renders on the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var A=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var H=(e,r)=>{for(var c in r)A(e,c,{get:r[c],enumerable:!0})},M=(e,r,c,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of E(r))!D.call(e,t)&&t!==c&&A(e,t,{get:()=>r[t],enumerable:!(n=z(r,t))||n.enumerable});return e};var S=e=>M(A({},"__esModule",{value:!0}),e);var G={};H(G,{Accordion:()=>$,AccordionContent:()=>F,AccordionItem:()=>q,AccordionTrigger:()=>B});module.exports=S(G);var o=require("react"),b=require("../../lib/cn.cjs"),d=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";"use client";var A=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var H=(e,r)=>{for(var c in r)A(e,c,{get:r[c],enumerable:!0})},M=(e,r,c,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of E(r))!D.call(e,t)&&t!==c&&A(e,t,{get:()=>r[t],enumerable:!(n=z(r,t))||n.enumerable});return e};var S=e=>M(A({},"__esModule",{value:!0}),e);var G={};H(G,{Accordion:()=>$,AccordionContent:()=>F,AccordionItem:()=>q,AccordionTrigger:()=>B});module.exports=S(G);var o=require("react"),b=require("../../lib/cn.cjs"),d=require("react/jsx-runtime"),C=(0,o.createContext)(null),N=(0,o.createContext)(null);function v(){let e=(0,o.useContext)(C);if(!e)throw new Error("Accordion sub-components must be used within <Accordion>");return e}function k(){let e=(0,o.useContext)(N);if(!e)throw new Error("AccordionTrigger/AccordionContent must be used within <AccordionItem>");return e}var w={sm:{trigger:"px-3 py-2",content:"px-3 pb-2",text:"text-sm",icon:"w-3.5 h-3.5"},md:{trigger:"px-4 py-3",content:"px-4 pb-3",text:"text-base",icon:"w-4 h-4"},lg:{trigger:"px-5 py-4",content:"px-5 pb-4",text:"text-lg",icon:"w-5 h-5"}},V=({className:e})=>(0,d.jsx)("svg",{className:e,viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,d.jsx)("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})}),K={default:"border border-gray-200 dark:border-gray-700 rounded-lg divide-y divide-gray-200 dark:divide-gray-700",bordered:"border-2 border-gray-300 dark:border-gray-600 rounded-lg divide-y divide-gray-300 dark:divide-gray-600",separated:"space-y-2",ghost:""},L={default:"",bordered:"",separated:"border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden",ghost:"border-b border-gray-200 dark:border-gray-700 last:border-b-0"};function $({type:e="single",value:r,defaultValue:c,onValueChange:n,collapsible:t=!1,variant:s="default",size:l="md",disabled:u=!1,iconPosition:a="right",icon:g,hideIcon:i=!1,className:y,children:R}){let[h,O]=(0,o.useState)(()=>c?Array.isArray(c)?c:[c]:[]),m=r!==void 0,p=(0,o.useMemo)(()=>m?Array.isArray(r)?r:[r]:h,[m,r,h]),I=(0,o.useCallback)(f=>{let x;e==="single"?p.includes(f)?x=t?[]:[f]:x=[f]:x=p.includes(f)?p.filter(T=>T!==f):[...p,f],m||O(x),n?.(e==="single"?x[0]??"":x)},[e,p,t,m,n]),P=(0,o.useMemo)(()=>({openItems:p,toggle:I,variant:s,size:l,disabled:u,iconPosition:a,icon:g??null,hideIcon:i}),[p,I,s,l,u,a,g,i]);return(0,d.jsx)(C.Provider,{value:P,children:(0,d.jsx)("div",{className:(0,b.cn)(K[s],y),"data-testid":"accordion",children:R})})}function q({value:e,disabled:r,className:c,children:n}){let t=v(),s=t.openItems.includes(e),l=r??t.disabled,u=(0,o.useId)(),a=`accordion-trigger-${u}`,g=`accordion-content-${u}`,i=(0,o.useMemo)(()=>({value:e,isOpen:s,disabled:l,triggerId:a,contentId:g}),[e,s,l,a,g]);return(0,d.jsx)(N.Provider,{value:i,children:(0,d.jsx)("div",{className:(0,b.cn)(L[t.variant],c),"data-state":s?"open":"closed","data-testid":"accordion-item",children:n})})}function B({className:e,icon:r,children:c}){let n=v(),t=k(),s=w[n.size],l=()=>{t.disabled||n.toggle(t.value)},u=i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),l())},a=r??n.icon??(0,d.jsx)(V,{className:s.icon}),g=!n.hideIcon&&(0,d.jsx)("span",{className:(0,b.cn)("shrink-0 text-gray-500 dark:text-gray-400 transition-transform duration-200",t.isOpen&&"rotate-180"),"data-testid":"accordion-icon",children:a});return(0,d.jsxs)("button",{type:"button",id:t.triggerId,"aria-expanded":t.isOpen,"aria-controls":t.contentId,disabled:t.disabled,onClick:l,onKeyDown:u,className:(0,b.cn)("flex items-center w-full text-left font-medium transition-colors cursor-pointer",s.trigger,s.text,"text-gray-900 dark:text-gray-100",!t.disabled&&"hover:bg-gray-50 dark:hover:bg-gray-800/50",t.disabled&&"opacity-50 cursor-not-allowed",e),"data-testid":"accordion-trigger",children:[n.iconPosition==="left"&&g,(0,d.jsx)("span",{className:"flex-1",children:c}),n.iconPosition==="right"&&g]})}function F({className:e,children:r}){let c=v(),n=k(),t=w[c.size],s=(0,o.useRef)(null),l=(0,o.useRef)(null),[u,a]=(0,o.useState)(n.isOpen?void 0:0),g=(0,o.useRef)(!0);return(0,o.useEffect)(()=>{let i=l.current;i&&(n.isOpen?i.removeAttribute("inert"):i.setAttribute("inert",""))},[n.isOpen]),(0,o.useEffect)(()=>{if(g.current){g.current=!1,a(n.isOpen?void 0:0);return}if(n.isOpen){let i=s.current;if(i){a(i.scrollHeight);let y=setTimeout(()=>a(void 0),200);return()=>clearTimeout(y)}}else{let i=s.current;i&&(a(i.scrollHeight),requestAnimationFrame(()=>a(0)))}},[n.isOpen]),(0,d.jsx)("div",{ref:l,id:n.contentId,role:"region","aria-labelledby":n.triggerId,className:"overflow-hidden transition-[height] duration-200 ease-in-out",style:{height:u===void 0?"auto":u},"data-testid":"accordion-content","data-state":n.isOpen?"open":"closed",children:(0,d.jsx)("div",{ref:s,className:(0,b.cn)(t.content,"text-gray-600 dark:text-gray-400",t.text==="text-lg"?"text-base":"text-sm",e),children:r})})}0&&(module.exports={Accordion,AccordionContent,AccordionItem,AccordionTrigger});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{createContext as
|
|
1
|
+
"use client";import{createContext as N,useContext as k,useState as w,useCallback as M,useMemo as A,useRef as y,useEffect as C,useId as S}from"react";import{cn as x}from"../../lib/cn.js";import{jsx as a,jsxs as $}from"react/jsx-runtime";var R=N(null),O=N(null);function v(){let t=k(R);if(!t)throw new Error("Accordion sub-components must be used within <Accordion>");return t}function P(){let t=k(O);if(!t)throw new Error("AccordionTrigger/AccordionContent must be used within <AccordionItem>");return t}var T={sm:{trigger:"px-3 py-2",content:"px-3 pb-2",text:"text-sm",icon:"w-3.5 h-3.5"},md:{trigger:"px-4 py-3",content:"px-4 pb-3",text:"text-base",icon:"w-4 h-4"},lg:{trigger:"px-5 py-4",content:"px-5 pb-4",text:"text-lg",icon:"w-5 h-5"}},V=({className:t})=>a("svg",{className:t,viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:a("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})}),K={default:"border border-gray-200 dark:border-gray-700 rounded-lg divide-y divide-gray-200 dark:divide-gray-700",bordered:"border-2 border-gray-300 dark:border-gray-600 rounded-lg divide-y divide-gray-300 dark:divide-gray-600",separated:"space-y-2",ghost:""},L={default:"",bordered:"",separated:"border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden",ghost:"border-b border-gray-200 dark:border-gray-700 last:border-b-0"};function F({type:t="single",value:c,defaultValue:l,onValueChange:e,collapsible:n=!1,variant:r="default",size:s="md",disabled:g=!1,iconPosition:i="right",icon:d,hideIcon:o=!1,className:m,children:z}){let[h,E]=w(()=>l?Array.isArray(l)?l:[l]:[]),b=c!==void 0,u=A(()=>b?Array.isArray(c)?c:[c]:h,[b,c,h]),I=M(p=>{let f;t==="single"?u.includes(p)?f=n?[]:[p]:f=[p]:f=u.includes(p)?u.filter(H=>H!==p):[...u,p],b||E(f),e?.(t==="single"?f[0]??"":f)},[t,u,n,b,e]),D=A(()=>({openItems:u,toggle:I,variant:r,size:s,disabled:g,iconPosition:i,icon:d??null,hideIcon:o}),[u,I,r,s,g,i,d,o]);return a(R.Provider,{value:D,children:a("div",{className:x(K[r],m),"data-testid":"accordion",children:z})})}function G({value:t,disabled:c,className:l,children:e}){let n=v(),r=n.openItems.includes(t),s=c??n.disabled,g=S(),i=`accordion-trigger-${g}`,d=`accordion-content-${g}`,o=A(()=>({value:t,isOpen:r,disabled:s,triggerId:i,contentId:d}),[t,r,s,i,d]);return a(O.Provider,{value:o,children:a("div",{className:x(L[n.variant],l),"data-state":r?"open":"closed","data-testid":"accordion-item",children:e})})}function J({className:t,icon:c,children:l}){let e=v(),n=P(),r=T[e.size],s=()=>{n.disabled||e.toggle(n.value)},g=o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),s())},i=c??e.icon??a(V,{className:r.icon}),d=!e.hideIcon&&a("span",{className:x("shrink-0 text-gray-500 dark:text-gray-400 transition-transform duration-200",n.isOpen&&"rotate-180"),"data-testid":"accordion-icon",children:i});return $("button",{type:"button",id:n.triggerId,"aria-expanded":n.isOpen,"aria-controls":n.contentId,disabled:n.disabled,onClick:s,onKeyDown:g,className:x("flex items-center w-full text-left font-medium transition-colors cursor-pointer",r.trigger,r.text,"text-gray-900 dark:text-gray-100",!n.disabled&&"hover:bg-gray-50 dark:hover:bg-gray-800/50",n.disabled&&"opacity-50 cursor-not-allowed",t),"data-testid":"accordion-trigger",children:[e.iconPosition==="left"&&d,a("span",{className:"flex-1",children:l}),e.iconPosition==="right"&&d]})}function Q({className:t,children:c}){let l=v(),e=P(),n=T[l.size],r=y(null),s=y(null),[g,i]=w(e.isOpen?void 0:0),d=y(!0);return C(()=>{let o=s.current;o&&(e.isOpen?o.removeAttribute("inert"):o.setAttribute("inert",""))},[e.isOpen]),C(()=>{if(d.current){d.current=!1,i(e.isOpen?void 0:0);return}if(e.isOpen){let o=r.current;if(o){i(o.scrollHeight);let m=setTimeout(()=>i(void 0),200);return()=>clearTimeout(m)}}else{let o=r.current;o&&(i(o.scrollHeight),requestAnimationFrame(()=>i(0)))}},[e.isOpen]),a("div",{ref:s,id:e.contentId,role:"region","aria-labelledby":e.triggerId,className:"overflow-hidden transition-[height] duration-200 ease-in-out",style:{height:g===void 0?"auto":g},"data-testid":"accordion-content","data-state":e.isOpen?"open":"closed",children:a("div",{ref:r,className:x(n.content,"text-gray-600 dark:text-gray-400",n.text==="text-lg"?"text-base":"text-sm",t),children:c})})}export{F as Accordion,Q as AccordionContent,G as AccordionItem,J as AccordionTrigger};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var Ne=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var Qe=Object.prototype.hasOwnProperty;var et=(c,u)=>{for(var n in u)Ne(c,n,{get:u[n],enumerable:!0})},tt=(c,u,n,d)=>{if(u&&typeof u=="object"||typeof u=="function")for(let p of Je(u))!Qe.call(c,p)&&p!==n&&Ne(c,p,{get:()=>u[p],enumerable:!(d=qe(u,p))||d.enumerable});return c};var nt=c=>tt(Ne({},"__esModule",{value:!0}),c);var ct={};et(ct,{AreaChart:()=>ut});module.exports=nt(ct);var l=require("react"),_e=require("../../lib/cn.cjs"),Ce=require("../../lib/i18n.cjs"),ae=require("../chart/ChartAnnotations.cjs"),De=require("../chart/ChartAxis.cjs"),q=require("../chart/ChartBrush.cjs"),Oe=require("../chart/ChartContainer.cjs"),Ge=require("../chart/ChartGrid.cjs"),Xe=require("../chart/ChartLegend.cjs"),ve=require("../chart/ChartPatterns.cjs"),$e=require("../chart/ChartSync.cjs"),Ue=require("../chart/ChartTableView.cjs"),ke=require("../chart/ChartTooltip.cjs"),A=require("../chart/palette.cjs"),g=require("../chart/utils/cartesian.cjs"),xe=require("../chart/utils/data.cjs"),se=require("../chart/utils/decimate.cjs"),W=require("../chart/utils/format.cjs"),Se=require("../chart/utils/keyboard.cjs"),I=require("../chart/utils/path.cjs"),Z=require("../chart/utils/scales.cjs"),Pe=require("../chart/utils/stack.cjs"),ze=require("../chart/utils/ticks.cjs"),Ye=require("../chart/utils/timestamp.cjs"),Fe=require("../chart/utils/touch.cjs"),r=require("react/jsx-runtime"),ot=6,rt=.12,at=.9,st=10,lt=(0,l.memo)(function({bands:u,stacked:n,patterns:d,patternBaseId:p}){return(0,r.jsx)("g",{children:u.map(m=>(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:m.area,fill:(0,ve.patternFill)(d,p,m.slot,m.color),fillOpacity:n?at:rt,stroke:"none"}),m.gap?(0,r.jsx)("path",{d:m.gap,fill:"none",strokeWidth:2,stroke:A.CHART_SURFACE_COLOR}):null,(0,r.jsx)("path",{d:m.edge,fill:"none",stroke:m.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),m.isolated.map((P,$)=>(0,r.jsx)("circle",{cx:P.x,cy:P.y,r:3,fill:m.color,strokeWidth:2,stroke:A.CHART_SURFACE_COLOR},$))]},m.key))})});function it({width:c,height:u,data:n,resolvedSeries:d,x:p,y:m,grid:P,size:$,curve:L,stack:M,baseline:N,connectNulls:D,referenceLines:K,annotations:w,annotationsLabel:Ae,patterns:le,patternBaseId:ie,overlay:Le,maxPoints:B,brush:ue,onBrush:ce,brushLabel:Re,syncEnabled:J,margin:he,tooltip:_,onPointClick:V,plotLabel:we,formatValue:O,formatRaw:U,formatX:z,locale:me}){let[Q,ee]=(0,l.useState)(null),h=Q!==null&&Q<n.length?Q:null,[Be,Ve]=(0,l.useState)(null),Ee=(0,$e.useChartSync)(),b=J?Ee:null,e=(0,l.useMemo)(()=>{let t=d.filter(x=>!x.hidden),o=t.map(x=>x.key),s=M!=="none",i=(0,Pe.stackSeries)(n,o,M),G=(0,g.widenBounds)(s?(0,Pe.stackExtent)(i):(0,ze.extent)([...(0,xe.collectAllValues)(n,o),N]),(0,g.annotationValues)(n,p.key,K,w)),f=(0,g.buildCartesianGeometry)({locale:me,width:c,height:u,data:n,x:p,y:m,bounds:G,margin:he,placement:"point",formatValue:O,formatX:z,defaultIncludeZero:!0}),F=f.categoryCenters,y=f.valueScale,k=y(s?0:N),re=t.map((x,X)=>({top:n.map((j,H)=>{let S=i[H].segments[X];return{x:F[H],y:S.value===null?Number.NaN:y(S.end),defined:S.value!==null}}),bottom:n.map((j,H)=>{let S=i[H].segments[X];return{x:F[H],y:S.value===null?Number.NaN:y(s?S.start:N),defined:S.value!==null}})})),We=B!==void 0&&B>0&&n.length>B,je=We&&s?[...new Set(re.flatMap(({top:x})=>(0,se.decimateIndices)(x,B)))].sort((x,X)=>x-X):null,Ze=t.map((x,X)=>{let{top:j,bottom:H}=re[X],S={connectNulls:D},be=je??(We?(0,se.decimateIndices)(j,B):null),ye=be?be.map(Me=>j[Me]):j,Ke=be?be.map(Me=>H[Me]):H;return B||(0,se.warnPointBudget)("AreaChart",j.length),{key:x.key,color:x.color,slot:x.slot,area:s?(0,I.buildAreaPath)(ye,Ke,L,S):(0,I.buildAreaPath)(ye,k,L,S),edge:(0,I.buildLinePath)(ye,L,S),gap:s&&X>0?(0,I.buildLinePath)(Ke,L,S):"",isolated:(0,I.isolatedPoints)(ye,D)}});return{visible:t,locate:(0,g.createCategoryLocator)(f),span:(0,g.createSpanLocator)(f),plot:(0,g.createPlotContext)({geometry:f,width:c,height:u,data:n,series:t,formatValue:O,formatX:z}),rows:i,stacked:s,xValues:f.xValues,positions:F,xTicks:f.categoryTicks,yTicks:f.valueTicks,valueScale:y,innerWidth:f.innerWidth,innerHeight:f.innerHeight,margin:f.margin,bands:Ze}},[me,n,d,p,m,c,u,he,L,M,N,D,B,K,w,O,z]),te=(0,l.useCallback)(t=>e.visible.map((o,s)=>{let i=(0,xe.readNumber)(n[t],o.key),G=e.rows[t].segments[s],f=i===null?"\u2014":M==="percent"?`${U(i)} (${O(G.end-G.start)})`:U(i);return{seriesKey:o.key,seriesLabel:(0,A.getSeriesLabel)(o),color:o.color,value:i,formattedValue:f,datum:n[t]}}),[n,e.visible,e.rows,M,O,U]),v=b?b.brush:Be,de=(0,l.useCallback)(t=>{Ve(t),b?.setBrush(t),ce?.(t)},[b,ce]),C=(0,q.useChartBrush)({enabled:ue,active:v!==null,centers:e.positions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:de}),Te=(0,l.useCallback)(t=>{if(C.onPointerMove(t),_===!1||n.length===0)return;let o=t.currentTarget.getBoundingClientRect(),s=t.clientX-o.left-e.margin.left,i=(0,Z.nearestIndex)(e.positions,s);ee(i>=0?i:null),b?.setHovered(i>=0?e.xValues[i]:null)},[C,_,n.length,e.margin.left,e.positions,e.xValues,b]),pe=(0,l.useCallback)(()=>{ee(null),b?.setHovered(null)},[b]),R=(0,l.useCallback)((t,o)=>{if(!V)return;let s=te(t),i=e.rows[t]?.segments??[],G=s.map((y,k)=>({point:y,segment:i[k]})).filter(({point:y,segment:k})=>y.value!==null&&k!==void 0),f=({segment:y})=>{if(o===null)return 0;let k=e.valueScale(y.end),re=e.valueScale(e.stacked?y.start:y.end);return e.stacked&&o.y>=Math.min(k,re)&&o.y<=Math.max(k,re)?-1:Math.abs(k-o.y)},F=G.length>0?G.reduce((y,k)=>f(k)<f(y)?k:y).point:s[0];F&&V({...F,index:t,x:e.xValues[t]})},[V,te,e.rows,e.stacked,e.valueScale,e.xValues]),T=(0,l.useCallback)(t=>{if(n.length===0)return;let o=V&&h!==null&&e.visible.length>0;if((0,Se.pressChartMark)(t,o?()=>R(h,null):null))return;let s=C.onKeyDown(t,h),i=(0,Se.chartCursorTarget)(t.key,h,n.length,"x");if(i===void 0){s&&t.preventDefault();return}t.preventDefault(),ee(i),b?.setHovered(i===null?null:e.xValues[i])},[n.length,h,C,b,e.xValues,e.visible.length,V,R]),He=(0,l.useCallback)(t=>{if(C.consumedClick()||!V||n.length===0)return;let o=(0,g.plotPointer)(t,e),s=h??(o===null?-1:(0,Z.nearestIndex)(e.positions,o.x));s<0||R(s,o)},[C,V,n.length,e,h,R]),Ie=h!==null||b===null||b.hovered===null?null:(()=>{let t=(0,Z.toKey)(b.hovered),o=e.xValues.findIndex(s=>(0,Z.toKey)(s)===t);return o<0?null:o})(),E=h??Ie,ne=h===null?null:te(h),oe=E===null?[]:e.visible.map((t,o)=>{let s=e.rows[E].segments[o];return s.value===null?null:{key:t.key,color:t.color,y:e.valueScale(s.end)}}).filter(t=>t!==null),fe=C.dragging??v,Y=fe?(0,q.locateBrush)(fe,e.xValues,e.positions,e.locate):null,ge=(0,g.splitOverlay)(Le),a=h===null||ne===null?null:{x:e.xValues[h],xLabel:z(e.xValues[h],h),index:h,points:ne};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("svg",{width:c,height:u,role:"img","aria-label":we??[e.visible.map(t=>(0,A.getSeriesLabel)(t)).join(", "),(0,ae.describeAnnotations)(w,Ae)].filter(Boolean).join(". "),tabIndex:0,className:(0,_e.cn)(Fe.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",ue&&"select-none"),onPointerDown:C.onPointerDown,onPointerMove:Te,onPointerUp:C.onPointerUp,onPointerCancel:C.onPointerUp,onPointerLeave:pe,onKeyDown:T,onBlur:pe,onClick:He,children:[le?(0,r.jsx)(ve.ChartPatternDefs,{id:ie,entries:d.map(t=>({slot:t.slot,color:t.color}))}):null,(0,r.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,r.jsx)(Ge.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:P==="y"||P==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:P==="x"||P==="both"?e.xTicks.map(t=>t.offset):void 0}),w?(0,r.jsx)(ae.ChartAnnotationLayer,{layer:"under",annotations:w,xAt:e.locate,spanAt:e.span,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,Y?(0,r.jsx)(q.ChartBrushLayer,{from:Y.from,to:Y.to,width:e.innerWidth,height:e.innerHeight,live:C.dragging!==null,label:Re,minSpan:ot}):null,ge.under?.(e.plot),(0,r.jsx)(lt,{bands:e.bands,stacked:e.stacked,patterns:le&&e.stacked,patternBaseId:ie}),w?(0,r.jsx)(ae.ChartAnnotationLayer,{annotations:w,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,K?.map(t=>{let o=e.valueScale(t.value),s=o<st?o+12:o-4;return(0,r.jsxs)("g",{children:[(0,r.jsx)("line",{x1:0,y1:o,x2:e.innerWidth,y2:o,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,r.jsx)("text",{x:e.innerWidth,y:s,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),ge.over?.(e.plot),E!==null?(0,r.jsxs)("g",{"aria-hidden":"true",children:[(0,r.jsx)("line",{x1:e.positions[E],y1:0,x2:e.positions[E],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:h===null?"3 3":void 0}),oe.map(t=>(0,r.jsx)("circle",{cx:e.positions[E],cy:t.y,r:4,fill:t.color,strokeWidth:2,stroke:A.CHART_SURFACE_COLOR},t.key))]}):null]}),(0,r.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:p.hidden?null:(0,r.jsx)(De.ChartAxis,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:p.label,size:$})}),(0,r.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:m?.hidden?null:(0,r.jsx)(De.ChartAxis,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:m?.label,size:$})})]}),a&&_!==!1?(0,r.jsx)(ke.ChartTooltip,{x:e.margin.left+e.positions[a.index],y:e.margin.top+(oe.length>0?Math.min(...oe.map(t=>t.y)):e.innerHeight/2),containerWidth:c,children:typeof _=="function"?_(a):(0,r.jsx)(ke.ChartTooltipContent,{title:a.xLabel,points:a.points})}):null]})}function ut({data:c,series:u,x:n,y:d,height:p=240,width:m,size:P="md",grid:$="y",legend:L,tooltip:M=!0,tableView:N=!1,emphasis:D,title:K,description:w,loading:Ae=!1,emptyState:le,error:ie=!1,errorState:Le,onRetry:B,actions:ue,onPointClick:ce,curve:Re="monotone",stack:J="none",baseline:he=0,connectNulls:_=!1,referenceLines:V,annotations:we,overlay:O,patterns:U=!1,legendToggle:z=!0,maxPoints:me,brush:Q=!1,onBrush:ee,brushLabel:h,sync:Be=!0,margin:Ve,locale:Ee,plotLabel:b,className:e,...te}){let v=(0,Ce.useUILocale)(Ee),de=(0,Ce.useUILabels)(),[C,Te]=(0,l.useState)(()=>new Set),pe=(0,l.useId)(),R=(0,l.useMemo)(()=>u.map((a,t)=>({...a,slot:t,hidden:a.hidden||C.has(a.key),color:(0,A.resolveSeriesColor)(a,t,D)})),[u,C,D]),T=J==="percent",He=(0,l.useMemo)(()=>T?{domain:[0,100],...d}:d,[T,d]),Ie=(0,l.useMemo)(()=>d?.format??(T?a=>(0,W.formatPercent)(a,{locale:v,alreadyScaled:!0,maximumFractionDigits:0}):a=>(0,W.formatAuto)(a,v)),[d?.format,T,v]),E=(0,l.useMemo)(()=>!T&&d?.format||(a=>(0,W.formatExact)(a,v)),[T,d?.format,v]),ne=(0,l.useMemo)(()=>n.format??(a=>n.scale==="time"?(0,Ye.formatTimeValue)(a,v):(0,W.formatXValue)(a,v)),[n.format,n.scale,v]),oe=(0,l.useCallback)(a=>{Te(t=>{let o=new Set(t);return o.has(a)?o.delete(a):o.add(a),o})},[]),fe=L===void 0?u.length>=2:L!==!1,Y=typeof L=="string"?L:"bottom",ge=R.filter(a=>!a.hidden).length;return(0,r.jsx)(Oe.ChartContainer,{title:K,description:w,height:p,width:m,size:P,loading:Ae,empty:c.length===0||ge===0,emptyState:le,error:ie,errorState:Le,onRetry:B,actions:ue,exportSource:{data:c,series:R,xKey:n.key,xLabel:n.label??n.key,formatX:n.format},tableView:N,legendPosition:Y,legend:fe?(0,r.jsx)(Xe.ChartLegend,{items:(0,A.toLegendItems)(R,D,U&&J!=="none"),position:Y,marker:"rect",size:P,onToggle:z?oe:void 0}):void 0,table:N?(0,r.jsx)(Ue.ChartTableView,{data:c,series:R,xKey:n.key,xLabel:n.label??n.key,formatX:ne,formatValue:E,caption:typeof K=="string"?K:void 0}):void 0,className:e,...te,children:({width:a})=>(0,r.jsx)(it,{locale:v,width:a,height:p,data:c,resolvedSeries:R,x:n,y:He,grid:$,size:P,curve:Re,stack:J,baseline:he,connectNulls:_,referenceLines:V,annotations:we,annotationsLabel:de.chartAnnotations,patterns:U,patternBaseId:pe,overlay:O,maxPoints:me,brush:Q,onBrush:ee,brushLabel:h??de.chartBrush,syncEnabled:Be,margin:Ve,tooltip:M,onPointClick:ce,plotLabel:b,formatValue:Ie,formatRaw:E,formatX:ne})})}0&&(module.exports={AreaChart});
|
|
1
|
+
"use strict";"use client";var Ne=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var Qe=Object.prototype.hasOwnProperty;var et=(c,u)=>{for(var n in u)Ne(c,n,{get:u[n],enumerable:!0})},tt=(c,u,n,d)=>{if(u&&typeof u=="object"||typeof u=="function")for(let p of Je(u))!Qe.call(c,p)&&p!==n&&Ne(c,p,{get:()=>u[p],enumerable:!(d=qe(u,p))||d.enumerable});return c};var nt=c=>tt(Ne({},"__esModule",{value:!0}),c);var ct={};et(ct,{AreaChart:()=>ut});module.exports=nt(ct);var l=require("react"),_e=require("../../lib/cn.cjs"),Ce=require("../../lib/i18n.cjs"),ae=require("../chart/ChartAnnotations.cjs"),De=require("../chart/ChartAxis.cjs"),q=require("../chart/ChartBrush.cjs"),Oe=require("../chart/ChartContainer.cjs"),Ge=require("../chart/ChartGrid.cjs"),Xe=require("../chart/ChartLegend.cjs"),ve=require("../chart/ChartPatterns.cjs"),$e=require("../chart/ChartSync.cjs"),Ue=require("../chart/ChartTableView.cjs"),ke=require("../chart/ChartTooltip.cjs"),A=require("../chart/palette.cjs"),g=require("../chart/utils/cartesian.cjs"),xe=require("../chart/utils/data.cjs"),se=require("../chart/utils/decimate.cjs"),W=require("../chart/utils/format.cjs"),Pe=require("../chart/utils/keyboard.cjs"),I=require("../chart/utils/path.cjs"),Z=require("../chart/utils/scales.cjs"),Se=require("../chart/utils/stack.cjs"),ze=require("../chart/utils/ticks.cjs"),Ye=require("../chart/utils/timestamp.cjs"),Fe=require("../chart/utils/touch.cjs"),r=require("react/jsx-runtime"),ot=6,rt=.12,at=.9,st=10,lt=(0,l.memo)(function({bands:u,stacked:n,patterns:d,patternBaseId:p}){return(0,r.jsx)("g",{children:u.map(m=>(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:m.area,fill:(0,ve.patternFill)(d,p,m.slot,m.color),fillOpacity:n?at:rt,stroke:"none"}),m.gap?(0,r.jsx)("path",{d:m.gap,fill:"none",strokeWidth:2,stroke:A.CHART_SURFACE_COLOR}):null,(0,r.jsx)("path",{d:m.edge,fill:"none",stroke:m.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),m.isolated.map((S,$)=>(0,r.jsx)("circle",{cx:S.x,cy:S.y,r:3,fill:m.color,strokeWidth:2,stroke:A.CHART_SURFACE_COLOR},$))]},m.key))})});function it({width:c,height:u,data:n,resolvedSeries:d,x:p,y:m,grid:S,size:$,curve:L,stack:M,baseline:N,connectNulls:D,referenceLines:K,annotations:B,annotationsLabel:Ae,patterns:le,patternBaseId:ie,overlay:Le,maxPoints:w,brush:ue,onBrush:ce,brushLabel:Re,syncEnabled:J,margin:he,tooltip:_,onPointClick:V,plotLabel:Be,formatValue:O,formatRaw:U,formatX:z,locale:me}){let[Q,ee]=(0,l.useState)(null),h=Q!==null&&Q<n.length?Q:null,[we,Ve]=(0,l.useState)(null),Ee=(0,$e.useChartSync)(),b=J?Ee:null,e=(0,l.useMemo)(()=>{let t=d.filter(x=>!x.hidden),o=t.map(x=>x.key),s=M!=="none",i=(0,Se.stackSeries)(n,o,M),G=(0,g.widenBounds)(s?(0,Se.stackExtent)(i):(0,ze.extent)([...(0,xe.collectAllValues)(n,o),N]),(0,g.annotationValues)(n,p.key,K,B)),f=(0,g.buildCartesianGeometry)({locale:me,width:c,height:u,data:n,x:p,y:m,bounds:G,margin:he,placement:"point",formatValue:O,formatX:z,defaultIncludeZero:!0}),F=f.categoryCenters,y=f.valueScale,k=y(s?0:N),re=t.map((x,X)=>({top:n.map((j,H)=>{let P=i[H].segments[X];return{x:F[H],y:P.value===null?Number.NaN:y(P.end),defined:P.value!==null}}),bottom:n.map((j,H)=>{let P=i[H].segments[X];return{x:F[H],y:P.value===null?Number.NaN:y(s?P.start:N),defined:P.value!==null}})})),We=w!==void 0&&w>0&&n.length>w,je=We&&s?[...new Set(re.flatMap(({top:x})=>(0,se.decimateIndices)(x,w)))].sort((x,X)=>x-X):null,Ze=t.map((x,X)=>{let{top:j,bottom:H}=re[X],P={connectNulls:D},be=je??(We?(0,se.decimateIndices)(j,w):null),ye=be?be.map(Me=>j[Me]):j,Ke=be?be.map(Me=>H[Me]):H;return w||(0,se.warnPointBudget)("AreaChart",j.length),{key:x.key,color:x.color,slot:x.slot,area:s?(0,I.buildAreaPath)(ye,Ke,L,P):(0,I.buildAreaPath)(ye,k,L,P),edge:(0,I.buildLinePath)(ye,L,P),gap:s&&X>0?(0,I.buildLinePath)(Ke,L,P):"",isolated:(0,I.isolatedPoints)(ye,D)}});return{visible:t,locate:(0,g.createCategoryLocator)(f),span:(0,g.createSpanLocator)(f),plot:(0,g.createPlotContext)({geometry:f,width:c,height:u,data:n,series:t,formatValue:O,formatX:z}),rows:i,stacked:s,xValues:f.xValues,positions:F,xTicks:f.categoryTicks,yTicks:f.valueTicks,valueScale:y,innerWidth:f.innerWidth,innerHeight:f.innerHeight,margin:f.margin,bands:Ze}},[me,n,d,p,m,c,u,he,L,M,N,D,w,K,B,O,z]),te=(0,l.useCallback)(t=>e.visible.map((o,s)=>{let i=(0,xe.readNumber)(n[t],o.key),G=e.rows[t].segments[s],f=i===null?"\u2014":M==="percent"?`${U(i)} (${O(G.end-G.start)})`:U(i);return{seriesKey:o.key,seriesLabel:(0,A.getSeriesLabel)(o),color:o.color,value:i,formattedValue:f,datum:n[t]}}),[n,e.visible,e.rows,M,O,U]),v=b?b.brush:we,de=(0,l.useCallback)(t=>{Ve(t),b?.setBrush(t),ce?.(t)},[b,ce]),C=(0,q.useChartBrush)({enabled:ue,active:v!==null,centers:e.positions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:de}),Te=(0,l.useCallback)(t=>{if(C.onPointerMove(t),_===!1||n.length===0)return;let o=t.currentTarget.getBoundingClientRect(),s=t.clientX-o.left-e.margin.left,i=(0,Z.nearestIndex)(e.positions,s);ee(i>=0?i:null),b?.setHovered(i>=0?e.xValues[i]:null)},[C,_,n.length,e.margin.left,e.positions,e.xValues,b]),pe=(0,l.useCallback)(()=>{ee(null),b?.setHovered(null)},[b]),R=(0,l.useCallback)((t,o)=>{if(!V)return;let s=te(t),i=e.rows[t]?.segments??[],G=s.map((y,k)=>({point:y,segment:i[k]})).filter(({point:y,segment:k})=>y.value!==null&&k!==void 0),f=({segment:y})=>{if(o===null)return 0;let k=e.valueScale(y.end),re=e.valueScale(e.stacked?y.start:y.end);return e.stacked&&o.y>=Math.min(k,re)&&o.y<=Math.max(k,re)?-1:Math.abs(k-o.y)},F=G.length>0?G.reduce((y,k)=>f(k)<f(y)?k:y).point:s[0];F&&V({...F,index:t,x:e.xValues[t]})},[V,te,e]),T=(0,l.useCallback)(t=>{if(n.length===0)return;let o=V&&h!==null&&e.visible.length>0;if((0,Pe.pressChartMark)(t,o?()=>R(h,null):null))return;let s=C.onKeyDown(t,h),i=(0,Pe.chartCursorTarget)(t.key,h,n.length,"x");if(i===void 0){s&&t.preventDefault();return}t.preventDefault(),ee(i),b?.setHovered(i===null?null:e.xValues[i])},[n.length,h,C,b,e.xValues,e.visible.length,V,R]),He=(0,l.useCallback)(t=>{if(C.consumedClick()||!V||n.length===0)return;let o=(0,g.plotPointer)(t,e),s=h??(o===null?-1:(0,Z.nearestIndex)(e.positions,o.x));s<0||R(s,o)},[C,V,n.length,e,h,R]),Ie=h!==null||b===null||b.hovered===null?null:(()=>{let t=(0,Z.toKey)(b.hovered),o=e.xValues.findIndex(s=>(0,Z.toKey)(s)===t);return o<0?null:o})(),E=h??Ie,ne=h===null?null:te(h),oe=E===null?[]:e.visible.map((t,o)=>{let s=e.rows[E].segments[o];return s.value===null?null:{key:t.key,color:t.color,y:e.valueScale(s.end)}}).filter(t=>t!==null),fe=C.dragging??v,Y=fe?(0,q.locateBrush)(fe,e.xValues,e.positions,e.locate):null,ge=(0,g.splitOverlay)(Le),a=h===null||ne===null?null:{x:e.xValues[h],xLabel:z(e.xValues[h],h),index:h,points:ne};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("svg",{width:c,height:u,role:"img","aria-label":Be??[e.visible.map(t=>(0,A.getSeriesLabel)(t)).join(", "),(0,ae.describeAnnotations)(B,Ae)].filter(Boolean).join(". "),tabIndex:0,className:(0,_e.cn)(Fe.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",ue&&"select-none"),onPointerDown:C.onPointerDown,onPointerMove:Te,onPointerUp:C.onPointerUp,onPointerCancel:C.onPointerUp,onPointerLeave:pe,onKeyDown:T,onBlur:pe,onClick:He,children:[le?(0,r.jsx)(ve.ChartPatternDefs,{id:ie,entries:d.map(t=>({slot:t.slot,color:t.color}))}):null,(0,r.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,r.jsx)(Ge.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:S==="y"||S==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:S==="x"||S==="both"?e.xTicks.map(t=>t.offset):void 0}),B?(0,r.jsx)(ae.ChartAnnotationLayer,{layer:"under",annotations:B,xAt:e.locate,spanAt:e.span,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,Y?(0,r.jsx)(q.ChartBrushLayer,{from:Y.from,to:Y.to,width:e.innerWidth,height:e.innerHeight,live:C.dragging!==null,label:Re,minSpan:ot}):null,ge.under?.(e.plot),(0,r.jsx)(lt,{bands:e.bands,stacked:e.stacked,patterns:le&&e.stacked,patternBaseId:ie}),B?(0,r.jsx)(ae.ChartAnnotationLayer,{annotations:B,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,K?.map(t=>{let o=e.valueScale(t.value),s=o<st?o+12:o-4;return(0,r.jsxs)("g",{children:[(0,r.jsx)("line",{x1:0,y1:o,x2:e.innerWidth,y2:o,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,r.jsx)("text",{x:e.innerWidth,y:s,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),ge.over?.(e.plot),E!==null?(0,r.jsxs)("g",{"aria-hidden":"true",children:[(0,r.jsx)("line",{x1:e.positions[E],y1:0,x2:e.positions[E],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:h===null?"3 3":void 0}),oe.map(t=>(0,r.jsx)("circle",{cx:e.positions[E],cy:t.y,r:4,fill:t.color,strokeWidth:2,stroke:A.CHART_SURFACE_COLOR},t.key))]}):null]}),(0,r.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:p.hidden?null:(0,r.jsx)(De.ChartAxis,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:p.label,size:$})}),(0,r.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:m?.hidden?null:(0,r.jsx)(De.ChartAxis,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:m?.label,size:$})})]}),a&&_!==!1?(0,r.jsx)(ke.ChartTooltip,{x:e.margin.left+e.positions[a.index],y:e.margin.top+(oe.length>0?Math.min(...oe.map(t=>t.y)):e.innerHeight/2),containerWidth:c,children:typeof _=="function"?_(a):(0,r.jsx)(ke.ChartTooltipContent,{title:a.xLabel,points:a.points})}):null]})}function ut({data:c,series:u,x:n,y:d,height:p=240,width:m,size:S="md",grid:$="y",legend:L,tooltip:M=!0,tableView:N=!1,emphasis:D,title:K,description:B,loading:Ae=!1,emptyState:le,error:ie=!1,errorState:Le,onRetry:w,actions:ue,onPointClick:ce,curve:Re="monotone",stack:J="none",baseline:he=0,connectNulls:_=!1,referenceLines:V,annotations:Be,overlay:O,patterns:U=!1,legendToggle:z=!0,maxPoints:me,brush:Q=!1,onBrush:ee,brushLabel:h,sync:we=!0,margin:Ve,locale:Ee,plotLabel:b,className:e,...te}){let v=(0,Ce.useUILocale)(Ee),de=(0,Ce.useUILabels)(),[C,Te]=(0,l.useState)(()=>new Set),pe=(0,l.useId)(),R=(0,l.useMemo)(()=>u.map((a,t)=>({...a,slot:t,hidden:a.hidden||C.has(a.key),color:(0,A.resolveSeriesColor)(a,t,D)})),[u,C,D]),T=J==="percent",He=(0,l.useMemo)(()=>T?{domain:[0,100],...d}:d,[T,d]),Ie=(0,l.useMemo)(()=>d?.format??(T?a=>(0,W.formatPercent)(a,{locale:v,alreadyScaled:!0,maximumFractionDigits:0}):a=>(0,W.formatAuto)(a,v)),[d?.format,T,v]),E=(0,l.useMemo)(()=>!T&&d?.format||(a=>(0,W.formatExact)(a,v)),[T,d?.format,v]),ne=(0,l.useMemo)(()=>n.format??(a=>n.scale==="time"?(0,Ye.formatTimeValue)(a,v):(0,W.formatXValue)(a,v)),[n.format,n.scale,v]),oe=(0,l.useCallback)(a=>{Te(t=>{let o=new Set(t);return o.has(a)?o.delete(a):o.add(a),o})},[]),fe=L===void 0?u.length>=2:L!==!1,Y=typeof L=="string"?L:"bottom",ge=R.filter(a=>!a.hidden).length;return(0,r.jsx)(Oe.ChartContainer,{title:K,description:B,height:p,width:m,size:S,loading:Ae,empty:c.length===0||ge===0,emptyState:le,error:ie,errorState:Le,onRetry:w,actions:ue,exportSource:{data:c,series:R,xKey:n.key,xLabel:n.label??n.key,formatX:n.format},tableView:N,legendPosition:Y,legend:fe?(0,r.jsx)(Xe.ChartLegend,{items:(0,A.toLegendItems)(R,D,U&&J!=="none"),position:Y,marker:"rect",size:S,onToggle:z?oe:void 0}):void 0,table:N?(0,r.jsx)(Ue.ChartTableView,{data:c,series:R,xKey:n.key,xLabel:n.label??n.key,formatX:ne,formatValue:E,caption:typeof K=="string"?K:void 0}):void 0,className:e,...te,children:({width:a})=>(0,r.jsx)(it,{locale:v,width:a,height:p,data:c,resolvedSeries:R,x:n,y:He,grid:$,size:S,curve:Re,stack:J,baseline:he,connectNulls:_,referenceLines:V,annotations:Be,annotationsLabel:de.chartAnnotations,patterns:U,patternBaseId:pe,overlay:O,maxPoints:me,brush:Q,onBrush:ee,brushLabel:h??de.chartBrush,syncEnabled:we,margin:Ve,tooltip:M,onPointClick:ce,plotLabel:b,formatValue:Ie,formatRaw:E,formatX:ne})})}0&&(module.exports={AreaChart});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{memo as De,useCallback as E,useId as Ke,useMemo as z,useState as Ae}from"react";import{cn as _e}from"../../lib/cn.js";import{useUILabels as Oe,useUILocale as Ge}from"../../lib/i18n.js";import{ChartAnnotationLayer as we,describeAnnotations as Xe}from"../chart/ChartAnnotations.js";import{ChartAxis as Be}from"../chart/ChartAxis.js";import{ChartBrushLayer as $e,locateBrush as Ue,useChartBrush as ze}from"../chart/ChartBrush.js";import{ChartContainer as Ye}from"../chart/ChartContainer.js";import{ChartGrid as Fe}from"../chart/ChartGrid.js";import{ChartLegend as je}from"../chart/ChartLegend.js";import{ChartPatternDefs as Ze,patternFill as qe}from"../chart/ChartPatterns.js";import{useChartSync as Je}from"../chart/ChartSync.js";import{ChartTableView as Qe}from"../chart/ChartTableView.js";import{ChartTooltip as et,ChartTooltipContent as tt}from"../chart/ChartTooltip.js";import{CHART_SURFACE_COLOR as Le,getSeriesLabel as Ve,resolveSeriesColor as nt,toLegendItems as ot}from"../chart/palette.js";import{annotationValues as rt,buildCartesianGeometry as at,createCategoryLocator as st,createPlotContext as lt,createSpanLocator as it,plotPointer as ut,splitOverlay as ct,widenBounds as ht}from"../chart/utils/cartesian.js";import{collectAllValues as mt,readNumber as dt}from"../chart/utils/data.js";import{decimateIndices as Ee,warnPointBudget as pt}from"../chart/utils/decimate.js";import{formatAuto as ft,formatExact as gt,formatPercent as bt,formatXValue as yt}from"../chart/utils/format.js";import{chartCursorTarget as Ct,pressChartMark as vt}from"../chart/utils/keyboard.js";import{buildAreaPath as Te,buildLinePath as He,isolatedPoints as kt}from"../chart/utils/path.js";import{nearestIndex as Ie,toKey as We}from"../chart/utils/scales.js";import{stackExtent as xt,stackSeries as St}from"../chart/utils/stack.js";import{extent as Pt}from"../chart/utils/ticks.js";import{formatTimeValue as At}from"../chart/utils/timestamp.js";import{CHART_TOUCH as Lt}from"../chart/utils/touch.js";import{Fragment as Ht,jsx as s,jsxs as Y}from"react/jsx-runtime";var Rt=6,wt=.12,Bt=.9,Vt=10,Et=De(function({bands:k,stacked:o,patterns:p,patternBaseId:x}){return s("g",{children:k.map(u=>Y("g",{children:[s("path",{d:u.area,fill:qe(p,x,u.slot,u.color),fillOpacity:o?Bt:wt,stroke:"none"}),u.gap?s("path",{d:u.gap,fill:"none",strokeWidth:2,stroke:Le}):null,s("path",{d:u.edge,fill:"none",stroke:u.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),u.isolated.map((v,_)=>s("circle",{cx:v.x,cy:v.y,r:3,fill:u.color,strokeWidth:2,stroke:Le},_))]},u.key))})});function Tt({width:C,height:k,data:o,resolvedSeries:p,x,y:u,grid:v,size:_,curve:S,stack:T,baseline:H,connectNulls:I,referenceLines:W,annotations:A,annotationsLabel:de,patterns:te,patternBaseId:ne,overlay:pe,maxPoints:L,brush:oe,onBrush:re,brushLabel:fe,syncEnabled:F,margin:ae,tooltip:M,onPointClick:R,plotLabel:ge,formatValue:N,formatRaw:O,formatX:G,locale:se}){let[j,Z]=Ae(null),i=j!==null&&j<o.length?j:null,[be,ye]=Ae(null),Ce=Je(),h=F?Ce:null,e=z(()=>{let t=p.filter(b=>!b.hidden),n=t.map(b=>b.key),a=T!=="none",l=St(o,n,T),D=ht(a?xt(l):Pt([...mt(o,n),H]),rt(o,x.key,W,A)),c=at({locale:se,width:C,height:k,data:o,x,y:u,bounds:D,margin:ae,placement:"point",formatValue:N,formatX:G,defaultIncludeZero:!0}),$=c.categoryCenters,m=c.valueScale,g=m(a?0:H),ee=t.map((b,K)=>({top:o.map((U,V)=>{let y=l[V].segments[K];return{x:$[V],y:y.value===null?Number.NaN:m(y.end),defined:y.value!==null}}),bottom:o.map((U,V)=>{let y=l[V].segments[K];return{x:$[V],y:y.value===null?Number.NaN:m(a?y.start:H),defined:y.value!==null}})})),Se=L!==void 0&&L>0&&o.length>L,Me=Se&&a?[...new Set(ee.flatMap(({top:b})=>Ee(b,L)))].sort((b,K)=>b-K):null,Ne=t.map((b,K)=>{let{top:U,bottom:V}=ee[K],y={connectNulls:I},he=Me??(Se?Ee(U,L):null),me=he?he.map(Pe=>U[Pe]):U,Re=he?he.map(Pe=>V[Pe]):V;return L||pt("AreaChart",U.length),{key:b.key,color:b.color,slot:b.slot,area:a?Te(me,Re,S,y):Te(me,g,S,y),edge:He(me,S,y),gap:a&&K>0?He(Re,S,y):"",isolated:kt(me,I)}});return{visible:t,locate:st(c),span:it(c),plot:lt({geometry:c,width:C,height:k,data:o,series:t,formatValue:N,formatX:G}),rows:l,stacked:a,xValues:c.xValues,positions:$,xTicks:c.categoryTicks,yTicks:c.valueTicks,valueScale:m,innerWidth:c.innerWidth,innerHeight:c.innerHeight,margin:c.margin,bands:Ne}},[se,o,p,x,u,C,k,ae,S,T,H,I,L,W,A,N,G]),q=E(t=>e.visible.map((n,a)=>{let l=dt(o[t],n.key),D=e.rows[t].segments[a],c=l===null?"\u2014":T==="percent"?`${O(l)} (${N(D.end-D.start)})`:O(l);return{seriesKey:n.key,seriesLabel:Ve(n),color:n.color,value:l,formattedValue:c,datum:o[t]}}),[o,e.visible,e.rows,T,N,O]),f=h?h.brush:be,le=E(t=>{ye(t),h?.setBrush(t),re?.(t)},[h,re]),d=ze({enabled:oe,active:f!==null,centers:e.positions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:le}),ve=E(t=>{if(d.onPointerMove(t),M===!1||o.length===0)return;let n=t.currentTarget.getBoundingClientRect(),a=t.clientX-n.left-e.margin.left,l=Ie(e.positions,a);Z(l>=0?l:null),h?.setHovered(l>=0?e.xValues[l]:null)},[d,M,o.length,e.margin.left,e.positions,e.xValues,h]),ie=E(()=>{Z(null),h?.setHovered(null)},[h]),P=E((t,n)=>{if(!R)return;let a=q(t),l=e.rows[t]?.segments??[],D=a.map((m,g)=>({point:m,segment:l[g]})).filter(({point:m,segment:g})=>m.value!==null&&g!==void 0),c=({segment:m})=>{if(n===null)return 0;let g=e.valueScale(m.end),ee=e.valueScale(e.stacked?m.start:m.end);return e.stacked&&n.y>=Math.min(g,ee)&&n.y<=Math.max(g,ee)?-1:Math.abs(g-n.y)},$=D.length>0?D.reduce((m,g)=>c(g)<c(m)?g:m).point:a[0];$&&R({...$,index:t,x:e.xValues[t]})},[R,q,e.rows,e.stacked,e.valueScale,e.xValues]),B=E(t=>{if(o.length===0)return;let n=R&&i!==null&&e.visible.length>0;if(vt(t,n?()=>P(i,null):null))return;let a=d.onKeyDown(t,i),l=Ct(t.key,i,o.length,"x");if(l===void 0){a&&t.preventDefault();return}t.preventDefault(),Z(l),h?.setHovered(l===null?null:e.xValues[l])},[o.length,i,d,h,e.xValues,e.visible.length,R,P]),ke=E(t=>{if(d.consumedClick()||!R||o.length===0)return;let n=ut(t,e),a=i??(n===null?-1:Ie(e.positions,n.x));a<0||P(a,n)},[d,R,o.length,e,i,P]),xe=i!==null||h===null||h.hovered===null?null:(()=>{let t=We(h.hovered),n=e.xValues.findIndex(a=>We(a)===t);return n<0?null:n})(),w=i??xe,J=i===null?null:q(i),Q=w===null?[]:e.visible.map((t,n)=>{let a=e.rows[w].segments[n];return a.value===null?null:{key:t.key,color:t.color,y:e.valueScale(a.end)}}).filter(t=>t!==null),ue=d.dragging??f,X=ue?Ue(ue,e.xValues,e.positions,e.locate):null,ce=ct(pe),r=i===null||J===null?null:{x:e.xValues[i],xLabel:G(e.xValues[i],i),index:i,points:J};return Y(Ht,{children:[Y("svg",{width:C,height:k,role:"img","aria-label":ge??[e.visible.map(t=>Ve(t)).join(", "),Xe(A,de)].filter(Boolean).join(". "),tabIndex:0,className:_e(Lt,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",oe&&"select-none"),onPointerDown:d.onPointerDown,onPointerMove:ve,onPointerUp:d.onPointerUp,onPointerCancel:d.onPointerUp,onPointerLeave:ie,onKeyDown:B,onBlur:ie,onClick:ke,children:[te?s(Ze,{id:ne,entries:p.map(t=>({slot:t.slot,color:t.color}))}):null,Y("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[s(Fe,{width:e.innerWidth,height:e.innerHeight,horizontal:v==="y"||v==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:v==="x"||v==="both"?e.xTicks.map(t=>t.offset):void 0}),A?s(we,{layer:"under",annotations:A,xAt:e.locate,spanAt:e.span,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,X?s($e,{from:X.from,to:X.to,width:e.innerWidth,height:e.innerHeight,live:d.dragging!==null,label:fe,minSpan:Rt}):null,ce.under?.(e.plot),s(Et,{bands:e.bands,stacked:e.stacked,patterns:te&&e.stacked,patternBaseId:ne}),A?s(we,{annotations:A,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,W?.map(t=>{let n=e.valueScale(t.value),a=n<Vt?n+12:n-4;return Y("g",{children:[s("line",{x1:0,y1:n,x2:e.innerWidth,y2:n,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?s("text",{x:e.innerWidth,y:a,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),ce.over?.(e.plot),w!==null?Y("g",{"aria-hidden":"true",children:[s("line",{x1:e.positions[w],y1:0,x2:e.positions[w],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:i===null?"3 3":void 0}),Q.map(t=>s("circle",{cx:e.positions[w],cy:t.y,r:4,fill:t.color,strokeWidth:2,stroke:Le},t.key))]}):null]}),s("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:x.hidden?null:s(Be,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:x.label,size:_})}),s("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:u?.hidden?null:s(Be,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:u?.label,size:_})})]}),r&&M!==!1?s(et,{x:e.margin.left+e.positions[r.index],y:e.margin.top+(Q.length>0?Math.min(...Q.map(t=>t.y)):e.innerHeight/2),containerWidth:C,children:typeof M=="function"?M(r):s(tt,{title:r.xLabel,points:r.points})}):null]})}function an({data:C,series:k,x:o,y:p,height:x=240,width:u,size:v="md",grid:_="y",legend:S,tooltip:T=!0,tableView:H=!1,emphasis:I,title:W,description:A,loading:de=!1,emptyState:te,error:ne=!1,errorState:pe,onRetry:L,actions:oe,onPointClick:re,curve:fe="monotone",stack:F="none",baseline:ae=0,connectNulls:M=!1,referenceLines:R,annotations:ge,overlay:N,patterns:O=!1,legendToggle:G=!0,maxPoints:se,brush:j=!1,onBrush:Z,brushLabel:i,sync:be=!0,margin:ye,locale:Ce,plotLabel:h,className:e,...q}){let f=Ge(Ce),le=Oe(),[d,ve]=Ae(()=>new Set),ie=Ke(),P=z(()=>k.map((r,t)=>({...r,slot:t,hidden:r.hidden||d.has(r.key),color:nt(r,t,I)})),[k,d,I]),B=F==="percent",ke=z(()=>B?{domain:[0,100],...p}:p,[B,p]),xe=z(()=>p?.format??(B?r=>bt(r,{locale:f,alreadyScaled:!0,maximumFractionDigits:0}):r=>ft(r,f)),[p?.format,B,f]),w=z(()=>!B&&p?.format||(r=>gt(r,f)),[B,p?.format,f]),J=z(()=>o.format??(r=>o.scale==="time"?At(r,f):yt(r,f)),[o.format,o.scale,f]),Q=E(r=>{ve(t=>{let n=new Set(t);return n.has(r)?n.delete(r):n.add(r),n})},[]),ue=S===void 0?k.length>=2:S!==!1,X=typeof S=="string"?S:"bottom",ce=P.filter(r=>!r.hidden).length;return s(Ye,{title:W,description:A,height:x,width:u,size:v,loading:de,empty:C.length===0||ce===0,emptyState:te,error:ne,errorState:pe,onRetry:L,actions:oe,exportSource:{data:C,series:P,xKey:o.key,xLabel:o.label??o.key,formatX:o.format},tableView:H,legendPosition:X,legend:ue?s(je,{items:ot(P,I,O&&F!=="none"),position:X,marker:"rect",size:v,onToggle:G?Q:void 0}):void 0,table:H?s(Qe,{data:C,series:P,xKey:o.key,xLabel:o.label??o.key,formatX:J,formatValue:w,caption:typeof W=="string"?W:void 0}):void 0,className:e,...q,children:({width:r})=>s(Tt,{locale:f,width:r,height:x,data:C,resolvedSeries:P,x:o,y:ke,grid:_,size:v,curve:fe,stack:F,baseline:ae,connectNulls:M,referenceLines:R,annotations:ge,annotationsLabel:le.chartAnnotations,patterns:O,patternBaseId:ie,overlay:N,maxPoints:se,brush:j,onBrush:Z,brushLabel:i??le.chartBrush,syncEnabled:be,margin:ye,tooltip:T,onPointClick:re,plotLabel:h,formatValue:xe,formatRaw:w,formatX:J})})}export{an as AreaChart};
|
|
1
|
+
"use client";import{memo as De,useCallback as E,useId as Ke,useMemo as z,useState as Ae}from"react";import{cn as _e}from"../../lib/cn.js";import{useUILabels as Oe,useUILocale as Ge}from"../../lib/i18n.js";import{ChartAnnotationLayer as Be,describeAnnotations as Xe}from"../chart/ChartAnnotations.js";import{ChartAxis as we}from"../chart/ChartAxis.js";import{ChartBrushLayer as $e,locateBrush as Ue,useChartBrush as ze}from"../chart/ChartBrush.js";import{ChartContainer as Ye}from"../chart/ChartContainer.js";import{ChartGrid as Fe}from"../chart/ChartGrid.js";import{ChartLegend as je}from"../chart/ChartLegend.js";import{ChartPatternDefs as Ze,patternFill as qe}from"../chart/ChartPatterns.js";import{useChartSync as Je}from"../chart/ChartSync.js";import{ChartTableView as Qe}from"../chart/ChartTableView.js";import{ChartTooltip as et,ChartTooltipContent as tt}from"../chart/ChartTooltip.js";import{CHART_SURFACE_COLOR as Le,getSeriesLabel as Ve,resolveSeriesColor as nt,toLegendItems as ot}from"../chart/palette.js";import{annotationValues as rt,buildCartesianGeometry as at,createCategoryLocator as st,createPlotContext as lt,createSpanLocator as it,plotPointer as ut,splitOverlay as ct,widenBounds as ht}from"../chart/utils/cartesian.js";import{collectAllValues as mt,readNumber as dt}from"../chart/utils/data.js";import{decimateIndices as Ee,warnPointBudget as pt}from"../chart/utils/decimate.js";import{formatAuto as ft,formatExact as gt,formatPercent as bt,formatXValue as yt}from"../chart/utils/format.js";import{chartCursorTarget as Ct,pressChartMark as vt}from"../chart/utils/keyboard.js";import{buildAreaPath as Te,buildLinePath as He,isolatedPoints as kt}from"../chart/utils/path.js";import{nearestIndex as Ie,toKey as We}from"../chart/utils/scales.js";import{stackExtent as xt,stackSeries as Pt}from"../chart/utils/stack.js";import{extent as St}from"../chart/utils/ticks.js";import{formatTimeValue as At}from"../chart/utils/timestamp.js";import{CHART_TOUCH as Lt}from"../chart/utils/touch.js";import{Fragment as Ht,jsx as s,jsxs as Y}from"react/jsx-runtime";var Rt=6,Bt=.12,wt=.9,Vt=10,Et=De(function({bands:k,stacked:o,patterns:p,patternBaseId:x}){return s("g",{children:k.map(u=>Y("g",{children:[s("path",{d:u.area,fill:qe(p,x,u.slot,u.color),fillOpacity:o?wt:Bt,stroke:"none"}),u.gap?s("path",{d:u.gap,fill:"none",strokeWidth:2,stroke:Le}):null,s("path",{d:u.edge,fill:"none",stroke:u.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),u.isolated.map((v,_)=>s("circle",{cx:v.x,cy:v.y,r:3,fill:u.color,strokeWidth:2,stroke:Le},_))]},u.key))})});function Tt({width:C,height:k,data:o,resolvedSeries:p,x,y:u,grid:v,size:_,curve:P,stack:T,baseline:H,connectNulls:I,referenceLines:W,annotations:A,annotationsLabel:de,patterns:te,patternBaseId:ne,overlay:pe,maxPoints:L,brush:oe,onBrush:re,brushLabel:fe,syncEnabled:F,margin:ae,tooltip:M,onPointClick:R,plotLabel:ge,formatValue:N,formatRaw:O,formatX:G,locale:se}){let[j,Z]=Ae(null),i=j!==null&&j<o.length?j:null,[be,ye]=Ae(null),Ce=Je(),h=F?Ce:null,e=z(()=>{let t=p.filter(b=>!b.hidden),n=t.map(b=>b.key),a=T!=="none",l=Pt(o,n,T),D=ht(a?xt(l):St([...mt(o,n),H]),rt(o,x.key,W,A)),c=at({locale:se,width:C,height:k,data:o,x,y:u,bounds:D,margin:ae,placement:"point",formatValue:N,formatX:G,defaultIncludeZero:!0}),$=c.categoryCenters,m=c.valueScale,g=m(a?0:H),ee=t.map((b,K)=>({top:o.map((U,V)=>{let y=l[V].segments[K];return{x:$[V],y:y.value===null?Number.NaN:m(y.end),defined:y.value!==null}}),bottom:o.map((U,V)=>{let y=l[V].segments[K];return{x:$[V],y:y.value===null?Number.NaN:m(a?y.start:H),defined:y.value!==null}})})),Pe=L!==void 0&&L>0&&o.length>L,Me=Pe&&a?[...new Set(ee.flatMap(({top:b})=>Ee(b,L)))].sort((b,K)=>b-K):null,Ne=t.map((b,K)=>{let{top:U,bottom:V}=ee[K],y={connectNulls:I},he=Me??(Pe?Ee(U,L):null),me=he?he.map(Se=>U[Se]):U,Re=he?he.map(Se=>V[Se]):V;return L||pt("AreaChart",U.length),{key:b.key,color:b.color,slot:b.slot,area:a?Te(me,Re,P,y):Te(me,g,P,y),edge:He(me,P,y),gap:a&&K>0?He(Re,P,y):"",isolated:kt(me,I)}});return{visible:t,locate:st(c),span:it(c),plot:lt({geometry:c,width:C,height:k,data:o,series:t,formatValue:N,formatX:G}),rows:l,stacked:a,xValues:c.xValues,positions:$,xTicks:c.categoryTicks,yTicks:c.valueTicks,valueScale:m,innerWidth:c.innerWidth,innerHeight:c.innerHeight,margin:c.margin,bands:Ne}},[se,o,p,x,u,C,k,ae,P,T,H,I,L,W,A,N,G]),q=E(t=>e.visible.map((n,a)=>{let l=dt(o[t],n.key),D=e.rows[t].segments[a],c=l===null?"\u2014":T==="percent"?`${O(l)} (${N(D.end-D.start)})`:O(l);return{seriesKey:n.key,seriesLabel:Ve(n),color:n.color,value:l,formattedValue:c,datum:o[t]}}),[o,e.visible,e.rows,T,N,O]),f=h?h.brush:be,le=E(t=>{ye(t),h?.setBrush(t),re?.(t)},[h,re]),d=ze({enabled:oe,active:f!==null,centers:e.positions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:le}),ve=E(t=>{if(d.onPointerMove(t),M===!1||o.length===0)return;let n=t.currentTarget.getBoundingClientRect(),a=t.clientX-n.left-e.margin.left,l=Ie(e.positions,a);Z(l>=0?l:null),h?.setHovered(l>=0?e.xValues[l]:null)},[d,M,o.length,e.margin.left,e.positions,e.xValues,h]),ie=E(()=>{Z(null),h?.setHovered(null)},[h]),S=E((t,n)=>{if(!R)return;let a=q(t),l=e.rows[t]?.segments??[],D=a.map((m,g)=>({point:m,segment:l[g]})).filter(({point:m,segment:g})=>m.value!==null&&g!==void 0),c=({segment:m})=>{if(n===null)return 0;let g=e.valueScale(m.end),ee=e.valueScale(e.stacked?m.start:m.end);return e.stacked&&n.y>=Math.min(g,ee)&&n.y<=Math.max(g,ee)?-1:Math.abs(g-n.y)},$=D.length>0?D.reduce((m,g)=>c(g)<c(m)?g:m).point:a[0];$&&R({...$,index:t,x:e.xValues[t]})},[R,q,e]),w=E(t=>{if(o.length===0)return;let n=R&&i!==null&&e.visible.length>0;if(vt(t,n?()=>S(i,null):null))return;let a=d.onKeyDown(t,i),l=Ct(t.key,i,o.length,"x");if(l===void 0){a&&t.preventDefault();return}t.preventDefault(),Z(l),h?.setHovered(l===null?null:e.xValues[l])},[o.length,i,d,h,e.xValues,e.visible.length,R,S]),ke=E(t=>{if(d.consumedClick()||!R||o.length===0)return;let n=ut(t,e),a=i??(n===null?-1:Ie(e.positions,n.x));a<0||S(a,n)},[d,R,o.length,e,i,S]),xe=i!==null||h===null||h.hovered===null?null:(()=>{let t=We(h.hovered),n=e.xValues.findIndex(a=>We(a)===t);return n<0?null:n})(),B=i??xe,J=i===null?null:q(i),Q=B===null?[]:e.visible.map((t,n)=>{let a=e.rows[B].segments[n];return a.value===null?null:{key:t.key,color:t.color,y:e.valueScale(a.end)}}).filter(t=>t!==null),ue=d.dragging??f,X=ue?Ue(ue,e.xValues,e.positions,e.locate):null,ce=ct(pe),r=i===null||J===null?null:{x:e.xValues[i],xLabel:G(e.xValues[i],i),index:i,points:J};return Y(Ht,{children:[Y("svg",{width:C,height:k,role:"img","aria-label":ge??[e.visible.map(t=>Ve(t)).join(", "),Xe(A,de)].filter(Boolean).join(". "),tabIndex:0,className:_e(Lt,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",oe&&"select-none"),onPointerDown:d.onPointerDown,onPointerMove:ve,onPointerUp:d.onPointerUp,onPointerCancel:d.onPointerUp,onPointerLeave:ie,onKeyDown:w,onBlur:ie,onClick:ke,children:[te?s(Ze,{id:ne,entries:p.map(t=>({slot:t.slot,color:t.color}))}):null,Y("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[s(Fe,{width:e.innerWidth,height:e.innerHeight,horizontal:v==="y"||v==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:v==="x"||v==="both"?e.xTicks.map(t=>t.offset):void 0}),A?s(Be,{layer:"under",annotations:A,xAt:e.locate,spanAt:e.span,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,X?s($e,{from:X.from,to:X.to,width:e.innerWidth,height:e.innerHeight,live:d.dragging!==null,label:fe,minSpan:Rt}):null,ce.under?.(e.plot),s(Et,{bands:e.bands,stacked:e.stacked,patterns:te&&e.stacked,patternBaseId:ne}),A?s(Be,{annotations:A,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,W?.map(t=>{let n=e.valueScale(t.value),a=n<Vt?n+12:n-4;return Y("g",{children:[s("line",{x1:0,y1:n,x2:e.innerWidth,y2:n,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?s("text",{x:e.innerWidth,y:a,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),ce.over?.(e.plot),B!==null?Y("g",{"aria-hidden":"true",children:[s("line",{x1:e.positions[B],y1:0,x2:e.positions[B],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:i===null?"3 3":void 0}),Q.map(t=>s("circle",{cx:e.positions[B],cy:t.y,r:4,fill:t.color,strokeWidth:2,stroke:Le},t.key))]}):null]}),s("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:x.hidden?null:s(we,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:x.label,size:_})}),s("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:u?.hidden?null:s(we,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:u?.label,size:_})})]}),r&&M!==!1?s(et,{x:e.margin.left+e.positions[r.index],y:e.margin.top+(Q.length>0?Math.min(...Q.map(t=>t.y)):e.innerHeight/2),containerWidth:C,children:typeof M=="function"?M(r):s(tt,{title:r.xLabel,points:r.points})}):null]})}function an({data:C,series:k,x:o,y:p,height:x=240,width:u,size:v="md",grid:_="y",legend:P,tooltip:T=!0,tableView:H=!1,emphasis:I,title:W,description:A,loading:de=!1,emptyState:te,error:ne=!1,errorState:pe,onRetry:L,actions:oe,onPointClick:re,curve:fe="monotone",stack:F="none",baseline:ae=0,connectNulls:M=!1,referenceLines:R,annotations:ge,overlay:N,patterns:O=!1,legendToggle:G=!0,maxPoints:se,brush:j=!1,onBrush:Z,brushLabel:i,sync:be=!0,margin:ye,locale:Ce,plotLabel:h,className:e,...q}){let f=Ge(Ce),le=Oe(),[d,ve]=Ae(()=>new Set),ie=Ke(),S=z(()=>k.map((r,t)=>({...r,slot:t,hidden:r.hidden||d.has(r.key),color:nt(r,t,I)})),[k,d,I]),w=F==="percent",ke=z(()=>w?{domain:[0,100],...p}:p,[w,p]),xe=z(()=>p?.format??(w?r=>bt(r,{locale:f,alreadyScaled:!0,maximumFractionDigits:0}):r=>ft(r,f)),[p?.format,w,f]),B=z(()=>!w&&p?.format||(r=>gt(r,f)),[w,p?.format,f]),J=z(()=>o.format??(r=>o.scale==="time"?At(r,f):yt(r,f)),[o.format,o.scale,f]),Q=E(r=>{ve(t=>{let n=new Set(t);return n.has(r)?n.delete(r):n.add(r),n})},[]),ue=P===void 0?k.length>=2:P!==!1,X=typeof P=="string"?P:"bottom",ce=S.filter(r=>!r.hidden).length;return s(Ye,{title:W,description:A,height:x,width:u,size:v,loading:de,empty:C.length===0||ce===0,emptyState:te,error:ne,errorState:pe,onRetry:L,actions:oe,exportSource:{data:C,series:S,xKey:o.key,xLabel:o.label??o.key,formatX:o.format},tableView:H,legendPosition:X,legend:ue?s(je,{items:ot(S,I,O&&F!=="none"),position:X,marker:"rect",size:v,onToggle:G?Q:void 0}):void 0,table:H?s(Qe,{data:C,series:S,xKey:o.key,xLabel:o.label??o.key,formatX:J,formatValue:B,caption:typeof W=="string"?W:void 0}):void 0,className:e,...q,children:({width:r})=>s(Tt,{locale:f,width:r,height:x,data:C,resolvedSeries:S,x:o,y:ke,grid:_,size:v,curve:fe,stack:F,baseline:ae,connectNulls:M,referenceLines:R,annotations:ge,annotationsLabel:le.chartAnnotations,patterns:O,patternBaseId:ie,overlay:N,maxPoints:se,brush:j,onBrush:Z,brushLabel:i??le.chartBrush,syncEnabled:be,margin:ye,tooltip:T,onPointClick:re,plotLabel:h,formatValue:xe,formatRaw:B,formatX:J})})}export{an as AreaChart};
|