@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/radio.tsx
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import * as RadixRadioGroup from '@radix-ui/react-radio-group';
|
|
2
|
+
// chakra() HOC removed — pure Radix + Tailwind
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
import { cn } from './utils';
|
|
6
|
+
|
|
7
|
+
// ─── Size classes ───────────────────────────────────────────────────
|
|
8
|
+
const SIZE_CLASSES = {
|
|
9
|
+
xs: {
|
|
10
|
+
root: 'gap-1.5',
|
|
11
|
+
control: 'h-3 w-3',
|
|
12
|
+
indicator: 'h-1.5 w-1.5',
|
|
13
|
+
label: 'text-xs',
|
|
14
|
+
},
|
|
15
|
+
sm: {
|
|
16
|
+
root: 'gap-1.5',
|
|
17
|
+
control: 'h-3.5 w-3.5',
|
|
18
|
+
indicator: 'h-1.5 w-1.5',
|
|
19
|
+
label: 'text-xs',
|
|
20
|
+
},
|
|
21
|
+
md: {
|
|
22
|
+
root: 'gap-2',
|
|
23
|
+
control: 'h-4 w-4',
|
|
24
|
+
indicator: 'h-2 w-2',
|
|
25
|
+
label: 'text-sm',
|
|
26
|
+
},
|
|
27
|
+
lg: {
|
|
28
|
+
root: 'gap-2.5',
|
|
29
|
+
control: 'h-5 w-5',
|
|
30
|
+
indicator: 'h-2.5 w-2.5',
|
|
31
|
+
label: 'text-base',
|
|
32
|
+
},
|
|
33
|
+
} as const;
|
|
34
|
+
|
|
35
|
+
type RadioSize = keyof typeof SIZE_CLASSES;
|
|
36
|
+
|
|
37
|
+
// ─── Size context ───────────────────────────────────────────────────
|
|
38
|
+
const RadioSizeContext = React.createContext<RadioSize>('md');
|
|
39
|
+
|
|
40
|
+
// ─── RadioGroup ─────────────────────────────────────────────────────
|
|
41
|
+
export interface RadioGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'defaultValue' | 'dir'> {
|
|
42
|
+
name?: string;
|
|
43
|
+
required?: boolean;
|
|
44
|
+
disabled?: boolean;
|
|
45
|
+
readOnly?: boolean;
|
|
46
|
+
orientation?: 'horizontal' | 'vertical';
|
|
47
|
+
loop?: boolean;
|
|
48
|
+
defaultValue?: string;
|
|
49
|
+
value?: string | null;
|
|
50
|
+
onValueChange?: (details: { value: string | null }) => void;
|
|
51
|
+
size?: RadioSize;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const RadioGroupBase = React.forwardRef<HTMLDivElement, RadioGroupProps>(
|
|
55
|
+
function RadioGroup(props, ref) {
|
|
56
|
+
const {
|
|
57
|
+
children,
|
|
58
|
+
name,
|
|
59
|
+
required,
|
|
60
|
+
disabled = false,
|
|
61
|
+
readOnly = false,
|
|
62
|
+
orientation = 'vertical',
|
|
63
|
+
loop = true,
|
|
64
|
+
defaultValue,
|
|
65
|
+
value,
|
|
66
|
+
onValueChange,
|
|
67
|
+
size = 'md',
|
|
68
|
+
className,
|
|
69
|
+
...rest
|
|
70
|
+
} = props;
|
|
71
|
+
|
|
72
|
+
const handleValueChange = React.useCallback(
|
|
73
|
+
(nextValue: string) => {
|
|
74
|
+
if (readOnly) return;
|
|
75
|
+
onValueChange?.({ value: nextValue });
|
|
76
|
+
},
|
|
77
|
+
[ readOnly, onValueChange ],
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<RadioSizeContext.Provider value={ size }>
|
|
82
|
+
<RadixRadioGroup.Root
|
|
83
|
+
ref={ ref }
|
|
84
|
+
name={ name }
|
|
85
|
+
required={ required }
|
|
86
|
+
disabled={ disabled || readOnly }
|
|
87
|
+
orientation={ orientation }
|
|
88
|
+
loop={ loop }
|
|
89
|
+
defaultValue={ defaultValue }
|
|
90
|
+
value={ value ?? undefined }
|
|
91
|
+
onValueChange={ handleValueChange }
|
|
92
|
+
className={ cn(
|
|
93
|
+
'flex',
|
|
94
|
+
orientation === 'vertical' ? 'flex-col gap-3' : 'flex-row gap-6',
|
|
95
|
+
className,
|
|
96
|
+
) }
|
|
97
|
+
{ ...rest }
|
|
98
|
+
>
|
|
99
|
+
{ children }
|
|
100
|
+
</RadixRadioGroup.Root>
|
|
101
|
+
</RadioSizeContext.Provider>
|
|
102
|
+
);
|
|
103
|
+
},
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
export const RadioGroup = RadioGroupBase;
|
|
107
|
+
|
|
108
|
+
const NOOP = () => { /* noop */ };
|
|
109
|
+
|
|
110
|
+
// ─── Radio ──────────────────────────────────────────────────────────
|
|
111
|
+
export interface RadioProps extends Omit<React.ComponentPropsWithoutRef<'label'>, 'onChange'> {
|
|
112
|
+
rootRef?: React.Ref<HTMLLabelElement>;
|
|
113
|
+
inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
|
|
114
|
+
value: string;
|
|
115
|
+
disabled?: boolean;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const RadioBase = React.forwardRef<HTMLInputElement, RadioProps>(
|
|
119
|
+
function Radio(props, ref) {
|
|
120
|
+
const { children, inputProps, rootRef, value, disabled, className, ...rest } = props;
|
|
121
|
+
const size = React.useContext(RadioSizeContext);
|
|
122
|
+
const sizeClasses = SIZE_CLASSES[size];
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<label
|
|
126
|
+
ref={ rootRef }
|
|
127
|
+
className={ cn(
|
|
128
|
+
'inline-flex items-center cursor-pointer select-none',
|
|
129
|
+
sizeClasses.root,
|
|
130
|
+
disabled && 'opacity-50 cursor-not-allowed',
|
|
131
|
+
className,
|
|
132
|
+
) }
|
|
133
|
+
data-disabled={ disabled || undefined }
|
|
134
|
+
{ ...rest }
|
|
135
|
+
>
|
|
136
|
+
<RadixRadioGroup.Item
|
|
137
|
+
value={ value }
|
|
138
|
+
disabled={ disabled }
|
|
139
|
+
className={ cn(
|
|
140
|
+
'inline-flex items-center justify-center shrink-0 rounded-full',
|
|
141
|
+
'border-2 border-current/30',
|
|
142
|
+
'data-[state=checked]:border-gray-800 dark:border-white',
|
|
143
|
+
'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-gray-500',
|
|
144
|
+
'transition-colors duration-150',
|
|
145
|
+
sizeClasses.control,
|
|
146
|
+
) }
|
|
147
|
+
>
|
|
148
|
+
<RadixRadioGroup.Indicator
|
|
149
|
+
className={ cn(
|
|
150
|
+
'block rounded-full bg-gray-800 dark:bg-white',
|
|
151
|
+
sizeClasses.indicator,
|
|
152
|
+
) }
|
|
153
|
+
/>
|
|
154
|
+
</RadixRadioGroup.Item>
|
|
155
|
+
{ /* Hidden native input for form compatibility and ref forwarding */ }
|
|
156
|
+
<input
|
|
157
|
+
ref={ ref }
|
|
158
|
+
type="radio"
|
|
159
|
+
className="sr-only"
|
|
160
|
+
value={ value }
|
|
161
|
+
disabled={ disabled }
|
|
162
|
+
tabIndex={ -1 }
|
|
163
|
+
aria-hidden
|
|
164
|
+
onChange={ NOOP }
|
|
165
|
+
{ ...inputProps }
|
|
166
|
+
/>
|
|
167
|
+
{ children != null && (
|
|
168
|
+
<span className={ sizeClasses.label }>{ children }</span>
|
|
169
|
+
) }
|
|
170
|
+
</label>
|
|
171
|
+
);
|
|
172
|
+
},
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
export const Radio = RadioBase;
|
package/src/rating.tsx
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { cn } from './utils';
|
|
4
|
+
|
|
5
|
+
// Inline star icons
|
|
6
|
+
const StarFilledIcon = ({ className }: { readonly className?: string }) => (
|
|
7
|
+
<svg className={ className } viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
|
|
8
|
+
<path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"/>
|
|
9
|
+
</svg>
|
|
10
|
+
);
|
|
11
|
+
const StarOutlineIcon = ({ className }: { readonly className?: string }) => (
|
|
12
|
+
<svg className={ className } viewBox="0 0 20 20" fill="none" stroke="currentColor" xmlns="http://www.w3.org/2000/svg">
|
|
13
|
+
<path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" strokeWidth="1.5"/>
|
|
14
|
+
</svg>
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export interface RatingProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'defaultValue' | 'onChange'> {
|
|
18
|
+
count?: number;
|
|
19
|
+
label?: string | Array<string>;
|
|
20
|
+
defaultValue?: number;
|
|
21
|
+
onValueChange?: ({ value }: { value: number }) => void;
|
|
22
|
+
readOnly?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const Rating = React.forwardRef<HTMLDivElement, RatingProps>(
|
|
26
|
+
function Rating(props, ref) {
|
|
27
|
+
const { count = 5, label: labelProp, defaultValue = 0, onValueChange, readOnly, className, ...rest } = props;
|
|
28
|
+
|
|
29
|
+
const [ value, setValue ] = React.useState(defaultValue);
|
|
30
|
+
const [ hoveredIndex, setHoveredIndex ] = React.useState(-1);
|
|
31
|
+
|
|
32
|
+
const highlightedIndex = hoveredIndex >= 0 && !readOnly ? hoveredIndex + 1 : value;
|
|
33
|
+
const label = Array.isArray(labelProp) ? labelProp[highlightedIndex - 1] : labelProp;
|
|
34
|
+
|
|
35
|
+
const handleClick = React.useCallback((index: number) => () => {
|
|
36
|
+
if (readOnly) return;
|
|
37
|
+
setValue(index);
|
|
38
|
+
onValueChange?.({ value: index });
|
|
39
|
+
}, [ readOnly, onValueChange ]);
|
|
40
|
+
|
|
41
|
+
const handleMouseEnter = React.useCallback((index: number) => () => {
|
|
42
|
+
if (readOnly) return;
|
|
43
|
+
setHoveredIndex(index);
|
|
44
|
+
}, [ readOnly ]);
|
|
45
|
+
|
|
46
|
+
const handleMouseLeave = React.useCallback(() => {
|
|
47
|
+
setHoveredIndex(-1);
|
|
48
|
+
}, []);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div ref={ ref } className={ cn('inline-flex items-center gap-1', className) } { ...rest }>
|
|
52
|
+
<div className="inline-flex items-center" onMouseLeave={ handleMouseLeave }>
|
|
53
|
+
{ Array.from({ length: count }).map((_, index) => {
|
|
54
|
+
const filled = index < highlightedIndex;
|
|
55
|
+
const starIndex = index + 1;
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<button
|
|
59
|
+
key={ index }
|
|
60
|
+
type="button"
|
|
61
|
+
tabIndex={ readOnly ? -1 : 0 }
|
|
62
|
+
aria-label={ `Rate ${ starIndex } of ${ count }` }
|
|
63
|
+
className={ cn(
|
|
64
|
+
'inline-flex items-center justify-center w-5 h-5 text-current',
|
|
65
|
+
readOnly ? 'cursor-default' : 'cursor-pointer',
|
|
66
|
+
) }
|
|
67
|
+
onClick={ handleClick(starIndex) }
|
|
68
|
+
onMouseEnter={ handleMouseEnter(index) }
|
|
69
|
+
>
|
|
70
|
+
{ filled ? <StarFilledIcon className="w-5 h-5"/> : <StarOutlineIcon className="w-5 h-5"/> }
|
|
71
|
+
</button>
|
|
72
|
+
);
|
|
73
|
+
}) }
|
|
74
|
+
</div>
|
|
75
|
+
{ label && <span className="text-sm">{ label }</span> }
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
);
|