@sybilion/uilib 1.3.99 → 1.3.100

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.
Files changed (46) hide show
  1. package/dist/esm/components/ui/AnalysesSelector/AnalysesSelector.js +61 -14
  2. package/dist/esm/components/ui/AnalysesSelector/AnalysesSelector.styl.js +2 -2
  3. package/dist/esm/components/ui/AnalysesSelector/SelectInlineRenamer.js +102 -0
  4. package/dist/esm/components/ui/Chart/Chart.js +9 -5
  5. package/dist/esm/components/ui/Chart/chartForecastVisualization.constants.js +23 -0
  6. package/dist/esm/components/ui/Chart/components/ConfidenceBands.js +9 -0
  7. package/dist/esm/components/ui/Chart/components/CustomChartLegend/CustomChartLegend.js +2 -2
  8. package/dist/esm/components/ui/Chart/components/ForecastBoundaries.js +32 -0
  9. package/dist/esm/components/ui/Chart/components/ForecastLine.js +24 -0
  10. package/dist/esm/components/ui/Chart/components/HistoricalLine.js +24 -0
  11. package/dist/esm/components/ui/Chart/hooks/useChartAnimation.js +17 -0
  12. package/dist/esm/components/ui/Chart/hooks/useChartColors.js +12 -0
  13. package/dist/esm/components/ui/Chart/hooks/useLegendState.js +30 -0
  14. package/dist/esm/components/ui/Chart/tools/formatters.js +19 -3
  15. package/dist/esm/components/ui/ChartAreaInteractive/ChartAreaInteractive.helpers.js +1 -10
  16. package/dist/esm/components/ui/Select/Select.js +3 -3
  17. package/dist/esm/components/widgets/DriverCard/DriverCard.js +6 -6
  18. package/dist/esm/components/widgets/DriverCard/DriverPerformanceChart.js +9 -5
  19. package/dist/esm/components/widgets/DriversComparisonChart/DriversComparisonChart.styl.js +1 -1
  20. package/dist/esm/components/widgets/PerformanceChart/PerformanceChart.styl.js +1 -1
  21. package/dist/esm/index.js +10 -1
  22. package/dist/esm/types/src/components/ui/AnalysesSelector/AnalysesSelector.d.ts +1 -1
  23. package/dist/esm/types/src/components/ui/AnalysesSelector/AnalysesSelector.types.d.ts +7 -1
  24. package/dist/esm/types/src/components/ui/AnalysesSelector/SelectInlineRenamer.d.ts +12 -0
  25. package/dist/esm/types/src/components/ui/Chart/Chart.d.ts +9 -0
  26. package/dist/esm/types/src/components/ui/Chart/components/index.d.ts +1 -1
  27. package/dist/esm/types/src/components/ui/Chart/tools/formatters.d.ts +3 -1
  28. package/dist/esm/types/src/components/ui/ChartAreaInteractive/index.d.ts +1 -1
  29. package/dist/esm/types/src/components/ui/Select/Select.d.ts +1 -1
  30. package/dist/esm/types/src/components/ui/Select/Select.types.d.ts +1 -0
  31. package/package.json +1 -1
  32. package/src/components/ui/AnalysesSelector/AnalysesSelector.styl +62 -1
  33. package/src/components/ui/AnalysesSelector/AnalysesSelector.styl.d.ts +8 -0
  34. package/src/components/ui/AnalysesSelector/AnalysesSelector.tsx +136 -27
  35. package/src/components/ui/AnalysesSelector/AnalysesSelector.types.ts +7 -2
  36. package/src/components/ui/AnalysesSelector/SelectInlineRenamer.tsx +191 -0
  37. package/src/components/ui/Chart/Chart.tsx +16 -0
  38. package/src/components/ui/Chart/components/CustomChartLegend/CustomChartLegend.tsx +2 -3
  39. package/src/components/ui/Chart/components/index.ts +5 -1
  40. package/src/components/ui/Chart/tools/formatters.ts +20 -2
  41. package/src/components/ui/ChartAreaInteractive/index.ts +15 -1
  42. package/src/components/ui/Select/Select.tsx +13 -5
  43. package/src/components/ui/Select/Select.types.ts +1 -0
  44. package/src/components/widgets/DriverCard/DriverCard.tsx +7 -8
  45. package/src/components/widgets/DriversComparisonChart/DriversComparisonChart.styl +0 -1
  46. package/src/components/widgets/PerformanceChart/PerformanceChart.styl +1 -1
