@tsiky/components-r19 1.0.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/.prettierignore +4 -0
- package/.prettierrc +9 -0
- package/.storybook/main.ts +17 -0
- package/.storybook/preview.ts +21 -0
- package/.storybook/vitest.setup.ts +7 -0
- package/README.md +69 -0
- package/chart.ts +1 -0
- package/eslint.config.js +40 -0
- package/index.html +13 -0
- package/index.ts +33 -0
- package/package.json +63 -0
- package/public/vite.svg +1 -0
- package/src/App.css +42 -0
- package/src/App.tsx +12 -0
- package/src/assets/accessibility.png +0 -0
- package/src/assets/accessibility.svg +1 -0
- package/src/assets/addon-library.png +0 -0
- package/src/assets/assets.png +0 -0
- package/src/assets/avif-test-image.avif +0 -0
- package/src/assets/context.png +0 -0
- package/src/assets/discord.svg +1 -0
- package/src/assets/docs.png +0 -0
- package/src/assets/figma-plugin.png +0 -0
- package/src/assets/github.svg +1 -0
- package/src/assets/react.svg +1 -0
- package/src/assets/share.png +0 -0
- package/src/assets/styling.png +0 -0
- package/src/assets/testing.png +0 -0
- package/src/assets/theming.png +0 -0
- package/src/assets/tutorials.svg +1 -0
- package/src/assets/youtube.svg +1 -0
- package/src/components/AddItemModal/AddItemModal.module.css +72 -0
- package/src/components/AddItemModal/AddItemModal.tsx +82 -0
- package/src/components/AddItemModal/index.ts +1 -0
- package/src/components/Alert/Alert.css +54 -0
- package/src/components/Alert/Alert.stories.tsx +82 -0
- package/src/components/Alert/Alert.tsx +85 -0
- package/src/components/Alert/AlertContext.tsx +200 -0
- package/src/components/Alert/AlertModels.ts +34 -0
- package/src/components/Alert/index.ts +3 -0
- package/src/components/AnnouncementPanel/FlexRowContainer.css +17 -0
- package/src/components/AnnouncementPanel/FlexRowContainer.stories.tsx +329 -0
- package/src/components/AnnouncementPanel/FlexRowContainer.tsx +24 -0
- package/src/components/AnnouncementPanel/ListBox/CounterListBox.css +56 -0
- package/src/components/AnnouncementPanel/ListBox/CounterListBox.stories.tsx +292 -0
- package/src/components/AnnouncementPanel/ListBox/CounterListBox.tsx +106 -0
- package/src/components/AnnouncementPanel/ListBox/SimpleListBox.css +57 -0
- package/src/components/AnnouncementPanel/ListBox/SimpleListBox.stories.tsx +189 -0
- package/src/components/AnnouncementPanel/ListBox/SimpleListBox.tsx +138 -0
- package/src/components/AnnouncementPanel/ListBox/TrendListBox.css +61 -0
- package/src/components/AnnouncementPanel/ListBox/TrendListBox.stories.tsx +257 -0
- package/src/components/AnnouncementPanel/ListBox/TrendListBox.tsx +90 -0
- package/src/components/AnnouncementPanel/ListBox/index.ts +3 -0
- package/src/components/AnnouncementPanel/ListContentContainer.css +23 -0
- package/src/components/AnnouncementPanel/ListContentContainer.stories.tsx +212 -0
- package/src/components/AnnouncementPanel/ListContentContainer.tsx +33 -0
- package/src/components/AnnouncementPanel/index.ts +3 -0
- package/src/components/BandChart/index.tsx +282 -0
- package/src/components/Button/Button.module.css +165 -0
- package/src/components/Button/Button.stories.ts +132 -0
- package/src/components/Button/Button.tsx +55 -0
- package/src/components/Button/button.css +29 -0
- package/src/components/Button/index.ts +2 -0
- package/src/components/ChartContainer/ChartContainer.css +116 -0
- package/src/components/ChartContainer/ChartContainer.stories.tsx +159 -0
- package/src/components/ChartContainer/ChartContainer.tsx +155 -0
- package/src/components/ChartContainer/index.ts +1 -0
- package/src/components/Charts/area-chart-admission/AreaChartAdmission.stories.tsx +65 -0
- package/src/components/Charts/area-chart-admission/AreaChartAdmission.tsx +89 -0
- package/src/components/Charts/area-chart-admission/content.json +48 -0
- package/src/components/Charts/area-chart-hospitalisation/AreaChartHospitalisation.stories.tsx +141 -0
- package/src/components/Charts/area-chart-hospitalisation/AreaChartHospitalisation.tsx +262 -0
- package/src/components/Charts/area-chart-hospitalisation/content.json +55 -0
- package/src/components/Charts/bar-chart/BarChart.stories.tsx +50 -0
- package/src/components/Charts/bar-chart/BarChart.tsx +132 -0
- package/src/components/Charts/bar-chart/content.json +15 -0
- package/src/components/Charts/boxplot-chart/BoxPlotChart.stories.tsx +63 -0
- package/src/components/Charts/boxplot-chart/BoxPlotChart.tsx +114 -0
- package/src/components/Charts/boxplot-chart/boxUtils.ts +22 -0
- package/src/components/Charts/boxplot-chart/content.json +11 -0
- package/src/components/Charts/mixed-chart/MixedChart.stories.tsx +83 -0
- package/src/components/Charts/mixed-chart/MixedChart.tsx +625 -0
- package/src/components/Charts/mixed-chart/content.json +34 -0
- package/src/components/Charts/sankey-adaptation/sankey.tsx +70 -0
- package/src/components/Charts/sankey-chart/SankeyChart.stories.tsx +69 -0
- package/src/components/Charts/sankey-chart/SankeyChart.tsx +155 -0
- package/src/components/Charts/sankey-chart/content.json +15 -0
- package/src/components/Charts/stacked-column/StackedColumn.stories.tsx +72 -0
- package/src/components/Charts/stacked-column/StackedColumn.tsx +406 -0
- package/src/components/Charts/stacked-column/content.json +37 -0
- package/src/components/Charts/stacked-column-one-hundred-percent/StackedColumnOneHundredPercent.stories.tsx +43 -0
- package/src/components/Charts/stacked-column-one-hundred-percent/StackedColumnOneHundredPercent.tsx +75 -0
- package/src/components/Charts/stacked-column-one-hundred-percent/content.json +6 -0
- package/src/components/CircularProgress/CircularProgress.css +79 -0
- package/src/components/CircularProgress/CircularProgress.stories.tsx +251 -0
- package/src/components/CircularProgress/CircularProgress.tsx +101 -0
- package/src/components/CircularProgress/index.ts +2 -0
- package/src/components/Configure.mdx +369 -0
- package/src/components/DayStatCard/DayStatCard.css +50 -0
- package/src/components/DayStatCard/DayStatCard.stories.tsx +273 -0
- package/src/components/DayStatCard/DayStatCard.tsx +69 -0
- package/src/components/DayStatCard/index.ts +2 -0
- package/src/components/DraggableSwitcher/DraggableSwitcherButton.tsx +58 -0
- package/src/components/DraggableSwitcher/context/useDraggableSwitcher.tsx +45 -0
- package/src/components/DraggableSwitcher/index.ts +2 -0
- package/src/components/DropdownMenu/DropdownMenu.css +100 -0
- package/src/components/DropdownMenu/DropdownMenu.stories.tsx +174 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +106 -0
- package/src/components/DropdownMenu/index.ts +1 -0
- package/src/components/DynamicForm/DynamicFom.stories.ts +773 -0
- package/src/components/DynamicForm/DynamicForm.module.css +468 -0
- package/src/components/DynamicForm/DynamicForm.tsx +224 -0
- package/src/components/DynamicForm/index.ts +3 -0
- package/src/components/DynamicForm/tools/form-metadata.ts +82 -0
- package/src/components/DynamicForm/tools/validation.ts +168 -0
- package/src/components/DynamicInput/DynamicInput.module.css +126 -0
- package/src/components/DynamicInput/DynamicInput.stories.ts +350 -0
- package/src/components/DynamicInput/DynamicInput.tsx +144 -0
- package/src/components/DynamicInput/index.ts +2 -0
- package/src/components/DynamicInput/input/CheckboxInput.tsx +41 -0
- package/src/components/DynamicInput/input/ColorInput.tsx +46 -0
- package/src/components/DynamicInput/input/DateInput.tsx +57 -0
- package/src/components/DynamicInput/input/FileInput.tsx +174 -0
- package/src/components/DynamicInput/input/InputWrapper.tsx +26 -0
- package/src/components/DynamicInput/input/RadioInput.tsx +46 -0
- package/src/components/DynamicInput/input/RangeInput.tsx +46 -0
- package/src/components/DynamicInput/input/SelectInput.tsx +75 -0
- package/src/components/DynamicInput/input/TextInput.tsx +101 -0
- package/src/components/DynamicInput/input/TextareaInput.tsx +47 -0
- package/src/components/DynamicInput/input/assets/ColorInput.module.css +48 -0
- package/src/components/DynamicInput/input/assets/DateInput.module.css +83 -0
- package/src/components/DynamicInput/input/assets/FileInput.module.css +133 -0
- package/src/components/DynamicInput/input/assets/RangeInput.module.css +169 -0
- package/src/components/DynamicInput/input/assets/SelectInput.module.css +95 -0
- package/src/components/DynamicInput/input/index.ts +10 -0
- package/src/components/DynamicTable/AdvancedFilters.tsx +196 -0
- package/src/components/DynamicTable/ColumnSorter.tsx +185 -0
- package/src/components/DynamicTable/Pagination.tsx +115 -0
- package/src/components/DynamicTable/TableBody.tsx +42 -0
- package/src/components/DynamicTable/TableCell.tsx +30 -0
- package/src/components/DynamicTable/TableHeader.tsx +34 -0
- package/src/components/DynamicTable/TableRow.tsx +56 -0
- package/src/components/DynamicTable/TableauDynamic.stories.ts +1014 -0
- package/src/components/DynamicTable/TableauDynamique.module.css +1287 -0
- package/src/components/DynamicTable/TableauDynamique.tsx +154 -0
- package/src/components/DynamicTable/filters/BooleanFilter.tsx +30 -0
- package/src/components/DynamicTable/filters/DateFilter.tsx +28 -0
- package/src/components/DynamicTable/filters/DateRangeFilter.tsx +51 -0
- package/src/components/DynamicTable/filters/FilterRenderer.tsx +117 -0
- package/src/components/DynamicTable/filters/MultiSelectFilter.tsx +59 -0
- package/src/components/DynamicTable/filters/NumberFilter.tsx +37 -0
- package/src/components/DynamicTable/filters/OperatorFilter.tsx +64 -0
- package/src/components/DynamicTable/filters/SelectFilter.tsx +69 -0
- package/src/components/DynamicTable/filters/TextFilter.tsx +39 -0
- package/src/components/DynamicTable/filters/index.ts +9 -0
- package/src/components/DynamicTable/hooks/index.ts +2 -0
- package/src/components/DynamicTable/hooks/useAsyncActions.ts +36 -0
- package/src/components/DynamicTable/hooks/useFilters.ts +142 -0
- package/src/components/DynamicTable/hooks/useTableData.ts +216 -0
- package/src/components/DynamicTable/index.ts +11 -0
- package/src/components/DynamicTable/tools/filterTypes.ts +118 -0
- package/src/components/DynamicTable/tools/index.ts +3 -0
- package/src/components/DynamicTable/tools/tableConfig.ts +96 -0
- package/src/components/DynamicTable/tools/tableTypes.ts +63 -0
- package/src/components/EntryControl/EntryControl.module.css +218 -0
- package/src/components/EntryControl/EntryControl.stories.tsx +71 -0
- package/src/components/EntryControl/EntryControl.tsx +117 -0
- package/src/components/EntryControl/index.ts +2 -0
- package/src/components/Grid/Grid.stories.tsx +94 -0
- package/src/components/Grid/Grid.tsx +214 -0
- package/src/components/Grid/grid.css +285 -0
- package/src/components/Grid/index.ts +2 -0
- package/src/components/Header/Header.stories.tsx +164 -0
- package/src/components/Header/Header.tsx +59 -0
- package/src/components/Header/header.css +31 -0
- package/src/components/Header/index.ts +1 -0
- package/src/components/IconText/IconText..stories.tsx +135 -0
- package/src/components/IconText/IconText.css +43 -0
- package/src/components/IconText/IconText.tsx +43 -0
- package/src/components/IconText/index.ts +1 -0
- package/src/components/LanguageSelector/LanguageSelector.css +31 -0
- package/src/components/LanguageSelector/LanguageSelector.stories.tsx +38 -0
- package/src/components/LanguageSelector/LanguageSelector.tsx +37 -0
- package/src/components/LanguageSelector/index.ts +1 -0
- package/src/components/Logo/Logo.css +89 -0
- package/src/components/Logo/Logo.stories.tsx +79 -0
- package/src/components/Logo/Logo.tsx +22 -0
- package/src/components/Logo/index.ts +2 -0
- package/src/components/MetricsPanel/MetricsItem.tsx +128 -0
- package/src/components/MetricsPanel/MetricsPanel.module.css +636 -0
- package/src/components/MetricsPanel/MetricsPanel.stories.tsx +692 -0
- package/src/components/MetricsPanel/MetricsPanel.tsx +282 -0
- package/src/components/MetricsPanel/PanelHeader.tsx +19 -0
- package/src/components/MetricsPanel/SummaryCard.tsx +61 -0
- package/src/components/MetricsPanel/index.ts +4 -0
- package/src/components/MetricsPanel/renderers/CompactRenderer.tsx +125 -0
- package/src/components/MetricsPanel/renderers/ImageCard.tsx +62 -0
- package/src/components/MetricsPanel/renderers/PertinenceCard.tsx +55 -0
- package/src/components/MetricsPanel/tools/MetricsPanelTypes.ts +62 -0
- package/src/components/MetricsPanel/tools/chooseDefaultRender.ts +50 -0
- package/src/components/MetricsPanel/tools/colorUtils.ts +39 -0
- package/src/components/MetricsPanel/tools/index.ts +2 -0
- package/src/components/ModuleHeader/ModuleHeader.css +37 -0
- package/src/components/ModuleHeader/ModuleHeader.stories.tsx +37 -0
- package/src/components/ModuleHeader/ModuleHeader.tsx +42 -0
- package/src/components/ModuleHeader/index.ts +1 -0
- package/src/components/ModuleSideBar/ModuleSideBar.css +227 -0
- package/src/components/ModuleSideBar/ModuleSideBar.stories.tsx +40 -0
- package/src/components/ModuleSideBar/ModuleSideBar.tsx +155 -0
- package/src/components/ModuleSideBar/index.ts +1 -0
- package/src/components/NavBar/NavBar.css +58 -0
- package/src/components/NavBar/NavBar.stories.tsx +169 -0
- package/src/components/NavBar/NavBar.tsx +100 -0
- package/src/components/NavBar/NavContext.tsx +30 -0
- package/src/components/NavBar/index.ts +2 -0
- package/src/components/NavItem/NavItem.css +29 -0
- package/src/components/NavItem/NavItem.tsx +58 -0
- package/src/components/NavItem/index.ts +1 -0
- package/src/components/Page/Dashboard.tsx +93 -0
- package/src/components/Page/Page.stories.ts +33 -0
- package/src/components/Page/Page.tsx +73 -0
- package/src/components/Page/page.css +81 -0
- package/src/components/PerformanceCard/PerformanceCard.module.css +232 -0
- package/src/components/PerformanceCard/PerformanceCard.stories.tsx +441 -0
- package/src/components/PerformanceCard/PerformanceCard.tsx +198 -0
- package/src/components/PerformanceCard/defaultHistogramRenderer.tsx +32 -0
- package/src/components/PerformanceCard/tools/types.ts +50 -0
- package/src/components/PerformanceCard/tools/usePerformanceCard.ts +93 -0
- package/src/components/PeriodRange/PeriodRange.module.css +158 -0
- package/src/components/PeriodRange/PeriodRange.stories.tsx +66 -0
- package/src/components/PeriodRange/PeriodRange.tsx +130 -0
- package/src/components/PeriodSelect/PeriodSelect.module.css +65 -0
- package/src/components/PeriodSelect/PeriodSelect.stories.tsx +40 -0
- package/src/components/PeriodSelect/PeriodSelect.tsx +42 -0
- package/src/components/PeriodSelect/index.ts +1 -0
- package/src/components/ScrollableHorizontale/ScrollableHorizontale.css +40 -0
- package/src/components/ScrollableHorizontale/ScrollableHorizontale.stories.tsx +133 -0
- package/src/components/ScrollableHorizontale/ScrollableHorizontale.tsx +29 -0
- package/src/components/ScrollableHorizontale/index.ts +1 -0
- package/src/components/SearchBar/SearchBar.css +40 -0
- package/src/components/SearchBar/SearchBar.stories.tsx +36 -0
- package/src/components/SearchBar/SearchBar.tsx +30 -0
- package/src/components/SearchBar/index.ts +1 -0
- package/src/components/SectionTitle/SectionTitle.css +21 -0
- package/src/components/SectionTitle/SectionTitle.stories.tsx +39 -0
- package/src/components/SectionTitle/SectionTitle.tsx +18 -0
- package/src/components/SideComponent/PatientEditor.tsx +64 -0
- package/src/components/SideComponent/SideComponent.css +179 -0
- package/src/components/SideComponent/SideComponent.stories.tsx +547 -0
- package/src/components/SideComponent/SideComponent.tsx +243 -0
- package/src/components/SideComponent/hooks/useBodyScrollLock.ts +15 -0
- package/src/components/SideComponent/index.ts +2 -0
- package/src/components/SideComponent/portal.ts +11 -0
- package/src/components/SubNavBar/SubNavBar.tsx +41 -0
- package/src/components/SubNavBar/index.ts +1 -0
- package/src/components/Switcher/Switcher.css +65 -0
- package/src/components/Switcher/Switcher.stories.tsx +153 -0
- package/src/components/Switcher/Switcher.tsx +83 -0
- package/src/components/Switcher/index.ts +1 -0
- package/src/components/Title/Title.stories.tsx +18 -0
- package/src/components/Title/Title.tsx +26 -0
- package/src/components/Title/index.ts +1 -0
- package/src/components/TranslationKey/TranslationKey.css +272 -0
- package/src/components/TranslationKey/TranslationKey.stories.tsx +50 -0
- package/src/components/TranslationKey/TranslationKey.tsx +245 -0
- package/src/components/TranslationKey/index.ts +1 -0
- package/src/components/TrendItem/TrendItem.css +36 -0
- package/src/components/TrendItem/TrendItem.stories.tsx +276 -0
- package/src/components/TrendItem/TrendItem.tsx +46 -0
- package/src/components/TrendItem/index.ts +1 -0
- package/src/components/TrendList/TrendList.css +16 -0
- package/src/components/TrendList/TrendList.stories.tsx +337 -0
- package/src/components/TrendList/TrendList.tsx +45 -0
- package/src/components/TrendList/index.ts +1 -0
- package/src/components/theme/ThemeSwitcherButton.tsx +64 -0
- package/src/components/theme/context/ThemeContext.tsx +61 -0
- package/src/components/theme/context/index.ts +2 -0
- package/src/components/theme/context/useThemeSwitcher.ts +18 -0
- package/src/components/theme/index.ts +1 -0
- package/src/index.css +68 -0
- package/src/main.tsx +10 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.app.json +27 -0
- package/tsconfig.json +4 -0
- package/tsconfig.node.json +25 -0
- package/vite.config.ts +43 -0
- package/vitest.shims.d.ts +1 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import MetricsPanel from '../MetricsPanel/MetricsPanel';
|
|
4
|
+
import { usePerformanceCard } from './tools/usePerformanceCard';
|
|
5
|
+
import { defaultHistogramRenderer } from './defaultHistogramRenderer';
|
|
6
|
+
import type { PerformanceCardData, PerformanceCardProps as BaseProps } from './tools/types';
|
|
7
|
+
import styles from './PerformanceCard.module.css';
|
|
8
|
+
|
|
9
|
+
// icons
|
|
10
|
+
import { TrendingUp, TrendingDown } from 'lucide-react';
|
|
11
|
+
|
|
12
|
+
type PerformanceCardProps = BaseProps & {
|
|
13
|
+
/**
|
|
14
|
+
* Contrôles de dimensions simples.
|
|
15
|
+
* Exemples acceptés: '320px', '100%', '24rem'
|
|
16
|
+
*/
|
|
17
|
+
width?: string;
|
|
18
|
+
maxWidth?: string;
|
|
19
|
+
height?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Hauteur du container du graphique (ex: '92px', '120px')
|
|
22
|
+
*/
|
|
23
|
+
chartHeight?: string;
|
|
24
|
+
/**
|
|
25
|
+
* style additionnel appliqué au root
|
|
26
|
+
*/
|
|
27
|
+
style?: React.CSSProperties;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const PerformanceCard: React.FC<PerformanceCardProps> = ({
|
|
31
|
+
data,
|
|
32
|
+
className = '',
|
|
33
|
+
compact = false,
|
|
34
|
+
editable = false,
|
|
35
|
+
onChange,
|
|
36
|
+
mapToMetricsItem,
|
|
37
|
+
renderHistogram,
|
|
38
|
+
defaultColors,
|
|
39
|
+
// new sizing props
|
|
40
|
+
width,
|
|
41
|
+
maxWidth,
|
|
42
|
+
height,
|
|
43
|
+
chartHeight,
|
|
44
|
+
style,
|
|
45
|
+
}) => {
|
|
46
|
+
const { local, histogramNormalized, autoFooter, updatePartial, toMetricsItems } =
|
|
47
|
+
usePerformanceCard(data, defaultColors);
|
|
48
|
+
|
|
49
|
+
const metricsPanelItems = toMetricsItems(local.topMetrics || [], mapToMetricsItem);
|
|
50
|
+
|
|
51
|
+
const handleUpdate = (next: Partial<PerformanceCardData>) => {
|
|
52
|
+
const merged = updatePartial(next);
|
|
53
|
+
onChange?.(merged);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const parseValue = (val?: React.ReactNode): number => {
|
|
57
|
+
if (val == null) return NaN;
|
|
58
|
+
|
|
59
|
+
if (typeof val === 'number') return val;
|
|
60
|
+
|
|
61
|
+
if (typeof val === 'string') {
|
|
62
|
+
return Number(val.replace('%', '').trim());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// JSX.Element, boolean, etc. → pas comparable
|
|
66
|
+
return NaN;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const normalize = (s?: string) =>
|
|
70
|
+
s
|
|
71
|
+
?.normalize('NFD')
|
|
72
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
73
|
+
.toLowerCase() ?? '';
|
|
74
|
+
|
|
75
|
+
const prediction = local.topMetrics?.find((m) => normalize(m.label).includes('pred'));
|
|
76
|
+
const performance = local.topMetrics?.find((m) => normalize(m.label).includes('perf'));
|
|
77
|
+
|
|
78
|
+
const perfVal = parseValue(performance?.value);
|
|
79
|
+
const predVal = parseValue(prediction?.value);
|
|
80
|
+
|
|
81
|
+
const isUp = !isNaN(perfVal) && !isNaN(predVal) && perfVal >= predVal;
|
|
82
|
+
|
|
83
|
+
// CSS custom properties for sizing (fallbacks are in CSS)
|
|
84
|
+
const cssVars: React.CSSProperties = {
|
|
85
|
+
['--pc-width' as any]: width,
|
|
86
|
+
['--pc-max-width' as any]: maxWidth,
|
|
87
|
+
['--pc-height' as any]: height,
|
|
88
|
+
['--pc-chart-height' as any]: chartHeight,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<div
|
|
93
|
+
className={[styles.card, compact ? styles.compact : '', className].join(' ')}
|
|
94
|
+
style={{ ...cssVars, ...(style ?? {}) }}
|
|
95
|
+
>
|
|
96
|
+
<div className={styles.headerRow}>
|
|
97
|
+
<div className={styles.title}>{local.title ?? 'Performance'}</div>
|
|
98
|
+
<div className={styles.headerActions} aria-hidden>
|
|
99
|
+
{isUp ? (
|
|
100
|
+
<TrendingUp size={18} className={styles.trendUp} />
|
|
101
|
+
) : (
|
|
102
|
+
<TrendingDown size={18} className={styles.trendDown} />
|
|
103
|
+
)}
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<div className={styles.metricsRow}>
|
|
108
|
+
<MetricsPanel
|
|
109
|
+
className={styles.metricsPanel}
|
|
110
|
+
items={metricsPanelItems}
|
|
111
|
+
summary
|
|
112
|
+
orientation='horizontal'
|
|
113
|
+
/>
|
|
114
|
+
</div>
|
|
115
|
+
|
|
116
|
+
{renderHistogram
|
|
117
|
+
? renderHistogram(histogramNormalized)
|
|
118
|
+
: defaultHistogramRenderer(histogramNormalized)}
|
|
119
|
+
|
|
120
|
+
<div className={styles.footerRow}>
|
|
121
|
+
<div className={styles.footerNote}>
|
|
122
|
+
{local.footerLeft ?? (autoFooter ? autoFooter.left : null) ?? (
|
|
123
|
+
<span className={styles.placeholder}>—</span>
|
|
124
|
+
)}
|
|
125
|
+
</div>
|
|
126
|
+
<div className={styles.footerNoteRight}>
|
|
127
|
+
{local.footerRight ?? (autoFooter ? autoFooter.right : null) ?? (
|
|
128
|
+
<span className={styles.placeholder}>—</span>
|
|
129
|
+
)}
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
|
|
133
|
+
{editable && (
|
|
134
|
+
<div className={styles.editorContainer}>
|
|
135
|
+
<div className={styles.editorColumn}>
|
|
136
|
+
<strong>Top metrics</strong>
|
|
137
|
+
<div className={styles.editorList}>
|
|
138
|
+
{local.topMetrics.map((m, idx) => (
|
|
139
|
+
<div className={styles.editorRow} key={m.id ?? `${m.label}-${idx}`}>
|
|
140
|
+
<input
|
|
141
|
+
className={styles.editorInputLabel}
|
|
142
|
+
value={String(m.label)}
|
|
143
|
+
onChange={(e) => {
|
|
144
|
+
const next = [...local.topMetrics];
|
|
145
|
+
next[idx] = { ...next[idx], label: e.target.value };
|
|
146
|
+
handleUpdate({ topMetrics: next });
|
|
147
|
+
}}
|
|
148
|
+
/>
|
|
149
|
+
<input
|
|
150
|
+
className={styles.editorInputValue}
|
|
151
|
+
value={String(m.value)}
|
|
152
|
+
onChange={(e) => {
|
|
153
|
+
const next = [...local.topMetrics];
|
|
154
|
+
next[idx] = { ...next[idx], value: e.target.value };
|
|
155
|
+
handleUpdate({ topMetrics: next });
|
|
156
|
+
}}
|
|
157
|
+
/>
|
|
158
|
+
</div>
|
|
159
|
+
))}
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
|
|
163
|
+
<div className={styles.editorColumn}>
|
|
164
|
+
<strong>Histogram</strong>
|
|
165
|
+
<div className={styles.editorList}>
|
|
166
|
+
{local.histogram?.map((b, idx) => (
|
|
167
|
+
<div className={styles.editorRow} key={b.id ?? idx}>
|
|
168
|
+
<input
|
|
169
|
+
className={styles.editorInputLabel}
|
|
170
|
+
value={String(b.label ?? '')}
|
|
171
|
+
placeholder='label'
|
|
172
|
+
onChange={(e) => {
|
|
173
|
+
const next = (local.histogram || []).slice();
|
|
174
|
+
next[idx] = { ...next[idx], label: e.target.value };
|
|
175
|
+
handleUpdate({ histogram: next });
|
|
176
|
+
}}
|
|
177
|
+
/>
|
|
178
|
+
<input
|
|
179
|
+
className={styles.editorInputValue}
|
|
180
|
+
type='number'
|
|
181
|
+
value={String(b.value)}
|
|
182
|
+
onChange={(e) => {
|
|
183
|
+
const next = (local.histogram || []).slice();
|
|
184
|
+
next[idx] = { ...next[idx], value: Number(e.target.value) };
|
|
185
|
+
handleUpdate({ histogram: next });
|
|
186
|
+
}}
|
|
187
|
+
/>
|
|
188
|
+
</div>
|
|
189
|
+
))}
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
</div>
|
|
193
|
+
)}
|
|
194
|
+
</div>
|
|
195
|
+
);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export default React.memo(PerformanceCard);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styles from './PerformanceCard.module.css';
|
|
3
|
+
|
|
4
|
+
interface HistogramBarNormalized {
|
|
5
|
+
id?: string | number;
|
|
6
|
+
label?: string;
|
|
7
|
+
value: number;
|
|
8
|
+
color?: string;
|
|
9
|
+
normalized: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const defaultHistogramRenderer = (bars: HistogramBarNormalized[]) => (
|
|
13
|
+
<div className={styles.chartContainer} aria-hidden>
|
|
14
|
+
<div className={styles.chartInner}>
|
|
15
|
+
<div className={styles.dynamicBars} style={{ ['--bars-count' as never]: bars.length }}>
|
|
16
|
+
{bars.map((b) => (
|
|
17
|
+
<div key={String(b.id ?? b.label ?? Math.random())} className={styles.dynamicBarWrapper}>
|
|
18
|
+
<div
|
|
19
|
+
className={styles.dynamicBar}
|
|
20
|
+
title={`${b.label ?? ''}: ${b.value}`}
|
|
21
|
+
style={{
|
|
22
|
+
height: `${b.normalized}%`,
|
|
23
|
+
background: b.color,
|
|
24
|
+
}}
|
|
25
|
+
/>
|
|
26
|
+
{b.label && <div className={styles.barLabel}>{b.label}</div>}
|
|
27
|
+
</div>
|
|
28
|
+
))}
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// types.ts
|
|
2
|
+
import type { MetricsItem } from '../../MetricsPanel/tools/MetricsPanelTypes';
|
|
3
|
+
|
|
4
|
+
export type TopMetric = {
|
|
5
|
+
id: string | number;
|
|
6
|
+
label: string;
|
|
7
|
+
value: string | number | React.ReactNode;
|
|
8
|
+
color?: string;
|
|
9
|
+
bgColor?: string;
|
|
10
|
+
borderColor?: string;
|
|
11
|
+
valueColor?: string;
|
|
12
|
+
subLabel?: string | React.ReactNode;
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
badge?: any;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type HistogramBar = {
|
|
18
|
+
id?: string | number;
|
|
19
|
+
label?: string;
|
|
20
|
+
value: number;
|
|
21
|
+
color?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type PerformanceCardColors = {
|
|
25
|
+
defaultMuted?: string;
|
|
26
|
+
defaultPrimary?: string;
|
|
27
|
+
defaultSuccess?: string;
|
|
28
|
+
accent?: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type PerformanceCardData = {
|
|
32
|
+
id?: string | number;
|
|
33
|
+
title?: string;
|
|
34
|
+
topMetrics: TopMetric[];
|
|
35
|
+
histogram?: HistogramBar[];
|
|
36
|
+
footerLeft?: string | React.ReactNode;
|
|
37
|
+
footerRight?: string | React.ReactNode;
|
|
38
|
+
colors?: PerformanceCardColors;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export interface PerformanceCardProps {
|
|
42
|
+
data: PerformanceCardData;
|
|
43
|
+
className?: string;
|
|
44
|
+
compact?: boolean;
|
|
45
|
+
editable?: boolean;
|
|
46
|
+
onChange?: (next: PerformanceCardData) => void;
|
|
47
|
+
mapToMetricsItem?: (m: TopMetric) => MetricsItem;
|
|
48
|
+
renderHistogram?: (bars: HistogramBar[]) => React.ReactNode;
|
|
49
|
+
defaultColors?: PerformanceCardColors;
|
|
50
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import type { PerformanceCardColors, PerformanceCardData, TopMetric } from './types';
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_COLORS: PerformanceCardColors = {
|
|
5
|
+
defaultMuted: '#9ca3af',
|
|
6
|
+
defaultPrimary: '#4f46e5',
|
|
7
|
+
defaultSuccess: '#10b981',
|
|
8
|
+
accent: '#7c3aed',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const usePerformanceCard = (
|
|
12
|
+
data: PerformanceCardData,
|
|
13
|
+
defaultColors?: PerformanceCardColors
|
|
14
|
+
) => {
|
|
15
|
+
const [local, setLocal] = useState<PerformanceCardData>(data);
|
|
16
|
+
|
|
17
|
+
useEffect(() => setLocal(data), [data]);
|
|
18
|
+
|
|
19
|
+
const mergedColors: PerformanceCardColors = {
|
|
20
|
+
...DEFAULT_COLORS,
|
|
21
|
+
...(defaultColors || {}),
|
|
22
|
+
...(data.colors || {}),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const defaultMap = (m: TopMetric) => ({
|
|
26
|
+
id: m.id ?? `${m.label}-${String(m.value)}`,
|
|
27
|
+
label: m.label,
|
|
28
|
+
subLabel: m.subLabel,
|
|
29
|
+
value: m.value,
|
|
30
|
+
valueColor: m.valueColor ?? m.color ?? undefined,
|
|
31
|
+
bgColor: m.bgColor,
|
|
32
|
+
borderColor: m.borderColor,
|
|
33
|
+
badge: m.badge,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
const toMetricsItems = (dataList: TopMetric[], mapToMetricsItem?: (m: TopMetric) => any) =>
|
|
38
|
+
dataList.map((m) => (mapToMetricsItem ? mapToMetricsItem(m) : defaultMap(m)));
|
|
39
|
+
|
|
40
|
+
const histogramBars = local.histogram ?? [];
|
|
41
|
+
|
|
42
|
+
const histogramNormalized = useMemo(() => {
|
|
43
|
+
if (!histogramBars.length) return [];
|
|
44
|
+
const vals = histogramBars.map((b) => (Number.isFinite(b.value) ? b.value : 0));
|
|
45
|
+
const max = Math.max(...vals, 1);
|
|
46
|
+
return histogramBars.map((b) => ({
|
|
47
|
+
...b,
|
|
48
|
+
normalized: Math.max(0, Math.round((b.value / max) * 100)),
|
|
49
|
+
color: b.color ?? mergedColors.defaultPrimary,
|
|
50
|
+
}));
|
|
51
|
+
}, [histogramBars, mergedColors.defaultPrimary]);
|
|
52
|
+
|
|
53
|
+
const autoFooter = useMemo(() => {
|
|
54
|
+
if (!local.topMetrics || local.topMetrics.length < 2) return null;
|
|
55
|
+
|
|
56
|
+
const tryNumber = (v: unknown) => {
|
|
57
|
+
if (typeof v === 'number') return v;
|
|
58
|
+
if (typeof v === 'string') {
|
|
59
|
+
const n = parseFloat(v.replace('%', '').trim());
|
|
60
|
+
return Number.isFinite(n) ? n : NaN;
|
|
61
|
+
}
|
|
62
|
+
return NaN;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const a = tryNumber(local.topMetrics[0].value);
|
|
66
|
+
const b = tryNumber(local.topMetrics[1].value);
|
|
67
|
+
|
|
68
|
+
if (Number.isFinite(a) && Number.isFinite(b)) {
|
|
69
|
+
const diff = Math.round(a - b);
|
|
70
|
+
const sign = diff > 0 ? '+' : '';
|
|
71
|
+
return {
|
|
72
|
+
left: `${local.topMetrics[0].label} ${a}${typeof local.topMetrics[0].value === 'string' && String(local.topMetrics[0].value).includes('%') ? '%' : ''}`,
|
|
73
|
+
right: `${sign}${diff}${typeof local.topMetrics[0].value === 'string' && String(local.topMetrics[0].value).includes('%') ? '%' : ''}`,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}, [local.topMetrics]);
|
|
78
|
+
|
|
79
|
+
const updatePartial = (next: Partial<PerformanceCardData>) => {
|
|
80
|
+
const merged = { ...local, ...next };
|
|
81
|
+
setLocal(merged);
|
|
82
|
+
return merged;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
local,
|
|
87
|
+
mergedColors,
|
|
88
|
+
histogramNormalized,
|
|
89
|
+
autoFooter,
|
|
90
|
+
updatePartial,
|
|
91
|
+
toMetricsItems,
|
|
92
|
+
};
|
|
93
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
.wrapper {
|
|
2
|
+
box-sizing: border-box;
|
|
3
|
+
display: flex;
|
|
4
|
+
align-items: center;
|
|
5
|
+
gap: 12px;
|
|
6
|
+
padding: 10px 16px;
|
|
7
|
+
background: var(--color-card-background);
|
|
8
|
+
border-radius: 10px;
|
|
9
|
+
border: 1px solid rgba(16, 24, 40, 0.06);
|
|
10
|
+
box-shadow: 0 1px 0 rgba(16, 24, 40, 0.03);
|
|
11
|
+
width: 100%;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.label {
|
|
15
|
+
display: inline-flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
gap: 8px;
|
|
18
|
+
color: var(--color-text);
|
|
19
|
+
font-size: 14px;
|
|
20
|
+
flex: 0 0 auto;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.labelText {
|
|
24
|
+
display: inline-block;
|
|
25
|
+
color: var(--color-text);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.calendarIcon {
|
|
29
|
+
opacity: 0.75;
|
|
30
|
+
display: block;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.rangeRow {
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
gap: 10px;
|
|
37
|
+
width: 100%;
|
|
38
|
+
flex-wrap: nowrap;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.dateWrap {
|
|
42
|
+
display: flex;
|
|
43
|
+
flex-direction: column;
|
|
44
|
+
gap: 6px;
|
|
45
|
+
min-width: 0;
|
|
46
|
+
flex: 1 1 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.innerLabel {
|
|
50
|
+
font-size: 12px;
|
|
51
|
+
color: #6b7280;
|
|
52
|
+
display: block;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.dateInput {
|
|
56
|
+
-webkit-appearance: none;
|
|
57
|
+
appearance: none;
|
|
58
|
+
border: 1px solid;
|
|
59
|
+
padding: 8px 10px;
|
|
60
|
+
border-radius: 8px;
|
|
61
|
+
border-color: var(--color-border);
|
|
62
|
+
font-size: 14px;
|
|
63
|
+
background: transparent;
|
|
64
|
+
width: 100%;
|
|
65
|
+
box-sizing: border-box;
|
|
66
|
+
color: var(--color-text);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.sepWrap {
|
|
70
|
+
display: flex;
|
|
71
|
+
align-items: center;
|
|
72
|
+
justify-content: center;
|
|
73
|
+
padding: 0 6px;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.separator {
|
|
77
|
+
color: #9ca3af;
|
|
78
|
+
font-weight: 600;
|
|
79
|
+
user-select: none;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.samplingWrap {
|
|
83
|
+
display: flex;
|
|
84
|
+
/* position: absolute; */
|
|
85
|
+
flex-direction: column;
|
|
86
|
+
gap: 6px;
|
|
87
|
+
min-width: 160px;
|
|
88
|
+
flex: 0 0 auto;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.samplingLabel {
|
|
92
|
+
font-size: 12px;
|
|
93
|
+
color: #374151;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.samplingSelect {
|
|
97
|
+
padding: 8px 10px;
|
|
98
|
+
border-radius: 8px;
|
|
99
|
+
border: 1px solid rgba(16, 24, 40, 0.06);
|
|
100
|
+
background: var(--color-background);
|
|
101
|
+
font-size: 14px;
|
|
102
|
+
box-sizing: border-box;
|
|
103
|
+
width: 100%;
|
|
104
|
+
border-color: var(--color-border);
|
|
105
|
+
color: var(--color-text);
|
|
106
|
+
cursor: pointer;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* Responsive: stack on smaller screens */
|
|
110
|
+
@media (max-width: 720px) {
|
|
111
|
+
.wrapper {
|
|
112
|
+
padding: 10px;
|
|
113
|
+
}
|
|
114
|
+
.rangeRow {
|
|
115
|
+
gap: 8px;
|
|
116
|
+
}
|
|
117
|
+
.label {
|
|
118
|
+
font-size: 13px;
|
|
119
|
+
}
|
|
120
|
+
.samplingWrap {
|
|
121
|
+
min-width: 140px;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@media (max-width: 520px) {
|
|
126
|
+
.wrapper {
|
|
127
|
+
flex-direction: column;
|
|
128
|
+
align-items: stretch;
|
|
129
|
+
gap: 10px;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.label {
|
|
133
|
+
order: 0;
|
|
134
|
+
}
|
|
135
|
+
.rangeRow {
|
|
136
|
+
flex-direction: row;
|
|
137
|
+
flex-wrap: wrap;
|
|
138
|
+
align-items: flex-start;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.dateWrap {
|
|
142
|
+
flex: 1 1 48%;
|
|
143
|
+
}
|
|
144
|
+
.sepWrap {
|
|
145
|
+
display: none;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.samplingWrap {
|
|
149
|
+
flex: 1 1 100%;
|
|
150
|
+
min-width: 0;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@media (max-width: 360px) {
|
|
155
|
+
.dateWrap {
|
|
156
|
+
flex: 1 1 100%;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// components/PeriodRange/PeriodRange.stories.tsx
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import PeriodRange from './PeriodRange';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof PeriodRange> = {
|
|
6
|
+
title: 'Components/PeriodRange',
|
|
7
|
+
component: PeriodRange,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: {
|
|
10
|
+
docs: {
|
|
11
|
+
source: {
|
|
12
|
+
language: 'tsx',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default meta;
|
|
19
|
+
|
|
20
|
+
type Story = StoryObj<typeof PeriodRange>;
|
|
21
|
+
|
|
22
|
+
const DefaultCode = `<PeriodRange
|
|
23
|
+
start={new Date(new Date().setDate(new Date().getDate() - 7)).toISOString().slice(0, 10)}
|
|
24
|
+
end={new Date().toISOString().slice(0, 10)}
|
|
25
|
+
onChange={(range) => console.log('range', range)}
|
|
26
|
+
onSamplingChange={(sampling) => console.log('sampling', sampling)}
|
|
27
|
+
/>`;
|
|
28
|
+
|
|
29
|
+
export const Default: Story = {
|
|
30
|
+
args: {
|
|
31
|
+
start: new Date(new Date().setDate(new Date().getDate() - 7)).toISOString().slice(0, 10),
|
|
32
|
+
end: new Date().toISOString().slice(0, 10),
|
|
33
|
+
onChange: (r: any) => console.log('range', r),
|
|
34
|
+
onSamplingChange: (s: any) => console.log('sampling', s),
|
|
35
|
+
},
|
|
36
|
+
render: (args) => (
|
|
37
|
+
<div style={{ padding: 24, background: '#f8fafc' }}>
|
|
38
|
+
<PeriodRange {...args} />
|
|
39
|
+
</div>
|
|
40
|
+
),
|
|
41
|
+
parameters: {
|
|
42
|
+
docs: {
|
|
43
|
+
source: {
|
|
44
|
+
code: DefaultCode,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const CompactCode = `<PeriodRange />`;
|
|
51
|
+
|
|
52
|
+
export const Compact: Story = {
|
|
53
|
+
args: {},
|
|
54
|
+
render: (args) => (
|
|
55
|
+
<div style={{ padding: 24 }}>
|
|
56
|
+
<PeriodRange {...args} />
|
|
57
|
+
</div>
|
|
58
|
+
),
|
|
59
|
+
parameters: {
|
|
60
|
+
docs: {
|
|
61
|
+
source: {
|
|
62
|
+
code: CompactCode,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|