@gunjo/ui 0.0.1-alpha.1 → 0.0.1-alpha.2
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/LICENSE +21 -0
- package/README.ja.md +90 -0
- package/README.md +52 -91
- package/package.json +47 -6
- package/src/components/display/Accordion.tsx +185 -0
- package/src/components/display/AccordionGroup.tsx +155 -0
- package/src/components/display/ActionDataTable.tsx +413 -0
- package/src/components/display/ActivityTimelineCard.tsx +483 -0
- package/src/components/display/AnalyticsCard.tsx +167 -0
- package/src/components/display/AssetCard.tsx +242 -0
- package/src/components/display/AssetGrid.tsx +164 -0
- package/src/components/display/Avatar.tsx +127 -0
- package/src/components/display/AvatarGroup.tsx +131 -0
- package/src/components/{atoms → display}/Badge.tsx +3 -3
- package/src/components/display/BarChart.tsx +247 -0
- package/src/components/{molecules → display}/Card.tsx +1 -1
- package/src/components/display/Carousel.tsx +593 -0
- package/src/components/display/ChartLegend.tsx +124 -0
- package/src/components/display/ChatMessage.tsx +382 -0
- package/src/components/display/ChoroplethMap.tsx +613 -0
- package/src/components/display/Code.tsx +42 -0
- package/src/components/display/CodeBlock.tsx +338 -0
- package/src/components/display/ColorSwatch.tsx +71 -0
- package/src/components/display/ConcentricProgressCard.tsx +545 -0
- package/src/components/display/DataTable.tsx +522 -0
- package/src/components/display/DistributionBar.tsx +102 -0
- package/src/components/display/DocNote.tsx +36 -0
- package/src/components/display/DonutChart.tsx +257 -0
- package/src/components/display/EmptyState.tsx +44 -0
- package/src/components/display/FileTree.tsx +180 -0
- package/src/components/display/GaugeChart.tsx +219 -0
- package/src/components/display/HeatmapChart.tsx +266 -0
- package/src/components/display/Icon.tsx +66 -0
- package/src/components/display/ImagePreview.tsx +140 -0
- package/src/components/{atoms → display}/Img.tsx +46 -12
- package/src/components/display/LabeledDonutCard.tsx +475 -0
- package/src/components/display/LineChart.tsx +464 -0
- package/src/components/{molecules → display}/List.tsx +20 -13
- package/src/components/display/MarkdownRenderer.tsx +157 -0
- package/src/components/display/MetadataList.tsx +81 -0
- package/src/components/display/MiniDistributionBarCard.tsx +314 -0
- package/src/components/display/PieChart.tsx +234 -0
- package/src/components/display/QuadrantMatrix.tsx +330 -0
- package/src/components/display/RadarChart.tsx +335 -0
- package/src/components/display/RadialBarChart.tsx +264 -0
- package/src/components/display/RetentionCohortCard.tsx +350 -0
- package/src/components/display/RibbonChart.tsx +618 -0
- package/src/components/display/SearchableAccordion.tsx +270 -0
- package/src/components/display/SegmentTimelineCard.tsx +452 -0
- package/src/components/display/SegmentedGaugeCard.tsx +607 -0
- package/src/components/display/Spacer.tsx +51 -0
- package/src/components/display/SparklineChart.tsx +394 -0
- package/src/components/display/StackedBarChart.tsx +393 -0
- package/src/components/display/Statistic.tsx +70 -0
- package/src/components/{molecules → display}/Table.tsx +22 -7
- package/src/components/display/Tag.tsx +80 -0
- package/src/components/display/TagEditor.tsx +141 -0
- package/src/components/display/Timeline.tsx +121 -0
- package/src/components/{atoms → display}/ToolPill.tsx +42 -18
- package/src/components/display/TreeView.tsx +226 -0
- package/src/components/display/chart-tooltip.tsx +423 -0
- package/src/components/display/chart-utils.ts +71 -0
- package/src/components/display/circular-chart-utils.ts +147 -0
- package/src/components/display/generated/default-variant-keys.ts +90 -0
- package/src/components/display/generated/variant-keys.ts +169 -0
- package/src/components/{atoms → feedback}/Alert.tsx +12 -5
- package/src/components/feedback/Banner.tsx +90 -0
- package/src/components/{molecules → feedback}/NotificationCenter.tsx +64 -31
- package/src/components/feedback/ProgressWidget.tsx +44 -0
- package/src/components/{atoms → feedback}/Spinner.tsx +2 -2
- package/src/components/{molecules → feedback}/StatusBar.tsx +4 -4
- package/src/components/feedback/StatusScreen.tsx +148 -0
- package/src/components/{molecules → feedback}/Stepper.tsx +10 -5
- package/src/components/feedback/Toast.tsx +108 -0
- package/src/components/feedback/ToastProvider.tsx +78 -0
- package/src/components/feedback/generated/default-variant-keys.ts +16 -0
- package/src/components/feedback/generated/variant-keys.ts +21 -0
- package/src/components/generated/component-manifest.ts +1568 -454
- package/src/components/generated/component-style-hints.ts +1958 -718
- package/src/components/{atoms → inputs}/ButtonVariants.ts +13 -3
- package/src/components/inputs/Calendar.tsx +212 -0
- package/src/components/inputs/ChatComposer.tsx +75 -0
- package/src/components/inputs/ChatInput.tsx +528 -0
- package/src/components/{atoms → inputs}/Checkbox.tsx +2 -2
- package/src/components/inputs/Combobox.tsx +175 -0
- package/src/components/inputs/CopyButton.tsx +187 -0
- package/src/components/inputs/DatePicker.tsx +519 -0
- package/src/components/inputs/DateRangePicker.tsx +878 -0
- package/src/components/inputs/EditableField.tsx +182 -0
- package/src/components/{organisms → inputs}/FileUploader.tsx +24 -9
- package/src/components/inputs/FilterButton.tsx +163 -0
- package/src/components/{molecules → inputs}/Form.tsx +20 -3
- package/src/components/{atoms → inputs}/Input.tsx +2 -0
- package/src/components/inputs/InputOTP.tsx +75 -0
- package/src/components/inputs/Mention.tsx +279 -0
- package/src/components/inputs/NumberInput.tsx +109 -0
- package/src/components/inputs/PasswordGroup.tsx +138 -0
- package/src/components/inputs/PasswordInput.tsx +74 -0
- package/src/components/inputs/PasswordRequirementList.tsx +96 -0
- package/src/components/inputs/PasswordStrengthMeter.tsx +93 -0
- package/src/components/inputs/PhoneInput.tsx +99 -0
- package/src/components/inputs/PostalCodeInput.tsx +98 -0
- package/src/components/inputs/RangeSlider.tsx +129 -0
- package/src/components/inputs/SearchInput.tsx +76 -0
- package/src/components/inputs/Select.tsx +39 -0
- package/src/components/{atoms → inputs}/Slider.tsx +18 -5
- package/src/components/{molecules → inputs}/SortButton.tsx +5 -2
- package/src/components/{atoms → inputs}/Switch.tsx +15 -4
- package/src/components/inputs/TagInput.tsx +114 -0
- package/src/components/{atoms → inputs}/Textarea.tsx +1 -0
- package/src/components/inputs/TimePicker.tsx +150 -0
- package/src/components/inputs/Toggle.tsx +48 -0
- package/src/components/{atoms → inputs}/ToggleGroup.tsx +2 -2
- package/src/components/inputs/TooltipButton.tsx +148 -0
- package/src/components/inputs/VoiceInputButton.tsx +317 -0
- package/src/components/inputs/calendar-holidays.ts +56 -0
- package/src/components/inputs/generated/default-variant-keys.ts +32 -0
- package/src/components/{atoms → inputs}/generated/variant-keys.ts +19 -27
- package/src/components/layout/AspectRatio.tsx +12 -0
- package/src/components/layout/AssetInspectorPanel.tsx +416 -0
- package/src/components/layout/Cluster.tsx +56 -0
- package/src/components/layout/CollapsiblePanelToggle.tsx +94 -0
- package/src/components/layout/Container.tsx +43 -0
- package/src/components/layout/DeviceFrame.tsx +227 -0
- package/src/components/layout/Grid.tsx +65 -0
- package/src/components/layout/HStack.tsx +73 -0
- package/src/components/{organisms → layout}/InspectorPanel.tsx +6 -5
- package/src/components/layout/MarqueeFrame.tsx +158 -0
- package/src/components/layout/Resizable.tsx +94 -0
- package/src/components/layout/ScrollArea.tsx +71 -0
- package/src/components/{organisms → layout}/SpatialCanvas.tsx +12 -7
- package/src/components/layout/VStack.tsx +69 -0
- package/src/components/layout/generated/default-variant-keys.ts +16 -0
- package/src/components/layout/generated/variant-keys.ts +21 -0
- package/src/components/{molecules → navigation}/Breadcrumb.tsx +5 -4
- package/src/components/navigation/Command.tsx +266 -0
- package/src/components/navigation/CommandPalette.tsx +83 -0
- package/src/components/navigation/DocumentPager.tsx +171 -0
- package/src/components/navigation/Footer.tsx +88 -0
- package/src/components/navigation/Header.tsx +80 -0
- package/src/components/{molecules → navigation}/Menubar.tsx +45 -12
- package/src/components/navigation/NavigationMenu.tsx +128 -0
- package/src/components/navigation/PageAside.tsx +84 -0
- package/src/components/{molecules → navigation}/Pagination.tsx +60 -7
- package/src/components/{organisms → navigation}/RightRail.tsx +1 -1
- package/src/components/navigation/Sidebar.tsx +223 -0
- package/src/components/navigation/SidebarItem.tsx +160 -0
- package/src/components/{molecules → navigation}/Tabs.tsx +2 -2
- package/src/components/navigation/TextLink.tsx +71 -0
- package/src/components/navigation/generated/default-variant-keys.ts +12 -0
- package/src/components/navigation/generated/variant-keys.ts +13 -0
- package/src/components/overlay/AIChatInput.tsx +5 -0
- package/src/components/overlay/AIChatMessage.tsx +6 -0
- package/src/components/overlay/AlertDialog.tsx +145 -0
- package/src/components/overlay/ChatPanel.tsx +180 -0
- package/src/components/{molecules → overlay}/ContextMenu.tsx +65 -29
- package/src/components/{molecules → overlay}/Dialog.tsx +21 -13
- package/src/components/overlay/Drawer.tsx +131 -0
- package/src/components/{molecules → overlay}/DropdownMenu.tsx +52 -17
- package/src/components/overlay/FloatingPanel.tsx +90 -0
- package/src/components/overlay/HoverCard.tsx +36 -0
- package/src/components/overlay/MediaLightbox.tsx +403 -0
- package/src/components/overlay/MediaPickerDialog.tsx +198 -0
- package/src/components/overlay/Modal.tsx +103 -0
- package/src/components/overlay/OnboardingFlow.tsx +172 -0
- package/src/components/overlay/Popover.tsx +36 -0
- package/src/components/overlay/ShareModal.tsx +324 -0
- package/src/components/{molecules → overlay}/Sheet.tsx +76 -19
- package/src/components/overlay/Tooltip.tsx +130 -0
- package/src/components/overlay/generated/default-variant-keys.ts +14 -0
- package/src/components/overlay/generated/variant-keys.ts +17 -0
- package/src/components/patterns/BlogTemplate.tsx +46 -0
- package/src/components/{templates → patterns}/DashboardTemplate.tsx +2 -2
- package/src/components/patterns/DocsTemplate.tsx +41 -0
- package/src/components/{templates → patterns}/MediaLibraryTemplate.tsx +1 -1
- package/src/components/patterns/OnboardingTemplate.tsx +32 -0
- package/src/components/patterns/PricingTemplate.tsx +106 -0
- package/src/globals.css +173 -22
- package/src/index.ts +177 -76
- package/tailwind-theme-extend.cjs +48 -3
- package/design/atoms-metadata.json +0 -82
- package/design/molecules-metadata.json +0 -130
- package/design/organisms-metadata.json +0 -38
- package/design/templates-metadata.json +0 -38
- package/src/components/atoms/Avatar.tsx +0 -57
- package/src/components/atoms/Select.tsx +0 -28
- package/src/components/atoms/generated/default-variant-keys.ts +0 -36
- package/src/components/molecules/AIChatInput.tsx +0 -140
- package/src/components/molecules/AIChatMessage.tsx +0 -109
- package/src/components/molecules/Accordion.tsx +0 -99
- package/src/components/molecules/Calendar.tsx +0 -60
- package/src/components/molecules/Carousel.tsx +0 -261
- package/src/components/molecules/Command.tsx +0 -152
- package/src/components/molecules/FilterButton.tsx +0 -133
- package/src/components/molecules/HoverCard.tsx +0 -29
- package/src/components/molecules/Modal.tsx +0 -66
- package/src/components/molecules/Popover.tsx +0 -31
- package/src/components/molecules/ProgressWidget.tsx +0 -40
- package/src/components/molecules/Resizable.tsx +0 -47
- package/src/components/molecules/ScrollArea.tsx +0 -48
- package/src/components/molecules/SidebarItem.tsx +0 -134
- package/src/components/molecules/Toast.tsx +0 -57
- package/src/components/molecules/Tooltip.tsx +0 -30
- package/src/components/molecules/generated/default-variant-keys.ts +0 -22
- package/src/components/molecules/generated/variant-keys.ts +0 -33
- package/src/components/organisms/CommandPalette.tsx +0 -58
- package/src/components/organisms/FloatingPanel.tsx +0 -46
- package/src/components/organisms/ShareModal.tsx +0 -182
- package/src/components/organisms/ToastProvider.tsx +0 -49
- /package/src/components/{atoms → display}/Kbd.tsx +0 -0
- /package/src/components/{atoms → display}/Separator.tsx +0 -0
- /package/src/components/{atoms → display}/Skeleton.tsx +0 -0
- /package/src/components/{atoms → feedback}/Progress.tsx +0 -0
- /package/src/components/{atoms → inputs}/Button.tsx +0 -0
- /package/src/components/{atoms → inputs}/Label.tsx +0 -0
- /package/src/components/{atoms → inputs}/RadioGroup.tsx +0 -0
- /package/src/components/{organisms → navigation}/AppRail.tsx +0 -0
- /package/src/components/{templates → patterns}/AuthTemplate.tsx +0 -0
- /package/src/components/{templates → patterns}/BannalyzeTemplate.tsx +0 -0
- /package/src/components/{templates → patterns}/ChatTemplate.tsx +0 -0
- /package/src/components/{templates → patterns}/EditorTemplate.tsx +0 -0
- /package/src/components/{templates → patterns}/KanbanTemplate.tsx +0 -0
- /package/src/components/{templates → patterns}/LandingTemplate.tsx +0 -0
- /package/src/components/{templates → patterns}/SettingsTemplate.tsx +0 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
import type { ChartDataPoint } from "./chart-utils"
|
|
7
|
+
import {
|
|
8
|
+
chartLabelToString,
|
|
9
|
+
defaultChartValueFormatter,
|
|
10
|
+
getChartColor,
|
|
11
|
+
normalizeChartValue,
|
|
12
|
+
} from "./chart-utils"
|
|
13
|
+
import { ChartTooltip } from "./chart-tooltip"
|
|
14
|
+
import type { BarChartVariantKey } from "./generated/variant-keys"
|
|
15
|
+
import { barChartDefaultVariantKey } from "./generated/default-variant-keys"
|
|
16
|
+
|
|
17
|
+
export interface BarChartProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
18
|
+
data: ChartDataPoint[]
|
|
19
|
+
variant?: BarChartVariantKey
|
|
20
|
+
max?: number
|
|
21
|
+
averageValue?: number
|
|
22
|
+
averageLabel?: React.ReactNode
|
|
23
|
+
formatValue?: (value: number) => React.ReactNode
|
|
24
|
+
showGrid?: boolean
|
|
25
|
+
showLabels?: boolean
|
|
26
|
+
showValues?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const barChartVariantClasses: Record<BarChartVariantKey, string> = {
|
|
30
|
+
horizontal: "h-[192px] w-full p-0",
|
|
31
|
+
vertical: "h-[192px] w-full p-0",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const BarChart = React.forwardRef<HTMLDivElement, BarChartProps>(
|
|
35
|
+
(
|
|
36
|
+
{
|
|
37
|
+
className,
|
|
38
|
+
data,
|
|
39
|
+
variant = barChartDefaultVariantKey,
|
|
40
|
+
max,
|
|
41
|
+
averageValue,
|
|
42
|
+
averageLabel = "Average",
|
|
43
|
+
formatValue = defaultChartValueFormatter,
|
|
44
|
+
showGrid = true,
|
|
45
|
+
showLabels = true,
|
|
46
|
+
showValues = false,
|
|
47
|
+
...props
|
|
48
|
+
},
|
|
49
|
+
ref
|
|
50
|
+
) => {
|
|
51
|
+
const values = data.map((item) => item.value)
|
|
52
|
+
const maxValue = Math.max(max ?? 0, averageValue ?? 0, ...values, 1)
|
|
53
|
+
const averagePercent =
|
|
54
|
+
averageValue === undefined
|
|
55
|
+
? null
|
|
56
|
+
: normalizeChartValue(averageValue, maxValue)
|
|
57
|
+
const averageText = chartLabelToString(averageLabel, "Average")
|
|
58
|
+
|
|
59
|
+
if (variant === "horizontal") {
|
|
60
|
+
return (
|
|
61
|
+
<div
|
|
62
|
+
ref={ref}
|
|
63
|
+
className={cn(
|
|
64
|
+
barChartVariantClasses[variant],
|
|
65
|
+
"flex flex-col justify-center gap-3 overflow-hidden",
|
|
66
|
+
className
|
|
67
|
+
)}
|
|
68
|
+
{...props}
|
|
69
|
+
>
|
|
70
|
+
{data.map((item, index) => {
|
|
71
|
+
const percent = normalizeChartValue(item.value, maxValue)
|
|
72
|
+
return (
|
|
73
|
+
<div
|
|
74
|
+
key={`${String(item.label)}-${index}`}
|
|
75
|
+
className={cn(
|
|
76
|
+
"grid min-w-0 items-center gap-3 text-sm",
|
|
77
|
+
showValues
|
|
78
|
+
? "grid-cols-[minmax(0,0.8fr)_minmax(0,2.8fr)_auto]"
|
|
79
|
+
: "grid-cols-[minmax(0,1fr)_minmax(0,3fr)]"
|
|
80
|
+
)}
|
|
81
|
+
>
|
|
82
|
+
{showLabels ? (
|
|
83
|
+
<span className="truncate text-muted-foreground">
|
|
84
|
+
{item.label}
|
|
85
|
+
</span>
|
|
86
|
+
) : null}
|
|
87
|
+
<div className="relative h-3 min-w-0 rounded-full bg-muted">
|
|
88
|
+
{averagePercent !== null ? (
|
|
89
|
+
<ChartTooltip
|
|
90
|
+
label={averageLabel}
|
|
91
|
+
value={formatValue(averageValue ?? 0)}
|
|
92
|
+
>
|
|
93
|
+
<span
|
|
94
|
+
className="absolute top-1/2 z-10 h-10 w-5 -translate-x-1/2 -translate-y-1/2 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
|
95
|
+
style={{ left: `${averagePercent}%` }}
|
|
96
|
+
tabIndex={index === 0 ? 0 : undefined}
|
|
97
|
+
aria-label={
|
|
98
|
+
index === 0
|
|
99
|
+
? `${averageText}: ${formatValue(averageValue ?? 0)}`
|
|
100
|
+
: undefined
|
|
101
|
+
}
|
|
102
|
+
>
|
|
103
|
+
<span
|
|
104
|
+
className="pointer-events-none absolute left-1/2 top-1/2 h-9 -translate-x-1/2 -translate-y-1/2 border-l border-dashed border-foreground/75"
|
|
105
|
+
aria-hidden="true"
|
|
106
|
+
/>
|
|
107
|
+
</span>
|
|
108
|
+
</ChartTooltip>
|
|
109
|
+
) : null}
|
|
110
|
+
<ChartTooltip
|
|
111
|
+
label={item.label}
|
|
112
|
+
value={formatValue(item.value)}
|
|
113
|
+
description={
|
|
114
|
+
averageValue !== undefined
|
|
115
|
+
? [averageLabel, ": ", formatValue(averageValue)]
|
|
116
|
+
: undefined
|
|
117
|
+
}
|
|
118
|
+
>
|
|
119
|
+
<span
|
|
120
|
+
className="block h-full rounded-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
|
121
|
+
style={{
|
|
122
|
+
width: `${percent}%`,
|
|
123
|
+
backgroundColor: getChartColor(item.color, index),
|
|
124
|
+
}}
|
|
125
|
+
tabIndex={0}
|
|
126
|
+
aria-label={`${chartLabelToString(item.label)}: ${formatValue(item.value)}${
|
|
127
|
+
averageValue !== undefined
|
|
128
|
+
? ` (${averageText}: ${formatValue(averageValue)})`
|
|
129
|
+
: ""
|
|
130
|
+
}`}
|
|
131
|
+
/>
|
|
132
|
+
</ChartTooltip>
|
|
133
|
+
</div>
|
|
134
|
+
{showValues ? (
|
|
135
|
+
<span className="text-xs tabular-nums text-muted-foreground">
|
|
136
|
+
{formatValue(item.value)}
|
|
137
|
+
</span>
|
|
138
|
+
) : null}
|
|
139
|
+
</div>
|
|
140
|
+
)
|
|
141
|
+
})}
|
|
142
|
+
</div>
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<div
|
|
148
|
+
ref={ref}
|
|
149
|
+
className={cn(
|
|
150
|
+
barChartVariantClasses[variant],
|
|
151
|
+
"flex flex-col justify-end",
|
|
152
|
+
className
|
|
153
|
+
)}
|
|
154
|
+
{...props}
|
|
155
|
+
>
|
|
156
|
+
<div className="relative min-h-0 flex-1 border-b border-border/70">
|
|
157
|
+
<div
|
|
158
|
+
className="absolute inset-x-0 bottom-0 flex items-end gap-2"
|
|
159
|
+
style={{ top: showValues ? "1.5rem" : 0 }}
|
|
160
|
+
>
|
|
161
|
+
{showGrid
|
|
162
|
+
? [25, 50, 75].map((percent) => (
|
|
163
|
+
<span
|
|
164
|
+
key={percent}
|
|
165
|
+
className="pointer-events-none absolute inset-x-0 border-t border-dashed border-border/70"
|
|
166
|
+
style={{ bottom: `${percent}%` }}
|
|
167
|
+
aria-hidden="true"
|
|
168
|
+
/>
|
|
169
|
+
))
|
|
170
|
+
: null}
|
|
171
|
+
{averagePercent !== null ? (
|
|
172
|
+
<ChartTooltip
|
|
173
|
+
label={averageLabel}
|
|
174
|
+
value={formatValue(averageValue ?? 0)}
|
|
175
|
+
>
|
|
176
|
+
<span
|
|
177
|
+
className="absolute inset-x-0 z-20 h-4 translate-y-1/2 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
|
178
|
+
style={{ bottom: `${averagePercent}%` }}
|
|
179
|
+
tabIndex={0}
|
|
180
|
+
aria-label={`${averageText}: ${formatValue(averageValue ?? 0)}`}
|
|
181
|
+
>
|
|
182
|
+
<span
|
|
183
|
+
className="pointer-events-none absolute inset-x-0 top-1/2 border-t border-dashed border-foreground/50"
|
|
184
|
+
aria-hidden="true"
|
|
185
|
+
/>
|
|
186
|
+
</span>
|
|
187
|
+
</ChartTooltip>
|
|
188
|
+
) : null}
|
|
189
|
+
{data.map((item, index) => {
|
|
190
|
+
const percent = normalizeChartValue(item.value, maxValue)
|
|
191
|
+
return (
|
|
192
|
+
<div
|
|
193
|
+
key={`${String(item.label)}-${index}`}
|
|
194
|
+
className="relative z-10 flex h-full min-w-0 flex-1 items-end justify-center"
|
|
195
|
+
>
|
|
196
|
+
<ChartTooltip
|
|
197
|
+
label={item.label}
|
|
198
|
+
value={formatValue(item.value)}
|
|
199
|
+
description={
|
|
200
|
+
averageValue !== undefined
|
|
201
|
+
? [averageLabel, ": ", formatValue(averageValue)]
|
|
202
|
+
: undefined
|
|
203
|
+
}
|
|
204
|
+
>
|
|
205
|
+
<div
|
|
206
|
+
className="w-full max-w-12 rounded-t-md shadow-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
|
207
|
+
style={{
|
|
208
|
+
height: `${percent}%`,
|
|
209
|
+
backgroundColor: getChartColor(item.color, index),
|
|
210
|
+
}}
|
|
211
|
+
tabIndex={0}
|
|
212
|
+
aria-label={`${chartLabelToString(item.label)}: ${formatValue(item.value)}${
|
|
213
|
+
averageValue !== undefined
|
|
214
|
+
? ` (${averageText}: ${formatValue(averageValue)})`
|
|
215
|
+
: ""
|
|
216
|
+
}`}
|
|
217
|
+
/>
|
|
218
|
+
</ChartTooltip>
|
|
219
|
+
{showValues ? (
|
|
220
|
+
<span
|
|
221
|
+
className="absolute text-xs font-medium text-foreground"
|
|
222
|
+
style={{ bottom: `calc(${percent}% + 0.375rem)` }}
|
|
223
|
+
>
|
|
224
|
+
{formatValue(item.value)}
|
|
225
|
+
</span>
|
|
226
|
+
) : null}
|
|
227
|
+
</div>
|
|
228
|
+
)
|
|
229
|
+
})}
|
|
230
|
+
</div>
|
|
231
|
+
</div>
|
|
232
|
+
{showLabels ? (
|
|
233
|
+
<div className="grid pt-2 text-xs text-muted-foreground" style={{ gridTemplateColumns: `repeat(${data.length}, minmax(0, 1fr))` }}>
|
|
234
|
+
{data.map((item, index) => (
|
|
235
|
+
<span key={`${String(item.label)}-label-${index}`} className="min-w-0 truncate text-center">
|
|
236
|
+
{item.label}
|
|
237
|
+
</span>
|
|
238
|
+
))}
|
|
239
|
+
</div>
|
|
240
|
+
) : null}
|
|
241
|
+
</div>
|
|
242
|
+
)
|
|
243
|
+
}
|
|
244
|
+
)
|
|
245
|
+
BarChart.displayName = "BarChart"
|
|
246
|
+
|
|
247
|
+
export { BarChart }
|