@@ -0,0 +1,191 @@
1
+ import cn from 'classnames';
2
+ import { useCallback, useEffect, useState } from 'react';
3
+
4
+ import { Button } from '#uilib/components/ui/Button';
5
+ import { Input } from '#uilib/components/ui/Input';
6
+ import { TextShimmer } from '#uilib/components/ui/TextShimmer/TextShimmer';
7
+ import {
8
+ Tooltip,
9
+ TooltipContent,
10
+ TooltipTrigger,
11
+ } from '#uilib/components/ui/Tooltip';
12
+ import { PencilSimpleIcon } from '@phosphor-icons/react';
13
+
14
+ import S from './AnalysesSelector.styl';
15
+
16
+ const LABEL_MAX = 64;
17
+ const MANUALLY_ADJUSTED_NAME = 'Manually adjusted';
18
+ const MANUALLY_ADJUSTED_RENAME_MAX =
19
+ LABEL_MAX - MANUALLY_ADJUSTED_NAME.length;
20
+
21
+ type SelectInlineRenamerProps = {
22
+ value: string;
23
+ /** Shown in trigger when not editing; defaults to `value`. */
24
+ displayLabel?: string;
25
+ onChange: (value: string) => void | Promise<void>;
26
+ disabled?: boolean;
27
+ className?: string;
28
+ isRenaming: boolean;
29
+ onEnterRenaming: () => void;
30
+ };
31
+
32
+ const stopSelectBubble = (e: React.SyntheticEvent) => {
33
+ e.stopPropagation();
34
+ };
35
+
36
+ const stopSelectOpen = (e: React.SyntheticEvent) => {
37
+ e.preventDefault();
38
+ e.stopPropagation();
39
+ };
40
+
41
+ const stopRenamerKeyboardBubble = (e: React.KeyboardEvent) => {
42
+ e.stopPropagation();
43
+ e.nativeEvent.stopImmediatePropagation();
44
+ };
45
+
46
+ export function SelectInlineRenamer({
47
+ value,
48
+ displayLabel,
49
+ onChange,
50
+ onEnterRenaming,
51
+ disabled,
52
+ className,
53
+ isRenaming,
54
+ }: SelectInlineRenamerProps) {
55
+ const [draft, setDraft] = useState(value);
56
+ const [isSaving, setIsSaving] = useState(false);
57
+
58
+ useEffect(() => {
59
+ if (!isSaving) {
60
+ setDraft(value);
61
+ }
62
+ }, [value, isSaving]);
63
+
64
+ const exitRenaming = useCallback(() => {
65
+ if (isRenaming) {
66
+ onEnterRenaming();
67
+ }
68
+ }, [isRenaming, onEnterRenaming]);
69
+
70
+ const persistRename = useCallback(
71
+ async (trimmed: string) => {
72
+ setIsSaving(true);
73
+ setDraft(trimmed);
74
+ exitRenaming();
75
+ try {
76
+ await onChange(trimmed);
77
+ } catch {
78
+ setDraft(value);
79
+ } finally {
80
+ setIsSaving(false);
81
+ }
82
+ },
83
+ [exitRenaming, onChange, value],
84
+ );
85
+
86
+ const commit = useCallback(() => {
87
+ const trimmed = draft.trim();
88
+ if (trimmed && trimmed !== value) {
89
+ void persistRename(trimmed);
90
+ return;
91
+ }
92
+ exitRenaming();
93
+ setDraft(value);
94
+ }, [draft, exitRenaming, persistRename, value]);
95
+
96
+ const cancel = useCallback(() => {
97
+ exitRenaming();
98
+ setDraft(value);
99
+ }, [exitRenaming, value]);
100
+
101
+ const onKeyDown = useCallback(
102
+ (e: React.KeyboardEvent<HTMLInputElement>) => {
103
+ stopRenamerKeyboardBubble(e);
104
+
105
+ if (e.key === 'Enter' && draft.trim()) {
106
+ e.preventDefault();
107
+ const trimmed = draft.trim();
108
+ if (trimmed !== value) {
109
+ void persistRename(trimmed);
110
+ return;
111
+ }
112
+ exitRenaming();
113
+ setDraft(trimmed);
114
+ }
115
+
116
+ if (e.key === 'Escape') {
117
+ e.preventDefault();
118
+ cancel();
119
+ }
120
+ },
121
+ [cancel, draft, exitRenaming, persistRename, value],
122
+ );
123
+
124
+ const onKeyUp = useCallback((e: React.KeyboardEvent<HTMLInputElement>) => {
125
+ if (e.key !== ' ') return;
126
+
127
+ e.preventDefault();
128
+ e.stopPropagation();
129
+ }, []);
130
+
131
+ const onDraftChange = useCallback(
132
+ (e: React.ChangeEvent<HTMLInputElement>) => {
133
+ setDraft(e.target.value.slice(0, MANUALLY_ADJUSTED_RENAME_MAX));
134
+ },
135
+ [],
136
+ );
137
+
138
+ if (isRenaming) {
139
+ return (
140
+ <Input
141
+ className={cn(S.selectInlineRenamerInput, className)}
142
+ autoFocus
143
+ variant="clean"
144
+ size="sm"
145
+ value={draft}
146
+ maxLength={MANUALLY_ADJUSTED_RENAME_MAX}
147
+ onChange={onDraftChange}
148
+ onBlur={commit}
149
+ onKeyDown={onKeyDown}
150
+ onKeyUp={onKeyUp}
151
+ onPointerDown={stopSelectBubble}
152
+ onClick={stopSelectBubble}
153
+ />
154
+ );
155
+ }
156
+
157
+ const triggerLabel = isSaving ? draft : (displayLabel ?? value);
158
+
159
+ return (
160
+ <div className={cn(S.selectInlineRenamer, className)}>
161
+ {isSaving ? (
162
+ <TextShimmer as="span" className={S.label}>
163
+ {triggerLabel}
164
+ </TextShimmer>
165
+ ) : (
166
+ <span className={S.label}>{triggerLabel}</span>
167
+ )}
168
+ {!disabled && !isSaving && (
169
+ <Tooltip>
170
+ <TooltipTrigger asChild>
171
+ <Button
172
+ variant="ghost"
173
+ size="sm"
174
+ type="button"
175
+ className={S.renamerEditButton}
176
+ onPointerDown={stopSelectOpen}
177
+ onClick={e => {
178
+ e.stopPropagation();
179
+ setDraft(value);
180
+ onEnterRenaming();
181
+ }}
182
+ >
183
+ <PencilSimpleIcon size={16} />
184
+ </Button>
185
+ </TooltipTrigger>
186
+ <TooltipContent side="bottom">Rename</TooltipContent>
187
+ </Tooltip>
188
+ )}
189
+ </div>
190
+ );
191
+ }
@@ -34,3 +34,19 @@ export {
34
34
  type ChartEmptyStateProps,
35
35
  type ChartEmptyStatusTone,
36
36
  } from './components/ChartEmptyState/ChartEmptyState';
