@rise-x/apps-sdk 0.9.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +117 -32
  2. package/build/rsbuild/index.d.ts +6 -1
  3. package/build/rsbuild/index.js +24 -3
  4. package/build/ui/classes.json +209 -0
  5. package/build/ui/components/ai.d.ts +33 -1
  6. package/build/ui/components/app-frame.d.ts +16 -10
  7. package/build/ui/components/chat-input.d.ts +28 -0
  8. package/build/ui/components/message-scroller.d.ts +34 -10
  9. package/build/ui/components/sheet.d.ts +10 -0
  10. package/build/ui/components/thinking-rings.d.ts +4 -0
  11. package/build/ui/demo.html +26794 -0
  12. package/build/ui/index.d.ts +2 -0
  13. package/build/ui/standalone.js +60 -58
  14. package/build/ui/styles.css +1 -1
  15. package/package.json +4 -3
  16. package/template/AGENTS.md +3 -3
  17. package/template/README.md +5 -5
  18. package/template/package.json +8 -9
  19. package/template/rsbuild.config.mts +17 -0
  20. package/template/src/App.tsx +4 -1
  21. package/template/tsconfig.json +3 -1
  22. package/build/ui/reference/README.md +0 -11
  23. package/build/ui/reference/components/accordion.tsx +0 -85
  24. package/build/ui/reference/components/ai.tsx +0 -293
  25. package/build/ui/reference/components/alert-dialog.tsx +0 -207
  26. package/build/ui/reference/components/alert.tsx +0 -112
  27. package/build/ui/reference/components/app-frame.tsx +0 -71
  28. package/build/ui/reference/components/aspect-ratio.tsx +0 -28
  29. package/build/ui/reference/components/avatar.tsx +0 -158
  30. package/build/ui/reference/components/badge.tsx +0 -160
  31. package/build/ui/reference/components/button-group.tsx +0 -77
  32. package/build/ui/reference/components/button.tsx +0 -109
  33. package/build/ui/reference/components/calendar.tsx +0 -119
  34. package/build/ui/reference/components/card.tsx +0 -144
  35. package/build/ui/reference/components/carousel.tsx +0 -248
  36. package/build/ui/reference/components/chart.tsx +0 -704
  37. package/build/ui/reference/components/checkbox.tsx +0 -44
  38. package/build/ui/reference/components/collapsible.tsx +0 -43
  39. package/build/ui/reference/components/combobox.tsx +0 -146
  40. package/build/ui/reference/components/command.tsx +0 -181
  41. package/build/ui/reference/components/context-menu.tsx +0 -243
  42. package/build/ui/reference/components/data-table.tsx +0 -650
  43. package/build/ui/reference/components/date-picker.tsx +0 -218
  44. package/build/ui/reference/components/dialog.tsx +0 -172
  45. package/build/ui/reference/components/direction.tsx +0 -22
  46. package/build/ui/reference/components/dropdown-menu.tsx +0 -245
  47. package/build/ui/reference/components/empty-state.tsx +0 -63
  48. package/build/ui/reference/components/field.tsx +0 -252
  49. package/build/ui/reference/components/file-upload.tsx +0 -116
  50. package/build/ui/reference/components/hover-card.tsx +0 -64
  51. package/build/ui/reference/components/input-group.tsx +0 -157
  52. package/build/ui/reference/components/input-otp.tsx +0 -106
  53. package/build/ui/reference/components/input.tsx +0 -86
  54. package/build/ui/reference/components/item.tsx +0 -188
  55. package/build/ui/reference/components/kbd.tsx +0 -43
  56. package/build/ui/reference/components/label.tsx +0 -19
  57. package/build/ui/reference/components/list.tsx +0 -191
  58. package/build/ui/reference/components/map.css +0 -251
  59. package/build/ui/reference/components/map.tsx +0 -294
  60. package/build/ui/reference/components/menubar.tsx +0 -275
  61. package/build/ui/reference/components/message-scroller.tsx +0 -141
  62. package/build/ui/reference/components/message.tsx +0 -177
  63. package/build/ui/reference/components/nav.tsx +0 -127
  64. package/build/ui/reference/components/navigation-menu.tsx +0 -191
  65. package/build/ui/reference/components/page-header.tsx +0 -245
  66. package/build/ui/reference/components/popover.tsx +0 -76
  67. package/build/ui/reference/components/progress.tsx +0 -31
  68. package/build/ui/reference/components/radio.tsx +0 -65
  69. package/build/ui/reference/components/resizable.tsx +0 -40
  70. package/build/ui/reference/components/scroll-area.tsx +0 -55
  71. package/build/ui/reference/components/segmented.tsx +0 -45
  72. package/build/ui/reference/components/select.tsx +0 -188
  73. package/build/ui/reference/components/separator.tsx +0 -26
  74. package/build/ui/reference/components/sheet.tsx +0 -184
  75. package/build/ui/reference/components/skeleton.tsx +0 -15
  76. package/build/ui/reference/components/slider.tsx +0 -161
  77. package/build/ui/reference/components/snackbar.tsx +0 -27
  78. package/build/ui/reference/components/sonner.tsx +0 -43
  79. package/build/ui/reference/components/spinner.tsx +0 -27
  80. package/build/ui/reference/components/statistic.tsx +0 -122
  81. package/build/ui/reference/components/stepper.tsx +0 -138
  82. package/build/ui/reference/components/switch.tsx +0 -47
  83. package/build/ui/reference/components/table.tsx +0 -246
  84. package/build/ui/reference/components/textarea.tsx +0 -28
  85. package/build/ui/reference/components/timeline.tsx +0 -101
  86. package/build/ui/reference/components/toggle-group.tsx +0 -86
  87. package/build/ui/reference/components/toggle.tsx +0 -46
  88. package/build/ui/reference/components/tooltip.tsx +0 -53
  89. package/build/ui/reference/index.ts +0 -69
  90. package/build/ui/reference/lib/utils.ts +0 -34
  91. package/template/webpack.config.js +0 -112
  92. package/template/webpack.local.config.js +0 -68
