@wakastellar/ui 2.0.0 → 2.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/README.md +71 -8
- package/dist/cli/commands/add.d.ts +7 -0
- package/dist/cli/commands/init.d.ts +6 -0
- package/dist/cli/commands/list.d.ts +5 -0
- package/dist/cli/commands/search.d.ts +1 -0
- package/dist/cli/index.cjs +6014 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/utils/config.d.ts +29 -0
- package/dist/cli/utils/logger.d.ts +20 -0
- package/dist/cli/utils/registry.d.ts +23 -0
- package/package.json +14 -3
- package/src/blocks/activity-timeline/index.tsx +586 -0
- package/src/blocks/calendar-view/index.tsx +756 -0
- package/src/blocks/chat/index.tsx +1018 -0
- package/src/blocks/chat/widget.tsx +504 -0
- package/src/blocks/dashboard/index.tsx +522 -0
- package/src/blocks/empty-states/index.tsx +452 -0
- package/src/blocks/error-pages/index.tsx +426 -0
- package/src/blocks/faq/index.tsx +479 -0
- package/src/blocks/file-manager/index.tsx +890 -0
- package/src/blocks/footer/index.tsx +133 -0
- package/src/blocks/header/index.tsx +357 -0
- package/src/blocks/headtab/index.tsx +139 -0
- package/src/blocks/i18n-editor/index.tsx +1016 -0
- package/src/blocks/index.ts +80 -0
- package/src/blocks/kanban-board/index.tsx +779 -0
- package/src/blocks/landing/index.tsx +677 -0
- package/src/blocks/language-selector/index.tsx +88 -0
- package/src/blocks/layout/index.tsx +159 -0
- package/src/blocks/login/index.tsx +339 -0
- package/src/blocks/login/types.ts +131 -0
- package/src/blocks/pricing/index.tsx +564 -0
- package/src/blocks/profile/index.tsx +746 -0
- package/src/blocks/settings/index.tsx +558 -0
- package/src/blocks/sidebar/index.tsx +713 -0
- package/src/blocks/theme-creator-block/index.tsx +835 -0
- package/src/blocks/user-management/index.tsx +1037 -0
- package/src/blocks/wizard/index.tsx +719 -0
- package/src/components/DataTable/DataTable.tsx +406 -0
- package/src/components/DataTable/DataTableAdvanced.tsx +720 -0
- package/src/components/DataTable/DataTableBody.tsx +216 -0
- package/src/components/DataTable/DataTableCell.tsx +172 -0
- package/src/components/DataTable/DataTableColumnResizer.tsx +62 -0
- package/src/components/DataTable/DataTableConflictResolver.tsx +478 -0
- package/src/components/DataTable/DataTableContextMenu.tsx +219 -0
- package/src/components/DataTable/DataTableEditCell.tsx +279 -0
- package/src/components/DataTable/DataTableFilterBuilder.tsx +519 -0
- package/src/components/DataTable/DataTableFilters.tsx +535 -0
- package/src/components/DataTable/DataTableGrouping.tsx +147 -0
- package/src/components/DataTable/DataTableHeader.tsx +172 -0
- package/src/components/DataTable/DataTablePagination.tsx +125 -0
- package/src/components/DataTable/DataTableSelection.tsx +269 -0
- package/src/components/DataTable/DataTableSyncStatus.tsx +281 -0
- package/src/components/DataTable/DataTableToolbar.tsx +262 -0
- package/src/components/DataTable/README.md +446 -0
- package/src/components/DataTable/__tests__/DataTableAdvanced.test.tsx +426 -0
- package/src/components/DataTable/__tests__/DataTableEdit.test.tsx +329 -0
- package/src/components/DataTable/__tests__/useDataTableAdvanced.test.ts +455 -0
- package/src/components/DataTable/examples/EditExample.tsx +166 -0
- package/src/components/DataTable/formatters/index.ts +335 -0
- package/src/components/DataTable/hooks/__tests__/useDataTableEdit.test.ts +239 -0
- package/src/components/DataTable/hooks/useDataTable.ts +145 -0
- package/src/components/DataTable/hooks/useDataTableAdvanced.ts +342 -0
- package/src/components/DataTable/hooks/useDataTableAdvancedFilters.ts +637 -0
- package/src/components/DataTable/hooks/useDataTableColumnTemplates.ts +186 -0
- package/src/components/DataTable/hooks/useDataTableEdit.ts +167 -0
- package/src/components/DataTable/hooks/useDataTableExport.ts +227 -0
- package/src/components/DataTable/hooks/useDataTableImport.ts +216 -0
- package/src/components/DataTable/hooks/useDataTableOffline.ts +481 -0
- package/src/components/DataTable/hooks/useDataTableTheme.ts +213 -0
- package/src/components/DataTable/hooks/useDataTableVirtualization.ts +99 -0
- package/src/components/DataTable/hooks/useTableLayout.ts +85 -0
- package/src/components/DataTable/index.ts +81 -0
- package/src/components/DataTable/services/IndexedDBService.ts +504 -0
- package/src/components/DataTable/templates/index.tsx +803 -0
- package/src/components/DataTable/types.ts +504 -0
- package/src/components/DataTable/utils.ts +164 -0
- package/src/components/DataTable/workers/exportWorker.ts +213 -0
- package/src/components/accordion/index.tsx +61 -0
- package/src/components/alert/index.tsx +61 -0
- package/src/components/alert-dialog/index.tsx +146 -0
- package/src/components/aspect-ratio/index.tsx +12 -0
- package/src/components/avatar/index.tsx +54 -0
- package/src/components/badge/Badge.stories.tsx +64 -0
- package/src/components/badge/index.tsx +38 -0
- package/src/components/button/Button.stories.tsx +173 -0
- package/src/components/button/index.tsx +56 -0
- package/src/components/calendar/index.tsx +73 -0
- package/src/components/card/index.tsx +78 -0
- package/src/components/checkbox/index.tsx +34 -0
- package/src/components/code/index.tsx +229 -0
- package/src/components/collapsible/index.tsx +16 -0
- package/src/components/command/index.tsx +162 -0
- package/src/components/context-menu/index.tsx +204 -0
- package/src/components/dialog/index.tsx +126 -0
- package/src/components/dropdown-menu/index.tsx +204 -0
- package/src/components/error-boundary/ErrorBoundary.tsx +281 -0
- package/src/components/error-boundary/index.ts +7 -0
- package/src/components/form/index.tsx +183 -0
- package/src/components/hover-card/index.tsx +33 -0
- package/src/components/index.ts +368 -0
- package/src/components/input/Input.stories.tsx +100 -0
- package/src/components/input/index.tsx +27 -0
- package/src/components/input-otp/index.tsx +277 -0
- package/src/components/label/index.tsx +30 -0
- package/src/components/language-selector/index.tsx +341 -0
- package/src/components/menubar/index.tsx +240 -0
- package/src/components/navigation-menu/index.tsx +134 -0
- package/src/components/popover/index.tsx +35 -0
- package/src/components/progress/index.tsx +32 -0
- package/src/components/radio-group/index.tsx +48 -0
- package/src/components/scroll-area/index.tsx +52 -0
- package/src/components/select/index.tsx +164 -0
- package/src/components/separator/index.tsx +35 -0
- package/src/components/sheet/index.tsx +147 -0
- package/src/components/skeleton/index.tsx +22 -0
- package/src/components/slider/index.tsx +32 -0
- package/src/components/switch/index.tsx +33 -0
- package/src/components/table/index.tsx +117 -0
- package/src/components/tabs/index.tsx +59 -0
- package/src/components/textarea/index.tsx +30 -0
- package/src/components/theme-selector/index.tsx +327 -0
- package/src/components/toast/index.tsx +133 -0
- package/src/components/toaster/index.tsx +34 -0
- package/src/components/toggle/index.tsx +49 -0
- package/src/components/tooltip/index.tsx +34 -0
- package/src/components/typography/index.tsx +276 -0
- package/src/components/waka-3d-pie-chart/index.tsx +486 -0
- package/src/components/waka-achievement-unlock/index.tsx +716 -0
- package/src/components/waka-activity-feed/index.tsx +686 -0
- package/src/components/waka-address-autocomplete/index.tsx +1202 -0
- package/src/components/waka-admincrumb/index.tsx +349 -0
- package/src/components/waka-alert-stack/index.tsx +827 -0
- package/src/components/waka-allocation-matrix/index.tsx +1278 -0
- package/src/components/waka-approval-chain/index.tsx +766 -0
- package/src/components/waka-audit-log/index.tsx +1475 -0
- package/src/components/waka-autocomplete/index.tsx +358 -0
- package/src/components/waka-badge-showcase/index.tsx +704 -0
- package/src/components/waka-barcode/index.tsx +260 -0
- package/src/components/waka-biometric-prompt/index.tsx +765 -0
- package/src/components/waka-bottom-sheet/index.tsx +495 -0
- package/src/components/waka-breadcrumb/index.tsx +376 -0
- package/src/components/waka-breadcrumb-path/index.tsx +513 -0
- package/src/components/waka-budget-burn/index.tsx +1234 -0
- package/src/components/waka-capacity-planner/index.tsx +1107 -0
- package/src/components/waka-carousel/index.tsx +893 -0
- package/src/components/waka-cart-summary/index.tsx +1055 -0
- package/src/components/waka-challenge-timer/index.tsx +1044 -0
- package/src/components/waka-charts/WakaAreaChart.tsx +251 -0
- package/src/components/waka-charts/WakaBarChart.tsx +222 -0
- package/src/components/waka-charts/WakaChart.tsx +124 -0
- package/src/components/waka-charts/WakaLineChart.tsx +219 -0
- package/src/components/waka-charts/WakaMiniChart.tsx +133 -0
- package/src/components/waka-charts/WakaPieChart.tsx +214 -0
- package/src/components/waka-charts/WakaSparkline.tsx +229 -0
- package/src/components/waka-charts/dataTableHelpers.ts +109 -0
- package/src/components/waka-charts/hooks/useChartTheme.ts +123 -0
- package/src/components/waka-charts/hooks/useRechartsLoader.ts +234 -0
- package/src/components/waka-charts/index.ts +90 -0
- package/src/components/waka-charts/types.ts +330 -0
- package/src/components/waka-chat-bubble/index.tsx +1060 -0
- package/src/components/waka-checklist/index.tsx +1067 -0
- package/src/components/waka-checkout-stepper/index.tsx +976 -0
- package/src/components/waka-cohort-table/index.tsx +1011 -0
- package/src/components/waka-color-picker/index.tsx +447 -0
- package/src/components/waka-combo-counter/index.tsx +864 -0
- package/src/components/waka-combobox/index.tsx +497 -0
- package/src/components/waka-command-bar/index.tsx +403 -0
- package/src/components/waka-compare-period/index.tsx +1230 -0
- package/src/components/waka-connection-matrix/index.tsx +1053 -0
- package/src/components/waka-contribution-graph/index.tsx +552 -0
- package/src/components/waka-cost-breakdown/index.tsx +1065 -0
- package/src/components/waka-coupon-input/index.tsx +592 -0
- package/src/components/waka-credit-card-input/index.tsx +982 -0
- package/src/components/waka-daily-reward/index.tsx +762 -0
- package/src/components/waka-date-range-picker/index.tsx +378 -0
- package/src/components/waka-datetime-picker/index.tsx +793 -0
- package/src/components/waka-datetime-picker.form-integration/index.tsx +402 -0
- package/src/components/waka-deployment-lane/index.tsx +673 -0
- package/src/components/waka-device-trust/index.tsx +1259 -0
- package/src/components/waka-dock/index.tsx +285 -0
- package/src/components/waka-drawer/index.tsx +319 -0
- package/src/components/waka-empty-state/index.tsx +545 -0
- package/src/components/waka-error-shake/index.tsx +398 -0
- package/src/components/waka-feature-announcement/index.tsx +991 -0
- package/src/components/waka-file-upload/index.tsx +437 -0
- package/src/components/waka-floating-nav/index.tsx +413 -0
- package/src/components/waka-flow-diagram/index.tsx +508 -0
- package/src/components/waka-funnel-chart/index.tsx +823 -0
- package/src/components/waka-glow-card/index.tsx +246 -0
- package/src/components/waka-goal-progress/index.tsx +1025 -0
- package/src/components/waka-haptic-button/index.tsx +388 -0
- package/src/components/waka-health-pulse/index.tsx +451 -0
- package/src/components/waka-heatmap/index.tsx +1026 -0
- package/src/components/waka-hotspot/index.tsx +682 -0
- package/src/components/waka-image/index.tsx +373 -0
- package/src/components/waka-incident-timeline/index.tsx +686 -0
- package/src/components/waka-invoice-preview/index.tsx +829 -0
- package/src/components/waka-kanban/index.tsx +646 -0
- package/src/components/waka-kpi-dashboard/index.tsx +755 -0
- package/src/components/waka-leaderboard/index.tsx +746 -0
- package/src/components/waka-level-progress/index.tsx +665 -0
- package/src/components/waka-liquid-button/index.tsx +520 -0
- package/src/components/waka-loading-orbit/index.tsx +478 -0
- package/src/components/waka-loot-box/index.tsx +1091 -0
- package/src/components/waka-magic-link/index.tsx +321 -0
- package/src/components/waka-magnetic-button/index.tsx +567 -0
- package/src/components/waka-mention-input/index.tsx +953 -0
- package/src/components/waka-metric-sparkline/index.tsx +627 -0
- package/src/components/waka-milestone-road/index.tsx +1064 -0
- package/src/components/waka-modal/index.tsx +374 -0
- package/src/components/waka-morph-button/index.tsx +495 -0
- package/src/components/waka-network-topology/index.tsx +801 -0
- package/src/components/waka-notifications/index.tsx +414 -0
- package/src/components/waka-number-input/index.tsx +373 -0
- package/src/components/waka-orbital-menu/index.tsx +445 -0
- package/src/components/waka-order-tracker/index.tsx +1041 -0
- package/src/components/waka-pagination/index.tsx +393 -0
- package/src/components/waka-password-strength/index.tsx +824 -0
- package/src/components/waka-payment-method-picker/index.tsx +715 -0
- package/src/components/waka-permission-matrix/index.tsx +1302 -0
- package/src/components/waka-phone-input/index.tsx +801 -0
- package/src/components/waka-pipeline-view/index.tsx +604 -0
- package/src/components/waka-player-card/index.tsx +691 -0
- package/src/components/waka-points-popup/index.tsx +366 -0
- package/src/components/waka-power-up/index.tsx +1155 -0
- package/src/components/waka-presence-indicator/index.tsx +1181 -0
- package/src/components/waka-pricing-table/index.tsx +755 -0
- package/src/components/waka-product-card/index.tsx +786 -0
- package/src/components/waka-progress-onboarding/index.tsx +878 -0
- package/src/components/waka-pull-to-refresh/index.tsx +451 -0
- package/src/components/waka-qrcode/index.tsx +232 -0
- package/src/components/waka-quest-card/index.tsx +1275 -0
- package/src/components/waka-quota-bar/index.tsx +693 -0
- package/src/components/waka-radar-score/index.tsx +512 -0
- package/src/components/waka-rank-badge/index.tsx +813 -0
- package/src/components/waka-rating-input/index.tsx +560 -0
- package/src/components/waka-reaction-picker/index.tsx +1062 -0
- package/src/components/waka-region-map/index.tsx +730 -0
- package/src/components/waka-resource-gauge/index.tsx +654 -0
- package/src/components/waka-resource-pool/index.tsx +1035 -0
- package/src/components/waka-rich-text-editor/index.tsx +594 -0
- package/src/components/waka-rollback-slider/index.tsx +891 -0
- package/src/components/waka-sankey-diagram/index.tsx +1032 -0
- package/src/components/waka-schedule-picker/index.tsx +1060 -0
- package/src/components/waka-scratch-card/index.tsx +914 -0
- package/src/components/waka-season-pass/index.tsx +886 -0
- package/src/components/waka-security-score/index.tsx +1126 -0
- package/src/components/waka-segmented-control/index.tsx +238 -0
- package/src/components/waka-server-rack/index.tsx +764 -0
- package/src/components/waka-session-manager/index.tsx +815 -0
- package/src/components/waka-signature-pad/index.tsx +744 -0
- package/src/components/waka-skeleton-wave/index.tsx +454 -0
- package/src/components/waka-skill-tree/index.tsx +1031 -0
- package/src/components/waka-sla-tracker/index.tsx +798 -0
- package/src/components/waka-slider-range/index.tsx +765 -0
- package/src/components/waka-spin-wheel/index.tsx +671 -0
- package/src/components/waka-spinner/index.tsx +284 -0
- package/src/components/waka-spotlight/index.tsx +410 -0
- package/src/components/waka-stat/index.tsx +428 -0
- package/src/components/waka-stats-hexagon/index.tsx +824 -0
- package/src/components/waka-status-matrix/index.tsx +565 -0
- package/src/components/waka-stepper/index.tsx +489 -0
- package/src/components/waka-streak-counter/index.tsx +334 -0
- package/src/components/waka-success-explosion/index.tsx +453 -0
- package/src/components/waka-swipe-card/index.tsx +574 -0
- package/src/components/waka-tabs-morph/index.tsx +509 -0
- package/src/components/waka-tag-input/index.tsx +877 -0
- package/src/components/waka-team-banner/index.tsx +1183 -0
- package/src/components/waka-terminal-output/index.tsx +836 -0
- package/src/components/waka-theme-creator/index.tsx +762 -0
- package/src/components/waka-theme-manager/index.tsx +654 -0
- package/src/components/waka-thread-view/index.tsx +874 -0
- package/src/components/waka-tilt-card/index.tsx +250 -0
- package/src/components/waka-time-picker/index.tsx +479 -0
- package/src/components/waka-timeline/index.tsx +385 -0
- package/src/components/waka-tooltip-tour/index.tsx +855 -0
- package/src/components/waka-tour-guide/index.tsx +920 -0
- package/src/components/waka-tournament-bracket/index.tsx +1276 -0
- package/src/components/waka-tree/index.tsx +557 -0
- package/src/components/waka-treemap-chart/index.tsx +1031 -0
- package/src/components/waka-two-factor-setup/index.tsx +995 -0
- package/src/components/waka-typewriter/index.tsx +566 -0
- package/src/components/waka-typing-indicator/index.tsx +649 -0
- package/src/components/waka-versus-card/index.tsx +1026 -0
- package/src/components/waka-video/index.tsx +557 -0
- package/src/components/waka-video-call/index.tsx +1087 -0
- package/src/components/waka-virtual-list/index.tsx +327 -0
- package/src/components/waka-voice-message/index.tsx +1019 -0
- package/src/components/waka-welcome-modal/index.tsx +790 -0
- package/src/components/waka-xp-bar/index.tsx +799 -0
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
5
|
+
import { cn } from "../../utils/cn"
|
|
6
|
+
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Types
|
|
9
|
+
// ============================================================================
|
|
10
|
+
|
|
11
|
+
export type SnapPoint = number | "content" | "full"
|
|
12
|
+
|
|
13
|
+
export interface WakaBottomSheetProps
|
|
14
|
+
extends Omit<React.HTMLAttributes<HTMLDivElement>, "children" | "onDragStart" | "onDragEnd">,
|
|
15
|
+
VariantProps<typeof bottomSheetVariants> {
|
|
16
|
+
/** Whether the sheet is open */
|
|
17
|
+
open: boolean
|
|
18
|
+
/** Callback when open state changes */
|
|
19
|
+
onOpenChange: (open: boolean) => void
|
|
20
|
+
/** Snap points as percentages (0-100) or special values */
|
|
21
|
+
snapPoints?: SnapPoint[]
|
|
22
|
+
/** Default snap point index */
|
|
23
|
+
defaultSnapPoint?: number
|
|
24
|
+
/** Current snap point index (controlled) */
|
|
25
|
+
snapPoint?: number
|
|
26
|
+
/** Callback when snap point changes */
|
|
27
|
+
onSnapPointChange?: (index: number) => void
|
|
28
|
+
/** Whether to show backdrop */
|
|
29
|
+
showBackdrop?: boolean
|
|
30
|
+
/** Whether clicking backdrop closes sheet */
|
|
31
|
+
closeOnBackdropClick?: boolean
|
|
32
|
+
/** Whether to show drag handle */
|
|
33
|
+
showHandle?: boolean
|
|
34
|
+
/** Whether to block scroll when open */
|
|
35
|
+
blockScroll?: boolean
|
|
36
|
+
/** Enable haptic feedback */
|
|
37
|
+
hapticFeedback?: boolean
|
|
38
|
+
/** Custom header content */
|
|
39
|
+
header?: React.ReactNode
|
|
40
|
+
/** Custom footer content */
|
|
41
|
+
footer?: React.ReactNode
|
|
42
|
+
/** Main content */
|
|
43
|
+
children: React.ReactNode
|
|
44
|
+
/** Callback when drag starts */
|
|
45
|
+
onDragStart?: () => void
|
|
46
|
+
/** Callback when drag ends */
|
|
47
|
+
onDragEnd?: (snapPointIndex: number) => void
|
|
48
|
+
/** Animation duration in ms */
|
|
49
|
+
animationDuration?: number
|
|
50
|
+
/** Enable keyboard escape to close */
|
|
51
|
+
closeOnEscape?: boolean
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// Styles
|
|
56
|
+
// ============================================================================
|
|
57
|
+
|
|
58
|
+
const bottomSheetVariants = cva(
|
|
59
|
+
"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-background touch-none",
|
|
60
|
+
{
|
|
61
|
+
variants: {
|
|
62
|
+
variant: {
|
|
63
|
+
default: "rounded-t-2xl shadow-2xl border-t border-border",
|
|
64
|
+
flat: "shadow-lg",
|
|
65
|
+
glass: "rounded-t-2xl bg-background/80 backdrop-blur-xl border-t border-white/20",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
defaultVariants: {
|
|
69
|
+
variant: "default",
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
const backdropVariants = cva(
|
|
75
|
+
"fixed inset-0 z-40 transition-opacity",
|
|
76
|
+
{
|
|
77
|
+
variants: {
|
|
78
|
+
variant: {
|
|
79
|
+
default: "bg-black/50",
|
|
80
|
+
blur: "bg-black/30 backdrop-blur-sm",
|
|
81
|
+
none: "bg-transparent pointer-events-none",
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
defaultVariants: {
|
|
85
|
+
variant: "default",
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
const handleVariants = cva(
|
|
91
|
+
"mx-auto mt-3 mb-2 rounded-full bg-muted transition-colors",
|
|
92
|
+
{
|
|
93
|
+
variants: {
|
|
94
|
+
size: {
|
|
95
|
+
sm: "w-8 h-1",
|
|
96
|
+
default: "w-12 h-1.5",
|
|
97
|
+
lg: "w-16 h-2",
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
defaultVariants: {
|
|
101
|
+
size: "default",
|
|
102
|
+
},
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
// ============================================================================
|
|
107
|
+
// Utility functions
|
|
108
|
+
// ============================================================================
|
|
109
|
+
|
|
110
|
+
function triggerHaptic(type: "light" | "medium" | "heavy" = "light") {
|
|
111
|
+
if (typeof window !== "undefined" && "vibrate" in navigator) {
|
|
112
|
+
const patterns = { light: 10, medium: 20, heavy: 30 }
|
|
113
|
+
navigator.vibrate(patterns[type])
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function clamp(value: number, min: number, max: number): number {
|
|
118
|
+
return Math.min(Math.max(value, min), max)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ============================================================================
|
|
122
|
+
// Component
|
|
123
|
+
// ============================================================================
|
|
124
|
+
|
|
125
|
+
export const WakaBottomSheet = React.forwardRef<HTMLDivElement, WakaBottomSheetProps>(
|
|
126
|
+
(
|
|
127
|
+
{
|
|
128
|
+
open,
|
|
129
|
+
onOpenChange,
|
|
130
|
+
snapPoints = [25, 50, 90],
|
|
131
|
+
defaultSnapPoint = 0,
|
|
132
|
+
snapPoint: controlledSnapPoint,
|
|
133
|
+
onSnapPointChange,
|
|
134
|
+
showBackdrop = true,
|
|
135
|
+
closeOnBackdropClick = true,
|
|
136
|
+
showHandle = true,
|
|
137
|
+
blockScroll = true,
|
|
138
|
+
hapticFeedback = true,
|
|
139
|
+
header,
|
|
140
|
+
footer,
|
|
141
|
+
children,
|
|
142
|
+
onDragStart,
|
|
143
|
+
onDragEnd,
|
|
144
|
+
animationDuration = 300,
|
|
145
|
+
closeOnEscape = true,
|
|
146
|
+
variant,
|
|
147
|
+
className,
|
|
148
|
+
...props
|
|
149
|
+
},
|
|
150
|
+
ref
|
|
151
|
+
) => {
|
|
152
|
+
const sheetRef = React.useRef<HTMLDivElement>(null)
|
|
153
|
+
const contentRef = React.useRef<HTMLDivElement>(null)
|
|
154
|
+
const [internalSnapPoint, setInternalSnapPoint] = React.useState(defaultSnapPoint)
|
|
155
|
+
const [isDragging, setIsDragging] = React.useState(false)
|
|
156
|
+
const [dragStart, setDragStart] = React.useState({ y: 0, height: 0 })
|
|
157
|
+
const [currentHeight, setCurrentHeight] = React.useState(0)
|
|
158
|
+
const [windowHeight, setWindowHeight] = React.useState(0)
|
|
159
|
+
const [isAnimating, setIsAnimating] = React.useState(false)
|
|
160
|
+
|
|
161
|
+
// Controlled vs uncontrolled snap point
|
|
162
|
+
const snapPointIndex = controlledSnapPoint ?? internalSnapPoint
|
|
163
|
+
const setSnapPointIndex = React.useCallback((index: number) => {
|
|
164
|
+
setInternalSnapPoint(index)
|
|
165
|
+
onSnapPointChange?.(index)
|
|
166
|
+
}, [onSnapPointChange])
|
|
167
|
+
|
|
168
|
+
// Combine refs
|
|
169
|
+
React.useImperativeHandle(ref, () => sheetRef.current!)
|
|
170
|
+
|
|
171
|
+
// Calculate snap point heights
|
|
172
|
+
const getSnapPointHeight = React.useCallback((point: SnapPoint): number => {
|
|
173
|
+
if (point === "full") return windowHeight
|
|
174
|
+
if (point === "content") {
|
|
175
|
+
return contentRef.current?.scrollHeight ?? windowHeight * 0.5
|
|
176
|
+
}
|
|
177
|
+
return (point / 100) * windowHeight
|
|
178
|
+
}, [windowHeight])
|
|
179
|
+
|
|
180
|
+
const snapPointHeights = React.useMemo(
|
|
181
|
+
() => snapPoints.map(getSnapPointHeight),
|
|
182
|
+
[snapPoints, getSnapPointHeight]
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
// Initialize window height
|
|
186
|
+
React.useEffect(() => {
|
|
187
|
+
const updateHeight = () => setWindowHeight(window.innerHeight)
|
|
188
|
+
updateHeight()
|
|
189
|
+
window.addEventListener("resize", updateHeight)
|
|
190
|
+
return () => window.removeEventListener("resize", updateHeight)
|
|
191
|
+
}, [])
|
|
192
|
+
|
|
193
|
+
// Set initial height when opening
|
|
194
|
+
React.useEffect(() => {
|
|
195
|
+
if (open && windowHeight > 0) {
|
|
196
|
+
const targetHeight = snapPointHeights[snapPointIndex] ?? snapPointHeights[0]
|
|
197
|
+
setCurrentHeight(targetHeight)
|
|
198
|
+
}
|
|
199
|
+
}, [open, windowHeight, snapPointHeights, snapPointIndex])
|
|
200
|
+
|
|
201
|
+
// Block scroll when open
|
|
202
|
+
React.useEffect(() => {
|
|
203
|
+
if (blockScroll && open) {
|
|
204
|
+
const originalOverflow = document.body.style.overflow
|
|
205
|
+
document.body.style.overflow = "hidden"
|
|
206
|
+
return () => {
|
|
207
|
+
document.body.style.overflow = originalOverflow
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}, [blockScroll, open])
|
|
211
|
+
|
|
212
|
+
// Handle escape key
|
|
213
|
+
React.useEffect(() => {
|
|
214
|
+
if (!closeOnEscape || !open) return
|
|
215
|
+
|
|
216
|
+
const handleKeyDown = (e: KeyboardEvent) => {
|
|
217
|
+
if (e.key === "Escape") {
|
|
218
|
+
onOpenChange(false)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
document.addEventListener("keydown", handleKeyDown)
|
|
223
|
+
return () => document.removeEventListener("keydown", handleKeyDown)
|
|
224
|
+
}, [closeOnEscape, open, onOpenChange])
|
|
225
|
+
|
|
226
|
+
// Find nearest snap point
|
|
227
|
+
const findNearestSnapPoint = React.useCallback((height: number): number => {
|
|
228
|
+
let nearestIndex = 0
|
|
229
|
+
let minDistance = Infinity
|
|
230
|
+
|
|
231
|
+
snapPointHeights.forEach((snapHeight, index) => {
|
|
232
|
+
const distance = Math.abs(height - snapHeight)
|
|
233
|
+
if (distance < minDistance) {
|
|
234
|
+
minDistance = distance
|
|
235
|
+
nearestIndex = index
|
|
236
|
+
}
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
return nearestIndex
|
|
240
|
+
}, [snapPointHeights])
|
|
241
|
+
|
|
242
|
+
// Drag handlers
|
|
243
|
+
const handleDragStart = React.useCallback((clientY: number) => {
|
|
244
|
+
if (isAnimating) return
|
|
245
|
+
|
|
246
|
+
setIsDragging(true)
|
|
247
|
+
setDragStart({ y: clientY, height: currentHeight })
|
|
248
|
+
onDragStart?.()
|
|
249
|
+
}, [isAnimating, currentHeight, onDragStart])
|
|
250
|
+
|
|
251
|
+
const handleDragMove = React.useCallback((clientY: number) => {
|
|
252
|
+
if (!isDragging) return
|
|
253
|
+
|
|
254
|
+
const diff = dragStart.y - clientY
|
|
255
|
+
const newHeight = clamp(
|
|
256
|
+
dragStart.height + diff,
|
|
257
|
+
0,
|
|
258
|
+
windowHeight
|
|
259
|
+
)
|
|
260
|
+
setCurrentHeight(newHeight)
|
|
261
|
+
}, [isDragging, dragStart, windowHeight])
|
|
262
|
+
|
|
263
|
+
const handleDragEnd = React.useCallback(() => {
|
|
264
|
+
if (!isDragging) return
|
|
265
|
+
|
|
266
|
+
setIsDragging(false)
|
|
267
|
+
|
|
268
|
+
// Find nearest snap point or close if dragged below minimum
|
|
269
|
+
const minHeight = snapPointHeights[0] * 0.5
|
|
270
|
+
|
|
271
|
+
if (currentHeight < minHeight) {
|
|
272
|
+
// Close the sheet
|
|
273
|
+
setIsAnimating(true)
|
|
274
|
+
setCurrentHeight(0)
|
|
275
|
+
setTimeout(() => {
|
|
276
|
+
onOpenChange(false)
|
|
277
|
+
setIsAnimating(false)
|
|
278
|
+
}, animationDuration)
|
|
279
|
+
onDragEnd?.(-1)
|
|
280
|
+
return
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const nearestIndex = findNearestSnapPoint(currentHeight)
|
|
284
|
+
const targetHeight = snapPointHeights[nearestIndex]
|
|
285
|
+
|
|
286
|
+
if (hapticFeedback && nearestIndex !== snapPointIndex) {
|
|
287
|
+
triggerHaptic("light")
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
setIsAnimating(true)
|
|
291
|
+
setCurrentHeight(targetHeight)
|
|
292
|
+
setSnapPointIndex(nearestIndex)
|
|
293
|
+
|
|
294
|
+
setTimeout(() => {
|
|
295
|
+
setIsAnimating(false)
|
|
296
|
+
}, animationDuration)
|
|
297
|
+
|
|
298
|
+
onDragEnd?.(nearestIndex)
|
|
299
|
+
}, [isDragging, currentHeight, snapPointHeights, findNearestSnapPoint, hapticFeedback, snapPointIndex, animationDuration, onOpenChange, onDragEnd, setSnapPointIndex])
|
|
300
|
+
|
|
301
|
+
// Touch event handlers
|
|
302
|
+
const handleTouchStart = React.useCallback((e: React.TouchEvent) => {
|
|
303
|
+
handleDragStart(e.touches[0].clientY)
|
|
304
|
+
}, [handleDragStart])
|
|
305
|
+
|
|
306
|
+
const handleTouchMove = React.useCallback((e: React.TouchEvent) => {
|
|
307
|
+
handleDragMove(e.touches[0].clientY)
|
|
308
|
+
}, [handleDragMove])
|
|
309
|
+
|
|
310
|
+
const handleTouchEnd = React.useCallback(() => {
|
|
311
|
+
handleDragEnd()
|
|
312
|
+
}, [handleDragEnd])
|
|
313
|
+
|
|
314
|
+
// Mouse event handlers (for desktop testing)
|
|
315
|
+
const handleMouseDown = React.useCallback((e: React.MouseEvent) => {
|
|
316
|
+
handleDragStart(e.clientY)
|
|
317
|
+
e.preventDefault()
|
|
318
|
+
}, [handleDragStart])
|
|
319
|
+
|
|
320
|
+
React.useEffect(() => {
|
|
321
|
+
if (!isDragging) return
|
|
322
|
+
|
|
323
|
+
const handleMouseMove = (e: MouseEvent) => {
|
|
324
|
+
handleDragMove(e.clientY)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const handleMouseUp = () => {
|
|
328
|
+
handleDragEnd()
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
document.addEventListener("mousemove", handleMouseMove)
|
|
332
|
+
document.addEventListener("mouseup", handleMouseUp)
|
|
333
|
+
|
|
334
|
+
return () => {
|
|
335
|
+
document.removeEventListener("mousemove", handleMouseMove)
|
|
336
|
+
document.removeEventListener("mouseup", handleMouseUp)
|
|
337
|
+
}
|
|
338
|
+
}, [isDragging, handleDragMove, handleDragEnd])
|
|
339
|
+
|
|
340
|
+
// Backdrop click handler
|
|
341
|
+
const handleBackdropClick = React.useCallback(() => {
|
|
342
|
+
if (closeOnBackdropClick) {
|
|
343
|
+
onOpenChange(false)
|
|
344
|
+
}
|
|
345
|
+
}, [closeOnBackdropClick, onOpenChange])
|
|
346
|
+
|
|
347
|
+
// Snap to specific point
|
|
348
|
+
const snapTo = React.useCallback((index: number) => {
|
|
349
|
+
if (index < 0 || index >= snapPoints.length) return
|
|
350
|
+
|
|
351
|
+
const targetHeight = snapPointHeights[index]
|
|
352
|
+
setIsAnimating(true)
|
|
353
|
+
setCurrentHeight(targetHeight)
|
|
354
|
+
setSnapPointIndex(index)
|
|
355
|
+
|
|
356
|
+
if (hapticFeedback) triggerHaptic("light")
|
|
357
|
+
|
|
358
|
+
setTimeout(() => {
|
|
359
|
+
setIsAnimating(false)
|
|
360
|
+
}, animationDuration)
|
|
361
|
+
}, [snapPoints.length, snapPointHeights, hapticFeedback, animationDuration, setSnapPointIndex])
|
|
362
|
+
|
|
363
|
+
// Backdrop opacity based on sheet height
|
|
364
|
+
const backdropOpacity = open ? clamp(currentHeight / (windowHeight * 0.5), 0, 1) : 0
|
|
365
|
+
|
|
366
|
+
if (!open && currentHeight === 0) return null
|
|
367
|
+
|
|
368
|
+
return (
|
|
369
|
+
<>
|
|
370
|
+
{/* Backdrop */}
|
|
371
|
+
{showBackdrop && (
|
|
372
|
+
<div
|
|
373
|
+
className={cn(backdropVariants({ variant: "default" }))}
|
|
374
|
+
style={{
|
|
375
|
+
opacity: backdropOpacity,
|
|
376
|
+
transition: isAnimating || !isDragging ? `opacity ${animationDuration}ms ease-out` : "none",
|
|
377
|
+
}}
|
|
378
|
+
onClick={handleBackdropClick}
|
|
379
|
+
aria-hidden="true"
|
|
380
|
+
/>
|
|
381
|
+
)}
|
|
382
|
+
|
|
383
|
+
{/* Sheet */}
|
|
384
|
+
<div
|
|
385
|
+
ref={sheetRef}
|
|
386
|
+
role="dialog"
|
|
387
|
+
aria-modal="true"
|
|
388
|
+
className={cn(bottomSheetVariants({ variant }), className)}
|
|
389
|
+
style={{
|
|
390
|
+
height: currentHeight,
|
|
391
|
+
maxHeight: windowHeight,
|
|
392
|
+
transition: isAnimating || !isDragging ? `height ${animationDuration}ms ease-out` : "none",
|
|
393
|
+
}}
|
|
394
|
+
{...props}
|
|
395
|
+
>
|
|
396
|
+
{/* Handle */}
|
|
397
|
+
{showHandle && (
|
|
398
|
+
<div
|
|
399
|
+
className="flex-shrink-0 cursor-grab active:cursor-grabbing"
|
|
400
|
+
onTouchStart={handleTouchStart}
|
|
401
|
+
onTouchMove={handleTouchMove}
|
|
402
|
+
onTouchEnd={handleTouchEnd}
|
|
403
|
+
onTouchCancel={handleTouchEnd}
|
|
404
|
+
onMouseDown={handleMouseDown}
|
|
405
|
+
>
|
|
406
|
+
<div className={cn(handleVariants({ size: "default" }))} />
|
|
407
|
+
</div>
|
|
408
|
+
)}
|
|
409
|
+
|
|
410
|
+
{/* Header */}
|
|
411
|
+
{header && (
|
|
412
|
+
<div className="flex-shrink-0 px-4 pb-2 border-b border-border">
|
|
413
|
+
{header}
|
|
414
|
+
</div>
|
|
415
|
+
)}
|
|
416
|
+
|
|
417
|
+
{/* Content */}
|
|
418
|
+
<div
|
|
419
|
+
ref={contentRef}
|
|
420
|
+
className="flex-1 overflow-auto overscroll-contain px-4 py-2"
|
|
421
|
+
>
|
|
422
|
+
{children}
|
|
423
|
+
</div>
|
|
424
|
+
|
|
425
|
+
{/* Footer */}
|
|
426
|
+
{footer && (
|
|
427
|
+
<div className="flex-shrink-0 px-4 pt-2 pb-4 border-t border-border safe-area-inset-bottom">
|
|
428
|
+
{footer}
|
|
429
|
+
</div>
|
|
430
|
+
)}
|
|
431
|
+
</div>
|
|
432
|
+
</>
|
|
433
|
+
)
|
|
434
|
+
}
|
|
435
|
+
)
|
|
436
|
+
|
|
437
|
+
WakaBottomSheet.displayName = "WakaBottomSheet"
|
|
438
|
+
|
|
439
|
+
// ============================================================================
|
|
440
|
+
// Hook for programmatic control
|
|
441
|
+
// ============================================================================
|
|
442
|
+
|
|
443
|
+
export interface UseBottomSheetOptions {
|
|
444
|
+
defaultOpen?: boolean
|
|
445
|
+
defaultSnapPoint?: number
|
|
446
|
+
onOpenChange?: (open: boolean) => void
|
|
447
|
+
onSnapPointChange?: (index: number) => void
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export function useBottomSheet(options: UseBottomSheetOptions = {}) {
|
|
451
|
+
const {
|
|
452
|
+
defaultOpen = false,
|
|
453
|
+
defaultSnapPoint = 0,
|
|
454
|
+
onOpenChange: onOpenChangeProp,
|
|
455
|
+
onSnapPointChange: onSnapPointChangeProp,
|
|
456
|
+
} = options
|
|
457
|
+
|
|
458
|
+
const [open, setOpen] = React.useState(defaultOpen)
|
|
459
|
+
const [snapPoint, setSnapPoint] = React.useState(defaultSnapPoint)
|
|
460
|
+
|
|
461
|
+
const onOpenChange = React.useCallback((newOpen: boolean) => {
|
|
462
|
+
setOpen(newOpen)
|
|
463
|
+
onOpenChangeProp?.(newOpen)
|
|
464
|
+
}, [onOpenChangeProp])
|
|
465
|
+
|
|
466
|
+
const onSnapPointChange = React.useCallback((index: number) => {
|
|
467
|
+
setSnapPoint(index)
|
|
468
|
+
onSnapPointChangeProp?.(index)
|
|
469
|
+
}, [onSnapPointChangeProp])
|
|
470
|
+
|
|
471
|
+
const openSheet = React.useCallback((snapPointIndex?: number) => {
|
|
472
|
+
if (snapPointIndex !== undefined) {
|
|
473
|
+
setSnapPoint(snapPointIndex)
|
|
474
|
+
}
|
|
475
|
+
setOpen(true)
|
|
476
|
+
}, [])
|
|
477
|
+
|
|
478
|
+
const closeSheet = React.useCallback(() => {
|
|
479
|
+
setOpen(false)
|
|
480
|
+
}, [])
|
|
481
|
+
|
|
482
|
+
const toggleSheet = React.useCallback(() => {
|
|
483
|
+
setOpen(prev => !prev)
|
|
484
|
+
}, [])
|
|
485
|
+
|
|
486
|
+
return {
|
|
487
|
+
open,
|
|
488
|
+
snapPoint,
|
|
489
|
+
onOpenChange,
|
|
490
|
+
onSnapPointChange,
|
|
491
|
+
openSheet,
|
|
492
|
+
closeSheet,
|
|
493
|
+
toggleSheet,
|
|
494
|
+
}
|
|
495
|
+
}
|