@middag-io/react 0.45.0 → 0.45.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/docs/public/schemas/ai-contract-manifest.json +1820 -0
- package/docs/public/schemas/blocks.json +445 -0
- package/docs/public/schemas/components.json +166 -0
- package/docs/public/schemas/connectors.json +97 -0
- package/docs/public/schemas/fragment.json +2329 -0
- package/docs/public/schemas/manifest.json +119 -0
- package/docs/public/schemas/navigation.json +72 -0
- package/docs/public/schemas/page-contract.json +2329 -0
- package/docs/public/schemas/shared-props.json +118 -0
- package/docs/public/schemas/theme-defaults.json +253 -0
- package/docs/public/schemas/theme.json +401 -0
- package/package.json +109 -3
- package/src/assets/lottie/calendar/schedule-1.json +1 -0
- package/src/assets/lottie/calendar/schedule-2.json +1 -0
- package/src/assets/lottie/celebration/confetti-1.json +1 -0
- package/src/assets/lottie/celebration/confetti-2.json +1 -0
- package/src/assets/lottie/celebration/confetti-3.json +1 -0
- package/src/assets/lottie/cloud/cloud-1.json +1 -0
- package/src/assets/lottie/cloud/cloud-2.json +1 -0
- package/src/assets/lottie/connection/network-1.json +1 -0
- package/src/assets/lottie/connection/network-2.json +1 -0
- package/src/assets/lottie/connection/network-3.json +1 -0
- package/src/assets/lottie/dashboard/analytics-1.json +1 -0
- package/src/assets/lottie/dashboard/analytics-2.json +1 -0
- package/src/assets/lottie/dashboard/analytics-3.json +1 -0
- package/src/assets/lottie/email/mail-1.json +1 -0
- package/src/assets/lottie/email/mail-2.json +1 -0
- package/src/assets/lottie/email/mail-3.json +1 -0
- package/src/assets/lottie/empty-state/empty-1.json +1 -0
- package/src/assets/lottie/empty-state/empty-2.json +1 -0
- package/src/assets/lottie/empty-state/empty-3.json +1 -0
- package/src/assets/lottie/error/warning-1.json +1 -0
- package/src/assets/lottie/error/warning-2.json +1 -0
- package/src/assets/lottie/error/warning-3.json +1 -0
- package/src/assets/lottie/index.ts +49 -0
- package/src/assets/lottie/loading/spinner-1.json +1 -0
- package/src/assets/lottie/loading/spinner-2.json +1 -0
- package/src/assets/lottie/loading/spinner-3.json +1 -0
- package/src/assets/lottie/maintenance/construction-1.json +1 -0
- package/src/assets/lottie/maintenance/construction-2.json +1 -0
- package/src/assets/lottie/maintenance/construction-3.json +1 -0
- package/src/assets/lottie/not-found/404-1.json +1 -0
- package/src/assets/lottie/not-found/404-2.json +1 -0
- package/src/assets/lottie/not-found/404-3.json +1 -0
- package/src/assets/lottie/notification/bell-1.json +1 -0
- package/src/assets/lottie/notification/bell-2.json +1 -0
- package/src/assets/lottie/notification/bell-3.json +1 -0
- package/src/assets/lottie/onboarding/welcome-1.json +1 -0
- package/src/assets/lottie/onboarding/welcome-2.json +1 -0
- package/src/assets/lottie/onboarding/welcome-3.json +1 -0
- package/src/assets/lottie/payment/wallet-1.json +1 -0
- package/src/assets/lottie/payment/wallet-2.json +1 -0
- package/src/assets/lottie/payment/wallet-3.json +1 -0
- package/src/assets/lottie/search/search-1.json +1 -0
- package/src/assets/lottie/search/search-2.json +1 -0
- package/src/assets/lottie/search/search-3.json +1 -0
- package/src/assets/lottie/security/lock-1.json +1 -0
- package/src/assets/lottie/security/lock-2.json +1 -0
- package/src/assets/lottie/security/lock-3.json +1 -0
- package/src/assets/lottie/settings/gear-1.json +1 -0
- package/src/assets/lottie/settings/gear-2.json +1 -0
- package/src/assets/lottie/settings/gear-3.json +1 -0
- package/src/assets/lottie/success/check-1.json +1 -0
- package/src/assets/lottie/success/check-2.json +1 -0
- package/src/assets/lottie/success/check-3.json +1 -0
- package/src/assets/lottie/upload/upload-1.json +1 -0
- package/src/assets/lottie/upload/upload-2.json +1 -0
- package/src/assets/lottie/upload/upload-3.json +1 -0
- package/src/assets/lottie/user/profile-1.json +1 -0
- package/src/assets/lottie/user/profile-2.json +1 -0
- package/src/assets/lottie/user/profile-3.json +1 -0
- package/src/base/blocks/ActionGridBlock.tsx +151 -0
- package/src/base/blocks/ActivityTimelineBlock.tsx +180 -0
- package/src/base/blocks/CardGridBlock.tsx +384 -0
- package/src/base/blocks/ChartBlock.tsx +81 -0
- package/src/base/blocks/DenseTableBlock.tsx +403 -0
- package/src/base/blocks/DetailPanelBlock.tsx +189 -0
- package/src/base/blocks/EmptyStateBlock.tsx +46 -0
- package/src/base/blocks/FormPanelBlock.lazy.tsx +38 -0
- package/src/base/blocks/FormPanelBlock.tsx +480 -0
- package/src/base/blocks/LinkListBlock.tsx +94 -0
- package/src/base/blocks/MarkdownPanelBlock.tsx +60 -0
- package/src/base/blocks/MetricCardBlock.tsx +128 -0
- package/src/base/blocks/StatusStripBlock.tsx +43 -0
- package/src/base/blocks/TabsBlock.tsx +94 -0
- package/src/base/form/FormField.tsx +607 -0
- package/src/base/form/fields/CheckboxField.tsx +56 -0
- package/src/base/form/fields/ColorField.tsx +76 -0
- package/src/base/form/fields/CurrencyField.tsx +126 -0
- package/src/base/form/fields/DateField.tsx +168 -0
- package/src/base/form/fields/DateRangeField.tsx +66 -0
- package/src/base/form/fields/DocumentField.tsx +222 -0
- package/src/base/form/fields/EntityPickerField.tsx +244 -0
- package/src/base/form/fields/FileUploadField.tsx +253 -0
- package/src/base/form/fields/MultiSelectField.tsx +286 -0
- package/src/base/form/fields/NativeSelectField.tsx +67 -0
- package/src/base/form/fields/NumberField.tsx +67 -0
- package/src/base/form/fields/OtpField.tsx +88 -0
- package/src/base/form/fields/PasswordField.tsx +69 -0
- package/src/base/form/fields/PhoneField.tsx +64 -0
- package/src/base/form/fields/RadioField.tsx +66 -0
- package/src/base/form/fields/RatingField.tsx +52 -0
- package/src/base/form/fields/SelectField.tsx +76 -0
- package/src/base/form/fields/SliderField.tsx +77 -0
- package/src/base/form/fields/SlugField.tsx +114 -0
- package/src/base/form/fields/StaticField.tsx +25 -0
- package/src/base/form/fields/SwitchField.tsx +56 -0
- package/src/base/form/fields/TagsField.tsx +128 -0
- package/src/base/form/fields/TextField.tsx +55 -0
- package/src/base/form/fields/TextareaField.tsx +55 -0
- package/src/base/form/fields/document-validation.ts +126 -0
- package/src/base/form/fields/field-registry.ts +53 -0
- package/src/base/form/fields/register-default-fields.ts +86 -0
- package/src/base/form/form-schema-builder.ts +192 -0
- package/src/base/form/form-utils.ts +71 -0
- package/src/base/hooks/useIsDark.ts +50 -0
- package/src/base/hooks/useLazyTabs.ts +98 -0
- package/src/base/hooks/usePolling.ts +43 -0
- package/src/base/hooks/useRemember.ts +58 -0
- package/src/base/hooks/useToast.ts +27 -0
- package/src/base/layout/BlockRegion.tsx +39 -0
- package/src/base/layout/DashboardLayout.tsx +110 -0
- package/src/base/layout/SidebarLayout.tsx +38 -0
- package/src/base/layout/StackLayout.tsx +32 -0
- package/src/base/layout/WizardLayout.tsx +49 -0
- package/src/base/partials/ActionBar/index.tsx +115 -0
- package/src/base/partials/ConfirmationDialog/index.tsx +128 -0
- package/src/base/partials/DataTable/cell-registry.ts +50 -0
- package/src/base/partials/DataTable/cell-renderers.tsx +372 -0
- package/src/base/partials/DataTable/index.tsx +1282 -0
- package/src/base/partials/DataTable/register-default-cells.ts +37 -0
- package/src/base/partials/DataTable/sanitize-html.ts +45 -0
- package/src/base/partials/DataTable/types.ts +229 -0
- package/src/base/partials/DetailSection/index.tsx +316 -0
- package/src/base/partials/EmptyPlaceholder/index.tsx +162 -0
- package/src/base/partials/EntityItem/index.tsx +154 -0
- package/src/base/partials/FilterBar/index.tsx +256 -0
- package/src/base/partials/FormSection/index.tsx +87 -0
- package/src/base/partials/LogViewer/JsonBlock.tsx +39 -0
- package/src/base/partials/LogViewer/LogEntry.tsx +68 -0
- package/src/base/partials/LogViewer/LogViewerToolbar.tsx +71 -0
- package/src/base/partials/LogViewer/index.tsx +110 -0
- package/src/base/partials/LogViewer/types.ts +28 -0
- package/src/base/partials/MarkdownContent/index.tsx +307 -0
- package/src/base/partials/MenuBar/index.tsx +80 -0
- package/src/base/partials/QuickRecordSheet/index.tsx +59 -0
- package/src/base/partials/ResizableSidebar/index.tsx +70 -0
- package/src/base/partials/StatRow/index.tsx +28 -0
- package/src/base/partials/StatusBar/index.tsx +126 -0
- package/src/base/partials/StatusIndicator/index.tsx +61 -0
- package/src/base/partials/StepIndicator/index.tsx +63 -0
- package/src/base/partials/TableOfContents/index.tsx +78 -0
- package/src/base/partials/TimelineList/index.tsx +273 -0
- package/src/base/partials/ToggleGroupControl/index.tsx +100 -0
- package/src/base/partials/TreeView/index.tsx +75 -0
- package/src/base/partials/index.ts +23 -0
- package/src/base/shell/AuthShell.tsx +54 -0
- package/src/base/shell/BasicShell.tsx +286 -0
- package/src/base/shell/ImmersiveShell.tsx +85 -0
- package/src/base/shell/partials/EditablePanelContext.tsx +82 -0
- package/src/base/shell/partials/EditablePanelProvider.tsx +122 -0
- package/src/base/shell/partials/InlineEditablePanel.tsx +239 -0
- package/src/base/shell/partials/InspectorContext.tsx +173 -0
- package/src/base/shell/partials/InspectorPanel.tsx +65 -0
- package/src/base/shell/partials/NavErrorBoundary.tsx +82 -0
- package/src/base/shell/partials/OverlayScreen.tsx +67 -0
- package/src/base/shell/partials/PageActionButton.tsx +203 -0
- package/src/base/theme/appearance.ts +133 -0
- package/src/base/theme/host-layout-detector.ts +119 -0
- package/src/base/theme/host-theme-detector.ts +146 -0
- package/src/base/theme/sidebar-safelist.txt +20 -0
- package/src/base/theme/tailwind-theme.css +136 -0
- package/src/base/theme/theme-bridge.css +164 -0
- package/src/base/theme/theme-context.tsx +142 -0
- package/src/base/theme/themes/classic.css +174 -0
- package/src/base/theme/tokens.css +290 -0
- package/src/base/theme/useHostTheme.ts +95 -0
- package/src/base/utils/clipboard.ts +39 -0
- package/src/base/utils/conditions.ts +27 -0
- package/src/base/utils/icon-registry.ts +78 -0
- package/src/base/utils/icons.ts +31 -0
- package/src/base/utils/interpolate.ts +9 -0
- package/src/base/utils/register-default-icons.ts +163 -0
- package/src/base/utils/storage.ts +65 -0
- package/src/base/utils/time.ts +139 -0
- package/src/contracts/block-data/actions.ts +73 -0
- package/src/contracts/block-data/data-display.ts +343 -0
- package/src/contracts/block-data/form.ts +164 -0
- package/src/contracts/block-data/index.ts +15 -0
- package/src/contracts/block-data/interactive.ts +34 -0
- package/src/contracts/block-data/shared.ts +44 -0
- package/src/contracts/connectors.ts +60 -0
- package/src/contracts/generated/contract-schema.ts +1237 -0
- package/src/contracts/generated/contract-types.ts +675 -0
- package/src/contracts/generated/index.ts +15 -0
- package/src/contracts/navigation.ts +59 -0
- package/src/contracts/page-contract-schema.ts +40 -0
- package/src/contracts/page-contract.ts +79 -0
- package/src/contracts/shared-props.ts +92 -0
- package/src/engine/ContractPage.tsx +178 -0
- package/src/engine/EntityRoutes.tsx +72 -0
- package/src/engine/HostSlot.tsx +126 -0
- package/src/engine/LazyBlock.tsx +92 -0
- package/src/engine/bootstrap.tsx +20 -0
- package/src/engine/providers/auth.tsx +87 -0
- package/src/engine/providers/error-reporter.tsx +89 -0
- package/src/engine/providers/flash.tsx +44 -0
- package/src/engine/providers/index.ts +18 -0
- package/src/engine/providers/inertia-error-reporter.tsx +61 -0
- package/src/engine/providers/progress.tsx +56 -0
- package/src/engine/providers/scope.tsx +51 -0
- package/src/engine/register-defaults.ts +88 -0
- package/src/engine/registries.ts +96 -0
- package/src/i18n/I18nProvider.tsx +53 -0
- package/src/i18n/MANIFEST.md +101 -0
- package/src/i18n/host-resolver.ts +18 -0
- package/src/i18n/instance.ts +69 -0
- package/src/i18n/locales/en/ui.json +277 -0
- package/src/i18n/locales/en/validators.json +13 -0
- package/src/i18n/locales/pt-BR/ui.json +277 -0
- package/src/i18n/locales/pt-BR/validators.json +13 -0
- package/src/i18n/register-strings.ts +10 -0
- package/src/i18n/render-label.ts +33 -0
- package/src/i18n/resolve-field-error.ts +29 -0
- package/src/i18n/useHostString.ts +50 -0
- package/src/i18n/useTranslation.ts +83 -0
- package/src/lib/actions/resolve-action-target.ts +151 -0
- package/src/lib/hooks/use-copy-to-clipboard.ts +37 -0
- package/src/lib/hooks/use-file-upload.ts +406 -0
- package/src/lib/hooks/use-mobile.ts +21 -0
- package/src/lib/host-pending.ts +76 -0
- package/src/lib/portal-container.ts +16 -0
- package/src/lib/test-ids.ts +40 -0
- package/src/lib/utils.ts +6 -0
- package/src/primitives/reui/MANIFEST.md +97 -0
- package/src/primitives/reui/accordion.tsx +64 -0
- package/src/primitives/reui/alert-dialog.tsx +196 -0
- package/src/primitives/reui/alert.tsx +92 -0
- package/src/primitives/reui/aspect-ratio.tsx +9 -0
- package/src/primitives/reui/autocomplete.tsx +343 -0
- package/src/primitives/reui/avatar.tsx +109 -0
- package/src/primitives/reui/badge.tsx +94 -0
- package/src/primitives/reui/breadcrumb.tsx +109 -0
- package/src/primitives/reui/button-group.tsx +83 -0
- package/src/primitives/reui/button.tsx +64 -0
- package/src/primitives/reui/calendar.tsx +220 -0
- package/src/primitives/reui/card.tsx +92 -0
- package/src/primitives/reui/carousel.tsx +239 -0
- package/src/primitives/reui/chart.tsx +388 -0
- package/src/primitives/reui/checkbox.tsx +30 -0
- package/src/primitives/reui/collapsible.tsx +31 -0
- package/src/primitives/reui/combobox.tsx +308 -0
- package/src/primitives/reui/command.tsx +182 -0
- package/src/primitives/reui/context-menu.tsx +250 -0
- package/src/primitives/reui/data-grid/data-grid-column-filter.tsx +172 -0
- package/src/primitives/reui/data-grid/data-grid-column-header.tsx +420 -0
- package/src/primitives/reui/data-grid/data-grid-column-visibility.tsx +51 -0
- package/src/primitives/reui/data-grid/data-grid-pagination.tsx +235 -0
- package/src/primitives/reui/data-grid/data-grid-scroll-area.tsx +427 -0
- package/src/primitives/reui/data-grid/data-grid-table-dnd-rows.tsx +308 -0
- package/src/primitives/reui/data-grid/data-grid-table-dnd.tsx +318 -0
- package/src/primitives/reui/data-grid/data-grid-table-virtual.tsx +491 -0
- package/src/primitives/reui/data-grid/data-grid-table.tsx +1430 -0
- package/src/primitives/reui/data-grid/data-grid.tsx +269 -0
- package/src/primitives/reui/data-grid-pagination.tsx +235 -0
- package/src/primitives/reui/date-selector.tsx +1353 -0
- package/src/primitives/reui/dialog.tsx +158 -0
- package/src/primitives/reui/drawer.tsx +133 -0
- package/src/primitives/reui/dropdown-menu.tsx +257 -0
- package/src/primitives/reui/empty.tsx +104 -0
- package/src/primitives/reui/field.tsx +246 -0
- package/src/primitives/reui/filters.tsx +1891 -0
- package/src/primitives/reui/frame.tsx +170 -0
- package/src/primitives/reui/hover-card.tsx +42 -0
- package/src/primitives/reui/icon-placeholder.tsx +39 -0
- package/src/primitives/reui/index.ts +98 -0
- package/src/primitives/reui/input-group.tsx +170 -0
- package/src/primitives/reui/input-otp.tsx +75 -0
- package/src/primitives/reui/input.tsx +21 -0
- package/src/primitives/reui/item.tsx +193 -0
- package/src/primitives/reui/kanban.tsx +743 -0
- package/src/primitives/reui/kbd.tsx +28 -0
- package/src/primitives/reui/label.tsx +22 -0
- package/src/primitives/reui/menubar.tsx +274 -0
- package/src/primitives/reui/native-select.tsx +62 -0
- package/src/primitives/reui/navigation-menu.tsx +168 -0
- package/src/primitives/reui/number-field.tsx +250 -0
- package/src/primitives/reui/pagination.tsx +127 -0
- package/src/primitives/reui/phone-input.tsx +231 -0
- package/src/primitives/reui/popover.tsx +87 -0
- package/src/primitives/reui/progress.tsx +31 -0
- package/src/primitives/reui/radio-group.tsx +43 -0
- package/src/primitives/reui/rating.tsx +177 -0
- package/src/primitives/reui/resizable.tsx +51 -0
- package/src/primitives/reui/scroll-area.tsx +58 -0
- package/src/primitives/reui/scrollspy.tsx +240 -0
- package/src/primitives/reui/select.tsx +188 -0
- package/src/primitives/reui/separator.tsx +28 -0
- package/src/primitives/reui/sheet.tsx +141 -0
- package/src/primitives/reui/sidebar.tsx +732 -0
- package/src/primitives/reui/skeleton.tsx +13 -0
- package/src/primitives/reui/slider.tsx +61 -0
- package/src/primitives/reui/sonner.tsx +47 -0
- package/src/primitives/reui/sortable.tsx +414 -0
- package/src/primitives/reui/spinner.tsx +16 -0
- package/src/primitives/reui/stepper.tsx +484 -0
- package/src/primitives/reui/svgs/claudeAiIcon.tsx +12 -0
- package/src/primitives/reui/svgs/gemini.tsx +171 -0
- package/src/primitives/reui/svgs/openai.tsx +9 -0
- package/src/primitives/reui/svgs/openaiDark.tsx +12 -0
- package/src/primitives/reui/switch.tsx +33 -0
- package/src/primitives/reui/table.tsx +114 -0
- package/src/primitives/reui/tabs.tsx +91 -0
- package/src/primitives/reui/textarea.tsx +18 -0
- package/src/primitives/reui/timeline.tsx +219 -0
- package/src/primitives/reui/toggle-group.tsx +83 -0
- package/src/primitives/reui/toggle.tsx +45 -0
- package/src/primitives/reui/tooltip.tsx +55 -0
- package/src/primitives/reui/tree.tsx +247 -0
- package/src/theme.css +71 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { cn } from "@/lib/utils";
|
|
4
|
+
|
|
5
|
+
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
|
6
|
+
return (
|
|
7
|
+
<div
|
|
8
|
+
data-slot="card"
|
|
9
|
+
className={cn(
|
|
10
|
+
"flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm",
|
|
11
|
+
className,
|
|
12
|
+
)}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
19
|
+
return (
|
|
20
|
+
<div
|
|
21
|
+
data-slot="card-header"
|
|
22
|
+
className={cn(
|
|
23
|
+
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
|
24
|
+
className,
|
|
25
|
+
)}
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
data-slot="card-title"
|
|
35
|
+
className={cn("leading-none font-semibold", className)}
|
|
36
|
+
{...props}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
|
42
|
+
return (
|
|
43
|
+
<div
|
|
44
|
+
data-slot="card-description"
|
|
45
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
46
|
+
{...props}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
|
52
|
+
return (
|
|
53
|
+
<div
|
|
54
|
+
data-slot="card-action"
|
|
55
|
+
className={cn(
|
|
56
|
+
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
|
57
|
+
className,
|
|
58
|
+
)}
|
|
59
|
+
{...props}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
65
|
+
return (
|
|
66
|
+
<div
|
|
67
|
+
data-slot="card-content"
|
|
68
|
+
className={cn("px-6", className)}
|
|
69
|
+
{...props}
|
|
70
|
+
/>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
75
|
+
return (
|
|
76
|
+
<div
|
|
77
|
+
data-slot="card-footer"
|
|
78
|
+
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
|
79
|
+
{...props}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
Card,
|
|
86
|
+
CardHeader,
|
|
87
|
+
CardFooter,
|
|
88
|
+
CardTitle,
|
|
89
|
+
CardAction,
|
|
90
|
+
CardDescription,
|
|
91
|
+
CardContent,
|
|
92
|
+
};
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import useEmblaCarousel, {
|
|
3
|
+
type UseEmblaCarouselType,
|
|
4
|
+
} from "embla-carousel-react";
|
|
5
|
+
import { ArrowLeft, ArrowRight } from "lucide-react";
|
|
6
|
+
|
|
7
|
+
import { cn } from "@/lib/utils";
|
|
8
|
+
import { Button } from "@/primitives/reui/button";
|
|
9
|
+
|
|
10
|
+
type CarouselApi = UseEmblaCarouselType[1];
|
|
11
|
+
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;
|
|
12
|
+
type CarouselOptions = UseCarouselParameters[0];
|
|
13
|
+
type CarouselPlugin = UseCarouselParameters[1];
|
|
14
|
+
|
|
15
|
+
type CarouselProps = {
|
|
16
|
+
opts?: CarouselOptions;
|
|
17
|
+
plugins?: CarouselPlugin;
|
|
18
|
+
orientation?: "horizontal" | "vertical";
|
|
19
|
+
setApi?: (api: CarouselApi) => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type CarouselContextProps = {
|
|
23
|
+
carouselRef: ReturnType<typeof useEmblaCarousel>[0];
|
|
24
|
+
api: ReturnType<typeof useEmblaCarousel>[1];
|
|
25
|
+
scrollPrev: () => void;
|
|
26
|
+
scrollNext: () => void;
|
|
27
|
+
canScrollPrev: boolean;
|
|
28
|
+
canScrollNext: boolean;
|
|
29
|
+
} & CarouselProps;
|
|
30
|
+
|
|
31
|
+
const CarouselContext = React.createContext<CarouselContextProps | null>(null);
|
|
32
|
+
|
|
33
|
+
function useCarousel() {
|
|
34
|
+
const context = React.useContext(CarouselContext);
|
|
35
|
+
|
|
36
|
+
if (!context) {
|
|
37
|
+
throw new Error("useCarousel must be used within a <Carousel />");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return context;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function Carousel({
|
|
44
|
+
orientation = "horizontal",
|
|
45
|
+
opts,
|
|
46
|
+
setApi,
|
|
47
|
+
plugins,
|
|
48
|
+
className,
|
|
49
|
+
children,
|
|
50
|
+
...props
|
|
51
|
+
}: React.ComponentProps<"div"> & CarouselProps) {
|
|
52
|
+
const [carouselRef, api] = useEmblaCarousel(
|
|
53
|
+
{
|
|
54
|
+
...opts,
|
|
55
|
+
axis: orientation === "horizontal" ? "x" : "y",
|
|
56
|
+
},
|
|
57
|
+
plugins,
|
|
58
|
+
);
|
|
59
|
+
const [canScrollPrev, setCanScrollPrev] = React.useState(false);
|
|
60
|
+
const [canScrollNext, setCanScrollNext] = React.useState(false);
|
|
61
|
+
|
|
62
|
+
const onSelect = React.useCallback((api: CarouselApi) => {
|
|
63
|
+
if (!api) return;
|
|
64
|
+
setCanScrollPrev(api.canScrollPrev());
|
|
65
|
+
setCanScrollNext(api.canScrollNext());
|
|
66
|
+
}, []);
|
|
67
|
+
|
|
68
|
+
const scrollPrev = React.useCallback(() => {
|
|
69
|
+
api?.scrollPrev();
|
|
70
|
+
}, [api]);
|
|
71
|
+
|
|
72
|
+
const scrollNext = React.useCallback(() => {
|
|
73
|
+
api?.scrollNext();
|
|
74
|
+
}, [api]);
|
|
75
|
+
|
|
76
|
+
const handleKeyDown = React.useCallback(
|
|
77
|
+
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
78
|
+
if (event.key === "ArrowLeft") {
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
scrollPrev();
|
|
81
|
+
} else if (event.key === "ArrowRight") {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
scrollNext();
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
[scrollPrev, scrollNext],
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
React.useEffect(() => {
|
|
90
|
+
if (!api || !setApi) return;
|
|
91
|
+
setApi(api);
|
|
92
|
+
}, [api, setApi]);
|
|
93
|
+
|
|
94
|
+
React.useEffect(() => {
|
|
95
|
+
if (!api) return;
|
|
96
|
+
onSelect(api);
|
|
97
|
+
api.on("reInit", onSelect);
|
|
98
|
+
api.on("select", onSelect);
|
|
99
|
+
|
|
100
|
+
return () => {
|
|
101
|
+
api?.off("select", onSelect);
|
|
102
|
+
};
|
|
103
|
+
}, [api, onSelect]);
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<CarouselContext.Provider
|
|
107
|
+
value={{
|
|
108
|
+
carouselRef,
|
|
109
|
+
api: api,
|
|
110
|
+
opts,
|
|
111
|
+
orientation:
|
|
112
|
+
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
|
113
|
+
scrollPrev,
|
|
114
|
+
scrollNext,
|
|
115
|
+
canScrollPrev,
|
|
116
|
+
canScrollNext,
|
|
117
|
+
}}
|
|
118
|
+
>
|
|
119
|
+
<div
|
|
120
|
+
onKeyDownCapture={handleKeyDown}
|
|
121
|
+
className={cn("relative", className)}
|
|
122
|
+
role="region"
|
|
123
|
+
aria-roledescription="carousel"
|
|
124
|
+
data-slot="carousel"
|
|
125
|
+
{...props}
|
|
126
|
+
>
|
|
127
|
+
{children}
|
|
128
|
+
</div>
|
|
129
|
+
</CarouselContext.Provider>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function CarouselContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
134
|
+
const { carouselRef, orientation } = useCarousel();
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<div
|
|
138
|
+
ref={carouselRef}
|
|
139
|
+
className="overflow-hidden"
|
|
140
|
+
data-slot="carousel-content"
|
|
141
|
+
>
|
|
142
|
+
<div
|
|
143
|
+
className={cn(
|
|
144
|
+
"flex",
|
|
145
|
+
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
|
|
146
|
+
className,
|
|
147
|
+
)}
|
|
148
|
+
{...props}
|
|
149
|
+
/>
|
|
150
|
+
</div>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
|
|
155
|
+
const { orientation } = useCarousel();
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<div
|
|
159
|
+
role="group"
|
|
160
|
+
aria-roledescription="slide"
|
|
161
|
+
data-slot="carousel-item"
|
|
162
|
+
className={cn(
|
|
163
|
+
"min-w-0 shrink-0 grow-0 basis-full",
|
|
164
|
+
orientation === "horizontal" ? "pl-4" : "pt-4",
|
|
165
|
+
className,
|
|
166
|
+
)}
|
|
167
|
+
{...props}
|
|
168
|
+
/>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function CarouselPrevious({
|
|
173
|
+
className,
|
|
174
|
+
variant = "outline",
|
|
175
|
+
size = "icon",
|
|
176
|
+
...props
|
|
177
|
+
}: React.ComponentProps<typeof Button>) {
|
|
178
|
+
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<Button
|
|
182
|
+
data-slot="carousel-previous"
|
|
183
|
+
variant={variant}
|
|
184
|
+
size={size}
|
|
185
|
+
className={cn(
|
|
186
|
+
"absolute size-8 rounded-full",
|
|
187
|
+
orientation === "horizontal"
|
|
188
|
+
? "top-1/2 -left-12 -translate-y-1/2"
|
|
189
|
+
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
190
|
+
className,
|
|
191
|
+
)}
|
|
192
|
+
disabled={!canScrollPrev}
|
|
193
|
+
onClick={scrollPrev}
|
|
194
|
+
{...props}
|
|
195
|
+
>
|
|
196
|
+
<ArrowLeft />
|
|
197
|
+
<span className="sr-only">Previous slide</span>
|
|
198
|
+
</Button>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function CarouselNext({
|
|
203
|
+
className,
|
|
204
|
+
variant = "outline",
|
|
205
|
+
size = "icon",
|
|
206
|
+
...props
|
|
207
|
+
}: React.ComponentProps<typeof Button>) {
|
|
208
|
+
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
<Button
|
|
212
|
+
data-slot="carousel-next"
|
|
213
|
+
variant={variant}
|
|
214
|
+
size={size}
|
|
215
|
+
className={cn(
|
|
216
|
+
"absolute size-8 rounded-full",
|
|
217
|
+
orientation === "horizontal"
|
|
218
|
+
? "top-1/2 -right-12 -translate-y-1/2"
|
|
219
|
+
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
220
|
+
className,
|
|
221
|
+
)}
|
|
222
|
+
disabled={!canScrollNext}
|
|
223
|
+
onClick={scrollNext}
|
|
224
|
+
{...props}
|
|
225
|
+
>
|
|
226
|
+
<ArrowRight />
|
|
227
|
+
<span className="sr-only">Next slide</span>
|
|
228
|
+
</Button>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export {
|
|
233
|
+
type CarouselApi,
|
|
234
|
+
Carousel,
|
|
235
|
+
CarouselContent,
|
|
236
|
+
CarouselItem,
|
|
237
|
+
CarouselPrevious,
|
|
238
|
+
CarouselNext,
|
|
239
|
+
};
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as RechartsPrimitive from "recharts";
|
|
3
|
+
import type { TooltipValueType } from "recharts";
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils";
|
|
6
|
+
|
|
7
|
+
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
8
|
+
const THEMES = { light: "", dark: ".dark" } as const;
|
|
9
|
+
|
|
10
|
+
const INITIAL_DIMENSION = { width: 320, height: 200 } as const;
|
|
11
|
+
|
|
12
|
+
// ChartStyle interpolates config keys, colours and the chart id into a
|
|
13
|
+
// <style> element. Keys and ids are limited to identifier characters, and a
|
|
14
|
+
// colour that could end the declaration, the rule or the element is dropped.
|
|
15
|
+
const SAFE_CSS_IDENT = /^[\w-]+$/;
|
|
16
|
+
const UNSAFE_CSS_VALUE = /[;{}<>\\]/;
|
|
17
|
+
|
|
18
|
+
function isSafeCssColor(color: string): boolean {
|
|
19
|
+
return color.trim() !== "" && !UNSAFE_CSS_VALUE.test(color);
|
|
20
|
+
}
|
|
21
|
+
type TooltipNameType = number | string;
|
|
22
|
+
|
|
23
|
+
export type ChartConfig = Record<
|
|
24
|
+
string,
|
|
25
|
+
{
|
|
26
|
+
label?: React.ReactNode;
|
|
27
|
+
icon?: React.ComponentType;
|
|
28
|
+
} & (
|
|
29
|
+
| { color?: string; theme?: never }
|
|
30
|
+
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
|
31
|
+
)
|
|
32
|
+
>;
|
|
33
|
+
|
|
34
|
+
type ChartContextProps = {
|
|
35
|
+
config: ChartConfig;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const ChartContext = React.createContext<ChartContextProps | null>(null);
|
|
39
|
+
|
|
40
|
+
function useChart() {
|
|
41
|
+
const context = React.useContext(ChartContext);
|
|
42
|
+
|
|
43
|
+
if (!context) {
|
|
44
|
+
throw new Error("useChart must be used within a <ChartContainer />");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return context;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function ChartContainer({
|
|
51
|
+
id,
|
|
52
|
+
className,
|
|
53
|
+
children,
|
|
54
|
+
config,
|
|
55
|
+
initialDimension = INITIAL_DIMENSION,
|
|
56
|
+
...props
|
|
57
|
+
}: React.ComponentProps<"div"> & {
|
|
58
|
+
config: ChartConfig;
|
|
59
|
+
children: React.ComponentProps<
|
|
60
|
+
typeof RechartsPrimitive.ResponsiveContainer
|
|
61
|
+
>["children"];
|
|
62
|
+
initialDimension?: {
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
};
|
|
66
|
+
}) {
|
|
67
|
+
const uniqueId = React.useId();
|
|
68
|
+
const chartId = `chart-${(id ?? uniqueId).replace(/[^\w-]/g, "")}`;
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<ChartContext.Provider value={{ config }}>
|
|
72
|
+
<div
|
|
73
|
+
data-slot="chart"
|
|
74
|
+
data-chart={chartId}
|
|
75
|
+
className={cn(
|
|
76
|
+
"flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
|
|
77
|
+
className,
|
|
78
|
+
)}
|
|
79
|
+
{...props}
|
|
80
|
+
>
|
|
81
|
+
<ChartStyle id={chartId} config={config} />
|
|
82
|
+
<RechartsPrimitive.ResponsiveContainer
|
|
83
|
+
initialDimension={initialDimension}
|
|
84
|
+
>
|
|
85
|
+
{children}
|
|
86
|
+
</RechartsPrimitive.ResponsiveContainer>
|
|
87
|
+
</div>
|
|
88
|
+
</ChartContext.Provider>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
|
93
|
+
const colorConfig = Object.entries(config).filter(
|
|
94
|
+
([key, config]) =>
|
|
95
|
+
SAFE_CSS_IDENT.test(key) &&
|
|
96
|
+
[config.color, ...Object.values(config.theme ?? {})].some(
|
|
97
|
+
(color) => color != null && isSafeCssColor(color),
|
|
98
|
+
),
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
if (!colorConfig.length) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<style
|
|
107
|
+
dangerouslySetInnerHTML={{
|
|
108
|
+
__html: Object.entries(THEMES)
|
|
109
|
+
.map(
|
|
110
|
+
([theme, prefix]) => `
|
|
111
|
+
${prefix} [data-chart=${id}] {
|
|
112
|
+
${colorConfig
|
|
113
|
+
.map(([key, itemConfig]) => {
|
|
114
|
+
const color =
|
|
115
|
+
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ??
|
|
116
|
+
itemConfig.color;
|
|
117
|
+
return color && isSafeCssColor(color)
|
|
118
|
+
? ` --color-${key}: ${color};`
|
|
119
|
+
: null;
|
|
120
|
+
})
|
|
121
|
+
.join("\n")}
|
|
122
|
+
}
|
|
123
|
+
`,
|
|
124
|
+
)
|
|
125
|
+
.join("\n"),
|
|
126
|
+
}}
|
|
127
|
+
/>
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const ChartTooltip = RechartsPrimitive.Tooltip;
|
|
132
|
+
|
|
133
|
+
function ChartTooltipContent({
|
|
134
|
+
active,
|
|
135
|
+
payload,
|
|
136
|
+
className,
|
|
137
|
+
indicator = "dot",
|
|
138
|
+
hideLabel = false,
|
|
139
|
+
hideIndicator = false,
|
|
140
|
+
label,
|
|
141
|
+
labelFormatter,
|
|
142
|
+
labelClassName,
|
|
143
|
+
formatter,
|
|
144
|
+
color,
|
|
145
|
+
nameKey,
|
|
146
|
+
labelKey,
|
|
147
|
+
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
|
|
148
|
+
React.ComponentProps<"div"> & {
|
|
149
|
+
hideLabel?: boolean;
|
|
150
|
+
hideIndicator?: boolean;
|
|
151
|
+
indicator?: "line" | "dot" | "dashed";
|
|
152
|
+
nameKey?: string;
|
|
153
|
+
labelKey?: string;
|
|
154
|
+
} & Omit<
|
|
155
|
+
RechartsPrimitive.DefaultTooltipContentProps<
|
|
156
|
+
TooltipValueType,
|
|
157
|
+
TooltipNameType
|
|
158
|
+
>,
|
|
159
|
+
"accessibilityLayer"
|
|
160
|
+
>) {
|
|
161
|
+
const { config } = useChart();
|
|
162
|
+
|
|
163
|
+
const tooltipLabel = React.useMemo(() => {
|
|
164
|
+
if (hideLabel || !payload?.length) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const [item] = payload;
|
|
169
|
+
const key = `${labelKey ?? item?.dataKey ?? item?.name ?? "value"}`;
|
|
170
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
171
|
+
const value =
|
|
172
|
+
!labelKey && typeof label === "string"
|
|
173
|
+
? (config[label]?.label ?? label)
|
|
174
|
+
: itemConfig?.label;
|
|
175
|
+
|
|
176
|
+
if (labelFormatter) {
|
|
177
|
+
return (
|
|
178
|
+
<div className={cn("font-medium", labelClassName)}>
|
|
179
|
+
{labelFormatter(value, payload)}
|
|
180
|
+
</div>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (!value) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return <div className={cn("font-medium", labelClassName)}>{value}</div>;
|
|
189
|
+
}, [
|
|
190
|
+
label,
|
|
191
|
+
labelFormatter,
|
|
192
|
+
payload,
|
|
193
|
+
hideLabel,
|
|
194
|
+
labelClassName,
|
|
195
|
+
config,
|
|
196
|
+
labelKey,
|
|
197
|
+
]);
|
|
198
|
+
|
|
199
|
+
if (!active || !payload?.length) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const nestLabel = payload.length === 1 && indicator !== "dot";
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<div
|
|
207
|
+
className={cn(
|
|
208
|
+
"grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",
|
|
209
|
+
className,
|
|
210
|
+
)}
|
|
211
|
+
>
|
|
212
|
+
{!nestLabel ? tooltipLabel : null}
|
|
213
|
+
<div className="grid gap-1.5">
|
|
214
|
+
{payload
|
|
215
|
+
.filter((item) => item.type !== "none")
|
|
216
|
+
.map((item, index) => {
|
|
217
|
+
const key = `${nameKey ?? item.name ?? item.dataKey ?? "value"}`;
|
|
218
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
219
|
+
const indicatorColor = color ?? item.payload?.fill ?? item.color;
|
|
220
|
+
|
|
221
|
+
return (
|
|
222
|
+
<div
|
|
223
|
+
key={index}
|
|
224
|
+
className={cn(
|
|
225
|
+
"flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",
|
|
226
|
+
indicator === "dot" && "items-center",
|
|
227
|
+
)}
|
|
228
|
+
>
|
|
229
|
+
{formatter && item?.value !== undefined && item.name ? (
|
|
230
|
+
formatter(item.value, item.name, item, index, item.payload)
|
|
231
|
+
) : (
|
|
232
|
+
<>
|
|
233
|
+
{itemConfig?.icon ? (
|
|
234
|
+
<itemConfig.icon />
|
|
235
|
+
) : (
|
|
236
|
+
!hideIndicator && (
|
|
237
|
+
<div
|
|
238
|
+
className={cn(
|
|
239
|
+
"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
|
|
240
|
+
{
|
|
241
|
+
"h-2.5 w-2.5": indicator === "dot",
|
|
242
|
+
"w-1": indicator === "line",
|
|
243
|
+
"w-0 border-[1.5px] border-dashed bg-transparent":
|
|
244
|
+
indicator === "dashed",
|
|
245
|
+
"my-0.5": nestLabel && indicator === "dashed",
|
|
246
|
+
},
|
|
247
|
+
)}
|
|
248
|
+
style={
|
|
249
|
+
{
|
|
250
|
+
"--color-bg": indicatorColor,
|
|
251
|
+
"--color-border": indicatorColor,
|
|
252
|
+
} as React.CSSProperties
|
|
253
|
+
}
|
|
254
|
+
/>
|
|
255
|
+
)
|
|
256
|
+
)}
|
|
257
|
+
<div
|
|
258
|
+
className={cn(
|
|
259
|
+
"flex flex-1 justify-between leading-none",
|
|
260
|
+
nestLabel ? "items-end" : "items-center",
|
|
261
|
+
)}
|
|
262
|
+
>
|
|
263
|
+
<div className="grid gap-1.5">
|
|
264
|
+
{nestLabel ? tooltipLabel : null}
|
|
265
|
+
<span className="text-muted-foreground">
|
|
266
|
+
{itemConfig?.label ?? item.name}
|
|
267
|
+
</span>
|
|
268
|
+
</div>
|
|
269
|
+
{item.value != null && (
|
|
270
|
+
<span className="font-mono font-medium text-foreground tabular-nums">
|
|
271
|
+
{typeof item.value === "number"
|
|
272
|
+
? item.value.toLocaleString()
|
|
273
|
+
: String(item.value)}
|
|
274
|
+
</span>
|
|
275
|
+
)}
|
|
276
|
+
</div>
|
|
277
|
+
</>
|
|
278
|
+
)}
|
|
279
|
+
</div>
|
|
280
|
+
);
|
|
281
|
+
})}
|
|
282
|
+
</div>
|
|
283
|
+
</div>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const ChartLegend = RechartsPrimitive.Legend;
|
|
288
|
+
|
|
289
|
+
function ChartLegendContent({
|
|
290
|
+
className,
|
|
291
|
+
hideIcon = false,
|
|
292
|
+
payload,
|
|
293
|
+
verticalAlign = "bottom",
|
|
294
|
+
nameKey,
|
|
295
|
+
}: React.ComponentProps<"div"> & {
|
|
296
|
+
hideIcon?: boolean;
|
|
297
|
+
nameKey?: string;
|
|
298
|
+
} & RechartsPrimitive.DefaultLegendContentProps) {
|
|
299
|
+
const { config } = useChart();
|
|
300
|
+
|
|
301
|
+
if (!payload?.length) {
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return (
|
|
306
|
+
<div
|
|
307
|
+
className={cn(
|
|
308
|
+
"flex items-center justify-center gap-4",
|
|
309
|
+
verticalAlign === "top" ? "pb-3" : "pt-3",
|
|
310
|
+
className,
|
|
311
|
+
)}
|
|
312
|
+
>
|
|
313
|
+
{payload
|
|
314
|
+
.filter((item) => item.type !== "none")
|
|
315
|
+
.map((item, index) => {
|
|
316
|
+
const key = `${nameKey ?? item.dataKey ?? "value"}`;
|
|
317
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
318
|
+
|
|
319
|
+
return (
|
|
320
|
+
<div
|
|
321
|
+
key={index}
|
|
322
|
+
className={cn(
|
|
323
|
+
"flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground",
|
|
324
|
+
)}
|
|
325
|
+
>
|
|
326
|
+
{itemConfig?.icon && !hideIcon ? (
|
|
327
|
+
<itemConfig.icon />
|
|
328
|
+
) : (
|
|
329
|
+
<div
|
|
330
|
+
className="h-2 w-2 shrink-0 rounded-[2px]"
|
|
331
|
+
style={{
|
|
332
|
+
backgroundColor: item.color,
|
|
333
|
+
}}
|
|
334
|
+
/>
|
|
335
|
+
)}
|
|
336
|
+
{itemConfig?.label}
|
|
337
|
+
</div>
|
|
338
|
+
);
|
|
339
|
+
})}
|
|
340
|
+
</div>
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Helper to extract item config from a payload.
|
|
345
|
+
function getPayloadConfigFromPayload(
|
|
346
|
+
config: ChartConfig,
|
|
347
|
+
payload: unknown,
|
|
348
|
+
key: string,
|
|
349
|
+
) {
|
|
350
|
+
if (typeof payload !== "object" || payload === null) {
|
|
351
|
+
return undefined;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const payloadPayload =
|
|
355
|
+
"payload" in payload &&
|
|
356
|
+
typeof payload.payload === "object" &&
|
|
357
|
+
payload.payload !== null
|
|
358
|
+
? payload.payload
|
|
359
|
+
: undefined;
|
|
360
|
+
|
|
361
|
+
let configLabelKey: string = key;
|
|
362
|
+
|
|
363
|
+
if (
|
|
364
|
+
key in payload &&
|
|
365
|
+
typeof payload[key as keyof typeof payload] === "string"
|
|
366
|
+
) {
|
|
367
|
+
configLabelKey = payload[key as keyof typeof payload] as string;
|
|
368
|
+
} else if (
|
|
369
|
+
payloadPayload &&
|
|
370
|
+
key in payloadPayload &&
|
|
371
|
+
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
|
372
|
+
) {
|
|
373
|
+
configLabelKey = payloadPayload[
|
|
374
|
+
key as keyof typeof payloadPayload
|
|
375
|
+
] as string;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return configLabelKey in config ? config[configLabelKey] : config[key];
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export {
|
|
382
|
+
ChartContainer,
|
|
383
|
+
ChartTooltip,
|
|
384
|
+
ChartTooltipContent,
|
|
385
|
+
ChartLegend,
|
|
386
|
+
ChartLegendContent,
|
|
387
|
+
ChartStyle,
|
|
388
|
+
};
|