@modoock/components 1.0.0 → 1.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.
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, type ReactNode } from "react";
|
|
4
|
+
import ClickableButton from "./button";
|
|
5
|
+
import Icon from "./icon";
|
|
6
|
+
|
|
7
|
+
export interface AccordionItem {
|
|
8
|
+
id: string;
|
|
9
|
+
title: string;
|
|
10
|
+
content: ReactNode;
|
|
11
|
+
/** When true, the item starts open. */
|
|
12
|
+
defaultOpen?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface AccordionProps {
|
|
16
|
+
items: AccordionItem[];
|
|
17
|
+
/**
|
|
18
|
+
* When true (default), several panels can stay open.
|
|
19
|
+
* When false, opening one panel closes the others.
|
|
20
|
+
*/
|
|
21
|
+
allowMultiple?: boolean;
|
|
22
|
+
className?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Accordion — FAQ-style open/close sections.
|
|
27
|
+
* Each item has a clickable header and a collapsible body.
|
|
28
|
+
*/
|
|
29
|
+
export default function Accordion({
|
|
30
|
+
items,
|
|
31
|
+
allowMultiple = true,
|
|
32
|
+
className = "",
|
|
33
|
+
}: AccordionProps) {
|
|
34
|
+
const [openIds, setOpenIds] = useState<Set<string>>(
|
|
35
|
+
() => new Set(items.filter((item) => item.defaultOpen).map((item) => item.id)),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const toggle = (id: string) => {
|
|
39
|
+
setOpenIds((previous) => {
|
|
40
|
+
const next = new Set(allowMultiple ? previous : []);
|
|
41
|
+
if (previous.has(id)) {
|
|
42
|
+
next.delete(id);
|
|
43
|
+
} else {
|
|
44
|
+
next.add(id);
|
|
45
|
+
}
|
|
46
|
+
return next;
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div className={`flex flex-col gap-inline ${className}`}>
|
|
52
|
+
{items.map((item) => {
|
|
53
|
+
const isOpen = openIds.has(item.id);
|
|
54
|
+
const panelId = `accordion-panel-${item.id}`;
|
|
55
|
+
const headerId = `accordion-header-${item.id}`;
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<section
|
|
59
|
+
key={item.id}
|
|
60
|
+
className="overflow-hidden rounded-large border border-border bg-surface"
|
|
61
|
+
>
|
|
62
|
+
<h3 className="m-0">
|
|
63
|
+
<ClickableButton
|
|
64
|
+
type="button"
|
|
65
|
+
variant="bare"
|
|
66
|
+
id={headerId}
|
|
67
|
+
aria-expanded={isOpen}
|
|
68
|
+
aria-controls={panelId}
|
|
69
|
+
onClick={() => toggle(item.id)}
|
|
70
|
+
className="flex !h-auto w-full items-center justify-between gap-inline rounded-none px-component py-component text-left text-component-title text-foreground hover:bg-surface-muted focus-visible:ring-primary"
|
|
71
|
+
>
|
|
72
|
+
<span className="min-w-0 flex-1 truncate">{item.title}</span>
|
|
73
|
+
<Icon
|
|
74
|
+
name="ChevronDown"
|
|
75
|
+
aria-hidden="true"
|
|
76
|
+
className={`shrink-0 transition-transform ${
|
|
77
|
+
isOpen ? "rotate-180" : ""
|
|
78
|
+
}`}
|
|
79
|
+
/>
|
|
80
|
+
</ClickableButton>
|
|
81
|
+
</h3>
|
|
82
|
+
{isOpen ? (
|
|
83
|
+
<div
|
|
84
|
+
id={panelId}
|
|
85
|
+
role="region"
|
|
86
|
+
aria-labelledby={headerId}
|
|
87
|
+
className="border-t border-border px-component py-component"
|
|
88
|
+
>
|
|
89
|
+
{item.content}
|
|
90
|
+
</div>
|
|
91
|
+
) : null}
|
|
92
|
+
</section>
|
|
93
|
+
);
|
|
94
|
+
})}
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
}
|
package/components/ui/index.ts
CHANGED
|
@@ -8,8 +8,8 @@ export { default as Input, Textarea } from "./input";
|
|
|
8
8
|
export type { InputState, InputProps, TextareaProps } from "./input";
|
|
9
9
|
export {default as Badge} from "./badge";
|
|
10
10
|
export type {BadgeProps} from "./badge";
|
|
11
|
-
export {default as
|
|
12
|
-
export type {Column, CardAction,
|
|
11
|
+
export { default as Table } from "./table";
|
|
12
|
+
export type { Column, CardAction, TableCardActions } from "./table";
|
|
13
13
|
export { Select, MultiSelect, SelectWithSearch, MultiSelectWithSearch, SelectFilter } from "./select";
|
|
14
14
|
export type { SelectOption } from "./select";
|
|
15
15
|
export { default as Modal } from "./modal";
|
|
@@ -23,6 +23,6 @@ export { default as MetricBar } from "./metric-bar";
|
|
|
23
23
|
export type { MetricTone } from "./metric-bar";
|
|
24
24
|
export { default as Stepper } from "./stepper";
|
|
25
25
|
export type { StepperStepState } from "./stepper";
|
|
26
|
-
export { default as
|
|
27
|
-
export type {
|
|
26
|
+
export { default as Accordion } from "./accordion";
|
|
27
|
+
export type { AccordionItem } from "./accordion";
|
|
28
28
|
|
package/components/ui/tab.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
2
|
|
|
3
3
|
import { useState, type ReactNode } from "react";
|
|
4
4
|
import ClickableButton from "./button";
|
|
@@ -19,7 +19,7 @@ interface TabsProps {
|
|
|
19
19
|
* the panel should fill the main scroll container without creating its own
|
|
20
20
|
* page-level scroll. At `md+`, internal component scrolling is allowed
|
|
21
21
|
* when content requires it — rely on component-internal `overflow-auto`
|
|
22
|
-
* (e.g. InfoCard `scrollable`,
|
|
22
|
+
* (e.g. InfoCard `scrollable`, Table) rather than on the panel wrapper.
|
|
23
23
|
* Below `md`, page-level vertical scrolling is allowed and internal component
|
|
24
24
|
* scrolling MUST NOT be used — so do NOT put `overflow-y-auto` here; let the
|
|
25
25
|
* page scroll keep reflowed content reachable.
|
|
@@ -29,7 +29,7 @@ export interface CardAction {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
export interface
|
|
32
|
+
export interface TableCardActions<T> {
|
|
33
33
|
/** Actions globales du dropdown « Actions » — jamais recopiées sur une carte. */
|
|
34
34
|
table?: CardAction[];
|
|
35
35
|
|
|
@@ -38,7 +38,7 @@ export interface UserTableCardActions<T> {
|
|
|
38
38
|
row?: (row: T) => CardAction[];
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export interface
|
|
41
|
+
export interface TableProps<T> {
|
|
42
42
|
columns: Column<T>[];
|
|
43
43
|
data: T[];
|
|
44
44
|
rowsPerPage?: number;
|
|
@@ -46,12 +46,12 @@ export interface UserTableProps<T> {
|
|
|
46
46
|
getRowKey?: (row: T, index: number) => React.Key;
|
|
47
47
|
|
|
48
48
|
cardVisiblePairs?: number;
|
|
49
|
-
/** Déclare des actions — voir `
|
|
49
|
+
/** Déclare des actions — voir `TableCardActions`.
|
|
50
50
|
* `table` : dropdowns globaux « Actions » (pas recopiés sur chaque carte).
|
|
51
51
|
* `row` : actions personnelles. Une seule s’affiche telle quelle ; plusieurs
|
|
52
52
|
* vont dans un dropdown (colonne tableau et menu 3 points de la carte).
|
|
53
53
|
* Sans `row`, la dernière colonne sans libellé est réutilisée. */
|
|
54
|
-
cardActions?:
|
|
54
|
+
cardActions?: TableCardActions<T>;
|
|
55
55
|
|
|
56
56
|
selectedKeys?: Set<React.Key> | null;
|
|
57
57
|
onToggleSelect?: ((rowKey: React.Key) => void) | null;
|
|
@@ -274,7 +274,7 @@ function TableActionsBar({
|
|
|
274
274
|
);
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
-
export default function
|
|
277
|
+
export default function Table<T extends object>({
|
|
278
278
|
columns,
|
|
279
279
|
data,
|
|
280
280
|
rowsPerPage = 8,
|
|
@@ -288,7 +288,7 @@ export default function UserTable<T extends object>({
|
|
|
288
288
|
transpose = false,
|
|
289
289
|
transposeLabel,
|
|
290
290
|
transposeHeader,
|
|
291
|
-
}:
|
|
291
|
+
}: TableProps<T>) {
|
|
292
292
|
const [sortKey, setSortKey] = useState<string | null>(null);
|
|
293
293
|
const [sortDirection, setSortDirection] = useState<SortDirection>("asc");
|
|
294
294
|
const [currentPage, setCurrentPage] = useState(1);
|
|
@@ -479,7 +479,7 @@ export default function UserTable<T extends object>({
|
|
|
479
479
|
/>
|
|
480
480
|
</div>
|
|
481
481
|
) : null}
|
|
482
|
-
<div className="hidden flex-1 overflow-auto md:
|
|
482
|
+
<div className="hidden min-h-0 flex-1 overflow-auto md:block">
|
|
483
483
|
<table className="w-full border-collapse text-body">
|
|
484
484
|
{transpose ? (
|
|
485
485
|
<>
|
|
@@ -504,14 +504,14 @@ export default function UserTable<T extends object>({
|
|
|
504
504
|
</tr>
|
|
505
505
|
) : (
|
|
506
506
|
columns.slice(1).map((column) => (
|
|
507
|
-
<tr key={String(column.key)} className="border-t border-border">
|
|
508
|
-
<td className="px-component
|
|
507
|
+
<tr key={String(column.key)} className="h-12 border-t border-border">
|
|
508
|
+
<td className="px-component align-middle text-label text-muted-foreground">
|
|
509
509
|
{column.label}
|
|
510
510
|
</td>
|
|
511
511
|
{data.map((item, i) => (
|
|
512
512
|
<td
|
|
513
513
|
key={i}
|
|
514
|
-
className={`px-component
|
|
514
|
+
className={`px-component align-middle ${
|
|
515
515
|
column.className ?? "text-body-medium text-foreground"
|
|
516
516
|
}`}
|
|
517
517
|
>
|
|
@@ -581,10 +581,10 @@ export default function UserTable<T extends object>({
|
|
|
581
581
|
return (
|
|
582
582
|
<tr
|
|
583
583
|
key={rowKey}
|
|
584
|
-
className="border-b border-border transition-colors last:border-b-0 hover:bg-surface-muted"
|
|
584
|
+
className="h-12 border-b border-border transition-colors last:border-b-0 hover:bg-surface-muted"
|
|
585
585
|
>
|
|
586
586
|
{hasSelectionControl ? (
|
|
587
|
-
<td className="px-component
|
|
587
|
+
<td className="px-component align-middle">
|
|
588
588
|
<ClickableButton
|
|
589
589
|
type="button"
|
|
590
590
|
variant="ghost"
|
|
@@ -608,7 +608,7 @@ export default function UserTable<T extends object>({
|
|
|
608
608
|
{visibleColumns.map((column, columnIndex) => (
|
|
609
609
|
<td
|
|
610
610
|
key={`col-${columnIndex}`}
|
|
611
|
-
className={`px-component
|
|
611
|
+
className={`px-component align-middle ${
|
|
612
612
|
column.className ?? "text-body-medium text-foreground"
|
|
613
613
|
}`}
|
|
614
614
|
>
|
package/package.json
CHANGED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import ClickableButton from "./button";
|
|
2
|
-
import type { ButtonVariant } from "./button";
|
|
3
|
-
|
|
4
|
-
export interface ActionStackItem {
|
|
5
|
-
key: string;
|
|
6
|
-
label: string;
|
|
7
|
-
variant?: ButtonVariant;
|
|
8
|
-
onClick: () => void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Pile verticale de boutons d'action, avec message si aucune action n'est disponible.
|
|
13
|
-
*/
|
|
14
|
-
export default function ActionStack({
|
|
15
|
-
actions,
|
|
16
|
-
emptyMessage,
|
|
17
|
-
}: {
|
|
18
|
-
actions: ActionStackItem[];
|
|
19
|
-
emptyMessage?: string;
|
|
20
|
-
}) {
|
|
21
|
-
if (actions.length === 0) {
|
|
22
|
-
return emptyMessage ? (
|
|
23
|
-
<p className="text-body text-muted-foreground">{emptyMessage}</p>
|
|
24
|
-
) : null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<div className="flex flex-col gap-inline">
|
|
29
|
-
{actions.map((action) => (
|
|
30
|
-
<ClickableButton
|
|
31
|
-
key={action.key}
|
|
32
|
-
type="button"
|
|
33
|
-
variant={action.variant}
|
|
34
|
-
fullWidth
|
|
35
|
-
onClick={action.onClick}
|
|
36
|
-
>
|
|
37
|
-
{action.label}
|
|
38
|
-
</ClickableButton>
|
|
39
|
-
))}
|
|
40
|
-
</div>
|
|
41
|
-
);
|
|
42
|
-
}
|