@goplusvn/core 0.1.0 → 0.1.1
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/package.json +2 -1
- package/src/assets/erp_wallpaper.png +0 -0
- package/src/assets/goeat_logo.png +0 -0
- package/src/audit/audit-manager.ts +139 -0
- package/src/audit/index.ts +11 -0
- package/src/audit/memory-audit-logger.ts +86 -0
- package/src/audit/types.ts +50 -0
- package/src/auth/auth-service.ts +97 -0
- package/src/auth/index.ts +266 -0
- package/src/code-generation/index.ts +69 -0
- package/src/configs/auth-routes.ts +17 -0
- package/src/configs/crud.ts +136 -0
- package/src/configs/data/navigations.ts +781 -0
- package/src/configs/data/oauth-links.ts +10 -0
- package/src/configs/entities/material-categories.config.ts +125 -0
- package/src/configs/i18n.ts +12 -0
- package/src/configs/index.ts +26 -0
- package/src/configs/status.ts +25 -0
- package/src/configs/themes.ts +100 -0
- package/src/crud/components/crud-bulk-actions.tsx +91 -0
- package/src/crud/components/crud-card-view.tsx +241 -0
- package/src/crud/components/crud-context.tsx +122 -0
- package/src/crud/components/crud-delete-dialog.tsx +145 -0
- package/src/crud/components/crud-dialog.tsx +406 -0
- package/src/crud/components/crud-empty-state.tsx +104 -0
- package/src/crud/components/crud-export-button.tsx +170 -0
- package/src/crud/components/crud-field-renderer.tsx +653 -0
- package/src/crud/components/crud-filter-chips.tsx +102 -0
- package/src/crud/components/crud-filters/checkbox-filter.tsx +97 -0
- package/src/crud/components/crud-filters/datetime-filter.tsx +83 -0
- package/src/crud/components/crud-filters/filter-builder.tsx +66 -0
- package/src/crud/components/crud-filters/index.tsx +76 -0
- package/src/crud/components/crud-filters/radio-filter.tsx +86 -0
- package/src/crud/components/crud-filters/select-filter.tsx +141 -0
- package/src/crud/components/crud-filters/text-filter.tsx +86 -0
- package/src/crud/components/crud-form.tsx +642 -0
- package/src/crud/components/crud-import-dialog.tsx +440 -0
- package/src/crud/components/crud-infinite-scroll.tsx +116 -0
- package/src/crud/components/crud-page.tsx +1017 -0
- package/src/crud/components/crud-provider.tsx +277 -0
- package/src/crud/components/crud-row-actions.tsx +189 -0
- package/src/crud/components/crud-search.tsx +82 -0
- package/src/crud/components/crud-sheet.tsx +336 -0
- package/src/crud/components/crud-table-skeleton.tsx +26 -0
- package/src/crud/components/crud-table-toolbar.tsx +91 -0
- package/src/crud/components/crud-table.tsx +352 -0
- package/src/crud/components/crud-virtual-table.tsx +55 -0
- package/src/crud/components/index.tsx +20 -0
- package/src/crud/crud-filters/checkbox-filter.tsx +87 -0
- package/src/crud/crud-filters/datetime-filter.tsx +82 -0
- package/src/crud/crud-filters/filter-builder.tsx +64 -0
- package/src/crud/crud-filters/index.tsx +78 -0
- package/src/crud/crud-filters/radio-filter.tsx +79 -0
- package/src/crud/crud-filters/select-filter.tsx +148 -0
- package/src/crud/crud-filters/text-filter.tsx +81 -0
- package/src/crud/index.ts +43 -0
- package/src/crud/lib/crud-service.test.ts +334 -0
- package/src/crud/lib/crud-service.ts +358 -0
- package/src/crud/lib/crud-utils.test.ts +354 -0
- package/src/crud/lib/crud-utils.ts +299 -0
- package/src/crud/lib/crud-validator.ts +247 -0
- package/src/crud/lib/data-loader.ts +234 -0
- package/src/crud/lib/field-calculator.ts +241 -0
- package/src/crud/lib/field-formatter.ts +240 -0
- package/src/crud/lib/import-export-service.test.ts +290 -0
- package/src/crud/lib/import-export-service.ts +352 -0
- package/src/crud/lib/import-server-utils.ts +109 -0
- package/src/crud/lib/lazy-loader.ts +241 -0
- package/src/crud/lib/parse-filters.ts +85 -0
- package/src/crud/lib/permissions.ts +52 -0
- package/src/crud/lib/serialize-config.ts +60 -0
- package/src/crud/lib/stream-loader.ts +145 -0
- package/src/crud/lib/translate-config.ts +335 -0
- package/src/crud/lib/types.ts +11 -0
- package/src/crud/pages/entity-crud-page.tsx +144 -0
- package/src/crud/server.ts +8 -0
- package/src/home/constants.tsx +142 -0
- package/src/home/feature-showcase.tsx +171 -0
- package/src/home/home-page.tsx +191 -0
- package/src/home/hooks/index.ts +1 -0
- package/src/home/hooks/useWidgetPreferences.ts +167 -0
- package/src/home/index.ts +33 -0
- package/src/home/quick-access-dialog.tsx +271 -0
- package/src/home/quick-access-menu.tsx +267 -0
- package/src/home/types.ts +140 -0
- package/src/home/welcome-card.tsx +92 -0
- package/src/home/widget-container.tsx +258 -0
- package/src/home/widgets/base-widget.tsx +200 -0
- package/src/home/widgets/customers-widget.tsx +74 -0
- package/src/home/widgets/index.ts +6 -0
- package/src/home/widgets/orders-widget.tsx +87 -0
- package/src/home/widgets/revenue-widget.tsx +71 -0
- package/src/home/widgets/stock-widget.tsx +109 -0
- package/src/hooks/index.tsx +598 -0
- package/src/hooks/use-tenant.test.tsx +30 -0
- package/src/hooks/use-tenant.ts +5 -0
- package/src/index.ts +17 -0
- package/src/infrastructure/__tests__/architecture-verification.spec.ts +103 -0
- package/src/infrastructure/api-service.ts +317 -0
- package/src/infrastructure/cache/cache-manager.ts +107 -0
- package/src/infrastructure/cache/cache.ts +120 -0
- package/src/infrastructure/cache/index.ts +8 -0
- package/src/infrastructure/cache/types.ts +48 -0
- package/src/infrastructure/cron/cron-manager.ts +239 -0
- package/src/infrastructure/cron/index.ts +6 -0
- package/src/infrastructure/cron/types.ts +41 -0
- package/src/infrastructure/event-bus/event-bus.ts +145 -0
- package/src/infrastructure/event-bus/index.ts +2 -0
- package/src/infrastructure/event-bus/types.ts +22 -0
- package/src/infrastructure/index.ts +32 -0
- package/src/infrastructure/lock/decorators.ts +67 -0
- package/src/infrastructure/lock/index.ts +2 -0
- package/src/infrastructure/lock/lock-manager.ts +33 -0
- package/src/infrastructure/logger/index.ts +2 -0
- package/src/infrastructure/logger/logger.ts +96 -0
- package/src/infrastructure/logger/types.ts +25 -0
- package/src/layout/index.tsx +185 -0
- package/src/navigation/index.ts +91 -0
- package/src/notification/index.ts +14 -0
- package/src/notification/notification-service.ts +120 -0
- package/src/notification/storage/in-memory.ts +56 -0
- package/src/notification/storage/index.ts +1 -0
- package/src/notification/types.ts +51 -0
- package/src/organization/branch-service.ts +299 -0
- package/src/organization/branches.config.ts +154 -0
- package/src/organization/index.ts +5 -0
- package/src/plugin/apps-registry.ts +97 -0
- package/src/plugin/index.ts +5 -0
- package/src/plugin/types.ts +41 -0
- package/src/providers/index.tsx +109 -0
- package/src/providers/tenant-provider.tsx +45 -0
- package/src/rbac/components/roles/role-card.tsx +158 -0
- package/src/rbac/components/roles/role-stats-cards.tsx +29 -0
- package/src/rbac/components/roles/role-toolbar.tsx +123 -0
- package/src/rbac/hooks/use-role-operations.ts +159 -0
- package/src/rbac/hooks/use-roles-data.ts +59 -0
- package/src/rbac/index.ts +297 -0
- package/src/rbac/lib/permission-helpers.ts +63 -0
- package/src/rbac/pages/action-list-page.tsx +25 -0
- package/src/rbac/pages/resource-list-page.tsx +25 -0
- package/src/rbac/pages/role-list-page.tsx +378 -0
- package/src/rbac/permission-service.ts +140 -0
- package/src/rbac/permissions.ts +135 -0
- package/src/rbac/resource-service.ts +115 -0
- package/src/rbac/resource-validator.ts +119 -0
- package/src/rbac/role-service.ts +165 -0
- package/src/rbac/server.ts +16 -0
- package/src/rbac/types.ts +38 -0
- package/src/schemas/action.schema.ts +66 -0
- package/src/schemas/branch.schema.ts +52 -0
- package/src/schemas/coming-soon-schema.ts +9 -0
- package/src/schemas/company.schema.ts +44 -0
- package/src/schemas/forgot-passward-schema.ts +9 -0
- package/src/schemas/index.ts +30 -0
- package/src/schemas/material-category.schema.ts +43 -0
- package/src/schemas/material-pricing.schema.ts +74 -0
- package/src/schemas/material.schema.ts +76 -0
- package/src/schemas/materials.ts +52 -0
- package/src/schemas/new-passward-schema.ts +15 -0
- package/src/schemas/partner-company.schema.ts +149 -0
- package/src/schemas/register-schema.ts +36 -0
- package/src/schemas/resource.schema.ts +133 -0
- package/src/schemas/role.schema.ts +11 -0
- package/src/schemas/sign-in-schema.ts +24 -0
- package/src/schemas/supplier-pricing.schema.ts +15 -0
- package/src/schemas/supplier.schema.ts +120 -0
- package/src/schemas/system-category-group.schema.ts +67 -0
- package/src/schemas/system-category.schema.ts +77 -0
- package/src/schemas/system-config.schema.ts +118 -0
- package/src/schemas/uom.schema.ts +75 -0
- package/src/schemas/user-supplier.schema.ts +179 -0
- package/src/schemas/user.schema.ts +18 -0
- package/src/schemas/verify-email-schema.ts +9 -0
- package/src/schemas/warehouse.schema.ts +49 -0
- package/src/system/components/categories/category-list.tsx +529 -0
- package/src/system/components/categories/category-manager.tsx +89 -0
- package/src/system/components/categories/group-sidebar.tsx +308 -0
- package/src/system/components/settings/setting-dialogs.tsx +197 -0
- package/src/system/components/settings/setting-field.tsx +291 -0
- package/src/system/components/settings/setting-form-dialog.tsx +308 -0
- package/src/system/components/settings/settings-groups.ts +80 -0
- package/src/system/components/settings/settings-search.tsx +71 -0
- package/src/system/components/settings/settings-section.tsx +74 -0
- package/src/system/components/settings/settings-sidebar.tsx +81 -0
- package/src/system/constants.ts +3 -0
- package/src/system/index.ts +150 -0
- package/src/system/job-manager.ts +176 -0
- package/src/system/pages/components/categories/category-list.tsx +537 -0
- package/src/system/pages/components/categories/category-manager.tsx +90 -0
- package/src/system/pages/components/categories/group-sidebar.tsx +311 -0
- package/src/system/pages/components/settings/sales-rules-settings.tsx +222 -0
- package/src/system/pages/components/settings/setting-dialogs.tsx +197 -0
- package/src/system/pages/components/settings/setting-field.tsx +292 -0
- package/src/system/pages/components/settings/setting-form-dialog.tsx +308 -0
- package/src/system/pages/components/settings/settings-groups.ts +87 -0
- package/src/system/pages/components/settings/settings-page.tsx +372 -0
- package/src/system/pages/components/settings/settings-search.tsx +71 -0
- package/src/system/pages/components/settings/settings-section.tsx +74 -0
- package/src/system/pages/components/settings/settings-sidebar.tsx +81 -0
- package/src/system/pages/components/settings/system-settings.tsx +244 -0
- package/src/system/pages/system-category-page.tsx +15 -0
- package/src/system/pages/system-settings-page.tsx +380 -0
- package/src/system/schemas/system-category-group.schema.ts +46 -0
- package/src/system/schemas/system-category.schema.ts +56 -0
- package/src/system/services/settings-service.ts +127 -0
- package/src/system/services/system-category-service.ts +63 -0
- package/src/system/types.ts +45 -0
- package/src/types/index.ts +703 -0
- package/src/ui/auth/auth-layout.tsx +135 -0
- package/src/ui/auth/forgot-password-form.tsx +98 -0
- package/src/ui/auth/index.tsx +7 -0
- package/src/ui/auth/new-password-form.tsx +107 -0
- package/src/ui/auth/oauth-links.tsx +30 -0
- package/src/ui/auth/register-form.tsx +202 -0
- package/src/ui/auth/sign-in-form.tsx +238 -0
- package/src/ui/auth/verify-email-form.tsx +104 -0
- package/src/ui/crud/index.tsx +10 -0
- package/src/ui/data-display/accordion.tsx +65 -0
- package/src/ui/data-display/aspect-ratio.tsx +11 -0
- package/src/ui/data-display/avatar.tsx +163 -0
- package/src/ui/data-display/bento-grid.tsx +77 -0
- package/src/ui/data-display/carousel.tsx +249 -0
- package/src/ui/data-display/chart.tsx +363 -0
- package/src/ui/data-display/code-block-highlight.tsx +54 -0
- package/src/ui/data-display/collapsible.tsx +42 -0
- package/src/ui/data-display/compact-stat-bar.tsx +149 -0
- package/src/ui/data-display/data-table/data-table-context.tsx +255 -0
- package/src/ui/data-display/data-table/data-table-empty-state.tsx +133 -0
- package/src/ui/data-display/data-table/data-table-skeleton.tsx +145 -0
- package/src/ui/data-display/data-table/data-table-toolbar.tsx +353 -0
- package/src/ui/data-display/data-table/data-table.tsx +597 -0
- package/src/ui/data-display/data-table/index.ts +44 -0
- package/src/ui/data-display/data-table-column-header.tsx +75 -0
- package/src/ui/data-display/data-table-pagination.tsx +130 -0
- package/src/ui/data-display/data-table-view-options.tsx +59 -0
- package/src/ui/data-display/formatted-number-input.tsx +210 -0
- package/src/ui/data-display/highlight.tsx +20 -0
- package/src/ui/data-display/hover-card.tsx +48 -0
- package/src/ui/data-display/index.tsx +50 -0
- package/src/ui/data-display/iphone-15-pro.tsx +114 -0
- package/src/ui/data-display/kanban/index.ts +4 -0
- package/src/ui/data-display/kanban/kanban-board.tsx +192 -0
- package/src/ui/data-display/kanban/kanban-column.tsx +74 -0
- package/src/ui/data-display/kanban/kanban-item.tsx +50 -0
- package/src/ui/data-display/kanban/kanban-types.ts +21 -0
- package/src/ui/data-display/kpi-card.tsx +68 -0
- package/src/ui/data-display/media-grid.tsx +110 -0
- package/src/ui/data-display/safari.tsx +175 -0
- package/src/ui/data-display/show-more-text.tsx +55 -0
- package/src/ui/data-display/tabs.tsx +68 -0
- package/src/ui/data-display/timeline.tsx +256 -0
- package/src/ui/feedback/alert.tsx +60 -0
- package/src/ui/feedback/context-menu.tsx +245 -0
- package/src/ui/feedback/drawer.tsx +132 -0
- package/src/ui/feedback/error-dialog.tsx +273 -0
- package/src/ui/feedback/index.tsx +183 -0
- package/src/ui/feedback/progress.tsx +32 -0
- package/src/ui/feedback/sheet.tsx +148 -0
- package/src/ui/feedback/sonner.tsx +36 -0
- package/src/ui/forms/command.tsx +157 -0
- package/src/ui/forms/date-picker.tsx +73 -0
- package/src/ui/forms/date-range-picker.tsx +76 -0
- package/src/ui/forms/date-time-picker.tsx +109 -0
- package/src/ui/forms/editor/editor-menu-bar.tsx +394 -0
- package/src/ui/forms/editor/index.tsx +130 -0
- package/src/ui/forms/editor/multi-select-example.tsx +1234 -0
- package/src/ui/forms/emoji-picker.tsx +109 -0
- package/src/ui/forms/file-dropzone.tsx +169 -0
- package/src/ui/forms/file-thumbnail.tsx +29 -0
- package/src/ui/forms/index.tsx +201 -0
- package/src/ui/forms/input-file.tsx +99 -0
- package/src/ui/forms/input-group.tsx +46 -0
- package/src/ui/forms/input-otp.tsx +81 -0
- package/src/ui/forms/input-phone.tsx +172 -0
- package/src/ui/forms/input-spin.tsx +116 -0
- package/src/ui/forms/input-tags.tsx +219 -0
- package/src/ui/forms/input-time.tsx +42 -0
- package/src/ui/forms/multi-select.tsx +629 -0
- package/src/ui/forms/multiple-date-picker.tsx +74 -0
- package/src/ui/forms/radio-group.tsx +42 -0
- package/src/ui/forms/rating.tsx +158 -0
- package/src/ui/forms/time-picker.tsx +57 -0
- package/src/ui/index.tsx +17 -0
- package/src/ui/layout/animated-list.tsx +77 -0
- package/src/ui/layout/animated-sidebar.tsx +294 -0
- package/src/ui/layout/command-menu.tsx +355 -0
- package/src/ui/layout/customizer.tsx +324 -0
- package/src/ui/layout/footer.tsx +43 -0
- package/src/ui/layout/full-screen-toggle.tsx +52 -0
- package/src/ui/layout/header-breadcrumb.tsx +77 -0
- package/src/ui/layout/horizontal-layout-header.tsx +83 -0
- package/src/ui/layout/horizontal-layout.tsx +50 -0
- package/src/ui/layout/index.tsx +25 -0
- package/src/ui/layout/language-dropdown.tsx +103 -0
- package/src/ui/layout/logo.tsx +63 -0
- package/src/ui/layout/main-layout.tsx +57 -0
- package/src/ui/layout/mode-dropdown.tsx +58 -0
- package/src/ui/layout/notification-dropdown.tsx +127 -0
- package/src/ui/layout/page-tabs.tsx +306 -0
- package/src/ui/layout/route-cache.tsx +214 -0
- package/src/ui/layout/sidebar-group-icon-menu.tsx +195 -0
- package/src/ui/layout/sidebar.tsx +279 -0
- package/src/ui/layout/tab-content-cache.tsx +201 -0
- package/src/ui/layout/tab-navigation-provider.tsx +536 -0
- package/src/ui/layout/toggle-mobile-sidebar.tsx +33 -0
- package/src/ui/layout/top-bar-header-menubar.tsx +412 -0
- package/src/ui/layout/user-dropdown.tsx +188 -0
- package/src/ui/layout/vertical-layout-header.tsx +65 -0
- package/src/ui/layout/vertical-layout.tsx +47 -0
- package/src/ui/management/audit-log-page.tsx +209 -0
- package/src/ui/management/cache-management.tsx +349 -0
- package/src/ui/management/index.ts +3 -0
- package/src/ui/management/job-management.tsx +308 -0
- package/src/ui/pages/not-found.tsx +30 -0
- package/src/ui/primitives/badge.tsx +66 -0
- package/src/ui/primitives/breadcrumb.tsx +103 -0
- package/src/ui/primitives/button.tsx +129 -0
- package/src/ui/primitives/calendar.tsx +74 -0
- package/src/ui/primitives/card.tsx +86 -0
- package/src/ui/primitives/checkbox.tsx +31 -0
- package/src/ui/primitives/client.ts +30 -0
- package/src/ui/primitives/combobox.tsx +290 -0
- package/src/ui/primitives/dialog.tsx +121 -0
- package/src/ui/primitives/dropdown-menu.tsx +239 -0
- package/src/ui/primitives/dynamic-icon.tsx +24 -0
- package/src/ui/primitives/index.tsx +134 -0
- package/src/ui/primitives/input-number.tsx +131 -0
- package/src/ui/primitives/input.tsx +22 -0
- package/src/ui/primitives/keyboard.tsx +23 -0
- package/src/ui/primitives/label.tsx +24 -0
- package/src/ui/primitives/menubar.tsx +262 -0
- package/src/ui/primitives/navigation-menu.tsx +157 -0
- package/src/ui/primitives/pagination.tsx +118 -0
- package/src/ui/primitives/popover.tsx +56 -0
- package/src/ui/primitives/prefetch-link.tsx +60 -0
- package/src/ui/primitives/resizable.tsx +59 -0
- package/src/ui/primitives/scroll-area.tsx +63 -0
- package/src/ui/primitives/select.tsx +172 -0
- package/src/ui/primitives/separator.tsx +51 -0
- package/src/ui/primitives/sidebar.tsx +844 -0
- package/src/ui/primitives/slider.tsx +27 -0
- package/src/ui/primitives/status-badge.tsx +47 -0
- package/src/ui/primitives/sticky-layout.tsx +50 -0
- package/src/ui/primitives/switch.tsx +29 -0
- package/src/ui/primitives/table.tsx +116 -0
- package/src/ui/primitives/tabs.tsx +55 -0
- package/src/ui/primitives/toggle-group.tsx +70 -0
- package/src/ui/primitives/toggle.tsx +47 -0
- package/src/ui/primitives/tooltip.tsx +59 -0
- package/src/user/components/dangerous-zone.tsx +34 -0
- package/src/user/components/delete-account-form.tsx +40 -0
- package/src/user/components/index.ts +4 -0
- package/src/user/components/profile-info-form.tsx +390 -0
- package/src/user/components/profile-info.tsx +32 -0
- package/src/user/components/unified-profile-dialog.tsx +1019 -0
- package/src/user/components/user-stats.tsx +27 -0
- package/src/user/components/user-toolbar.tsx +137 -0
- package/src/user/components/users-card-view.tsx +253 -0
- package/src/user/index.ts +11 -0
- package/src/user/pages/user-list-page.tsx +234 -0
- package/src/user/pages/users-client-page.tsx +385 -0
- package/src/user/profile-page.tsx +19 -0
- package/src/user/schemas.ts +68 -0
- package/src/user/types.ts +34 -0
- package/src/user/user-service.ts +538 -0
- package/src/utils/index.ts +906 -0
- package/src/workflow/activity-timeline.tsx +412 -0
- package/src/workflow/approval-workflow.tsx +31 -0
- package/src/workflow/index.ts +2 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useCallback,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useState,
|
|
9
|
+
} from "react";
|
|
10
|
+
import useEmblaCarousel from "embla-carousel-react";
|
|
11
|
+
import { ArrowLeft, ArrowRight } from "lucide-react";
|
|
12
|
+
|
|
13
|
+
import type { UseEmblaCarouselType } from "embla-carousel-react";
|
|
14
|
+
import type { ComponentProps, KeyboardEvent } from "react";
|
|
15
|
+
|
|
16
|
+
import { cn } from "../../utils";
|
|
17
|
+
|
|
18
|
+
import { Button } from "../primitives";
|
|
19
|
+
|
|
20
|
+
export type CarouselApi = UseEmblaCarouselType[1];
|
|
21
|
+
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;
|
|
22
|
+
type CarouselOptions = UseCarouselParameters[0];
|
|
23
|
+
type CarouselPlugin = UseCarouselParameters[1];
|
|
24
|
+
|
|
25
|
+
type CarouselProps = {
|
|
26
|
+
opts?: CarouselOptions;
|
|
27
|
+
plugins?: CarouselPlugin;
|
|
28
|
+
orientation?: "horizontal" | "vertical";
|
|
29
|
+
setApi?: (api: CarouselApi) => void;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type CarouselContextProps = {
|
|
33
|
+
carouselRef: ReturnType<typeof useEmblaCarousel>[0];
|
|
34
|
+
api: ReturnType<typeof useEmblaCarousel>[1];
|
|
35
|
+
scrollPrev: () => void;
|
|
36
|
+
scrollNext: () => void;
|
|
37
|
+
canScrollPrev: boolean;
|
|
38
|
+
canScrollNext: boolean;
|
|
39
|
+
} & CarouselProps;
|
|
40
|
+
|
|
41
|
+
const CarouselContext = createContext<CarouselContextProps | null>(null);
|
|
42
|
+
|
|
43
|
+
function useCarousel() {
|
|
44
|
+
const context = useContext(CarouselContext);
|
|
45
|
+
|
|
46
|
+
if (!context) {
|
|
47
|
+
throw new Error("useCarousel must be used within a <Carousel />");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return context;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function Carousel({
|
|
54
|
+
orientation = "horizontal",
|
|
55
|
+
opts,
|
|
56
|
+
setApi,
|
|
57
|
+
plugins,
|
|
58
|
+
className,
|
|
59
|
+
children,
|
|
60
|
+
...props
|
|
61
|
+
}: ComponentProps<"div"> & CarouselProps) {
|
|
62
|
+
const [carouselRef, api] = useEmblaCarousel(
|
|
63
|
+
{
|
|
64
|
+
...opts,
|
|
65
|
+
axis: orientation === "horizontal" ? "x" : "y",
|
|
66
|
+
},
|
|
67
|
+
plugins,
|
|
68
|
+
);
|
|
69
|
+
const [canScrollPrev, setCanScrollPrev] = useState(false);
|
|
70
|
+
const [canScrollNext, setCanScrollNext] = useState(false);
|
|
71
|
+
|
|
72
|
+
const onSelect = useCallback((api: CarouselApi) => {
|
|
73
|
+
if (!api) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
setCanScrollPrev(api.canScrollPrev());
|
|
78
|
+
setCanScrollNext(api.canScrollNext());
|
|
79
|
+
}, []);
|
|
80
|
+
|
|
81
|
+
const scrollPrev = useCallback(() => {
|
|
82
|
+
api?.scrollPrev();
|
|
83
|
+
}, [api]);
|
|
84
|
+
|
|
85
|
+
const scrollNext = useCallback(() => {
|
|
86
|
+
api?.scrollNext();
|
|
87
|
+
}, [api]);
|
|
88
|
+
|
|
89
|
+
const handleKeyDown = useCallback(
|
|
90
|
+
(event: KeyboardEvent<HTMLDivElement>) => {
|
|
91
|
+
if (event.key === "ArrowLeft") {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
scrollPrev();
|
|
94
|
+
} else if (event.key === "ArrowRight") {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
scrollNext();
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
[scrollPrev, scrollNext],
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (!api || !setApi) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
setApi(api);
|
|
108
|
+
}, [api, setApi]);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!api) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
onSelect(api);
|
|
116
|
+
api.on("reInit", onSelect);
|
|
117
|
+
api.on("select", onSelect);
|
|
118
|
+
|
|
119
|
+
return () => {
|
|
120
|
+
api?.off("select", onSelect);
|
|
121
|
+
};
|
|
122
|
+
}, [api, onSelect]);
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<CarouselContext.Provider
|
|
126
|
+
value={{
|
|
127
|
+
carouselRef,
|
|
128
|
+
api: api,
|
|
129
|
+
opts,
|
|
130
|
+
orientation:
|
|
131
|
+
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
|
132
|
+
scrollPrev,
|
|
133
|
+
scrollNext,
|
|
134
|
+
canScrollPrev,
|
|
135
|
+
canScrollNext,
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
<div
|
|
139
|
+
data-slot="carousel"
|
|
140
|
+
onKeyDownCapture={handleKeyDown}
|
|
141
|
+
className={cn("relative", className)}
|
|
142
|
+
role="region"
|
|
143
|
+
aria-roledescription="carousel"
|
|
144
|
+
{...props}
|
|
145
|
+
>
|
|
146
|
+
{children}
|
|
147
|
+
</div>
|
|
148
|
+
</CarouselContext.Provider>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function CarouselContent({
|
|
153
|
+
className,
|
|
154
|
+
...props
|
|
155
|
+
}: ComponentProps<"div">) {
|
|
156
|
+
const { carouselRef, orientation } = useCarousel();
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<div ref={carouselRef} className="overflow-hidden">
|
|
160
|
+
<div
|
|
161
|
+
data-slot="carousel-content"
|
|
162
|
+
className={cn(
|
|
163
|
+
"flex",
|
|
164
|
+
orientation === "horizontal" ? "-ms-4" : "-mt-4 flex-col",
|
|
165
|
+
className,
|
|
166
|
+
)}
|
|
167
|
+
{...props}
|
|
168
|
+
/>
|
|
169
|
+
</div>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function CarouselItem({ className, ...props }: ComponentProps<"div">) {
|
|
174
|
+
const { orientation } = useCarousel();
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<div
|
|
178
|
+
data-slot="carousel-item"
|
|
179
|
+
role="group"
|
|
180
|
+
aria-roledescription="slide"
|
|
181
|
+
className={cn(
|
|
182
|
+
"min-w-0 shrink-0 grow-0 basis-full",
|
|
183
|
+
orientation === "horizontal" ? "ps-4" : "pt-4",
|
|
184
|
+
className,
|
|
185
|
+
)}
|
|
186
|
+
{...props}
|
|
187
|
+
/>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function CarouselPrevious({
|
|
192
|
+
className,
|
|
193
|
+
variant = "outline",
|
|
194
|
+
size = "icon",
|
|
195
|
+
...props
|
|
196
|
+
}: ComponentProps<typeof Button>) {
|
|
197
|
+
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
|
198
|
+
|
|
199
|
+
return (
|
|
200
|
+
<Button
|
|
201
|
+
data-slot="carousel-previous"
|
|
202
|
+
variant={variant}
|
|
203
|
+
size={size}
|
|
204
|
+
className={cn(
|
|
205
|
+
"absolute h-8 w-8",
|
|
206
|
+
orientation === "horizontal"
|
|
207
|
+
? "top-1/2 -translate-y-1/2 ltr:-left-12 rtl:-right-12 rtl:[&_svg]:-scale-100"
|
|
208
|
+
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
209
|
+
className,
|
|
210
|
+
)}
|
|
211
|
+
aria-label="Previous slide"
|
|
212
|
+
disabled={!canScrollPrev}
|
|
213
|
+
onClick={scrollPrev}
|
|
214
|
+
{...props}
|
|
215
|
+
>
|
|
216
|
+
<ArrowLeft className="h-4 w-4" />
|
|
217
|
+
</Button>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export function CarouselNext({
|
|
222
|
+
className,
|
|
223
|
+
variant = "outline",
|
|
224
|
+
size = "icon",
|
|
225
|
+
...props
|
|
226
|
+
}: ComponentProps<typeof Button>) {
|
|
227
|
+
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
|
228
|
+
|
|
229
|
+
return (
|
|
230
|
+
<Button
|
|
231
|
+
data-slot="carousel-next"
|
|
232
|
+
variant={variant}
|
|
233
|
+
size={size}
|
|
234
|
+
className={cn(
|
|
235
|
+
"absolute h-8 w-8",
|
|
236
|
+
orientation === "horizontal"
|
|
237
|
+
? "top-1/2 -translate-y-1/2 ltr:-right-12 rtl:-left-12 rtl:[&_svg]:-scale-100"
|
|
238
|
+
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
239
|
+
className,
|
|
240
|
+
)}
|
|
241
|
+
aria-label="Next slide"
|
|
242
|
+
disabled={!canScrollNext}
|
|
243
|
+
onClick={scrollNext}
|
|
244
|
+
{...props}
|
|
245
|
+
>
|
|
246
|
+
<ArrowRight className="h-4 w-4" />
|
|
247
|
+
</Button>
|
|
248
|
+
);
|
|
249
|
+
}
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext, useId, useMemo } from "react";
|
|
4
|
+
import * as RechartsPrimitive from "recharts";
|
|
5
|
+
import type {
|
|
6
|
+
CSSProperties,
|
|
7
|
+
ComponentProps,
|
|
8
|
+
ComponentType,
|
|
9
|
+
ReactNode,
|
|
10
|
+
} from "react";
|
|
11
|
+
import { cn } from "../../utils";
|
|
12
|
+
|
|
13
|
+
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
14
|
+
const THEMES = { light: "", dark: ".dark" } as const;
|
|
15
|
+
|
|
16
|
+
export type ChartConfig = {
|
|
17
|
+
[k in string]: {
|
|
18
|
+
label?: ReactNode;
|
|
19
|
+
icon?: ComponentType;
|
|
20
|
+
} & (
|
|
21
|
+
| { color?: string; theme?: never }
|
|
22
|
+
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type ChartContextProps = {
|
|
27
|
+
config: ChartConfig;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const ChartContext = createContext<ChartContextProps | null>(null);
|
|
31
|
+
|
|
32
|
+
function useChart() {
|
|
33
|
+
const context = useContext(ChartContext);
|
|
34
|
+
|
|
35
|
+
if (!context) {
|
|
36
|
+
throw new Error("useChart must be used within a <ChartContainer />");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return context;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type ChartContainerProps = ComponentProps<"div"> & {
|
|
43
|
+
config: ChartConfig;
|
|
44
|
+
children: ComponentProps<
|
|
45
|
+
typeof RechartsPrimitive.ResponsiveContainer
|
|
46
|
+
>["children"];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export function ChartContainer({
|
|
50
|
+
id,
|
|
51
|
+
className,
|
|
52
|
+
children,
|
|
53
|
+
config,
|
|
54
|
+
...props
|
|
55
|
+
}: ChartContainerProps) {
|
|
56
|
+
const uniqueId = useId();
|
|
57
|
+
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`;
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<ChartContext.Provider value={{ config }}>
|
|
61
|
+
<div
|
|
62
|
+
data-slot="chart"
|
|
63
|
+
data-chart={chartId}
|
|
64
|
+
className={cn(
|
|
65
|
+
"flex aspect-video justify-center text-sm [&_.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[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-hidden [&_.recharts-surface]:outline-hidden",
|
|
66
|
+
className,
|
|
67
|
+
)}
|
|
68
|
+
{...props}
|
|
69
|
+
>
|
|
70
|
+
<ChartStyle id={chartId} config={config} />
|
|
71
|
+
<RechartsPrimitive.ResponsiveContainer>
|
|
72
|
+
{children}
|
|
73
|
+
</RechartsPrimitive.ResponsiveContainer>
|
|
74
|
+
</div>
|
|
75
|
+
</ChartContext.Provider>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function ChartStyle({
|
|
80
|
+
id,
|
|
81
|
+
config,
|
|
82
|
+
}: {
|
|
83
|
+
id: string;
|
|
84
|
+
config: ChartConfig;
|
|
85
|
+
}) {
|
|
86
|
+
const colorConfig = Object.entries(config).filter(
|
|
87
|
+
([_, config]) => config.theme || config.color,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
if (!colorConfig.length) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<style
|
|
96
|
+
dangerouslySetInnerHTML={{
|
|
97
|
+
__html: Object.entries(THEMES)
|
|
98
|
+
.map(
|
|
99
|
+
([theme, prefix]) => `
|
|
100
|
+
${prefix} [data-chart=${id}] {
|
|
101
|
+
${colorConfig
|
|
102
|
+
.map(([key, itemConfig]) => {
|
|
103
|
+
const color =
|
|
104
|
+
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
|
|
105
|
+
itemConfig.color;
|
|
106
|
+
return color ? ` --color-${key}: ${color};` : null;
|
|
107
|
+
})
|
|
108
|
+
.join("\n")}
|
|
109
|
+
}
|
|
110
|
+
`,
|
|
111
|
+
)
|
|
112
|
+
.join("\n"),
|
|
113
|
+
}}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const ChartTooltip = RechartsPrimitive.Tooltip;
|
|
119
|
+
|
|
120
|
+
type ChartTooltipContentProps = ComponentProps<
|
|
121
|
+
typeof RechartsPrimitive.Tooltip
|
|
122
|
+
> &
|
|
123
|
+
ComponentProps<"div"> & {
|
|
124
|
+
hideLabel?: boolean;
|
|
125
|
+
hideIndicator?: boolean;
|
|
126
|
+
indicator?: "line" | "dot" | "dashed";
|
|
127
|
+
nameKey?: string;
|
|
128
|
+
labelKey?: string;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export function ChartTooltipContent({
|
|
132
|
+
active,
|
|
133
|
+
payload,
|
|
134
|
+
className,
|
|
135
|
+
indicator = "dot",
|
|
136
|
+
hideLabel = false,
|
|
137
|
+
hideIndicator = false,
|
|
138
|
+
label,
|
|
139
|
+
labelFormatter,
|
|
140
|
+
labelClassName,
|
|
141
|
+
formatter,
|
|
142
|
+
color,
|
|
143
|
+
nameKey,
|
|
144
|
+
labelKey,
|
|
145
|
+
}: ChartTooltipContentProps) {
|
|
146
|
+
const { config } = useChart();
|
|
147
|
+
|
|
148
|
+
const tooltipLabel = useMemo(() => {
|
|
149
|
+
if (hideLabel || !payload?.length) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const [item] = payload;
|
|
154
|
+
const key = `${labelKey || item.dataKey || item.name || "value"}`;
|
|
155
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
156
|
+
const value =
|
|
157
|
+
!labelKey && typeof label === "string"
|
|
158
|
+
? config[label as keyof typeof config]?.label || label
|
|
159
|
+
: itemConfig?.label;
|
|
160
|
+
|
|
161
|
+
if (labelFormatter) {
|
|
162
|
+
return (
|
|
163
|
+
<div className={cn("font-medium", labelClassName)}>
|
|
164
|
+
{labelFormatter(value, payload)}
|
|
165
|
+
</div>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!value) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return <div className={cn("font-medium", labelClassName)}>{value}</div>;
|
|
174
|
+
}, [
|
|
175
|
+
label,
|
|
176
|
+
labelFormatter,
|
|
177
|
+
payload,
|
|
178
|
+
hideLabel,
|
|
179
|
+
labelClassName,
|
|
180
|
+
config,
|
|
181
|
+
labelKey,
|
|
182
|
+
]);
|
|
183
|
+
|
|
184
|
+
if (!active || !payload?.length) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const nestLabel = payload.length === 1 && indicator !== "dot";
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<div
|
|
192
|
+
className={cn(
|
|
193
|
+
"grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-sm shadow-xl",
|
|
194
|
+
className,
|
|
195
|
+
)}
|
|
196
|
+
>
|
|
197
|
+
{!nestLabel ? tooltipLabel : null}
|
|
198
|
+
<div className="grid gap-1.5">
|
|
199
|
+
{payload.map((item, index) => {
|
|
200
|
+
const key = `${nameKey || item.name || item.dataKey || "value"}`;
|
|
201
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
202
|
+
const indicatorColor = color || item.payload.fill || item.color;
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<div
|
|
206
|
+
key={item.dataKey}
|
|
207
|
+
className={cn(
|
|
208
|
+
"flex w-full flex-wrap items-stretch gap-1 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",
|
|
209
|
+
indicator === "dot" && "items-center",
|
|
210
|
+
)}
|
|
211
|
+
>
|
|
212
|
+
{formatter && item?.value !== undefined && item.name ? (
|
|
213
|
+
formatter(item.value, item.name, item, index, item.payload)
|
|
214
|
+
) : (
|
|
215
|
+
<>
|
|
216
|
+
{itemConfig?.icon ? (
|
|
217
|
+
<itemConfig.icon />
|
|
218
|
+
) : (
|
|
219
|
+
!hideIndicator && (
|
|
220
|
+
<div
|
|
221
|
+
className={cn(
|
|
222
|
+
"shrink-0 rounded-sm border-(--color-border) bg-(--color-bg)",
|
|
223
|
+
{
|
|
224
|
+
"h-2.5 w-2.5": indicator === "dot",
|
|
225
|
+
"w-1": indicator === "line",
|
|
226
|
+
"w-0 border-[1.5px] border-dashed bg-transparent":
|
|
227
|
+
indicator === "dashed",
|
|
228
|
+
"my-0.5": nestLabel && indicator === "dashed",
|
|
229
|
+
},
|
|
230
|
+
)}
|
|
231
|
+
style={
|
|
232
|
+
{
|
|
233
|
+
"--color-bg": indicatorColor,
|
|
234
|
+
"--color-border": indicatorColor,
|
|
235
|
+
} as CSSProperties
|
|
236
|
+
}
|
|
237
|
+
/>
|
|
238
|
+
)
|
|
239
|
+
)}
|
|
240
|
+
<div
|
|
241
|
+
className={cn(
|
|
242
|
+
"flex flex-1 justify-between gap-4 leading-none",
|
|
243
|
+
nestLabel ? "items-end" : "items-center",
|
|
244
|
+
)}
|
|
245
|
+
>
|
|
246
|
+
<div className="grid gap-1.5">
|
|
247
|
+
{nestLabel ? tooltipLabel : null}
|
|
248
|
+
<span className="text-muted-foreground">
|
|
249
|
+
{itemConfig?.label || item.name}
|
|
250
|
+
</span>
|
|
251
|
+
</div>
|
|
252
|
+
{item.value && (
|
|
253
|
+
<span className="font-medium tabular-nums text-foreground">
|
|
254
|
+
{item.value.toLocaleString()}
|
|
255
|
+
</span>
|
|
256
|
+
)}
|
|
257
|
+
</div>
|
|
258
|
+
</>
|
|
259
|
+
)}
|
|
260
|
+
</div>
|
|
261
|
+
);
|
|
262
|
+
})}
|
|
263
|
+
</div>
|
|
264
|
+
</div>
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export const ChartLegend = RechartsPrimitive.Legend;
|
|
269
|
+
|
|
270
|
+
type ChartLegendContentProps = ComponentProps<"div"> &
|
|
271
|
+
Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
|
|
272
|
+
hideIcon?: boolean;
|
|
273
|
+
nameKey?: string;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
export function ChartLegendContent({
|
|
277
|
+
className,
|
|
278
|
+
hideIcon = false,
|
|
279
|
+
payload,
|
|
280
|
+
verticalAlign = "bottom",
|
|
281
|
+
nameKey,
|
|
282
|
+
}: ChartLegendContentProps) {
|
|
283
|
+
const { config } = useChart();
|
|
284
|
+
|
|
285
|
+
if (!payload?.length) {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return (
|
|
290
|
+
<div
|
|
291
|
+
className={cn(
|
|
292
|
+
"flex items-center justify-center gap-4",
|
|
293
|
+
verticalAlign === "top" ? "pb-3" : "pt-3",
|
|
294
|
+
className,
|
|
295
|
+
)}
|
|
296
|
+
>
|
|
297
|
+
{payload.map((item) => {
|
|
298
|
+
const key = `${nameKey || item.dataKey || "value"}`;
|
|
299
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
300
|
+
|
|
301
|
+
return (
|
|
302
|
+
<div
|
|
303
|
+
key={item.value}
|
|
304
|
+
className={cn(
|
|
305
|
+
"flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground",
|
|
306
|
+
)}
|
|
307
|
+
>
|
|
308
|
+
{itemConfig?.icon && !hideIcon ? (
|
|
309
|
+
<itemConfig.icon />
|
|
310
|
+
) : (
|
|
311
|
+
<div
|
|
312
|
+
className="h-2 w-2 shrink-0 rounded-[2px]"
|
|
313
|
+
style={{
|
|
314
|
+
backgroundColor: item.color,
|
|
315
|
+
}}
|
|
316
|
+
/>
|
|
317
|
+
)}
|
|
318
|
+
{itemConfig?.label}
|
|
319
|
+
</div>
|
|
320
|
+
);
|
|
321
|
+
})}
|
|
322
|
+
</div>
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Helper to extract item config from a payload.
|
|
327
|
+
function getPayloadConfigFromPayload(
|
|
328
|
+
config: ChartConfig,
|
|
329
|
+
payload: unknown,
|
|
330
|
+
key: string,
|
|
331
|
+
) {
|
|
332
|
+
if (typeof payload !== "object" || payload === null) {
|
|
333
|
+
return undefined;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const payloadPayload =
|
|
337
|
+
"payload" in payload &&
|
|
338
|
+
typeof payload.payload === "object" &&
|
|
339
|
+
payload.payload !== null
|
|
340
|
+
? payload.payload
|
|
341
|
+
: undefined;
|
|
342
|
+
|
|
343
|
+
let configLabelKey: string = key;
|
|
344
|
+
|
|
345
|
+
if (
|
|
346
|
+
key in payload &&
|
|
347
|
+
typeof payload[key as keyof typeof payload] === "string"
|
|
348
|
+
) {
|
|
349
|
+
configLabelKey = payload[key as keyof typeof payload] as string;
|
|
350
|
+
} else if (
|
|
351
|
+
payloadPayload &&
|
|
352
|
+
key in payloadPayload &&
|
|
353
|
+
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
|
354
|
+
) {
|
|
355
|
+
configLabelKey = payloadPayload[
|
|
356
|
+
key as keyof typeof payloadPayload
|
|
357
|
+
] as string;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return configLabelKey in config
|
|
361
|
+
? config[configLabelKey]
|
|
362
|
+
: config[key as keyof typeof config];
|
|
363
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useLayoutEffect, useState } from "react";
|
|
4
|
+
import { bundledLanguages } from "shiki/bundle/web";
|
|
5
|
+
|
|
6
|
+
import type { JSX } from "react";
|
|
7
|
+
import type { BundledLanguage } from "shiki/bundle/web";
|
|
8
|
+
|
|
9
|
+
import { Button } from "../primitives";
|
|
10
|
+
import { highlight } from "./highlight";
|
|
11
|
+
|
|
12
|
+
function isBundledLanguage(value: unknown): value is BundledLanguage {
|
|
13
|
+
return typeof value === "string" && value in bundledLanguages;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function CodeBlock({
|
|
17
|
+
children,
|
|
18
|
+
lang,
|
|
19
|
+
}: {
|
|
20
|
+
children: string;
|
|
21
|
+
lang: string;
|
|
22
|
+
}) {
|
|
23
|
+
const [nodes, setNodes] = useState<JSX.Element>();
|
|
24
|
+
const [copied, setCopied] = useState(false);
|
|
25
|
+
|
|
26
|
+
const language = isBundledLanguage(lang) ? lang : "markdown";
|
|
27
|
+
|
|
28
|
+
useLayoutEffect(() => {
|
|
29
|
+
void highlight(children, language).then(setNodes);
|
|
30
|
+
}, [children, language]);
|
|
31
|
+
|
|
32
|
+
const handleCopy = async () => {
|
|
33
|
+
try {
|
|
34
|
+
await navigator.clipboard.writeText(children);
|
|
35
|
+
setCopied(true);
|
|
36
|
+
setTimeout(() => setCopied(false), 2000);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error("Failed to copy text: ", error);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div className="relative">
|
|
44
|
+
<Button
|
|
45
|
+
variant="secondary"
|
|
46
|
+
className="absolute end-2 top-2 w-16"
|
|
47
|
+
onClick={handleCopy}
|
|
48
|
+
>
|
|
49
|
+
{copied ? "Copied!" : "Copy"}
|
|
50
|
+
</Button>
|
|
51
|
+
{nodes}
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
|
|
4
|
+
|
|
5
|
+
import type { ComponentProps } from "react";
|
|
6
|
+
|
|
7
|
+
import { cn } from "../../utils";
|
|
8
|
+
|
|
9
|
+
export function Collapsible({
|
|
10
|
+
...props
|
|
11
|
+
}: ComponentProps<typeof CollapsiblePrimitive.Root>) {
|
|
12
|
+
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function CollapsibleTrigger({
|
|
16
|
+
className,
|
|
17
|
+
...props
|
|
18
|
+
}: ComponentProps<typeof CollapsiblePrimitive.CollapsibleTrigger>) {
|
|
19
|
+
return (
|
|
20
|
+
<CollapsiblePrimitive.CollapsibleTrigger
|
|
21
|
+
data-slot="collapsible-trigger"
|
|
22
|
+
className={cn("cursor-pointer", className)}
|
|
23
|
+
{...props}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function CollapsibleContent({
|
|
29
|
+
className,
|
|
30
|
+
...props
|
|
31
|
+
}: ComponentProps<typeof CollapsiblePrimitive.CollapsibleContent>) {
|
|
32
|
+
return (
|
|
33
|
+
<CollapsiblePrimitive.CollapsibleContent
|
|
34
|
+
data-slot="collapsible-content"
|
|
35
|
+
className={cn(
|
|
36
|
+
"overflow-hidden data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",
|
|
37
|
+
className,
|
|
38
|
+
)}
|
|
39
|
+
{...props}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
}
|