@luxfi/ui 5.6.0 → 6.0.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.
Files changed (125) hide show
  1. package/README.md +109 -0
  2. package/package.json +81 -278
  3. package/dist/accordion.cjs +0 -213
  4. package/dist/accordion.js +0 -186
  5. package/dist/alert.cjs +0 -553
  6. package/dist/alert.js +0 -531
  7. package/dist/avatar.cjs +0 -149
  8. package/dist/avatar.js +0 -125
  9. package/dist/badge.cjs +0 -611
  10. package/dist/badge.js +0 -589
  11. package/dist/button.cjs +0 -689
  12. package/dist/button.js +0 -664
  13. package/dist/checkbox.cjs +0 -265
  14. package/dist/checkbox.js +0 -241
  15. package/dist/close-button.cjs +0 -73
  16. package/dist/close-button.js +0 -51
  17. package/dist/collapsible.cjs +0 -702
  18. package/dist/collapsible.js +0 -679
  19. package/dist/color-mode.cjs +0 -96
  20. package/dist/color-mode.js +0 -72
  21. package/dist/dialog.cjs +0 -279
  22. package/dist/dialog.js +0 -246
  23. package/dist/drawer.cjs +0 -207
  24. package/dist/drawer.js +0 -175
  25. package/dist/empty-state.cjs +0 -93
  26. package/dist/empty-state.js +0 -71
  27. package/dist/field.cjs +0 -183
  28. package/dist/field.js +0 -160
  29. package/dist/heading.cjs +0 -46
  30. package/dist/heading.js +0 -40
  31. package/dist/icon-button.cjs +0 -491
  32. package/dist/icon-button.js +0 -470
  33. package/dist/image.cjs +0 -572
  34. package/dist/image.js +0 -551
  35. package/dist/index.cjs +0 -5779
  36. package/dist/index.js +0 -5619
  37. package/dist/input-group.cjs +0 -155
  38. package/dist/input-group.js +0 -133
  39. package/dist/input.cjs +0 -65
  40. package/dist/input.js +0 -59
  41. package/dist/link.cjs +0 -630
  42. package/dist/link.js +0 -606
  43. package/dist/menu.cjs +0 -305
  44. package/dist/menu.js +0 -269
  45. package/dist/pin-input.cjs +0 -182
  46. package/dist/pin-input.js +0 -160
  47. package/dist/popover.cjs +0 -327
  48. package/dist/popover.js +0 -294
  49. package/dist/progress-circle.cjs +0 -152
  50. package/dist/progress-circle.js +0 -128
  51. package/dist/progress.cjs +0 -117
  52. package/dist/progress.js +0 -94
  53. package/dist/provider.cjs +0 -62
  54. package/dist/provider.js +0 -40
  55. package/dist/radio.cjs +0 -177
  56. package/dist/radio.js +0 -153
  57. package/dist/rating.cjs +0 -80
  58. package/dist/rating.js +0 -58
  59. package/dist/select.cjs +0 -791
  60. package/dist/select.js +0 -757
  61. package/dist/separator.cjs +0 -57
  62. package/dist/separator.js +0 -51
  63. package/dist/skeleton.cjs +0 -370
  64. package/dist/skeleton.js +0 -346
  65. package/dist/slider.cjs +0 -138
  66. package/dist/slider.js +0 -115
  67. package/dist/switch.cjs +0 -163
  68. package/dist/switch.js +0 -140
  69. package/dist/table.cjs +0 -1044
  70. package/dist/table.js +0 -1013
  71. package/dist/tabs.cjs +0 -240
  72. package/dist/tabs.js +0 -213
  73. package/dist/tag.cjs +0 -651
  74. package/dist/tag.js +0 -628
  75. package/dist/textarea.cjs +0 -65
  76. package/dist/textarea.js +0 -59
  77. package/dist/toaster.cjs +0 -99
  78. package/dist/toaster.js +0 -96
  79. package/dist/tooltip.cjs +0 -171
  80. package/dist/tooltip.js +0 -148
  81. package/dist/utils.cjs +0 -11
  82. package/dist/utils.js +0 -9
  83. package/src/accordion.tsx +0 -285
  84. package/src/alert.tsx +0 -221
  85. package/src/avatar.tsx +0 -174
  86. package/src/badge.tsx +0 -158
  87. package/src/button.tsx +0 -411
  88. package/src/checkbox.tsx +0 -307
  89. package/src/close-button.tsx +0 -51
  90. package/src/collapsible.tsx +0 -126
  91. package/src/color-mode.tsx +0 -125
  92. package/src/dialog.tsx +0 -356
  93. package/src/drawer.tsx +0 -186
  94. package/src/empty-state.tsx +0 -97
  95. package/src/field.tsx +0 -202
  96. package/src/heading.tsx +0 -55
  97. package/src/icon-button.tsx +0 -192
  98. package/src/image.tsx +0 -280
  99. package/src/index.ts +0 -192
  100. package/src/input-group.tsx +0 -159
  101. package/src/input.tsx +0 -60
  102. package/src/link.tsx +0 -326
  103. package/src/menu.tsx +0 -471
  104. package/src/pin-input.tsx +0 -187
  105. package/src/popover.tsx +0 -400
  106. package/src/progress-circle.tsx +0 -180
  107. package/src/progress.tsx +0 -109
  108. package/src/provider.tsx +0 -12
  109. package/src/radio.tsx +0 -175
  110. package/src/rating.tsx +0 -79
  111. package/src/select.tsx +0 -696
  112. package/src/separator.tsx +0 -59
  113. package/src/skeleton.tsx +0 -302
  114. package/src/slider.tsx +0 -152
  115. package/src/switch.tsx +0 -158
  116. package/src/table.tsx +0 -621
  117. package/src/tabs.tsx +0 -354
  118. package/src/tag.tsx +0 -159
  119. package/src/textarea.tsx +0 -60
  120. package/src/toaster.tsx +0 -117
  121. package/src/tokens.css +0 -438
  122. package/src/tooltip.tsx +0 -184
  123. package/src/utils/cn.ts +0 -7
  124. package/src/utils.ts +0 -6
  125. package/tokens.css +0 -438
