@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.
Files changed (290) hide show
  1. package/dist/cli/commands/add.d.ts +7 -0
  2. package/dist/cli/commands/init.d.ts +6 -0
  3. package/dist/cli/commands/list.d.ts +5 -0
  4. package/dist/cli/commands/search.d.ts +1 -0
  5. package/dist/cli/index.cjs +4844 -0
  6. package/dist/cli/index.d.ts +1 -0
  7. package/dist/cli/utils/config.d.ts +29 -0
  8. package/dist/cli/utils/logger.d.ts +20 -0
  9. package/dist/cli/utils/registry.d.ts +23 -0
  10. package/package.json +14 -3
  11. package/src/blocks/activity-timeline/index.tsx +586 -0
  12. package/src/blocks/calendar-view/index.tsx +756 -0
  13. package/src/blocks/chat/index.tsx +1018 -0
  14. package/src/blocks/chat/widget.tsx +504 -0
  15. package/src/blocks/dashboard/index.tsx +522 -0
  16. package/src/blocks/empty-states/index.tsx +452 -0
  17. package/src/blocks/error-pages/index.tsx +426 -0
  18. package/src/blocks/faq/index.tsx +479 -0
  19. package/src/blocks/file-manager/index.tsx +890 -0
  20. package/src/blocks/footer/index.tsx +133 -0
  21. package/src/blocks/header/index.tsx +357 -0
  22. package/src/blocks/headtab/index.tsx +139 -0
  23. package/src/blocks/i18n-editor/index.tsx +1016 -0
  24. package/src/blocks/index.ts +80 -0
  25. package/src/blocks/kanban-board/index.tsx +779 -0
  26. package/src/blocks/landing/index.tsx +677 -0
  27. package/src/blocks/language-selector/index.tsx +88 -0
  28. package/src/blocks/layout/index.tsx +159 -0
  29. package/src/blocks/login/index.tsx +339 -0
  30. package/src/blocks/login/types.ts +131 -0
  31. package/src/blocks/pricing/index.tsx +564 -0
  32. package/src/blocks/profile/index.tsx +746 -0
  33. package/src/blocks/settings/index.tsx +558 -0
  34. package/src/blocks/sidebar/index.tsx +713 -0
  35. package/src/blocks/theme-creator-block/index.tsx +835 -0
  36. package/src/blocks/user-management/index.tsx +1037 -0
  37. package/src/blocks/wizard/index.tsx +719 -0
  38. package/src/components/DataTable/DataTable.tsx +406 -0
  39. package/src/components/DataTable/DataTableAdvanced.tsx +720 -0
  40. package/src/components/DataTable/DataTableBody.tsx +216 -0
  41. package/src/components/DataTable/DataTableCell.tsx +172 -0
  42. package/src/components/DataTable/DataTableColumnResizer.tsx +62 -0
  43. package/src/components/DataTable/DataTableConflictResolver.tsx +478 -0
  44. package/src/components/DataTable/DataTableContextMenu.tsx +219 -0
  45. package/src/components/DataTable/DataTableEditCell.tsx +279 -0
  46. package/src/components/DataTable/DataTableFilterBuilder.tsx +519 -0
  47. package/src/components/DataTable/DataTableFilters.tsx +535 -0
  48. package/src/components/DataTable/DataTableGrouping.tsx +147 -0
  49. package/src/components/DataTable/DataTableHeader.tsx +172 -0
  50. package/src/components/DataTable/DataTablePagination.tsx +125 -0
  51. package/src/components/DataTable/DataTableSelection.tsx +269 -0
  52. package/src/components/DataTable/DataTableSyncStatus.tsx +281 -0
  53. package/src/components/DataTable/DataTableToolbar.tsx +262 -0
  54. package/src/components/DataTable/README.md +446 -0
  55. package/src/components/DataTable/__tests__/DataTableAdvanced.test.tsx +426 -0
  56. package/src/components/DataTable/__tests__/DataTableEdit.test.tsx +329 -0
  57. package/src/components/DataTable/__tests__/useDataTableAdvanced.test.ts +455 -0
  58. package/src/components/DataTable/examples/EditExample.tsx +166 -0
  59. package/src/components/DataTable/formatters/index.ts +335 -0
  60. package/src/components/DataTable/hooks/__tests__/useDataTableEdit.test.ts +239 -0
  61. package/src/components/DataTable/hooks/useDataTable.ts +145 -0
  62. package/src/components/DataTable/hooks/useDataTableAdvanced.ts +342 -0
  63. package/src/components/DataTable/hooks/useDataTableAdvancedFilters.ts +637 -0
  64. package/src/components/DataTable/hooks/useDataTableColumnTemplates.ts +186 -0
  65. package/src/components/DataTable/hooks/useDataTableEdit.ts +167 -0
  66. package/src/components/DataTable/hooks/useDataTableExport.ts +227 -0
  67. package/src/components/DataTable/hooks/useDataTableImport.ts +216 -0
  68. package/src/components/DataTable/hooks/useDataTableOffline.ts +481 -0
  69. package/src/components/DataTable/hooks/useDataTableTheme.ts +213 -0
  70. package/src/components/DataTable/hooks/useDataTableVirtualization.ts +99 -0
  71. package/src/components/DataTable/hooks/useTableLayout.ts +85 -0
  72. package/src/components/DataTable/index.ts +81 -0
  73. package/src/components/DataTable/services/IndexedDBService.ts +504 -0
  74. package/src/components/DataTable/templates/index.tsx +803 -0
  75. package/src/components/DataTable/types.ts +504 -0
  76. package/src/components/DataTable/utils.ts +164 -0
  77. package/src/components/DataTable/workers/exportWorker.ts +213 -0
  78. package/src/components/accordion/index.tsx +61 -0
  79. package/src/components/alert/index.tsx +61 -0
  80. package/src/components/alert-dialog/index.tsx +146 -0
  81. package/src/components/aspect-ratio/index.tsx +12 -0
  82. package/src/components/avatar/index.tsx +54 -0
  83. package/src/components/badge/Badge.stories.tsx +64 -0
  84. package/src/components/badge/index.tsx +38 -0
  85. package/src/components/button/Button.stories.tsx +173 -0
  86. package/src/components/button/index.tsx +56 -0
  87. package/src/components/calendar/index.tsx +73 -0
  88. package/src/components/card/index.tsx +78 -0
  89. package/src/components/checkbox/index.tsx +34 -0
  90. package/src/components/code/index.tsx +229 -0
  91. package/src/components/collapsible/index.tsx +16 -0
  92. package/src/components/command/index.tsx +162 -0
  93. package/src/components/context-menu/index.tsx +204 -0
  94. package/src/components/dialog/index.tsx +126 -0
  95. package/src/components/dropdown-menu/index.tsx +204 -0
  96. package/src/components/error-boundary/ErrorBoundary.tsx +281 -0
  97. package/src/components/error-boundary/index.ts +7 -0
  98. package/src/components/form/index.tsx +183 -0
  99. package/src/components/hover-card/index.tsx +33 -0
  100. package/src/components/index.ts +368 -0
  101. package/src/components/input/Input.stories.tsx +100 -0
  102. package/src/components/input/index.tsx +27 -0
  103. package/src/components/input-otp/index.tsx +277 -0
  104. package/src/components/label/index.tsx +30 -0
  105. package/src/components/language-selector/index.tsx +341 -0
  106. package/src/components/menubar/index.tsx +240 -0
  107. package/src/components/navigation-menu/index.tsx +134 -0
  108. package/src/components/popover/index.tsx +35 -0
  109. package/src/components/progress/index.tsx +32 -0
  110. package/src/components/radio-group/index.tsx +48 -0
  111. package/src/components/scroll-area/index.tsx +52 -0
  112. package/src/components/select/index.tsx +164 -0
  113. package/src/components/separator/index.tsx +35 -0
  114. package/src/components/sheet/index.tsx +147 -0
  115. package/src/components/skeleton/index.tsx +22 -0
  116. package/src/components/slider/index.tsx +32 -0
  117. package/src/components/switch/index.tsx +33 -0
  118. package/src/components/table/index.tsx +117 -0
  119. package/src/components/tabs/index.tsx +59 -0
  120. package/src/components/textarea/index.tsx +30 -0
  121. package/src/components/theme-selector/index.tsx +327 -0
  122. package/src/components/toast/index.tsx +133 -0
  123. package/src/components/toaster/index.tsx +34 -0
  124. package/src/components/toggle/index.tsx +49 -0
  125. package/src/components/tooltip/index.tsx +34 -0
  126. package/src/components/typography/index.tsx +276 -0
  127. package/src/components/waka-3d-pie-chart/index.tsx +486 -0
  128. package/src/components/waka-achievement-unlock/index.tsx +716 -0
  129. package/src/components/waka-activity-feed/index.tsx +686 -0
  130. package/src/components/waka-address-autocomplete/index.tsx +1202 -0
  131. package/src/components/waka-admincrumb/index.tsx +349 -0
  132. package/src/components/waka-alert-stack/index.tsx +827 -0
  133. package/src/components/waka-allocation-matrix/index.tsx +1278 -0
  134. package/src/components/waka-approval-chain/index.tsx +766 -0
  135. package/src/components/waka-audit-log/index.tsx +1475 -0
  136. package/src/components/waka-autocomplete/index.tsx +358 -0
  137. package/src/components/waka-badge-showcase/index.tsx +704 -0
  138. package/src/components/waka-barcode/index.tsx +260 -0
  139. package/src/components/waka-biometric-prompt/index.tsx +765 -0
  140. package/src/components/waka-bottom-sheet/index.tsx +495 -0
  141. package/src/components/waka-breadcrumb/index.tsx +376 -0
  142. package/src/components/waka-breadcrumb-path/index.tsx +513 -0
  143. package/src/components/waka-budget-burn/index.tsx +1234 -0
  144. package/src/components/waka-capacity-planner/index.tsx +1107 -0
  145. package/src/components/waka-carousel/index.tsx +893 -0
  146. package/src/components/waka-cart-summary/index.tsx +1055 -0
  147. package/src/components/waka-challenge-timer/index.tsx +1044 -0
  148. package/src/components/waka-charts/WakaAreaChart.tsx +251 -0
  149. package/src/components/waka-charts/WakaBarChart.tsx +222 -0
  150. package/src/components/waka-charts/WakaChart.tsx +124 -0
  151. package/src/components/waka-charts/WakaLineChart.tsx +219 -0
  152. package/src/components/waka-charts/WakaMiniChart.tsx +133 -0
  153. package/src/components/waka-charts/WakaPieChart.tsx +214 -0
  154. package/src/components/waka-charts/WakaSparkline.tsx +229 -0
  155. package/src/components/waka-charts/dataTableHelpers.ts +109 -0
  156. package/src/components/waka-charts/hooks/useChartTheme.ts +123 -0
  157. package/src/components/waka-charts/hooks/useRechartsLoader.ts +234 -0
  158. package/src/components/waka-charts/index.ts +90 -0
  159. package/src/components/waka-charts/types.ts +330 -0
  160. package/src/components/waka-chat-bubble/index.tsx +1060 -0
  161. package/src/components/waka-checklist/index.tsx +1067 -0
  162. package/src/components/waka-checkout-stepper/index.tsx +976 -0
  163. package/src/components/waka-cohort-table/index.tsx +1011 -0
  164. package/src/components/waka-color-picker/index.tsx +447 -0
  165. package/src/components/waka-combo-counter/index.tsx +864 -0
  166. package/src/components/waka-combobox/index.tsx +497 -0
  167. package/src/components/waka-command-bar/index.tsx +403 -0
  168. package/src/components/waka-compare-period/index.tsx +1230 -0
  169. package/src/components/waka-connection-matrix/index.tsx +1053 -0
  170. package/src/components/waka-contribution-graph/index.tsx +552 -0
  171. package/src/components/waka-cost-breakdown/index.tsx +1065 -0
  172. package/src/components/waka-coupon-input/index.tsx +592 -0
  173. package/src/components/waka-credit-card-input/index.tsx +982 -0
  174. package/src/components/waka-daily-reward/index.tsx +762 -0
  175. package/src/components/waka-date-range-picker/index.tsx +378 -0
  176. package/src/components/waka-datetime-picker/index.tsx +793 -0
  177. package/src/components/waka-datetime-picker.form-integration/index.tsx +402 -0
  178. package/src/components/waka-deployment-lane/index.tsx +673 -0
  179. package/src/components/waka-device-trust/index.tsx +1259 -0
  180. package/src/components/waka-dock/index.tsx +285 -0
  181. package/src/components/waka-drawer/index.tsx +319 -0
  182. package/src/components/waka-empty-state/index.tsx +545 -0
  183. package/src/components/waka-error-shake/index.tsx +398 -0
  184. package/src/components/waka-feature-announcement/index.tsx +991 -0
  185. package/src/components/waka-file-upload/index.tsx +437 -0
  186. package/src/components/waka-floating-nav/index.tsx +413 -0
  187. package/src/components/waka-flow-diagram/index.tsx +508 -0
  188. package/src/components/waka-funnel-chart/index.tsx +823 -0
  189. package/src/components/waka-glow-card/index.tsx +246 -0
  190. package/src/components/waka-goal-progress/index.tsx +1025 -0
  191. package/src/components/waka-haptic-button/index.tsx +388 -0
  192. package/src/components/waka-health-pulse/index.tsx +451 -0
  193. package/src/components/waka-heatmap/index.tsx +1026 -0
  194. package/src/components/waka-hotspot/index.tsx +682 -0
  195. package/src/components/waka-image/index.tsx +373 -0
  196. package/src/components/waka-incident-timeline/index.tsx +686 -0
  197. package/src/components/waka-invoice-preview/index.tsx +829 -0
  198. package/src/components/waka-kanban/index.tsx +646 -0
  199. package/src/components/waka-kpi-dashboard/index.tsx +755 -0
  200. package/src/components/waka-leaderboard/index.tsx +746 -0
  201. package/src/components/waka-level-progress/index.tsx +665 -0
  202. package/src/components/waka-liquid-button/index.tsx +520 -0
  203. package/src/components/waka-loading-orbit/index.tsx +478 -0
  204. package/src/components/waka-loot-box/index.tsx +1091 -0
  205. package/src/components/waka-magic-link/index.tsx +321 -0
  206. package/src/components/waka-magnetic-button/index.tsx +567 -0
  207. package/src/components/waka-mention-input/index.tsx +953 -0
  208. package/src/components/waka-metric-sparkline/index.tsx +627 -0
  209. package/src/components/waka-milestone-road/index.tsx +1064 -0
  210. package/src/components/waka-modal/index.tsx +374 -0
  211. package/src/components/waka-morph-button/index.tsx +495 -0
  212. package/src/components/waka-network-topology/index.tsx +801 -0
  213. package/src/components/waka-notifications/index.tsx +414 -0
  214. package/src/components/waka-number-input/index.tsx +373 -0
  215. package/src/components/waka-orbital-menu/index.tsx +445 -0
  216. package/src/components/waka-order-tracker/index.tsx +1041 -0
  217. package/src/components/waka-pagination/index.tsx +393 -0
  218. package/src/components/waka-password-strength/index.tsx +824 -0
  219. package/src/components/waka-payment-method-picker/index.tsx +715 -0
  220. package/src/components/waka-permission-matrix/index.tsx +1302 -0
  221. package/src/components/waka-phone-input/index.tsx +801 -0
  222. package/src/components/waka-pipeline-view/index.tsx +604 -0
  223. package/src/components/waka-player-card/index.tsx +691 -0
  224. package/src/components/waka-points-popup/index.tsx +366 -0
  225. package/src/components/waka-power-up/index.tsx +1155 -0
  226. package/src/components/waka-presence-indicator/index.tsx +1181 -0
  227. package/src/components/waka-pricing-table/index.tsx +755 -0
  228. package/src/components/waka-product-card/index.tsx +786 -0
  229. package/src/components/waka-progress-onboarding/index.tsx +878 -0
  230. package/src/components/waka-pull-to-refresh/index.tsx +451 -0
  231. package/src/components/waka-qrcode/index.tsx +232 -0
  232. package/src/components/waka-quest-card/index.tsx +1275 -0
  233. package/src/components/waka-quota-bar/index.tsx +693 -0
  234. package/src/components/waka-radar-score/index.tsx +512 -0
  235. package/src/components/waka-rank-badge/index.tsx +813 -0
  236. package/src/components/waka-rating-input/index.tsx +560 -0
  237. package/src/components/waka-reaction-picker/index.tsx +1062 -0
  238. package/src/components/waka-region-map/index.tsx +730 -0
  239. package/src/components/waka-resource-gauge/index.tsx +654 -0
  240. package/src/components/waka-resource-pool/index.tsx +1035 -0
  241. package/src/components/waka-rich-text-editor/index.tsx +594 -0
  242. package/src/components/waka-rollback-slider/index.tsx +891 -0
  243. package/src/components/waka-sankey-diagram/index.tsx +1032 -0
  244. package/src/components/waka-schedule-picker/index.tsx +1060 -0
  245. package/src/components/waka-scratch-card/index.tsx +914 -0
  246. package/src/components/waka-season-pass/index.tsx +886 -0
  247. package/src/components/waka-security-score/index.tsx +1126 -0
  248. package/src/components/waka-segmented-control/index.tsx +238 -0
  249. package/src/components/waka-server-rack/index.tsx +764 -0
  250. package/src/components/waka-session-manager/index.tsx +815 -0
  251. package/src/components/waka-signature-pad/index.tsx +744 -0
  252. package/src/components/waka-skeleton-wave/index.tsx +454 -0
  253. package/src/components/waka-skill-tree/index.tsx +1031 -0
  254. package/src/components/waka-sla-tracker/index.tsx +798 -0
  255. package/src/components/waka-slider-range/index.tsx +765 -0
  256. package/src/components/waka-spin-wheel/index.tsx +671 -0
  257. package/src/components/waka-spinner/index.tsx +284 -0
  258. package/src/components/waka-spotlight/index.tsx +410 -0
  259. package/src/components/waka-stat/index.tsx +428 -0
  260. package/src/components/waka-stats-hexagon/index.tsx +824 -0
  261. package/src/components/waka-status-matrix/index.tsx +565 -0
  262. package/src/components/waka-stepper/index.tsx +489 -0
  263. package/src/components/waka-streak-counter/index.tsx +334 -0
  264. package/src/components/waka-success-explosion/index.tsx +453 -0
  265. package/src/components/waka-swipe-card/index.tsx +574 -0
  266. package/src/components/waka-tabs-morph/index.tsx +509 -0
  267. package/src/components/waka-tag-input/index.tsx +877 -0
  268. package/src/components/waka-team-banner/index.tsx +1183 -0
  269. package/src/components/waka-terminal-output/index.tsx +836 -0
  270. package/src/components/waka-theme-creator/index.tsx +762 -0
  271. package/src/components/waka-theme-manager/index.tsx +654 -0
  272. package/src/components/waka-thread-view/index.tsx +874 -0
  273. package/src/components/waka-tilt-card/index.tsx +250 -0
  274. package/src/components/waka-time-picker/index.tsx +479 -0
  275. package/src/components/waka-timeline/index.tsx +385 -0
  276. package/src/components/waka-tooltip-tour/index.tsx +855 -0
  277. package/src/components/waka-tour-guide/index.tsx +920 -0
  278. package/src/components/waka-tournament-bracket/index.tsx +1276 -0
  279. package/src/components/waka-tree/index.tsx +557 -0
  280. package/src/components/waka-treemap-chart/index.tsx +1031 -0
  281. package/src/components/waka-two-factor-setup/index.tsx +995 -0
  282. package/src/components/waka-typewriter/index.tsx +566 -0
  283. package/src/components/waka-typing-indicator/index.tsx +649 -0
  284. package/src/components/waka-versus-card/index.tsx +1026 -0
  285. package/src/components/waka-video/index.tsx +557 -0
  286. package/src/components/waka-video-call/index.tsx +1087 -0
  287. package/src/components/waka-virtual-list/index.tsx +327 -0
  288. package/src/components/waka-voice-message/index.tsx +1019 -0
  289. package/src/components/waka-welcome-modal/index.tsx +790 -0
  290. package/src/components/waka-xp-bar/index.tsx +799 -0
