@soadtech/cli 0.1.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/index.js +272 -0
- package/package.json +24 -0
- package/registry/base/cn.ts +5 -0
- package/registry/base/css-modules.d.ts +4 -0
- package/registry/base/theme/reset.css +43 -0
- package/registry/base/theme/tokens.css +154 -0
- package/registry/components/Accordion/Accordion.module.css +3 -0
- package/registry/components/Accordion/Accordion.tsx +54 -0
- package/registry/components/Accordion/Accordion.types.ts +17 -0
- package/registry/components/Accordion/AccordionContext.ts +18 -0
- package/registry/components/Accordion/AccordionItem.module.css +124 -0
- package/registry/components/Accordion/AccordionItem.tsx +148 -0
- package/registry/components/Accordion/AccordionItem.types.ts +14 -0
- package/registry/components/Accordion/index.ts +8 -0
- package/registry/components/ActionBar/ActionBar.module.css +18 -0
- package/registry/components/ActionBar/ActionBar.tsx +21 -0
- package/registry/components/ActionBar/ActionBar.types.ts +8 -0
- package/registry/components/ActionBar/ActionBarLink.module.css +31 -0
- package/registry/components/ActionBar/ActionBarLink.tsx +55 -0
- package/registry/components/ActionBar/ActionBarLink.types.ts +7 -0
- package/registry/components/ActionBar/index.ts +4 -0
- package/registry/components/Alert/Alert.module.css +172 -0
- package/registry/components/Alert/Alert.tsx +146 -0
- package/registry/components/Alert/Alert.types.ts +25 -0
- package/registry/components/Alert/index.ts +7 -0
- package/registry/components/Avatar/Avatar.module.css +100 -0
- package/registry/components/Avatar/Avatar.tsx +54 -0
- package/registry/components/Avatar/Avatar.types.ts +18 -0
- package/registry/components/Avatar/AvatarGroup.module.css +64 -0
- package/registry/components/Avatar/AvatarGroup.tsx +65 -0
- package/registry/components/Avatar/AvatarGroup.types.ts +13 -0
- package/registry/components/Avatar/index.ts +8 -0
- package/registry/components/Badge/Badge.module.css +92 -0
- package/registry/components/Badge/Badge.tsx +89 -0
- package/registry/components/Badge/Badge.types.ts +20 -0
- package/registry/components/Badge/TrendBadge.module.css +47 -0
- package/registry/components/Badge/TrendBadge.tsx +65 -0
- package/registry/components/Badge/TrendBadge.types.ts +15 -0
- package/registry/components/Badge/index.ts +14 -0
- package/registry/components/Breadcrumbs/BreadcrumbItem.tsx +41 -0
- package/registry/components/Breadcrumbs/Breadcrumbs.module.css +81 -0
- package/registry/components/Breadcrumbs/Breadcrumbs.tsx +71 -0
- package/registry/components/Breadcrumbs/Breadcrumbs.types.ts +22 -0
- package/registry/components/Breadcrumbs/index.ts +7 -0
- package/registry/components/Button/Button.module.css +169 -0
- package/registry/components/Button/Button.tsx +43 -0
- package/registry/components/Button/Button.types.ts +18 -0
- package/registry/components/Button/index.ts +7 -0
- package/registry/components/ButtonLink/ButtonLink.module.css +85 -0
- package/registry/components/ButtonLink/ButtonLink.tsx +42 -0
- package/registry/components/ButtonLink/ButtonLink.types.ts +18 -0
- package/registry/components/ButtonLink/index.ts +6 -0
- package/registry/components/Calendar/Calendar.module.css +213 -0
- package/registry/components/Calendar/Calendar.tsx +370 -0
- package/registry/components/Calendar/Calendar.types.ts +28 -0
- package/registry/components/Calendar/CalendarDialog.module.css +29 -0
- package/registry/components/Calendar/CalendarDialog.tsx +173 -0
- package/registry/components/Calendar/CalendarDialog.types.ts +30 -0
- package/registry/components/Calendar/index.ts +9 -0
- package/registry/components/Card/Card.module.css +35 -0
- package/registry/components/Card/Card.tsx +36 -0
- package/registry/components/Card/Card.types.ts +37 -0
- package/registry/components/Card/CardContent.module.css +3 -0
- package/registry/components/Card/CardContent.tsx +16 -0
- package/registry/components/Card/CardFooter.module.css +31 -0
- package/registry/components/Card/CardFooter.tsx +34 -0
- package/registry/components/Card/CardHeader.module.css +61 -0
- package/registry/components/Card/CardHeader.tsx +46 -0
- package/registry/components/Card/InsightCard.module.css +106 -0
- package/registry/components/Card/InsightCard.tsx +68 -0
- package/registry/components/Card/InsightCard.types.ts +24 -0
- package/registry/components/Card/KPICard.module.css +31 -0
- package/registry/components/Card/KPICard.tsx +29 -0
- package/registry/components/Card/KPICard.types.ts +13 -0
- package/registry/components/Card/ListItemCard.module.css +59 -0
- package/registry/components/Card/ListItemCard.tsx +37 -0
- package/registry/components/Card/ListItemCard.types.ts +18 -0
- package/registry/components/Card/PlanCard.module.css +125 -0
- package/registry/components/Card/PlanCard.tsx +108 -0
- package/registry/components/Card/PlanCard.types.ts +30 -0
- package/registry/components/Card/ProductCard.module.css +118 -0
- package/registry/components/Card/ProductCard.tsx +56 -0
- package/registry/components/Card/ProductCard.types.ts +24 -0
- package/registry/components/Card/StatCard.module.css +20 -0
- package/registry/components/Card/StatCard.tsx +26 -0
- package/registry/components/Card/StatCard.types.ts +12 -0
- package/registry/components/Card/UserGroupCard.module.css +50 -0
- package/registry/components/Card/UserGroupCard.tsx +59 -0
- package/registry/components/Card/UserGroupCard.types.ts +23 -0
- package/registry/components/Card/index.ts +38 -0
- package/registry/components/Chart/BarChart.module.css +54 -0
- package/registry/components/Chart/BarChart.tsx +196 -0
- package/registry/components/Chart/BarChart.types.ts +20 -0
- package/registry/components/Chart/ChartAction.module.css +43 -0
- package/registry/components/Chart/ChartAction.tsx +35 -0
- package/registry/components/Chart/ChartAction.types.ts +17 -0
- package/registry/components/Chart/ChartAxis.module.css +47 -0
- package/registry/components/Chart/ChartAxis.tsx +79 -0
- package/registry/components/Chart/ChartAxis.types.ts +14 -0
- package/registry/components/Chart/ChartLegend.module.css +31 -0
- package/registry/components/Chart/ChartLegend.tsx +49 -0
- package/registry/components/Chart/ChartLegend.types.ts +18 -0
- package/registry/components/Chart/ChartTooltip.module.css +54 -0
- package/registry/components/Chart/ChartTooltip.tsx +44 -0
- package/registry/components/Chart/ChartTooltip.types.ts +19 -0
- package/registry/components/Chart/DonutChart.module.css +32 -0
- package/registry/components/Chart/DonutChart.tsx +107 -0
- package/registry/components/Chart/DonutChart.types.ts +20 -0
- package/registry/components/Chart/GridChart.module.css +26 -0
- package/registry/components/Chart/GridChart.tsx +61 -0
- package/registry/components/Chart/GridChart.types.ts +14 -0
- package/registry/components/Chart/HoverTooltip.module.css +16 -0
- package/registry/components/Chart/HoverTooltip.tsx +22 -0
- package/registry/components/Chart/KPIIndicator.module.css +48 -0
- package/registry/components/Chart/KPIIndicator.tsx +28 -0
- package/registry/components/Chart/KPIIndicator.types.ts +16 -0
- package/registry/components/Chart/LineChart.module.css +54 -0
- package/registry/components/Chart/LineChart.tsx +282 -0
- package/registry/components/Chart/LineChart.types.ts +22 -0
- package/registry/components/Chart/ProgressChart.module.css +54 -0
- package/registry/components/Chart/ProgressChart.tsx +64 -0
- package/registry/components/Chart/ProgressChart.types.ts +18 -0
- package/registry/components/Chart/TrendLineChart.module.css +5 -0
- package/registry/components/Chart/TrendLineChart.tsx +131 -0
- package/registry/components/Chart/TrendLineChart.types.ts +19 -0
- package/registry/components/Chart/chart.utils.ts +131 -0
- package/registry/components/Chart/index.ts +47 -0
- package/registry/components/Chart/useChartHover.ts +24 -0
- package/registry/components/Checkbox/Checkbox.module.css +101 -0
- package/registry/components/Checkbox/Checkbox.tsx +100 -0
- package/registry/components/Checkbox/Checkbox.types.ts +11 -0
- package/registry/components/Checkbox/CheckboxField.module.css +69 -0
- package/registry/components/Checkbox/CheckboxField.tsx +54 -0
- package/registry/components/Checkbox/CheckboxField.types.ts +9 -0
- package/registry/components/Checkbox/CheckboxGroup.module.css +41 -0
- package/registry/components/Checkbox/CheckboxGroup.tsx +60 -0
- package/registry/components/Checkbox/CheckboxGroup.types.ts +11 -0
- package/registry/components/Checkbox/CheckboxGroupContext.ts +13 -0
- package/registry/components/Checkbox/index.ts +11 -0
- package/registry/components/Chip/Chip.module.css +143 -0
- package/registry/components/Chip/Chip.tsx +93 -0
- package/registry/components/Chip/Chip.types.ts +19 -0
- package/registry/components/Chip/ChipGroup.module.css +5 -0
- package/registry/components/Chip/ChipGroup.tsx +16 -0
- package/registry/components/Chip/ChipGroup.types.ts +3 -0
- package/registry/components/Chip/index.ts +9 -0
- package/registry/components/Datepicker/Datepicker.module.css +133 -0
- package/registry/components/Datepicker/Datepicker.tsx +236 -0
- package/registry/components/Datepicker/Datepicker.types.ts +36 -0
- package/registry/components/Datepicker/index.ts +2 -0
- package/registry/components/Dialog/Dialog.module.css +18 -0
- package/registry/components/Dialog/Dialog.tsx +69 -0
- package/registry/components/Dialog/Dialog.types.ts +45 -0
- package/registry/components/Dialog/DialogBody.module.css +3 -0
- package/registry/components/Dialog/DialogBody.tsx +16 -0
- package/registry/components/Dialog/DialogContext.ts +11 -0
- package/registry/components/Dialog/DialogFooter.module.css +38 -0
- package/registry/components/Dialog/DialogFooter.tsx +30 -0
- package/registry/components/Dialog/DialogHeader.module.css +70 -0
- package/registry/components/Dialog/DialogHeader.tsx +72 -0
- package/registry/components/Dialog/DialogIcon.module.css +31 -0
- package/registry/components/Dialog/DialogIcon.tsx +89 -0
- package/registry/components/Dialog/index.ts +14 -0
- package/registry/components/Divider/Divider.module.css +19 -0
- package/registry/components/Divider/Divider.tsx +20 -0
- package/registry/components/Divider/Divider.types.ts +9 -0
- package/registry/components/Divider/index.ts +2 -0
- package/registry/components/DropdownMenu/DropdownMenu.module.css +9 -0
- package/registry/components/DropdownMenu/DropdownMenu.tsx +21 -0
- package/registry/components/DropdownMenu/DropdownMenu.types.ts +22 -0
- package/registry/components/DropdownMenu/DropdownMenuDivider.module.css +5 -0
- package/registry/components/DropdownMenu/DropdownMenuDivider.tsx +20 -0
- package/registry/components/DropdownMenu/DropdownMenuHeader.module.css +7 -0
- package/registry/components/DropdownMenu/DropdownMenuHeader.tsx +17 -0
- package/registry/components/DropdownMenu/DropdownMenuItem.module.css +78 -0
- package/registry/components/DropdownMenu/DropdownMenuItem.tsx +40 -0
- package/registry/components/DropdownMenu/index.ts +10 -0
- package/registry/components/FileUpload/FileUpload.module.css +122 -0
- package/registry/components/FileUpload/FileUpload.tsx +354 -0
- package/registry/components/FileUpload/FileUpload.types.ts +89 -0
- package/registry/components/FileUpload/FileUploadIcon.module.css +61 -0
- package/registry/components/FileUpload/FileUploadIcon.tsx +84 -0
- package/registry/components/FileUpload/FileUploadInput.module.css +140 -0
- package/registry/components/FileUpload/FileUploadInput.tsx +113 -0
- package/registry/components/FileUpload/FileUploadItem.module.css +41 -0
- package/registry/components/FileUpload/FileUploadItem.tsx +39 -0
- package/registry/components/FileUpload/index.ts +12 -0
- package/registry/components/InputCounter/InputCounter.module.css +146 -0
- package/registry/components/InputCounter/InputCounter.tsx +232 -0
- package/registry/components/InputCounter/InputCounter.types.ts +37 -0
- package/registry/components/InputCounter/index.ts +7 -0
- package/registry/components/InputMessage/InputMessage.module.css +148 -0
- package/registry/components/InputMessage/InputMessage.tsx +294 -0
- package/registry/components/InputMessage/InputMessage.types.ts +30 -0
- package/registry/components/InputMessage/index.ts +2 -0
- package/registry/components/InputSearch/InputSearch.module.css +168 -0
- package/registry/components/InputSearch/InputSearch.tsx +251 -0
- package/registry/components/InputSearch/InputSearch.types.ts +35 -0
- package/registry/components/InputSearch/index.ts +6 -0
- package/registry/components/InputText/InputText.module.css +183 -0
- package/registry/components/InputText/InputText.tsx +244 -0
- package/registry/components/InputText/InputText.types.ts +32 -0
- package/registry/components/InputText/index.ts +7 -0
- package/registry/components/InputTextArea/InputTextArea.module.css +141 -0
- package/registry/components/InputTextArea/InputTextArea.tsx +170 -0
- package/registry/components/InputTextArea/InputTextArea.types.ts +18 -0
- package/registry/components/InputTextArea/index.ts +6 -0
- package/registry/components/NavbarUser/NavbarUser.module.css +265 -0
- package/registry/components/NavbarUser/NavbarUser.tsx +202 -0
- package/registry/components/NavbarUser/NavbarUser.types.ts +31 -0
- package/registry/components/NavbarUser/index.ts +2 -0
- package/registry/components/Notification/Notification.types.ts +65 -0
- package/registry/components/Notification/NotificationItem.module.css +143 -0
- package/registry/components/Notification/NotificationItem.tsx +157 -0
- package/registry/components/Notification/NotificationPanel.module.css +75 -0
- package/registry/components/Notification/NotificationPanel.tsx +68 -0
- package/registry/components/Notification/NotificationReply.module.css +56 -0
- package/registry/components/Notification/NotificationReply.tsx +52 -0
- package/registry/components/Notification/index.ts +9 -0
- package/registry/components/Pagination/Pagination.module.css +123 -0
- package/registry/components/Pagination/Pagination.tsx +212 -0
- package/registry/components/Pagination/Pagination.types.ts +24 -0
- package/registry/components/Pagination/PaginationDots.module.css +60 -0
- package/registry/components/Pagination/PaginationDots.tsx +48 -0
- package/registry/components/Pagination/PaginationDots.types.ts +17 -0
- package/registry/components/Pagination/index.ts +12 -0
- package/registry/components/Persona/MessageDropdown.module.css +76 -0
- package/registry/components/Persona/MessageDropdown.tsx +68 -0
- package/registry/components/Persona/Persona.module.css +92 -0
- package/registry/components/Persona/Persona.tsx +90 -0
- package/registry/components/Persona/Persona.types.ts +71 -0
- package/registry/components/Persona/PersonaAction.module.css +80 -0
- package/registry/components/Persona/PersonaAction.tsx +49 -0
- package/registry/components/Persona/PersonaMessage.module.css +156 -0
- package/registry/components/Persona/PersonaMessage.tsx +70 -0
- package/registry/components/Persona/index.ts +11 -0
- package/registry/components/Progress/Progress.module.css +41 -0
- package/registry/components/Progress/Progress.tsx +43 -0
- package/registry/components/Progress/Progress.types.ts +10 -0
- package/registry/components/Progress/index.ts +2 -0
- package/registry/components/RadioButton/RadioButton.module.css +103 -0
- package/registry/components/RadioButton/RadioButton.tsx +59 -0
- package/registry/components/RadioButton/RadioButton.types.ts +19 -0
- package/registry/components/RadioButton/RadioField.module.css +68 -0
- package/registry/components/RadioButton/RadioField.tsx +68 -0
- package/registry/components/RadioButton/RadioGroup.module.css +41 -0
- package/registry/components/RadioButton/RadioGroup.tsx +76 -0
- package/registry/components/RadioButton/RadioGroupContext.ts +16 -0
- package/registry/components/RadioButton/index.ts +12 -0
- package/registry/components/RangeSlider/RangeSlider.module.css +133 -0
- package/registry/components/RangeSlider/RangeSlider.tsx +251 -0
- package/registry/components/RangeSlider/RangeSlider.types.ts +25 -0
- package/registry/components/RangeSlider/index.ts +2 -0
- package/registry/components/Rating/Rating.module.css +56 -0
- package/registry/components/Rating/Rating.tsx +142 -0
- package/registry/components/Rating/Rating.types.ts +14 -0
- package/registry/components/Rating/index.ts +7 -0
- package/registry/components/SegmentedControl/SegmentedControl.module.css +56 -0
- package/registry/components/SegmentedControl/SegmentedControl.tsx +46 -0
- package/registry/components/SegmentedControl/SegmentedControl.types.ts +27 -0
- package/registry/components/SegmentedControl/SegmentedControlContext.ts +20 -0
- package/registry/components/SegmentedControl/SegmentedControlItem.module.css +55 -0
- package/registry/components/SegmentedControl/SegmentedControlItem.tsx +32 -0
- package/registry/components/SegmentedControl/index.ts +8 -0
- package/registry/components/SelectDropdown/SelectDropdown.module.css +214 -0
- package/registry/components/SelectDropdown/SelectDropdown.tsx +375 -0
- package/registry/components/SelectDropdown/SelectDropdown.types.ts +50 -0
- package/registry/components/SelectDropdown/SelectDropdownOption.module.css +101 -0
- package/registry/components/SelectDropdown/SelectDropdownOption.tsx +86 -0
- package/registry/components/SelectDropdown/SelectDropdownOverlay.module.css +74 -0
- package/registry/components/SelectDropdown/SelectDropdownOverlay.tsx +202 -0
- package/registry/components/SelectDropdown/index.ts +11 -0
- package/registry/components/Sidebar/Sidebar.module.css +14 -0
- package/registry/components/Sidebar/Sidebar.tsx +41 -0
- package/registry/components/Sidebar/Sidebar.types.ts +41 -0
- package/registry/components/Sidebar/SidebarContent.module.css +5 -0
- package/registry/components/Sidebar/SidebarContent.tsx +14 -0
- package/registry/components/Sidebar/SidebarContext.ts +15 -0
- package/registry/components/Sidebar/SidebarDivider.module.css +5 -0
- package/registry/components/Sidebar/SidebarDivider.tsx +17 -0
- package/registry/components/Sidebar/SidebarFooter.module.css +5 -0
- package/registry/components/Sidebar/SidebarFooter.tsx +14 -0
- package/registry/components/Sidebar/SidebarGroup.module.css +12 -0
- package/registry/components/Sidebar/SidebarGroup.tsx +22 -0
- package/registry/components/Sidebar/SidebarHeader.module.css +5 -0
- package/registry/components/Sidebar/SidebarHeader.tsx +14 -0
- package/registry/components/Sidebar/SidebarNavItem.module.css +176 -0
- package/registry/components/Sidebar/SidebarNavItem.tsx +96 -0
- package/registry/components/Sidebar/index.ts +16 -0
- package/registry/components/Stepper/Stepper.module.css +11 -0
- package/registry/components/Stepper/Stepper.tsx +47 -0
- package/registry/components/Stepper/Stepper.types.ts +26 -0
- package/registry/components/Stepper/StepperContext.ts +17 -0
- package/registry/components/Stepper/StepperStep.module.css +183 -0
- package/registry/components/Stepper/StepperStep.tsx +204 -0
- package/registry/components/Stepper/index.ts +9 -0
- package/registry/components/Switch/Switch.module.css +145 -0
- package/registry/components/Switch/Switch.tsx +96 -0
- package/registry/components/Switch/Switch.types.ts +19 -0
- package/registry/components/Switch/SwitchField.module.css +69 -0
- package/registry/components/Switch/SwitchField.tsx +49 -0
- package/registry/components/Switch/index.ts +8 -0
- package/registry/components/Tab/Tab.module.css +20 -0
- package/registry/components/Tab/Tab.tsx +35 -0
- package/registry/components/Tab/Tab.types.ts +21 -0
- package/registry/components/Tab/TabAdd.module.css +36 -0
- package/registry/components/Tab/TabAdd.tsx +41 -0
- package/registry/components/Tab/TabContext.ts +19 -0
- package/registry/components/Tab/TabItem.module.css +145 -0
- package/registry/components/Tab/TabItem.tsx +87 -0
- package/registry/components/Tab/index.ts +9 -0
- package/registry/components/Table/Table.module.css +33 -0
- package/registry/components/Table/Table.tsx +74 -0
- package/registry/components/Table/Table.types.ts +64 -0
- package/registry/components/Table/TableBody.tsx +23 -0
- package/registry/components/Table/TableCell.module.css +21 -0
- package/registry/components/Table/TableCell.tsx +20 -0
- package/registry/components/Table/TableContext.ts +22 -0
- package/registry/components/Table/TableFooter.module.css +27 -0
- package/registry/components/Table/TableFooter.tsx +20 -0
- package/registry/components/Table/TableHeader.module.css +3 -0
- package/registry/components/Table/TableHeader.tsx +17 -0
- package/registry/components/Table/TableHeaderCell.module.css +55 -0
- package/registry/components/Table/TableHeaderCell.tsx +98 -0
- package/registry/components/Table/TableRow.module.css +53 -0
- package/registry/components/Table/TableRow.tsx +31 -0
- package/registry/components/Table/TableToolbar.module.css +7 -0
- package/registry/components/Table/TableToolbar.tsx +16 -0
- package/registry/components/Table/index.ts +22 -0
- package/registry/components/Tag/Tag.module.css +46 -0
- package/registry/components/Tag/Tag.tsx +38 -0
- package/registry/components/Tag/Tag.types.ts +37 -0
- package/registry/components/Tag/TagBrand.module.css +42 -0
- package/registry/components/Tag/TagBrand.tsx +38 -0
- package/registry/components/Tag/TagStatus.module.css +43 -0
- package/registry/components/Tag/TagStatus.tsx +119 -0
- package/registry/components/Tag/index.ts +15 -0
- package/registry/components/Tooltip/Tooltip.module.css +208 -0
- package/registry/components/Tooltip/Tooltip.tsx +81 -0
- package/registry/components/Tooltip/Tooltip.types.ts +27 -0
- package/registry/components/Tooltip/index.ts +7 -0
- package/registry/components/TreeviewList/TreeviewItem.module.css +89 -0
- package/registry/components/TreeviewList/TreeviewItem.tsx +142 -0
- package/registry/components/TreeviewList/TreeviewList.module.css +3 -0
- package/registry/components/TreeviewList/TreeviewList.tsx +19 -0
- package/registry/components/TreeviewList/TreeviewList.types.ts +18 -0
- package/registry/components/TreeviewList/TreeviewListContext.ts +13 -0
- package/registry/components/TreeviewList/index.ts +6 -0
- package/registry/components/VerificationCode/VerificationCode.module.css +49 -0
- package/registry/components/VerificationCode/VerificationCode.tsx +147 -0
- package/registry/components/VerificationCode/VerificationCode.types.ts +21 -0
- package/registry/components/VerificationCode/index.ts +2 -0
- package/registry/registry.json +746 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { forwardRef, useState, useRef, useCallback } from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
import type { TooltipProps } from './Tooltip.types';
|
|
4
|
+
import styles from './Tooltip.module.css';
|
|
5
|
+
|
|
6
|
+
export const Tooltip = forwardRef<HTMLSpanElement, TooltipProps>(
|
|
7
|
+
(
|
|
8
|
+
{
|
|
9
|
+
content,
|
|
10
|
+
title,
|
|
11
|
+
body,
|
|
12
|
+
action,
|
|
13
|
+
placement = 'top',
|
|
14
|
+
align = 'center',
|
|
15
|
+
variant = 'default',
|
|
16
|
+
open,
|
|
17
|
+
children,
|
|
18
|
+
className,
|
|
19
|
+
...rest
|
|
20
|
+
},
|
|
21
|
+
ref
|
|
22
|
+
) => {
|
|
23
|
+
const [hovered, setHovered] = useState(false);
|
|
24
|
+
const showTimerRef = useRef<ReturnType<typeof setTimeout>>();
|
|
25
|
+
const hideTimerRef = useRef<ReturnType<typeof setTimeout>>();
|
|
26
|
+
|
|
27
|
+
const isRich = !!(title || body || action);
|
|
28
|
+
const hasContent = isRich || !!content;
|
|
29
|
+
const visible = open !== undefined ? open : hovered;
|
|
30
|
+
|
|
31
|
+
const show = useCallback(() => {
|
|
32
|
+
clearTimeout(hideTimerRef.current);
|
|
33
|
+
showTimerRef.current = setTimeout(() => setHovered(true), 200);
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
const hide = useCallback(() => {
|
|
37
|
+
clearTimeout(showTimerRef.current);
|
|
38
|
+
hideTimerRef.current = setTimeout(() => setHovered(false), 100);
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
41
|
+
const posClass = styles[`${placement}_${align}`];
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<span
|
|
45
|
+
ref={ref}
|
|
46
|
+
className={cn(styles.root, className)}
|
|
47
|
+
onMouseEnter={open === undefined ? show : undefined}
|
|
48
|
+
onMouseLeave={open === undefined ? hide : undefined}
|
|
49
|
+
onFocus={open === undefined ? show : undefined}
|
|
50
|
+
onBlur={open === undefined ? hide : undefined}
|
|
51
|
+
{...rest}
|
|
52
|
+
>
|
|
53
|
+
{children}
|
|
54
|
+
{hasContent && visible && (
|
|
55
|
+
<span
|
|
56
|
+
role="tooltip"
|
|
57
|
+
className={cn(
|
|
58
|
+
styles.tooltip,
|
|
59
|
+
styles[variant],
|
|
60
|
+
isRich ? styles.rich : styles.inline,
|
|
61
|
+
posClass
|
|
62
|
+
)}
|
|
63
|
+
>
|
|
64
|
+
<span className={styles.beak} />
|
|
65
|
+
{isRich ? (
|
|
66
|
+
<>
|
|
67
|
+
{title && <span className={styles.title}>{title}</span>}
|
|
68
|
+
{body && <span className={styles.body}>{body}</span>}
|
|
69
|
+
{action && <span className={styles.action}>{action}</span>}
|
|
70
|
+
</>
|
|
71
|
+
) : (
|
|
72
|
+
<span className={styles.content}>{content}</span>
|
|
73
|
+
)}
|
|
74
|
+
</span>
|
|
75
|
+
)}
|
|
76
|
+
</span>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
Tooltip.displayName = 'Tooltip';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export type TooltipPlacement = 'top' | 'bottom' | 'start' | 'end';
|
|
4
|
+
export type TooltipAlign = 'start' | 'center' | 'end';
|
|
5
|
+
export type TooltipVariant = 'default' | 'inverted';
|
|
6
|
+
|
|
7
|
+
export interface TooltipProps
|
|
8
|
+
extends Omit<HTMLAttributes<HTMLSpanElement>, 'content'> {
|
|
9
|
+
/** Inline mode text */
|
|
10
|
+
content?: string;
|
|
11
|
+
/** Rich mode title */
|
|
12
|
+
title?: string;
|
|
13
|
+
/** Rich mode body */
|
|
14
|
+
body?: string;
|
|
15
|
+
/** Rich mode action slot (e.g. Button) */
|
|
16
|
+
action?: ReactNode;
|
|
17
|
+
/** Tooltip placement relative to the trigger */
|
|
18
|
+
placement?: TooltipPlacement;
|
|
19
|
+
/** Tooltip alignment along the placement axis */
|
|
20
|
+
align?: TooltipAlign;
|
|
21
|
+
/** Visual variant */
|
|
22
|
+
variant?: TooltipVariant;
|
|
23
|
+
/** Controlled visibility — overrides hover/focus behavior */
|
|
24
|
+
open?: boolean;
|
|
25
|
+
/** Trigger element */
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/* ─── Trigger row ─── */
|
|
2
|
+
|
|
3
|
+
.trigger {
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
width: 100%;
|
|
7
|
+
gap: var(--st-space-2);
|
|
8
|
+
padding: var(--st-space-2) var(--st-space-3);
|
|
9
|
+
background: transparent;
|
|
10
|
+
border: none;
|
|
11
|
+
border-radius: var(--st-radius-md);
|
|
12
|
+
font-family: var(--st-font-family);
|
|
13
|
+
font-size: var(--st-font-size-sm);
|
|
14
|
+
color: var(--st-color-foreground);
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
text-align: left;
|
|
17
|
+
transition: background-color var(--st-transition-fast);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.trigger:hover:not(:disabled) {
|
|
21
|
+
background-color: var(--st-color-neutral-100);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.trigger:focus-visible {
|
|
25
|
+
outline: 2px solid var(--st-color-primary);
|
|
26
|
+
outline-offset: -2px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.trigger:disabled {
|
|
30
|
+
opacity: 0.5;
|
|
31
|
+
cursor: not-allowed;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.selected {
|
|
35
|
+
background-color: var(--st-color-neutral-100);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.selected:hover:not(:disabled) {
|
|
39
|
+
background-color: var(--st-color-neutral-100);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* ─── Chevron ─── */
|
|
43
|
+
|
|
44
|
+
.chevron {
|
|
45
|
+
flex-shrink: 0;
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
justify-content: center;
|
|
49
|
+
transition: transform 0.15s ease;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.chevronOpen {
|
|
53
|
+
transform: rotate(90deg);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* ─── Icon ─── */
|
|
57
|
+
|
|
58
|
+
.icon {
|
|
59
|
+
flex-shrink: 0;
|
|
60
|
+
display: flex;
|
|
61
|
+
align-items: center;
|
|
62
|
+
justify-content: center;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* ─── Label ─── */
|
|
66
|
+
|
|
67
|
+
.label {
|
|
68
|
+
flex: 1;
|
|
69
|
+
min-width: 0;
|
|
70
|
+
overflow: hidden;
|
|
71
|
+
text-overflow: ellipsis;
|
|
72
|
+
white-space: nowrap;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* ─── Animated panel ─── */
|
|
76
|
+
|
|
77
|
+
.panel {
|
|
78
|
+
display: grid;
|
|
79
|
+
grid-template-rows: 0fr;
|
|
80
|
+
transition: grid-template-rows 0.2s ease;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.panelOpen {
|
|
84
|
+
grid-template-rows: 1fr;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.panelContent {
|
|
88
|
+
overflow: hidden;
|
|
89
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { forwardRef, useState, Children } from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
import { TreeviewListContext, useTreeviewDepth } from './TreeviewListContext';
|
|
4
|
+
import type { TreeviewItemProps } from './TreeviewList.types';
|
|
5
|
+
import styles from './TreeviewItem.module.css';
|
|
6
|
+
|
|
7
|
+
/* ─── Inline SVG Icons ─── */
|
|
8
|
+
|
|
9
|
+
function ChevronIcon() {
|
|
10
|
+
return (
|
|
11
|
+
<svg width="12" height="12" viewBox="0 0 12 12" fill="none">
|
|
12
|
+
<path
|
|
13
|
+
d="M4.5 2.5L8 6L4.5 9.5"
|
|
14
|
+
stroke="currentColor"
|
|
15
|
+
strokeWidth="1.5"
|
|
16
|
+
strokeLinecap="round"
|
|
17
|
+
strokeLinejoin="round"
|
|
18
|
+
/>
|
|
19
|
+
</svg>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function FolderIcon() {
|
|
24
|
+
return (
|
|
25
|
+
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
|
|
26
|
+
<path
|
|
27
|
+
d="M1.5 3.5C1.5 2.94772 1.94772 2.5 2.5 2.5H5.79289C6.05811 2.5 6.31246 2.60536 6.5 2.79289L7.70711 4H13.5C14.0523 4 14.5 4.44772 14.5 5V12.5C14.5 13.0523 14.0523 13.5 13.5 13.5H2.5C1.94772 13.5 1.5 13.0523 1.5 12.5V3.5Z"
|
|
28
|
+
fill="var(--st-color-primary)"
|
|
29
|
+
/>
|
|
30
|
+
</svg>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function FolderOpenIcon() {
|
|
35
|
+
return (
|
|
36
|
+
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
|
|
37
|
+
<path
|
|
38
|
+
d="M1.5 3.5C1.5 2.94772 1.94772 2.5 2.5 2.5H5.79289C6.05811 2.5 6.31246 2.60536 6.5 2.79289L7.70711 4H13.5C14.0523 4 14.5 4.44772 14.5 5V6H3.5L1.5 12.5V3.5Z"
|
|
39
|
+
fill="var(--st-color-primary)"
|
|
40
|
+
/>
|
|
41
|
+
<path
|
|
42
|
+
d="M3.5 6H14.5L12.8333 13.5H2.5C1.94772 13.5 1.5 13.0523 1.5 12.5L3.5 6Z"
|
|
43
|
+
fill="var(--st-color-primary)"
|
|
44
|
+
/>
|
|
45
|
+
</svg>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function FileIcon() {
|
|
50
|
+
return (
|
|
51
|
+
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
|
|
52
|
+
<path
|
|
53
|
+
d="M3.5 1.5C2.94772 1.5 2.5 1.94772 2.5 2.5V13.5C2.5 14.0523 2.94772 14.5 3.5 14.5H12.5C13.0523 14.5 13.5 14.0523 13.5 13.5V5.5L9.5 1.5H3.5Z"
|
|
54
|
+
fill="var(--st-color-neutral-400)"
|
|
55
|
+
/>
|
|
56
|
+
<path
|
|
57
|
+
d="M9.5 1.5V4.5C9.5 5.05228 9.94772 5.5 10.5 5.5H13.5"
|
|
58
|
+
fill="var(--st-color-neutral-300)"
|
|
59
|
+
/>
|
|
60
|
+
</svg>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* ─── Constants ─── */
|
|
65
|
+
|
|
66
|
+
const INDENT_PX = 24;
|
|
67
|
+
const CHEVRON_PLACEHOLDER_WIDTH = 12;
|
|
68
|
+
|
|
69
|
+
export const TreeviewItem = forwardRef<HTMLDivElement, TreeviewItemProps>(
|
|
70
|
+
(
|
|
71
|
+
{
|
|
72
|
+
label,
|
|
73
|
+
icon,
|
|
74
|
+
disabled = false,
|
|
75
|
+
selected = false,
|
|
76
|
+
defaultExpanded = false,
|
|
77
|
+
expanded,
|
|
78
|
+
onExpandedChange,
|
|
79
|
+
onSelect,
|
|
80
|
+
className,
|
|
81
|
+
children,
|
|
82
|
+
...rest
|
|
83
|
+
},
|
|
84
|
+
ref
|
|
85
|
+
) => {
|
|
86
|
+
const depth = useTreeviewDepth();
|
|
87
|
+
const isFolder = Children.count(children) > 0;
|
|
88
|
+
|
|
89
|
+
const [internalOpen, setInternalOpen] = useState(defaultExpanded);
|
|
90
|
+
const isOpen = expanded !== undefined ? expanded : internalOpen;
|
|
91
|
+
|
|
92
|
+
const toggle = () => {
|
|
93
|
+
if (disabled) return;
|
|
94
|
+
|
|
95
|
+
if (isFolder) {
|
|
96
|
+
const next = !isOpen;
|
|
97
|
+
if (expanded === undefined) setInternalOpen(next);
|
|
98
|
+
onExpandedChange?.(next);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
onSelect?.();
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const paddingLeft = depth * INDENT_PX;
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<div ref={ref} className={className} role="treeitem" aria-expanded={isFolder ? isOpen : undefined} {...rest}>
|
|
108
|
+
<button
|
|
109
|
+
type="button"
|
|
110
|
+
disabled={disabled}
|
|
111
|
+
className={cn(styles.trigger, selected && styles.selected)}
|
|
112
|
+
style={{ paddingLeft: paddingLeft + 'px' }}
|
|
113
|
+
onClick={toggle}
|
|
114
|
+
>
|
|
115
|
+
{isFolder ? (
|
|
116
|
+
<span className={cn(styles.chevron, isOpen && styles.chevronOpen)}>
|
|
117
|
+
<ChevronIcon />
|
|
118
|
+
</span>
|
|
119
|
+
) : (
|
|
120
|
+
<span style={{ width: CHEVRON_PLACEHOLDER_WIDTH }} />
|
|
121
|
+
)}
|
|
122
|
+
<span className={styles.icon}>
|
|
123
|
+
{icon ?? (isFolder ? (isOpen ? <FolderOpenIcon /> : <FolderIcon />) : <FileIcon />)}
|
|
124
|
+
</span>
|
|
125
|
+
<span className={styles.label}>{label}</span>
|
|
126
|
+
</button>
|
|
127
|
+
|
|
128
|
+
{isFolder && (
|
|
129
|
+
<div className={cn(styles.panel, isOpen && styles.panelOpen)}>
|
|
130
|
+
<div className={styles.panelContent}>
|
|
131
|
+
<TreeviewListContext.Provider value={{ depth: depth + 1 }}>
|
|
132
|
+
{children}
|
|
133
|
+
</TreeviewListContext.Provider>
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
)}
|
|
137
|
+
</div>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
TreeviewItem.displayName = 'TreeviewItem';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { forwardRef } from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
import { TreeviewListContext } from './TreeviewListContext';
|
|
4
|
+
import type { TreeviewListProps } from './TreeviewList.types';
|
|
5
|
+
import styles from './TreeviewList.module.css';
|
|
6
|
+
|
|
7
|
+
export const TreeviewList = forwardRef<HTMLDivElement, TreeviewListProps>(
|
|
8
|
+
({ className, children, ...rest }, ref) => {
|
|
9
|
+
return (
|
|
10
|
+
<TreeviewListContext.Provider value={{ depth: 0 }}>
|
|
11
|
+
<div ref={ref} role="tree" className={cn(styles.root, className)} {...rest}>
|
|
12
|
+
{children}
|
|
13
|
+
</div>
|
|
14
|
+
</TreeviewListContext.Provider>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
TreeviewList.displayName = 'TreeviewList';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface TreeviewListProps extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface TreeviewItemProps
|
|
8
|
+
extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
9
|
+
label: string;
|
|
10
|
+
icon?: ReactNode;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
selected?: boolean;
|
|
13
|
+
defaultExpanded?: boolean;
|
|
14
|
+
expanded?: boolean;
|
|
15
|
+
onExpandedChange?: (expanded: boolean) => void;
|
|
16
|
+
onSelect?: () => void;
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface TreeviewListContextValue {
|
|
4
|
+
depth: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const TreeviewListContext =
|
|
8
|
+
createContext<TreeviewListContextValue | null>(null);
|
|
9
|
+
|
|
10
|
+
export function useTreeviewDepth(): number {
|
|
11
|
+
const ctx = useContext(TreeviewListContext);
|
|
12
|
+
return ctx?.depth ?? 0;
|
|
13
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/* ─── Root ─── */
|
|
2
|
+
.root {
|
|
3
|
+
display: inline-flex;
|
|
4
|
+
gap: var(--st-space-3);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/* ─── Digit box ─── */
|
|
8
|
+
.digit {
|
|
9
|
+
width: 48px;
|
|
10
|
+
height: 48px;
|
|
11
|
+
border: 1.5px solid var(--st-color-border);
|
|
12
|
+
border-radius: var(--st-radius-full);
|
|
13
|
+
background: var(--st-color-neutral-50);
|
|
14
|
+
text-align: center;
|
|
15
|
+
font-size: var(--st-font-size-2xl);
|
|
16
|
+
font-weight: var(--st-font-weight-bold);
|
|
17
|
+
font-family: var(--st-font-family);
|
|
18
|
+
color: var(--st-color-foreground);
|
|
19
|
+
outline: none;
|
|
20
|
+
caret-color: var(--st-color-primary);
|
|
21
|
+
transition: border-color var(--st-transition-fast),
|
|
22
|
+
box-shadow var(--st-transition-fast);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.digit:focus {
|
|
26
|
+
border-color: var(--st-color-success);
|
|
27
|
+
box-shadow: 0 0 0 2px var(--st-color-success);
|
|
28
|
+
background: var(--st-color-background);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.filled {
|
|
32
|
+
border-color: var(--st-color-border);
|
|
33
|
+
background: var(--st-color-background);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.digitError {
|
|
37
|
+
border-color: var(--st-color-error);
|
|
38
|
+
color: var(--st-color-error);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.digitError:focus {
|
|
42
|
+
border-color: var(--st-color-error);
|
|
43
|
+
box-shadow: 0 0 0 2px var(--st-color-error);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.digit:disabled {
|
|
47
|
+
opacity: 0.5;
|
|
48
|
+
cursor: not-allowed;
|
|
49
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { forwardRef, useState, useRef, useCallback, useEffect } from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
import type { VerificationCodeProps } from './VerificationCode.types';
|
|
4
|
+
import styles from './VerificationCode.module.css';
|
|
5
|
+
|
|
6
|
+
function toDigits(value: string, length: number): string[] {
|
|
7
|
+
const chars = value.replace(/[^0-9]/g, '').split('');
|
|
8
|
+
return Array.from({ length }, (_, i) => chars[i] ?? '');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const VerificationCode = forwardRef<HTMLDivElement, VerificationCodeProps>(
|
|
12
|
+
(
|
|
13
|
+
{
|
|
14
|
+
length = 4,
|
|
15
|
+
value,
|
|
16
|
+
defaultValue,
|
|
17
|
+
onChange,
|
|
18
|
+
onComplete,
|
|
19
|
+
error,
|
|
20
|
+
disabled,
|
|
21
|
+
autoFocus,
|
|
22
|
+
className,
|
|
23
|
+
...rest
|
|
24
|
+
},
|
|
25
|
+
ref,
|
|
26
|
+
) => {
|
|
27
|
+
const inputRefs = useRef<(HTMLInputElement | null)[]>([]);
|
|
28
|
+
const [internalDigits, setInternalDigits] = useState<string[]>(() =>
|
|
29
|
+
toDigits(defaultValue ?? '', length),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const isControlled = value !== undefined;
|
|
33
|
+
const digits = isControlled ? toDigits(value, length) : internalDigits;
|
|
34
|
+
|
|
35
|
+
// Ensure internal array stays in sync with length changes
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (!isControlled && internalDigits.length !== length) {
|
|
38
|
+
setInternalDigits(toDigits(internalDigits.join(''), length));
|
|
39
|
+
}
|
|
40
|
+
}, [length, isControlled, internalDigits]);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (autoFocus) {
|
|
44
|
+
inputRefs.current[0]?.focus();
|
|
45
|
+
}
|
|
46
|
+
}, [autoFocus]);
|
|
47
|
+
|
|
48
|
+
const updateDigits = useCallback(
|
|
49
|
+
(next: string[]) => {
|
|
50
|
+
if (!isControlled) setInternalDigits(next);
|
|
51
|
+
const joined = next.join('');
|
|
52
|
+
onChange?.(joined);
|
|
53
|
+
if (next.every((d) => d !== '')) {
|
|
54
|
+
onComplete?.(joined);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
[isControlled, onChange, onComplete],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const handleChange = (index: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
61
|
+
const char = e.target.value.replace(/[^0-9]/g, '').slice(-1);
|
|
62
|
+
if (!char) return;
|
|
63
|
+
|
|
64
|
+
const next = [...digits];
|
|
65
|
+
next[index] = char;
|
|
66
|
+
updateDigits(next);
|
|
67
|
+
|
|
68
|
+
// Auto-advance
|
|
69
|
+
if (index < length - 1) {
|
|
70
|
+
inputRefs.current[index + 1]?.focus();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const handleKeyDown = (index: number) => (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
75
|
+
if (e.key === 'Backspace') {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
const next = [...digits];
|
|
78
|
+
if (digits[index]) {
|
|
79
|
+
next[index] = '';
|
|
80
|
+
updateDigits(next);
|
|
81
|
+
} else if (index > 0) {
|
|
82
|
+
next[index - 1] = '';
|
|
83
|
+
updateDigits(next);
|
|
84
|
+
inputRefs.current[index - 1]?.focus();
|
|
85
|
+
}
|
|
86
|
+
} else if (e.key === 'ArrowLeft' && index > 0) {
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
inputRefs.current[index - 1]?.focus();
|
|
89
|
+
} else if (e.key === 'ArrowRight' && index < length - 1) {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
inputRefs.current[index + 1]?.focus();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const handlePaste = (e: React.ClipboardEvent<HTMLInputElement>) => {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
const pasted = e.clipboardData.getData('text').replace(/[^0-9]/g, '');
|
|
98
|
+
if (!pasted) return;
|
|
99
|
+
|
|
100
|
+
const target = inputRefs.current.indexOf(e.currentTarget as HTMLInputElement);
|
|
101
|
+
const start = target >= 0 ? target : 0;
|
|
102
|
+
const next = [...digits];
|
|
103
|
+
|
|
104
|
+
for (let i = 0; i < pasted.length && start + i < length; i++) {
|
|
105
|
+
next[start + i] = pasted[i];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
updateDigits(next);
|
|
109
|
+
|
|
110
|
+
// Focus last filled or next empty
|
|
111
|
+
const focusIndex = Math.min(start + pasted.length, length) - 1;
|
|
112
|
+
inputRefs.current[focusIndex]?.focus();
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const handleFocus = () => (e: React.FocusEvent<HTMLInputElement>) => {
|
|
116
|
+
e.target.select();
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<div ref={ref} className={cn(styles.root, className)} {...rest}>
|
|
121
|
+
{digits.map((digit, i) => (
|
|
122
|
+
<input
|
|
123
|
+
key={i}
|
|
124
|
+
ref={(el) => { inputRefs.current[i] = el; }}
|
|
125
|
+
type="text"
|
|
126
|
+
inputMode="numeric"
|
|
127
|
+
maxLength={1}
|
|
128
|
+
value={digit}
|
|
129
|
+
disabled={disabled}
|
|
130
|
+
className={cn(
|
|
131
|
+
styles.digit,
|
|
132
|
+
digit && styles.filled,
|
|
133
|
+
error && styles.digitError,
|
|
134
|
+
)}
|
|
135
|
+
onChange={handleChange(i)}
|
|
136
|
+
onKeyDown={handleKeyDown(i)}
|
|
137
|
+
onPaste={handlePaste}
|
|
138
|
+
onFocus={handleFocus()}
|
|
139
|
+
aria-label={`Digit ${i + 1}`}
|
|
140
|
+
/>
|
|
141
|
+
))}
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
},
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
VerificationCode.displayName = 'VerificationCode';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface VerificationCodeProps
|
|
4
|
+
extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {
|
|
5
|
+
/** Number of digit inputs. */
|
|
6
|
+
length?: number;
|
|
7
|
+
/** Controlled value string. */
|
|
8
|
+
value?: string;
|
|
9
|
+
/** Initial value for uncontrolled usage. */
|
|
10
|
+
defaultValue?: string;
|
|
11
|
+
/** Called on every digit change with the full value string. */
|
|
12
|
+
onChange?: (value: string) => void;
|
|
13
|
+
/** Called when all digits are filled. */
|
|
14
|
+
onComplete?: (value: string) => void;
|
|
15
|
+
/** Shows error ring + red text on all digits. */
|
|
16
|
+
error?: boolean;
|
|
17
|
+
/** Disables all digit inputs. */
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/** Auto-focuses the first input on mount. */
|
|
20
|
+
autoFocus?: boolean;
|
|
21
|
+
}
|