@moontra/moonui-pro 2.20.1 → 2.20.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/dist/index.d.ts +691 -261
  2. package/dist/index.mjs +7418 -4934
  3. package/package.json +11 -5
  4. package/plugin/index.d.ts +86 -0
  5. package/plugin/index.js +308 -0
  6. package/scripts/postbuild.js +27 -0
  7. package/scripts/postinstall.js +176 -23
  8. package/src/__tests__/use-intersection-observer.test.tsx +0 -216
  9. package/src/__tests__/use-local-storage.test.tsx +0 -174
  10. package/src/__tests__/use-pro-access.test.tsx +0 -183
  11. package/src/components/advanced-chart/advanced-chart.test.tsx +0 -281
  12. package/src/components/advanced-chart/index.tsx +0 -1242
  13. package/src/components/advanced-forms/index.tsx +0 -426
  14. package/src/components/animated-button/index.tsx +0 -385
  15. package/src/components/calendar/event-dialog.tsx +0 -372
  16. package/src/components/calendar/index.tsx +0 -1073
  17. package/src/components/calendar-pro/index.tsx +0 -1697
  18. package/src/components/color-picker/index.tsx +0 -432
  19. package/src/components/credit-card-input/index.tsx +0 -406
  20. package/src/components/dashboard/dashboard-grid.tsx +0 -462
  21. package/src/components/dashboard/demo.tsx +0 -425
  22. package/src/components/dashboard/index.tsx +0 -1046
  23. package/src/components/dashboard/time-range-picker.tsx +0 -336
  24. package/src/components/dashboard/types.ts +0 -222
  25. package/src/components/dashboard/widgets/activity-feed.tsx +0 -344
  26. package/src/components/dashboard/widgets/chart-widget.tsx +0 -418
  27. package/src/components/dashboard/widgets/metric-card.tsx +0 -343
  28. package/src/components/data-table/data-table-bulk-actions.tsx +0 -204
  29. package/src/components/data-table/data-table-column-toggle.tsx +0 -169
  30. package/src/components/data-table/data-table-export.ts +0 -156
  31. package/src/components/data-table/data-table-filter-drawer.tsx +0 -448
  32. package/src/components/data-table/data-table.test.tsx +0 -187
  33. package/src/components/data-table/index.tsx +0 -845
  34. package/src/components/draggable-list/index.tsx +0 -100
  35. package/src/components/enhanced/badge.tsx +0 -191
  36. package/src/components/enhanced/button.tsx +0 -362
  37. package/src/components/enhanced/card.tsx +0 -266
  38. package/src/components/enhanced/dialog.tsx +0 -246
  39. package/src/components/enhanced/index.ts +0 -4
  40. package/src/components/error-boundary/index.tsx +0 -109
  41. package/src/components/file-upload/file-upload.test.tsx +0 -243
  42. package/src/components/file-upload/index.tsx +0 -1660
  43. package/src/components/floating-action-button/index.tsx +0 -206
  44. package/src/components/form-wizard/form-wizard-context.tsx +0 -307
  45. package/src/components/form-wizard/form-wizard-navigation.tsx +0 -118
  46. package/src/components/form-wizard/form-wizard-progress.tsx +0 -298
  47. package/src/components/form-wizard/form-wizard-step.tsx +0 -111
  48. package/src/components/form-wizard/index.tsx +0 -102
  49. package/src/components/form-wizard/types.ts +0 -76
  50. package/src/components/gesture-drawer/index.tsx +0 -551
  51. package/src/components/github-stars/github-api.ts +0 -426
  52. package/src/components/github-stars/hooks.ts +0 -516
  53. package/src/components/github-stars/index.tsx +0 -375
  54. package/src/components/github-stars/types.ts +0 -148
  55. package/src/components/github-stars/variants.tsx +0 -513
  56. package/src/components/health-check/index.tsx +0 -439
  57. package/src/components/hover-card-3d/index.tsx +0 -530
  58. package/src/components/index.ts +0 -128
  59. package/src/components/internal/index.ts +0 -78
  60. package/src/components/kanban/add-card-modal.tsx +0 -502
  61. package/src/components/kanban/card-detail-modal.tsx +0 -761
  62. package/src/components/kanban/index.ts +0 -13
  63. package/src/components/kanban/kanban.tsx +0 -1684
  64. package/src/components/kanban/types.ts +0 -168
  65. package/src/components/lazy-component/index.tsx +0 -823
  66. package/src/components/license-error/index.tsx +0 -29
  67. package/src/components/magnetic-button/index.tsx +0 -167
  68. package/src/components/memory-efficient-data/index.tsx +0 -1016
  69. package/src/components/moonui-quiz-form/index.tsx +0 -817
  70. package/src/components/optimized-image/index.tsx +0 -425
  71. package/src/components/performance-debugger/index.tsx +0 -589
  72. package/src/components/performance-monitor/index.tsx +0 -794
  73. package/src/components/phone-number-input/index.tsx +0 -338
  74. package/src/components/pinch-zoom/index.tsx +0 -566
  75. package/src/components/quiz-form/index.tsx +0 -479
  76. package/src/components/rich-text-editor/index-old-backup.tsx +0 -437
  77. package/src/components/rich-text-editor/index.tsx +0 -2324
  78. package/src/components/rich-text-editor/slash-commands-extension.ts +0 -220
  79. package/src/components/rich-text-editor/slash-commands.css +0 -35
  80. package/src/components/rich-text-editor/table-styles.css +0 -65
  81. package/src/components/sidebar/index.tsx +0 -865
  82. package/src/components/spotlight-card/index.tsx +0 -191
  83. package/src/components/swipeable-card/index.tsx +0 -100
  84. package/src/components/timeline/index.tsx +0 -1148
  85. package/src/components/ui/accordion.tsx +0 -73
  86. package/src/components/ui/alert-dialog.tsx +0 -141
  87. package/src/components/ui/alert.tsx +0 -141
  88. package/src/components/ui/aspect-ratio.tsx +0 -245
  89. package/src/components/ui/avatar.tsx +0 -153
  90. package/src/components/ui/badge.tsx +0 -228
  91. package/src/components/ui/breadcrumb.tsx +0 -214
  92. package/src/components/ui/button.tsx +0 -222
  93. package/src/components/ui/calendar.tsx +0 -387
  94. package/src/components/ui/card.tsx +0 -214
  95. package/src/components/ui/checkbox.tsx +0 -259
  96. package/src/components/ui/collapsible.tsx +0 -135
  97. package/src/components/ui/color-picker.tsx +0 -97
  98. package/src/components/ui/command.tsx +0 -225
  99. package/src/components/ui/dialog.tsx +0 -334
  100. package/src/components/ui/dropdown-menu.tsx +0 -218
  101. package/src/components/ui/gesture-drawer.tsx +0 -11
  102. package/src/components/ui/hover-card.tsx +0 -29
  103. package/src/components/ui/index.ts +0 -190
  104. package/src/components/ui/input.tsx +0 -222
  105. package/src/components/ui/label.tsx +0 -29
  106. package/src/components/ui/lightbox.tsx +0 -606
  107. package/src/components/ui/magnetic-button.tsx +0 -129
  108. package/src/components/ui/media-gallery.tsx +0 -612
  109. package/src/components/ui/pagination.tsx +0 -123
  110. package/src/components/ui/popover.tsx +0 -185
  111. package/src/components/ui/progress.tsx +0 -30
  112. package/src/components/ui/radio-group.tsx +0 -257
  113. package/src/components/ui/scroll-area.tsx +0 -47
  114. package/src/components/ui/select.tsx +0 -374
  115. package/src/components/ui/separator.tsx +0 -145
  116. package/src/components/ui/sheet.tsx +0 -139
  117. package/src/components/ui/skeleton.tsx +0 -20
  118. package/src/components/ui/slider.tsx +0 -354
  119. package/src/components/ui/spotlight-card.tsx +0 -119
  120. package/src/components/ui/switch.tsx +0 -86
  121. package/src/components/ui/table.tsx +0 -329
  122. package/src/components/ui/tabs.tsx +0 -198
  123. package/src/components/ui/textarea.tsx +0 -28
  124. package/src/components/ui/toast.tsx +0 -317
  125. package/src/components/ui/toggle.tsx +0 -119
  126. package/src/components/ui/tooltip.tsx +0 -151
  127. package/src/components/virtual-list/index.tsx +0 -668
  128. package/src/hooks/use-chart.ts +0 -205
  129. package/src/hooks/use-data-table.ts +0 -182
  130. package/src/hooks/use-docs-pro-access.ts +0 -13
  131. package/src/hooks/use-license-check.ts +0 -65
  132. package/src/hooks/use-subscription.ts +0 -19
  133. package/src/hooks/use-toast.ts +0 -15
  134. package/src/index.ts +0 -14
  135. package/src/lib/ai-providers.ts +0 -377
  136. package/src/lib/component-metadata.ts +0 -18
  137. package/src/lib/micro-interactions.ts +0 -255
  138. package/src/lib/paddle.ts +0 -17
  139. package/src/lib/utils.ts +0 -6
  140. package/src/patterns/login-form/index.tsx +0 -276
  141. package/src/patterns/login-form/types.ts +0 -67
  142. package/src/setupTests.ts +0 -41
  143. package/src/styles/advanced-chart.css +0 -239
  144. package/src/styles/calendar.css +0 -35
  145. package/src/styles/design-system.css +0 -363
  146. package/src/styles/index.css +0 -85
  147. package/src/styles/tailwind.css +0 -7
  148. package/src/styles/tokens.css +0 -455
  149. package/src/types/moonui.d.ts +0 -22
  150. package/src/types/next-auth.d.ts +0 -21
  151. package/src/use-intersection-observer.tsx +0 -154
  152. package/src/use-local-storage.tsx +0 -71
  153. package/src/use-paddle.ts +0 -138
  154. package/src/use-performance-optimizer.ts +0 -389
  155. package/src/use-pro-access.ts +0 -141
  156. package/src/use-scroll-animation.ts +0 -219
  157. package/src/use-subscription.ts +0 -37
  158. package/src/use-toast.ts +0 -32
  159. package/src/utils/chart-helpers.ts +0 -357
  160. package/src/utils/cn.ts +0 -6
  161. package/src/utils/data-processing.ts +0 -151
  162. package/src/utils/license-validator.tsx +0 -183
