@soadtech/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +272 -0
- package/package.json +24 -0
- package/registry/base/cn.ts +5 -0
- package/registry/base/css-modules.d.ts +4 -0
- package/registry/base/theme/reset.css +43 -0
- package/registry/base/theme/tokens.css +154 -0
- package/registry/components/Accordion/Accordion.module.css +3 -0
- package/registry/components/Accordion/Accordion.tsx +54 -0
- package/registry/components/Accordion/Accordion.types.ts +17 -0
- package/registry/components/Accordion/AccordionContext.ts +18 -0
- package/registry/components/Accordion/AccordionItem.module.css +124 -0
- package/registry/components/Accordion/AccordionItem.tsx +148 -0
- package/registry/components/Accordion/AccordionItem.types.ts +14 -0
- package/registry/components/Accordion/index.ts +8 -0
- package/registry/components/ActionBar/ActionBar.module.css +18 -0
- package/registry/components/ActionBar/ActionBar.tsx +21 -0
- package/registry/components/ActionBar/ActionBar.types.ts +8 -0
- package/registry/components/ActionBar/ActionBarLink.module.css +31 -0
- package/registry/components/ActionBar/ActionBarLink.tsx +55 -0
- package/registry/components/ActionBar/ActionBarLink.types.ts +7 -0
- package/registry/components/ActionBar/index.ts +4 -0
- package/registry/components/Alert/Alert.module.css +172 -0
- package/registry/components/Alert/Alert.tsx +146 -0
- package/registry/components/Alert/Alert.types.ts +25 -0
- package/registry/components/Alert/index.ts +7 -0
- package/registry/components/Avatar/Avatar.module.css +100 -0
- package/registry/components/Avatar/Avatar.tsx +54 -0
- package/registry/components/Avatar/Avatar.types.ts +18 -0
- package/registry/components/Avatar/AvatarGroup.module.css +64 -0
- package/registry/components/Avatar/AvatarGroup.tsx +65 -0
- package/registry/components/Avatar/AvatarGroup.types.ts +13 -0
- package/registry/components/Avatar/index.ts +8 -0
- package/registry/components/Badge/Badge.module.css +92 -0
- package/registry/components/Badge/Badge.tsx +89 -0
- package/registry/components/Badge/Badge.types.ts +20 -0
- package/registry/components/Badge/TrendBadge.module.css +47 -0
- package/registry/components/Badge/TrendBadge.tsx +65 -0
- package/registry/components/Badge/TrendBadge.types.ts +15 -0
- package/registry/components/Badge/index.ts +14 -0
- package/registry/components/Breadcrumbs/BreadcrumbItem.tsx +41 -0
- package/registry/components/Breadcrumbs/Breadcrumbs.module.css +81 -0
- package/registry/components/Breadcrumbs/Breadcrumbs.tsx +71 -0
- package/registry/components/Breadcrumbs/Breadcrumbs.types.ts +22 -0
- package/registry/components/Breadcrumbs/index.ts +7 -0
- package/registry/components/Button/Button.module.css +169 -0
- package/registry/components/Button/Button.tsx +43 -0
- package/registry/components/Button/Button.types.ts +18 -0
- package/registry/components/Button/index.ts +7 -0
- package/registry/components/ButtonLink/ButtonLink.module.css +85 -0
- package/registry/components/ButtonLink/ButtonLink.tsx +42 -0
- package/registry/components/ButtonLink/ButtonLink.types.ts +18 -0
- package/registry/components/ButtonLink/index.ts +6 -0
- package/registry/components/Calendar/Calendar.module.css +213 -0
- package/registry/components/Calendar/Calendar.tsx +370 -0
- package/registry/components/Calendar/Calendar.types.ts +28 -0
- package/registry/components/Calendar/CalendarDialog.module.css +29 -0
- package/registry/components/Calendar/CalendarDialog.tsx +173 -0
- package/registry/components/Calendar/CalendarDialog.types.ts +30 -0
- package/registry/components/Calendar/index.ts +9 -0
- package/registry/components/Card/Card.module.css +35 -0
- package/registry/components/Card/Card.tsx +36 -0
- package/registry/components/Card/Card.types.ts +37 -0
- package/registry/components/Card/CardContent.module.css +3 -0
- package/registry/components/Card/CardContent.tsx +16 -0
- package/registry/components/Card/CardFooter.module.css +31 -0
- package/registry/components/Card/CardFooter.tsx +34 -0
- package/registry/components/Card/CardHeader.module.css +61 -0
- package/registry/components/Card/CardHeader.tsx +46 -0
- package/registry/components/Card/InsightCard.module.css +106 -0
- package/registry/components/Card/InsightCard.tsx +68 -0
- package/registry/components/Card/InsightCard.types.ts +24 -0
- package/registry/components/Card/KPICard.module.css +31 -0
- package/registry/components/Card/KPICard.tsx +29 -0
- package/registry/components/Card/KPICard.types.ts +13 -0
- package/registry/components/Card/ListItemCard.module.css +59 -0
- package/registry/components/Card/ListItemCard.tsx +37 -0
- package/registry/components/Card/ListItemCard.types.ts +18 -0
- package/registry/components/Card/PlanCard.module.css +125 -0
- package/registry/components/Card/PlanCard.tsx +108 -0
- package/registry/components/Card/PlanCard.types.ts +30 -0
- package/registry/components/Card/ProductCard.module.css +118 -0
- package/registry/components/Card/ProductCard.tsx +56 -0
- package/registry/components/Card/ProductCard.types.ts +24 -0
- package/registry/components/Card/StatCard.module.css +20 -0
- package/registry/components/Card/StatCard.tsx +26 -0
- package/registry/components/Card/StatCard.types.ts +12 -0
- package/registry/components/Card/UserGroupCard.module.css +50 -0
- package/registry/components/Card/UserGroupCard.tsx +59 -0
- package/registry/components/Card/UserGroupCard.types.ts +23 -0
- package/registry/components/Card/index.ts +38 -0
- package/registry/components/Chart/BarChart.module.css +54 -0
- package/registry/components/Chart/BarChart.tsx +196 -0
- package/registry/components/Chart/BarChart.types.ts +20 -0
- package/registry/components/Chart/ChartAction.module.css +43 -0
- package/registry/components/Chart/ChartAction.tsx +35 -0
- package/registry/components/Chart/ChartAction.types.ts +17 -0
- package/registry/components/Chart/ChartAxis.module.css +47 -0
- package/registry/components/Chart/ChartAxis.tsx +79 -0
- package/registry/components/Chart/ChartAxis.types.ts +14 -0
- package/registry/components/Chart/ChartLegend.module.css +31 -0
- package/registry/components/Chart/ChartLegend.tsx +49 -0
- package/registry/components/Chart/ChartLegend.types.ts +18 -0
- package/registry/components/Chart/ChartTooltip.module.css +54 -0
- package/registry/components/Chart/ChartTooltip.tsx +44 -0
- package/registry/components/Chart/ChartTooltip.types.ts +19 -0
- package/registry/components/Chart/DonutChart.module.css +32 -0
- package/registry/components/Chart/DonutChart.tsx +107 -0
- package/registry/components/Chart/DonutChart.types.ts +20 -0
- package/registry/components/Chart/GridChart.module.css +26 -0
- package/registry/components/Chart/GridChart.tsx +61 -0
- package/registry/components/Chart/GridChart.types.ts +14 -0
- package/registry/components/Chart/HoverTooltip.module.css +16 -0
- package/registry/components/Chart/HoverTooltip.tsx +22 -0
- package/registry/components/Chart/KPIIndicator.module.css +48 -0
- package/registry/components/Chart/KPIIndicator.tsx +28 -0
- package/registry/components/Chart/KPIIndicator.types.ts +16 -0
- package/registry/components/Chart/LineChart.module.css +54 -0
- package/registry/components/Chart/LineChart.tsx +282 -0
- package/registry/components/Chart/LineChart.types.ts +22 -0
- package/registry/components/Chart/ProgressChart.module.css +54 -0
- package/registry/components/Chart/ProgressChart.tsx +64 -0
- package/registry/components/Chart/ProgressChart.types.ts +18 -0
- package/registry/components/Chart/TrendLineChart.module.css +5 -0
- package/registry/components/Chart/TrendLineChart.tsx +131 -0
- package/registry/components/Chart/TrendLineChart.types.ts +19 -0
- package/registry/components/Chart/chart.utils.ts +131 -0
- package/registry/components/Chart/index.ts +47 -0
- package/registry/components/Chart/useChartHover.ts +24 -0
- package/registry/components/Checkbox/Checkbox.module.css +101 -0
- package/registry/components/Checkbox/Checkbox.tsx +100 -0
- package/registry/components/Checkbox/Checkbox.types.ts +11 -0
- package/registry/components/Checkbox/CheckboxField.module.css +69 -0
- package/registry/components/Checkbox/CheckboxField.tsx +54 -0
- package/registry/components/Checkbox/CheckboxField.types.ts +9 -0
- package/registry/components/Checkbox/CheckboxGroup.module.css +41 -0
- package/registry/components/Checkbox/CheckboxGroup.tsx +60 -0
- package/registry/components/Checkbox/CheckboxGroup.types.ts +11 -0
- package/registry/components/Checkbox/CheckboxGroupContext.ts +13 -0
- package/registry/components/Checkbox/index.ts +11 -0
- package/registry/components/Chip/Chip.module.css +143 -0
- package/registry/components/Chip/Chip.tsx +93 -0
- package/registry/components/Chip/Chip.types.ts +19 -0
- package/registry/components/Chip/ChipGroup.module.css +5 -0
- package/registry/components/Chip/ChipGroup.tsx +16 -0
- package/registry/components/Chip/ChipGroup.types.ts +3 -0
- package/registry/components/Chip/index.ts +9 -0
- package/registry/components/Datepicker/Datepicker.module.css +133 -0
- package/registry/components/Datepicker/Datepicker.tsx +236 -0
- package/registry/components/Datepicker/Datepicker.types.ts +36 -0
- package/registry/components/Datepicker/index.ts +2 -0
- package/registry/components/Dialog/Dialog.module.css +18 -0
- package/registry/components/Dialog/Dialog.tsx +69 -0
- package/registry/components/Dialog/Dialog.types.ts +45 -0
- package/registry/components/Dialog/DialogBody.module.css +3 -0
- package/registry/components/Dialog/DialogBody.tsx +16 -0
- package/registry/components/Dialog/DialogContext.ts +11 -0
- package/registry/components/Dialog/DialogFooter.module.css +38 -0
- package/registry/components/Dialog/DialogFooter.tsx +30 -0
- package/registry/components/Dialog/DialogHeader.module.css +70 -0
- package/registry/components/Dialog/DialogHeader.tsx +72 -0
- package/registry/components/Dialog/DialogIcon.module.css +31 -0
- package/registry/components/Dialog/DialogIcon.tsx +89 -0
- package/registry/components/Dialog/index.ts +14 -0
- package/registry/components/Divider/Divider.module.css +19 -0
- package/registry/components/Divider/Divider.tsx +20 -0
- package/registry/components/Divider/Divider.types.ts +9 -0
- package/registry/components/Divider/index.ts +2 -0
- package/registry/components/DropdownMenu/DropdownMenu.module.css +9 -0
- package/registry/components/DropdownMenu/DropdownMenu.tsx +21 -0
- package/registry/components/DropdownMenu/DropdownMenu.types.ts +22 -0
- package/registry/components/DropdownMenu/DropdownMenuDivider.module.css +5 -0
- package/registry/components/DropdownMenu/DropdownMenuDivider.tsx +20 -0
- package/registry/components/DropdownMenu/DropdownMenuHeader.module.css +7 -0
- package/registry/components/DropdownMenu/DropdownMenuHeader.tsx +17 -0
- package/registry/components/DropdownMenu/DropdownMenuItem.module.css +78 -0
- package/registry/components/DropdownMenu/DropdownMenuItem.tsx +40 -0
- package/registry/components/DropdownMenu/index.ts +10 -0
- package/registry/components/FileUpload/FileUpload.module.css +122 -0
- package/registry/components/FileUpload/FileUpload.tsx +354 -0
- package/registry/components/FileUpload/FileUpload.types.ts +89 -0
- package/registry/components/FileUpload/FileUploadIcon.module.css +61 -0
- package/registry/components/FileUpload/FileUploadIcon.tsx +84 -0
- package/registry/components/FileUpload/FileUploadInput.module.css +140 -0
- package/registry/components/FileUpload/FileUploadInput.tsx +113 -0
- package/registry/components/FileUpload/FileUploadItem.module.css +41 -0
- package/registry/components/FileUpload/FileUploadItem.tsx +39 -0
- package/registry/components/FileUpload/index.ts +12 -0
- package/registry/components/InputCounter/InputCounter.module.css +146 -0
- package/registry/components/InputCounter/InputCounter.tsx +232 -0
- package/registry/components/InputCounter/InputCounter.types.ts +37 -0
- package/registry/components/InputCounter/index.ts +7 -0
- package/registry/components/InputMessage/InputMessage.module.css +148 -0
- package/registry/components/InputMessage/InputMessage.tsx +294 -0
- package/registry/components/InputMessage/InputMessage.types.ts +30 -0
- package/registry/components/InputMessage/index.ts +2 -0
- package/registry/components/InputSearch/InputSearch.module.css +168 -0
- package/registry/components/InputSearch/InputSearch.tsx +251 -0
- package/registry/components/InputSearch/InputSearch.types.ts +35 -0
- package/registry/components/InputSearch/index.ts +6 -0
- package/registry/components/InputText/InputText.module.css +183 -0
- package/registry/components/InputText/InputText.tsx +244 -0
- package/registry/components/InputText/InputText.types.ts +32 -0
- package/registry/components/InputText/index.ts +7 -0
- package/registry/components/InputTextArea/InputTextArea.module.css +141 -0
- package/registry/components/InputTextArea/InputTextArea.tsx +170 -0
- package/registry/components/InputTextArea/InputTextArea.types.ts +18 -0
- package/registry/components/InputTextArea/index.ts +6 -0
- package/registry/components/NavbarUser/NavbarUser.module.css +265 -0
- package/registry/components/NavbarUser/NavbarUser.tsx +202 -0
- package/registry/components/NavbarUser/NavbarUser.types.ts +31 -0
- package/registry/components/NavbarUser/index.ts +2 -0
- package/registry/components/Notification/Notification.types.ts +65 -0
- package/registry/components/Notification/NotificationItem.module.css +143 -0
- package/registry/components/Notification/NotificationItem.tsx +157 -0
- package/registry/components/Notification/NotificationPanel.module.css +75 -0
- package/registry/components/Notification/NotificationPanel.tsx +68 -0
- package/registry/components/Notification/NotificationReply.module.css +56 -0
- package/registry/components/Notification/NotificationReply.tsx +52 -0
- package/registry/components/Notification/index.ts +9 -0
- package/registry/components/Pagination/Pagination.module.css +123 -0
- package/registry/components/Pagination/Pagination.tsx +212 -0
- package/registry/components/Pagination/Pagination.types.ts +24 -0
- package/registry/components/Pagination/PaginationDots.module.css +60 -0
- package/registry/components/Pagination/PaginationDots.tsx +48 -0
- package/registry/components/Pagination/PaginationDots.types.ts +17 -0
- package/registry/components/Pagination/index.ts +12 -0
- package/registry/components/Persona/MessageDropdown.module.css +76 -0
- package/registry/components/Persona/MessageDropdown.tsx +68 -0
- package/registry/components/Persona/Persona.module.css +92 -0
- package/registry/components/Persona/Persona.tsx +90 -0
- package/registry/components/Persona/Persona.types.ts +71 -0
- package/registry/components/Persona/PersonaAction.module.css +80 -0
- package/registry/components/Persona/PersonaAction.tsx +49 -0
- package/registry/components/Persona/PersonaMessage.module.css +156 -0
- package/registry/components/Persona/PersonaMessage.tsx +70 -0
- package/registry/components/Persona/index.ts +11 -0
- package/registry/components/Progress/Progress.module.css +41 -0
- package/registry/components/Progress/Progress.tsx +43 -0
- package/registry/components/Progress/Progress.types.ts +10 -0
- package/registry/components/Progress/index.ts +2 -0
- package/registry/components/RadioButton/RadioButton.module.css +103 -0
- package/registry/components/RadioButton/RadioButton.tsx +59 -0
- package/registry/components/RadioButton/RadioButton.types.ts +19 -0
- package/registry/components/RadioButton/RadioField.module.css +68 -0
- package/registry/components/RadioButton/RadioField.tsx +68 -0
- package/registry/components/RadioButton/RadioGroup.module.css +41 -0
- package/registry/components/RadioButton/RadioGroup.tsx +76 -0
- package/registry/components/RadioButton/RadioGroupContext.ts +16 -0
- package/registry/components/RadioButton/index.ts +12 -0
- package/registry/components/RangeSlider/RangeSlider.module.css +133 -0
- package/registry/components/RangeSlider/RangeSlider.tsx +251 -0
- package/registry/components/RangeSlider/RangeSlider.types.ts +25 -0
- package/registry/components/RangeSlider/index.ts +2 -0
- package/registry/components/Rating/Rating.module.css +56 -0
- package/registry/components/Rating/Rating.tsx +142 -0
- package/registry/components/Rating/Rating.types.ts +14 -0
- package/registry/components/Rating/index.ts +7 -0
- package/registry/components/SegmentedControl/SegmentedControl.module.css +56 -0
- package/registry/components/SegmentedControl/SegmentedControl.tsx +46 -0
- package/registry/components/SegmentedControl/SegmentedControl.types.ts +27 -0
- package/registry/components/SegmentedControl/SegmentedControlContext.ts +20 -0
- package/registry/components/SegmentedControl/SegmentedControlItem.module.css +55 -0
- package/registry/components/SegmentedControl/SegmentedControlItem.tsx +32 -0
- package/registry/components/SegmentedControl/index.ts +8 -0
- package/registry/components/SelectDropdown/SelectDropdown.module.css +214 -0
- package/registry/components/SelectDropdown/SelectDropdown.tsx +375 -0
- package/registry/components/SelectDropdown/SelectDropdown.types.ts +50 -0
- package/registry/components/SelectDropdown/SelectDropdownOption.module.css +101 -0
- package/registry/components/SelectDropdown/SelectDropdownOption.tsx +86 -0
- package/registry/components/SelectDropdown/SelectDropdownOverlay.module.css +74 -0
- package/registry/components/SelectDropdown/SelectDropdownOverlay.tsx +202 -0
- package/registry/components/SelectDropdown/index.ts +11 -0
- package/registry/components/Sidebar/Sidebar.module.css +14 -0
- package/registry/components/Sidebar/Sidebar.tsx +41 -0
- package/registry/components/Sidebar/Sidebar.types.ts +41 -0
- package/registry/components/Sidebar/SidebarContent.module.css +5 -0
- package/registry/components/Sidebar/SidebarContent.tsx +14 -0
- package/registry/components/Sidebar/SidebarContext.ts +15 -0
- package/registry/components/Sidebar/SidebarDivider.module.css +5 -0
- package/registry/components/Sidebar/SidebarDivider.tsx +17 -0
- package/registry/components/Sidebar/SidebarFooter.module.css +5 -0
- package/registry/components/Sidebar/SidebarFooter.tsx +14 -0
- package/registry/components/Sidebar/SidebarGroup.module.css +12 -0
- package/registry/components/Sidebar/SidebarGroup.tsx +22 -0
- package/registry/components/Sidebar/SidebarHeader.module.css +5 -0
- package/registry/components/Sidebar/SidebarHeader.tsx +14 -0
- package/registry/components/Sidebar/SidebarNavItem.module.css +176 -0
- package/registry/components/Sidebar/SidebarNavItem.tsx +96 -0
- package/registry/components/Sidebar/index.ts +16 -0
- package/registry/components/Stepper/Stepper.module.css +11 -0
- package/registry/components/Stepper/Stepper.tsx +47 -0
- package/registry/components/Stepper/Stepper.types.ts +26 -0
- package/registry/components/Stepper/StepperContext.ts +17 -0
- package/registry/components/Stepper/StepperStep.module.css +183 -0
- package/registry/components/Stepper/StepperStep.tsx +204 -0
- package/registry/components/Stepper/index.ts +9 -0
- package/registry/components/Switch/Switch.module.css +145 -0
- package/registry/components/Switch/Switch.tsx +96 -0
- package/registry/components/Switch/Switch.types.ts +19 -0
- package/registry/components/Switch/SwitchField.module.css +69 -0
- package/registry/components/Switch/SwitchField.tsx +49 -0
- package/registry/components/Switch/index.ts +8 -0
- package/registry/components/Tab/Tab.module.css +20 -0
- package/registry/components/Tab/Tab.tsx +35 -0
- package/registry/components/Tab/Tab.types.ts +21 -0
- package/registry/components/Tab/TabAdd.module.css +36 -0
- package/registry/components/Tab/TabAdd.tsx +41 -0
- package/registry/components/Tab/TabContext.ts +19 -0
- package/registry/components/Tab/TabItem.module.css +145 -0
- package/registry/components/Tab/TabItem.tsx +87 -0
- package/registry/components/Tab/index.ts +9 -0
- package/registry/components/Table/Table.module.css +33 -0
- package/registry/components/Table/Table.tsx +74 -0
- package/registry/components/Table/Table.types.ts +64 -0
- package/registry/components/Table/TableBody.tsx +23 -0
- package/registry/components/Table/TableCell.module.css +21 -0
- package/registry/components/Table/TableCell.tsx +20 -0
- package/registry/components/Table/TableContext.ts +22 -0
- package/registry/components/Table/TableFooter.module.css +27 -0
- package/registry/components/Table/TableFooter.tsx +20 -0
- package/registry/components/Table/TableHeader.module.css +3 -0
- package/registry/components/Table/TableHeader.tsx +17 -0
- package/registry/components/Table/TableHeaderCell.module.css +55 -0
- package/registry/components/Table/TableHeaderCell.tsx +98 -0
- package/registry/components/Table/TableRow.module.css +53 -0
- package/registry/components/Table/TableRow.tsx +31 -0
- package/registry/components/Table/TableToolbar.module.css +7 -0
- package/registry/components/Table/TableToolbar.tsx +16 -0
- package/registry/components/Table/index.ts +22 -0
- package/registry/components/Tag/Tag.module.css +46 -0
- package/registry/components/Tag/Tag.tsx +38 -0
- package/registry/components/Tag/Tag.types.ts +37 -0
- package/registry/components/Tag/TagBrand.module.css +42 -0
- package/registry/components/Tag/TagBrand.tsx +38 -0
- package/registry/components/Tag/TagStatus.module.css +43 -0
- package/registry/components/Tag/TagStatus.tsx +119 -0
- package/registry/components/Tag/index.ts +15 -0
- package/registry/components/Tooltip/Tooltip.module.css +208 -0
- package/registry/components/Tooltip/Tooltip.tsx +81 -0
- package/registry/components/Tooltip/Tooltip.types.ts +27 -0
- package/registry/components/Tooltip/index.ts +7 -0
- package/registry/components/TreeviewList/TreeviewItem.module.css +89 -0
- package/registry/components/TreeviewList/TreeviewItem.tsx +142 -0
- package/registry/components/TreeviewList/TreeviewList.module.css +3 -0
- package/registry/components/TreeviewList/TreeviewList.tsx +19 -0
- package/registry/components/TreeviewList/TreeviewList.types.ts +18 -0
- package/registry/components/TreeviewList/TreeviewListContext.ts +13 -0
- package/registry/components/TreeviewList/index.ts +6 -0
- package/registry/components/VerificationCode/VerificationCode.module.css +49 -0
- package/registry/components/VerificationCode/VerificationCode.tsx +147 -0
- package/registry/components/VerificationCode/VerificationCode.types.ts +21 -0
- package/registry/components/VerificationCode/index.ts +2 -0
- package/registry/registry.json +746 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { forwardRef } from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
import type { KPIIndicatorProps } from './KPIIndicator.types';
|
|
4
|
+
import styles from './KPIIndicator.module.css';
|
|
5
|
+
|
|
6
|
+
export const KPIIndicator = forwardRef<HTMLDivElement, KPIIndicatorProps>(
|
|
7
|
+
(
|
|
8
|
+
{ value, label, trend, description, size = 'md', className, ...rest },
|
|
9
|
+
ref
|
|
10
|
+
) => {
|
|
11
|
+
return (
|
|
12
|
+
<div
|
|
13
|
+
ref={ref}
|
|
14
|
+
className={cn(styles.root, styles[size], className)}
|
|
15
|
+
{...rest}
|
|
16
|
+
>
|
|
17
|
+
{label && <span className={styles.label}>{label}</span>}
|
|
18
|
+
<div className={styles.valueRow}>
|
|
19
|
+
<span className={styles.value}>{value}</span>
|
|
20
|
+
{trend && <span className={styles.trend}>{trend}</span>}
|
|
21
|
+
</div>
|
|
22
|
+
{description && <span className={styles.description}>{description}</span>}
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
KPIIndicator.displayName = 'KPIIndicator';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export type KPIIndicatorSize = 'sm' | 'md' | 'lg';
|
|
4
|
+
|
|
5
|
+
export interface KPIIndicatorProps extends HTMLAttributes<HTMLDivElement> {
|
|
6
|
+
/** Large display value (e.g. "2,450" or "$12.5k") */
|
|
7
|
+
value: string;
|
|
8
|
+
/** Label displayed above the value */
|
|
9
|
+
label?: string;
|
|
10
|
+
/** Trend badge element (e.g. <TrendBadge />) */
|
|
11
|
+
trend?: ReactNode;
|
|
12
|
+
/** Description text below the value */
|
|
13
|
+
description?: string;
|
|
14
|
+
/** Size variant */
|
|
15
|
+
size?: KPIIndicatorSize;
|
|
16
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: var(--st-space-3);
|
|
5
|
+
font-family: var(--st-font-family);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.legend {
|
|
9
|
+
display: flex;
|
|
10
|
+
justify-content: flex-end;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.grid {
|
|
14
|
+
display: grid;
|
|
15
|
+
grid-template-columns: auto 1fr;
|
|
16
|
+
grid-template-rows: 1fr auto;
|
|
17
|
+
gap: var(--st-space-2);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.yAxis {
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
justify-content: space-between;
|
|
24
|
+
text-align: right;
|
|
25
|
+
padding-right: var(--st-space-2);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.yLabel {
|
|
29
|
+
font-size: var(--st-font-size-xs);
|
|
30
|
+
color: var(--st-color-chart-axis);
|
|
31
|
+
line-height: 1;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.chartArea {
|
|
35
|
+
position: relative;
|
|
36
|
+
width: 100%;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.chartArea svg {
|
|
40
|
+
display: block;
|
|
41
|
+
width: 100%;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.xAxis {
|
|
45
|
+
display: flex;
|
|
46
|
+
justify-content: space-between;
|
|
47
|
+
padding-top: var(--st-space-2);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.xLabel {
|
|
51
|
+
font-size: var(--st-font-size-xs);
|
|
52
|
+
color: var(--st-color-chart-axis);
|
|
53
|
+
text-align: center;
|
|
54
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { forwardRef, useMemo, useRef, useEffect, useState, useId } from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
import { niceScale, smoothPath, areaPath } from './chart.utils';
|
|
4
|
+
import { useChartHover } from './useChartHover';
|
|
5
|
+
import { HoverTooltip } from './HoverTooltip';
|
|
6
|
+
import type { LineChartProps } from './LineChart.types';
|
|
7
|
+
import styles from './LineChart.module.css';
|
|
8
|
+
|
|
9
|
+
function buildLinePath(
|
|
10
|
+
values: number[],
|
|
11
|
+
chartWidth: number,
|
|
12
|
+
chartHeight: number,
|
|
13
|
+
scaleMax: number,
|
|
14
|
+
smooth: boolean
|
|
15
|
+
): { points: { x: number; y: number }[]; path: string } {
|
|
16
|
+
const points = values.map((v, i) => ({
|
|
17
|
+
x: (i / (values.length - 1)) * chartWidth,
|
|
18
|
+
y: chartHeight - (scaleMax > 0 ? (v / scaleMax) * chartHeight : 0),
|
|
19
|
+
}));
|
|
20
|
+
const path = smooth
|
|
21
|
+
? smoothPath(points)
|
|
22
|
+
: `M${points.map((p) => `${p.x},${p.y}`).join('L')}`;
|
|
23
|
+
return { points, path };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const LineChart = forwardRef<HTMLDivElement, LineChartProps>(
|
|
27
|
+
(
|
|
28
|
+
{
|
|
29
|
+
data,
|
|
30
|
+
comparison = false,
|
|
31
|
+
smooth = true,
|
|
32
|
+
areaFill = true,
|
|
33
|
+
height = 200,
|
|
34
|
+
legend,
|
|
35
|
+
className,
|
|
36
|
+
...rest
|
|
37
|
+
},
|
|
38
|
+
ref
|
|
39
|
+
) => {
|
|
40
|
+
const chartRef = useRef<HTMLDivElement>(null);
|
|
41
|
+
const [chartWidth, setChartWidth] = useState(0);
|
|
42
|
+
const gradId1 = useId();
|
|
43
|
+
const gradId2 = useId();
|
|
44
|
+
const { hover, show, hide } = useChartHover();
|
|
45
|
+
const [activeIdx, setActiveIdx] = useState<number | null>(null);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!chartRef.current) return;
|
|
49
|
+
const ro = new ResizeObserver((entries) => {
|
|
50
|
+
for (const entry of entries) {
|
|
51
|
+
setChartWidth(entry.contentRect.width);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
ro.observe(chartRef.current);
|
|
55
|
+
return () => ro.disconnect();
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
const allValues = useMemo(() => {
|
|
59
|
+
const vals = data.map((d) => d.value);
|
|
60
|
+
if (comparison) vals.push(...data.map((d) => d.compareValue ?? 0));
|
|
61
|
+
return vals;
|
|
62
|
+
}, [data, comparison]);
|
|
63
|
+
|
|
64
|
+
const maxVal = Math.max(...allValues, 0);
|
|
65
|
+
const ticks = niceScale(0, maxVal);
|
|
66
|
+
const scaleMax = ticks[ticks.length - 1];
|
|
67
|
+
|
|
68
|
+
const primary = useMemo(
|
|
69
|
+
() =>
|
|
70
|
+
chartWidth > 0
|
|
71
|
+
? buildLinePath(data.map((d) => d.value), chartWidth, height, scaleMax, smooth)
|
|
72
|
+
: null,
|
|
73
|
+
[data, chartWidth, height, scaleMax, smooth]
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const secondary = useMemo(
|
|
77
|
+
() =>
|
|
78
|
+
comparison && chartWidth > 0
|
|
79
|
+
? buildLinePath(
|
|
80
|
+
data.map((d) => d.compareValue ?? 0),
|
|
81
|
+
chartWidth,
|
|
82
|
+
height,
|
|
83
|
+
scaleMax,
|
|
84
|
+
smooth
|
|
85
|
+
)
|
|
86
|
+
: null,
|
|
87
|
+
[data, comparison, chartWidth, height, scaleMax, smooth]
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const slotWidth = chartWidth > 0 && data.length > 1 ? chartWidth / (data.length - 1) : chartWidth;
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<div ref={ref} className={cn(styles.root, className)} {...rest}>
|
|
94
|
+
{legend && <div className={styles.legend}>{legend}</div>}
|
|
95
|
+
<div className={styles.grid}>
|
|
96
|
+
{/* Y-axis */}
|
|
97
|
+
<div className={styles.yAxis} style={{ height }}>
|
|
98
|
+
{[...ticks].reverse().map((tick, i) => (
|
|
99
|
+
<span key={i} className={styles.yLabel}>
|
|
100
|
+
{tick >= 1000
|
|
101
|
+
? `${(tick / 1000).toFixed(tick % 1000 === 0 ? 0 : 1)}k`
|
|
102
|
+
: tick}
|
|
103
|
+
</span>
|
|
104
|
+
))}
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
{/* Chart area */}
|
|
108
|
+
<div ref={chartRef} className={styles.chartArea} style={{ height }}>
|
|
109
|
+
{chartWidth > 0 && primary && (
|
|
110
|
+
<svg
|
|
111
|
+
width={chartWidth}
|
|
112
|
+
height={height}
|
|
113
|
+
viewBox={`0 0 ${chartWidth} ${height}`}
|
|
114
|
+
>
|
|
115
|
+
<defs>
|
|
116
|
+
<linearGradient id={gradId1} x1="0" y1="0" x2="0" y2="1">
|
|
117
|
+
<stop
|
|
118
|
+
offset="0%"
|
|
119
|
+
stopColor="var(--st-color-chart-1)"
|
|
120
|
+
stopOpacity="0.3"
|
|
121
|
+
/>
|
|
122
|
+
<stop
|
|
123
|
+
offset="100%"
|
|
124
|
+
stopColor="var(--st-color-chart-1-subtle)"
|
|
125
|
+
stopOpacity="0"
|
|
126
|
+
/>
|
|
127
|
+
</linearGradient>
|
|
128
|
+
<linearGradient id={gradId2} x1="0" y1="0" x2="0" y2="1">
|
|
129
|
+
<stop
|
|
130
|
+
offset="0%"
|
|
131
|
+
stopColor="var(--st-color-chart-2)"
|
|
132
|
+
stopOpacity="0.3"
|
|
133
|
+
/>
|
|
134
|
+
<stop
|
|
135
|
+
offset="100%"
|
|
136
|
+
stopColor="var(--st-color-chart-2-subtle)"
|
|
137
|
+
stopOpacity="0"
|
|
138
|
+
/>
|
|
139
|
+
</linearGradient>
|
|
140
|
+
</defs>
|
|
141
|
+
|
|
142
|
+
{/* Grid lines */}
|
|
143
|
+
{ticks.map((_, i) => {
|
|
144
|
+
const y =
|
|
145
|
+
height - (i / (ticks.length - 1)) * height;
|
|
146
|
+
return (
|
|
147
|
+
<line
|
|
148
|
+
key={i}
|
|
149
|
+
x1={0}
|
|
150
|
+
y1={y}
|
|
151
|
+
x2={chartWidth}
|
|
152
|
+
y2={y}
|
|
153
|
+
stroke="var(--st-color-chart-grid)"
|
|
154
|
+
strokeWidth="1"
|
|
155
|
+
/>
|
|
156
|
+
);
|
|
157
|
+
})}
|
|
158
|
+
|
|
159
|
+
{/* Secondary area + line */}
|
|
160
|
+
{secondary && areaFill && (
|
|
161
|
+
<path
|
|
162
|
+
d={areaPath(
|
|
163
|
+
secondary.path,
|
|
164
|
+
height,
|
|
165
|
+
secondary.points[0].x,
|
|
166
|
+
secondary.points[secondary.points.length - 1].x
|
|
167
|
+
)}
|
|
168
|
+
fill={`url(#${gradId2})`}
|
|
169
|
+
/>
|
|
170
|
+
)}
|
|
171
|
+
{secondary && (
|
|
172
|
+
<path
|
|
173
|
+
d={secondary.path}
|
|
174
|
+
fill="none"
|
|
175
|
+
stroke="var(--st-color-chart-2)"
|
|
176
|
+
strokeWidth="2"
|
|
177
|
+
strokeLinecap="round"
|
|
178
|
+
/>
|
|
179
|
+
)}
|
|
180
|
+
|
|
181
|
+
{/* Primary area + line */}
|
|
182
|
+
{areaFill && (
|
|
183
|
+
<path
|
|
184
|
+
d={areaPath(
|
|
185
|
+
primary.path,
|
|
186
|
+
height,
|
|
187
|
+
primary.points[0].x,
|
|
188
|
+
primary.points[primary.points.length - 1].x
|
|
189
|
+
)}
|
|
190
|
+
fill={`url(#${gradId1})`}
|
|
191
|
+
/>
|
|
192
|
+
)}
|
|
193
|
+
<path
|
|
194
|
+
d={primary.path}
|
|
195
|
+
fill="none"
|
|
196
|
+
stroke="var(--st-color-chart-1)"
|
|
197
|
+
strokeWidth="2"
|
|
198
|
+
strokeLinecap="round"
|
|
199
|
+
/>
|
|
200
|
+
|
|
201
|
+
{/* Dots + active highlight */}
|
|
202
|
+
{primary.points.map((p, i) => (
|
|
203
|
+
<circle
|
|
204
|
+
key={i}
|
|
205
|
+
cx={p.x}
|
|
206
|
+
cy={p.y}
|
|
207
|
+
r={activeIdx === i ? 5 : 3}
|
|
208
|
+
fill="var(--st-color-chart-1)"
|
|
209
|
+
stroke={activeIdx === i ? 'var(--st-color-surface)' : 'none'}
|
|
210
|
+
strokeWidth={activeIdx === i ? 2 : 0}
|
|
211
|
+
/>
|
|
212
|
+
))}
|
|
213
|
+
|
|
214
|
+
{/* Vertical indicator line */}
|
|
215
|
+
{activeIdx !== null && primary.points[activeIdx] && (
|
|
216
|
+
<line
|
|
217
|
+
x1={primary.points[activeIdx].x}
|
|
218
|
+
y1={0}
|
|
219
|
+
x2={primary.points[activeIdx].x}
|
|
220
|
+
y2={height}
|
|
221
|
+
stroke="var(--st-color-chart-axis)"
|
|
222
|
+
strokeWidth="1"
|
|
223
|
+
strokeDasharray="4 3"
|
|
224
|
+
opacity="0.5"
|
|
225
|
+
/>
|
|
226
|
+
)}
|
|
227
|
+
|
|
228
|
+
{/* Invisible hit areas per data point */}
|
|
229
|
+
{data.map((d, i) => {
|
|
230
|
+
const px = primary.points[i]?.x ?? 0;
|
|
231
|
+
const py = primary.points[i]?.y ?? 0;
|
|
232
|
+
return (
|
|
233
|
+
<rect
|
|
234
|
+
key={`hit-${i}`}
|
|
235
|
+
x={px - slotWidth / 2}
|
|
236
|
+
y={0}
|
|
237
|
+
width={slotWidth}
|
|
238
|
+
height={height}
|
|
239
|
+
fill="transparent"
|
|
240
|
+
onMouseEnter={() => {
|
|
241
|
+
setActiveIdx(i);
|
|
242
|
+
const content = comparison && d.compareValue != null ? (
|
|
243
|
+
<div>
|
|
244
|
+
<div style={{ fontWeight: 600, marginBottom: 2 }}>{d.label}</div>
|
|
245
|
+
<div>{d.value}</div>
|
|
246
|
+
<div>{d.compareValue}</div>
|
|
247
|
+
</div>
|
|
248
|
+
) : (
|
|
249
|
+
<div>
|
|
250
|
+
<div style={{ fontWeight: 600, marginBottom: 2 }}>{d.label}</div>
|
|
251
|
+
<div>{d.value}</div>
|
|
252
|
+
</div>
|
|
253
|
+
);
|
|
254
|
+
show(px, py, content);
|
|
255
|
+
}}
|
|
256
|
+
onMouseLeave={() => { setActiveIdx(null); hide(); }}
|
|
257
|
+
/>
|
|
258
|
+
);
|
|
259
|
+
})}
|
|
260
|
+
</svg>
|
|
261
|
+
)}
|
|
262
|
+
<HoverTooltip hover={hover} />
|
|
263
|
+
</div>
|
|
264
|
+
|
|
265
|
+
{/* Spacer */}
|
|
266
|
+
<div />
|
|
267
|
+
|
|
268
|
+
{/* X-axis */}
|
|
269
|
+
<div className={styles.xAxis}>
|
|
270
|
+
{data.map((d, i) => (
|
|
271
|
+
<span key={i} className={styles.xLabel}>
|
|
272
|
+
{d.label}
|
|
273
|
+
</span>
|
|
274
|
+
))}
|
|
275
|
+
</div>
|
|
276
|
+
</div>
|
|
277
|
+
</div>
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
LineChart.displayName = 'LineChart';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface LineChartDataPoint {
|
|
4
|
+
label: string;
|
|
5
|
+
value: number;
|
|
6
|
+
compareValue?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface LineChartProps extends HTMLAttributes<HTMLDivElement> {
|
|
10
|
+
/** Chart data */
|
|
11
|
+
data: LineChartDataPoint[];
|
|
12
|
+
/** Show comparison line */
|
|
13
|
+
comparison?: boolean;
|
|
14
|
+
/** Use smooth curves (Catmull-Rom) */
|
|
15
|
+
smooth?: boolean;
|
|
16
|
+
/** Fill area under the line */
|
|
17
|
+
areaFill?: boolean;
|
|
18
|
+
/** Chart height in px */
|
|
19
|
+
height?: number;
|
|
20
|
+
/** Legend element */
|
|
21
|
+
legend?: ReactNode;
|
|
22
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
position: relative;
|
|
3
|
+
width: 100%;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.bar {
|
|
7
|
+
display: flex;
|
|
8
|
+
width: 100%;
|
|
9
|
+
height: var(--pc-height, 8px);
|
|
10
|
+
border-radius: var(--pc-radius, 4px);
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
gap: 2px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.segment {
|
|
16
|
+
min-width: 2px;
|
|
17
|
+
cursor: default;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* ─── Primary palette ─── */
|
|
21
|
+
|
|
22
|
+
.primary .seg1 {
|
|
23
|
+
background-color: var(--st-color-chart-1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.primary .seg2 {
|
|
27
|
+
background-color: var(--st-color-chart-1-muted);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.primary .seg3 {
|
|
31
|
+
background-color: var(--st-color-chart-1-faded);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.primary .seg4 {
|
|
35
|
+
background-color: var(--st-color-chart-1-subtle);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* ─── Secondary palette ─── */
|
|
39
|
+
|
|
40
|
+
.secondary .seg1 {
|
|
41
|
+
background-color: var(--st-color-chart-2);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.secondary .seg2 {
|
|
45
|
+
background-color: var(--st-color-chart-2-muted);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.secondary .seg3 {
|
|
49
|
+
background-color: var(--st-color-chart-2-faded);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.secondary .seg4 {
|
|
53
|
+
background-color: var(--st-color-chart-2-subtle);
|
|
54
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { forwardRef } from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
import { normalizeSegments } from './chart.utils';
|
|
4
|
+
import { useChartHover } from './useChartHover';
|
|
5
|
+
import { HoverTooltip } from './HoverTooltip';
|
|
6
|
+
import type { ProgressChartProps } from './ProgressChart.types';
|
|
7
|
+
import styles from './ProgressChart.module.css';
|
|
8
|
+
|
|
9
|
+
export const ProgressChart = forwardRef<HTMLDivElement, ProgressChartProps>(
|
|
10
|
+
(
|
|
11
|
+
{
|
|
12
|
+
segments,
|
|
13
|
+
radius = 4,
|
|
14
|
+
color = 'primary',
|
|
15
|
+
barHeight = 8,
|
|
16
|
+
className,
|
|
17
|
+
style,
|
|
18
|
+
...rest
|
|
19
|
+
},
|
|
20
|
+
ref
|
|
21
|
+
) => {
|
|
22
|
+
const fractions = normalizeSegments(segments.map((s) => s.value));
|
|
23
|
+
const { hover, show, hide } = useChartHover();
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div
|
|
27
|
+
ref={ref}
|
|
28
|
+
className={cn(styles.root, styles[color], className)}
|
|
29
|
+
style={
|
|
30
|
+
{
|
|
31
|
+
'--pc-height': `${barHeight}px`,
|
|
32
|
+
'--pc-radius': `${radius}px`,
|
|
33
|
+
...style,
|
|
34
|
+
} as React.CSSProperties
|
|
35
|
+
}
|
|
36
|
+
role="meter"
|
|
37
|
+
{...rest}
|
|
38
|
+
>
|
|
39
|
+
<div className={styles.bar}>
|
|
40
|
+
{fractions.map((frac, i) => (
|
|
41
|
+
<div
|
|
42
|
+
key={i}
|
|
43
|
+
className={cn(styles.segment, styles[`seg${i + 1}`])}
|
|
44
|
+
style={{ flex: frac }}
|
|
45
|
+
onMouseEnter={(e) => {
|
|
46
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
47
|
+
const rootRect = e.currentTarget.closest(`.${styles.root}`)!.getBoundingClientRect();
|
|
48
|
+
show(
|
|
49
|
+
rect.left - rootRect.left + rect.width / 2,
|
|
50
|
+
-4,
|
|
51
|
+
<div>{(frac * 100).toFixed(1)}%</div>
|
|
52
|
+
);
|
|
53
|
+
}}
|
|
54
|
+
onMouseLeave={hide}
|
|
55
|
+
/>
|
|
56
|
+
))}
|
|
57
|
+
</div>
|
|
58
|
+
<HoverTooltip hover={hover} />
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
ProgressChart.displayName = 'ProgressChart';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface ProgressChartSegment {
|
|
4
|
+
value: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type ProgressChartColor = 'primary' | 'secondary';
|
|
8
|
+
|
|
9
|
+
export interface ProgressChartProps extends HTMLAttributes<HTMLDivElement> {
|
|
10
|
+
/** Segments with values (will be normalized to percentages) */
|
|
11
|
+
segments: ProgressChartSegment[];
|
|
12
|
+
/** Border radius */
|
|
13
|
+
radius?: number;
|
|
14
|
+
/** Color palette */
|
|
15
|
+
color?: ProgressChartColor;
|
|
16
|
+
/** Height of the progress bar in px */
|
|
17
|
+
barHeight?: number;
|
|
18
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { forwardRef, useId, useMemo, useState } from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
import { smoothPath, areaPath } from './chart.utils';
|
|
4
|
+
import { useChartHover } from './useChartHover';
|
|
5
|
+
import { HoverTooltip } from './HoverTooltip';
|
|
6
|
+
import type { TrendLineChartProps } from './TrendLineChart.types';
|
|
7
|
+
import styles from './TrendLineChart.module.css';
|
|
8
|
+
|
|
9
|
+
const COLOR_MAP = {
|
|
10
|
+
primary: {
|
|
11
|
+
stroke: 'var(--st-color-chart-1)',
|
|
12
|
+
fill: 'var(--st-color-chart-1)',
|
|
13
|
+
fillEnd: 'var(--st-color-chart-1-subtle)',
|
|
14
|
+
},
|
|
15
|
+
secondary: {
|
|
16
|
+
stroke: 'var(--st-color-chart-2)',
|
|
17
|
+
fill: 'var(--st-color-chart-2)',
|
|
18
|
+
fillEnd: 'var(--st-color-chart-2-subtle)',
|
|
19
|
+
},
|
|
20
|
+
} as const;
|
|
21
|
+
|
|
22
|
+
export const TrendLineChart = forwardRef<HTMLDivElement, TrendLineChartProps>(
|
|
23
|
+
(
|
|
24
|
+
{
|
|
25
|
+
data,
|
|
26
|
+
color = 'primary',
|
|
27
|
+
showDots = false,
|
|
28
|
+
areaFill = true,
|
|
29
|
+
width = 120,
|
|
30
|
+
height = 40,
|
|
31
|
+
className,
|
|
32
|
+
...rest
|
|
33
|
+
},
|
|
34
|
+
ref
|
|
35
|
+
) => {
|
|
36
|
+
const gradId = useId();
|
|
37
|
+
const palette = COLOR_MAP[color];
|
|
38
|
+
const { hover, show, hide } = useChartHover();
|
|
39
|
+
const [activeIdx, setActiveIdx] = useState<number | null>(null);
|
|
40
|
+
|
|
41
|
+
const { points, linePath: line } = useMemo(() => {
|
|
42
|
+
if (data.length < 2) return { points: [], linePath: '' };
|
|
43
|
+
const min = Math.min(...data);
|
|
44
|
+
const max = Math.max(...data);
|
|
45
|
+
const range = max - min || 1;
|
|
46
|
+
const pad = 4;
|
|
47
|
+
const w = width - pad * 2;
|
|
48
|
+
const h = height - pad * 2;
|
|
49
|
+
|
|
50
|
+
const pts = data.map((v, i) => ({
|
|
51
|
+
x: pad + (i / (data.length - 1)) * w,
|
|
52
|
+
y: pad + (1 - (v - min) / range) * h,
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
return { points: pts, linePath: smoothPath(pts) };
|
|
56
|
+
}, [data, width, height]);
|
|
57
|
+
|
|
58
|
+
if (data.length < 2) return null;
|
|
59
|
+
|
|
60
|
+
const area = areaFill
|
|
61
|
+
? areaPath(line, height - 4, points[0].x, points[points.length - 1].x)
|
|
62
|
+
: null;
|
|
63
|
+
|
|
64
|
+
const slotWidth = width / data.length;
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div ref={ref} className={cn(styles.root, className)} {...rest}>
|
|
68
|
+
<svg
|
|
69
|
+
width={width}
|
|
70
|
+
height={height}
|
|
71
|
+
viewBox={`0 0 ${width} ${height}`}
|
|
72
|
+
fill="none"
|
|
73
|
+
>
|
|
74
|
+
{areaFill && (
|
|
75
|
+
<defs>
|
|
76
|
+
<linearGradient id={gradId} x1="0" y1="0" x2="0" y2="1">
|
|
77
|
+
<stop offset="0%" stopColor={palette.fill} stopOpacity="0.3" />
|
|
78
|
+
<stop
|
|
79
|
+
offset="100%"
|
|
80
|
+
stopColor={palette.fillEnd}
|
|
81
|
+
stopOpacity="0"
|
|
82
|
+
/>
|
|
83
|
+
</linearGradient>
|
|
84
|
+
</defs>
|
|
85
|
+
)}
|
|
86
|
+
{area && <path d={area} fill={`url(#${gradId})`} />}
|
|
87
|
+
<path
|
|
88
|
+
d={line}
|
|
89
|
+
stroke={palette.stroke}
|
|
90
|
+
strokeWidth="2"
|
|
91
|
+
strokeLinecap="round"
|
|
92
|
+
strokeLinejoin="round"
|
|
93
|
+
/>
|
|
94
|
+
{/* Dots — always show active, optionally show all */}
|
|
95
|
+
{points.map((p, i) => (
|
|
96
|
+
(showDots || activeIdx === i) ? (
|
|
97
|
+
<circle
|
|
98
|
+
key={i}
|
|
99
|
+
cx={p.x}
|
|
100
|
+
cy={p.y}
|
|
101
|
+
r={activeIdx === i ? 3.5 : 2.5}
|
|
102
|
+
fill={palette.stroke}
|
|
103
|
+
stroke={activeIdx === i ? 'var(--st-color-surface)' : 'none'}
|
|
104
|
+
strokeWidth={activeIdx === i ? 1.5 : 0}
|
|
105
|
+
/>
|
|
106
|
+
) : null
|
|
107
|
+
))}
|
|
108
|
+
{/* Hit areas */}
|
|
109
|
+
{data.map((val, i) => (
|
|
110
|
+
<rect
|
|
111
|
+
key={`hit-${i}`}
|
|
112
|
+
x={points[i].x - slotWidth / 2}
|
|
113
|
+
y={0}
|
|
114
|
+
width={slotWidth}
|
|
115
|
+
height={height}
|
|
116
|
+
fill="transparent"
|
|
117
|
+
onMouseEnter={() => {
|
|
118
|
+
setActiveIdx(i);
|
|
119
|
+
show(points[i].x, points[i].y, <div>{val}</div>);
|
|
120
|
+
}}
|
|
121
|
+
onMouseLeave={() => { setActiveIdx(null); hide(); }}
|
|
122
|
+
/>
|
|
123
|
+
))}
|
|
124
|
+
</svg>
|
|
125
|
+
<HoverTooltip hover={hover} />
|
|
126
|
+
</div>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
TrendLineChart.displayName = 'TrendLineChart';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
export type TrendLineChartColor = 'primary' | 'secondary';
|
|
4
|
+
|
|
5
|
+
export interface TrendLineChartProps
|
|
6
|
+
extends Omit<HTMLAttributes<HTMLDivElement>, 'color'> {
|
|
7
|
+
/** Array of numeric data points */
|
|
8
|
+
data: number[];
|
|
9
|
+
/** Color palette */
|
|
10
|
+
color?: TrendLineChartColor;
|
|
11
|
+
/** Show dots at data points */
|
|
12
|
+
showDots?: boolean;
|
|
13
|
+
/** Fill the area under the line */
|
|
14
|
+
areaFill?: boolean;
|
|
15
|
+
/** Chart width in px */
|
|
16
|
+
width?: number;
|
|
17
|
+
/** Chart height in px */
|
|
18
|
+
height?: number;
|
|
19
|
+
}
|