37
+ export { ConfidenceBands } from './components/ConfidenceBands';
38
+ export { ForecastBoundaries } from './components/ForecastBoundaries';
39
+ export { ForecastLine } from './components/ForecastLine';
40
+ export { HistoricalLine } from './components/HistoricalLine';
41
+ export {
42
+ DEFAULT_QUANTILE_BAND_COLOR,
43
+ QuantileBands,
44
+ } from './components/QuantileBands';
45
+ export {
46
+ formatCompactAxisNumber,
47
+ formatDate,
48
+ formatNumber,
49
+ } from './tools/formatters';
50
+ export { useChartAnimation } from './hooks/useChartAnimation';
51
+ export { useChartColors } from './hooks/useChartColors';
52
+ export { useLegendState } from './hooks/useLegendState';
@@ -1,9 +1,8 @@
1
- import cn from 'classnames';
2
1
  import { useCallback, useMemo } from 'react';
3
2
 
4
3
  import { AnalysesSelector } from '#uilib/components/ui/AnalysesSelector';
5
-
6
4
  import S from './CustomChartLegend.styl';
5
+ import cn from 'classnames';
7
6
 
8
7
  interface CustomChartLegendPayloadItem {
9
8
  value: string;
@@ -138,7 +137,7 @@ export function CustomChartLegend({
138
137
  selectedIds={selectedIds}
139
138
  onItemToggle={handleItemToggle}
140
139
  inlineMode
141
- size="sm"
140
+ size="xs"
142
141
  variant="clear"
143
142
  onFailedItemClick={onFailedAnalysisClick}
144
143
  enableToggleHidden
@@ -5,7 +5,11 @@ export { ChartGrid } from './ChartGrid';
5
5
  export { ChartLegendContent } from './ChartLegendContent';
6
6
  export { ChartTooltipContent } from './ChartTooltipContent';
7
7
  export { ForecastLine } from './ForecastLine';
8
- export { formatDate, formatNumber } from '../tools/formatters';
8
+ export {
9
+ formatCompactAxisNumber,
10
+ formatDate,
11
+ formatNumber,
12
+ } from '../tools/formatters';
9
13
  export { HistoricalLine } from './HistoricalLine';
10
14
  export { useChartAnimation } from '../hooks/useChartAnimation';
11
15
  export { useChartColors } from '../hooks/useChartColors';
@@ -1,15 +1,33 @@
1
1
  /**
2
- * Format number for display (with k/m abbreviations)
2
+ * Format number for display (with k/m/b abbreviations)
3
3
  */
4
4
  export const formatNumber = (value: number): string => {
5
+ if (Math.abs(value) >= 1000000000) {
6
+ return (value / 1000000000).toFixed(1).replace(/\.0$/, '') + 'B';
7
+ }
5
8
  if (Math.abs(value) >= 1000000) {
6
9
  return (value / 1000000).toFixed(1).replace(/\.0$/, '') + 'M';
7
- } else if (Math.abs(value) >= 1000) {
10
+ }
11
+ if (Math.abs(value) >= 1000) {
8
12
  return (value / 1000).toFixed(1).replace(/\.0$/, '') + 'K';
9
13
  }
10
14
  return value.toFixed(0);
11
15
  };
12
16
 
17
+ /** Shorter Y-axis style labels (integer B/M/K) for tight layouts. */
18
+ export const formatCompactAxisNumber = (value: number): string => {
19
+ if (Math.abs(value) >= 1000000000) {
20
+ return `${Math.round(value / 1000000000)}B`;
21
+ }
22
+ if (Math.abs(value) >= 1000000) {
23
+ return `${Math.round(value / 1000000)}M`;
24
+ }
25
+ if (Math.abs(value) >= 1000) {
26
+ return `${Math.round(value / 1000)}K`;
27
+ }
28
+ return value.toFixed(0);
29
+ };
30
+
13
31
  /**
14
32
  * Round a number based on its magnitude
15
33
  * - 2 digits (10-99): round to nearest 10
@@ -1,5 +1,19 @@
1
1
  export * from './ChartAreaInteractive';
2
- export * from './ChartAreaInteractive.helpers';
2
+ export {
3
+ DRAG_TIME_RANGE_PREFIX,
4
+ encodeDragTimeRange,
5
+ filterDataForTimeRange,
6
+ findPinPositionForDate,
7
+ isAnalysisDone,
8
+ isAnalysisFailed,
9
+ isAnalysisNotFailed,
10
+ isTimeRangePreset,
11
+ longDateFormatter,
12
+ parseDragTimeRange,
13
+ shortDateFormatter,
14
+ type FilterDataForTimeRangeOptions,
15
+ type TimeRangePreset,
16
+ } from './ChartAreaInteractive.helpers';
3
17
  export * from './ChartAreaInteractive.types';
4
18
  export * from './ChartLines';
5
19
  export type { OverlayMode } from './ChartAreaInteractive.types';
@@ -45,6 +45,7 @@ function SelectTrigger({
45
45
  darker = false,
46
46
  children,
47
47
  hideChevron = false,
48
+ asChild = false,
48
49
  ...props
49
50
  }: SelectTriggerProps) {
50
51
  return (
@@ -53,13 +54,20 @@ function SelectTrigger({
53
54
  data-size={size}
54
55
  data-variant={variant}
55
56
  className={cn(S.selectTrigger, darker && S.darker, className)}
57
+ asChild={asChild}
56
58
  {...props}
57
59
  >
58
- {children}
59
- {!hideChevron && (
60
- <SelectPrimitive.Icon asChild>
61
- <ChevronDownIcon className={S.selectIcon} />
62
- </SelectPrimitive.Icon>
60
+ {asChild ? (
61
+ children
62
+ ) : (
63
+ <>
64
+ {children}
65
+ {!hideChevron && (
66
+ <SelectPrimitive.Icon asChild>
67
+ <ChevronDownIcon className={S.selectIcon} />
68
+ </SelectPrimitive.Icon>
69
+ )}
70
+ </>
63
71
  )}
64
72
  </SelectPrimitive.Trigger>
65
73
  );
@@ -9,6 +9,7 @@ export interface SelectTriggerProps extends React.ComponentProps<
9
9
  className?: string;
10
10
  children?: React.ReactNode;
11
11
  hideChevron?: boolean;
12
+ asChild?: boolean;
12
13
  }
13
14
 
14
15
  export type SelectProps = React.ComponentProps<typeof SelectPrimitive.Root>;
@@ -1,16 +1,15 @@
1
- import React, { useMemo } from 'react';
2
-
1
+ import { Card, CardContent } from '@sybilion/uilib';
3
2
  import { CoffeeIcon, TrendDownIcon, TrendUpIcon } from '@phosphor-icons/react';
3
+ import React, { useMemo } from 'react';
4
+ import { Tooltip, TooltipContent, TooltipTrigger } from '../../ui/Tooltip';
4
5
 
5
6
  import { Badge } from '../../ui/Badge';
6
- import { Card, CardContent } from '../../ui/Card';
7
+ import type { DriverData } from '../DriverMap/driverMapGeography';
8
+ import { DriverPerformanceChart } from './DriverPerformanceChart';
7
9
  import { LabelWithId } from '../../ui/LabelWithId';
10
+ import S from './DriverCard.styl';
8
11
  import { Skeleton } from '../../ui/Skeleton';
9
- import { Tooltip, TooltipContent, TooltipTrigger } from '../../ui/Tooltip';
10
12
  import { getCategoryIcon } from '../DriverMap/driverCategoryIcon';
11
- import type { DriverData } from '../DriverMap/driverMapGeography';
12
- import S from './DriverCard.styl';
13
- import { DriverPerformanceChart } from './DriverPerformanceChart';
14
13
 
15
14
  export interface DriverCardProps {
16
15
  selectedDriver: DriverData | null;
@@ -114,7 +113,7 @@ export function DriverCard({
114
113
 
115
114
  if (isLoading) {
116
115
  return (
117
- <Card className={S.root}>
116
+ <Card className={S.root} radiusSize="xl">
118
117
  <CardContent noScroll>
119
118
  <div className={S.skeletonContainer}>
120
119
  <Skeleton className={`${S.skeletonItem} ${S.hs} ${S.w75}`} />
@@ -127,7 +127,6 @@
127
127
  .seriesLabel
128
128
  min-width 0
129
129
  max-width 60vw
130
- padding var(--p-2) 0
131
130
  line-clamp(3)
132
131
  white-space break-spaces
133
132
 
@@ -154,7 +154,7 @@
154
154
 
155
155
  button
156
156
  width calc(100% - 2px)
157
- height calc(100% - 2px)
157
+ height var(--p-12)
158
158
  border-radius 0
159
159
 
160
160
  .scrollbar