@@ -1,222 +0,0 @@
1
- import * as React from "react";
2
- import { cva, type VariantProps } from "class-variance-authority";
3
- import { cn } from "../../lib/utils";
4
- import { Loader2 } from "lucide-react";
5
-
6
- /**
7
- * MoonUI Button Pro Component
8
- *
9
- * A world-class, accessible, and versatile button component.
10
- * Pixel-perfect design with extensive variants and states.
11
- */
12
- const moonUIButtonProVariants = cva(
13
- ["inline-flex items-center justify-center gap-2 whitespace-nowrap",
14
- "font-medium relative",
15
- "transition-all duration-200 ease-out",
16
- "transform active:scale-[0.98]",
17
- "focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2",
18
- "disabled:opacity-50 disabled:cursor-not-allowed disabled:pointer-events-none disabled:transform-none"],
19
- {
20
- variants: {
21
- variant: {
22
- primary: [
23
- "bg-primary text-primary-foreground",
24
- "dark:bg-primary dark:text-primary-foreground",
25
- "hover:bg-primary/90 dark:hover:bg-primary/90",
26
- "active:bg-primary/80 dark:active:bg-primary/80",
27
- "shadow-sm hover:shadow-md",
28
- "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
29
- "transition-all duration-200",
30
- ],
31
- secondary: [
32
- "bg-muted text-muted-foreground",
33
- "dark:bg-muted dark:text-muted-foreground",
34
- "hover:bg-muted/80 dark:hover:bg-muted/80",
35
- "active:bg-muted/70 dark:active:bg-muted/70",
36
- "border border-input dark:border-input",
37
- "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
38
- "shadow-sm hover:shadow-md",
39
- ],
40
- outline: [
41
- "bg-background text-foreground",
42
- "dark:bg-background dark:text-foreground",
43
- "border border-input dark:border-input",
44
- "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent dark:hover:text-accent-foreground",
45
- "active:bg-accent/80 dark:active:bg-accent/80",
46
- "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
47
- "transition-all duration-200",
48
- ],
49
- ghost: [
50
- "text-foreground",
51
- "dark:text-foreground",
52
- "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent dark:hover:text-accent-foreground",
53
- "active:bg-accent/80 dark:active:bg-accent/80",
54
- "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
55
- "transition-all duration-200",
56
- ],
57
- destructive: [
58
- "bg-destructive text-destructive-foreground",
59
- "dark:bg-destructive dark:text-destructive-foreground",
60
- "hover:bg-destructive/90 dark:hover:bg-destructive/90",
61
- "active:bg-destructive/80 dark:active:bg-destructive/80",
62
- "shadow-sm hover:shadow-md",
63
- "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
64
- "transition-all duration-200",
65
- ],
66
- success: [
67
- "bg-success text-success-foreground",
68
- "dark:bg-success dark:text-success-foreground",
69
- "hover:bg-success/90 dark:hover:bg-success/90",
70
- "active:bg-success/80 dark:active:bg-success/80",
71
- "shadow-sm hover:shadow-md",
72
- "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
73
- "transition-all duration-200",
74
- ],
75
- link: [
76
- "text-primary bg-transparent",
77
- "underline-offset-4 hover:underline",
78
- "hover:text-primary/80 active:text-primary/70",
79
- "p-0 h-auto",
80
- "transition-colors duration-200",
81
- ],
82
- gradient: [
83
- "bg-gradient-to-r from-blue-600 to-purple-600 text-white",
84
- "hover:from-blue-700 hover:to-purple-700",
85
- "active:from-blue-800 active:to-purple-800",
86
- "shadow-lg shadow-purple-500/25",
87
- "focus-visible:ring-purple-500/50",
88
- "transition-all duration-300",
89
- ],
90
- glow: [
91
- "bg-primary text-primary-foreground",
92
- "shadow-lg shadow-primary/50",
93
- "hover:shadow-xl hover:shadow-primary/60",
94
- "active:shadow-md active:shadow-primary/40",
95
- "focus-visible:ring-primary/50",
96
- "transition-all duration-300",
97
- ],
98
- soft: [
99
- "bg-primary/10 text-primary",
100
- "hover:bg-primary/20",
101
- "active:bg-primary/30",
102
- "focus-visible:ring-primary/50",
103
- "dark:bg-primary/20 dark:text-primary-foreground",
104
- "dark:hover:bg-primary/30 dark:active:bg-primary/40",
105
- "transition-colors duration-200",
106
- ],
107
- glass: [
108
- "bg-white/10 backdrop-blur-md text-foreground",
109
- "border border-white/20",
110
- "hover:bg-white/20 hover:border-white/30",
111
- "active:bg-white/30",
112
- "shadow-lg",
113
- "focus-visible:ring-white/50",
114
- "dark:bg-gray-800/10 dark:border-gray-700/20",
115
- "dark:hover:bg-gray-800/20 dark:hover:border-gray-700/30",
116
- "transition-all duration-200",
117
- ],
118
- neon: [
119
- "bg-transparent text-primary",
120
- "border-2 border-primary",
121
- "hover:bg-primary hover:text-primary-foreground",
122
- "hover:shadow-[0_0_20px_rgba(var(--primary),0.5)]",
123
- "active:shadow-[0_0_10px_rgba(var(--primary),0.3)]",
124
- "focus-visible:ring-primary/50",
125
- "transition-all duration-300",
126
- ],
127
- },
128
- size: {
129
- xs: "h-7 px-2.5 text-xs rounded-md",
130
- sm: "h-8 px-3 text-sm rounded-md",
131
- md: "h-10 px-4 text-base rounded-lg",
132
- lg: "h-12 px-6 text-lg rounded-lg",
133
- xl: "h-14 px-8 text-xl rounded-xl",
134
- icon: "h-10 w-10 p-2 rounded-lg",
135
- "icon-sm": "h-8 w-8 p-1.5 rounded-md",
136
- "icon-lg": "h-12 w-12 p-3 rounded-xl",
137
- },
138
- rounded: {
139
- default: "",
140
- full: "rounded-full",
141
- none: "rounded-none",
142
- },
143
- fullWidth: {
144
- true: "w-full",
145
- },
146
- },
147
- defaultVariants: {
148
- variant: "primary",
149
- size: "md",
150
- rounded: "default",
151
- fullWidth: false,
152
- },
153
- }
154
- );
155
-
156
- // MoonUI Button Pro component props
157
- export interface MoonUIButtonProProps
158
- extends React.ButtonHTMLAttributes<HTMLButtonElement>,
159
- VariantProps<typeof moonUIButtonProVariants> {
160
- asChild?: boolean;
161
- loading?: boolean;
162
- leftIcon?: React.ReactNode;
163
- rightIcon?: React.ReactNode;
164
- }
165
-
166
- /**
167
- * MoonUI Button Pro Component
168
- *
169
- * @param props - MoonUI Button Pro component properties
170
- * @param props.variant - Visual variant (primary, secondary, ghost, etc.)
171
- * @param props.size - Button size (xs, sm, md, lg, xl)
172
- * @param props.loading - Loading state display
173
- * @param props.leftIcon - Icon on the left side
174
- * @param props.rightIcon - Icon on the right side
175
- * @param props.fullWidth - Full width display
176
- * @param props.rounded - Corner rounding style (default, full, none)
177
- * @param props.asChild - For Radix UI polymorphic component
178
- */
179
- const MoonUIButtonPro = React.forwardRef<HTMLButtonElement, MoonUIButtonProProps>(
180
- ({
181
- className,
182
- variant,
183
- size,
184
- rounded,
185
- fullWidth,
186
- asChild = false,
187
- loading = false,
188
- leftIcon,
189
- rightIcon,
190
- children,
191
- disabled,
192
- ...props
193
- }, ref) => {
194
- // Radix UI'ın asChild pattern'i için - "as" prop yerine
195
- const Comp = asChild ? "button" : "button";
196
-
197
- return (
198
- <Comp
199
- className={cn(moonUIButtonProVariants({ variant, size, rounded, fullWidth, className }))}
200
- ref={ref}
201
- disabled={disabled || loading}
202
- data-loading={loading ? "" : undefined}
203
- {...props}
204
- >
205
- {loading && (
206
- <Loader2 className="w-4 h-4 animate-spin" aria-hidden="true" />
207
- )}
208
- {!loading && leftIcon}
209
- {children}
210
- {!loading && rightIcon}
211
- </Comp>
212
- );
213
- }
214
- );
215
-
216
- MoonUIButtonPro.displayName = "MoonUIButtonPro";
217
-
218
- export { MoonUIButtonPro, moonUIButtonProVariants };
219
-
220
- // Backward compatibility exports
221
- export { MoonUIButtonPro as Button, moonUIButtonProVariants as buttonVariants };
222
- export type { MoonUIButtonProProps as ButtonProps };
@@ -1,387 +0,0 @@
1
- "use client";
2
-
3
- import * as React from "react";
4
- import { ChevronLeft, ChevronRight } from "lucide-react";
5
- import { cn } from "../../lib/utils";
6
- import { buttonVariants } from "./button";
7
- import {
8
- format,
9
- startOfMonth,
10
- endOfMonth,
11
- eachDayOfInterval,
12
- getDay,
13
- isSameMonth,
14
- isSameDay,
15
- isToday,
16
- addMonths,
17
- subMonths,
18
- startOfWeek,
19
- endOfWeek
20
- } from "date-fns";
21
-
22
- export interface CalendarProps {
23
- mode?: "single" | "range" | "multiple";
24
- selected?: Date | Date[] | { from?: Date; to?: Date } | undefined;
25
- onSelect?: (date: Date | Date[] | { from?: Date; to?: Date } | undefined) => void;
26
- disabled?: (date: Date) => boolean;
27
- showOutsideDays?: boolean;
28
- className?: string;
29
- classNames?: Record<string, string>;
30
- numberOfMonths?: number;
31
- defaultMonth?: Date;
32
- initialFocus?: boolean;
33
- }
34
-
35
- function Calendar({
36
- mode = "single",
37
- selected,
38
- onSelect,
39
- disabled,
40
- showOutsideDays = false,
41
- className,
42
- classNames,
43
- numberOfMonths = 1,
44
- defaultMonth,
45
- ...props
46
- }: CalendarProps) {
47
- const getInitialMonth = () => {
48
- if (defaultMonth) return defaultMonth;
49
- if (mode === "range" && selected) {
50
- const range = selected as { from?: Date; to?: Date };
51
- if (range.from && range.from instanceof Date) return range.from;
52
- }
53
- if (selected && selected instanceof Date) return selected;
54
- return new Date();
55
- };
56
-
57
- const [currentMonth, setCurrentMonth] = React.useState(getInitialMonth());
58
-
59
- const weekDays = [
60
- { short: "S", full: "Sunday" },
61
- { short: "M", full: "Monday" },
62
- { short: "T", full: "Tuesday" },
63
- { short: "W", full: "Wednesday" },
64
- { short: "T", full: "Thursday" },
65
- { short: "F", full: "Friday" },
66
- { short: "S", full: "Saturday" }
67
- ];
68
-
69
- const handlePreviousMonth = () => {
70
- setCurrentMonth(subMonths(currentMonth, 1));
71
- };
72
-
73
- const handleNextMonth = () => {
74
- setCurrentMonth(addMonths(currentMonth, 1));
75
- };
76
-
77
- const handleDateClick = (date: Date) => {
78
- if (disabled?.(date)) return;
79
-
80
- if (mode === "single") {
81
- onSelect?.(date);
82
- } else if (mode === "range") {
83
- const currentSelection = selected as { from?: Date; to?: Date } | undefined;
84
- if (!currentSelection?.from || (currentSelection.from && currentSelection.to)) {
85
- onSelect?.({ from: date, to: undefined });
86
- } else {
87
- if (date < currentSelection.from) {
88
- onSelect?.({ from: date, to: currentSelection.from });
89
- } else {
90
- onSelect?.({ from: currentSelection.from, to: date });
91
- }
92
- }
93
- }
94
- };
95
-
96
- const isDateSelected = (date: Date) => {
97
- if (!selected) return false;
98
-
99
- if (mode === "single") {
100
- return isSameDay(date, selected as Date);
101
- } else if (mode === "range") {
102
- const range = selected as { from?: Date; to?: Date };
103
- if (range.from && range.to) {
104
- return date >= range.from && date <= range.to;
105
- }
106
- return range.from ? isSameDay(date, range.from) : false;
107
- }
108
- return false;
109
- };
110
-
111
- const isRangeStart = (date: Date) => {
112
- if (mode !== "range" || !selected) return false;
113
- const range = selected as { from?: Date; to?: Date };
114
- return range.from ? isSameDay(date, range.from) : false;
115
- };
116
-
117
- const isRangeEnd = (date: Date) => {
118
- if (mode !== "range" || !selected) return false;
119
- const range = selected as { from?: Date; to?: Date };
120
- return range.to ? isSameDay(date, range.to) : false;
121
- };
122
-
123
- const isRangeMiddle = (date: Date) => {
124
- if (mode !== "range" || !selected) return false;
125
- const range = selected as { from?: Date; to?: Date };
126
- if (!range.from || !range.to) return false;
127
- return date > range.from && date < range.to;
128
- };
129
-
130
- const getDaysInMonth = () => {
131
- const start = startOfMonth(currentMonth);
132
- const end = endOfMonth(currentMonth);
133
- const days = eachDayOfInterval({ start, end });
134
-
135
- // Get days from previous month to fill the first week
136
- const firstDayOfWeek = getDay(start);
137
- const previousMonthDays = [];
138
- if (firstDayOfWeek > 0 && showOutsideDays) {
139
- const previousMonthStart = startOfWeek(start);
140
- const previousMonthEnd = new Date(start);
141
- previousMonthEnd.setDate(previousMonthEnd.getDate() - 1);
142
- previousMonthDays.push(...eachDayOfInterval({
143
- start: previousMonthStart,
144
- end: previousMonthEnd
145
- }));
146
- }
147
-
148
- // Get days from next month to fill the last week
149
- const lastDayOfWeek = getDay(end);
150
- const nextMonthDays = [];
151
- if (lastDayOfWeek < 6 && showOutsideDays) {
152
- const nextMonthStart = new Date(end);
153
- nextMonthStart.setDate(nextMonthStart.getDate() + 1);
154
- const nextMonthEnd = endOfWeek(end);
155
- nextMonthDays.push(...eachDayOfInterval({
156
- start: nextMonthStart,
157
- end: nextMonthEnd
158
- }));
159
- }
160
-
161
- // Add empty cells for the first week if not showing outside days
162
- const emptyCells = [];
163
- if (!showOutsideDays && firstDayOfWeek > 0) {
164
- for (let i = 0; i < firstDayOfWeek; i++) {
165
- emptyCells.push(null);
166
- }
167
- }
168
-
169
- return [...previousMonthDays, ...emptyCells, ...days, ...nextMonthDays];
170
- };
171
-
172
- const renderCalendar = (monthOffset: number = 0) => {
173
- const displayMonth = addMonths(currentMonth, monthOffset);
174
- const start = startOfMonth(displayMonth);
175
- const end = endOfMonth(displayMonth);
176
- const days = eachDayOfInterval({ start, end });
177
-
178
- // Get days from previous month to fill the first week
179
- const firstDayOfWeek = getDay(start);
180
- const previousMonthDays = [];
181
- if (firstDayOfWeek > 0 && showOutsideDays) {
182
- const previousMonthStart = startOfWeek(start);
183
- const previousMonthEnd = new Date(start);
184
- previousMonthEnd.setDate(previousMonthEnd.getDate() - 1);
185
- previousMonthDays.push(...eachDayOfInterval({
186
- start: previousMonthStart,
187
- end: previousMonthEnd
188
- }));
189
- }
190
-
191
- // Get days from next month to fill the last week
192
- const lastDayOfWeek = getDay(end);
193
- const nextMonthDays = [];
194
- if (lastDayOfWeek < 6 && showOutsideDays) {
195
- const nextMonthStart = new Date(end);
196
- nextMonthStart.setDate(nextMonthStart.getDate() + 1);
197
- const nextMonthEnd = endOfWeek(end);
198
- nextMonthDays.push(...eachDayOfInterval({
199
- start: nextMonthStart,
200
- end: nextMonthEnd
201
- }));
202
- }
203
-
204
- // Add empty cells for the first week if not showing outside days
205
- const emptyCells = [];
206
- if (!showOutsideDays && firstDayOfWeek > 0) {
207
- for (let i = 0; i < firstDayOfWeek; i++) {
208
- emptyCells.push(null);
209
- }
210
- }
211
-
212
- const allDays = [...previousMonthDays, ...emptyCells, ...days, ...nextMonthDays];
213
-
214
- return (
215
- <div className="moonui-calendar-month flex-1 min-w-0">
216
- {/* Month header for multi-month display */}
217
- {numberOfMonths > 1 && (
218
- <div className="flex items-center justify-center pb-2">
219
- <h3 className="text-xs sm:text-sm font-medium">
220
- {displayMonth instanceof Date && !isNaN(displayMonth.getTime())
221
- ? format(displayMonth, "MMMM yyyy")
222
- : ""}
223
- </h3>
224
- </div>
225
- )}
226
-
227
- {/* Week days header for each month */}
228
- <div className="grid grid-cols-7 gap-0 mb-1">
229
- {weekDays.map((day, index) => (
230
- <div
231
- key={`weekday-${monthOffset}-${index}`}
232
- className="text-muted-foreground text-[0.65rem] sm:text-[0.75rem] font-normal h-6 sm:h-7 w-full flex items-center justify-center"
233
- title={day.full}
234
- >
235
- {day.short}
236
- </div>
237
- ))}
238
- </div>
239
-
240
- {/* Days grid */}
241
- <div className="grid grid-cols-7 gap-0">
242
- {allDays.map((date, index) => {
243
- if (!date) {
244
- return <div key={`empty-${monthOffset}-${index}`} className="h-8 sm:h-9 w-full" />;
245
- }
246
-
247
- const isOutsideMonth = !isSameMonth(date, displayMonth);
248
- const isDisabled = disabled?.(date) || false;
249
- const isSelected = isDateSelected(date);
250
- const isTodayDate = isToday(date);
251
- const rangeStart = isRangeStart(date);
252
- const rangeEnd = isRangeEnd(date);
253
- const rangeMiddle = isRangeMiddle(date);
254
-
255
- return (
256
- <button
257
- key={date.toISOString()}
258
- onClick={() => handleDateClick(date)}
259
- disabled={isDisabled}
260
- className={cn(
261
- "h-8 sm:h-9 w-full p-0 font-normal",
262
- "inline-flex items-center justify-center rounded-md",
263
- "hover:bg-muted transition-colors text-xs sm:text-sm",
264
- "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
265
- isOutsideMonth && "text-muted-foreground/50",
266
- isDisabled && "text-muted-foreground/30 cursor-not-allowed hover:bg-transparent",
267
- isSelected && !rangeMiddle && "bg-primary text-primary-foreground font-medium hover:bg-primary hover:text-primary-foreground",
268
- isTodayDate && !isSelected && "bg-accent text-accent-foreground",
269
- rangeMiddle && "bg-accent rounded-none",
270
- rangeStart && "rounded-r-none",
271
- rangeEnd && "rounded-l-none"
272
- )}
273
- type="button"
274
- >
275
- {date instanceof Date && !isNaN(date.getTime())
276
- ? format(date, "d")
277
- : ""}
278
- </button>
279
- );
280
- })}
281
- </div>
282
- </div>
283
- );
284
- };
285
-
286
- return (
287
- <div className={cn("moonui-calendar p-2 sm:p-3", className)}>
288
- {/* Header - only show for single month */}
289
- {numberOfMonths === 1 && (
290
- <div className="flex items-center justify-between px-1 pb-3">
291
- <button
292
- onClick={handlePreviousMonth}
293
- className={cn(
294
- buttonVariants({ variant: "outline" }),
295
- "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"
296
- )}
297
- type="button"
298
- >
299
- <ChevronLeft className="h-4 w-4" />
300
- </button>
301
-
302
- <h2 className="text-sm font-medium">
303
- {currentMonth instanceof Date && !isNaN(currentMonth.getTime())
304
- ? format(currentMonth, "MMMM yyyy")
305
- : ""
306
- }
307
- </h2>
308
-
309
- <button
310
- onClick={handleNextMonth}
311
- className={cn(
312
- buttonVariants({ variant: "outline" }),
313
- "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"
314
- )}
315
- type="button"
316
- >
317
- <ChevronRight className="h-4 w-4" />
318
- </button>
319
- </div>
320
- )}
321
-
322
- {/* Navigation for multiple months */}
323
- {numberOfMonths > 1 && (
324
- <div className="flex items-center justify-between px-1 pb-3">
325
- <button
326
- onClick={handlePreviousMonth}
327
- className={cn(
328
- buttonVariants({ variant: "outline" }),
329
- "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"
330
- )}
331
- type="button"
332
- >
333
- <ChevronLeft className="h-4 w-4" />
334
- </button>
335
-
336
- <h2 className="text-xs sm:text-sm font-medium text-center">
337
- {currentMonth instanceof Date && !isNaN(currentMonth.getTime())
338
- ? `${format(currentMonth, "MMM yyyy")} - ${format(addMonths(currentMonth, numberOfMonths - 1), "MMM yyyy")}`
339
- : ""
340
- }
341
- </h2>
342
-
343
- <button
344
- onClick={handleNextMonth}
345
- className={cn(
346
- buttonVariants({ variant: "outline" }),
347
- "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"
348
- )}
349
- type="button"
350
- >
351
- <ChevronRight className="h-4 w-4" />
352
- </button>
353
- </div>
354
- )}
355
-
356
- {/* Week days header for single month */}
357
- {numberOfMonths === 1 && (
358
- <div className="grid grid-cols-7 gap-0 mb-1">
359
- {weekDays.map((day, index) => (
360
- <div
361
- key={`weekday-${index}`}
362
- className="text-muted-foreground text-[0.65rem] sm:text-[0.75rem] font-normal h-6 sm:h-7 w-full flex items-center justify-center"
363
- title={day.full}
364
- >
365
- {day.short}
366
- </div>
367
- ))}
368
- </div>
369
- )}
370
-
371
- {/* Calendar(s) */}
372
- <div className={cn(
373
- numberOfMonths > 1 && "flex flex-col sm:flex-row gap-2 sm:gap-4"
374
- )}>
375
- {Array.from({ length: numberOfMonths }).map((_, i) => (
376
- <div key={i} className="flex-1">
377
- {renderCalendar(i)}
378
- </div>
379
- ))}
380
- </div>
381
- </div>
382
- );
383
- }
384
-
385
- Calendar.displayName = "Calendar";
386
-
387
- export { Calendar };