agentic-ds-kit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +10 -0
- package/CLAUDE.md +1 -0
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/contracts/accordion.json +38 -0
- package/contracts/alert.json +57 -0
- package/contracts/alertdialog.json +89 -0
- package/contracts/appheader.json +140 -0
- package/contracts/appnav.json +72 -0
- package/contracts/avatar.json +63 -0
- package/contracts/avatargroup.json +83 -0
- package/contracts/badge.json +92 -0
- package/contracts/barchart.json +55 -0
- package/contracts/breadcrumb.json +76 -0
- package/contracts/button.json +120 -0
- package/contracts/buttongroup.json +48 -0
- package/contracts/calendar.json +93 -0
- package/contracts/card.json +123 -0
- package/contracts/carousel.json +98 -0
- package/contracts/cell.json +203 -0
- package/contracts/chat.json +131 -0
- package/contracts/checkbox.json +101 -0
- package/contracts/collapsible.json +66 -0
- package/contracts/command.json +84 -0
- package/contracts/datatable.json +126 -0
- package/contracts/datepicker.json +102 -0
- package/contracts/drawer.json +93 -0
- package/contracts/dropdownmenu.json +190 -0
- package/contracts/empty.json +79 -0
- package/contracts/field.json +49 -0
- package/contracts/fieldset.json +29 -0
- package/contracts/headercell.json +107 -0
- package/contracts/index.json +478 -0
- package/contracts/input.json +119 -0
- package/contracts/inputotp.json +119 -0
- package/contracts/insightcard.json +130 -0
- package/contracts/linechart.json +51 -0
- package/contracts/loadinganimation.json +33 -0
- package/contracts/modal.json +100 -0
- package/contracts/modalcard.json +88 -0
- package/contracts/navigationmenu.json +65 -0
- package/contracts/numbertransition.json +33 -0
- package/contracts/pageheader.json +101 -0
- package/contracts/pagination.json +85 -0
- package/contracts/patterns/activity.json +30 -0
- package/contracts/patterns/assistant-workspace.json +16 -0
- package/contracts/patterns/dashboard.json +12 -0
- package/contracts/patterns/empty-first-run.json +15 -0
- package/contracts/patterns/inbox.json +32 -0
- package/contracts/patterns/invite-members.json +14 -0
- package/contracts/patterns/list-detail.json +13 -0
- package/contracts/patterns/settings-form.json +13 -0
- package/contracts/piechart.json +68 -0
- package/contracts/progress.json +124 -0
- package/contracts/progresssteps.json +91 -0
- package/contracts/radiogroup.json +132 -0
- package/contracts/scoreboard.json +46 -0
- package/contracts/scorecard.json +124 -0
- package/contracts/section.json +97 -0
- package/contracts/select.json +130 -0
- package/contracts/shimmertext.json +33 -0
- package/contracts/sidenav.json +133 -0
- package/contracts/slider.json +81 -0
- package/contracts/spinner.json +52 -0
- package/contracts/switch.json +94 -0
- package/contracts/table.json +92 -0
- package/contracts/tabs.json +90 -0
- package/contracts/textarea.json +54 -0
- package/contracts/thinkinganimation.json +32 -0
- package/contracts/timeline.json +49 -0
- package/contracts/toast.json +104 -0
- package/contracts/tooltip.json +66 -0
- package/lib/tokens.css +637 -0
- package/package.json +60 -0
- package/skills/prototype-from-kit/SKILL.md +29 -0
- package/src/index.ts +71 -0
- package/tokens/tokens.json +725 -0
- package/ui/Accordion/Accordion.module.css +68 -0
- package/ui/Accordion/Accordion.tsx +51 -0
- package/ui/Accordion/Accordion.types.ts +10 -0
- package/ui/Accordion/index.ts +2 -0
- package/ui/Alert/Alert.module.css +62 -0
- package/ui/Alert/Alert.tsx +27 -0
- package/ui/Alert/Alert.types.ts +7 -0
- package/ui/Alert/index.ts +2 -0
- package/ui/AlertDialog/AlertDialog.module.css +71 -0
- package/ui/AlertDialog/AlertDialog.tsx +109 -0
- package/ui/AlertDialog/AlertDialog.types.ts +14 -0
- package/ui/AlertDialog/index.ts +6 -0
- package/ui/AppHeader/AppHeader.module.css +120 -0
- package/ui/AppHeader/AppHeader.tsx +70 -0
- package/ui/AppHeader/AppHeader.types.ts +28 -0
- package/ui/AppHeader/index.ts +2 -0
- package/ui/AppNav/AppNav.module.css +168 -0
- package/ui/AppNav/AppNav.tsx +137 -0
- package/ui/AppNav/AppNav.types.ts +24 -0
- package/ui/AppNav/index.ts +2 -0
- package/ui/Avatar/Avatar.module.css +52 -0
- package/ui/Avatar/Avatar.tsx +62 -0
- package/ui/Avatar/Avatar.types.ts +8 -0
- package/ui/Avatar/index.ts +2 -0
- package/ui/AvatarGroup/AvatarGroup.module.css +49 -0
- package/ui/AvatarGroup/AvatarGroup.tsx +29 -0
- package/ui/AvatarGroup/AvatarGroup.types.ts +16 -0
- package/ui/AvatarGroup/index.ts +2 -0
- package/ui/Badge/Badge.module.css +92 -0
- package/ui/Badge/Badge.tsx +43 -0
- package/ui/Badge/Badge.types.ts +11 -0
- package/ui/Badge/index.ts +2 -0
- package/ui/BarChart/BarChart.module.css +56 -0
- package/ui/BarChart/BarChart.tsx +380 -0
- package/ui/BarChart/BarChart.types.ts +18 -0
- package/ui/BarChart/index.ts +2 -0
- package/ui/Breadcrumb/Breadcrumb.module.css +64 -0
- package/ui/Breadcrumb/Breadcrumb.tsx +89 -0
- package/ui/Breadcrumb/Breadcrumb.types.ts +14 -0
- package/ui/Breadcrumb/index.ts +2 -0
- package/ui/Button/Button.module.css +101 -0
- package/ui/Button/Button.tsx +49 -0
- package/ui/Button/Button.types.ts +18 -0
- package/ui/Button/index.ts +2 -0
- package/ui/Button/lucideName.tsx +188 -0
- package/ui/ButtonGroup/ButtonGroup.module.css +31 -0
- package/ui/ButtonGroup/ButtonGroup.tsx +12 -0
- package/ui/ButtonGroup/ButtonGroup.types.ts +6 -0
- package/ui/ButtonGroup/index.ts +2 -0
- package/ui/Calendar/Calendar.module.css +146 -0
- package/ui/Calendar/Calendar.tsx +296 -0
- package/ui/Calendar/Calendar.types.ts +11 -0
- package/ui/Calendar/index.ts +2 -0
- package/ui/Card/Card.module.css +95 -0
- package/ui/Card/Card.tsx +69 -0
- package/ui/Card/Card.types.ts +23 -0
- package/ui/Card/index.ts +2 -0
- package/ui/Carousel/Carousel.module.css +114 -0
- package/ui/Carousel/Carousel.tsx +152 -0
- package/ui/Carousel/Carousel.types.ts +17 -0
- package/ui/Carousel/index.ts +7 -0
- package/ui/Cell/Cell.module.css +133 -0
- package/ui/Cell/Cell.tsx +300 -0
- package/ui/Cell/Cell.types.ts +69 -0
- package/ui/Cell/index.ts +11 -0
- package/ui/Chat/Chat.module.css +149 -0
- package/ui/Chat/Chat.tsx +175 -0
- package/ui/Chat/Chat.types.ts +39 -0
- package/ui/Chat/index.ts +2 -0
- package/ui/Checkbox/Checkbox.module.css +135 -0
- package/ui/Checkbox/Checkbox.tsx +70 -0
- package/ui/Checkbox/Checkbox.types.ts +15 -0
- package/ui/Checkbox/index.ts +2 -0
- package/ui/Collapsible/Collapsible.module.css +68 -0
- package/ui/Collapsible/Collapsible.tsx +59 -0
- package/ui/Collapsible/Collapsible.types.ts +9 -0
- package/ui/Collapsible/index.ts +2 -0
- package/ui/Command/Command.module.css +138 -0
- package/ui/Command/Command.tsx +152 -0
- package/ui/Command/Command.types.ts +20 -0
- package/ui/Command/index.ts +2 -0
- package/ui/DataTable/DataTable.module.css +211 -0
- package/ui/DataTable/DataTable.tsx +429 -0
- package/ui/DataTable/DataTable.types.ts +35 -0
- package/ui/DataTable/index.ts +8 -0
- package/ui/DatePicker/DatePicker.module.css +44 -0
- package/ui/DatePicker/DatePicker.tsx +123 -0
- package/ui/DatePicker/DatePicker.types.ts +15 -0
- package/ui/DatePicker/index.ts +2 -0
- package/ui/Drawer/Drawer.module.css +204 -0
- package/ui/Drawer/Drawer.tsx +112 -0
- package/ui/Drawer/Drawer.types.ts +14 -0
- package/ui/Drawer/index.ts +2 -0
- package/ui/DropdownMenu/DropdownMenu.module.css +319 -0
- package/ui/DropdownMenu/DropdownMenu.tsx +580 -0
- package/ui/DropdownMenu/DropdownMenu.types.ts +48 -0
- package/ui/DropdownMenu/index.ts +8 -0
- package/ui/Empty/Empty.module.css +68 -0
- package/ui/Empty/Empty.tsx +35 -0
- package/ui/Empty/Empty.types.ts +10 -0
- package/ui/Empty/index.ts +2 -0
- package/ui/Field/Field.module.css +66 -0
- package/ui/Field/Field.tsx +46 -0
- package/ui/Field/Field.types.ts +12 -0
- package/ui/Field/index.ts +2 -0
- package/ui/FieldSet/FieldSet.module.css +30 -0
- package/ui/FieldSet/FieldSet.tsx +14 -0
- package/ui/FieldSet/FieldSet.types.ts +7 -0
- package/ui/FieldSet/index.ts +2 -0
- package/ui/HeaderCell/HeaderCell.module.css +85 -0
- package/ui/HeaderCell/HeaderCell.tsx +71 -0
- package/ui/HeaderCell/HeaderCell.types.ts +18 -0
- package/ui/HeaderCell/index.ts +2 -0
- package/ui/Input/Input.module.css +59 -0
- package/ui/Input/Input.tsx +65 -0
- package/ui/Input/Input.types.ts +22 -0
- package/ui/Input/index.ts +2 -0
- package/ui/InputOTP/InputOTP.module.css +139 -0
- package/ui/InputOTP/InputOTP.tsx +136 -0
- package/ui/InputOTP/InputOTP.types.ts +19 -0
- package/ui/InputOTP/index.ts +2 -0
- package/ui/InsightCard/InsightCard.module.css +166 -0
- package/ui/InsightCard/InsightCard.tsx +90 -0
- package/ui/InsightCard/InsightCard.types.ts +20 -0
- package/ui/InsightCard/index.ts +7 -0
- package/ui/LineChart/LineChart.module.css +93 -0
- package/ui/LineChart/LineChart.tsx +424 -0
- package/ui/LineChart/LineChart.types.ts +19 -0
- package/ui/LineChart/index.ts +2 -0
- package/ui/LoadingAnimation/LoadingAnimation.module.css +66 -0
- package/ui/LoadingAnimation/LoadingAnimation.tsx +41 -0
- package/ui/LoadingAnimation/LoadingAnimation.types.ts +9 -0
- package/ui/LoadingAnimation/index.ts +6 -0
- package/ui/Modal/Modal.module.css +48 -0
- package/ui/Modal/Modal.tsx +114 -0
- package/ui/Modal/Modal.types.ts +15 -0
- package/ui/Modal/index.ts +2 -0
- package/ui/ModalCard/ModalCard.module.css +137 -0
- package/ui/ModalCard/ModalCard.tsx +58 -0
- package/ui/ModalCard/ModalCard.types.ts +15 -0
- package/ui/ModalCard/index.ts +2 -0
- package/ui/NavigationMenu/NavigationMenu.module.css +31 -0
- package/ui/NavigationMenu/NavigationMenu.tsx +57 -0
- package/ui/NavigationMenu/NavigationMenu.types.ts +22 -0
- package/ui/NavigationMenu/index.ts +7 -0
- package/ui/NumberTransition/NumberTransition.module.css +110 -0
- package/ui/NumberTransition/NumberTransition.tsx +78 -0
- package/ui/NumberTransition/NumberTransition.types.ts +9 -0
- package/ui/NumberTransition/index.ts +2 -0
- package/ui/PageHeader/PageHeader.module.css +57 -0
- package/ui/PageHeader/PageHeader.tsx +39 -0
- package/ui/PageHeader/PageHeader.types.ts +12 -0
- package/ui/PageHeader/index.ts +2 -0
- package/ui/Pagination/Pagination.module.css +19 -0
- package/ui/Pagination/Pagination.tsx +147 -0
- package/ui/Pagination/Pagination.types.ts +12 -0
- package/ui/Pagination/index.ts +2 -0
- package/ui/PieChart/PieChart.module.css +116 -0
- package/ui/PieChart/PieChart.tsx +293 -0
- package/ui/PieChart/PieChart.types.ts +22 -0
- package/ui/PieChart/index.ts +2 -0
- package/ui/Progress/Progress.module.css +226 -0
- package/ui/Progress/Progress.tsx +167 -0
- package/ui/Progress/Progress.types.ts +15 -0
- package/ui/Progress/index.ts +8 -0
- package/ui/ProgressSteps/ProgressSteps.module.css +210 -0
- package/ui/ProgressSteps/ProgressSteps.tsx +105 -0
- package/ui/ProgressSteps/ProgressSteps.types.ts +19 -0
- package/ui/ProgressSteps/index.ts +8 -0
- package/ui/RadioGroup/RadioGroup.module.css +284 -0
- package/ui/RadioGroup/RadioGroup.tsx +116 -0
- package/ui/RadioGroup/RadioGroup.types.ts +30 -0
- package/ui/RadioGroup/index.ts +8 -0
- package/ui/Scoreboard/Scoreboard.module.css +53 -0
- package/ui/Scoreboard/Scoreboard.tsx +41 -0
- package/ui/Scoreboard/Scoreboard.types.ts +7 -0
- package/ui/Scoreboard/index.ts +2 -0
- package/ui/Scorecard/Scorecard.module.css +150 -0
- package/ui/Scorecard/Scorecard.tsx +92 -0
- package/ui/Scorecard/Scorecard.types.ts +18 -0
- package/ui/Scorecard/index.ts +2 -0
- package/ui/Section/Section.module.css +104 -0
- package/ui/Section/Section.tsx +75 -0
- package/ui/Section/Section.types.ts +15 -0
- package/ui/Section/index.ts +2 -0
- package/ui/Select/Select.module.css +7 -0
- package/ui/Select/Select.tsx +113 -0
- package/ui/Select/Select.types.ts +26 -0
- package/ui/Select/index.ts +2 -0
- package/ui/ShimmerText/ShimmerText.module.css +46 -0
- package/ui/ShimmerText/ShimmerText.tsx +48 -0
- package/ui/ShimmerText/ShimmerText.types.ts +12 -0
- package/ui/ShimmerText/index.ts +2 -0
- package/ui/SideNav/SideNav.module.css +347 -0
- package/ui/SideNav/SideNav.tsx +222 -0
- package/ui/SideNav/SideNav.types.ts +42 -0
- package/ui/SideNav/index.ts +8 -0
- package/ui/Slider/Slider.module.css +105 -0
- package/ui/Slider/Slider.tsx +187 -0
- package/ui/Slider/Slider.types.ts +11 -0
- package/ui/Slider/index.ts +2 -0
- package/ui/Spinner/Spinner.module.css +58 -0
- package/ui/Spinner/Spinner.tsx +19 -0
- package/ui/Spinner/Spinner.types.ts +6 -0
- package/ui/Spinner/index.ts +2 -0
- package/ui/Switch/Switch.module.css +189 -0
- package/ui/Switch/Switch.tsx +65 -0
- package/ui/Switch/Switch.types.ts +12 -0
- package/ui/Switch/index.ts +2 -0
- package/ui/Table/Table.module.css +132 -0
- package/ui/Table/Table.tsx +108 -0
- package/ui/Table/Table.types.ts +26 -0
- package/ui/Table/index.ts +8 -0
- package/ui/Tabs/Tabs.module.css +162 -0
- package/ui/Tabs/Tabs.tsx +150 -0
- package/ui/Tabs/Tabs.types.ts +21 -0
- package/ui/Tabs/index.ts +2 -0
- package/ui/Textarea/Textarea.module.css +74 -0
- package/ui/Textarea/Textarea.tsx +38 -0
- package/ui/Textarea/Textarea.types.ts +14 -0
- package/ui/Textarea/index.ts +2 -0
- package/ui/ThinkingAnimation/ThinkingAnimation.module.css +75 -0
- package/ui/ThinkingAnimation/ThinkingAnimation.tsx +31 -0
- package/ui/ThinkingAnimation/ThinkingAnimation.types.ts +8 -0
- package/ui/ThinkingAnimation/index.ts +2 -0
- package/ui/Timeline/Timeline.module.css +99 -0
- package/ui/Timeline/Timeline.tsx +47 -0
- package/ui/Timeline/Timeline.types.ts +16 -0
- package/ui/Timeline/index.ts +2 -0
- package/ui/Toast/Toast.module.css +133 -0
- package/ui/Toast/Toast.tsx +89 -0
- package/ui/Toast/Toast.types.ts +17 -0
- package/ui/Toast/index.ts +2 -0
- package/ui/Tooltip/Tooltip.module.css +111 -0
- package/ui/Tooltip/Tooltip.tsx +101 -0
- package/ui/Tooltip/index.ts +2 -0
- package/ui/patterns/ActivityPattern/ActivityFeed.tsx +77 -0
- package/ui/patterns/ActivityPattern/ActivityPattern.tsx +120 -0
- package/ui/patterns/ActivityPattern/ActivityTasks.tsx +86 -0
- package/ui/patterns/ActivityPattern/TaskDrawer.module.css +39 -0
- package/ui/patterns/ActivityPattern/TaskDrawer.tsx +186 -0
- package/ui/patterns/ActivityPattern/index.ts +2 -0
- package/ui/patterns/AssistantWorkspacePattern/AssistantWorkspacePattern.module.css +16 -0
- package/ui/patterns/AssistantWorkspacePattern/AssistantWorkspacePattern.tsx +159 -0
- package/ui/patterns/AssistantWorkspacePattern/index.ts +2 -0
- package/ui/patterns/DashboardPattern/DashboardPattern.tsx +102 -0
- package/ui/patterns/DashboardPattern/index.ts +1 -0
- package/ui/patterns/DashboardPattern/patterns.module.css +6 -0
- package/ui/patterns/EmptyFirstRunPattern/EmptyFirstRunPattern.tsx +125 -0
- package/ui/patterns/EmptyFirstRunPattern/index.ts +2 -0
- package/ui/patterns/InboxPattern/InboxPattern.module.css +40 -0
- package/ui/patterns/InboxPattern/InboxPattern.tsx +192 -0
- package/ui/patterns/InboxPattern/InboxReplyDrawer.tsx +97 -0
- package/ui/patterns/InboxPattern/inbox-data.ts +101 -0
- package/ui/patterns/InboxPattern/index.ts +2 -0
- package/ui/patterns/InviteMembersPattern/InviteMembersPattern.tsx +148 -0
- package/ui/patterns/InviteMembersPattern/index.ts +2 -0
- package/ui/patterns/ListDetailPattern/ListDetailPattern.module.css +34 -0
- package/ui/patterns/ListDetailPattern/ListDetailPattern.tsx +145 -0
- package/ui/patterns/ListDetailPattern/index.ts +2 -0
- package/ui/patterns/SettingsFormPattern/SettingsFormPattern.module.css +12 -0
- package/ui/patterns/SettingsFormPattern/SettingsFormPattern.tsx +89 -0
- package/ui/patterns/SettingsFormPattern/index.ts +3 -0
- package/ui/shared/ChartFrame.module.css +295 -0
- package/ui/shared/ChartFrame.tsx +87 -0
- package/ui/shared/chartMath.ts +228 -0
- package/ui/shared/controls.module.css +48 -0
- package/ui/shared/useChartSize.ts +22 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type BadgeTone = "neutral" | "brand" | "success" | "warning" | "danger" | "info";
|
|
2
|
+
export type BadgeSize = "sm" | "md" | "lg";
|
|
3
|
+
|
|
4
|
+
export interface BadgeProps {
|
|
5
|
+
children: string;
|
|
6
|
+
tone?: BadgeTone;
|
|
7
|
+
size?: BadgeSize;
|
|
8
|
+
removable?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
onRemove?: () => void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
.plot {
|
|
2
|
+
position: relative;
|
|
3
|
+
width: 100%;
|
|
4
|
+
min-width: 0;
|
|
5
|
+
overflow: visible;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.chart {
|
|
9
|
+
display: block;
|
|
10
|
+
width: 100%;
|
|
11
|
+
overflow: visible;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.grid {
|
|
15
|
+
stroke: var(--border-strong);
|
|
16
|
+
stroke-width: 1;
|
|
17
|
+
shape-rendering: crispEdges;
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.axis {
|
|
22
|
+
stroke: var(--border-strong);
|
|
23
|
+
stroke-width: 1;
|
|
24
|
+
shape-rendering: crispEdges;
|
|
25
|
+
pointer-events: none;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.bar {
|
|
29
|
+
cursor: pointer;
|
|
30
|
+
outline: none;
|
|
31
|
+
transition: opacity 0.48s cubic-bezier(0.22, 1, 0.36, 1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.barDimmed {
|
|
35
|
+
opacity: 0.45;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.bar:focus-visible {
|
|
39
|
+
outline: var(--border-focus-width) solid var(--focus-ring);
|
|
40
|
+
outline-offset: var(--space-inset-2xs);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.categoryLabel,
|
|
44
|
+
.tickLabel {
|
|
45
|
+
fill: var(--text-muted);
|
|
46
|
+
font-family: var(--font-sans);
|
|
47
|
+
font-size: var(--type-size-caption);
|
|
48
|
+
font-variant-numeric: tabular-nums;
|
|
49
|
+
pointer-events: none;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@media (prefers-reduced-motion: reduce) {
|
|
53
|
+
.bar {
|
|
54
|
+
transition: opacity var(--motion-interaction-duration) var(--motion-interaction-easing);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import { ChartFrame } from "../shared/ChartFrame";
|
|
5
|
+
import frameStyles from "../shared/ChartFrame.module.css";
|
|
6
|
+
import {
|
|
7
|
+
CHART_MARGINS,
|
|
8
|
+
colorAt,
|
|
9
|
+
formatAxisTick,
|
|
10
|
+
formatValue,
|
|
11
|
+
linearScale,
|
|
12
|
+
niceTicks,
|
|
13
|
+
normalizeBarInput,
|
|
14
|
+
seriesExtent,
|
|
15
|
+
type ChartSeries,
|
|
16
|
+
} from "../shared/chartMath";
|
|
17
|
+
import { useChartSize } from "../shared/useChartSize";
|
|
18
|
+
import type { BarChartProps } from "./BarChart.types";
|
|
19
|
+
import styles from "./BarChart.module.css";
|
|
20
|
+
|
|
21
|
+
export type { BarChartProps, BarChartOrientation } from "./BarChart.types";
|
|
22
|
+
|
|
23
|
+
const DEFAULT_MAX_BAR_WIDTH = 32;
|
|
24
|
+
|
|
25
|
+
type BarGeom = {
|
|
26
|
+
key: string;
|
|
27
|
+
category: string;
|
|
28
|
+
series: string;
|
|
29
|
+
color: string;
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
value: number;
|
|
35
|
+
cx: number;
|
|
36
|
+
cy: number;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type TickMark = {
|
|
40
|
+
value: number;
|
|
41
|
+
label: string;
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
gridX1: number;
|
|
45
|
+
gridX2: number;
|
|
46
|
+
gridY1: number;
|
|
47
|
+
gridY2: number;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type CategoryLabel = { label: string; x: number; y: number };
|
|
51
|
+
|
|
52
|
+
const EMPTY_LAYOUT = {
|
|
53
|
+
bars: [] as BarGeom[],
|
|
54
|
+
ticks: [] as TickMark[],
|
|
55
|
+
categoryLabels: [] as CategoryLabel[],
|
|
56
|
+
baseline: 0,
|
|
57
|
+
plotLeft: 0,
|
|
58
|
+
plotRight: 0,
|
|
59
|
+
plotTop: 0,
|
|
60
|
+
plotBottom: 0,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function ChartTable({ categories, series }: { categories: string[]; series: ChartSeries[] }) {
|
|
64
|
+
return (
|
|
65
|
+
<div className={frameStyles.tableScroll}>
|
|
66
|
+
<table className={frameStyles.table}>
|
|
67
|
+
<thead>
|
|
68
|
+
<tr>
|
|
69
|
+
<th scope="col">Category</th>
|
|
70
|
+
{series.map((entry) => (
|
|
71
|
+
<th key={entry.label} scope="col">
|
|
72
|
+
{entry.label}
|
|
73
|
+
</th>
|
|
74
|
+
))}
|
|
75
|
+
</tr>
|
|
76
|
+
</thead>
|
|
77
|
+
<tbody>
|
|
78
|
+
{categories.map((category, index) => (
|
|
79
|
+
<tr key={category}>
|
|
80
|
+
<th scope="row">{category}</th>
|
|
81
|
+
{series.map((entry) => (
|
|
82
|
+
<td key={entry.label}>{formatValue(entry.data[index] ?? 0)}</td>
|
|
83
|
+
))}
|
|
84
|
+
</tr>
|
|
85
|
+
))}
|
|
86
|
+
</tbody>
|
|
87
|
+
</table>
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function Legend({
|
|
93
|
+
series,
|
|
94
|
+
active,
|
|
95
|
+
onActivate,
|
|
96
|
+
onClear,
|
|
97
|
+
}: {
|
|
98
|
+
series: ChartSeries[];
|
|
99
|
+
active: string | null;
|
|
100
|
+
onActivate: (label: string) => void;
|
|
101
|
+
onClear: () => void;
|
|
102
|
+
}) {
|
|
103
|
+
return (
|
|
104
|
+
<ul className={`${frameStyles.legend} ${frameStyles.legendInteractive}`}>
|
|
105
|
+
{series.map((entry) => {
|
|
106
|
+
const dimmed = Boolean(active) && active !== entry.label;
|
|
107
|
+
return (
|
|
108
|
+
<li key={entry.label}>
|
|
109
|
+
<button
|
|
110
|
+
type="button"
|
|
111
|
+
className={`${frameStyles.legendItem} ${frameStyles.legendButton}${dimmed ? ` ${frameStyles.legendItemDimmed}` : ""}`}
|
|
112
|
+
onMouseEnter={() => onActivate(entry.label)}
|
|
113
|
+
onMouseLeave={onClear}
|
|
114
|
+
onFocus={() => onActivate(entry.label)}
|
|
115
|
+
onBlur={onClear}
|
|
116
|
+
>
|
|
117
|
+
<span
|
|
118
|
+
className={`${frameStyles.legendSwatch} ${frameStyles.legendSwatchPill}`}
|
|
119
|
+
style={{ background: entry.color }}
|
|
120
|
+
aria-hidden
|
|
121
|
+
/>
|
|
122
|
+
<span>{entry.label}</span>
|
|
123
|
+
</button>
|
|
124
|
+
</li>
|
|
125
|
+
);
|
|
126
|
+
})}
|
|
127
|
+
</ul>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function BarChart({
|
|
132
|
+
data,
|
|
133
|
+
categories: categoriesProp,
|
|
134
|
+
series: seriesProp,
|
|
135
|
+
title,
|
|
136
|
+
description,
|
|
137
|
+
orientation = "vertical",
|
|
138
|
+
height = 240,
|
|
139
|
+
showGrid = true,
|
|
140
|
+
showTable = true,
|
|
141
|
+
emptyLabel = "No data for this range",
|
|
142
|
+
isLoading = false,
|
|
143
|
+
className = "",
|
|
144
|
+
}: BarChartProps) {
|
|
145
|
+
const [activeBar, setActiveBar] = useState<string | null>(null);
|
|
146
|
+
const [highlighted, setHighlighted] = useState<string | null>(null);
|
|
147
|
+
const { ref, width } = useChartSize(height);
|
|
148
|
+
|
|
149
|
+
const { categories, series } = useMemo(
|
|
150
|
+
() => normalizeBarInput({ data, categories: categoriesProp, series: seriesProp }),
|
|
151
|
+
[data, categoriesProp, seriesProp],
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const hasValues = series.some((entry) => entry.data.some((value) => Number.isFinite(value) && value !== 0));
|
|
155
|
+
const isEmpty = !categories.length || !series.length || !hasValues;
|
|
156
|
+
const isVertical = orientation === "vertical";
|
|
157
|
+
const isSingleSeries = series.length === 1;
|
|
158
|
+
const labelledSeries = series.filter((entry) => entry.label.trim().length > 0);
|
|
159
|
+
const showLegend = labelledSeries.length >= 2;
|
|
160
|
+
|
|
161
|
+
const layout = useMemo(() => {
|
|
162
|
+
if (isEmpty || width <= 0) return EMPTY_LAYOUT;
|
|
163
|
+
|
|
164
|
+
const plotLeft = CHART_MARGINS.left;
|
|
165
|
+
const plotRight = width - CHART_MARGINS.right;
|
|
166
|
+
const plotTop = CHART_MARGINS.top;
|
|
167
|
+
const plotBottom = height - CHART_MARGINS.bottom;
|
|
168
|
+
|
|
169
|
+
const [rawMin, rawMax] = seriesExtent(series, { includeZero: true });
|
|
170
|
+
const { ticks, min, max } = niceTicks(rawMin, rawMax, 5);
|
|
171
|
+
const valueScale = linearScale(
|
|
172
|
+
[min, max],
|
|
173
|
+
isVertical ? [plotBottom, plotTop] : [plotLeft, plotRight],
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const groupCount = categories.length;
|
|
177
|
+
const seriesCount = series.length;
|
|
178
|
+
const plotSpan = isVertical ? plotRight - plotLeft : plotBottom - plotTop;
|
|
179
|
+
const groupSize = plotSpan / Math.max(groupCount, 1);
|
|
180
|
+
const bandPad = groupSize * 0.24;
|
|
181
|
+
const barGap = seriesCount > 1 ? 4 : 0;
|
|
182
|
+
const inner = Math.max(groupSize - bandPad * 2, 8);
|
|
183
|
+
const barWidth = Math.min(
|
|
184
|
+
DEFAULT_MAX_BAR_WIDTH,
|
|
185
|
+
Math.max(8, (inner - barGap * Math.max(seriesCount - 1, 0)) / seriesCount),
|
|
186
|
+
);
|
|
187
|
+
const clusterWidth = seriesCount * barWidth + Math.max(seriesCount - 1, 0) * barGap;
|
|
188
|
+
|
|
189
|
+
const bars: BarGeom[] = categories.flatMap((category, categoryIndex) => {
|
|
190
|
+
const groupStart = isVertical
|
|
191
|
+
? plotLeft + categoryIndex * groupSize
|
|
192
|
+
: plotTop + categoryIndex * groupSize;
|
|
193
|
+
const clusterStart = groupStart + (groupSize - clusterWidth) / 2;
|
|
194
|
+
return series.map((entry, seriesIndex) => {
|
|
195
|
+
const value = entry.data[categoryIndex] ?? 0;
|
|
196
|
+
const start = clusterStart + seriesIndex * (barWidth + barGap);
|
|
197
|
+
const end = valueScale(value);
|
|
198
|
+
const origin = valueScale(0);
|
|
199
|
+
const color = isSingleSeries
|
|
200
|
+
? colorAt(categoryIndex, data?.[categoryIndex]?.color)
|
|
201
|
+
: (entry.color ?? colorAt(seriesIndex));
|
|
202
|
+
const x = isVertical ? start : Math.min(origin, end);
|
|
203
|
+
const y = isVertical ? Math.min(origin, end) : start;
|
|
204
|
+
const barW = isVertical ? barWidth : Math.abs(end - origin);
|
|
205
|
+
const barH = isVertical ? Math.abs(end - origin) : barWidth;
|
|
206
|
+
return {
|
|
207
|
+
key: `${category}-${entry.label}`,
|
|
208
|
+
category,
|
|
209
|
+
series: entry.label,
|
|
210
|
+
color,
|
|
211
|
+
x,
|
|
212
|
+
y,
|
|
213
|
+
width: barW,
|
|
214
|
+
height: barH,
|
|
215
|
+
value,
|
|
216
|
+
cx: x + barW / 2,
|
|
217
|
+
cy: y + barH / 2,
|
|
218
|
+
};
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const tickMarks: TickMark[] = ticks.map((tick) => ({
|
|
223
|
+
value: tick,
|
|
224
|
+
label: formatAxisTick(tick),
|
|
225
|
+
x: isVertical ? plotLeft - 8 : valueScale(tick),
|
|
226
|
+
y: isVertical ? valueScale(tick) : plotBottom + 18,
|
|
227
|
+
gridX1: isVertical ? plotLeft : valueScale(tick),
|
|
228
|
+
gridX2: isVertical ? plotRight : valueScale(tick),
|
|
229
|
+
gridY1: isVertical ? valueScale(tick) : plotTop,
|
|
230
|
+
gridY2: isVertical ? valueScale(tick) : plotBottom,
|
|
231
|
+
}));
|
|
232
|
+
|
|
233
|
+
const categoryLabels: CategoryLabel[] = categories.map((label, index) => ({
|
|
234
|
+
label,
|
|
235
|
+
x: isVertical ? plotLeft + index * groupSize + groupSize / 2 : plotLeft - 8,
|
|
236
|
+
y: isVertical ? plotBottom + 18 : plotTop + index * groupSize + groupSize / 2,
|
|
237
|
+
}));
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
bars,
|
|
241
|
+
ticks: tickMarks,
|
|
242
|
+
categoryLabels,
|
|
243
|
+
baseline: valueScale(0),
|
|
244
|
+
plotLeft,
|
|
245
|
+
plotRight,
|
|
246
|
+
plotTop,
|
|
247
|
+
plotBottom,
|
|
248
|
+
};
|
|
249
|
+
}, [categories, data, height, isEmpty, isSingleSeries, isVertical, series, width]);
|
|
250
|
+
|
|
251
|
+
const active = layout.bars.find((bar) => bar.key === activeBar) ?? null;
|
|
252
|
+
const flipTooltip = Boolean(active && width > 0 && active.cx > width * 0.6);
|
|
253
|
+
|
|
254
|
+
const isDimmed = (bar: BarGeom) => {
|
|
255
|
+
if (highlighted) return bar.series !== highlighted;
|
|
256
|
+
if (activeBar) return bar.key !== activeBar;
|
|
257
|
+
return false;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
return (
|
|
261
|
+
<ChartFrame
|
|
262
|
+
title={title}
|
|
263
|
+
description={description}
|
|
264
|
+
legend={showLegend ? (
|
|
265
|
+
<Legend
|
|
266
|
+
series={labelledSeries}
|
|
267
|
+
active={highlighted}
|
|
268
|
+
onActivate={setHighlighted}
|
|
269
|
+
onClear={() => setHighlighted(null)}
|
|
270
|
+
/>
|
|
271
|
+
) : undefined}
|
|
272
|
+
table={showTable ? <ChartTable categories={categories} series={series} /> : undefined}
|
|
273
|
+
isEmpty={isEmpty}
|
|
274
|
+
emptyLabel={emptyLabel}
|
|
275
|
+
isLoading={isLoading}
|
|
276
|
+
className={className}
|
|
277
|
+
>
|
|
278
|
+
<div ref={ref} className={styles.plot}>
|
|
279
|
+
<svg className={styles.chart} width={width || "100%"} height={height} role="img" aria-label={title}>
|
|
280
|
+
{showGrid
|
|
281
|
+
? layout.ticks.map((tick) => {
|
|
282
|
+
const horizontal = tick.gridY1 === tick.gridY2;
|
|
283
|
+
const x1 = horizontal ? tick.gridX1 : Math.round(tick.gridX1) + 0.5;
|
|
284
|
+
const x2 = horizontal ? tick.gridX2 : Math.round(tick.gridX2) + 0.5;
|
|
285
|
+
const y1 = horizontal ? Math.round(tick.gridY1) + 0.5 : tick.gridY1;
|
|
286
|
+
const y2 = horizontal ? Math.round(tick.gridY2) + 0.5 : tick.gridY2;
|
|
287
|
+
return (
|
|
288
|
+
<line
|
|
289
|
+
key={tick.value}
|
|
290
|
+
x1={x1}
|
|
291
|
+
x2={x2}
|
|
292
|
+
y1={y1}
|
|
293
|
+
y2={y2}
|
|
294
|
+
className={styles.grid}
|
|
295
|
+
vectorEffect="non-scaling-stroke"
|
|
296
|
+
/>
|
|
297
|
+
);
|
|
298
|
+
})
|
|
299
|
+
: null}
|
|
300
|
+
{width > 0 && !showGrid ? (
|
|
301
|
+
<>
|
|
302
|
+
<line
|
|
303
|
+
className={styles.axis}
|
|
304
|
+
x1={layout.plotLeft}
|
|
305
|
+
x2={layout.plotLeft}
|
|
306
|
+
y1={layout.plotTop}
|
|
307
|
+
y2={layout.plotBottom}
|
|
308
|
+
/>
|
|
309
|
+
<line
|
|
310
|
+
className={styles.axis}
|
|
311
|
+
x1={layout.plotLeft}
|
|
312
|
+
x2={layout.plotRight}
|
|
313
|
+
y1={layout.plotBottom}
|
|
314
|
+
y2={layout.plotBottom}
|
|
315
|
+
/>
|
|
316
|
+
</>
|
|
317
|
+
) : null}
|
|
318
|
+
{layout.bars.map((bar) => (
|
|
319
|
+
<rect
|
|
320
|
+
key={bar.key}
|
|
321
|
+
className={`${styles.bar}${isDimmed(bar) ? ` ${styles.barDimmed}` : ""}`}
|
|
322
|
+
x={bar.x}
|
|
323
|
+
y={bar.y}
|
|
324
|
+
width={bar.width}
|
|
325
|
+
height={bar.height}
|
|
326
|
+
fill={bar.color}
|
|
327
|
+
rx={2}
|
|
328
|
+
tabIndex={0}
|
|
329
|
+
role="button"
|
|
330
|
+
aria-label={`${bar.category} ${bar.series}: ${formatValue(bar.value)}`}
|
|
331
|
+
onMouseEnter={() => setActiveBar(bar.key)}
|
|
332
|
+
onMouseLeave={() => setActiveBar(null)}
|
|
333
|
+
onFocus={() => setActiveBar(bar.key)}
|
|
334
|
+
onBlur={() => setActiveBar(null)}
|
|
335
|
+
/>
|
|
336
|
+
))}
|
|
337
|
+
{layout.categoryLabels.map((entry) => (
|
|
338
|
+
<text
|
|
339
|
+
key={entry.label}
|
|
340
|
+
x={entry.x}
|
|
341
|
+
y={entry.y}
|
|
342
|
+
className={styles.categoryLabel}
|
|
343
|
+
textAnchor={isVertical ? "middle" : "end"}
|
|
344
|
+
dominantBaseline={isVertical ? "hanging" : "middle"}
|
|
345
|
+
>
|
|
346
|
+
{entry.label}
|
|
347
|
+
</text>
|
|
348
|
+
))}
|
|
349
|
+
{layout.ticks.map((tick) => (
|
|
350
|
+
<text
|
|
351
|
+
key={`tick-${tick.value}`}
|
|
352
|
+
x={tick.x}
|
|
353
|
+
y={tick.y}
|
|
354
|
+
className={styles.tickLabel}
|
|
355
|
+
textAnchor={isVertical ? "end" : "middle"}
|
|
356
|
+
dominantBaseline={isVertical ? "middle" : "hanging"}
|
|
357
|
+
>
|
|
358
|
+
{tick.label}
|
|
359
|
+
</text>
|
|
360
|
+
))}
|
|
361
|
+
</svg>
|
|
362
|
+
{active ? (
|
|
363
|
+
<div
|
|
364
|
+
className={`${frameStyles.tooltip}${flipTooltip ? ` ${frameStyles.tooltipFlip}` : ""}`}
|
|
365
|
+
style={{ left: active.cx, top: active.cy }}
|
|
366
|
+
role="status"
|
|
367
|
+
aria-live="polite"
|
|
368
|
+
>
|
|
369
|
+
<p className={frameStyles.tooltipTitle}>{active.category}</p>
|
|
370
|
+
<div className={frameStyles.tooltipRow}>
|
|
371
|
+
<span className={frameStyles.tooltipKey} style={{ background: active.color }} aria-hidden />
|
|
372
|
+
<span className={frameStyles.tooltipShare}>{active.series}</span>
|
|
373
|
+
<span className={frameStyles.tooltipValue}>{formatValue(active.value)}</span>
|
|
374
|
+
</div>
|
|
375
|
+
</div>
|
|
376
|
+
) : null}
|
|
377
|
+
</div>
|
|
378
|
+
</ChartFrame>
|
|
379
|
+
);
|
|
380
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ChartDatum, ChartSeries } from "../shared/chartMath";
|
|
2
|
+
|
|
3
|
+
export type BarChartOrientation = "vertical" | "horizontal";
|
|
4
|
+
|
|
5
|
+
export interface BarChartProps {
|
|
6
|
+
data?: ChartDatum[];
|
|
7
|
+
categories?: string[];
|
|
8
|
+
series?: ChartSeries[];
|
|
9
|
+
title?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
orientation?: BarChartOrientation;
|
|
12
|
+
height?: number;
|
|
13
|
+
showGrid?: boolean;
|
|
14
|
+
showTable?: boolean;
|
|
15
|
+
emptyLabel?: string;
|
|
16
|
+
isLoading?: boolean;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
.list {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-wrap: wrap;
|
|
4
|
+
align-items: center;
|
|
5
|
+
gap: var(--space-1);
|
|
6
|
+
margin: 0;
|
|
7
|
+
padding: 0;
|
|
8
|
+
list-style: none;
|
|
9
|
+
font-family: var(--font-sans);
|
|
10
|
+
font-size: var(--type-size-body-sm);
|
|
11
|
+
line-height: var(--type-line-body);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.item {
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
gap: var(--space-1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.link {
|
|
21
|
+
color: var(--text-secondary);
|
|
22
|
+
text-decoration: none;
|
|
23
|
+
border-radius: var(--radius-control-sm);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
button.link {
|
|
27
|
+
appearance: none;
|
|
28
|
+
margin: 0;
|
|
29
|
+
padding: 0;
|
|
30
|
+
border: 0;
|
|
31
|
+
background: transparent;
|
|
32
|
+
font: inherit;
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.link:hover {
|
|
37
|
+
color: var(--text-primary);
|
|
38
|
+
text-decoration: underline;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.link:focus-visible {
|
|
42
|
+
outline: var(--border-focus-width) solid var(--focus-ring);
|
|
43
|
+
outline-offset: var(--space-inset-2xs);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.current {
|
|
47
|
+
color: var(--text-primary);
|
|
48
|
+
font-weight: var(--type-weight-label);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.crumb {
|
|
52
|
+
color: var(--text-secondary);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.separator,
|
|
56
|
+
.ellipsis {
|
|
57
|
+
display: flex;
|
|
58
|
+
align-items: center;
|
|
59
|
+
color: var(--icon-muted);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.slash {
|
|
63
|
+
color: var(--text-muted);
|
|
64
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { LucideByName } from "../Button/lucideName";
|
|
2
|
+
import type { BreadcrumbItem, BreadcrumbProps } from "./Breadcrumb.types";
|
|
3
|
+
import styles from "./Breadcrumb.module.css";
|
|
4
|
+
|
|
5
|
+
export type { BreadcrumbItem, BreadcrumbProps, BreadcrumbSeparator } from "./Breadcrumb.types";
|
|
6
|
+
|
|
7
|
+
type VisibleNode =
|
|
8
|
+
| { kind: "ellipsis" }
|
|
9
|
+
| { kind: "item"; item: BreadcrumbItem; index: number };
|
|
10
|
+
|
|
11
|
+
function visibleNodes(items: BreadcrumbItem[], maxItems?: number): VisibleNode[] {
|
|
12
|
+
if (
|
|
13
|
+
maxItems == null ||
|
|
14
|
+
!Number.isFinite(maxItems) ||
|
|
15
|
+
maxItems < 1 ||
|
|
16
|
+
items.length <= maxItems
|
|
17
|
+
) {
|
|
18
|
+
return items.map((item, index) => ({ kind: "item", item, index }));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const tailCount = Math.max(maxItems - 1, 0);
|
|
22
|
+
const tail = items.slice(-tailCount);
|
|
23
|
+
const tailStart = items.length - tail.length;
|
|
24
|
+
const nodes: VisibleNode[] = [{ kind: "item", item: items[0], index: 0 }, { kind: "ellipsis" }];
|
|
25
|
+
|
|
26
|
+
tail.forEach((item, offset) => {
|
|
27
|
+
nodes.push({ kind: "item", item, index: tailStart + offset });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return nodes;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function Breadcrumb({ items, separator = "chevron", maxItems }: BreadcrumbProps) {
|
|
34
|
+
const nodes = visibleNodes(items, maxItems);
|
|
35
|
+
const lastIndex = items.length - 1;
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<nav aria-label="Breadcrumb">
|
|
39
|
+
<ol className={styles.list}>
|
|
40
|
+
{nodes.map((node, position) => {
|
|
41
|
+
const key = node.kind === "ellipsis" ? "ellipsis" : `crumb-${node.index}`;
|
|
42
|
+
const after =
|
|
43
|
+
position < nodes.length - 1 ? (
|
|
44
|
+
<li key={`sep-${position}`} className={styles.separator} aria-hidden="true">
|
|
45
|
+
{separator === "slash" ? (
|
|
46
|
+
<span className={styles.slash}>/</span>
|
|
47
|
+
) : (
|
|
48
|
+
<LucideByName name="ChevronRight" size={14} />
|
|
49
|
+
)}
|
|
50
|
+
</li>
|
|
51
|
+
) : null;
|
|
52
|
+
|
|
53
|
+
if (node.kind === "ellipsis") {
|
|
54
|
+
return [
|
|
55
|
+
<li key={key} className={styles.ellipsis} aria-hidden="true">
|
|
56
|
+
<LucideByName name="Ellipsis" size={14} />
|
|
57
|
+
</li>,
|
|
58
|
+
after,
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const isCurrent = node.index === lastIndex;
|
|
63
|
+
const content = isCurrent ? (
|
|
64
|
+
<span className={styles.current} aria-current="page">
|
|
65
|
+
{node.item.label}
|
|
66
|
+
</span>
|
|
67
|
+
) : node.item.onClick ? (
|
|
68
|
+
<button type="button" className={styles.link} onClick={node.item.onClick}>
|
|
69
|
+
{node.item.label}
|
|
70
|
+
</button>
|
|
71
|
+
) : node.item.href ? (
|
|
72
|
+
<a className={styles.link} href={node.item.href}>
|
|
73
|
+
{node.item.label}
|
|
74
|
+
</a>
|
|
75
|
+
) : (
|
|
76
|
+
<span className={styles.crumb}>{node.item.label}</span>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return [
|
|
80
|
+
<li key={key} className={styles.item}>
|
|
81
|
+
{content}
|
|
82
|
+
</li>,
|
|
83
|
+
after,
|
|
84
|
+
];
|
|
85
|
+
})}
|
|
86
|
+
</ol>
|
|
87
|
+
</nav>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface BreadcrumbItem {
|
|
2
|
+
label: string;
|
|
3
|
+
href?: string;
|
|
4
|
+
/** In-app select. When set, the crumb is a button (or a link that does not navigate). */
|
|
5
|
+
onClick?: () => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type BreadcrumbSeparator = "chevron" | "slash";
|
|
9
|
+
|
|
10
|
+
export interface BreadcrumbProps {
|
|
11
|
+
items: BreadcrumbItem[];
|
|
12
|
+
separator?: BreadcrumbSeparator;
|
|
13
|
+
maxItems?: number;
|
|
14
|
+
}
|