@luxfi/ui 5.5.3 → 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 -65
- 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 -112
- 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/button.tsx
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
2
|
+
import { cva } from 'class-variance-authority';
|
|
3
|
+
import type { VariantProps } from 'class-variance-authority';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
|
|
6
|
+
import { cn } from './utils';
|
|
7
|
+
|
|
8
|
+
import { Skeleton } from './skeleton';
|
|
9
|
+
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// CVA variant definition
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// All colors reference CSS custom properties from styles/tokens.css so they
|
|
14
|
+
// automatically adapt to light/dark mode via the .dark class.
|
|
15
|
+
//
|
|
16
|
+
// Sizes use Tailwind spacing utilities that match the old Chakra recipe values:
|
|
17
|
+
// 2xs → h-5 (20px) xs → h-6 (24px) sm → h-8 (32px) md → h-10 (40px)
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
const buttonVariants = cva(
|
|
21
|
+
// base styles (shared across all variants)
|
|
22
|
+
[
|
|
23
|
+
'inline-flex items-center justify-center',
|
|
24
|
+
'gap-0 font-semibold overflow-hidden rounded-md',
|
|
25
|
+
'cursor-pointer select-none whitespace-nowrap',
|
|
26
|
+
'transition-colors duration-150',
|
|
27
|
+
'disabled:opacity-[0.2] disabled:cursor-not-allowed',
|
|
28
|
+
],
|
|
29
|
+
{
|
|
30
|
+
variants: {
|
|
31
|
+
variant: {
|
|
32
|
+
// --- Solid ---
|
|
33
|
+
solid: [
|
|
34
|
+
'bg-[var(--color-button-solid-bg)] text-[var(--color-button-solid-text)]',
|
|
35
|
+
'hover:bg-[var(--color-hover)]',
|
|
36
|
+
'data-[expanded]:bg-[var(--color-hover)]',
|
|
37
|
+
],
|
|
38
|
+
// --- Solid Danger ---
|
|
39
|
+
solid_danger: [
|
|
40
|
+
'bg-red-600 text-[var(--color-button-solid-text)]',
|
|
41
|
+
'hover:bg-red-500',
|
|
42
|
+
'data-[expanded]:bg-red-500',
|
|
43
|
+
],
|
|
44
|
+
// --- Outline ---
|
|
45
|
+
outline: [
|
|
46
|
+
'border-2 border-solid bg-transparent',
|
|
47
|
+
'text-[var(--color-button-outline-fg)] border-[var(--color-button-outline-fg)]',
|
|
48
|
+
'hover:bg-transparent hover:text-[var(--color-hover)] hover:border-[var(--color-hover)]',
|
|
49
|
+
],
|
|
50
|
+
// --- Outline Danger ---
|
|
51
|
+
outline_danger: [
|
|
52
|
+
'border-2 border-solid bg-transparent',
|
|
53
|
+
'text-red-600 border-red-600',
|
|
54
|
+
'hover:bg-transparent hover:text-red-500 hover:border-red-500',
|
|
55
|
+
],
|
|
56
|
+
// --- Dropdown ---
|
|
57
|
+
dropdown: [
|
|
58
|
+
'border-2 border-solid bg-transparent',
|
|
59
|
+
'text-[var(--color-button-dropdown-fg)] border-[var(--color-button-dropdown-border)]',
|
|
60
|
+
'hover:bg-transparent hover:text-[var(--color-hover)] hover:border-[var(--color-hover)]',
|
|
61
|
+
'data-[expanded]:bg-transparent data-[expanded]:text-[var(--color-hover)] data-[expanded]:border-[var(--color-hover)]',
|
|
62
|
+
'data-[selected]:bg-[var(--color-selected-control-bg)] data-[selected]:text-[var(--color-selected-control-text)] data-[selected]:border-transparent',
|
|
63
|
+
'data-[selected]:hover:bg-[var(--color-selected-control-bg)]',
|
|
64
|
+
'data-[selected]:hover:text-[var(--color-hover)] data-[selected]:hover:border-transparent',
|
|
65
|
+
'data-[selected]:data-[expanded]:text-[var(--color-hover)]',
|
|
66
|
+
],
|
|
67
|
+
// --- Header ---
|
|
68
|
+
header: [
|
|
69
|
+
'bg-transparent border-2 border-solid',
|
|
70
|
+
'text-[var(--color-button-header-fg)] border-[var(--color-button-header-border)]',
|
|
71
|
+
'hover:bg-transparent hover:text-[var(--color-hover)] hover:border-[var(--color-hover)]',
|
|
72
|
+
// selected
|
|
73
|
+
'data-[selected]:bg-[var(--color-button-header-bg-selected)]',
|
|
74
|
+
'data-[selected]:text-[var(--color-button-header-fg-selected)] data-[selected]:border-transparent data-[selected]:border-0',
|
|
75
|
+
'data-[selected]:hover:bg-[var(--color-button-header-bg-selected)] data-[selected]:hover:text-[var(--color-hover)]',
|
|
76
|
+
'data-[selected]:data-[expanded]:text-[var(--color-hover)]',
|
|
77
|
+
// selected + highlighted
|
|
78
|
+
'data-[selected]:data-[highlighted]:bg-[var(--color-button-header-bg-highlighted)]',
|
|
79
|
+
'data-[selected]:data-[highlighted]:text-[var(--color-button-header-fg-highlighted)]',
|
|
80
|
+
'data-[selected]:data-[highlighted]:border-transparent data-[selected]:data-[highlighted]:border-0',
|
|
81
|
+
'data-[selected]:data-[highlighted]:hover:bg-[var(--color-button-header-bg-highlighted)]',
|
|
82
|
+
'data-[selected]:data-[highlighted]:hover:text-[var(--color-hover)]',
|
|
83
|
+
'data-[selected]:data-[highlighted]:data-[expanded]:text-[var(--color-hover)]',
|
|
84
|
+
],
|
|
85
|
+
// --- Hero ---
|
|
86
|
+
hero: [
|
|
87
|
+
'bg-[var(--color-button-hero-bg)] text-[var(--color-button-hero-fg)]',
|
|
88
|
+
'hover:bg-[var(--color-button-hero-bg-hover)] hover:text-[var(--color-button-hero-fg-hover)]',
|
|
89
|
+
'data-[selected]:bg-[var(--color-button-hero-bg-selected)] data-[selected]:text-[var(--color-button-hero-fg-selected)]',
|
|
90
|
+
'data-[selected]:hover:bg-[var(--color-button-hero-bg-selected)] data-[selected]:hover:text-[var(--color-hover)]',
|
|
91
|
+
'data-[selected]:data-[expanded]:text-[var(--color-hover)]',
|
|
92
|
+
],
|
|
93
|
+
// --- Segmented ---
|
|
94
|
+
segmented: [
|
|
95
|
+
'bg-transparent border-2 border-solid rounded-none',
|
|
96
|
+
'text-[var(--color-button-segmented-fg)] border-[var(--color-selected-control-bg)]',
|
|
97
|
+
'hover:text-[var(--color-hover)]',
|
|
98
|
+
// selected
|
|
99
|
+
'data-[selected]:bg-[var(--color-selected-control-bg)] data-[selected]:text-[var(--color-selected-control-text)]',
|
|
100
|
+
'data-[selected]:hover:bg-[var(--color-selected-control-bg)] data-[selected]:hover:text-[var(--color-selected-control-text)]',
|
|
101
|
+
// border collapse: hide right border except when selected; first/last get rounded
|
|
102
|
+
'[&:not(:last-child)]:border-r-0 data-[selected]:[&:not(:last-child)]:border-r-2',
|
|
103
|
+
'data-[selected]+*:border-l-0',
|
|
104
|
+
'first:rounded-l-md last:rounded-r-md',
|
|
105
|
+
],
|
|
106
|
+
// --- Plain ---
|
|
107
|
+
plain: [
|
|
108
|
+
'bg-transparent text-inherit border-none',
|
|
109
|
+
'hover:bg-transparent',
|
|
110
|
+
],
|
|
111
|
+
// --- Subtle ---
|
|
112
|
+
subtle: [
|
|
113
|
+
'bg-[var(--color-button-subtle-bg)] text-[var(--color-button-subtle-fg)]',
|
|
114
|
+
'hover:bg-[var(--color-button-subtle-bg)] hover:text-[var(--color-hover)]',
|
|
115
|
+
'disabled:bg-[var(--color-button-subtle-bg)] disabled:text-[var(--color-button-subtle-fg)]',
|
|
116
|
+
],
|
|
117
|
+
// --- Link ---
|
|
118
|
+
link: [
|
|
119
|
+
'bg-transparent text-[var(--color-link-primary)] border-none font-normal',
|
|
120
|
+
'px-0 h-auto',
|
|
121
|
+
'hover:bg-transparent hover:text-[var(--color-link-primary-hover)]',
|
|
122
|
+
'disabled:text-[var(--color-text-secondary)]',
|
|
123
|
+
],
|
|
124
|
+
// --- Icon Secondary ---
|
|
125
|
+
icon_secondary: [
|
|
126
|
+
'bg-transparent text-[var(--color-icon-secondary)] border-none',
|
|
127
|
+
'hover:text-[var(--color-hover)]',
|
|
128
|
+
'data-[selected]:bg-[var(--color-selected-control-bg)] data-[selected]:text-[var(--color-selected-control-text)]',
|
|
129
|
+
'data-[selected]:hover:bg-[var(--color-selected-control-bg)] data-[selected]:hover:text-[var(--color-hover)]',
|
|
130
|
+
'data-[selected]:data-[expanded]:text-[var(--color-hover)]',
|
|
131
|
+
'data-[expanded]:text-[var(--color-hover)]',
|
|
132
|
+
],
|
|
133
|
+
// --- Icon Background ---
|
|
134
|
+
icon_background: [
|
|
135
|
+
'bg-[var(--color-button-icon-background-bg)] text-[var(--color-icon-secondary)] border-none',
|
|
136
|
+
'hover:text-[var(--color-hover)]',
|
|
137
|
+
'data-[selected]:bg-[var(--color-selected-control-bg)] data-[selected]:text-[var(--color-selected-control-text)]',
|
|
138
|
+
'data-[selected]:hover:bg-[var(--color-selected-control-bg)] data-[selected]:hover:text-[var(--color-hover)]',
|
|
139
|
+
'data-[selected]:data-[expanded]:text-[var(--color-hover)]',
|
|
140
|
+
'data-[expanded]:text-[var(--color-hover)]',
|
|
141
|
+
],
|
|
142
|
+
// --- Pagination ---
|
|
143
|
+
pagination: [
|
|
144
|
+
'border-2 border-solid bg-transparent',
|
|
145
|
+
'text-[var(--color-button-pagination-fg)] border-[var(--color-button-pagination-border)]',
|
|
146
|
+
'hover:bg-transparent hover:text-[var(--color-hover)] hover:border-[var(--color-hover)]',
|
|
147
|
+
'data-[selected]:bg-[var(--color-selected-control-bg)] data-[selected]:text-[var(--color-selected-control-text)] data-[selected]:border-transparent',
|
|
148
|
+
'data-[selected]:hover:bg-[var(--color-selected-control-bg)]',
|
|
149
|
+
'data-[selected]:hover:text-[var(--color-selected-control-text)] data-[selected]:hover:border-transparent',
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
size: {
|
|
154
|
+
'2xs': 'px-2 h-5 min-w-5 text-xs rounded-sm gap-1',
|
|
155
|
+
xs: 'px-2 h-6 min-w-6 text-sm rounded-sm gap-1',
|
|
156
|
+
sm: 'px-3 h-8 min-w-8 text-sm rounded-md gap-1',
|
|
157
|
+
md: 'px-3 h-10 min-w-10 text-base rounded-md gap-2',
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
defaultVariants: {
|
|
162
|
+
variant: 'solid',
|
|
163
|
+
size: 'md',
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
// Spinner (replaces Chakra's built-in loading spinner)
|
|
170
|
+
// ---------------------------------------------------------------------------
|
|
171
|
+
|
|
172
|
+
interface SpinnerProps {
|
|
173
|
+
readonly className?: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function Spinner({ className }: SpinnerProps): React.ReactElement {
|
|
177
|
+
return (
|
|
178
|
+
<span
|
|
179
|
+
className={ cn(
|
|
180
|
+
'inline-block h-4 w-4 animate-spin rounded-full',
|
|
181
|
+
'border-2 border-current border-b-transparent border-l-transparent',
|
|
182
|
+
className,
|
|
183
|
+
) }
|
|
184
|
+
role="status"
|
|
185
|
+
aria-label="Loading"
|
|
186
|
+
/>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// ---------------------------------------------------------------------------
|
|
191
|
+
// Button
|
|
192
|
+
// ---------------------------------------------------------------------------
|
|
193
|
+
|
|
194
|
+
export interface ButtonProps
|
|
195
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
196
|
+
VariantProps<typeof buttonVariants> {
|
|
197
|
+
readonly asChild?: boolean;
|
|
198
|
+
readonly loading?: boolean;
|
|
199
|
+
readonly loadingText?: React.ReactNode;
|
|
200
|
+
readonly loadingSkeleton?: boolean;
|
|
201
|
+
readonly expanded?: boolean;
|
|
202
|
+
readonly selected?: boolean;
|
|
203
|
+
readonly highlighted?: boolean;
|
|
204
|
+
// Legacy Chakra style-prop shims
|
|
205
|
+
readonly mt?: number | string;
|
|
206
|
+
readonly ml?: number | string;
|
|
207
|
+
readonly mr?: number | string;
|
|
208
|
+
readonly px?: number | string;
|
|
209
|
+
readonly py?: number | string;
|
|
210
|
+
readonly fontWeight?: number | string;
|
|
211
|
+
readonly gap?: number | string;
|
|
212
|
+
readonly flexShrink?: number;
|
|
213
|
+
readonly columnGap?: number | string;
|
|
214
|
+
readonly gridColumn?: number | string;
|
|
215
|
+
readonly gridRow?: string;
|
|
216
|
+
readonly justifySelf?: string;
|
|
217
|
+
readonly alignSelf?: string;
|
|
218
|
+
readonly textStyle?: string;
|
|
219
|
+
readonly h?: string;
|
|
220
|
+
readonly w?: string;
|
|
221
|
+
readonly display?: string;
|
|
222
|
+
readonly borderBottomRightRadius?: number | string;
|
|
223
|
+
readonly borderTopRightRadius?: number | string;
|
|
224
|
+
readonly 'data-call-strategy'?: string;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
228
|
+
function Button(props, ref) {
|
|
229
|
+
const {
|
|
230
|
+
className,
|
|
231
|
+
variant,
|
|
232
|
+
size,
|
|
233
|
+
asChild = false,
|
|
234
|
+
loading = false,
|
|
235
|
+
loadingText,
|
|
236
|
+
loadingSkeleton = false,
|
|
237
|
+
expanded,
|
|
238
|
+
selected,
|
|
239
|
+
highlighted,
|
|
240
|
+
disabled,
|
|
241
|
+
children,
|
|
242
|
+
style: styleProp,
|
|
243
|
+
// Strip Chakra style props
|
|
244
|
+
mt: _mt, ml: _ml, mr: _mr, px: _px, py: _py,
|
|
245
|
+
fontWeight: _fontWeight, gap: _gap, flexShrink: _flexShrink,
|
|
246
|
+
columnGap: _columnGap, gridColumn: _gridColumn, gridRow: _gridRow,
|
|
247
|
+
justifySelf: _justifySelf, alignSelf: _alignSelf, textStyle: _textStyle,
|
|
248
|
+
h: _h, w: _w, display: _display,
|
|
249
|
+
borderBottomRightRadius: _bbrr, borderTopRightRadius: _btrr,
|
|
250
|
+
...rest
|
|
251
|
+
} = props;
|
|
252
|
+
|
|
253
|
+
const SP = 4;
|
|
254
|
+
const shimStyle: React.CSSProperties = { ...styleProp };
|
|
255
|
+
if (_mt !== undefined) shimStyle.marginTop = typeof _mt === 'number' ? `${ _mt * SP }px` : _mt;
|
|
256
|
+
if (_ml !== undefined) shimStyle.marginLeft = typeof _ml === 'number' ? `${ _ml * SP }px` : _ml;
|
|
257
|
+
if (_mr !== undefined) shimStyle.marginRight = typeof _mr === 'number' ? `${ _mr * SP }px` : _mr;
|
|
258
|
+
if (_px !== undefined) { const v = typeof _px === 'number' ? `${ _px * SP }px` : _px; shimStyle.paddingLeft = v; shimStyle.paddingRight = v; }
|
|
259
|
+
if (_py !== undefined) { const v = typeof _py === 'number' ? `${ _py * SP }px` : _py; shimStyle.paddingTop = v; shimStyle.paddingBottom = v; }
|
|
260
|
+
if (_fontWeight !== undefined) shimStyle.fontWeight = _fontWeight;
|
|
261
|
+
if (_gap !== undefined) shimStyle.gap = typeof _gap === 'number' ? `${ _gap * SP }px` : _gap;
|
|
262
|
+
if (_flexShrink !== undefined) shimStyle.flexShrink = _flexShrink;
|
|
263
|
+
if (_columnGap !== undefined) shimStyle.columnGap = typeof _columnGap === 'number' ? `${ _columnGap * SP }px` : _columnGap;
|
|
264
|
+
if (_gridColumn !== undefined) shimStyle.gridColumn = typeof _gridColumn === 'number' ? String(_gridColumn) : _gridColumn;
|
|
265
|
+
if (_gridRow) shimStyle.gridRow = _gridRow;
|
|
266
|
+
if (_justifySelf) shimStyle.justifySelf = _justifySelf;
|
|
267
|
+
if (_alignSelf) shimStyle.alignSelf = _alignSelf;
|
|
268
|
+
if (_h) shimStyle.height = _h;
|
|
269
|
+
if (_w) shimStyle.width = _w;
|
|
270
|
+
if (_display) shimStyle.display = _display;
|
|
271
|
+
if (_bbrr !== undefined) shimStyle.borderBottomRightRadius = typeof _bbrr === 'number' ? `${ _bbrr }px` : _bbrr;
|
|
272
|
+
if (_btrr !== undefined) shimStyle.borderTopRightRadius = typeof _btrr === 'number' ? `${ _btrr }px` : _btrr;
|
|
273
|
+
const mergedStyle = Object.keys(shimStyle).length > 0 ? shimStyle : undefined;
|
|
274
|
+
|
|
275
|
+
const Comp = asChild ? Slot : 'button';
|
|
276
|
+
|
|
277
|
+
// Build data-* attributes for state-driven variant styles
|
|
278
|
+
const dataAttrs: Record<string, true> = {};
|
|
279
|
+
if (expanded) dataAttrs['data-expanded'] = true;
|
|
280
|
+
if (selected) dataAttrs['data-selected'] = true;
|
|
281
|
+
if (highlighted) dataAttrs['data-highlighted'] = true;
|
|
282
|
+
if (loadingSkeleton) dataAttrs['data-loading-skeleton'] = true;
|
|
283
|
+
|
|
284
|
+
const isDisabled = !loadingSkeleton && (loading || disabled);
|
|
285
|
+
|
|
286
|
+
const inner = loading ? (
|
|
287
|
+
<>
|
|
288
|
+
<Spinner/>
|
|
289
|
+
{ loadingText != null && <span className="ml-2">{ loadingText }</span> }
|
|
290
|
+
</>
|
|
291
|
+
) : (
|
|
292
|
+
children
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
const button = (
|
|
296
|
+
<Comp
|
|
297
|
+
ref={ ref }
|
|
298
|
+
className={ cn(buttonVariants({ variant, size }), className) }
|
|
299
|
+
style={ mergedStyle }
|
|
300
|
+
disabled={ isDisabled || undefined }
|
|
301
|
+
{ ...dataAttrs }
|
|
302
|
+
{ ...rest }
|
|
303
|
+
>
|
|
304
|
+
{ inner }
|
|
305
|
+
</Comp>
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
if (loadingSkeleton) {
|
|
309
|
+
return (
|
|
310
|
+
<Skeleton loading={ loadingSkeleton } asChild ref={ ref as React.ForwardedRef<HTMLDivElement> }>
|
|
311
|
+
{ button }
|
|
312
|
+
</Skeleton>
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return button;
|
|
317
|
+
},
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
// ---------------------------------------------------------------------------
|
|
321
|
+
// ButtonGroup
|
|
322
|
+
// ---------------------------------------------------------------------------
|
|
323
|
+
|
|
324
|
+
export interface ButtonGroupProps extends React.HTMLAttributes<HTMLDivElement> {}
|
|
325
|
+
|
|
326
|
+
export const ButtonGroup = React.forwardRef<HTMLDivElement, ButtonGroupProps>(
|
|
327
|
+
function ButtonGroup(props, ref) {
|
|
328
|
+
const { className, ...rest } = props;
|
|
329
|
+
|
|
330
|
+
return (
|
|
331
|
+
<div
|
|
332
|
+
ref={ ref }
|
|
333
|
+
className={ cn('inline-flex', className) }
|
|
334
|
+
role="group"
|
|
335
|
+
{ ...rest }
|
|
336
|
+
/>
|
|
337
|
+
);
|
|
338
|
+
},
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
// ---------------------------------------------------------------------------
|
|
342
|
+
// ButtonGroupRadio
|
|
343
|
+
// ---------------------------------------------------------------------------
|
|
344
|
+
|
|
345
|
+
export interface ButtonGroupRadioProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children' | 'onChange'> {
|
|
346
|
+
children: Array<React.ReactElement<ButtonProps>>;
|
|
347
|
+
onChange?: (value: string) => void;
|
|
348
|
+
defaultValue?: string;
|
|
349
|
+
loading?: boolean;
|
|
350
|
+
equalWidth?: boolean;
|
|
351
|
+
variant?: ButtonProps['variant'];
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export const ButtonGroupRadio = React.forwardRef<HTMLDivElement, ButtonGroupRadioProps>(
|
|
355
|
+
function ButtonGroupRadio(props, ref) {
|
|
356
|
+
const {
|
|
357
|
+
children,
|
|
358
|
+
onChange,
|
|
359
|
+
variant = 'segmented',
|
|
360
|
+
defaultValue,
|
|
361
|
+
loading = false,
|
|
362
|
+
equalWidth = false,
|
|
363
|
+
className,
|
|
364
|
+
...rest
|
|
365
|
+
} = props;
|
|
366
|
+
|
|
367
|
+
const firstChildValue = React.useMemo(() => {
|
|
368
|
+
const firstChild = Array.isArray(children) ? children[0] : undefined;
|
|
369
|
+
return typeof firstChild?.props.value === 'string' ? firstChild.props.value : undefined;
|
|
370
|
+
}, [ children ]);
|
|
371
|
+
|
|
372
|
+
const [ value, setValue ] = React.useState<string | undefined>(defaultValue ?? firstChildValue);
|
|
373
|
+
|
|
374
|
+
const handleItemClick = React.useCallback((event: React.MouseEvent<HTMLButtonElement>) => {
|
|
375
|
+
const v = event.currentTarget.value;
|
|
376
|
+
setValue(v);
|
|
377
|
+
onChange?.(v);
|
|
378
|
+
}, [ onChange ]);
|
|
379
|
+
|
|
380
|
+
const clonedChildren = React.Children.map(children, (child: React.ReactElement<ButtonProps>) => {
|
|
381
|
+
return React.cloneElement(child, {
|
|
382
|
+
onClick: handleItemClick,
|
|
383
|
+
selected: value === child.props.value,
|
|
384
|
+
variant,
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
const childrenLength = React.Children.count(children);
|
|
389
|
+
|
|
390
|
+
return (
|
|
391
|
+
<Skeleton loading={ loading }>
|
|
392
|
+
<div
|
|
393
|
+
ref={ ref }
|
|
394
|
+
className={ cn(
|
|
395
|
+
'inline-flex gap-0',
|
|
396
|
+
equalWidth && 'grid',
|
|
397
|
+
className,
|
|
398
|
+
) }
|
|
399
|
+
style={ equalWidth ? { gridTemplateColumns: `repeat(${ childrenLength }, 1fr)` } : undefined }
|
|
400
|
+
role="group"
|
|
401
|
+
{ ...rest }
|
|
402
|
+
>
|
|
403
|
+
{ clonedChildren }
|
|
404
|
+
</div>
|
|
405
|
+
</Skeleton>
|
|
406
|
+
);
|
|
407
|
+
},
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
// Re-export the variant function for consumers that need it (e.g., IconButton)
|
|
411
|
+
export { buttonVariants };
|