@rise-x/apps-sdk 0.7.0 → 0.8.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/build/ui/components/accordion.d.ts +7 -0
- package/build/ui/components/aspect-ratio.d.ts +4 -0
- package/build/ui/components/button-group.d.ts +7 -0
- package/build/ui/components/carousel.d.ts +18 -0
- package/build/ui/components/chart.d.ts +45 -94
- package/build/ui/components/collapsible.d.ts +6 -0
- package/build/ui/components/combobox.d.ts +19 -0
- package/build/ui/components/command.d.ts +18 -0
- package/build/ui/components/context-menu.d.ts +29 -0
- package/build/ui/components/date-picker.d.ts +16 -0
- package/build/ui/components/direction.d.ts +6 -0
- package/build/ui/components/field.d.ts +25 -0
- package/build/ui/components/hover-card.d.ts +6 -0
- package/build/ui/components/input-group.d.ts +13 -0
- package/build/ui/components/input-otp.d.ts +34 -0
- package/build/ui/components/input.d.ts +1 -3
- package/build/ui/components/item.d.ts +23 -0
- package/build/ui/components/kbd.d.ts +4 -0
- package/build/ui/components/menubar.d.ts +26 -0
- package/build/ui/components/message-scroller.d.ts +15 -0
- package/build/ui/components/navigation-menu.d.ts +13 -0
- package/build/ui/components/page-header.d.ts +7 -1
- package/build/ui/index.d.ts +19 -0
- package/build/ui/reference/components/accordion.tsx +85 -0
- package/build/ui/reference/components/alert-dialog.tsx +1 -1
- package/build/ui/reference/components/aspect-ratio.tsx +28 -0
- package/build/ui/reference/components/button-group.tsx +77 -0
- package/build/ui/reference/components/carousel.tsx +248 -0
- package/build/ui/reference/components/chart.tsx +441 -1131
- package/build/ui/reference/components/collapsible.tsx +43 -0
- package/build/ui/reference/components/combobox.tsx +141 -0
- package/build/ui/reference/components/command.tsx +181 -0
- package/build/ui/reference/components/context-menu.tsx +243 -0
- package/build/ui/reference/components/data-table.tsx +3 -3
- package/build/ui/reference/components/date-picker.tsx +218 -0
- package/build/ui/reference/components/dialog.tsx +2 -2
- package/build/ui/reference/components/direction.tsx +22 -0
- package/build/ui/reference/components/field.tsx +252 -0
- package/build/ui/reference/components/hover-card.tsx +64 -0
- package/build/ui/reference/components/input-group.tsx +157 -0
- package/build/ui/reference/components/input-otp.tsx +106 -0
- package/build/ui/reference/components/input.tsx +4 -32
- package/build/ui/reference/components/item.tsx +188 -0
- package/build/ui/reference/components/kbd.tsx +43 -0
- package/build/ui/reference/components/label.tsx +1 -1
- package/build/ui/reference/components/menubar.tsx +275 -0
- package/build/ui/reference/components/message-scroller.tsx +141 -0
- package/build/ui/reference/components/nav.tsx +6 -0
- package/build/ui/reference/components/navigation-menu.tsx +191 -0
- package/build/ui/reference/components/page-header.tsx +32 -0
- package/build/ui/reference/components/popover.tsx +2 -2
- package/build/ui/reference/components/select.tsx +11 -8
- package/build/ui/reference/components/sheet.tsx +9 -1
- package/build/ui/reference/components/timeline.tsx +7 -0
- package/build/ui/reference/components/toggle.tsx +1 -1
- package/build/ui/reference/index.ts +19 -0
- package/build/ui/standalone.js +167 -28
- package/build/ui/styles.css +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { CalendarIcon, ChevronDownIcon } from 'lucide-react';
|
|
5
|
+
|
|
6
|
+
import { cn } from '@rise-x/ui/lib/utils';
|
|
7
|
+
import { Calendar, type CalendarDay } from '@rise-x/ui/components/calendar';
|
|
8
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@rise-x/ui/components/popover';
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Calendar plus Popover plus a field trigger. Calendar is deliberately dumb — it
|
|
12
|
+
* renders whatever days it is handed — so the month arithmetic lives here, once,
|
|
13
|
+
* instead of in every app that needs a date.
|
|
14
|
+
*
|
|
15
|
+
* DATES ARE BUILT FROM PARTS, NEVER PARSED FROM A DATE-ONLY STRING.
|
|
16
|
+
* `new Date("2027-08-31")` is parsed as UTC midnight, so anywhere west of London
|
|
17
|
+
* it renders as the 30th. Every Date in this file is constructed with
|
|
18
|
+
* `new Date(y, m, d)` (local midnight) and compared on its local parts. If you
|
|
19
|
+
* add a formatter, keep it on the parts too.
|
|
20
|
+
*
|
|
21
|
+
* The trigger is a FIELD, so it takes the brand focus ring like Input and Select —
|
|
22
|
+
* a control you commit data into, not one you merely operate.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const MONTHS = [
|
|
26
|
+
'January',
|
|
27
|
+
'February',
|
|
28
|
+
'March',
|
|
29
|
+
'April',
|
|
30
|
+
'May',
|
|
31
|
+
'June',
|
|
32
|
+
'July',
|
|
33
|
+
'August',
|
|
34
|
+
'September',
|
|
35
|
+
'October',
|
|
36
|
+
'November',
|
|
37
|
+
'December',
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
/** Monday-first, matching Calendar's own day-of-week header. */
|
|
41
|
+
function startOffset(year: number, month: number) {
|
|
42
|
+
const jsDay = new Date(year, month, 1).getDay(); // 0 = Sunday
|
|
43
|
+
return (jsDay + 6) % 7;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function daysInMonth(year: number, month: number) {
|
|
47
|
+
// day 0 of the next month is the last day of this one
|
|
48
|
+
return new Date(year, month + 1, 0).getDate();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Normalise the parts before comparing: buildDays pushes outside days with
|
|
52
|
+
* unnormalised indexes (month - 1 is -1 in January, month + 1 is 12 in
|
|
53
|
+
* December) and the year of the VIEW, while getMonth() only returns 0-11. Raw
|
|
54
|
+
* comparison therefore misses the selection and today ring on the adjacent
|
|
55
|
+
* month's cells at a year boundary — the same class as the trailing-day
|
|
56
|
+
* numbering bug. new Date(y, m, d) rolls both into range, which is why the
|
|
57
|
+
* range highlight (via dayValue) was never affected. */
|
|
58
|
+
function sameDay(a: Date | undefined, y: number, m: number, d: number) {
|
|
59
|
+
if (!a) return false;
|
|
60
|
+
const b = new Date(y, m, d);
|
|
61
|
+
return (
|
|
62
|
+
a.getFullYear() === b.getFullYear() &&
|
|
63
|
+
a.getMonth() === b.getMonth() &&
|
|
64
|
+
a.getDate() === b.getDate()
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Local-midnight comparison, so a time component can never flip the answer. */
|
|
69
|
+
function dayValue(y: number, m: number, d: number) {
|
|
70
|
+
return new Date(y, m, d).setHours(0, 0, 0, 0);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface DatePickerRange {
|
|
74
|
+
from?: Date;
|
|
75
|
+
to?: Date;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function buildDays(
|
|
79
|
+
year: number,
|
|
80
|
+
month: number,
|
|
81
|
+
selected: Date | undefined,
|
|
82
|
+
range: DatePickerRange | undefined,
|
|
83
|
+
): Array<CalendarDay & { y: number; m: number; d: number }> {
|
|
84
|
+
const out: Array<CalendarDay & { y: number; m: number; d: number }> = [];
|
|
85
|
+
const lead = startOffset(year, month);
|
|
86
|
+
const prevCount = daysInMonth(year, month - 1);
|
|
87
|
+
const today = new Date();
|
|
88
|
+
|
|
89
|
+
const push = (y: number, m: number, d: number, outside: boolean) => {
|
|
90
|
+
const v = dayValue(y, m, d);
|
|
91
|
+
let position: CalendarDay['range'];
|
|
92
|
+
if (range?.from && range?.to) {
|
|
93
|
+
const from = dayValue(range.from.getFullYear(), range.from.getMonth(), range.from.getDate());
|
|
94
|
+
const to = dayValue(range.to.getFullYear(), range.to.getMonth(), range.to.getDate());
|
|
95
|
+
if (v === from) position = 'start';
|
|
96
|
+
else if (v === to) position = 'end';
|
|
97
|
+
else if (v > from && v < to) position = 'in';
|
|
98
|
+
} else if (
|
|
99
|
+
range?.from &&
|
|
100
|
+
dayValue(range.from.getFullYear(), range.from.getMonth(), range.from.getDate()) === v
|
|
101
|
+
) {
|
|
102
|
+
position = 'start';
|
|
103
|
+
} else if (sameDay(selected, y, m, d)) {
|
|
104
|
+
// a single selected date is drawn as a one-day span, so selection looks the
|
|
105
|
+
// same whether the picker is in single or range mode
|
|
106
|
+
position = 'start';
|
|
107
|
+
}
|
|
108
|
+
out.push({
|
|
109
|
+
label: d,
|
|
110
|
+
outside: outside || undefined,
|
|
111
|
+
today: sameDay(today, y, m, d) || undefined,
|
|
112
|
+
range: position,
|
|
113
|
+
y,
|
|
114
|
+
m,
|
|
115
|
+
d,
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
for (let i = lead; i > 0; i--) push(year, month - 1, prevCount - i + 1, true);
|
|
120
|
+
for (let d = 1; d <= daysInMonth(year, month); d++) push(year, month, d, false);
|
|
121
|
+
// fill to a whole number of weeks so the grid never reflows between months.
|
|
122
|
+
// The trailing days count from 1, so they need their own counter — deriving
|
|
123
|
+
// the number from out.length numbered them by grid position instead.
|
|
124
|
+
for (let d = 1; out.length % 7 !== 0; d++) push(year, month + 1, d, true);
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const DatePicker = React.forwardRef<
|
|
129
|
+
HTMLButtonElement,
|
|
130
|
+
Omit<React.ComponentProps<'button'>, 'value' | 'onChange'> & {
|
|
131
|
+
value?: Date;
|
|
132
|
+
onValueChange?: (date: Date) => void;
|
|
133
|
+
/** Renders a range span instead of a single day. Selection stays the caller's. */
|
|
134
|
+
range?: DatePickerRange;
|
|
135
|
+
placeholder?: string;
|
|
136
|
+
/** Formats the trigger label. Keep it on the date's local parts. */
|
|
137
|
+
format?: (date: Date) => string;
|
|
138
|
+
footer?: React.ReactNode;
|
|
139
|
+
}
|
|
140
|
+
>(function DatePicker(
|
|
141
|
+
{ className, value, onValueChange, range, placeholder = 'Pick a date', format, footer, ...props },
|
|
142
|
+
ref,
|
|
143
|
+
) {
|
|
144
|
+
const [open, setOpen] = React.useState(false);
|
|
145
|
+
const anchor = value ?? range?.from ?? new Date();
|
|
146
|
+
const [view, setView] = React.useState({ y: anchor.getFullYear(), m: anchor.getMonth() });
|
|
147
|
+
|
|
148
|
+
/* Follow the selection when it changes from outside — a preset button or a
|
|
149
|
+
* form reset writes a new value while the popover is closed, and reopening
|
|
150
|
+
* on the month captured at first render hides the day that was just picked.
|
|
151
|
+
* Only the anchor's month is a dependency, so paging stays the user's. */
|
|
152
|
+
const anchorMonth = `${anchor.getFullYear()}-${anchor.getMonth()}`;
|
|
153
|
+
React.useEffect(() => {
|
|
154
|
+
const [y, m] = anchorMonth.split('-').map(Number);
|
|
155
|
+
setView({ y, m });
|
|
156
|
+
}, [anchorMonth]);
|
|
157
|
+
|
|
158
|
+
const label = React.useMemo(() => {
|
|
159
|
+
const show = (d: Date) =>
|
|
160
|
+
format ? format(d) : `${d.getDate()} ${MONTHS[d.getMonth()].slice(0, 3)} ${d.getFullYear()}`;
|
|
161
|
+
if (range?.from && range?.to) return `${show(range.from)} – ${show(range.to)}`;
|
|
162
|
+
if (value) return show(value);
|
|
163
|
+
return null;
|
|
164
|
+
}, [value, range?.from, range?.to, format]);
|
|
165
|
+
|
|
166
|
+
const days = buildDays(view.y, view.m, value, range);
|
|
167
|
+
const step = (delta: number) => {
|
|
168
|
+
const next = new Date(view.y, view.m + delta, 1);
|
|
169
|
+
setView({ y: next.getFullYear(), m: next.getMonth() });
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
174
|
+
<PopoverTrigger asChild>
|
|
175
|
+
<button
|
|
176
|
+
ref={ref}
|
|
177
|
+
type="button"
|
|
178
|
+
data-slot="date-picker-trigger"
|
|
179
|
+
data-placeholder={label ? undefined : ''}
|
|
180
|
+
className={cn(
|
|
181
|
+
'flex h-control w-full items-center gap-1.5 rounded-lg border border-input bg-card px-2.5 text-ui whitespace-nowrap transition-[border-color,box-shadow] duration-100 outline-none',
|
|
182
|
+
'focus-visible:border-brand focus-visible:ring-3 focus-visible:ring-brand/12',
|
|
183
|
+
'disabled:cursor-not-allowed disabled:bg-muted disabled:text-subtle',
|
|
184
|
+
'aria-invalid:border-error aria-invalid:focus-visible:border-error aria-invalid:focus-visible:ring-error/18',
|
|
185
|
+
'[&>svg]:pointer-events-none [&>svg]:size-3.5 [&>svg]:shrink-0 [&>svg]:text-subtle',
|
|
186
|
+
className,
|
|
187
|
+
)}
|
|
188
|
+
{...props}
|
|
189
|
+
>
|
|
190
|
+
<CalendarIcon />
|
|
191
|
+
{/* muted-foreground, the same placeholder tone as Select and Combobox */}
|
|
192
|
+
<span className={cn('min-w-0 flex-1 text-left', !label && 'text-muted-foreground')}>
|
|
193
|
+
{label ?? placeholder}
|
|
194
|
+
</span>
|
|
195
|
+
<ChevronDownIcon className="text-muted-foreground!" />
|
|
196
|
+
</button>
|
|
197
|
+
</PopoverTrigger>
|
|
198
|
+
{/* Popover's own padding and width would fight the calendar, which brings
|
|
199
|
+
its own 14px padding and fixed 294px width. */}
|
|
200
|
+
<PopoverContent align="start" className="w-auto gap-0 p-0 shadow-none">
|
|
201
|
+
<Calendar
|
|
202
|
+
title={`${MONTHS[view.m]} ${view.y}`}
|
|
203
|
+
days={days}
|
|
204
|
+
onPrev={() => step(-1)}
|
|
205
|
+
onNext={() => step(1)}
|
|
206
|
+
onSelectDay={(_day, index) => {
|
|
207
|
+
const picked = days[index];
|
|
208
|
+
onValueChange?.(new Date(picked.y, picked.m, picked.d));
|
|
209
|
+
setOpen(false);
|
|
210
|
+
}}
|
|
211
|
+
footer={footer}
|
|
212
|
+
/>
|
|
213
|
+
</PopoverContent>
|
|
214
|
+
</Popover>
|
|
215
|
+
);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
export { DatePicker };
|
|
@@ -72,7 +72,7 @@ const DialogContent = React.forwardRef<
|
|
|
72
72
|
ref={ref}
|
|
73
73
|
data-slot="dialog-content"
|
|
74
74
|
className={cn(
|
|
75
|
-
'fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-(var(--spacing)*8))] -translate-x-1/2 -translate-y-1/2 gap-6 rounded-2xl bg-popover p-6 text-
|
|
75
|
+
'fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-(var(--spacing)*8))] -translate-x-1/2 -translate-y-1/2 gap-6 rounded-2xl bg-popover p-6 text-ui text-popover-foreground shadow-pop duration-100 outline-none sm:max-w-md data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95',
|
|
76
76
|
className,
|
|
77
77
|
)}
|
|
78
78
|
{...props}
|
|
@@ -150,7 +150,7 @@ const DialogDescription = React.forwardRef<
|
|
|
150
150
|
ref={ref}
|
|
151
151
|
data-slot="dialog-description"
|
|
152
152
|
className={cn(
|
|
153
|
-
'text-
|
|
153
|
+
'text-ui text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground',
|
|
154
154
|
className,
|
|
155
155
|
)}
|
|
156
156
|
{...props}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Direction as DirectionPrimitive } from 'radix-ui';
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Reading direction for every Radix primitive beneath it. Not a visual component
|
|
6
|
+
* — it renders no DOM node at all — but it is the switch that makes the whole kit
|
|
7
|
+
* behave in RTL: menus align from the other edge, sliders fill the other way,
|
|
8
|
+
* and arrow keys reverse.
|
|
9
|
+
*
|
|
10
|
+
* WHY IT HAS TO BE EXPLICIT. Radix reads direction from this provider, not from
|
|
11
|
+
* the `dir` attribute on `<html>`, so setting `dir="rtl"` on the document flips
|
|
12
|
+
* CSS but leaves every popper anchored and every arrow key pointing the wrong
|
|
13
|
+
* way. The host owns the document attribute; this owns the primitives. Set both.
|
|
14
|
+
*
|
|
15
|
+
* Mount it once, above the app — a federated app inherits it from the host along
|
|
16
|
+
* with everything else, so an app should not normally render its own.
|
|
17
|
+
*/
|
|
18
|
+
function DirectionProvider({ dir, children }: { dir: 'ltr' | 'rtl'; children?: React.ReactNode }) {
|
|
19
|
+
return <DirectionPrimitive.Provider dir={dir}>{children}</DirectionPrimitive.Provider>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { DirectionProvider };
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
5
|
+
|
|
6
|
+
import { cn } from '@rise-x/ui/lib/utils';
|
|
7
|
+
import { Label } from '@rise-x/ui/components/label';
|
|
8
|
+
import { Separator } from '@rise-x/ui/components/separator';
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Form scaffolding: label + control + helper + error as ONE addressable unit,
|
|
12
|
+
* so spacing between them is owned here and never re-invented per form.
|
|
13
|
+
*
|
|
14
|
+
* The error slot REPLACES the description rather than stacking under it — a
|
|
15
|
+
* field explains itself or reports a problem, never both at once, and the row
|
|
16
|
+
* keeps its height when validation fires.
|
|
17
|
+
*
|
|
18
|
+
* A FieldLabel wrapping a whole Field becomes a selectable choice card. The
|
|
19
|
+
* checked affirmation is BRAND (border + tint), same rule as Input focus:
|
|
20
|
+
* committing data gets brand, operating chrome gets grey.
|
|
21
|
+
*/
|
|
22
|
+
function FieldSet({ className, ...props }: React.ComponentProps<'fieldset'>) {
|
|
23
|
+
return (
|
|
24
|
+
<fieldset
|
|
25
|
+
data-slot="field-set"
|
|
26
|
+
className={cn(
|
|
27
|
+
'flex flex-col gap-6',
|
|
28
|
+
'has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3',
|
|
29
|
+
className,
|
|
30
|
+
)}
|
|
31
|
+
{...props}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function FieldLegend({
|
|
37
|
+
className,
|
|
38
|
+
variant = 'legend',
|
|
39
|
+
...props
|
|
40
|
+
}: React.ComponentProps<'legend'> & { variant?: 'legend' | 'label' }) {
|
|
41
|
+
return (
|
|
42
|
+
<legend
|
|
43
|
+
data-slot="field-legend"
|
|
44
|
+
data-variant={variant}
|
|
45
|
+
className={cn(
|
|
46
|
+
'mb-3 font-medium',
|
|
47
|
+
/* legend heads a group of fields, label matches a single Label.
|
|
48
|
+
* 17px is the scale's step above the 13px body — text-base would add a
|
|
49
|
+
* sixth size to a documented five-size scale. */
|
|
50
|
+
'data-[variant=legend]:text-[17px]',
|
|
51
|
+
'data-[variant=label]:text-ui',
|
|
52
|
+
className,
|
|
53
|
+
)}
|
|
54
|
+
{...props}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function FieldGroup({ className, ...props }: React.ComponentProps<'div'>) {
|
|
60
|
+
return (
|
|
61
|
+
<div
|
|
62
|
+
data-slot="field-group"
|
|
63
|
+
className={cn(
|
|
64
|
+
'group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4',
|
|
65
|
+
className,
|
|
66
|
+
)}
|
|
67
|
+
{...props}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const fieldVariants = cva('group/field flex w-full gap-3 data-[invalid=true]:text-error-text', {
|
|
73
|
+
variants: {
|
|
74
|
+
orientation: {
|
|
75
|
+
vertical: ['flex-col [&>*]:w-full [&>.sr-only]:w-auto'],
|
|
76
|
+
horizontal: [
|
|
77
|
+
'flex-row items-center',
|
|
78
|
+
'[&>[data-slot=field-label]]:flex-auto',
|
|
79
|
+
'has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px',
|
|
80
|
+
],
|
|
81
|
+
responsive: [
|
|
82
|
+
'flex-col @md/field-group:flex-row @md/field-group:items-center [&>*]:w-full @md/field-group:[&>*]:w-auto [&>.sr-only]:w-auto',
|
|
83
|
+
'@md/field-group:[&>[data-slot=field-label]]:flex-auto',
|
|
84
|
+
'@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px',
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
defaultVariants: {
|
|
89
|
+
orientation: 'vertical',
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
function Field({
|
|
94
|
+
className,
|
|
95
|
+
orientation = 'vertical',
|
|
96
|
+
...props
|
|
97
|
+
}: React.ComponentProps<'div'> & VariantProps<typeof fieldVariants>) {
|
|
98
|
+
return (
|
|
99
|
+
<div
|
|
100
|
+
role="group"
|
|
101
|
+
data-slot="field"
|
|
102
|
+
data-orientation={orientation}
|
|
103
|
+
className={cn(fieldVariants({ orientation }), className)}
|
|
104
|
+
{...props}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function FieldContent({ className, ...props }: React.ComponentProps<'div'>) {
|
|
110
|
+
return (
|
|
111
|
+
<div
|
|
112
|
+
data-slot="field-content"
|
|
113
|
+
className={cn('group/field-content flex flex-1 flex-col gap-1.5 leading-snug', className)}
|
|
114
|
+
{...props}
|
|
115
|
+
/>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function FieldLabel({ className, ...props }: React.ComponentProps<typeof Label>) {
|
|
120
|
+
return (
|
|
121
|
+
<Label
|
|
122
|
+
data-slot="field-label"
|
|
123
|
+
className={cn(
|
|
124
|
+
'group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50',
|
|
125
|
+
// wrapping a whole Field turns the label into a choice card
|
|
126
|
+
'has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-lg has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4',
|
|
127
|
+
'has-data-[state=checked]:border-brand has-data-[state=checked]:bg-brand-tint',
|
|
128
|
+
className,
|
|
129
|
+
)}
|
|
130
|
+
{...props}
|
|
131
|
+
/>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function FieldTitle({ className, ...props }: React.ComponentProps<'div'>) {
|
|
136
|
+
return (
|
|
137
|
+
<div
|
|
138
|
+
data-slot="field-label"
|
|
139
|
+
className={cn(
|
|
140
|
+
'flex w-fit items-center gap-2 text-ui leading-snug font-medium group-data-[disabled=true]/field:opacity-50',
|
|
141
|
+
className,
|
|
142
|
+
)}
|
|
143
|
+
{...props}
|
|
144
|
+
/>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function FieldDescription({ className, ...props }: React.ComponentProps<'p'>) {
|
|
149
|
+
return (
|
|
150
|
+
<p
|
|
151
|
+
data-slot="field-description"
|
|
152
|
+
className={cn(
|
|
153
|
+
// helper text is meta, one step below the label — same step as CardDescription
|
|
154
|
+
'text-xs leading-normal font-normal text-muted-foreground group-has-[[data-orientation=horizontal]]/field:text-balance',
|
|
155
|
+
'last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5',
|
|
156
|
+
'[&>a]:underline [&>a]:underline-offset-3 [&>a:hover]:text-foreground',
|
|
157
|
+
className,
|
|
158
|
+
)}
|
|
159
|
+
{...props}
|
|
160
|
+
/>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function FieldSeparator({
|
|
165
|
+
children,
|
|
166
|
+
className,
|
|
167
|
+
...props
|
|
168
|
+
}: React.ComponentProps<'div'> & {
|
|
169
|
+
children?: React.ReactNode;
|
|
170
|
+
}) {
|
|
171
|
+
return (
|
|
172
|
+
<div
|
|
173
|
+
data-slot="field-separator"
|
|
174
|
+
data-content={!!children}
|
|
175
|
+
className={cn(
|
|
176
|
+
'relative -my-2 h-5 text-xs group-data-[variant=outline]/field-group:-mb-2',
|
|
177
|
+
className,
|
|
178
|
+
)}
|
|
179
|
+
{...props}
|
|
180
|
+
>
|
|
181
|
+
<Separator className="absolute inset-0 top-1/2" />
|
|
182
|
+
{children && (
|
|
183
|
+
<span
|
|
184
|
+
// forms sit on the card surface, so the chip masks with bg-card
|
|
185
|
+
className="relative mx-auto block w-fit bg-card px-2 text-muted-foreground"
|
|
186
|
+
data-slot="field-separator-content"
|
|
187
|
+
>
|
|
188
|
+
{children}
|
|
189
|
+
</span>
|
|
190
|
+
)}
|
|
191
|
+
</div>
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function FieldError({
|
|
196
|
+
className,
|
|
197
|
+
children,
|
|
198
|
+
errors,
|
|
199
|
+
...props
|
|
200
|
+
}: React.ComponentProps<'div'> & {
|
|
201
|
+
errors?: Array<{ message?: string } | undefined>;
|
|
202
|
+
}) {
|
|
203
|
+
const content = React.useMemo(() => {
|
|
204
|
+
if (children) {
|
|
205
|
+
return children;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (!errors?.length) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const uniqueErrors = [...new Map(errors.map((error) => [error?.message, error])).values()];
|
|
213
|
+
|
|
214
|
+
if (uniqueErrors?.length === 1) {
|
|
215
|
+
return uniqueErrors[0]?.message;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
<ul className="ml-4 flex list-disc flex-col gap-1">
|
|
220
|
+
{uniqueErrors.map((error, index) => error?.message && <li key={index}>{error.message}</li>)}
|
|
221
|
+
</ul>
|
|
222
|
+
);
|
|
223
|
+
}, [children, errors]);
|
|
224
|
+
|
|
225
|
+
if (!content) {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return (
|
|
230
|
+
<div
|
|
231
|
+
role="alert"
|
|
232
|
+
data-slot="field-error"
|
|
233
|
+
className={cn('text-xs font-normal text-error-text', className)}
|
|
234
|
+
{...props}
|
|
235
|
+
>
|
|
236
|
+
{content}
|
|
237
|
+
</div>
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export {
|
|
242
|
+
Field,
|
|
243
|
+
FieldLabel,
|
|
244
|
+
FieldDescription,
|
|
245
|
+
FieldError,
|
|
246
|
+
FieldGroup,
|
|
247
|
+
FieldLegend,
|
|
248
|
+
FieldSeparator,
|
|
249
|
+
FieldSet,
|
|
250
|
+
FieldContent,
|
|
251
|
+
FieldTitle,
|
|
252
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { HoverCard as HoverCardPrimitive } from 'radix-ui';
|
|
5
|
+
|
|
6
|
+
import { cn } from '@rise-x/ui/lib/utils';
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* A preview on hover — who a person is, what a reference points at — without
|
|
10
|
+
* leaving the page. Same surface as Popover (14px, shadow-pop, 16px padding),
|
|
11
|
+
* because it is the same object; only the way it opens differs.
|
|
12
|
+
*
|
|
13
|
+
* IT OPENS ON A DELAY AND IT IS NEVER THE ONLY PATH. 300ms in, 150ms out: opening
|
|
14
|
+
* instantly turns every stray cursor sweep into a flash of cards, and closing
|
|
15
|
+
* instantly makes the card impossible to move onto. Hover does not exist on touch
|
|
16
|
+
* and is invisible to keyboard-only use, so whatever is in here must also be
|
|
17
|
+
* reachable by clicking the thing it describes.
|
|
18
|
+
*
|
|
19
|
+
* NOTHING INTERACTIVE INSIDE. A hover card that holds a button asks the user to
|
|
20
|
+
* keep the pointer inside a shape they cannot see the edges of. Use Popover for
|
|
21
|
+
* anything with a control in it.
|
|
22
|
+
*/
|
|
23
|
+
function HoverCard({
|
|
24
|
+
openDelay = 300,
|
|
25
|
+
closeDelay = 150,
|
|
26
|
+
...props
|
|
27
|
+
}: React.ComponentProps<typeof HoverCardPrimitive.Root>) {
|
|
28
|
+
return (
|
|
29
|
+
<HoverCardPrimitive.Root
|
|
30
|
+
data-slot="hover-card"
|
|
31
|
+
openDelay={openDelay}
|
|
32
|
+
closeDelay={closeDelay}
|
|
33
|
+
{...props}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function HoverCardTrigger({ ...props }: React.ComponentProps<typeof HoverCardPrimitive.Trigger>) {
|
|
39
|
+
return <HoverCardPrimitive.Trigger data-slot="hover-card-trigger" {...props} />;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function HoverCardContent({
|
|
43
|
+
className,
|
|
44
|
+
align = 'center',
|
|
45
|
+
sideOffset = 4,
|
|
46
|
+
...props
|
|
47
|
+
}: React.ComponentProps<typeof HoverCardPrimitive.Content>) {
|
|
48
|
+
return (
|
|
49
|
+
<HoverCardPrimitive.Portal>
|
|
50
|
+
<HoverCardPrimitive.Content
|
|
51
|
+
data-slot="hover-card-content"
|
|
52
|
+
align={align}
|
|
53
|
+
sideOffset={sideOffset}
|
|
54
|
+
className={cn(
|
|
55
|
+
'z-50 flex w-64 origin-(--radix-hover-card-content-transform-origin) flex-col gap-2.5 rounded-xl bg-popover p-4 text-xs text-popover-foreground shadow-pop outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:ring-foreground/10 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95',
|
|
56
|
+
className,
|
|
57
|
+
)}
|
|
58
|
+
{...props}
|
|
59
|
+
/>
|
|
60
|
+
</HoverCardPrimitive.Portal>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { HoverCard, HoverCardTrigger, HoverCardContent };
|