@@ -1,207 +0,0 @@
1
- 'use client';
2
-
3
- import * as React from 'react';
4
- import { AlertDialog as AlertDialogPrimitive } from 'radix-ui';
5
-
6
- import { cn } from '@rise-x/ui/lib/utils';
7
- import { Button } from '@rise-x/ui/components/button';
8
-
9
- /*
10
- * forwardRef throughout, for the same reason button.tsx uses it (see the comment
11
- * there): the classic React 18 host renders these components too, and React 18
12
- * strips `ref` from a plain function component instead of passing it as a prop.
13
- *
14
- * This is not only about refs a caller passes. Radix refs the overlay ITSELF:
15
- * AlertDialogContent puts <AlertDialogOverlay /> inside the portal, and radix's
16
- * Portal wraps each child in Presence + `Primitive.div asChild`, whose Slot
17
- * hands the child a composed ref. Under React 18 a plain-function overlay drops
18
- * it, so Presence never sees the overlay node and closes it without its
19
- * exit animation — plus a "Function components cannot be given refs" warning on
20
- * every open. Only AlertDialog (Root) and AlertDialogPortal are left as plain
21
- * functions: neither renders a DOM node, and radix's own are plain too.
22
- */
23
-
24
- function AlertDialog({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
25
- return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />;
26
- }
27
-
28
- const AlertDialogTrigger = React.forwardRef<
29
- HTMLButtonElement,
30
- React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Trigger>
31
- >(function AlertDialogTrigger({ ...props }, ref) {
32
- return <AlertDialogPrimitive.Trigger ref={ref} data-slot="alert-dialog-trigger" {...props} />;
33
- });
34
-
35
- function AlertDialogPortal({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
36
- return <AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />;
37
- }
38
-
39
- const AlertDialogOverlay = React.forwardRef<
40
- HTMLDivElement,
41
- React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
42
- >(function AlertDialogOverlay({ className, ...props }, ref) {
43
- return (
44
- <AlertDialogPrimitive.Overlay
45
- ref={ref}
46
- data-slot="alert-dialog-overlay"
47
- className={cn(
48
- 'fixed inset-0 z-50 bg-black/30 duration-100 dark:bg-black/60 supports-backdrop-filter:backdrop-blur-sm data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0',
49
- className,
50
- )}
51
- {...props}
52
- />
53
- );
54
- });
55
-
56
- const AlertDialogContent = React.forwardRef<
57
- HTMLDivElement,
58
- React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content> & {
59
- size?: 'default' | 'sm';
60
- }
61
- >(function AlertDialogContent({ className, size = 'default', ...props }, ref) {
62
- return (
63
- <AlertDialogPortal>
64
- <AlertDialogOverlay />
65
- <AlertDialogPrimitive.Content
66
- ref={ref}
67
- data-slot="alert-dialog-content"
68
- data-size={size}
69
- className={cn(
70
- 'group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-6 rounded-2xl bg-popover p-6 text-popover-foreground shadow-pop duration-100 outline-none 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',
71
- /* min() folds dialog.tsx's viewport-gutter clamp into the size cap —
72
- * a separate bare max-w-* would lose to these data-variants on
73
- * specificity, and without it the xs cap sits flush against the
74
- * screen edge on viewports at or under 320px. */
75
- 'data-[size=default]:max-w-[min(var(--container-xs),calc(100%-(var(--spacing)*8)))] data-[size=sm]:max-w-[min(var(--container-xs),calc(100%-(var(--spacing)*8)))] data-[size=default]:sm:max-w-md',
76
- className,
77
- )}
78
- {...props}
79
- />
80
- </AlertDialogPortal>
81
- );
82
- });
83
-
84
- const AlertDialogHeader = React.forwardRef<HTMLDivElement, React.ComponentPropsWithoutRef<'div'>>(
85
- function AlertDialogHeader({ className, ...props }, ref) {
86
- return (
87
- <div
88
- ref={ref}
89
- data-slot="alert-dialog-header"
90
- className={cn(
91
- 'grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-6 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]',
92
- className,
93
- )}
94
- {...props}
95
- />
96
- );
97
- },
98
- );
99
-
100
- const AlertDialogFooter = React.forwardRef<HTMLDivElement, React.ComponentPropsWithoutRef<'div'>>(
101
- function AlertDialogFooter({ className, ...props }, ref) {
102
- return (
103
- <div
104
- ref={ref}
105
- data-slot="alert-dialog-footer"
106
- className={cn(
107
- 'flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end',
108
- className,
109
- )}
110
- {...props}
111
- />
112
- );
113
- },
114
- );
115
-
116
- const AlertDialogMedia = React.forwardRef<HTMLDivElement, React.ComponentPropsWithoutRef<'div'>>(
117
- function AlertDialogMedia({ className, ...props }, ref) {
118
- return (
119
- <div
120
- ref={ref}
121
- data-slot="alert-dialog-media"
122
- className={cn(
123
- "mb-2 inline-flex size-16 items-center justify-center rounded-full bg-muted sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-8",
124
- className,
125
- )}
126
- {...props}
127
- />
128
- );
129
- },
130
- );
131
-
132
- const AlertDialogTitle = React.forwardRef<
133
- HTMLHeadingElement,
134
- React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
135
- >(function AlertDialogTitle({ className, ...props }, ref) {
136
- return (
137
- <AlertDialogPrimitive.Title
138
- ref={ref}
139
- data-slot="alert-dialog-title"
140
- className={cn(
141
- 'font-heading text-lg font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2',
142
- className,
143
- )}
144
- {...props}
145
- />
146
- );
147
- });
148
-
149
- const AlertDialogDescription = React.forwardRef<
150
- HTMLParagraphElement,
151
- React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
152
- >(function AlertDialogDescription({ className, ...props }, ref) {
153
- return (
154
- <AlertDialogPrimitive.Description
155
- ref={ref}
156
- data-slot="alert-dialog-description"
157
- className={cn(
158
- 'text-ui text-balance text-muted-foreground md:text-pretty *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground',
159
- className,
160
- )}
161
- {...props}
162
- />
163
- );
164
- });
165
-
166
- const AlertDialogAction = React.forwardRef<
167
- HTMLButtonElement,
168
- React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action> &
169
- Pick<React.ComponentProps<typeof Button>, 'variant' | 'size'>
170
- >(function AlertDialogAction({ className, variant = 'default', size = 'default', ...props }, ref) {
171
- return (
172
- // className goes to the Button, not to the slotted child: Radix's Slot
173
- // CONCATENATES classNames instead of merging them, so a caller's override on
174
- // the child would tie with the variant's own class and lose or win purely on
175
- // stylesheet order. Routed here, it goes through Button's cn() and wins.
176
- <Button variant={variant} size={size} className={className} asChild>
177
- <AlertDialogPrimitive.Action ref={ref} data-slot="alert-dialog-action" {...props} />
178
- </Button>
179
- );
180
- });
181
-
182
- const AlertDialogCancel = React.forwardRef<
183
- HTMLButtonElement,
184
- React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel> &
185
- Pick<React.ComponentProps<typeof Button>, 'variant' | 'size'>
186
- >(function AlertDialogCancel({ className, variant = 'outline', size = 'default', ...props }, ref) {
187
- return (
188
- <Button variant={variant} size={size} className={className} asChild>
189
- <AlertDialogPrimitive.Cancel ref={ref} data-slot="alert-dialog-cancel" {...props} />
190
- </Button>
191
- );
192
- });
193
-
194
- export {
195
- AlertDialog,
196
- AlertDialogAction,
197
- AlertDialogCancel,
198
- AlertDialogContent,
199
- AlertDialogDescription,
200
- AlertDialogFooter,
201
- AlertDialogHeader,
202
- AlertDialogMedia,
203
- AlertDialogOverlay,
204
- AlertDialogPortal,
205
- AlertDialogTitle,
206
- AlertDialogTrigger,
207
- };
@@ -1,112 +0,0 @@
1
- import * as React from 'react';
2
- import { cva, type VariantProps } from 'class-variance-authority';
3
-
4
- import { cn } from '@rise-x/ui/lib/utils';
5
-
6
- /*
7
- * Alert (in-flow, bordered) and Banner (full-width, tinted). Both put tone in
8
- * the ICON and the text, not in a coloured left edge — an edge stripe reads as
9
- * something stuck on, a glyph reads as part of the message.
10
- */
11
- const alertVariants = cva(
12
- 'flex gap-[9px] rounded-lg border px-3 py-2.5 text-xs [&>svg]:mt-px [&>svg]:size-3.5 [&>svg]:shrink-0',
13
- {
14
- variants: {
15
- tone: {
16
- neutral: 'border-border bg-card [&>svg]:text-muted-foreground',
17
- success: 'border-success/25 bg-success/8 [&>svg]:text-success-text',
18
- warning: 'border-warning/30 bg-warning/10 [&>svg]:text-warning-text',
19
- error: 'border-error/25 bg-error/8 [&>svg]:text-error-text',
20
- info: 'border-info/25 bg-info/8 [&>svg]:text-info-text',
21
- ai: 'border-ai-edge bg-ai-tint [&>svg]:text-ai-text',
22
- },
23
- },
24
- defaultVariants: { tone: 'neutral' },
25
- },
26
- );
27
-
28
- function Alert({
29
- className,
30
- tone = 'neutral',
31
- ...props
32
- }: React.ComponentProps<'div'> & VariantProps<typeof alertVariants>) {
33
- return (
34
- <div
35
- data-slot="alert"
36
- role="status"
37
- className={cn(alertVariants({ tone }), className)}
38
- {...props}
39
- />
40
- );
41
- }
42
-
43
- function AlertTitle({ className, ...props }: React.ComponentProps<'div'>) {
44
- return (
45
- <div
46
- data-slot="alert-title"
47
- className={cn('mb-px text-ui font-medium', className)}
48
- {...props}
49
- />
50
- );
51
- }
52
-
53
- function AlertDescription({ className, ...props }: React.ComponentProps<'div'>) {
54
- return (
55
- <div
56
- data-slot="alert-description"
57
- className={cn('text-xs text-muted-foreground', className)}
58
- {...props}
59
- />
60
- );
61
- }
62
-
63
- function Banner({
64
- className,
65
- tone = 'neutral',
66
- ...props
67
- }: React.ComponentProps<'div'> & VariantProps<typeof alertVariants>) {
68
- return (
69
- <div
70
- data-slot="banner"
71
- role="status"
72
- className={cn(
73
- alertVariants({ tone }),
74
- 'items-center px-3.5 py-2.5 [&>svg]:mt-0 [&>[data-slot=button]]:ml-auto',
75
- className,
76
- )}
77
- {...props}
78
- />
79
- );
80
- }
81
-
82
- /* Inline message: the smallest form — a 12px glyph and a line of text, for
83
- * where even a bordered alert is too much furniture (under a field, in a cell). */
84
- const inlineVariants = cva('inline-flex items-center gap-1.5 text-micro [&>svg]:size-3', {
85
- variants: {
86
- tone: {
87
- neutral: 'text-muted-foreground',
88
- success: 'text-success-text',
89
- warning: 'text-warning-text',
90
- error: 'text-error-text',
91
- info: 'text-info-text',
92
- ai: 'text-ai-text',
93
- },
94
- },
95
- defaultVariants: { tone: 'neutral' },
96
- });
97
-
98
- function InlineMessage({
99
- className,
100
- tone = 'neutral',
101
- ...props
102
- }: React.ComponentProps<'span'> & VariantProps<typeof inlineVariants>) {
103
- return (
104
- <span
105
- data-slot="inline-message"
106
- className={cn(inlineVariants({ tone }), className)}
107
- {...props}
108
- />
109
- );
110
- }
111
-
112
- export { Alert, AlertTitle, AlertDescription, Banner, InlineMessage, alertVariants };
@@ -1,71 +0,0 @@
1
- import * as React from 'react';
2
-
3
- import { cn } from '@rise-x/ui/lib/utils';
4
-
5
- /*
6
- * THE APP LAYOUT CONTRACT for federated apps.
7
- *
8
- * The next-gen shell hands an app a full-bleed region that extends UNDER its
9
- * floating top bar and publishes the bar's height as `--topbar-h` on the
10
- * document. These three primitives split that region the way the shell's own
11
- * surfaces do: a rail that starts below the bar and never scrolls away, and a
12
- * content column whose scroller spans the full height so content slides in
13
- * BEHIND the bar's progressive blur instead of being clipped at its edge.
14
- *
15
- * RESPONSIVE STANDARD: below md the frame stacks — the rail becomes a
16
- * horizontal, scrollable nav strip under the top bar (Nav rows flip to a row,
17
- * NavSection headers hide) and the content column scrolls beneath it. Apps
18
- * get a sane phone/tablet layout without writing their own breakpoints.
19
- *
20
- * In hosts that don't publish the variable (the classic ClientApp shell,
21
- * standalone dev) every offset falls back to 0px and the frame degrades to a
22
- * plain rail-plus-content flex layout in normal flow.
23
- */
24
-
25
- function AppFrame({ className, ...props }: React.ComponentProps<'div'>) {
26
- return (
27
- <div
28
- data-slot="app-frame"
29
- className={cn('flex h-full min-h-0 flex-col text-foreground md:flex-row', className)}
30
- {...props}
31
- />
32
- );
33
- }
34
-
35
- /** Fixed left rail from md up (180px, the Nav convention; override via
36
- * className) — long rails scroll themselves, the page never scrolls them
37
- * away. Below md it renders as a horizontal nav strip under the top bar. */
38
- function AppRail({ className, ...props }: React.ComponentProps<'aside'>) {
39
- return (
40
- <aside
41
- data-slot="app-rail"
42
- className={cn(
43
- 'flex w-full shrink-0 flex-row items-center gap-1 overflow-x-auto px-3 pt-[calc(var(--topbar-h,0px)_+_8px)] pb-1',
44
- 'max-md:[&_[data-slot=nav]]:flex-row max-md:[&_[data-slot=nav]]:items-center max-md:[&_[data-slot=nav-item]]:w-auto max-md:[&_[data-slot=nav-item]]:shrink-0 max-md:[&_[data-slot=nav-section]]:hidden',
45
- 'md:w-[180px] md:flex-col md:items-stretch md:gap-0 md:overflow-x-visible md:overflow-y-auto md:p-3 md:pt-[calc(var(--topbar-h,0px)_+_12px)]',
46
- className,
47
- )}
48
- {...props}
49
- />
50
- );
51
- }
52
-
53
- /** The scrolling content column. From md up it spans under the shell top bar —
54
- * the top padding keeps resting content below it, so only scrolled content
55
- * passes behind. Below md the rail strip clears the bar and the column
56
- * scrolls beneath it with plain padding; a rail-less frame (AppContent as
57
- * the frame's first child) pads itself below the bar instead. */
58
- function AppContent({ className, ...props }: React.ComponentProps<'main'>) {
59
- return (
60
- <main
61
- data-slot="app-content"
62
- className={cn(
63
- 'min-w-0 flex-1 overflow-y-auto p-4 max-md:first:pt-[calc(var(--topbar-h,0px)_+_16px)] md:p-6 md:pt-[calc(var(--topbar-h,0px)_+_24px)]',
64
- className,
65
- )}
66
- {...props}
67
- />
68
- );
69
- }
70
-
71
- export { AppFrame, AppRail, AppContent };
@@ -1,28 +0,0 @@
1
- import * as React from 'react';
2
- import { AspectRatio as AspectRatioPrimitive } from 'radix-ui';
3
-
4
- import { cn } from '@rise-x/ui/lib/utils';
5
-
6
- /*
7
- * Holds a box at a fixed ratio so media cannot shift the layout while it loads.
8
- * Deliberately carries no surface, radius or border of its own — the caller
9
- * decides whether the thing inside is a thumbnail (10px) or a card (14px), and a
10
- * radius here would clip at the wrong step.
11
- *
12
- * Use `MediaThumb` instead for a fixed-size square in a gallery; this is for the
13
- * responsive case where the width is unknown and only the ratio is fixed.
14
- */
15
- function AspectRatio({
16
- className,
17
- ...props
18
- }: React.ComponentProps<typeof AspectRatioPrimitive.Root>) {
19
- return (
20
- <AspectRatioPrimitive.Root
21
- data-slot="aspect-ratio"
22
- className={cn('[&>img]:size-full [&>img]:object-cover [&>video]:size-full', className)}
23
- {...props}
24
- />
25
- );
26
- }
27
-
28
- export { AspectRatio };
@@ -1,158 +0,0 @@
1
- 'use client';
2
-
3
- import * as React from 'react';
4
- import { Avatar as AvatarPrimitive } from 'radix-ui';
5
-
6
- import { cn } from '@rise-x/ui/lib/utils';
7
-
8
- /*
9
- * ONE tonal recipe, not a hand-picked pastel set. Every tone derives from a
10
- * single hue variable: 16% over the surface for the fill, 58% toward the text
11
- * colour for the initials, one 24% inset ring. No per-colour tuning, and every
12
- * tone lands at the same visual weight — pastels chosen by eye always drift.
13
- *
14
- * THE 58% IS A CONTRAST FLOOR, NOT A TASTE CALL. At 78% — where this started —
15
- * the initials sat at 3.11:1 for amber, 3.51:1 for tango and 4.29:1 on blue,
16
- * i.e. below AA at 10px, because the same recipe has to clear its own 16% tint
17
- * for every hue. Pulling the mix toward the foreground puts the worst tone at
18
- * 5.21:1 light / 6.39:1 dark while keeping the hue legible. Re-measure every
19
- * tone against its own tint before changing it.
20
- *
21
- * SHAPE carries "who vs what": people are circles, organisations are rounded
22
- * squares. Shape survives greyscale and never collides with status colour,
23
- * which a colour-coded distinction would.
24
- *
25
- * TINT HAS AN INFORMATION RULE. Tint only when the avatar is the sole
26
- * identifier — a stack, a bare list, a comment thread. When a name sits right
27
- * beside it the colour carries nothing, so use the default `neutral`; a table
28
- * of tinted avatars next to their own labels is just confetti. That is why
29
- * `tone` is an explicit prop rather than hashed from the initials.
30
- */
31
- const AVATAR_TONES = ['neutral', 'blue', 'tango', 'amber', 'red', 'slate', 'ai'] as const;
32
-
33
- type AvatarTone = (typeof AVATAR_TONES)[number];
34
-
35
- function Avatar({
36
- className,
37
- size = 'default',
38
- tone = 'neutral',
39
- shape = 'circle',
40
- style,
41
- ...props
42
- }: React.ComponentProps<typeof AvatarPrimitive.Root> & {
43
- size?: 'default' | 'sm' | 'lg';
44
- /** Only tint when the avatar is the sole identifier — see the note above. */
45
- tone?: AvatarTone;
46
- /** `org` renders a rounded square. People are circles. */
47
- shape?: 'circle' | 'org';
48
- }) {
49
- return (
50
- <AvatarPrimitive.Root
51
- data-slot="avatar"
52
- data-size={size}
53
- data-tone={tone}
54
- data-shape={shape}
55
- style={
56
- {
57
- '--av-h': tone === 'ai' ? 'var(--ai)' : `var(--${tone === 'neutral' ? 'slate' : tone})`,
58
- ...style,
59
- } as React.CSSProperties
60
- }
61
- className={cn(
62
- /* 24 / 20 / 32px. Smaller than the kit's old 32/24/40 — these sit inside
63
- * 52px table rows and next to 13px labels, where a 32px default reads as
64
- * a photo rather than an identifier. */
65
- 'group/avatar relative grid size-6 shrink-0 place-items-center overflow-hidden rounded-full text-[10px] font-medium tracking-[0.01em] select-none',
66
- 'data-[size=sm]:size-5 data-[size=sm]:text-[9px] data-[size=lg]:size-8 data-[size=lg]:text-xs',
67
- /* rounded square for organisations, stepped with the box so the corner
68
- * stays proportional: 6px at sm, 8px default, 10px at lg */
69
- 'data-[shape=org]:rounded-md data-[shape=org]:data-[size=sm]:rounded-sm data-[shape=org]:data-[size=lg]:rounded-lg',
70
- // neutral is the default and spends no colour at all
71
- 'data-[tone=neutral]:bg-muted data-[tone=neutral]:text-muted-foreground data-[tone=neutral]:shadow-[inset_0_0_0_1px_var(--border)]',
72
- 'not-data-[tone=neutral]:bg-[color-mix(in_oklab,var(--av-h)_16%,var(--card))]',
73
- 'not-data-[tone=neutral]:text-[color-mix(in_oklab,var(--av-h)_58%,var(--foreground))]',
74
- 'not-data-[tone=neutral]:shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--av-h)_24%,transparent)]',
75
- className,
76
- )}
77
- {...props}
78
- />
79
- );
80
- }
81
-
82
- function AvatarImage({ className, ...props }: React.ComponentProps<typeof AvatarPrimitive.Image>) {
83
- return (
84
- <AvatarPrimitive.Image
85
- data-slot="avatar-image"
86
- className={cn('aspect-square size-full object-cover', className)}
87
- {...props}
88
- />
89
- );
90
- }
91
-
92
- function AvatarFallback({
93
- className,
94
- ...props
95
- }: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
96
- return (
97
- <AvatarPrimitive.Fallback
98
- data-slot="avatar-fallback"
99
- className={cn('grid size-full place-items-center bg-transparent text-inherit', className)}
100
- {...props}
101
- />
102
- );
103
- }
104
-
105
- function AvatarBadge({ className, ...props }: React.ComponentProps<'span'>) {
106
- return (
107
- <span
108
- data-slot="avatar-badge"
109
- className={cn(
110
- 'absolute right-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground ring-2 ring-card select-none',
111
- 'group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden',
112
- 'group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2',
113
- 'group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2',
114
- className,
115
- )}
116
- {...props}
117
- />
118
- );
119
- }
120
-
121
- function AvatarGroup({ className, ...props }: React.ComponentProps<'div'>) {
122
- return (
123
- <div
124
- data-slot="avatar-group"
125
- className={cn(
126
- 'group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-card',
127
- className,
128
- )}
129
- {...props}
130
- />
131
- );
132
- }
133
-
134
- function AvatarGroupCount({ className, ...props }: React.ComponentProps<'div'>) {
135
- return (
136
- <div
137
- data-slot="avatar-group-count"
138
- className={cn(
139
- /* Same 24 / 20 / 32 ramp as Avatar itself — the overflow bubble sits in
140
- * the row with the avatars, so any other scale makes it a step mid-row. */
141
- 'relative grid size-6 shrink-0 place-items-center rounded-full bg-muted text-[10px] font-medium text-muted-foreground ring-2 ring-card group-has-data-[size=lg]/avatar-group:size-8 group-has-data-[size=lg]/avatar-group:text-xs group-has-data-[size=sm]/avatar-group:size-5 group-has-data-[size=sm]/avatar-group:text-[9px] [&>svg]:size-3',
142
- className,
143
- )}
144
- {...props}
145
- />
146
- );
147
- }
148
-
149
- export {
150
- Avatar,
151
- AvatarImage,
152
- AvatarFallback,
153
- AvatarGroup,
154
- AvatarGroupCount,
155
- AvatarBadge,
156
- AVATAR_TONES,
157
- type AvatarTone,
158
- };