@luxfi/ui 5.5.2 → 5.6.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/dist/accordion.cjs +213 -0
- package/dist/accordion.js +186 -0
- package/dist/alert.cjs +553 -0
- package/dist/alert.js +531 -0
- package/dist/avatar.cjs +149 -0
- package/dist/avatar.js +125 -0
- package/dist/badge.cjs +611 -0
- package/dist/badge.js +589 -0
- package/dist/button.cjs +689 -0
- package/dist/button.js +664 -0
- package/dist/checkbox.cjs +265 -0
- package/dist/checkbox.js +241 -0
- package/dist/close-button.cjs +73 -0
- package/dist/close-button.js +51 -0
- package/dist/collapsible.cjs +702 -0
- package/dist/collapsible.js +679 -0
- package/dist/color-mode.cjs +96 -0
- package/dist/color-mode.js +72 -0
- package/dist/dialog.cjs +279 -0
- package/dist/dialog.js +246 -0
- package/dist/drawer.cjs +207 -0
- package/dist/drawer.js +175 -0
- package/dist/empty-state.cjs +93 -0
- package/dist/empty-state.js +71 -0
- package/dist/field.cjs +183 -0
- package/dist/field.js +160 -0
- package/dist/heading.cjs +46 -0
- package/dist/heading.js +40 -0
- package/dist/icon-button.cjs +491 -0
- package/dist/icon-button.js +470 -0
- package/dist/image.cjs +572 -0
- package/dist/image.js +551 -0
- package/dist/index.cjs +5779 -0
- package/dist/index.js +5619 -0
- package/dist/input-group.cjs +155 -0
- package/dist/input-group.js +133 -0
- package/dist/input.cjs +65 -0
- package/dist/input.js +59 -0
- package/dist/link.cjs +630 -0
- package/dist/link.js +606 -0
- package/dist/menu.cjs +305 -0
- package/dist/menu.js +269 -0
- package/dist/pin-input.cjs +182 -0
- package/dist/pin-input.js +160 -0
- package/dist/popover.cjs +327 -0
- package/dist/popover.js +294 -0
- package/dist/progress-circle.cjs +152 -0
- package/dist/progress-circle.js +128 -0
- package/dist/progress.cjs +117 -0
- package/dist/progress.js +94 -0
- package/dist/provider.cjs +62 -0
- package/dist/provider.js +40 -0
- package/dist/radio.cjs +177 -0
- package/dist/radio.js +153 -0
- package/dist/rating.cjs +80 -0
- package/dist/rating.js +58 -0
- package/dist/select.cjs +791 -0
- package/dist/select.js +757 -0
- package/dist/separator.cjs +57 -0
- package/dist/separator.js +51 -0
- package/dist/skeleton.cjs +370 -0
- package/dist/skeleton.js +346 -0
- package/dist/slider.cjs +138 -0
- package/dist/slider.js +115 -0
- package/dist/switch.cjs +163 -0
- package/dist/switch.js +140 -0
- package/dist/table.cjs +1044 -0
- package/dist/table.js +1013 -0
- package/dist/tabs.cjs +240 -0
- package/dist/tabs.js +213 -0
- package/dist/tag.cjs +651 -0
- package/dist/tag.js +628 -0
- package/dist/textarea.cjs +65 -0
- package/dist/textarea.js +59 -0
- package/dist/toaster.cjs +99 -0
- package/dist/toaster.js +96 -0
- package/dist/tooltip.cjs +171 -0
- package/dist/tooltip.js +148 -0
- package/dist/utils.cjs +11 -0
- package/dist/utils.js +9 -0
- package/package.json +270 -66
- package/src/accordion.tsx +285 -0
- package/src/alert.tsx +221 -0
- package/src/avatar.tsx +174 -0
- package/src/badge.tsx +158 -0
- package/src/button.tsx +411 -0
- package/src/checkbox.tsx +307 -0
- package/src/close-button.tsx +51 -0
- package/src/collapsible.tsx +126 -0
- package/src/color-mode.tsx +125 -0
- package/src/dialog.tsx +356 -0
- package/src/drawer.tsx +186 -0
- package/src/empty-state.tsx +97 -0
- package/src/field.tsx +202 -0
- package/src/heading.tsx +55 -0
- package/src/icon-button.tsx +192 -0
- package/src/image.tsx +280 -0
- package/src/index.ts +192 -0
- package/src/input-group.tsx +159 -0
- package/src/input.tsx +60 -0
- package/src/link.tsx +326 -0
- package/src/menu.tsx +471 -0
- package/src/pin-input.tsx +187 -0
- package/src/popover.tsx +400 -0
- package/src/progress-circle.tsx +180 -0
- package/src/progress.tsx +109 -0
- package/src/provider.tsx +12 -0
- package/src/radio.tsx +175 -0
- package/src/rating.tsx +79 -0
- package/src/select.tsx +696 -0
- package/src/separator.tsx +59 -0
- package/src/skeleton.tsx +302 -0
- package/src/slider.tsx +152 -0
- package/src/switch.tsx +158 -0
- package/src/table.tsx +621 -0
- package/src/tabs.tsx +354 -0
- package/src/tag.tsx +159 -0
- package/src/textarea.tsx +60 -0
- package/src/toaster.tsx +117 -0
- package/src/tokens.css +438 -0
- package/src/tooltip.tsx +184 -0
- package/src/utils/cn.ts +7 -0
- package/src/utils.ts +6 -0
- package/tokens.css +438 -0
- package/commerce/ui/conf.ts +0 -13
- package/commerce/ui/context.tsx +0 -123
- package/commerce/ui/store.ts +0 -295
- package/components/access-code-input.tsx +0 -71
- package/components/analytics.tsx +0 -23
- package/components/auth/auth-listener.tsx +0 -29
- package/components/auth/auth-token/clear-auth-token.tsx +0 -12
- package/components/auth/auth-token/set-auth-token.tsx +0 -16
- package/components/auth/common-auth-domains.ts +0 -17
- package/components/auth/login-panel.tsx +0 -111
- package/components/auth/mobile-login-button.tsx +0 -107
- package/components/auth/signup-panel.tsx +0 -113
- package/components/back-button.tsx +0 -49
- package/components/chat-widget.tsx +0 -85
- package/components/commerce/bag-button.tsx +0 -98
- package/components/commerce/buy-button.tsx +0 -34
- package/components/commerce/checkout-button.tsx +0 -129
- package/components/commerce/checkout-panel/cart-accordian.tsx +0 -66
- package/components/commerce/checkout-panel/checkout-panel-props.ts +0 -10
- package/components/commerce/checkout-panel/desktop-bag-carousel.tsx +0 -36
- package/components/commerce/checkout-panel/desktop-cp.tsx +0 -83
- package/components/commerce/checkout-panel/index.tsx +0 -126
- package/components/commerce/checkout-panel/mobile-cp.tsx +0 -67
- package/components/commerce/checkout-panel/policy-links.tsx +0 -29
- package/components/commerce/checkout-panel/steps-indicator.tsx +0 -39
- package/components/commerce/checkout-panel/thank-you.tsx +0 -18
- package/components/commerce/desktop-bag-popup.tsx +0 -78
- package/components/commerce/drawer/index.tsx +0 -88
- package/components/commerce/drawer/micro.tsx +0 -145
- package/components/commerce/drawer/shell.tsx +0 -85
- package/components/contact-dialog/contact-form.tsx +0 -116
- package/components/contact-dialog/disclaimer.tsx +0 -13
- package/components/contact-dialog/index.tsx +0 -64
- package/components/copyright.tsx +0 -21
- package/components/drawer-margin.tsx +0 -28
- package/components/footer.tsx +0 -78
- package/components/header/desktop-nav-menu.tsx +0 -204
- package/components/header/desktop.tsx +0 -65
- package/components/header/index.tsx +0 -50
- package/components/header/mobile-bag-drawer.tsx +0 -51
- package/components/header/mobile-menu-toggle-button.tsx +0 -35
- package/components/header/mobile-nav-menu-ai.tsx +0 -51
- package/components/header/mobile-nav-menu-item.tsx +0 -47
- package/components/header/mobile-nav-menu.tsx +0 -102
- package/components/header/mobile.tsx +0 -170
- package/components/header/theme-toggle.tsx +0 -26
- package/components/icons/avatar.tsx +0 -11
- package/components/icons/bag-icon.tsx +0 -10
- package/components/icons/index.ts +0 -6
- package/components/icons/left-arrow.tsx +0 -11
- package/components/icons/lux-logo.tsx +0 -10
- package/components/icons/right-arrow.tsx +0 -10
- package/components/icons/social-icon.tsx +0 -35
- package/components/icons/social-svg.css +0 -3
- package/components/index.ts +0 -26
- package/components/logo.tsx +0 -92
- package/components/main.tsx +0 -27
- package/components/mini-chart/index.tsx +0 -8
- package/components/mini-chart/mini-chart-props.ts +0 -44
- package/components/mini-chart/mini-chart.tsx +0 -85
- package/components/mini-chart/wrapper.tsx +0 -23
- package/components/not-found/index.tsx +0 -28
- package/components/not-found/not-found-content.mdx +0 -5
- package/components/tooltip.tsx +0 -31
- package/environment.d.ts +0 -6
- package/next/analytics/fpixel.ts +0 -16
- package/next/analytics/google-analytics.ts +0 -14
- package/next/analytics/index.ts +0 -3
- package/next/analytics/pixel-analytics.tsx +0 -55
- package/next/font/get-app-router-font-classes.ts +0 -17
- package/next/font/load-and-return-lux-next-fonts-on-import.ts +0 -68
- package/next/font/local/Druk-Wide-Bold.ttf +0 -0
- package/next/font/local/Druk-Wide-Medium.ttf +0 -0
- package/next/font/local/InterVariable-Italic.ttf +0 -0
- package/next/font/local/InterVariable-Italic.woff2 +0 -0
- package/next/font/local/InterVariable.ttf +0 -0
- package/next/font/local/InterVariable.woff2 +0 -0
- package/next/font/next-font-desc.ts +0 -28
- package/next/font/pages-router-font-vars.tsx +0 -18
- package/next/head-metadata/from-next/metadata-types.ts +0 -158
- package/next/head-metadata/from-next/opengraph-types.ts +0 -267
- package/next/head-metadata/from-next/twitter-types.ts +0 -92
- package/next/head-metadata/index.tsx +0 -208
- package/next/index.ts +0 -2
- package/next/middleware/determine-device-mw.ts +0 -29
- package/root-layout/WHY_THIS_IS_SEPARATE.txt +0 -2
- package/root-layout/index.tsx +0 -111
- package/server/auth-wrapper.ts +0 -24
- package/server-actions/TO-DO.txt +0 -1
- package/server-actions/firebase-app.ts +0 -29
- package/server-actions/index.ts +0 -5
- package/server-actions/store-contact.ts +0 -66
- package/site-def/footer/community.tsx +0 -61
- package/site-def/footer/company.ts +0 -37
- package/site-def/footer/ecosystem.ts +0 -37
- package/site-def/footer/index.tsx +0 -26
- package/site-def/footer/legal.ts +0 -28
- package/site-def/footer/network.ts +0 -45
- package/site-def/footer/svg/warpcast-logo.svg +0 -12
- package/site-def/index.ts +0 -4
- package/site-def/main-nav.tsx +0 -460
- package/style/cart-animation.css +0 -29
- package/style/checkout-animation.css +0 -23
- package/style/drawer-handle-overrides.css +0 -160
- package/style/fonts/COPY_TO_PUBLIC_FOR_NON_NEXT.txt +0 -0
- package/style/fonts/Druk-Wide-Bold.ttf +0 -0
- package/style/fonts/Druk-Wide-Medium.ttf +0 -0
- package/style/fonts/InterVariable-Italic.ttf +0 -0
- package/style/fonts/InterVariable-Italic.woff2 +0 -0
- package/style/fonts/InterVariable.ttf +0 -0
- package/style/fonts/InterVariable.woff2 +0 -0
- package/style/lux-colors.css +0 -85
- package/style/lux-fonts.css +0 -30
- package/style/lux-global-non-next.css +0 -52
- package/style/lux-global.css +0 -51
- package/tailwind/fontFamily.tailwind.lux.ts +0 -18
- package/tailwind/index.ts +0 -2
- package/tailwind/lux-tw-fonts.ts +0 -40
- package/tailwind/tailwind.config.lux-preset.ts +0 -10
- package/tsconfig.json +0 -15
- package/types/chatbot-config.ts +0 -7
- package/types/chatbot-suggested-question.ts +0 -7
- package/types/contact-info.ts +0 -11
- package/types/index.ts +0 -4
- package/types/site-def.ts +0 -46
package/src/alert.tsx
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
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
|
+
);
|
package/src/badge.tsx
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { cva } from 'class-variance-authority';
|
|
2
|
+
import type { VariantProps } from 'class-variance-authority';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
import { cn } from './utils';
|
|
6
|
+
|
|
7
|
+
import { Skeleton } from './skeleton';
|
|
8
|
+
import { Tooltip } from './tooltip';
|
|
9
|
+
|
|
10
|
+
// Inline truncation tooltip (replaces explorer's TruncatedTextTooltip)
|
|
11
|
+
function TruncatedTextTooltip({ label, children }: { readonly label: React.ReactNode; readonly children: React.ReactNode }) {
|
|
12
|
+
return (
|
|
13
|
+
<Tooltip content={ label } positioning={{ placement: 'top' }}>
|
|
14
|
+
{ children }
|
|
15
|
+
</Tooltip>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type ColorPalette =
|
|
20
|
+
'gray' | 'green' | 'red' | 'purple' | 'orange' | 'blue' | 'yellow' |
|
|
21
|
+
'teal' | 'cyan' | 'pink' | 'purple_alt' | 'blue_alt' |
|
|
22
|
+
'bright_gray' | 'bright_green' | 'bright_red' | 'bright_blue' |
|
|
23
|
+
'bright_yellow' | 'bright_teal' | 'bright_cyan' | 'bright_orange' |
|
|
24
|
+
'bright_purple' | 'bright_pink';
|
|
25
|
+
|
|
26
|
+
const badgeVariants = cva(
|
|
27
|
+
'inline-flex items-center rounded-sm gap-1 font-medium w-fit max-w-full whitespace-nowrap select-text',
|
|
28
|
+
{
|
|
29
|
+
variants: {
|
|
30
|
+
variant: {
|
|
31
|
+
subtle: '',
|
|
32
|
+
solid: '',
|
|
33
|
+
},
|
|
34
|
+
size: {
|
|
35
|
+
sm: 'text-xs p-1 h-[18px] min-h-[18px]',
|
|
36
|
+
md: 'text-sm px-1 py-0.5 min-h-6',
|
|
37
|
+
lg: 'text-sm px-2 py-1 min-h-7 font-semibold',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
defaultVariants: {
|
|
41
|
+
variant: 'subtle',
|
|
42
|
+
size: 'md',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const COLOR_PALETTE_CLASSES: Record<ColorPalette, string> = {
|
|
48
|
+
gray: 'bg-badge-gray-bg text-badge-gray-fg',
|
|
49
|
+
green: 'bg-badge-green-bg text-badge-green-fg',
|
|
50
|
+
red: 'bg-badge-red-bg text-badge-red-fg',
|
|
51
|
+
purple: 'bg-badge-purple-bg text-badge-purple-fg',
|
|
52
|
+
orange: 'bg-badge-orange-bg text-badge-orange-fg',
|
|
53
|
+
blue: 'bg-badge-blue-bg text-badge-blue-fg',
|
|
54
|
+
yellow: 'bg-badge-yellow-bg text-badge-yellow-fg',
|
|
55
|
+
teal: 'bg-badge-teal-bg text-badge-teal-fg',
|
|
56
|
+
cyan: 'bg-badge-cyan-bg text-badge-cyan-fg',
|
|
57
|
+
pink: 'bg-badge-pink-bg text-badge-pink-fg',
|
|
58
|
+
purple_alt: 'bg-badge-purple-alt-bg text-badge-purple-alt-fg',
|
|
59
|
+
blue_alt: 'bg-badge-blue-alt-bg text-badge-blue-alt-fg',
|
|
60
|
+
bright_gray: 'bg-badge-bright-gray-bg text-badge-bright-gray-fg',
|
|
61
|
+
bright_green: 'bg-badge-bright-green-bg text-badge-bright-green-fg',
|
|
62
|
+
bright_red: 'bg-badge-bright-red-bg text-badge-bright-red-fg',
|
|
63
|
+
bright_blue: 'bg-badge-bright-blue-bg text-badge-bright-blue-fg',
|
|
64
|
+
bright_yellow: 'bg-badge-bright-yellow-bg text-badge-bright-yellow-fg',
|
|
65
|
+
bright_teal: 'bg-badge-bright-teal-bg text-badge-bright-teal-fg',
|
|
66
|
+
bright_cyan: 'bg-badge-bright-cyan-bg text-badge-bright-cyan-fg',
|
|
67
|
+
bright_orange: 'bg-badge-bright-orange-bg text-badge-bright-orange-fg',
|
|
68
|
+
bright_purple: 'bg-badge-bright-purple-bg text-badge-bright-purple-fg',
|
|
69
|
+
bright_pink: 'bg-badge-bright-pink-bg text-badge-bright-pink-fg',
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export interface BadgeProps
|
|
73
|
+
extends Omit<React.HTMLAttributes<HTMLSpanElement>, 'color'>,
|
|
74
|
+
VariantProps<typeof badgeVariants> {
|
|
75
|
+
readonly loading?: boolean;
|
|
76
|
+
readonly startElement?: React.ReactNode;
|
|
77
|
+
readonly endElement?: React.ReactNode;
|
|
78
|
+
readonly truncated?: boolean;
|
|
79
|
+
readonly colorPalette?: ColorPalette;
|
|
80
|
+
// Legacy Chakra style-prop shims
|
|
81
|
+
readonly flexShrink?: number;
|
|
82
|
+
readonly gap?: number | string;
|
|
83
|
+
readonly ml?: number | string | Record<string, number>;
|
|
84
|
+
readonly mr?: number | string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const Badge = React.forwardRef<HTMLDivElement, BadgeProps>(
|
|
88
|
+
function Badge(props, ref) {
|
|
89
|
+
const {
|
|
90
|
+
loading,
|
|
91
|
+
startElement,
|
|
92
|
+
children,
|
|
93
|
+
truncated = false,
|
|
94
|
+
endElement,
|
|
95
|
+
variant,
|
|
96
|
+
size,
|
|
97
|
+
colorPalette = 'gray',
|
|
98
|
+
className,
|
|
99
|
+
flexShrink: _flexShrink,
|
|
100
|
+
gap: _gap,
|
|
101
|
+
ml: _ml,
|
|
102
|
+
mr: _mr,
|
|
103
|
+
style: styleProp,
|
|
104
|
+
...rest
|
|
105
|
+
} = props;
|
|
106
|
+
|
|
107
|
+
const shimStyle: React.CSSProperties = { ...styleProp };
|
|
108
|
+
if (_flexShrink !== undefined) shimStyle.flexShrink = _flexShrink;
|
|
109
|
+
if (_gap !== undefined) shimStyle.gap = typeof _gap === 'number' ? `${ _gap * 4 }px` : _gap;
|
|
110
|
+
if (_ml !== undefined) {
|
|
111
|
+
if (typeof _ml === 'object') {
|
|
112
|
+
const obj = _ml as Record<string, number>;
|
|
113
|
+
shimStyle.marginLeft = `${ (obj.base ?? obj.lg ?? 0) * 4 }px`;
|
|
114
|
+
} else {
|
|
115
|
+
shimStyle.marginLeft = typeof _ml === 'number' ? `${ _ml * 4 }px` : _ml;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (_mr !== undefined) shimStyle.marginRight = typeof _mr === 'number' ? `${ _mr * 4 }px` : _mr;
|
|
119
|
+
const badgeStyle = Object.keys(shimStyle).length > 0 ? shimStyle : undefined;
|
|
120
|
+
|
|
121
|
+
const child = children ? (
|
|
122
|
+
<span className="overflow-hidden text-ellipsis">{ children }</span>
|
|
123
|
+
) : null;
|
|
124
|
+
|
|
125
|
+
const childrenElement = truncated ? (
|
|
126
|
+
<TruncatedTextTooltip label={ children }>
|
|
127
|
+
{ child }
|
|
128
|
+
</TruncatedTextTooltip>
|
|
129
|
+
) : child;
|
|
130
|
+
|
|
131
|
+
const badgeElement = (
|
|
132
|
+
<span
|
|
133
|
+
ref={ ref as React.Ref<HTMLSpanElement> }
|
|
134
|
+
className={ cn(
|
|
135
|
+
badgeVariants({ variant, size }),
|
|
136
|
+
COLOR_PALETTE_CLASSES[colorPalette],
|
|
137
|
+
className,
|
|
138
|
+
) }
|
|
139
|
+
style={ badgeStyle }
|
|
140
|
+
{ ...rest }
|
|
141
|
+
>
|
|
142
|
+
{ startElement }
|
|
143
|
+
{ childrenElement }
|
|
144
|
+
{ endElement }
|
|
145
|
+
</span>
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
if (loading) {
|
|
149
|
+
return (
|
|
150
|
+
<Skeleton loading={ loading } asChild>
|
|
151
|
+
{ badgeElement }
|
|
152
|
+
</Skeleton>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return badgeElement;
|
|
157
|
+
},
|
|
158
|
+
);
|