@@ -0,0 +1,447 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { Pipette } from "lucide-react"
5
+ import { Popover, PopoverContent, PopoverTrigger } from "../popover"
6
+ import { Button } from "../button"
7
+ import { Input } from "../input"
8
+ import { Label } from "../label"
9
+ import { cn } from "../../utils/cn"
10
+
11
+ export type ColorFormat = "hex" | "rgb" | "hsl"
12
+
13
+ export interface WakaColorPickerProps {
14
+ /** Valeur de la couleur */
15
+ value?: string
16
+ /** Callback de changement */
17
+ onChange?: (color: string) => void
18
+ /** Format de couleur */
19
+ format?: ColorFormat
20
+ /** Afficher le canal alpha */
21
+ showAlpha?: boolean
22
+ /** Afficher les couleurs prédéfinies */
23
+ showPresets?: boolean
24
+ /** Couleurs prédéfinies personnalisées */
25
+ presets?: string[]
26
+ /** Afficher l'outil EyeDropper (si supporté) */
27
+ showEyeDropper?: boolean
28
+ /** Désactivé */
29
+ disabled?: boolean
30
+ /** Placeholder */
31
+ placeholder?: string
32
+ /** Classes CSS additionnelles */
33
+ className?: string
34
+ /** Taille */
35
+ size?: "sm" | "md" | "lg"
36
+ }
37
+
38
+ // Couleurs prédéfinies par défaut
39
+ const DEFAULT_PRESETS = [
40
+ "#ef4444", "#f97316", "#f59e0b", "#eab308", "#84cc16",
41
+ "#22c55e", "#10b981", "#14b8a6", "#06b6d4", "#0ea5e9",
42
+ "#3b82f6", "#6366f1", "#8b5cf6", "#a855f7", "#d946ef",
43
+ "#ec4899", "#f43f5e", "#000000", "#6b7280", "#ffffff",
44
+ ]
45
+
46
+ /**
47
+ * Convertit une couleur HSL en RGB
48
+ */
49
+ function hslToRgb(h: number, s: number, l: number): [number, number, number] {
50
+ s /= 100
51
+ l /= 100
52
+ const a = s * Math.min(l, 1 - l)
53
+ const f = (n: number) => {
54
+ const k = (n + h / 30) % 12
55
+ return l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1)
56
+ }
57
+ return [Math.round(f(0) * 255), Math.round(f(8) * 255), Math.round(f(4) * 255)]
58
+ }
59
+
60
+ /**
61
+ * Convertit une couleur RGB en HSL
62
+ */
63
+ function rgbToHsl(r: number, g: number, b: number): [number, number, number] {
64
+ r /= 255
65
+ g /= 255
66
+ b /= 255
67
+ const max = Math.max(r, g, b)
68
+ const min = Math.min(r, g, b)
69
+ let h = 0
70
+ let s = 0
71
+ const l = (max + min) / 2
72
+
73
+ if (max !== min) {
74
+ const d = max - min
75
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min)
76
+ switch (max) {
77
+ case r:
78
+ h = ((g - b) / d + (g < b ? 6 : 0)) * 60
79
+ break
80
+ case g:
81
+ h = ((b - r) / d + 2) * 60
82
+ break
83
+ case b:
84
+ h = ((r - g) / d + 4) * 60
85
+ break
86
+ }
87
+ }
88
+
89
+ return [Math.round(h), Math.round(s * 100), Math.round(l * 100)]
90
+ }
91
+
92
+ /**
93
+ * Convertit une couleur hex en RGB
94
+ */
95
+ function hexToRgb(hex: string): [number, number, number] | null {
96
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
97
+ if (!result) return null
98
+ return [
99
+ parseInt(result[1], 16),
100
+ parseInt(result[2], 16),
101
+ parseInt(result[3], 16),
102
+ ]
103
+ }
104
+
105
+ /**
106
+ * Convertit une couleur RGB en hex
107
+ */
108
+ function rgbToHex(r: number, g: number, b: number): string {
109
+ return "#" + [r, g, b].map((x) => x.toString(16).padStart(2, "0")).join("")
110
+ }
111
+
112
+ /**
113
+ * Parse une couleur en RGB
114
+ */
115
+ function parseColor(color: string): [number, number, number] | null {
116
+ // Hex
117
+ if (color.startsWith("#")) {
118
+ return hexToRgb(color)
119
+ }
120
+
121
+ // RGB
122
+ const rgbMatch = color.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/)
123
+ if (rgbMatch) {
124
+ return [parseInt(rgbMatch[1]), parseInt(rgbMatch[2]), parseInt(rgbMatch[3])]
125
+ }
126
+
127
+ // HSL
128
+ const hslMatch = color.match(/hsl\((\d+),\s*(\d+)%?,\s*(\d+)%?\)/)
129
+ if (hslMatch) {
130
+ return hslToRgb(parseInt(hslMatch[1]), parseInt(hslMatch[2]), parseInt(hslMatch[3]))
131
+ }
132
+
133
+ return null
134
+ }
135
+
136
+ /**
137
+ * Formate une couleur selon le format demandé
138
+ */
139
+ function formatColor(r: number, g: number, b: number, format: ColorFormat): string {
140
+ switch (format) {
141
+ case "hex":
142
+ return rgbToHex(r, g, b)
143
+ case "rgb":
144
+ return `rgb(${r}, ${g}, ${b})`
145
+ case "hsl": {
146
+ const [h, s, l] = rgbToHsl(r, g, b)
147
+ return `hsl(${h}, ${s}%, ${l}%)`
148
+ }
149
+ default:
150
+ return rgbToHex(r, g, b)
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Composant WakaColorPicker
156
+ */
157
+ export const WakaColorPicker = React.forwardRef<HTMLButtonElement, WakaColorPickerProps>(
158
+ (
159
+ {
160
+ value = "#3b82f6",
161
+ onChange,
162
+ format = "hex",
163
+ showAlpha = false,
164
+ showPresets = true,
165
+ presets = DEFAULT_PRESETS,
166
+ showEyeDropper = true,
167
+ disabled = false,
168
+ placeholder = "Sélectionner une couleur",
169
+ className,
170
+ size = "md",
171
+ },
172
+ ref
173
+ ) => {
174
+ const [open, setOpen] = React.useState(false)
175
+ const [hue, setHue] = React.useState(0)
176
+ const [saturation, setSaturation] = React.useState(100)
177
+ const [lightness, setLightness] = React.useState(50)
178
+ const [inputValue, setInputValue] = React.useState(value)
179
+
180
+ const saturationRef = React.useRef<HTMLDivElement>(null)
181
+ const hueRef = React.useRef<HTMLDivElement>(null)
182
+
183
+ // Synchroniser l'état avec la valeur prop
184
+ React.useEffect(() => {
185
+ const rgb = parseColor(value)
186
+ if (rgb) {
187
+ const [h, s, l] = rgbToHsl(...rgb)
188
+ setHue(h)
189
+ setSaturation(s)
190
+ setLightness(l)
191
+ setInputValue(value)
192
+ }
193
+ }, [value])
194
+
195
+ // Mettre à jour la couleur
196
+ const updateColor = React.useCallback(
197
+ (h: number, s: number, l: number) => {
198
+ const [r, g, b] = hslToRgb(h, s, l)
199
+ const color = formatColor(r, g, b, format)
200
+ setInputValue(color)
201
+ onChange?.(color)
202
+ },
203
+ [format, onChange]
204
+ )
205
+
206
+ // Gestionnaire de glissement pour la saturation/lightness
207
+ const handleSaturationMouseDown = (e: React.MouseEvent) => {
208
+ e.preventDefault()
209
+ const rect = saturationRef.current?.getBoundingClientRect()
210
+ if (!rect) return
211
+
212
+ const handleMove = (clientX: number, clientY: number) => {
213
+ const s = Math.max(0, Math.min(100, ((clientX - rect.left) / rect.width) * 100))
214
+ const l = Math.max(0, Math.min(100, 100 - ((clientY - rect.top) / rect.height) * 100))
215
+ setSaturation(s)
216
+ setLightness(l)
217
+ updateColor(hue, s, l)
218
+ }
219
+
220
+ handleMove(e.clientX, e.clientY)
221
+
222
+ const onMouseMove = (e: MouseEvent) => handleMove(e.clientX, e.clientY)
223
+ const onMouseUp = () => {
224
+ document.removeEventListener("mousemove", onMouseMove)
225
+ document.removeEventListener("mouseup", onMouseUp)
226
+ }
227
+
228
+ document.addEventListener("mousemove", onMouseMove)
229
+ document.addEventListener("mouseup", onMouseUp)
230
+ }
231
+
232
+ // Gestionnaire de glissement pour la teinte
233
+ const handleHueMouseDown = (e: React.MouseEvent) => {
234
+ e.preventDefault()
235
+ const rect = hueRef.current?.getBoundingClientRect()
236
+ if (!rect) return
237
+
238
+ const handleMove = (clientX: number) => {
239
+ const h = Math.max(0, Math.min(360, ((clientX - rect.left) / rect.width) * 360))
240
+ setHue(h)
241
+ updateColor(h, saturation, lightness)
242
+ }
243
+
244
+ handleMove(e.clientX)
245
+
246
+ const onMouseMove = (e: MouseEvent) => handleMove(e.clientX)
247
+ const onMouseUp = () => {
248
+ document.removeEventListener("mousemove", onMouseMove)
249
+ document.removeEventListener("mouseup", onMouseUp)
250
+ }
251
+
252
+ document.addEventListener("mousemove", onMouseMove)
253
+ document.addEventListener("mouseup", onMouseUp)
254
+ }
255
+
256
+ // EyeDropper API
257
+ const handleEyeDropper = async () => {
258
+ if (!("EyeDropper" in window)) return
259
+
260
+ try {
261
+ // @ts-expect-error - EyeDropper API not in TypeScript types yet
262
+ const eyeDropper = new window.EyeDropper()
263
+ const result = await eyeDropper.open()
264
+ const rgb = parseColor(result.sRGBHex)
265
+ if (rgb) {
266
+ const [h, s, l] = rgbToHsl(...rgb)
267
+ setHue(h)
268
+ setSaturation(s)
269
+ setLightness(l)
270
+ updateColor(h, s, l)
271
+ }
272
+ } catch {
273
+ // Utilisateur a annulé
274
+ }
275
+ }
276
+
277
+ // Gestionnaire de changement d'input
278
+ const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
279
+ const val = e.target.value
280
+ setInputValue(val)
281
+ const rgb = parseColor(val)
282
+ if (rgb) {
283
+ const [h, s, l] = rgbToHsl(...rgb)
284
+ setHue(h)
285
+ setSaturation(s)
286
+ setLightness(l)
287
+ onChange?.(formatColor(...rgb, format))
288
+ }
289
+ }
290
+
291
+ const sizeClasses = {
292
+ sm: "h-7 w-7",
293
+ md: "h-9 w-9",
294
+ lg: "h-11 w-11",
295
+ }
296
+
297
+ const hasEyeDropper = showEyeDropper && typeof window !== "undefined" && "EyeDropper" in window
298
+
299
+ return (
300
+ <Popover open={open} onOpenChange={setOpen}>
301
+ <PopoverTrigger asChild>
302
+ <Button
303
+ ref={ref}
304
+ variant="outline"
305
+ disabled={disabled}
306
+ className={cn(
307
+ "p-0.5 rounded-md border",
308
+ sizeClasses[size],
309
+ className
310
+ )}
311
+ title={placeholder}
312
+ >
313
+ <div
314
+ className="w-full h-full rounded"
315
+ style={{ backgroundColor: value }}
316
+ />
317
+ </Button>
318
+ </PopoverTrigger>
319
+ <PopoverContent className="w-64 p-3" align="start">
320
+ <div className="space-y-3">
321
+ {/* Zone de saturation/luminosité */}
322
+ <div
323
+ ref={saturationRef}
324
+ className="relative w-full h-36 rounded cursor-crosshair"
325
+ style={{
326
+ background: `
327
+ linear-gradient(to top, #000, transparent),
328
+ linear-gradient(to right, #fff, transparent),
329
+ hsl(${hue}, 100%, 50%)
330
+ `,
331
+ }}
332
+ onMouseDown={handleSaturationMouseDown}
333
+ >
334
+ <div
335
+ className="absolute w-4 h-4 border-2 border-white rounded-full shadow -translate-x-1/2 -translate-y-1/2 pointer-events-none"
336
+ style={{
337
+ left: `${saturation}%`,
338
+ top: `${100 - lightness}%`,
339
+ backgroundColor: `hsl(${hue}, ${saturation}%, ${lightness}%)`,
340
+ }}
341
+ />
342
+ </div>
343
+
344
+ {/* Slider de teinte */}
345
+ <div
346
+ ref={hueRef}
347
+ className="relative w-full h-3 rounded cursor-pointer"
348
+ style={{
349
+ background: "linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00)",
350
+ }}
351
+ onMouseDown={handleHueMouseDown}
352
+ >
353
+ <div
354
+ className="absolute w-3 h-5 border-2 border-white rounded -translate-x-1/2 -top-1 shadow pointer-events-none"
355
+ style={{
356
+ left: `${(hue / 360) * 100}%`,
357
+ backgroundColor: `hsl(${hue}, 100%, 50%)`,
358
+ }}
359
+ />
360
+ </div>
361
+
362
+ {/* Input de couleur */}
363
+ <div className="flex items-center gap-2">
364
+ <div
365
+ className="w-8 h-8 rounded border flex-shrink-0"
366
+ style={{ backgroundColor: value }}
367
+ />
368
+ <Input
369
+ value={inputValue}
370
+ onChange={handleInputChange}
371
+ className="h-8 text-sm font-mono"
372
+ placeholder={format === "hex" ? "#000000" : format === "rgb" ? "rgb(0,0,0)" : "hsl(0,0%,0%)"}
373
+ />
374
+ {hasEyeDropper && (
375
+ <Button
376
+ variant="ghost"
377
+ size="icon"
378
+ className="h-8 w-8"
379
+ onClick={handleEyeDropper}
380
+ title="Pipette"
381
+ >
382
+ <Pipette className="h-4 w-4" />
383
+ </Button>
384
+ )}
385
+ </div>
386
+
387
+ {/* Presets */}
388
+ {showPresets && presets.length > 0 && (
389
+ <div>
390
+ <Label className="text-xs text-muted-foreground">Couleurs prédéfinies</Label>
391
+ <div className="grid grid-cols-10 gap-1 mt-1">
392
+ {presets.map((color) => (
393
+ <button
394
+ key={color}
395
+ className={cn(
396
+ "w-5 h-5 rounded border transition-transform hover:scale-110",
397
+ value.toLowerCase() === color.toLowerCase() && "ring-2 ring-primary ring-offset-1"
398
+ )}
399
+ style={{ backgroundColor: color }}
400
+ onClick={() => {
401
+ const rgb = parseColor(color)
402
+ if (rgb) {
403
+ const [h, s, l] = rgbToHsl(...rgb)
404
+ setHue(h)
405
+ setSaturation(s)
406
+ setLightness(l)
407
+ updateColor(h, s, l)
408
+ }
409
+ }}
410
+ />
411
+ ))}
412
+ </div>
413
+ </div>
414
+ )}
415
+ </div>
416
+ </PopoverContent>
417
+ </Popover>
418
+ )
419
+ }
420
+ )
421
+
422
+ WakaColorPicker.displayName = "WakaColorPicker"
423
+
424
+ /**
425
+ * Version intégrée avec react-hook-form
426
+ */
427
+ export interface WakaColorPickerFormProps extends WakaColorPickerProps {
428
+ name: string
429
+ error?: string
430
+ label?: string
431
+ }
432
+
433
+ export const WakaColorPickerForm = React.forwardRef<HTMLButtonElement, WakaColorPickerFormProps>(
434
+ ({ error, label, className, ...props }, ref) => {
435
+ return (
436
+ <div className={cn("space-y-1.5", className)}>
437
+ {label && <Label htmlFor={props.name}>{label}</Label>}
438
+ <WakaColorPicker ref={ref} {...props} />
439
+ {error && <p className="text-sm text-destructive">{error}</p>}
440
+ </div>
441
+ )
442
+ }
443
+ )
444
+
445
+ WakaColorPickerForm.displayName = "WakaColorPickerForm"
446
+
447
+ export default WakaColorPicker