package/src/accordion.tsx DELETED
@@ -1,285 +0,0 @@
1
- import * as AccordionPrimitive from '@radix-ui/react-accordion';
2
- import * as React from 'react';
3
-
4
- import { cn } from './utils';
5
-
6
- // Inline chevron icon (east-mini arrow)
7
- const IndicatorIcon = ({ className }: { readonly className?: string }) => (
8
- <svg className={ className } viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
9
- <path d="M7.5 15L12.5 10L7.5 5" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
10
- </svg>
11
- );
12
-
13
- // ---------------------------------------------------------------------------
14
- // AccordionRoot
15
- // ---------------------------------------------------------------------------
16
-
17
- interface AccordionRootProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'defaultValue' | 'dir'> {
18
-
19
- /** Open multiple items simultaneously. Defaults to true. */
20
- readonly multiple?: boolean;
21
-
22
- /** Controlled open items (array of `value` strings). */
23
- readonly value?: Array<string>;
24
-
25
- /** Uncontrolled initial open items. */
26
- readonly defaultValue?: Array<string>;
27
-
28
- /**
29
- * Called when open items change.
30
- * Wraps the value in `{ value }` to stay compatible with the Chakra callback shape
31
- * that consumers already rely on.
32
- */
33
- readonly onValueChange?: (details: { value: Array<string> }) => void;
34
- readonly variant?: 'outline' | 'faq';
35
- readonly size?: 'sm' | 'md';
36
-
37
- /** Accepted for compatibility; not applied visually. */
38
- readonly noAnimation?: boolean;
39
-
40
- /** Accepted for compatibility; Radix defers rendering internally. */
41
- readonly lazyMount?: boolean;
42
- readonly children?: React.ReactNode;
43
- // Legacy Chakra style-prop shims
44
- readonly position?: string;
45
- readonly w?: string;
46
- readonly bgColor?: string | Record<string, string>;
47
- readonly borderRadius?: string;
48
- }
49
-
50
- export const AccordionRoot = React.forwardRef<HTMLDivElement, AccordionRootProps>(
51
- function AccordionRoot(props, ref) {
52
- const {
53
- multiple: _multiple,
54
- value,
55
- defaultValue,
56
- onValueChange,
57
- variant,
58
- size,
59
- noAnimation: _noAnimation,
60
- lazyMount: _lazyMount,
61
- className,
62
- children,
63
- position: _position,
64
- w: _w,
65
- bgColor: _bgColor,
66
- borderRadius: _borderRadius,
67
- ...rest
68
- } = props;
69
-
70
- // Radix requires `type` discriminant. We default to "multiple" to match
71
- // the original Chakra wrapper behavior.
72
- const handleValueChange = React.useCallback(
73
- (next: Array<string>) => {
74
- onValueChange?.({ value: next });
75
- },
76
- [ onValueChange ],
77
- );
78
-
79
- return (
80
- <AccordionPrimitive.Root
81
- ref={ ref }
82
- type="multiple"
83
- value={ value }
84
- defaultValue={ defaultValue }
85
- onValueChange={ handleValueChange }
86
- className={ cn(
87
- 'w-full',
88
- variant === 'faq' && 'accordion-faq',
89
- size === 'sm' && 'accordion-sm',
90
- className,
91
- ) }
92
- data-variant={ variant }
93
- data-size={ size }
94
- { ...rest }
95
- >
96
- { children }
97
- </AccordionPrimitive.Root>
98
- );
99
- },
100
- );
101
-
102
- // ---------------------------------------------------------------------------
103
- // AccordionItem
104
- // ---------------------------------------------------------------------------
105
-
106
- interface AccordionItemProps extends React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item> {
107
- // Legacy Chakra style-prop shims
108
- as?: string;
109
- _first?: Record<string, unknown>;
110
- _last?: Record<string, unknown>;
111
- display?: string;
112
- }
113
-
114
- export const AccordionItem = React.forwardRef<HTMLDivElement, AccordionItemProps>(
115
- function AccordionItem(props, ref) {
116
- const { className, as: _as, _first, _last, display: _display, ...rest } = props;
117
- return (
118
- <AccordionPrimitive.Item
119
- ref={ ref }
120
- className={ cn(
121
- 'border-b border-[var(--color-border-divider)]',
122
- className,
123
- ) }
124
- { ...rest }
125
- />
126
- );
127
- },
128
- );
129
-
130
- // ---------------------------------------------------------------------------
131
- // AccordionItemTrigger
132
- // ---------------------------------------------------------------------------
133
-
134
- interface AccordionItemTriggerProps extends Omit<React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>, 'dir'> {
135
- readonly indicatorPlacement?: 'start' | 'end';
136
- readonly noIndicator?: boolean;
137
- readonly variant?: 'outline' | 'faq';
138
- // Legacy Chakra style-prop shims
139
- px?: number | string;
140
- py?: number | string;
141
- _hover?: Record<string, string>;
142
- wordBreak?: string;
143
- textAlign?: string;
144
- cursor?: string;
145
- display?: string;
146
- alignItems?: string;
147
- columnGap?: number | string;
148
- }
149
-
150
- export const AccordionItemTrigger = React.forwardRef<
151
- HTMLButtonElement,
152
- AccordionItemTriggerProps
153
- >(function AccordionItemTrigger(props, ref) {
154
- const {
155
- children, indicatorPlacement: indicatorPlacementProp, variant, noIndicator, className,
156
- // Strip Chakra style props
157
- px: _px, py: _py, _hover, wordBreak: _wordBreak, textAlign: _textAlign,
158
- cursor: _cursor, display: _display, alignItems: _alignItems, columnGap: _columnGap,
159
- ...rest
160
- } = props;
161
-
162
- const indicatorPlacement = variant === 'faq' ? 'start' : (indicatorPlacementProp ?? 'end');
163
-
164
- const indicator = variant === 'faq' ? (
165
- <span
166
- className={ cn(
167
- 'relative inline-block h-3 w-3 shrink-0',
168
- // horizontal bar (always visible)
169
- 'before:absolute before:left-0 before:top-1/2 before:block before:h-[2px] before:w-full before:-translate-y-1/2 before:rounded-[2px] before:bg-current',
170
- // vertical bar (rotates to 0 when open)
171
- 'after:absolute after:left-1/2 after:top-0 after:block after:h-full after:w-[2px]',
172
- 'after:-translate-x-1/2 after:rounded-[2px] after:bg-current',
173
- 'after:transition-transform after:duration-200 after:ease-in-out',
174
- // When parent trigger has data-state="open", rotate vertical bar
175
- 'group-data-[state=open]/trigger:after:rotate-90',
176
- ) }
177
- />
178
- ) : (
179
- <span
180
- className={ cn(
181
- 'inline-flex shrink-0 transition-transform duration-200',
182
- 'rotate-180',
183
- 'group-data-[state=open]/trigger:rotate-[270deg]',
184
- ) }
185
- >
186
- <IndicatorIcon className="h-5 w-5"/>
187
- </span>
188
- );
189
-
190
- return (
191
- <AccordionPrimitive.Header asChild>
192
- <div>
193
- <AccordionPrimitive.Trigger
194
- ref={ ref }
195
- className={ cn(
196
- 'group/trigger flex w-full cursor-pointer items-center gap-2 py-3 text-left text-[var(--color-text-primary)]',
197
- 'hover:text-[var(--color-hover)]',
198
- 'focus-visible:outline-none',
199
- className,
200
- ) }
201
- { ...rest }
202
- >
203
- { indicatorPlacement === 'start' && !noIndicator && indicator }
204
- { children }
205
- { indicatorPlacement === 'end' && !noIndicator && indicator }
206
- </AccordionPrimitive.Trigger>
207
- </div>
208
- </AccordionPrimitive.Header>
209
- );
210
- });
211
-
212
- // ---------------------------------------------------------------------------
213
- // AccordionItemContent
214
- // ---------------------------------------------------------------------------
215
-
216
- export interface AccordionItemContentProps extends React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content> {
217
- // Legacy Chakra style-prop shims
218
- pb?: number | string;
219
- pr?: number | string;
220
- pl?: string;
221
- w?: string;
222
- display?: string;
223
- flexDir?: string;
224
- rowGap?: number | string;
225
- }
226
-
227
- export const AccordionItemContent = React.forwardRef<
228
- HTMLDivElement,
229
- AccordionItemContentProps
230
- >(function AccordionItemContent(props, ref) {
231
- const { className, children, pb: _pb, pr: _pr, pl: _pl, w: _w, display: _display, flexDir: _flexDir, rowGap: _rowGap, ...rest } = props;
232
- return (
233
- <AccordionPrimitive.Content
234
- ref={ ref }
235
- className={ cn(
236
- 'overflow-hidden text-[var(--color-text-primary)]',
237
- 'data-[state=open]:animate-accordion-down',
238
- 'data-[state=closed]:animate-accordion-up',
239
- className,
240
- ) }
241
- { ...rest }
242
- >
243
- <div className="pb-3">
244
- { children }
245
- </div>
246
- </AccordionPrimitive.Content>
247
- );
248
- });
249
-
250
- // ---------------------------------------------------------------------------
251
- // useAccordion
252
- // ---------------------------------------------------------------------------
253
-
254
- export function useAccordion(items: Array<{ id: string }>) {
255
- const [ value, setValue ] = React.useState<Array<string>>([]);
256
-
257
- const onValueChange = React.useCallback(({ value }: { value: Array<string> }) => {
258
- setValue(value);
259
- }, []);
260
-
261
- const scrollToItemFromUrl = React.useCallback(() => {
262
- const hash = window.location.hash.replace('#', '');
263
-
264
- if (!hash) {
265
- return;
266
- }
267
-
268
- const itemToScroll = items.find((item) => item.id === hash);
269
- if (itemToScroll) {
270
- const el = document.getElementById(itemToScroll.id);
271
- if (el) {
272
- el.scrollIntoView({ behavior: 'smooth', block: 'start' });
273
- }
274
- setValue([ itemToScroll.id ]);
275
- }
276
- }, [ items ]);
277
-
278
- return React.useMemo(() => {
279
- return {
280
- value,
281
- onValueChange,
282
- scrollToItemFromUrl,
283
- };
284
- }, [ value, onValueChange, scrollToItemFromUrl ]);
285
- }
package/src/alert.tsx DELETED
@@ -1,221 +0,0 @@
1
- import { cva } from 'class-variance-authority';
2
- import * as React from 'react';
3
-
4
- import { cn } from './utils';
5
-
6
- // Inline info icon (filled circle with i)
7
- const IndicatorIcon = ({ className }: { readonly className?: string }) => (
8
- <svg className={ className } viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
9
- <path fillRule="evenodd" clipRule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm.75-11.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zM9.25 10a.75.75 0 011.5 0v3a.75.75 0 01-1.5 0v-3z"/>
10
- </svg>
11
- );
12
-
13
- import { CloseButton } from './close-button';
14
- import { Skeleton } from './skeleton';
15
-
16
- /* ------------------------------------------------------------------ */
17
- /* Status type */
18
- /* ------------------------------------------------------------------ */
19
-
20
- type AlertStatus = 'info' | 'warning' | 'warning_table' | 'success' | 'error';
21
-
22
- /* ------------------------------------------------------------------ */
23
- /* CVA variants */
24
- /* ------------------------------------------------------------------ */
25
-
26
- const alertRoot = cva(
27
- // base
28
- 'w-full flex items-start relative rounded text-[var(--color-alert-fg)]',
29
- {
30
- variants: {
31
- status: {
32
- info: 'bg-[var(--color-alert-bg-info)]',
33
- warning: 'bg-[var(--color-alert-bg-warning)]',
34
- warning_table: 'bg-[var(--color-alert-bg-warning-table)]',
35
- success: 'bg-[var(--color-alert-bg-success)]',
36
- error: 'bg-[var(--color-alert-bg-error)]',
37
- },
38
- size: {
39
- sm: 'gap-2 px-2 py-2 text-xs',
40
- md: 'gap-2 px-3 py-2 text-base',
41
- },
42
- },
43
- defaultVariants: {
44
- status: 'info',
45
- size: 'md',
46
- },
47
- },
48
- );
49
-
50
- const alertContent = cva('flex flex-1', {
51
- variants: {
52
- inline: {
53
- 'true': 'inline-flex flex-row items-center',
54
- 'false': 'flex flex-col',
55
- },
56
- },
57
- defaultVariants: {
58
- inline: true,
59
- },
60
- });
61
-
62
- const INDICATOR_BASE = 'inline-flex items-center justify-center shrink-0 w-5 h-5 text-[var(--color-alert-fg)] [&>svg]:w-full [&>svg]:h-full';
63
-
64
- const indicatorVariants = cva(INDICATOR_BASE, {
65
- variants: {
66
- size: {
67
- sm: 'w-5 h-5 my-0',
68
- md: 'w-5 h-5 my-[2px]',
69
- },
70
- },
71
- defaultVariants: {
72
- size: 'md',
73
- },
74
- });
75
-
76
- /* ------------------------------------------------------------------ */
77
- /* Props */
78
- /* ------------------------------------------------------------------ */
79
-
80
- export interface AlertProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'title'> {
81
- readonly status?: AlertStatus;
82
- readonly size?: 'sm' | 'md';
83
- readonly inline?: boolean;
84
- readonly startElement?: React.ReactNode;
85
- readonly endElement?: React.ReactNode;
86
- readonly descriptionProps?: Omit<React.ComponentPropsWithoutRef<'div'>, 'ref'> & {
87
- whiteSpace?: string;
88
- alignItems?: string;
89
- flexDir?: string;
90
- flexWrap?: string;
91
- rowGap?: number | string;
92
- columnGap?: number | string;
93
- };
94
- readonly title?: React.ReactNode;
95
- readonly icon?: React.ReactElement;
96
- readonly closable?: boolean;
97
- readonly onClose?: () => void;
98
- readonly loading?: boolean;
99
- readonly showIcon?: boolean;
100
- // Legacy Chakra style-prop shims
101
- readonly whiteSpace?: string;
102
- readonly mb?: number | string;
103
- readonly mt?: number | string;
104
- }
105
-
106
- /* ------------------------------------------------------------------ */
107
- /* Component */
108
- /* ------------------------------------------------------------------ */
109
-
110
- export const Alert = React.forwardRef<HTMLDivElement, AlertProps>(
111
- function Alert(props, ref) {
112
- const {
113
- title,
114
- children,
115
- icon,
116
- closable,
117
- onClose,
118
- startElement,
119
- endElement,
120
- loading,
121
- size,
122
- inline = true,
123
- showIcon = false,
124
- descriptionProps,
125
- status = 'info',
126
- className,
127
- ...rest
128
- } = props;
129
-
130
- // Strip style prop shims
131
- const { whiteSpace: _whiteSpace, mb: _mb, mt: _mt, style: styleProp, ...alertRest } = rest;
132
- const shimStyle: React.CSSProperties = { ...styleProp };
133
- if (_whiteSpace) shimStyle.whiteSpace = _whiteSpace as React.CSSProperties['whiteSpace'];
134
- if (_mb !== undefined) shimStyle.marginBottom = typeof _mb === 'number' ? `${ _mb * 4 }px` : _mb;
135
- if (_mt !== undefined) shimStyle.marginTop = typeof _mt === 'number' ? `${ _mt * 4 }px` : _mt;
136
- const alertStyle = Object.keys(shimStyle).length > 0 ? shimStyle : undefined;
137
-
138
- const [ isOpen, setIsOpen ] = React.useState(true);
139
-
140
- const resolvedSize = size ?? 'md';
141
-
142
- const defaultIcon = (
143
- <IndicatorIcon className="w-5 h-5"/>
144
- );
145
-
146
- const iconElement = (() => {
147
- if (startElement !== undefined) {
148
- return startElement;
149
- }
150
-
151
- if (!showIcon && icon === undefined) {
152
- return null;
153
- }
154
-
155
- return (
156
- <span className={ indicatorVariants({ size: resolvedSize }) }>
157
- { icon || defaultIcon }
158
- </span>
159
- );
160
- })();
161
-
162
- const handleClose = React.useCallback(() => {
163
- setIsOpen(false);
164
- onClose?.();
165
- }, [ onClose ]);
166
-
167
- if (closable && !isOpen) {
168
- return null;
169
- }
170
-
171
- const {
172
- className: descClassName, whiteSpace: descWhiteSpace,
173
- alignItems: descAlignItems, flexDir: descFlexDir,
174
- flexWrap: descFlexWrap, rowGap: descRowGap, columnGap: descColumnGap,
175
- style: descStyleProp, ...descRest
176
- } = descriptionProps ?? {};
177
- const descStyle: React.CSSProperties = {
178
- ...descStyleProp,
179
- ...(descWhiteSpace ? { whiteSpace: descWhiteSpace as React.CSSProperties['whiteSpace'] } : {}),
180
- ...(descAlignItems ? { alignItems: descAlignItems } : {}),
181
- ...(descFlexDir ? { flexDirection: descFlexDir as React.CSSProperties['flexDirection'] } : {}),
182
- ...(descFlexWrap ? { flexWrap: descFlexWrap as React.CSSProperties['flexWrap'] } : {}),
183
- ...(descRowGap !== undefined ? { rowGap: typeof descRowGap === 'number' ? `${ descRowGap * 4 }px` : descRowGap } : {}),
184
- ...(descColumnGap !== undefined ? { columnGap: typeof descColumnGap === 'number' ? `${ descColumnGap * 4 }px` : descColumnGap } : {}),
185
- };
186
-
187
- return (
188
- <Skeleton loading={ loading }>
189
- <div
190
- ref={ ref }
191
- className={ cn(alertRoot({ status, size: resolvedSize }), className) }
192
- style={ alertStyle }
193
- { ...alertRest }
194
- >
195
- { iconElement }
196
- { children ? (
197
- <div className={ alertContent({ inline }) }>
198
- { title && <div className="font-semibold">{ title }</div> }
199
- <div
200
- className={ cn('inline-flex flex-wrap', descClassName) }
201
- style={ Object.keys(descStyle).length > 0 ? descStyle : undefined }
202
- { ...descRest }
203
- >
204
- { children }
205
- </div>
206
- </div>
207
- ) : (
208
- <div className="font-semibold flex-1">{ title }</div>
209
- ) }
210
- { endElement }
211
- { closable && (
212
- <CloseButton
213
- className="relative self-start"
214
- onClick={ handleClose }
215
- />
216
- ) }
217
- </div>
218
- </Skeleton>
219
- );
220
- },
221
- );
package/src/avatar.tsx DELETED
@@ -1,174 +0,0 @@
1
- 'use client';
2
-
3
- import * as RadixAvatar from '@radix-ui/react-avatar';
4
- import * as React from 'react';
5
-
6
- import { cn } from './utils';
7
-
8
- type ImageProps = React.ImgHTMLAttributes<HTMLImageElement>;
9
-
10
- // -- Size & variant mappings ------------------------------------------------
11
-
12
- type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
13
- type AvatarVariant = 'solid' | 'subtle' | 'outline';
14
-
15
- const SIZE_CLASSES: Record<AvatarSize, string> = {
16
- xs: 'h-6 w-6 text-[10px]',
17
- sm: 'h-8 w-8 text-xs',
18
- md: 'h-10 w-10 text-sm',
19
- lg: 'h-12 w-12 text-base',
20
- xl: 'h-16 w-16 text-lg',
21
- '2xl': 'h-20 w-20 text-xl',
22
- };
23
-
24
- const VARIANT_CLASSES: Record<AvatarVariant, string> = {
25
- solid: 'bg-gray-500 text-white',
26
- subtle: 'bg-gray-200 text-gray-700 dark:bg-gray-700 dark:text-gray-200',
27
- outline: 'border-2 border-gray-300 bg-transparent text-gray-700 dark:border-gray-600 dark:text-gray-200',
28
- };
29
-
30
- const DEFAULT_SIZE: AvatarSize = 'md';
31
- const DEFAULT_VARIANT: AvatarVariant = 'subtle';
32
-
33
- // -- Context for AvatarGroup ------------------------------------------------
34
-
35
- interface AvatarGroupContextValue {
36
- readonly size?: AvatarSize;
37
- readonly variant?: AvatarVariant;
38
- readonly borderless?: boolean;
39
- }
40
-
41
- const AvatarGroupContext = React.createContext<AvatarGroupContextValue>({});
42
-
43
- function useAvatarGroupContext(): AvatarGroupContextValue {
44
- return React.useContext(AvatarGroupContext);
45
- }
46
-
47
- // -- Avatar -----------------------------------------------------------------
48
-
49
- export interface AvatarProps extends React.ComponentPropsWithoutRef<'span'> {
50
- name?: string;
51
- src?: string;
52
- srcSet?: string;
53
- loading?: ImageProps['loading'];
54
- icon?: React.ReactElement;
55
- fallback?: React.ReactNode;
56
- size?: AvatarSize;
57
- variant?: AvatarVariant;
58
- borderless?: boolean;
59
- }
60
-
61
- export const Avatar = React.forwardRef<HTMLSpanElement, AvatarProps>(
62
- function Avatar(props, ref) {
63
- const group = useAvatarGroupContext();
64
- const {
65
- name,
66
- src,
67
- srcSet,
68
- loading,
69
- icon,
70
- fallback,
71
- children,
72
- className,
73
- size: sizeProp,
74
- variant: variantProp,
75
- borderless,
76
- ...rest
77
- } = props;
78
-
79
- const size = sizeProp ?? group.size ?? DEFAULT_SIZE;
80
- const variant = variantProp ?? group.variant ?? DEFAULT_VARIANT;
81
- const isBorderless = borderless ?? group.borderless ?? false;
82
-
83
- return (
84
- <RadixAvatar.Root
85
- ref={ ref }
86
- className={ cn(
87
- 'relative inline-flex shrink-0 items-center justify-center overflow-hidden rounded-full align-middle',
88
- SIZE_CLASSES[size],
89
- VARIANT_CLASSES[variant],
90
- !isBorderless && 'ring-2 ring-white dark:ring-gray-900',
91
- className,
92
- ) }
93
- { ...rest }
94
- >
95
- <AvatarFallback name={ name } icon={ icon }>
96
- { fallback }
97
- </AvatarFallback>
98
- <RadixAvatar.Image
99
- className="h-full w-full rounded-[inherit] object-cover"
100
- src={ src }
101
- srcSet={ srcSet }
102
- loading={ loading }
103
- alt={ name ?? '' }
104
- />
105
- { children }
106
- </RadixAvatar.Root>
107
- );
108
- },
109
- );
110
-
111
- // -- AvatarFallback (internal) ----------------------------------------------
112
-
113
- interface AvatarFallbackInternalProps extends React.ComponentPropsWithoutRef<'span'> {
114
- name?: string;
115
- icon?: React.ReactElement;
116
- }
117
-
118
- const AvatarFallback = React.forwardRef<HTMLSpanElement, AvatarFallbackInternalProps>(
119
- function AvatarFallback(props, ref) {
120
- const { name, icon, children, className, ...rest } = props;
121
- return (
122
- <RadixAvatar.Fallback
123
- ref={ ref }
124
- className={ cn(
125
- 'flex h-full w-full items-center justify-center font-medium',
126
- className,
127
- ) }
128
- { ...rest }
129
- >
130
- { children }
131
- { name != null && children == null && <>{ getInitials(name) }</> }
132
- { name == null && children == null && icon }
133
- </RadixAvatar.Fallback>
134
- );
135
- },
136
- );
137
-
138
- // -- getInitials ------------------------------------------------------------
139
-
140
- function getInitials(name: string): string {
141
- const names = name.trim().split(' ');
142
- const firstName = names[0] != null ? names[0] : '';
143
- const lastName = names.length > 1 ? names[names.length - 1] : '';
144
- return firstName && lastName ?
145
- `${ firstName.charAt(0) }${ lastName.charAt(0) }` :
146
- firstName.charAt(0);
147
- }
148
-
149
- // -- AvatarGroup ------------------------------------------------------------
150
-
151
- interface AvatarGroupProps extends React.ComponentPropsWithoutRef<'div'> {
152
- size?: AvatarSize;
153
- variant?: AvatarVariant;
154
- borderless?: boolean;
155
- }
156
-
157
- export const AvatarGroup = React.forwardRef<HTMLDivElement, AvatarGroupProps>(
158
- function AvatarGroup(props, ref) {
159
- const { size, variant, borderless, className, ...rest } = props;
160
- const contextValue = React.useMemo(
161
- () => ({ size, variant, borderless }),
162
- [ size, variant, borderless ],
163
- );
164
- return (
165
- <AvatarGroupContext.Provider value={ contextValue }>
166
- <div
167
- ref={ ref }
168
- className={ cn('flex -space-x-3', className) }
169
- { ...rest }
170
- />
171
- </AvatarGroupContext.Provider>
172
- );
173
- },
174
- );