@xk2800/nextjs-template 0.7.1-beta.8 → 0.7.2-beta.0
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/components/auth/oneTap.tsx +15 -5
- package/components/dashboard/admin/adminActivityLogsTable.tsx +4 -0
- package/components/dashboard/admin/adminUsersTable.tsx +154 -34
- package/components/dashboard/admin/impersonationLogCard.tsx +2 -2
- package/components/dashboard/appSidebar.tsx +2 -2
- package/components/dashboard/deleteAccountCard.tsx +31 -4
- package/components/dashboard/navStyleToggle.tsx +29 -0
- package/components/dashboard/topNav.tsx +95 -0
- package/components/email/email-template-banned.tsx +53 -0
- package/components/ui/alert-dialog.tsx +2 -2
- package/components/ui/avatar.tsx +1 -1
- package/components/ui/badge.tsx +5 -3
- package/components/ui/calendar.tsx +220 -0
- package/components/ui/card.tsx +1 -1
- package/components/ui/category-selector.tsx +215 -0
- package/components/ui/chart.tsx +374 -0
- package/components/ui/column-picker.tsx +140 -0
- package/components/ui/command.tsx +184 -0
- package/components/ui/data-table.tsx +44 -6
- package/components/ui/date-picker-with-presets.tsx +122 -0
- package/components/ui/dialog.tsx +2 -2
- package/components/ui/disclaimer.tsx +4 -0
- package/components/ui/dropdown-menu.tsx +3 -3
- package/components/ui/field.tsx +248 -0
- package/components/ui/info-tooltip.tsx +53 -0
- package/components/ui/input.tsx +10 -1
- package/components/ui/label.tsx +1 -1
- package/components/ui/month-selector.tsx +194 -0
- package/components/ui/navigation-menu.tsx +168 -0
- package/components/ui/pagination.tsx +127 -0
- package/components/ui/popover.tsx +89 -0
- package/components/ui/select.tsx +1 -1
- package/components/ui/source-selector.tsx +164 -0
- package/components/ui/switch.tsx +3 -3
- package/dist/activity/logger.d.mts +3 -1
- package/dist/activity/logger.d.ts +3 -1
- package/dist/activity/logger.js +20 -0
- package/dist/activity/logger.js.map +1 -1
- package/dist/activity/logger.mjs +4 -4
- package/dist/activity/queries.d.mts +1 -1
- package/dist/activity/queries.d.ts +1 -1
- package/dist/activity/queries.js +20 -0
- package/dist/activity/queries.js.map +1 -1
- package/dist/activity/queries.mjs +3 -3
- package/dist/admin/queries.js +20 -0
- package/dist/admin/queries.js.map +1 -1
- package/dist/admin/queries.mjs +3 -3
- package/dist/api/feedback.js +527 -70
- package/dist/api/feedback.js.map +1 -1
- package/dist/api/feedback.mjs +8 -8
- package/dist/api/marketing.js +527 -70
- package/dist/api/marketing.js.map +1 -1
- package/dist/api/marketing.mjs +10 -10
- package/dist/auth/helpers.js +525 -68
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/helpers.mjs +8 -8
- package/dist/auth/index.d.mts +149 -10
- package/dist/auth/index.d.ts +149 -10
- package/dist/auth/index.js +525 -68
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +7 -7
- package/dist/{chunk-ZJMFE5B2.mjs → chunk-4C7JHGT5.mjs} +4 -4
- package/dist/{chunk-ZJMFE5B2.mjs.map → chunk-4C7JHGT5.mjs.map} +1 -1
- package/dist/{chunk-7F2POZM6.mjs → chunk-4F6KE47S.mjs} +4 -4
- package/dist/chunk-4F6KE47S.mjs.map +1 -0
- package/dist/{chunk-P2G23JMY.mjs → chunk-A6JXMHOQ.mjs} +5 -5
- package/dist/{chunk-P2G23JMY.mjs.map → chunk-A6JXMHOQ.mjs.map} +1 -1
- package/dist/{chunk-TKWNEKK6.mjs → chunk-HUEDEAY3.mjs} +8 -2
- package/dist/chunk-HUEDEAY3.mjs.map +1 -0
- package/dist/{chunk-6Z3WUSDJ.mjs → chunk-JUSU6UZA.mjs} +5 -5
- package/dist/{chunk-6Z3WUSDJ.mjs.map → chunk-JUSU6UZA.mjs.map} +1 -1
- package/dist/{chunk-TR5XFBTD.mjs → chunk-KA2KMGPY.mjs} +17 -3
- package/dist/chunk-KA2KMGPY.mjs.map +1 -0
- package/dist/{chunk-OVKVD2HH.mjs → chunk-L242CZ64.mjs} +3 -3
- package/dist/{chunk-OVKVD2HH.mjs.map → chunk-L242CZ64.mjs.map} +1 -1
- package/dist/{chunk-C6RGN6QA.mjs → chunk-NQELV53D.mjs} +4 -4
- package/dist/{chunk-C6RGN6QA.mjs.map → chunk-NQELV53D.mjs.map} +1 -1
- package/dist/chunk-VHNGYAIG.mjs +899 -0
- package/dist/chunk-VHNGYAIG.mjs.map +1 -0
- package/dist/{chunk-6MDQRT6U.mjs → chunk-YH53UPUW.mjs} +4 -4
- package/dist/{chunk-6MDQRT6U.mjs.map → chunk-YH53UPUW.mjs.map} +1 -1
- package/dist/config/env.d.mts +2 -0
- package/dist/config/env.d.ts +2 -0
- package/dist/config/env.js +6 -0
- package/dist/config/env.js.map +1 -1
- package/dist/config/env.mjs +1 -1
- package/dist/db/index.d.mts +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +20 -0
- package/dist/db/index.js.map +1 -1
- package/dist/db/index.mjs +3 -3
- package/dist/db/schema.d.mts +1 -1
- package/dist/db/schema.d.ts +1 -1
- package/dist/db/schema.js +14 -0
- package/dist/db/schema.js.map +1 -1
- package/dist/db/schema.mjs +1 -1
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +4 -4
- package/dist/marketing/index.js +6 -0
- package/dist/marketing/index.js.map +1 -1
- package/dist/marketing/index.mjs +3 -3
- package/dist/{schema-CN_Y6EXv.d.mts → schema-DzC5zdOq.d.mts} +146 -2
- package/dist/{schema-CN_Y6EXv.d.ts → schema-DzC5zdOq.d.ts} +146 -2
- package/dist/sessions/queries.js +20 -0
- package/dist/sessions/queries.js.map +1 -1
- package/dist/sessions/queries.mjs +3 -3
- package/dist/settings/queries.d.mts +1 -1
- package/dist/settings/queries.d.ts +1 -1
- package/dist/settings/queries.js +20 -0
- package/dist/settings/queries.js.map +1 -1
- package/dist/settings/queries.mjs +4 -4
- package/dist/users/queries.d.mts +3 -0
- package/dist/users/queries.d.ts +3 -0
- package/dist/users/queries.js +20 -0
- package/dist/users/queries.js.map +1 -1
- package/dist/users/queries.mjs +3 -3
- package/lib/recalculate-columns.ts +8 -2
- package/package.json +28 -18
- package/styles/theme.css +23 -3
- package/dist/chunk-7F2POZM6.mjs.map +0 -1
- package/dist/chunk-7QVIOQ47.mjs +0 -462
- package/dist/chunk-7QVIOQ47.mjs.map +0 -1
- package/dist/chunk-TKWNEKK6.mjs.map +0 -1
- package/dist/chunk-TR5XFBTD.mjs.map +0 -1
package/components/ui/badge.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from "react"
|
|
2
|
-
import { Slot } from "
|
|
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"
|
|
6
6
|
|
|
7
7
|
const badgeVariants = cva(
|
|
8
|
-
"inline-flex items-center justify-center rounded-
|
|
8
|
+
"inline-flex items-center justify-center rounded-(--pill-radius) border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
|
9
9
|
{
|
|
10
10
|
variants: {
|
|
11
11
|
variant: {
|
|
@@ -17,6 +17,8 @@ const badgeVariants = cva(
|
|
|
17
17
|
"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
18
18
|
outline:
|
|
19
19
|
"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
|
20
|
+
success:
|
|
21
|
+
"border-transparent bg-success text-success-foreground [a&]:hover:bg-success/90",
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
defaultVariants: {
|
|
@@ -32,7 +34,7 @@ function Badge({
|
|
|
32
34
|
...props
|
|
33
35
|
}: React.ComponentProps<"span"> &
|
|
34
36
|
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
|
35
|
-
const Comp = asChild ? Slot : "span"
|
|
37
|
+
const Comp = asChild ? Slot.Root : "span"
|
|
36
38
|
|
|
37
39
|
return (
|
|
38
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 }
|
package/components/ui/card.tsx
CHANGED
|
@@ -7,7 +7,7 @@ function Card({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
7
7
|
<div
|
|
8
8
|
data-slot="card"
|
|
9
9
|
className={cn(
|
|
10
|
-
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-
|
|
10
|
+
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border-(length:--surface-border-width) border-(--surface-border-color) py-6 shadow-(--card-shadow)",
|
|
11
11
|
className
|
|
12
12
|
)}
|
|
13
13
|
{...props}
|
|
@@ -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
|
+
}
|