@wakastellar/ui 2.0.0 → 2.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/cli/commands/add.d.ts +7 -0
- package/dist/cli/commands/init.d.ts +6 -0
- package/dist/cli/commands/list.d.ts +5 -0
- package/dist/cli/commands/search.d.ts +1 -0
- package/dist/cli/index.cjs +4844 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/utils/config.d.ts +29 -0
- package/dist/cli/utils/logger.d.ts +20 -0
- package/dist/cli/utils/registry.d.ts +23 -0
- package/package.json +14 -3
- package/src/blocks/activity-timeline/index.tsx +586 -0
- package/src/blocks/calendar-view/index.tsx +756 -0
- package/src/blocks/chat/index.tsx +1018 -0
- package/src/blocks/chat/widget.tsx +504 -0
- package/src/blocks/dashboard/index.tsx +522 -0
- package/src/blocks/empty-states/index.tsx +452 -0
- package/src/blocks/error-pages/index.tsx +426 -0
- package/src/blocks/faq/index.tsx +479 -0
- package/src/blocks/file-manager/index.tsx +890 -0
- package/src/blocks/footer/index.tsx +133 -0
- package/src/blocks/header/index.tsx +357 -0
- package/src/blocks/headtab/index.tsx +139 -0
- package/src/blocks/i18n-editor/index.tsx +1016 -0
- package/src/blocks/index.ts +80 -0
- package/src/blocks/kanban-board/index.tsx +779 -0
- package/src/blocks/landing/index.tsx +677 -0
- package/src/blocks/language-selector/index.tsx +88 -0
- package/src/blocks/layout/index.tsx +159 -0
- package/src/blocks/login/index.tsx +339 -0
- package/src/blocks/login/types.ts +131 -0
- package/src/blocks/pricing/index.tsx +564 -0
- package/src/blocks/profile/index.tsx +746 -0
- package/src/blocks/settings/index.tsx +558 -0
- package/src/blocks/sidebar/index.tsx +713 -0
- package/src/blocks/theme-creator-block/index.tsx +835 -0
- package/src/blocks/user-management/index.tsx +1037 -0
- package/src/blocks/wizard/index.tsx +719 -0
- package/src/components/DataTable/DataTable.tsx +406 -0
- package/src/components/DataTable/DataTableAdvanced.tsx +720 -0
- package/src/components/DataTable/DataTableBody.tsx +216 -0
- package/src/components/DataTable/DataTableCell.tsx +172 -0
- package/src/components/DataTable/DataTableColumnResizer.tsx +62 -0
- package/src/components/DataTable/DataTableConflictResolver.tsx +478 -0
- package/src/components/DataTable/DataTableContextMenu.tsx +219 -0
- package/src/components/DataTable/DataTableEditCell.tsx +279 -0
- package/src/components/DataTable/DataTableFilterBuilder.tsx +519 -0
- package/src/components/DataTable/DataTableFilters.tsx +535 -0
- package/src/components/DataTable/DataTableGrouping.tsx +147 -0
- package/src/components/DataTable/DataTableHeader.tsx +172 -0
- package/src/components/DataTable/DataTablePagination.tsx +125 -0
- package/src/components/DataTable/DataTableSelection.tsx +269 -0
- package/src/components/DataTable/DataTableSyncStatus.tsx +281 -0
- package/src/components/DataTable/DataTableToolbar.tsx +262 -0
- package/src/components/DataTable/README.md +446 -0
- package/src/components/DataTable/__tests__/DataTableAdvanced.test.tsx +426 -0
- package/src/components/DataTable/__tests__/DataTableEdit.test.tsx +329 -0
- package/src/components/DataTable/__tests__/useDataTableAdvanced.test.ts +455 -0
- package/src/components/DataTable/examples/EditExample.tsx +166 -0
- package/src/components/DataTable/formatters/index.ts +335 -0
- package/src/components/DataTable/hooks/__tests__/useDataTableEdit.test.ts +239 -0
- package/src/components/DataTable/hooks/useDataTable.ts +145 -0
- package/src/components/DataTable/hooks/useDataTableAdvanced.ts +342 -0
- package/src/components/DataTable/hooks/useDataTableAdvancedFilters.ts +637 -0
- package/src/components/DataTable/hooks/useDataTableColumnTemplates.ts +186 -0
- package/src/components/DataTable/hooks/useDataTableEdit.ts +167 -0
- package/src/components/DataTable/hooks/useDataTableExport.ts +227 -0
- package/src/components/DataTable/hooks/useDataTableImport.ts +216 -0
- package/src/components/DataTable/hooks/useDataTableOffline.ts +481 -0
- package/src/components/DataTable/hooks/useDataTableTheme.ts +213 -0
- package/src/components/DataTable/hooks/useDataTableVirtualization.ts +99 -0
- package/src/components/DataTable/hooks/useTableLayout.ts +85 -0
- package/src/components/DataTable/index.ts +81 -0
- package/src/components/DataTable/services/IndexedDBService.ts +504 -0
- package/src/components/DataTable/templates/index.tsx +803 -0
- package/src/components/DataTable/types.ts +504 -0
- package/src/components/DataTable/utils.ts +164 -0
- package/src/components/DataTable/workers/exportWorker.ts +213 -0
- package/src/components/accordion/index.tsx +61 -0
- package/src/components/alert/index.tsx +61 -0
- package/src/components/alert-dialog/index.tsx +146 -0
- package/src/components/aspect-ratio/index.tsx +12 -0
- package/src/components/avatar/index.tsx +54 -0
- package/src/components/badge/Badge.stories.tsx +64 -0
- package/src/components/badge/index.tsx +38 -0
- package/src/components/button/Button.stories.tsx +173 -0
- package/src/components/button/index.tsx +56 -0
- package/src/components/calendar/index.tsx +73 -0
- package/src/components/card/index.tsx +78 -0
- package/src/components/checkbox/index.tsx +34 -0
- package/src/components/code/index.tsx +229 -0
- package/src/components/collapsible/index.tsx +16 -0
- package/src/components/command/index.tsx +162 -0
- package/src/components/context-menu/index.tsx +204 -0
- package/src/components/dialog/index.tsx +126 -0
- package/src/components/dropdown-menu/index.tsx +204 -0
- package/src/components/error-boundary/ErrorBoundary.tsx +281 -0
- package/src/components/error-boundary/index.ts +7 -0
- package/src/components/form/index.tsx +183 -0
- package/src/components/hover-card/index.tsx +33 -0
- package/src/components/index.ts +368 -0
- package/src/components/input/Input.stories.tsx +100 -0
- package/src/components/input/index.tsx +27 -0
- package/src/components/input-otp/index.tsx +277 -0
- package/src/components/label/index.tsx +30 -0
- package/src/components/language-selector/index.tsx +341 -0
- package/src/components/menubar/index.tsx +240 -0
- package/src/components/navigation-menu/index.tsx +134 -0
- package/src/components/popover/index.tsx +35 -0
- package/src/components/progress/index.tsx +32 -0
- package/src/components/radio-group/index.tsx +48 -0
- package/src/components/scroll-area/index.tsx +52 -0
- package/src/components/select/index.tsx +164 -0
- package/src/components/separator/index.tsx +35 -0
- package/src/components/sheet/index.tsx +147 -0
- package/src/components/skeleton/index.tsx +22 -0
- package/src/components/slider/index.tsx +32 -0
- package/src/components/switch/index.tsx +33 -0
- package/src/components/table/index.tsx +117 -0
- package/src/components/tabs/index.tsx +59 -0
- package/src/components/textarea/index.tsx +30 -0
- package/src/components/theme-selector/index.tsx +327 -0
- package/src/components/toast/index.tsx +133 -0
- package/src/components/toaster/index.tsx +34 -0
- package/src/components/toggle/index.tsx +49 -0
- package/src/components/tooltip/index.tsx +34 -0
- package/src/components/typography/index.tsx +276 -0
- package/src/components/waka-3d-pie-chart/index.tsx +486 -0
- package/src/components/waka-achievement-unlock/index.tsx +716 -0
- package/src/components/waka-activity-feed/index.tsx +686 -0
- package/src/components/waka-address-autocomplete/index.tsx +1202 -0
- package/src/components/waka-admincrumb/index.tsx +349 -0
- package/src/components/waka-alert-stack/index.tsx +827 -0
- package/src/components/waka-allocation-matrix/index.tsx +1278 -0
- package/src/components/waka-approval-chain/index.tsx +766 -0
- package/src/components/waka-audit-log/index.tsx +1475 -0
- package/src/components/waka-autocomplete/index.tsx +358 -0
- package/src/components/waka-badge-showcase/index.tsx +704 -0
- package/src/components/waka-barcode/index.tsx +260 -0
- package/src/components/waka-biometric-prompt/index.tsx +765 -0
- package/src/components/waka-bottom-sheet/index.tsx +495 -0
- package/src/components/waka-breadcrumb/index.tsx +376 -0
- package/src/components/waka-breadcrumb-path/index.tsx +513 -0
- package/src/components/waka-budget-burn/index.tsx +1234 -0
- package/src/components/waka-capacity-planner/index.tsx +1107 -0
- package/src/components/waka-carousel/index.tsx +893 -0
- package/src/components/waka-cart-summary/index.tsx +1055 -0
- package/src/components/waka-challenge-timer/index.tsx +1044 -0
- package/src/components/waka-charts/WakaAreaChart.tsx +251 -0
- package/src/components/waka-charts/WakaBarChart.tsx +222 -0
- package/src/components/waka-charts/WakaChart.tsx +124 -0
- package/src/components/waka-charts/WakaLineChart.tsx +219 -0
- package/src/components/waka-charts/WakaMiniChart.tsx +133 -0
- package/src/components/waka-charts/WakaPieChart.tsx +214 -0
- package/src/components/waka-charts/WakaSparkline.tsx +229 -0
- package/src/components/waka-charts/dataTableHelpers.ts +109 -0
- package/src/components/waka-charts/hooks/useChartTheme.ts +123 -0
- package/src/components/waka-charts/hooks/useRechartsLoader.ts +234 -0
- package/src/components/waka-charts/index.ts +90 -0
- package/src/components/waka-charts/types.ts +330 -0
- package/src/components/waka-chat-bubble/index.tsx +1060 -0
- package/src/components/waka-checklist/index.tsx +1067 -0
- package/src/components/waka-checkout-stepper/index.tsx +976 -0
- package/src/components/waka-cohort-table/index.tsx +1011 -0
- package/src/components/waka-color-picker/index.tsx +447 -0
- package/src/components/waka-combo-counter/index.tsx +864 -0
- package/src/components/waka-combobox/index.tsx +497 -0
- package/src/components/waka-command-bar/index.tsx +403 -0
- package/src/components/waka-compare-period/index.tsx +1230 -0
- package/src/components/waka-connection-matrix/index.tsx +1053 -0
- package/src/components/waka-contribution-graph/index.tsx +552 -0
- package/src/components/waka-cost-breakdown/index.tsx +1065 -0
- package/src/components/waka-coupon-input/index.tsx +592 -0
- package/src/components/waka-credit-card-input/index.tsx +982 -0
- package/src/components/waka-daily-reward/index.tsx +762 -0
- package/src/components/waka-date-range-picker/index.tsx +378 -0
- package/src/components/waka-datetime-picker/index.tsx +793 -0
- package/src/components/waka-datetime-picker.form-integration/index.tsx +402 -0
- package/src/components/waka-deployment-lane/index.tsx +673 -0
- package/src/components/waka-device-trust/index.tsx +1259 -0
- package/src/components/waka-dock/index.tsx +285 -0
- package/src/components/waka-drawer/index.tsx +319 -0
- package/src/components/waka-empty-state/index.tsx +545 -0
- package/src/components/waka-error-shake/index.tsx +398 -0
- package/src/components/waka-feature-announcement/index.tsx +991 -0
- package/src/components/waka-file-upload/index.tsx +437 -0
- package/src/components/waka-floating-nav/index.tsx +413 -0
- package/src/components/waka-flow-diagram/index.tsx +508 -0
- package/src/components/waka-funnel-chart/index.tsx +823 -0
- package/src/components/waka-glow-card/index.tsx +246 -0
- package/src/components/waka-goal-progress/index.tsx +1025 -0
- package/src/components/waka-haptic-button/index.tsx +388 -0
- package/src/components/waka-health-pulse/index.tsx +451 -0
- package/src/components/waka-heatmap/index.tsx +1026 -0
- package/src/components/waka-hotspot/index.tsx +682 -0
- package/src/components/waka-image/index.tsx +373 -0
- package/src/components/waka-incident-timeline/index.tsx +686 -0
- package/src/components/waka-invoice-preview/index.tsx +829 -0
- package/src/components/waka-kanban/index.tsx +646 -0
- package/src/components/waka-kpi-dashboard/index.tsx +755 -0
- package/src/components/waka-leaderboard/index.tsx +746 -0
- package/src/components/waka-level-progress/index.tsx +665 -0
- package/src/components/waka-liquid-button/index.tsx +520 -0
- package/src/components/waka-loading-orbit/index.tsx +478 -0
- package/src/components/waka-loot-box/index.tsx +1091 -0
- package/src/components/waka-magic-link/index.tsx +321 -0
- package/src/components/waka-magnetic-button/index.tsx +567 -0
- package/src/components/waka-mention-input/index.tsx +953 -0
- package/src/components/waka-metric-sparkline/index.tsx +627 -0
- package/src/components/waka-milestone-road/index.tsx +1064 -0
- package/src/components/waka-modal/index.tsx +374 -0
- package/src/components/waka-morph-button/index.tsx +495 -0
- package/src/components/waka-network-topology/index.tsx +801 -0
- package/src/components/waka-notifications/index.tsx +414 -0
- package/src/components/waka-number-input/index.tsx +373 -0
- package/src/components/waka-orbital-menu/index.tsx +445 -0
- package/src/components/waka-order-tracker/index.tsx +1041 -0
- package/src/components/waka-pagination/index.tsx +393 -0
- package/src/components/waka-password-strength/index.tsx +824 -0
- package/src/components/waka-payment-method-picker/index.tsx +715 -0
- package/src/components/waka-permission-matrix/index.tsx +1302 -0
- package/src/components/waka-phone-input/index.tsx +801 -0
- package/src/components/waka-pipeline-view/index.tsx +604 -0
- package/src/components/waka-player-card/index.tsx +691 -0
- package/src/components/waka-points-popup/index.tsx +366 -0
- package/src/components/waka-power-up/index.tsx +1155 -0
- package/src/components/waka-presence-indicator/index.tsx +1181 -0
- package/src/components/waka-pricing-table/index.tsx +755 -0
- package/src/components/waka-product-card/index.tsx +786 -0
- package/src/components/waka-progress-onboarding/index.tsx +878 -0
- package/src/components/waka-pull-to-refresh/index.tsx +451 -0
- package/src/components/waka-qrcode/index.tsx +232 -0
- package/src/components/waka-quest-card/index.tsx +1275 -0
- package/src/components/waka-quota-bar/index.tsx +693 -0
- package/src/components/waka-radar-score/index.tsx +512 -0
- package/src/components/waka-rank-badge/index.tsx +813 -0
- package/src/components/waka-rating-input/index.tsx +560 -0
- package/src/components/waka-reaction-picker/index.tsx +1062 -0
- package/src/components/waka-region-map/index.tsx +730 -0
- package/src/components/waka-resource-gauge/index.tsx +654 -0
- package/src/components/waka-resource-pool/index.tsx +1035 -0
- package/src/components/waka-rich-text-editor/index.tsx +594 -0
- package/src/components/waka-rollback-slider/index.tsx +891 -0
- package/src/components/waka-sankey-diagram/index.tsx +1032 -0
- package/src/components/waka-schedule-picker/index.tsx +1060 -0
- package/src/components/waka-scratch-card/index.tsx +914 -0
- package/src/components/waka-season-pass/index.tsx +886 -0
- package/src/components/waka-security-score/index.tsx +1126 -0
- package/src/components/waka-segmented-control/index.tsx +238 -0
- package/src/components/waka-server-rack/index.tsx +764 -0
- package/src/components/waka-session-manager/index.tsx +815 -0
- package/src/components/waka-signature-pad/index.tsx +744 -0
- package/src/components/waka-skeleton-wave/index.tsx +454 -0
- package/src/components/waka-skill-tree/index.tsx +1031 -0
- package/src/components/waka-sla-tracker/index.tsx +798 -0
- package/src/components/waka-slider-range/index.tsx +765 -0
- package/src/components/waka-spin-wheel/index.tsx +671 -0
- package/src/components/waka-spinner/index.tsx +284 -0
- package/src/components/waka-spotlight/index.tsx +410 -0
- package/src/components/waka-stat/index.tsx +428 -0
- package/src/components/waka-stats-hexagon/index.tsx +824 -0
- package/src/components/waka-status-matrix/index.tsx +565 -0
- package/src/components/waka-stepper/index.tsx +489 -0
- package/src/components/waka-streak-counter/index.tsx +334 -0
- package/src/components/waka-success-explosion/index.tsx +453 -0
- package/src/components/waka-swipe-card/index.tsx +574 -0
- package/src/components/waka-tabs-morph/index.tsx +509 -0
- package/src/components/waka-tag-input/index.tsx +877 -0
- package/src/components/waka-team-banner/index.tsx +1183 -0
- package/src/components/waka-terminal-output/index.tsx +836 -0
- package/src/components/waka-theme-creator/index.tsx +762 -0
- package/src/components/waka-theme-manager/index.tsx +654 -0
- package/src/components/waka-thread-view/index.tsx +874 -0
- package/src/components/waka-tilt-card/index.tsx +250 -0
- package/src/components/waka-time-picker/index.tsx +479 -0
- package/src/components/waka-timeline/index.tsx +385 -0
- package/src/components/waka-tooltip-tour/index.tsx +855 -0
- package/src/components/waka-tour-guide/index.tsx +920 -0
- package/src/components/waka-tournament-bracket/index.tsx +1276 -0
- package/src/components/waka-tree/index.tsx +557 -0
- package/src/components/waka-treemap-chart/index.tsx +1031 -0
- package/src/components/waka-two-factor-setup/index.tsx +995 -0
- package/src/components/waka-typewriter/index.tsx +566 -0
- package/src/components/waka-typing-indicator/index.tsx +649 -0
- package/src/components/waka-versus-card/index.tsx +1026 -0
- package/src/components/waka-video/index.tsx +557 -0
- package/src/components/waka-video-call/index.tsx +1087 -0
- package/src/components/waka-virtual-list/index.tsx +327 -0
- package/src/components/waka-voice-message/index.tsx +1019 -0
- package/src/components/waka-welcome-modal/index.tsx +790 -0
- package/src/components/waka-xp-bar/index.tsx +799 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { Check, ChevronsUpDown, X, Loader2, Plus } from "lucide-react"
|
|
5
|
+
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "../command"
|
|
6
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../popover"
|
|
7
|
+
import { Badge } from "../badge"
|
|
8
|
+
import { Button } from "../button"
|
|
9
|
+
import { Label } from "../label"
|
|
10
|
+
import { cn } from "../../utils/cn"
|
|
11
|
+
|
|
12
|
+
export interface AutocompleteOption {
|
|
13
|
+
value: string
|
|
14
|
+
label: string
|
|
15
|
+
disabled?: boolean
|
|
16
|
+
group?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface WakaAutocompleteProps {
|
|
20
|
+
/** Options disponibles */
|
|
21
|
+
options: AutocompleteOption[]
|
|
22
|
+
/** Valeur sélectionnée (string ou array pour multiple) */
|
|
23
|
+
value?: string | string[]
|
|
24
|
+
/** Callback de changement */
|
|
25
|
+
onChange?: (value: string | string[] | null) => void
|
|
26
|
+
/** Recherche asynchrone */
|
|
27
|
+
onSearch?: (query: string) => Promise<AutocompleteOption[]>
|
|
28
|
+
/** Mode sélection multiple */
|
|
29
|
+
multiple?: boolean
|
|
30
|
+
/** Permet de créer de nouvelles options */
|
|
31
|
+
creatable?: boolean
|
|
32
|
+
/** Callback lors de la création d'une option */
|
|
33
|
+
onCreate?: (value: string) => void
|
|
34
|
+
/** Placeholder */
|
|
35
|
+
placeholder?: string
|
|
36
|
+
/** Message quand aucun résultat */
|
|
37
|
+
emptyMessage?: string
|
|
38
|
+
/** Chargement en cours */
|
|
39
|
+
loading?: boolean
|
|
40
|
+
/** Désactivé */
|
|
41
|
+
disabled?: boolean
|
|
42
|
+
/** Erreur */
|
|
43
|
+
error?: string
|
|
44
|
+
/** Classes CSS additionnelles */
|
|
45
|
+
className?: string
|
|
46
|
+
/** Label */
|
|
47
|
+
label?: string
|
|
48
|
+
/** Description */
|
|
49
|
+
description?: string
|
|
50
|
+
/** Nombre max de sélections (mode multiple) */
|
|
51
|
+
maxSelections?: number
|
|
52
|
+
/** Tri des options */
|
|
53
|
+
sortOptions?: boolean
|
|
54
|
+
/** Debounce pour la recherche (ms) */
|
|
55
|
+
searchDebounce?: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Composant WakaAutocomplete
|
|
60
|
+
*/
|
|
61
|
+
export const WakaAutocomplete = React.forwardRef<HTMLButtonElement, WakaAutocompleteProps>(
|
|
62
|
+
(
|
|
63
|
+
{
|
|
64
|
+
options: initialOptions,
|
|
65
|
+
value,
|
|
66
|
+
onChange,
|
|
67
|
+
onSearch,
|
|
68
|
+
multiple = false,
|
|
69
|
+
creatable = false,
|
|
70
|
+
onCreate,
|
|
71
|
+
placeholder = "Sélectionner...",
|
|
72
|
+
emptyMessage = "Aucun résultat.",
|
|
73
|
+
loading: externalLoading = false,
|
|
74
|
+
disabled = false,
|
|
75
|
+
error,
|
|
76
|
+
className,
|
|
77
|
+
label,
|
|
78
|
+
description,
|
|
79
|
+
maxSelections,
|
|
80
|
+
sortOptions = false,
|
|
81
|
+
searchDebounce = 300,
|
|
82
|
+
},
|
|
83
|
+
ref
|
|
84
|
+
) => {
|
|
85
|
+
const [open, setOpen] = React.useState(false)
|
|
86
|
+
const [search, setSearch] = React.useState("")
|
|
87
|
+
const [options, setOptions] = React.useState<AutocompleteOption[]>(initialOptions)
|
|
88
|
+
const [loading, setLoading] = React.useState(false)
|
|
89
|
+
const searchTimeoutRef = React.useRef<NodeJS.Timeout>()
|
|
90
|
+
|
|
91
|
+
// Synchroniser les options quand elles changent
|
|
92
|
+
React.useEffect(() => {
|
|
93
|
+
if (!onSearch) {
|
|
94
|
+
setOptions(initialOptions)
|
|
95
|
+
}
|
|
96
|
+
}, [initialOptions, onSearch])
|
|
97
|
+
|
|
98
|
+
// Valeurs sélectionnées normalisées
|
|
99
|
+
const selectedValues = React.useMemo(() => {
|
|
100
|
+
if (!value) return []
|
|
101
|
+
return Array.isArray(value) ? value : [value]
|
|
102
|
+
}, [value])
|
|
103
|
+
|
|
104
|
+
// Recherche avec debounce
|
|
105
|
+
React.useEffect(() => {
|
|
106
|
+
if (!onSearch) return
|
|
107
|
+
|
|
108
|
+
if (searchTimeoutRef.current) {
|
|
109
|
+
clearTimeout(searchTimeoutRef.current)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!search.trim()) {
|
|
113
|
+
setOptions(initialOptions)
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
searchTimeoutRef.current = setTimeout(async () => {
|
|
118
|
+
setLoading(true)
|
|
119
|
+
try {
|
|
120
|
+
const results = await onSearch(search)
|
|
121
|
+
setOptions(results)
|
|
122
|
+
} catch {
|
|
123
|
+
setOptions([])
|
|
124
|
+
} finally {
|
|
125
|
+
setLoading(false)
|
|
126
|
+
}
|
|
127
|
+
}, searchDebounce)
|
|
128
|
+
|
|
129
|
+
return () => {
|
|
130
|
+
if (searchTimeoutRef.current) {
|
|
131
|
+
clearTimeout(searchTimeoutRef.current)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}, [search, onSearch, searchDebounce, initialOptions])
|
|
135
|
+
|
|
136
|
+
// Options filtrées et triées
|
|
137
|
+
const filteredOptions = React.useMemo(() => {
|
|
138
|
+
let filtered = options
|
|
139
|
+
|
|
140
|
+
// Filtrer par recherche si pas de recherche async
|
|
141
|
+
if (!onSearch && search.trim()) {
|
|
142
|
+
const searchLower = search.toLowerCase()
|
|
143
|
+
filtered = options.filter(
|
|
144
|
+
(opt) =>
|
|
145
|
+
opt.label.toLowerCase().includes(searchLower) ||
|
|
146
|
+
opt.value.toLowerCase().includes(searchLower)
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Trier
|
|
151
|
+
if (sortOptions) {
|
|
152
|
+
filtered = [...filtered].sort((a, b) => a.label.localeCompare(b.label))
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return filtered
|
|
156
|
+
}, [options, search, onSearch, sortOptions])
|
|
157
|
+
|
|
158
|
+
// Grouper les options
|
|
159
|
+
const groupedOptions = React.useMemo(() => {
|
|
160
|
+
const groups: Record<string, AutocompleteOption[]> = { _ungrouped: [] }
|
|
161
|
+
|
|
162
|
+
for (const option of filteredOptions) {
|
|
163
|
+
const group = option.group || "_ungrouped"
|
|
164
|
+
if (!groups[group]) groups[group] = []
|
|
165
|
+
groups[group].push(option)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return groups
|
|
169
|
+
}, [filteredOptions])
|
|
170
|
+
|
|
171
|
+
// Peut créer une nouvelle option?
|
|
172
|
+
const canCreate =
|
|
173
|
+
creatable &&
|
|
174
|
+
search.trim() &&
|
|
175
|
+
!options.some((opt) => opt.value.toLowerCase() === search.toLowerCase())
|
|
176
|
+
|
|
177
|
+
// Sélectionner une option
|
|
178
|
+
const handleSelect = (optionValue: string) => {
|
|
179
|
+
if (multiple) {
|
|
180
|
+
const newValues = selectedValues.includes(optionValue)
|
|
181
|
+
? selectedValues.filter((v) => v !== optionValue)
|
|
182
|
+
: maxSelections && selectedValues.length >= maxSelections
|
|
183
|
+
? selectedValues
|
|
184
|
+
: [...selectedValues, optionValue]
|
|
185
|
+
onChange?.(newValues.length > 0 ? newValues : null)
|
|
186
|
+
} else {
|
|
187
|
+
onChange?.(optionValue === (value as string) ? null : optionValue)
|
|
188
|
+
setOpen(false)
|
|
189
|
+
}
|
|
190
|
+
setSearch("")
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Créer une nouvelle option
|
|
194
|
+
const handleCreate = () => {
|
|
195
|
+
if (!search.trim()) return
|
|
196
|
+
|
|
197
|
+
const newOption: AutocompleteOption = {
|
|
198
|
+
value: search.trim(),
|
|
199
|
+
label: search.trim(),
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
setOptions((prev) => [...prev, newOption])
|
|
203
|
+
handleSelect(newOption.value)
|
|
204
|
+
onCreate?.(newOption.value)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Supprimer une valeur (mode multiple)
|
|
208
|
+
const handleRemove = (valueToRemove: string, e: React.MouseEvent) => {
|
|
209
|
+
e.stopPropagation()
|
|
210
|
+
const newValues = selectedValues.filter((v) => v !== valueToRemove)
|
|
211
|
+
onChange?.(newValues.length > 0 ? newValues : null)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Label pour une valeur
|
|
215
|
+
const getLabel = (val: string) => {
|
|
216
|
+
const option = options.find((opt) => opt.value === val)
|
|
217
|
+
return option?.label || val
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const isLoading = loading || externalLoading
|
|
221
|
+
|
|
222
|
+
return (
|
|
223
|
+
<div className={cn("space-y-1.5", className)}>
|
|
224
|
+
{label && <Label>{label}</Label>}
|
|
225
|
+
{description && <p className="text-sm text-muted-foreground">{description}</p>}
|
|
226
|
+
|
|
227
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
228
|
+
<PopoverTrigger asChild>
|
|
229
|
+
<Button
|
|
230
|
+
ref={ref}
|
|
231
|
+
variant="outline"
|
|
232
|
+
role="combobox"
|
|
233
|
+
aria-expanded={open}
|
|
234
|
+
disabled={disabled}
|
|
235
|
+
className={cn(
|
|
236
|
+
"w-full justify-between font-normal",
|
|
237
|
+
!value && "text-muted-foreground",
|
|
238
|
+
error && "border-destructive"
|
|
239
|
+
)}
|
|
240
|
+
>
|
|
241
|
+
{multiple ? (
|
|
242
|
+
<div className="flex flex-wrap gap-1 flex-1 min-w-0">
|
|
243
|
+
{selectedValues.length > 0 ? (
|
|
244
|
+
selectedValues.map((val) => (
|
|
245
|
+
<Badge key={val} variant="secondary" className="text-xs">
|
|
246
|
+
{getLabel(val)}
|
|
247
|
+
<button
|
|
248
|
+
className="ml-1 hover:text-destructive"
|
|
249
|
+
onClick={(e) => handleRemove(val, e)}
|
|
250
|
+
>
|
|
251
|
+
<X className="h-3 w-3" />
|
|
252
|
+
</button>
|
|
253
|
+
</Badge>
|
|
254
|
+
))
|
|
255
|
+
) : (
|
|
256
|
+
<span>{placeholder}</span>
|
|
257
|
+
)}
|
|
258
|
+
</div>
|
|
259
|
+
) : (
|
|
260
|
+
<span className="truncate">
|
|
261
|
+
{value ? getLabel(value as string) : placeholder}
|
|
262
|
+
</span>
|
|
263
|
+
)}
|
|
264
|
+
{isLoading ? (
|
|
265
|
+
<Loader2 className="ml-2 h-4 w-4 shrink-0 animate-spin" />
|
|
266
|
+
) : (
|
|
267
|
+
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
|
268
|
+
)}
|
|
269
|
+
</Button>
|
|
270
|
+
</PopoverTrigger>
|
|
271
|
+
<PopoverContent className="w-[var(--radix-popover-trigger-width)] p-0" align="start">
|
|
272
|
+
<Command shouldFilter={false}>
|
|
273
|
+
<CommandInput
|
|
274
|
+
placeholder="Rechercher..."
|
|
275
|
+
value={search}
|
|
276
|
+
onValueChange={setSearch}
|
|
277
|
+
/>
|
|
278
|
+
<CommandList>
|
|
279
|
+
{isLoading && (
|
|
280
|
+
<div className="py-6 text-center text-sm">
|
|
281
|
+
<Loader2 className="h-4 w-4 animate-spin mx-auto mb-2" />
|
|
282
|
+
Chargement...
|
|
283
|
+
</div>
|
|
284
|
+
)}
|
|
285
|
+
|
|
286
|
+
{!isLoading && filteredOptions.length === 0 && !canCreate && (
|
|
287
|
+
<CommandEmpty>{emptyMessage}</CommandEmpty>
|
|
288
|
+
)}
|
|
289
|
+
|
|
290
|
+
{/* Options créables */}
|
|
291
|
+
{canCreate && (
|
|
292
|
+
<CommandGroup>
|
|
293
|
+
<CommandItem onSelect={handleCreate} className="cursor-pointer">
|
|
294
|
+
<Plus className="mr-2 h-4 w-4" />
|
|
295
|
+
Créer "{search}"
|
|
296
|
+
</CommandItem>
|
|
297
|
+
</CommandGroup>
|
|
298
|
+
)}
|
|
299
|
+
|
|
300
|
+
{/* Options groupées */}
|
|
301
|
+
{Object.entries(groupedOptions).map(([group, groupOptions]) => {
|
|
302
|
+
if (groupOptions.length === 0) return null
|
|
303
|
+
|
|
304
|
+
return (
|
|
305
|
+
<CommandGroup key={group} heading={group !== "_ungrouped" ? group : undefined}>
|
|
306
|
+
{groupOptions.map((option) => (
|
|
307
|
+
<CommandItem
|
|
308
|
+
key={option.value}
|
|
309
|
+
value={option.value}
|
|
310
|
+
onSelect={() => handleSelect(option.value)}
|
|
311
|
+
disabled={option.disabled}
|
|
312
|
+
className="cursor-pointer"
|
|
313
|
+
>
|
|
314
|
+
<Check
|
|
315
|
+
className={cn(
|
|
316
|
+
"mr-2 h-4 w-4",
|
|
317
|
+
selectedValues.includes(option.value)
|
|
318
|
+
? "opacity-100"
|
|
319
|
+
: "opacity-0"
|
|
320
|
+
)}
|
|
321
|
+
/>
|
|
322
|
+
{option.label}
|
|
323
|
+
</CommandItem>
|
|
324
|
+
))}
|
|
325
|
+
</CommandGroup>
|
|
326
|
+
)
|
|
327
|
+
})}
|
|
328
|
+
</CommandList>
|
|
329
|
+
</Command>
|
|
330
|
+
</PopoverContent>
|
|
331
|
+
</Popover>
|
|
332
|
+
|
|
333
|
+
{error && <p className="text-sm text-destructive">{error}</p>}
|
|
334
|
+
</div>
|
|
335
|
+
)
|
|
336
|
+
}
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
WakaAutocomplete.displayName = "WakaAutocomplete"
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Version intégrée avec react-hook-form via Controller
|
|
343
|
+
*/
|
|
344
|
+
export interface WakaAutocompleteFormProps extends Omit<WakaAutocompleteProps, "value" | "onChange"> {
|
|
345
|
+
name: string
|
|
346
|
+
value?: string | string[]
|
|
347
|
+
onChange?: (value: string | string[] | null) => void
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export const WakaAutocompleteForm = React.forwardRef<HTMLButtonElement, WakaAutocompleteFormProps>(
|
|
351
|
+
(props, ref) => {
|
|
352
|
+
return <WakaAutocomplete ref={ref} {...props} />
|
|
353
|
+
}
|
|
354
|
+
)
|
|
355
|
+
|
|
356
|
+
WakaAutocompleteForm.displayName = "WakaAutocompleteForm"
|
|
357
|
+
|
|
358
|
+
export default WakaAutocomplete
|