@xk2800/nextjs-template 0.7.1-beta.12 → 0.7.1-beta.14

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.
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
 
3
3
  import * as React from "react"
4
- import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"
4
+ import { AlertDialog as AlertDialogPrimitive } from "radix-ui"
5
5
  import { cn } from "../../lib/utils"
6
6
  import { buttonVariants } from "./button"
7
7
 
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
 
3
3
  import * as React from "react"
4
- import * as AvatarPrimitive from "@radix-ui/react-avatar"
4
+ import { Avatar as AvatarPrimitive } from "radix-ui"
5
5
 
6
6
  import { cn } from "../../lib/utils"
7
7
 
@@ -1,5 +1,5 @@
1
1
  import * as React from "react"
2
- import { Slot } from "@radix-ui/react-slot"
2
+ import { Slot } from "radix-ui"
3
3
  import { cva, type VariantProps } from "class-variance-authority"
4
4
 
5
5
  import { cn } from "../../lib/utils"
@@ -34,7 +34,7 @@ function Badge({
34
34
  ...props
35
35
  }: React.ComponentProps<"span"> &
36
36
  VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
37
- const Comp = asChild ? Slot : "span"
37
+ const Comp = asChild ? Slot.Root : "span"
38
38
 
39
39
  return (
40
40
  <Comp
@@ -0,0 +1,220 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import {
5
+ ChevronDownIcon,
6
+ ChevronLeftIcon,
7
+ ChevronRightIcon,
8
+ } from "lucide-react"
9
+ import {
10
+ DayPicker,
11
+ getDefaultClassNames,
12
+ type DayButton,
13
+ } from "react-day-picker"
14
+
15
+ import { cn } from "../../lib/utils"
16
+ import { Button, buttonVariants } from "./button"
17
+
18
+ function Calendar({
19
+ className,
20
+ classNames,
21
+ showOutsideDays = true,
22
+ captionLayout = "label",
23
+ buttonVariant = "ghost",
24
+ formatters,
25
+ components,
26
+ ...props
27
+ }: React.ComponentProps<typeof DayPicker> & {
28
+ buttonVariant?: React.ComponentProps<typeof Button>["variant"]
29
+ }) {
30
+ const defaultClassNames = getDefaultClassNames()
31
+
32
+ return (
33
+ <DayPicker
34
+ showOutsideDays={showOutsideDays}
35
+ className={cn(
36
+ "group/calendar bg-background p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",
37
+ String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
38
+ String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
39
+ className
40
+ )}
41
+ captionLayout={captionLayout}
42
+ formatters={{
43
+ formatMonthDropdown: (date) =>
44
+ date.toLocaleString("default", { month: "short" }),
45
+ ...formatters,
46
+ }}
47
+ classNames={{
48
+ root: cn("w-fit", defaultClassNames.root),
49
+ months: cn(
50
+ "relative flex flex-col gap-4 md:flex-row",
51
+ defaultClassNames.months
52
+ ),
53
+ month: cn("flex w-full flex-col gap-4", defaultClassNames.month),
54
+ nav: cn(
55
+ "absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",
56
+ defaultClassNames.nav
57
+ ),
58
+ button_previous: cn(
59
+ buttonVariants({ variant: buttonVariant }),
60
+ "size-(--cell-size) p-0 select-none aria-disabled:opacity-50",
61
+ defaultClassNames.button_previous
62
+ ),
63
+ button_next: cn(
64
+ buttonVariants({ variant: buttonVariant }),
65
+ "size-(--cell-size) p-0 select-none aria-disabled:opacity-50",
66
+ defaultClassNames.button_next
67
+ ),
68
+ month_caption: cn(
69
+ "flex h-(--cell-size) w-full items-center justify-center px-(--cell-size)",
70
+ defaultClassNames.month_caption
71
+ ),
72
+ dropdowns: cn(
73
+ "flex h-(--cell-size) w-full items-center justify-center gap-1.5 text-sm font-medium",
74
+ defaultClassNames.dropdowns
75
+ ),
76
+ dropdown_root: cn(
77
+ "relative rounded-md border border-input shadow-xs has-focus:border-ring has-focus:ring-[3px] has-focus:ring-ring/50",
78
+ defaultClassNames.dropdown_root
79
+ ),
80
+ dropdown: cn(
81
+ "absolute inset-0 bg-popover opacity-0",
82
+ defaultClassNames.dropdown
83
+ ),
84
+ caption_label: cn(
85
+ "font-medium select-none",
86
+ captionLayout === "label"
87
+ ? "text-sm"
88
+ : "flex h-8 items-center gap-1 rounded-md pr-1 pl-2 text-sm [&>svg]:size-3.5 [&>svg]:text-muted-foreground",
89
+ defaultClassNames.caption_label
90
+ ),
91
+ month_grid: "w-full border-collapse",
92
+ weekdays: cn("flex", defaultClassNames.weekdays),
93
+ weekday: cn(
94
+ "flex-1 rounded-md text-[0.8rem] font-normal text-muted-foreground select-none",
95
+ defaultClassNames.weekday
96
+ ),
97
+ week: cn("mt-2 flex w-full", defaultClassNames.week),
98
+ week_number_header: cn(
99
+ "w-(--cell-size) select-none",
100
+ defaultClassNames.week_number_header
101
+ ),
102
+ week_number: cn(
103
+ "text-[0.8rem] text-muted-foreground select-none",
104
+ defaultClassNames.week_number
105
+ ),
106
+ day: cn(
107
+ "group/day relative aspect-square h-full w-full p-0 text-center select-none [&:last-child[data-selected=true]_button]:rounded-r-md",
108
+ props.showWeekNumber
109
+ ? "[&:nth-child(2)[data-selected=true]_button]:rounded-l-md"
110
+ : "[&:first-child[data-selected=true]_button]:rounded-l-md",
111
+ defaultClassNames.day
112
+ ),
113
+ range_start: cn(
114
+ "rounded-l-md bg-accent",
115
+ defaultClassNames.range_start
116
+ ),
117
+ range_middle: cn("rounded-none", defaultClassNames.range_middle),
118
+ range_end: cn("rounded-r-md bg-accent", defaultClassNames.range_end),
119
+ today: cn(
120
+ "rounded-md bg-accent text-accent-foreground data-[selected=true]:rounded-none",
121
+ defaultClassNames.today
122
+ ),
123
+ outside: cn(
124
+ "text-muted-foreground aria-selected:text-muted-foreground",
125
+ defaultClassNames.outside
126
+ ),
127
+ disabled: cn(
128
+ "text-muted-foreground opacity-50",
129
+ defaultClassNames.disabled
130
+ ),
131
+ hidden: cn("invisible", defaultClassNames.hidden),
132
+ ...classNames,
133
+ }}
134
+ components={{
135
+ Root: ({ className, rootRef, ...props }) => {
136
+ return (
137
+ <div
138
+ data-slot="calendar"
139
+ ref={rootRef}
140
+ className={cn(className)}
141
+ {...props}
142
+ />
143
+ )
144
+ },
145
+ Chevron: ({ className, orientation, ...props }) => {
146
+ if (orientation === "left") {
147
+ return (
148
+ <ChevronLeftIcon className={cn("size-4", className)} {...props} />
149
+ )
150
+ }
151
+
152
+ if (orientation === "right") {
153
+ return (
154
+ <ChevronRightIcon
155
+ className={cn("size-4", className)}
156
+ {...props}
157
+ />
158
+ )
159
+ }
160
+
161
+ return (
162
+ <ChevronDownIcon className={cn("size-4", className)} {...props} />
163
+ )
164
+ },
165
+ DayButton: CalendarDayButton,
166
+ WeekNumber: ({ children, ...props }) => {
167
+ return (
168
+ <td {...props}>
169
+ <div className="flex size-(--cell-size) items-center justify-center text-center">
170
+ {children}
171
+ </div>
172
+ </td>
173
+ )
174
+ },
175
+ ...components,
176
+ }}
177
+ {...props}
178
+ />
179
+ )
180
+ }
181
+
182
+ function CalendarDayButton({
183
+ className,
184
+ day,
185
+ modifiers,
186
+ ...props
187
+ }: React.ComponentProps<typeof DayButton>) {
188
+ const defaultClassNames = getDefaultClassNames()
189
+
190
+ const ref = React.useRef<HTMLButtonElement>(null)
191
+ React.useEffect(() => {
192
+ if (modifiers.focused) ref.current?.focus()
193
+ }, [modifiers.focused])
194
+
195
+ return (
196
+ <Button
197
+ ref={ref}
198
+ variant="ghost"
199
+ size="icon"
200
+ data-day={day.date.toLocaleDateString()}
201
+ data-selected-single={
202
+ modifiers.selected &&
203
+ !modifiers.range_start &&
204
+ !modifiers.range_end &&
205
+ !modifiers.range_middle
206
+ }
207
+ data-range-start={modifiers.range_start}
208
+ data-range-end={modifiers.range_end}
209
+ data-range-middle={modifiers.range_middle}
210
+ className={cn(
211
+ "flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-[3px] group-data-[focused=true]/day:ring-ring/50 data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground data-[range-middle=true]:rounded-none data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground dark:hover:text-accent-foreground [&>span]:text-xs [&>span]:opacity-70",
212
+ defaultClassNames.day,
213
+ className
214
+ )}
215
+ {...props}
216
+ />
217
+ )
218
+ }
219
+
220
+ export { Calendar, CalendarDayButton }
@@ -0,0 +1,215 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { Check, ChevronDown, Plus } from "lucide-react"
5
+ import { cn } from "../../lib/utils"
6
+ import { Button } from "./button"
7
+ import { Input } from "./input"
8
+ import {
9
+ Command,
10
+ CommandEmpty,
11
+ CommandGroup,
12
+ CommandInput,
13
+ CommandItem,
14
+ CommandList,
15
+ CommandSeparator,
16
+ } from "./command"
17
+ import { Popover, PopoverContent, PopoverTrigger } from "./popover"
18
+ import { Disclaimer } from "./disclaimer"
19
+
20
+ export type CategoryOption<TId extends string | number = number> = {
21
+ id: TId
22
+ name: string
23
+ color?: string | null
24
+ }
25
+
26
+ /** Extra names offered below the user's own categories, e.g. tax-relief or budget-bucket names. */
27
+ export type SuggestionGroup = {
28
+ heading: string
29
+ items: { name: string; note?: string }[]
30
+ }
31
+
32
+ interface CategorySelectorProps<TId extends string | number> {
33
+ /** The user's existing categories. */
34
+ categories: CategoryOption<TId>[]
35
+ isLoading?: boolean
36
+ value?: TId | null
37
+ onCategoryChange?: (categoryId: TId | null) => void
38
+ onNewCategoryChange?: (categoryName: string) => void
39
+ newCategoryValue?: string
40
+ className?: string
41
+ placeholder?: string
42
+ disabled?: boolean
43
+ /**
44
+ * Picking a suggestion selects the existing category with that name (case-insensitive),
45
+ * or opens the new-category input pre-filled with it.
46
+ */
47
+ suggestionGroups?: SuggestionGroup[]
48
+ /** Small print under the new-category input. */
49
+ newCategoryNote?: string
50
+ }
51
+
52
+ /** Combobox over the user's categories, with optional suggestion groups and "Add new category". */
53
+ export function CategorySelector<TId extends string | number = number>({
54
+ categories,
55
+ isLoading = false,
56
+ value,
57
+ onCategoryChange,
58
+ onNewCategoryChange,
59
+ newCategoryValue = "",
60
+ className,
61
+ placeholder = "Select category...",
62
+ disabled = false,
63
+ suggestionGroups,
64
+ newCategoryNote,
65
+ }: CategorySelectorProps<TId>) {
66
+ const [open, setOpen] = React.useState(false)
67
+ const [showNewInput, setShowNewInput] = React.useState(false)
68
+
69
+ const selectedCategory = categories.find((category) => category.id === value)
70
+ const groups = suggestionGroups?.filter((g) => g.items.length > 0) ?? []
71
+
72
+ const handleCategorySelect = (categoryId: TId) => {
73
+ onCategoryChange?.(categoryId)
74
+ setShowNewInput(false)
75
+ setOpen(false)
76
+ }
77
+
78
+ const handleAddNewCategory = () => {
79
+ onCategoryChange?.(null)
80
+ setShowNewInput(true)
81
+ setOpen(false)
82
+ }
83
+
84
+ // When a suggestion is picked: select existing match by ID, or pre-fill new-category input
85
+ const handleSuggestionSelect = (name: string) => {
86
+ const existing = categories.find((c) => c.name.toLowerCase() === name.toLowerCase())
87
+ if (existing) {
88
+ handleCategorySelect(existing.id)
89
+ } else {
90
+ onCategoryChange?.(null)
91
+ onNewCategoryChange?.(name)
92
+ setShowNewInput(true)
93
+ setOpen(false)
94
+ }
95
+ }
96
+
97
+ const isSuggestionSelected = (name: string) =>
98
+ selectedCategory?.name.toLowerCase() === name.toLowerCase() ||
99
+ newCategoryValue.toLowerCase() === name.toLowerCase()
100
+
101
+ return (
102
+ <div className={cn("space-y-2", className)}>
103
+ <Popover open={open} onOpenChange={setOpen}>
104
+ <PopoverTrigger asChild>
105
+ <Button
106
+ variant="outline"
107
+ role="combobox"
108
+ aria-expanded={open}
109
+ className="w-full justify-between"
110
+ disabled={disabled || isLoading}
111
+ >
112
+ {isLoading ? (
113
+ "Loading categories..."
114
+ ) : selectedCategory ? (
115
+ <div className="flex items-center gap-2">
116
+ {selectedCategory.color && (
117
+ <div
118
+ className="w-3 h-3 rounded-full"
119
+ style={{ backgroundColor: selectedCategory.color }}
120
+ />
121
+ )}
122
+ {selectedCategory.name}
123
+ </div>
124
+ ) : showNewInput ? (
125
+ "Add new category"
126
+ ) : (
127
+ placeholder
128
+ )}
129
+ <ChevronDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
130
+ </Button>
131
+ </PopoverTrigger>
132
+ <PopoverContent className="w-full p-0">
133
+ <Command>
134
+ <CommandInput placeholder="Search categories..." />
135
+ <CommandList>
136
+ <CommandEmpty>No categories found.</CommandEmpty>
137
+
138
+ <CommandGroup heading={groups.length ? "My Categories" : undefined}>
139
+ {categories.map((category) => (
140
+ <CommandItem
141
+ key={category.id}
142
+ value={category.name}
143
+ onSelect={() => handleCategorySelect(category.id)}
144
+ >
145
+ <div className="flex items-center gap-2 flex-1">
146
+ {category.color && (
147
+ <div
148
+ className="w-3 h-3 rounded-full"
149
+ style={{ backgroundColor: category.color }}
150
+ />
151
+ )}
152
+ {category.name}
153
+ </div>
154
+ <Check
155
+ className={cn(
156
+ "ml-auto h-4 w-4",
157
+ value === category.id ? "opacity-100" : "opacity-0"
158
+ )}
159
+ />
160
+ </CommandItem>
161
+ ))}
162
+ <CommandItem onSelect={handleAddNewCategory}>
163
+ <Plus className="mr-2 h-4 w-4" />
164
+ Add new category
165
+ </CommandItem>
166
+ </CommandGroup>
167
+
168
+ {groups.map((group) => (
169
+ <React.Fragment key={group.heading}>
170
+ <CommandSeparator />
171
+ <CommandGroup heading={group.heading}>
172
+ {group.items.map((s) => (
173
+ <CommandItem
174
+ key={s.name}
175
+ value={s.name}
176
+ onSelect={() => handleSuggestionSelect(s.name)}
177
+ >
178
+ <div className="flex flex-col flex-1 min-w-0">
179
+ <span className="truncate">{s.name}</span>
180
+ {s.note && (
181
+ <span className="text-xs text-muted-foreground truncate">{s.note}</span>
182
+ )}
183
+ </div>
184
+ <Check
185
+ className={cn(
186
+ "ml-2 h-4 w-4 shrink-0",
187
+ isSuggestionSelected(s.name) ? "opacity-100" : "opacity-0"
188
+ )}
189
+ />
190
+ </CommandItem>
191
+ ))}
192
+ </CommandGroup>
193
+ </React.Fragment>
194
+ ))}
195
+ </CommandList>
196
+ </Command>
197
+ </PopoverContent>
198
+ </Popover>
199
+
200
+ {/* New category input - shown when "Add new" is selected */}
201
+ {showNewInput && (
202
+ <>
203
+ <Input
204
+ placeholder="Enter new category name..."
205
+ value={newCategoryValue}
206
+ onChange={(e) => onNewCategoryChange?.(e.target.value)}
207
+ disabled={disabled}
208
+ autoFocus
209
+ />
210
+ {newCategoryNote && <Disclaimer disclaimerText={newCategoryNote} />}
211
+ </>
212
+ )}
213
+ </div>
214
+ )
215
+ }