siesa-ui-kit 1.0.2 → 1.0.4

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 (189) hide show
  1. package/README.md +115 -115
  2. package/bin/install.cjs +502 -502
  3. package/bin/prepare-publish.cjs +28 -28
  4. package/bin/restore-folders.cjs +28 -28
  5. package/claude/agents/siesa-ui-kit-specialist.md +2445 -0
  6. package/claude/prompts/component-template.md +121 -0
  7. package/claude/prompts/siesa-ui-kit.md +28 -0
  8. package/claude/settings.local.json +67 -2
  9. package/dist/components/Button/icons.d.ts +6 -5
  10. package/dist/components/Button/icons.d.ts.map +1 -1
  11. package/dist/components/DropdownItemCollapsible/DropdownItemCollapsible.d.ts.map +1 -1
  12. package/dist/components/DropdownItemCollapsible/DropdownItemCollapsible.types.d.ts +21 -0
  13. package/dist/components/DropdownItemCollapsible/DropdownItemCollapsible.types.d.ts.map +1 -1
  14. package/dist/components/NavigationRailCommercial/NavigationRailCommercial.d.ts +122 -0
  15. package/dist/components/NavigationRailCommercial/NavigationRailCommercial.d.ts.map +1 -0
  16. package/dist/components/NavigationRailCommercial/NavigationRailCommercial.types.d.ts +139 -0
  17. package/dist/components/NavigationRailCommercial/NavigationRailCommercial.types.d.ts.map +1 -0
  18. package/dist/components/NavigationRailCommercial/icons.d.ts +33 -0
  19. package/dist/components/NavigationRailCommercial/icons.d.ts.map +1 -0
  20. package/dist/components/NavigationRailCommercial/index.d.ts +4 -0
  21. package/dist/components/NavigationRailCommercial/index.d.ts.map +1 -0
  22. package/dist/components/NavigationRailItem/NavigationRailItem.d.ts.map +1 -1
  23. package/dist/components/NavigationRailItem/NavigationRailItem.types.d.ts +7 -0
  24. package/dist/components/NavigationRailItem/NavigationRailItem.types.d.ts.map +1 -1
  25. package/dist/components/NavigationRailTypes/NavigationRailTypes.d.ts.map +1 -1
  26. package/dist/components/NavigationRailTypes/NavigationRailTypes.types.d.ts +41 -0
  27. package/dist/components/NavigationRailTypes/NavigationRailTypes.types.d.ts.map +1 -1
  28. package/dist/components/NavigationRailTypes/icons.d.ts +15 -29
  29. package/dist/components/NavigationRailTypes/icons.d.ts.map +1 -1
  30. package/dist/components/Select/Select.d.ts.map +1 -1
  31. package/dist/components/Select/icons.d.ts +6 -2
  32. package/dist/components/Select/icons.d.ts.map +1 -1
  33. package/dist/index.d.ts +32 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/siesa-ui-kit.cjs +404 -190
  36. package/dist/siesa-ui-kit.cjs.map +1 -1
  37. package/dist/siesa-ui-kit.mjs +6590 -1506
  38. package/dist/siesa-ui-kit.mjs.map +1 -1
  39. package/dist/views/LayoutCommercial/LayoutCommercial.d.ts +48 -0
  40. package/dist/views/LayoutCommercial/LayoutCommercial.d.ts.map +1 -0
  41. package/dist/views/LayoutCommercial/LayoutCommercial.types.d.ts +49 -0
  42. package/dist/views/LayoutCommercial/LayoutCommercial.types.d.ts.map +1 -0
  43. package/dist/views/LayoutCommercial/index.d.ts +3 -0
  44. package/dist/views/LayoutCommercial/index.d.ts.map +1 -0
  45. package/docs/icons.md +12 -31
  46. package/package.json +111 -110
  47. package/src/components/Avatar/Avatar.stories.tsx +494 -494
  48. package/src/components/Button/Button.stories.tsx +950 -950
  49. package/src/components/Button/Button.tsx +337 -337
  50. package/src/components/Button/Button.types.ts +180 -180
  51. package/src/components/Button/icons.tsx +23 -62
  52. package/src/components/DescriptionList/DescriptionList.stories.tsx +250 -250
  53. package/src/components/Divider/Divider.stories.tsx +263 -263
  54. package/src/components/DropdownItemCollapsible/DropdownItemCollapsible.stories.tsx +317 -317
  55. package/src/components/DropdownItemCollapsible/DropdownItemCollapsible.tsx +307 -287
  56. package/src/components/DropdownItemCollapsible/DropdownItemCollapsible.types.ts +136 -111
  57. package/src/components/DropdownItemCollapsible/README.md +264 -264
  58. package/src/components/DropdownItemCollapsible/icons.tsx +57 -57
  59. package/src/components/DropdownItemCollapsible/index.ts +12 -12
  60. package/src/components/DropdownItemHeading/DropdownItemHeading.stories.tsx +386 -386
  61. package/src/components/DropdownItemHeading/DropdownItemHeading.tsx +216 -216
  62. package/src/components/DropdownItemHeading/DropdownItemHeading.types.ts +93 -93
  63. package/src/components/DropdownItemHeading/README.md +573 -573
  64. package/src/components/DropdownItemHeading/icons.tsx +125 -125
  65. package/src/components/DropdownItemHeading/index.ts +3 -3
  66. package/src/components/Input/Input.stories.tsx +583 -583
  67. package/src/components/LoginView/LoginView.stories.tsx +148 -148
  68. package/src/components/LoginView/LoginView.tsx +426 -426
  69. package/src/components/LoginView/LoginView.types.ts +52 -52
  70. package/src/components/LoginView/README.md +396 -396
  71. package/src/components/LoginView/icons.tsx +85 -85
  72. package/src/components/LoginView/index.ts +3 -3
  73. package/src/components/Navbar/Navbar.stories.tsx +810 -810
  74. package/src/components/Navbar/Navbar.tsx +755 -755
  75. package/src/components/Navbar/Navbar.types.ts +219 -219
  76. package/src/components/Navbar/README.md +279 -279
  77. package/src/components/Navbar/index.ts +8 -8
  78. package/src/components/NavigationRailCommercial/NavigationRailCommercial.stories.tsx +464 -0
  79. package/src/components/NavigationRailCommercial/NavigationRailCommercial.tsx +301 -0
  80. package/src/components/NavigationRailCommercial/NavigationRailCommercial.types.ts +162 -0
  81. package/src/components/NavigationRailCommercial/README.md +251 -0
  82. package/src/components/NavigationRailCommercial/icons.tsx +54 -0
  83. package/src/components/NavigationRailCommercial/index.ts +6 -0
  84. package/src/components/NavigationRailItem/NavigationRailItem.stories.tsx +667 -667
  85. package/src/components/NavigationRailItem/NavigationRailItem.tsx +314 -313
  86. package/src/components/NavigationRailItem/NavigationRailItem.types.ts +175 -167
  87. package/src/components/NavigationRailItem/README.md +476 -476
  88. package/src/components/NavigationRailItem/index.ts +2 -2
  89. package/src/components/NavigationRailPanel/NavigationRailPanel.stories.tsx +462 -462
  90. package/src/components/NavigationRailPanel/NavigationRailPanel.tsx +332 -332
  91. package/src/components/NavigationRailPanel/NavigationRailPanel.types.ts +178 -178
  92. package/src/components/NavigationRailPanel/README.md +461 -461
  93. package/src/components/NavigationRailPanel/index.ts +6 -6
  94. package/src/components/NavigationRailTypes/NavigationRailTypes.stories.tsx +682 -528
  95. package/src/components/NavigationRailTypes/NavigationRailTypes.tsx +363 -378
  96. package/src/components/NavigationRailTypes/NavigationRailTypes.types.ts +178 -130
  97. package/src/components/NavigationRailTypes/README.md +573 -573
  98. package/src/components/NavigationRailTypes/icons.tsx +76 -141
  99. package/src/components/NavigationRailTypes/index.ts +7 -7
  100. package/src/components/Notification/Notification.stories.tsx +513 -513
  101. package/src/components/Notification/Notification.tsx +145 -145
  102. package/src/components/Notification/Notification.types.ts +142 -142
  103. package/src/components/Notification/README.md +409 -409
  104. package/src/components/POSConvention/POSConvention.stories.tsx +235 -235
  105. package/src/components/POSConvention/POSConvention.tsx +129 -129
  106. package/src/components/POSConvention/POSConvention.types.ts +38 -38
  107. package/src/components/POSConvention/README.md +123 -123
  108. package/src/components/POSConvention/icons.tsx +45 -45
  109. package/src/components/POSConvention/index.ts +3 -3
  110. package/src/components/POSLocationButton/POSLocationButton.stories.tsx +531 -531
  111. package/src/components/POSLocationButton/POSLocationButton.tsx +247 -247
  112. package/src/components/POSLocationButton/POSLocationButton.types.ts +87 -87
  113. package/src/components/POSLocationButton/README.md +253 -253
  114. package/src/components/POSLocationButton/icons.tsx +120 -120
  115. package/src/components/POSLocationButton/index.ts +14 -14
  116. package/src/components/POSNumberButton/POSNumberButton.stories.tsx +415 -415
  117. package/src/components/POSNumberButton/POSNumberButton.tsx +179 -179
  118. package/src/components/POSNumberButton/POSNumberButton.types.ts +51 -51
  119. package/src/components/POSNumberButton/README.md +321 -321
  120. package/src/components/POSNumberButton/index.ts +3 -3
  121. package/src/components/POSProductButton/POSProductButton.stories.tsx +318 -318
  122. package/src/components/POSProductCard/POSProductCard.stories.tsx +642 -642
  123. package/src/components/POSProductCard/POSProductCard.tsx +208 -208
  124. package/src/components/POSProductCard/POSProductCard.types.ts +76 -76
  125. package/src/components/POSProductCard/README.md +179 -179
  126. package/src/components/POSProductCard/icons.tsx +26 -26
  127. package/src/components/POSProductCard/index.ts +2 -2
  128. package/src/components/POSProductSidebarItems/POSProductSidebarItems.stories.tsx +753 -753
  129. package/src/components/POSProductSidebarItems/POSProductSidebarItems.tsx +332 -332
  130. package/src/components/POSProductSidebarItems/POSProductSidebarItems.types.ts +119 -119
  131. package/src/components/POSProductSidebarItems/README.md +198 -198
  132. package/src/components/POSProductSidebarItems/icons.tsx +21 -21
  133. package/src/components/POSProductSidebarItems/index.ts +3 -3
  134. package/src/components/POSTable/POSTable.stories.tsx +737 -737
  135. package/src/components/POSTable/POSTable.tsx +401 -401
  136. package/src/components/POSTable/README.md +286 -286
  137. package/src/components/Quantity/Quantity.stories.tsx +457 -457
  138. package/src/components/Radio/Radio.stories.tsx +523 -523
  139. package/src/components/Radio/Radio.tsx +1 -1
  140. package/src/components/Select/Select.stories.tsx +32 -0
  141. package/src/components/Select/Select.tsx +457 -454
  142. package/src/components/Select/icons.tsx +16 -41
  143. package/src/components/SignUpView/SignUpView.stories.tsx +129 -129
  144. package/src/components/SignUpView/SignUpView.tsx +503 -503
  145. package/src/components/SignUpView/SignUpView.types.ts +58 -58
  146. package/src/components/SignUpView/icons.tsx +71 -71
  147. package/src/components/SignUpView/index.ts +3 -3
  148. package/src/components/Switch/README.md +112 -112
  149. package/src/components/Switch/Switch.stories.tsx +550 -550
  150. package/src/components/Switch/Switch.tsx +246 -246
  151. package/src/components/Switch/Switch.types.ts +67 -67
  152. package/src/components/Table/Table.stories.tsx +805 -805
  153. package/src/components/Tabs/README.md +201 -201
  154. package/src/components/Tabs/Tabs.stories.tsx +580 -580
  155. package/src/components/Tabs/Tabs.tsx +356 -356
  156. package/src/components/Tabs/Tabs.types.ts +127 -127
  157. package/src/components/Tabs/icons.tsx +129 -129
  158. package/src/components/Tabs/index.ts +11 -11
  159. package/src/components/Textarea/Textarea.stories.tsx +535 -535
  160. package/src/index.ts +133 -102
  161. package/src/views/LayoutCommercial/LayoutCommercial.stories.tsx +374 -0
  162. package/src/views/LayoutCommercial/LayoutCommercial.tsx +125 -0
  163. package/src/views/LayoutCommercial/LayoutCommercial.types.ts +54 -0
  164. package/src/views/LayoutCommercial/README.md +286 -0
  165. package/src/views/LayoutCommercial/index.ts +2 -0
  166. package/src/views/ListView/ListView.stories.tsx +329 -329
  167. package/src/views/ListView/ListView.tsx +570 -570
  168. package/src/views/ListView/ListView.types.ts +211 -211
  169. package/src/views/ListView/icons.tsx +282 -282
  170. package/src/views/ListView/index.ts +11 -11
  171. package/src/views/LoginView/LoginView.tsx +426 -426
  172. package/src/views/ProductsView/ProductsView.stories.tsx +344 -344
  173. package/src/views/ProductsView/ProductsView.tsx +480 -480
  174. package/src/views/ProductsView/ProductsView.types.ts +238 -238
  175. package/src/views/ProductsView/README.md +312 -312
  176. package/src/views/ProductsView/icons.tsx +38 -38
  177. package/src/views/ProductsView/index.ts +8 -8
  178. package/src/views/RecoverPasswordView/RecoverPasswordView.tsx +376 -376
  179. package/src/views/SignUpView/SignUpView.tsx +503 -503
  180. package/src/views/TableLayoutView/README.md +268 -268
  181. package/src/views/TableLayoutView/TableLayoutView.stories.tsx +235 -235
  182. package/src/views/TableLayoutView/TableLayoutView.tsx +461 -461
  183. package/src/views/TableLayoutView/TableLayoutView.types.ts +209 -209
  184. package/src/views/TableLayoutView/icons.tsx +113 -113
  185. package/src/views/TableLayoutView/index.ts +6 -6
  186. package/storybook/main.ts +19 -19
  187. package/storybook/preview.tsx +84 -84
  188. package/storybook/vitest.setup.ts +6 -6
  189. package/tailwind.config.js +128 -128
@@ -1,454 +1,457 @@
1
- import React, { useState, useRef, useEffect } from 'react';
2
- import type { SelectProps, SelectOption } from './Select.types';
3
- import { ChevronUpDownIcon, CheckIcon } from './icons';
4
-
5
- /**
6
- * Select - Componente de selección (dropdown) del sistema de diseño Siesa
7
- *
8
- * Componente Select personalizado con menú desplegable para seleccionar opciones
9
- * de una lista. Incluye navegación por teclado, click outside y dark mode completo.
10
- *
11
- * Mejores prácticas implementadas:
12
- * - Orden de modificadores: {responsive}:{dark}:{state}:{utility}
13
- * - Dark mode con estrategia 'class' (darkMode: 'class')
14
- * - Tokens de color consistentes con la documentación
15
- * - Type safety con TypeScript estricto
16
- * - Accesibilidad con ARIA labels y keyboard navigation
17
- * - Click outside para cerrar el menú
18
- * - Soporte de teclado (Enter, Escape, Arrow Up/Down)
19
- *
20
- * @see docs/colors.md - Sistema de colores
21
- * @see docs/typography.md - Sistema tipográfico
22
- * @see docs/spacing.md - Sistema de espaciado
23
- *
24
- * @example
25
- * ```tsx
26
- * <Select
27
- * options={[
28
- * { value: '1', label: 'Option 1' },
29
- * { value: '2', label: 'Option 2' },
30
- * ]}
31
- * value={selectedValue}
32
- * onChange={setSelectedValue}
33
- * placeholder="Select an option"
34
- * label="Choose one"
35
- * />
36
- * ```
37
- */
38
- export const Select: React.FC<SelectProps> = ({
39
- options = [],
40
- value,
41
- defaultValue,
42
- placeholder = 'Seleccionar...',
43
- disabled = false,
44
- error = false,
45
- label,
46
- description,
47
- showLabel = true,
48
- showDescription = true,
49
- menuHeader,
50
- onChange,
51
- className = '',
52
- triggerClassName = '',
53
- menuClassName = '',
54
- ariaLabel,
55
- id,
56
- name,
57
- required = false,
58
- menuPosition = 'bottom',
59
- fullWidth = false,
60
- }) => {
61
- // ===== ESTADO Y REFS =====
62
- const [isOpen, setIsOpen] = useState(false);
63
- const [selectedValue, setSelectedValue] = useState<string | number | undefined>(
64
- value !== undefined ? value : defaultValue
65
- );
66
- const [focusedIndex, setFocusedIndex] = useState(-1);
67
-
68
- const containerRef = useRef<HTMLDivElement>(null);
69
- const triggerRef = useRef<HTMLButtonElement>(null);
70
- const menuRef = useRef<HTMLDivElement>(null);
71
-
72
- // ===== SINCRONIZAR VALOR CONTROLADO =====
73
- useEffect(() => {
74
- if (value !== undefined) {
75
- setSelectedValue(value);
76
- }
77
- }, [value]);
78
-
79
- // ===== CERRAR AL HACER CLICK FUERA =====
80
- useEffect(() => {
81
- const handleClickOutside = (event: MouseEvent) => {
82
- if (containerRef.current && !containerRef.current.contains(event.target as Node)) {
83
- setIsOpen(false);
84
- }
85
- };
86
-
87
- if (isOpen) {
88
- document.addEventListener('mousedown', handleClickOutside);
89
- return () => {
90
- document.removeEventListener('mousedown', handleClickOutside);
91
- };
92
- }
93
- }, [isOpen]);
94
-
95
- // ===== KEYBOARD NAVIGATION =====
96
- useEffect(() => {
97
- const handleKeyDown = (event: KeyboardEvent) => {
98
- if (!isOpen) return;
99
-
100
- switch (event.key) {
101
- case 'Escape':
102
- setIsOpen(false);
103
- triggerRef.current?.focus();
104
- break;
105
- case 'ArrowDown':
106
- event.preventDefault();
107
- setFocusedIndex((prev) => (prev < options.length - 1 ? prev + 1 : 0));
108
- break;
109
- case 'ArrowUp':
110
- event.preventDefault();
111
- setFocusedIndex((prev) => (prev > 0 ? prev - 1 : options.length - 1));
112
- break;
113
- case 'Enter':
114
- event.preventDefault();
115
- if (focusedIndex >= 0 && focusedIndex < options.length) {
116
- handleSelect(options[focusedIndex]);
117
- }
118
- break;
119
- }
120
- };
121
-
122
- if (isOpen) {
123
- document.addEventListener('keydown', handleKeyDown);
124
- return () => {
125
- document.removeEventListener('keydown', handleKeyDown);
126
- };
127
- }
128
- }, [isOpen, focusedIndex, options]);
129
-
130
- // ===== HELPERS =====
131
- const selectedOption = options.find((opt) => opt.value === selectedValue);
132
-
133
- const toggleMenu = () => {
134
- if (!disabled) {
135
- setIsOpen(!isOpen);
136
- setFocusedIndex(-1);
137
- }
138
- };
139
-
140
- const handleSelect = (option: SelectOption) => {
141
- if (option.disabled) return;
142
-
143
- setSelectedValue(option.value);
144
- setIsOpen(false);
145
- onChange?.(option.value);
146
-
147
- setTimeout(() => {
148
- triggerRef.current?.focus();
149
- }, 0);
150
- };
151
-
152
- // ===== CLASES BASE DEL TRIGGER =====
153
- // Usando el sistema tipográfico Paragraph Regular (14px = text-sm)
154
- // Border radius rounded-lg (8px) consistente con especificaciones
155
- // Gap de 12px (gap-3) entre texto e icono según Figma
156
- const baseTriggerClasses = `
157
- inline-flex
158
- items-center
159
- justify-between
160
- gap-3
161
- w-full
162
- px-3
163
- py-2
164
- text-sm
165
- font-normal
166
- leading-5
167
- rounded-lg
168
- border
169
- transition-all
170
- duration-150
171
- `;
172
-
173
- // ===== CLASES DE WIDTH =====
174
- const widthClasses = fullWidth ? 'w-full' : 'min-w-[200px]';
175
-
176
- // ===== CLASES PARA ESTADOS DEL TRIGGER =====
177
- // Orden de modificadores: {responsive}:{dark}:{state}:{utility}
178
- const triggerStateClasses = error
179
- ? `
180
- border-error-border
181
- bg-error-bg
182
- text-content-primary
183
- dark:border-error-border
184
- dark:bg-error-bg
185
- dark:text-dark-content-primary
186
- `
187
- : `
188
- bg-bg-primary
189
- border-border-primary
190
- text-content-primary
191
- dark:bg-dark-bg-primary
192
- dark:border-dark-border-primary
193
- dark:text-dark-content-primary
194
- `;
195
-
196
- // ===== CLASES PARA HOVER DEL TRIGGER =====
197
- // Hover overlay rgba(0,0,0,0.024) según Figma
198
- const triggerHoverClasses =
199
- !disabled && !error
200
- ? `
201
- hover:bg-[rgba(255,255,255,1)]
202
- hover:bg-[linear-gradient(90deg,rgba(0,0,0,0.024)_0%,rgba(0,0,0,0.024)_100%)]
203
- dark:hover:bg-[rgba(17,45,87,1)]
204
- dark:hover:bg-[linear-gradient(90deg,rgba(255,255,255,0.1)_0%,rgba(255,255,255,0.1)_100%)]
205
- `
206
- : '';
207
-
208
- // ===== CLASES PARA FOCUS DEL TRIGGER =====
209
- // Focus rings adaptativos siguiendo el patrón de otros componentes
210
- const triggerFocusClasses = !disabled
211
- ? `
212
- focus:outline-none
213
- focus:ring-2
214
- focus:ring-primary-custom-400
215
- focus:ring-offset-2
216
- dark:focus:ring-dark-border-custom
217
- dark:focus:ring-offset-dark-bg-primary
218
- `
219
- : '';
220
-
221
- // ===== CLASES PARA DISABLED DEL TRIGGER =====
222
- const triggerDisabledClasses = disabled
223
- ? `
224
- opacity-50
225
- cursor-not-allowed
226
- `
227
- : '';
228
-
229
- // ===== COMBINAR CLASES DEL TRIGGER =====
230
- const finalTriggerClasses = [
231
- baseTriggerClasses,
232
- widthClasses,
233
- triggerStateClasses,
234
- triggerHoverClasses,
235
- triggerFocusClasses,
236
- triggerDisabledClasses,
237
- triggerClassName,
238
- ]
239
- .join(' ')
240
- .replace(/\s+/g, ' ')
241
- .trim();
242
-
243
- // ===== CLASES BASE DEL MENU =====
244
- // Según Figma: altura fija 160px (h-40), sin borde visible (border-0),
245
- // spacing de 4px desde trigger (mt-1), sin shadow prominente
246
- const baseMenuClasses = `
247
- absolute
248
- z-50
249
- w-full
250
- min-w-[200px]
251
- max-h-40
252
- overflow-y-auto
253
- p-1
254
- rounded-md
255
- border-0
256
- transition-all
257
- duration-150
258
- `;
259
-
260
- // ===== CLASES DE POSICIÓN DEL MENU =====
261
- // Figma muestra 4px de separación, usando mt-1 en lugar de mt-2
262
- const menuPositionClasses = menuPosition === 'top' ? 'bottom-full mb-1' : 'top-full mt-1';
263
-
264
- // ===== CLASES DE COLOR DEL MENU =====
265
- // Background secundario según Figma, sin borde prominente
266
- const menuColorClasses = `
267
- bg-background-secondary
268
- dark:bg-dark-bg-primary
269
- `;
270
-
271
- // ===== CLASES DE VISIBILIDAD DEL MENU =====
272
- const menuVisibilityClasses = isOpen ? 'opacity-100 visible' : 'opacity-0 invisible';
273
-
274
- // ===== COMBINAR CLASES DEL MENU =====
275
- const finalMenuClasses = [
276
- baseMenuClasses,
277
- menuPositionClasses,
278
- menuColorClasses,
279
- menuVisibilityClasses,
280
- menuClassName,
281
- ]
282
- .join(' ')
283
- .replace(/\s+/g, ' ')
284
- .trim();
285
-
286
- // ===== CLASES BASE DEL MENU ITEM =====
287
- // CRÍTICO: Figma especifica text-[10px] leading-[12px] (Label XXSmall)
288
- // NO usar text-xs que es 12px - debe ser exactamente 10px según diseño
289
- const baseMenuItemClasses = `
290
- flex
291
- items-center
292
- cursor-pointer
293
- rounded-md
294
- transition-all
295
- duration-150
296
- pl-2
297
- pr-2.5
298
- py-0.5
299
- gap-0.5
300
- text-[10px]
301
- leading-[12px]
302
- font-bold
303
- `;
304
-
305
- // ===== FUNCIÓN PARA OBTENER CLASES DE MENU ITEM =====
306
- const getMenuItemClasses = (option: SelectOption, index: number) => {
307
- const isSelected = option.value === selectedValue;
308
- const isFocused = index === focusedIndex;
309
-
310
- // Estados de color
311
- const colorClasses =
312
- isSelected && !isFocused
313
- ? 'text-content-primary dark:text-dark-content-primary'
314
- : isFocused || (isSelected && isFocused)
315
- ? 'bg-primary-custom-600 text-primary-inverse-content dark:bg-primary-custom-600 dark:text-primary-inverse-content'
316
- : 'text-content-primary dark:text-dark-content-primary';
317
-
318
- // Hover
319
- const hoverClasses = !option.disabled
320
- ? 'hover:bg-primary-custom-600 hover:text-primary-inverse-content dark:hover:bg-primary-custom-600 dark:hover:text-primary-inverse-content'
321
- : '';
322
-
323
- // Disabled
324
- const disabledClasses = option.disabled ? 'opacity-50 cursor-not-allowed' : '';
325
-
326
- return [baseMenuItemClasses, colorClasses, hoverClasses, disabledClasses]
327
- .join(' ')
328
- .replace(/\s+/g, ' ')
329
- .trim();
330
- };
331
-
332
- // ===== CLASES DEL ICONO DEL TRIGGER =====
333
- const iconClasses = [
334
- 'flex-shrink-0',
335
- 'transition-transform',
336
- 'duration-150',
337
- isOpen && 'rotate-180',
338
- disabled ? 'text-content-tertiary dark:text-content-tertiary' : 'text-content-secondary dark:text-content-secondary',
339
- ]
340
- .filter(Boolean)
341
- .join(' ')
342
- .replace(/\s+/g, ' ')
343
- .trim();
344
-
345
- // ===== CLASES DEL CHECK ICON =====
346
- const checkIconClasses = 'flex-shrink-0 w-4 h-4';
347
-
348
- // ===== RENDERIZAR COMPONENTE =====
349
- return (
350
- <div className={`relative ${fullWidth ? 'w-full' : ''} ${className}`} ref={containerRef}>
351
- {/* Label and Description - Según Figma, van ANTES del trigger con gap-1 (4px) */}
352
- {(showLabel && label) || (showDescription && description) ? (
353
- <div className="flex flex-col gap-1 mb-1 w-full">
354
- {/* Label - Label Small (14px bold) */}
355
- {showLabel && label && (
356
- <label
357
- htmlFor={id}
358
- className="text-sm font-bold leading-5 text-content-primary dark:text-dark-content-primary"
359
- >
360
- {label}
361
- {required && <span className="ml-1 text-error-content">*</span>}
362
- </label>
363
- )}
364
-
365
- {/* Description - Paragraph Small (14px regular) */}
366
- {showDescription && description && (
367
- <p className="text-sm font-normal leading-5 text-content-tertiary dark:text-content-tertiary">
368
- {description}
369
- </p>
370
- )}
371
- </div>
372
- ) : null}
373
-
374
- {/* Trigger Button */}
375
- <button
376
- ref={triggerRef}
377
- type="button"
378
- className={finalTriggerClasses}
379
- onClick={toggleMenu}
380
- disabled={disabled}
381
- aria-label={ariaLabel || label}
382
- aria-haspopup="listbox"
383
- aria-expanded={isOpen}
384
- id={id}
385
- >
386
- {/* Selected value or placeholder */}
387
- <span
388
- className={
389
- selectedOption ? '' : 'text-content-secondary dark:text-content-secondary'
390
- }
391
- >
392
- {selectedOption ? selectedOption.label : placeholder}
393
- </span>
394
-
395
- {/* Chevron icon */}
396
- <ChevronUpDownIcon className={iconClasses} />
397
- </button>
398
-
399
- {/* Hidden input for forms */}
400
- {name && (
401
- <input
402
- type="hidden"
403
- name={name}
404
- value={selectedValue !== undefined ? String(selectedValue) : ''}
405
- />
406
- )}
407
-
408
- {/* Menu */}
409
- {isOpen && (
410
- <div ref={menuRef} className={finalMenuClasses} role="listbox">
411
- {/* Menu Header - Opcional según Figma */}
412
- {menuHeader && (
413
- <div className="flex items-center gap-0.5 px-6 py-0.5 rounded-[5px]">
414
- <span className="text-[10px] font-bold leading-[12px] text-content-tertiary dark:text-content-tertiary">
415
- {menuHeader}
416
- </span>
417
- </div>
418
- )}
419
-
420
- {/* Empty state */}
421
- {options.length === 0 && (
422
- <div className="px-2 py-1.5 text-[10px] leading-[12px] text-content-secondary dark:text-content-secondary">
423
- No hay opciones disponibles
424
- </div>
425
- )}
426
-
427
- {/* Options */}
428
- {options.map((option, index) => (
429
- <div
430
- key={option.value}
431
- className={getMenuItemClasses(option, index)}
432
- onClick={() => handleSelect(option)}
433
- onMouseEnter={() => setFocusedIndex(index)}
434
- role="option"
435
- aria-selected={option.value === selectedValue}
436
- aria-disabled={option.disabled}
437
- >
438
- {/* Check icon for selected item */}
439
- <div className="w-4 flex items-center justify-center">
440
- {option.value === selectedValue && <CheckIcon className={checkIconClasses} />}
441
- </div>
442
-
443
- {/* Custom icon if provided */}
444
- {option.icon && <span className="flex-shrink-0 w-4 h-4">{option.icon}</span>}
445
-
446
- {/* Label */}
447
- <span className="flex-1 text-left">{option.label}</span>
448
- </div>
449
- ))}
450
- </div>
451
- )}
452
- </div>
453
- );
454
- };
1
+ import React, { useState, useRef, useEffect } from 'react';
2
+ import type { SelectProps, SelectOption } from './Select.types';
3
+ import { ChevronUpDownIcon, CheckIcon } from './icons';
4
+
5
+ /**
6
+ * Select - Componente de selección (dropdown) del sistema de diseño Siesa
7
+ *
8
+ * Componente Select personalizado con menú desplegable para seleccionar opciones
9
+ * de una lista. Incluye navegación por teclado, click outside y dark mode completo.
10
+ *
11
+ * Mejores prácticas implementadas:
12
+ * - Orden de modificadores: {responsive}:{dark}:{state}:{utility}
13
+ * - Dark mode con estrategia 'class' (darkMode: 'class')
14
+ * - Tokens de color consistentes con la documentación
15
+ * - Type safety con TypeScript estricto
16
+ * - Accesibilidad con ARIA labels y keyboard navigation
17
+ * - Click outside para cerrar el menú
18
+ * - Soporte de teclado (Enter, Escape, Arrow Up/Down)
19
+ *
20
+ * @see docs/colors.md - Sistema de colores
21
+ * @see docs/typography.md - Sistema tipográfico
22
+ * @see docs/spacing.md - Sistema de espaciado
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * <Select
27
+ * options={[
28
+ * { value: '1', label: 'Option 1' },
29
+ * { value: '2', label: 'Option 2' },
30
+ * ]}
31
+ * value={selectedValue}
32
+ * onChange={setSelectedValue}
33
+ * placeholder="Select an option"
34
+ * label="Choose one"
35
+ * />
36
+ * ```
37
+ */
38
+ export const Select: React.FC<SelectProps> = ({
39
+ options = [],
40
+ value,
41
+ defaultValue,
42
+ placeholder = 'Seleccionar...',
43
+ disabled = false,
44
+ error = false,
45
+ label,
46
+ description,
47
+ showLabel = true,
48
+ showDescription = true,
49
+ menuHeader,
50
+ onChange,
51
+ className = '',
52
+ triggerClassName = '',
53
+ menuClassName = '',
54
+ ariaLabel,
55
+ id,
56
+ name,
57
+ required = false,
58
+ menuPosition = 'bottom',
59
+ fullWidth = false,
60
+ }) => {
61
+ // ===== ESTADO Y REFS =====
62
+ const [isOpen, setIsOpen] = useState(false);
63
+ const [selectedValue, setSelectedValue] = useState<string | number | undefined>(
64
+ value !== undefined ? value : defaultValue
65
+ );
66
+ const [focusedIndex, setFocusedIndex] = useState(-1);
67
+
68
+ const containerRef = useRef<HTMLDivElement>(null);
69
+ const triggerRef = useRef<HTMLButtonElement>(null);
70
+ const menuRef = useRef<HTMLDivElement>(null);
71
+
72
+ // ===== SINCRONIZAR VALOR CONTROLADO =====
73
+ useEffect(() => {
74
+ if (value !== undefined) {
75
+ setSelectedValue(value);
76
+ }
77
+ }, [value]);
78
+
79
+ // ===== CERRAR AL HACER CLICK FUERA =====
80
+ useEffect(() => {
81
+ const handleClickOutside = (event: MouseEvent) => {
82
+ if (containerRef.current && !containerRef.current.contains(event.target as Node)) {
83
+ setIsOpen(false);
84
+ }
85
+ };
86
+
87
+ if (isOpen) {
88
+ document.addEventListener('mousedown', handleClickOutside);
89
+ return () => {
90
+ document.removeEventListener('mousedown', handleClickOutside);
91
+ };
92
+ }
93
+ }, [isOpen]);
94
+
95
+ // ===== KEYBOARD NAVIGATION =====
96
+ useEffect(() => {
97
+ const handleKeyDown = (event: KeyboardEvent) => {
98
+ if (!isOpen) return;
99
+
100
+ switch (event.key) {
101
+ case 'Escape':
102
+ setIsOpen(false);
103
+ triggerRef.current?.focus();
104
+ break;
105
+ case 'ArrowDown':
106
+ event.preventDefault();
107
+ setFocusedIndex((prev) => (prev < options.length - 1 ? prev + 1 : 0));
108
+ break;
109
+ case 'ArrowUp':
110
+ event.preventDefault();
111
+ setFocusedIndex((prev) => (prev > 0 ? prev - 1 : options.length - 1));
112
+ break;
113
+ case 'Enter':
114
+ event.preventDefault();
115
+ if (focusedIndex >= 0 && focusedIndex < options.length) {
116
+ handleSelect(options[focusedIndex]);
117
+ }
118
+ break;
119
+ }
120
+ };
121
+
122
+ if (isOpen) {
123
+ document.addEventListener('keydown', handleKeyDown);
124
+ return () => {
125
+ document.removeEventListener('keydown', handleKeyDown);
126
+ };
127
+ }
128
+ }, [isOpen, focusedIndex, options]);
129
+
130
+ // ===== HELPERS =====
131
+ const selectedOption = options.find((opt) => opt.value === selectedValue);
132
+
133
+ const toggleMenu = () => {
134
+ if (!disabled) {
135
+ setIsOpen(!isOpen);
136
+ setFocusedIndex(-1);
137
+ }
138
+ };
139
+
140
+ const handleSelect = (option: SelectOption) => {
141
+ if (option.disabled) return;
142
+
143
+ setSelectedValue(option.value);
144
+ setIsOpen(false);
145
+ onChange?.(option.value);
146
+
147
+ setTimeout(() => {
148
+ triggerRef.current?.focus();
149
+ }, 0);
150
+ };
151
+
152
+ // ===== CLASES BASE DEL TRIGGER =====
153
+ // Usando el sistema tipográfico Paragraph Regular (14px = text-sm)
154
+ // Border radius rounded-lg (8px) consistente con especificaciones
155
+ // Gap de 12px (gap-3) entre texto e icono según Figma
156
+ const baseTriggerClasses = `
157
+ inline-flex
158
+ items-center
159
+ justify-between
160
+ gap-3
161
+ w-full
162
+ px-3
163
+ py-2
164
+ text-sm
165
+ font-normal
166
+ leading-5
167
+ rounded-lg
168
+ border
169
+ transition-all
170
+ duration-150
171
+ `;
172
+
173
+ // ===== CLASES DE WIDTH =====
174
+ const widthClasses = fullWidth ? 'w-full' : 'min-w-[200px]';
175
+
176
+ // ===== CLASES PARA ESTADOS DEL TRIGGER =====
177
+ // Orden de modificadores: {responsive}:{dark}:{state}:{utility}
178
+ const triggerStateClasses = error
179
+ ? `
180
+ border-error-border
181
+ bg-error-bg
182
+ text-content-primary
183
+ dark:border-error-border
184
+ dark:bg-error-bg
185
+ dark:text-dark-content-primary
186
+ `
187
+ : `
188
+ bg-bg-primary
189
+ border-border-primary
190
+ text-content-primary
191
+ dark:bg-dark-bg-primary
192
+ dark:border-dark-border-primary
193
+ dark:text-dark-content-primary
194
+ `;
195
+
196
+ // ===== CLASES PARA HOVER DEL TRIGGER =====
197
+ // Hover: border más claro según Figma (#f9f9f9)
198
+ const triggerHoverClasses =
199
+ !disabled && !error
200
+ ? `
201
+ hover:border-[#f9f9f9]
202
+ dark:hover:border-[#3a3a3f]
203
+ `
204
+ : '';
205
+
206
+ // ===== CLASES PARA FOCUS DEL TRIGGER =====
207
+ // Focus: border-2 con color específico #329cff según Figma
208
+ const triggerFocusClasses = !disabled
209
+ ? `
210
+ focus:outline-none
211
+ focus-within:border-2
212
+ focus-within:border-[#329cff]
213
+ dark:focus-within:border-[#329cff]
214
+ `
215
+ : '';
216
+
217
+ // ===== CLASES PARA DISABLED DEL TRIGGER =====
218
+ const triggerDisabledClasses = disabled
219
+ ? `
220
+ opacity-50
221
+ cursor-not-allowed
222
+ `
223
+ : '';
224
+
225
+ // ===== COMBINAR CLASES DEL TRIGGER =====
226
+ const finalTriggerClasses = [
227
+ baseTriggerClasses,
228
+ widthClasses,
229
+ triggerStateClasses,
230
+ triggerHoverClasses,
231
+ triggerFocusClasses,
232
+ triggerDisabledClasses,
233
+ triggerClassName,
234
+ ]
235
+ .join(' ')
236
+ .replace(/\s+/g, ' ')
237
+ .trim();
238
+
239
+ // ===== CLASES BASE DEL MENU =====
240
+ // Según Figma: altura fija 160px (h-40), border secundario,
241
+ // spacing de 4px desde trigger (mt-1), shadow-lg para elevación
242
+ const baseMenuClasses = `
243
+ absolute
244
+ z-50
245
+ w-full
246
+ min-w-[200px]
247
+ max-h-40
248
+ overflow-y-auto
249
+ p-1
250
+ rounded-md
251
+ border
252
+ shadow-lg
253
+ transition-all
254
+ duration-150
255
+ `;
256
+
257
+ // ===== CLASES DE POSICIÓN DEL MENU =====
258
+ // Figma muestra 4px de separación, usando mt-1 en lugar de mt-2
259
+ const menuPositionClasses = menuPosition === 'top' ? 'bottom-full mb-1' : 'top-full mt-1';
260
+
261
+ // ===== CLASES DE COLOR DEL MENU =====
262
+ // Background secundario según Figma con border secundario
263
+ const menuColorClasses = `
264
+ bg-background-secondary
265
+ border-border-secondary
266
+ dark:bg-dark-bg-primary
267
+ dark:border-dark-border-primary
268
+ `;
269
+
270
+ // ===== CLASES DE VISIBILIDAD DEL MENU =====
271
+ const menuVisibilityClasses = isOpen ? 'opacity-100 visible' : 'opacity-0 invisible';
272
+
273
+ // ===== COMBINAR CLASES DEL MENU =====
274
+ const finalMenuClasses = [
275
+ baseMenuClasses,
276
+ menuPositionClasses,
277
+ menuColorClasses,
278
+ menuVisibilityClasses,
279
+ menuClassName,
280
+ ]
281
+ .join(' ')
282
+ .replace(/\s+/g, ' ')
283
+ .trim();
284
+
285
+ // ===== CLASES BASE DEL MENU ITEM =====
286
+ // CRÍTICO: Figma especifica text-[10px] leading-[12px] (Label XXSmall)
287
+ // Gap de 2px (gap-0.5) entre elementos según Figma
288
+ const baseMenuItemClasses = `
289
+ flex
290
+ items-center
291
+ cursor-pointer
292
+ rounded-md
293
+ transition-all
294
+ duration-150
295
+ pl-2
296
+ pr-2.5
297
+ py-0.5
298
+ gap-0.5
299
+ text-[10px]
300
+ leading-[12px]
301
+ font-bold
302
+ `;
303
+
304
+ // ===== FUNCIÓN PARA OBTENER CLASES DE MENU ITEM =====
305
+ const getMenuItemClasses = (option: SelectOption, index: number) => {
306
+ const isSelected = option.value === selectedValue;
307
+ const isFocused = index === focusedIndex;
308
+
309
+ // Estados de color según Figma:
310
+ // - Default: text-content-primary
311
+ // - Hover: bg-primary-custom-600 + text-primary-inverse-content
312
+ // - Selected: muestra check icon, mismo text color que default
313
+ const colorClasses =
314
+ isFocused || (isSelected && isFocused)
315
+ ? 'bg-primary-custom-600 text-primary-inverse-content dark:bg-primary-custom-600 dark:text-primary-inverse-content'
316
+ : 'text-content-primary dark:text-dark-content-primary';
317
+
318
+ // Hover: fondo azul primario con texto blanco
319
+ const hoverClasses = !option.disabled
320
+ ? 'hover:bg-primary-custom-600 hover:text-primary-inverse-content dark:hover:bg-primary-custom-600 dark:hover:text-primary-inverse-content'
321
+ : '';
322
+
323
+ // Disabled
324
+ const disabledClasses = option.disabled ? 'opacity-50 cursor-not-allowed' : '';
325
+
326
+ return [baseMenuItemClasses, colorClasses, hoverClasses, disabledClasses]
327
+ .join(' ')
328
+ .replace(/\s+/g, ' ')
329
+ .trim();
330
+ };
331
+
332
+ // ===== CLASES DEL ICONO DEL TRIGGER =====
333
+ // Chevron icon 20x20px (size-5) según sistema Heroicons
334
+ const iconClasses = [
335
+ 'size-5',
336
+ 'flex-shrink-0',
337
+ 'transition-transform',
338
+ 'duration-150',
339
+ isOpen && 'rotate-180',
340
+ disabled ? 'text-content-tertiary dark:text-content-tertiary' : 'text-content-secondary dark:text-content-secondary',
341
+ ]
342
+ .filter(Boolean)
343
+ .join(' ')
344
+ .replace(/\s+/g, ' ')
345
+ .trim();
346
+
347
+ // ===== CLASES DEL CHECK ICON =====
348
+ // Check icon 16x16px (size-4) según sistema Heroicons
349
+ const checkIconClasses = 'size-4 flex-shrink-0';
350
+
351
+ // ===== RENDERIZAR COMPONENTE =====
352
+ return (
353
+ <div className={`relative ${fullWidth ? 'w-full' : ''} ${className}`} ref={containerRef}>
354
+ {/* Label and Description - Según Figma, van ANTES del trigger con gap-1 (4px) */}
355
+ {(showLabel && label) || (showDescription && description) ? (
356
+ <div className="flex flex-col gap-1 mb-1 w-full">
357
+ {/* Label - Label Small (14px bold) */}
358
+ {showLabel && label && (
359
+ <label
360
+ htmlFor={id}
361
+ className="text-sm font-bold leading-5 text-content-primary dark:text-dark-content-primary"
362
+ >
363
+ {label}
364
+ {required && <span className="ml-1 text-error-content">*</span>}
365
+ </label>
366
+ )}
367
+
368
+ {/* Description - Paragraph Small (14px regular) */}
369
+ {showDescription && description && (
370
+ <p className="text-sm font-normal leading-5 text-content-tertiary dark:text-content-tertiary">
371
+ {description}
372
+ </p>
373
+ )}
374
+ </div>
375
+ ) : null}
376
+
377
+ {/* Trigger Button */}
378
+ <button
379
+ ref={triggerRef}
380
+ type="button"
381
+ className={finalTriggerClasses}
382
+ onClick={toggleMenu}
383
+ disabled={disabled}
384
+ aria-label={ariaLabel || label}
385
+ aria-haspopup="listbox"
386
+ aria-expanded={isOpen}
387
+ id={id}
388
+ >
389
+ {/* Selected value or placeholder */}
390
+ <span
391
+ className={
392
+ selectedOption ? '' : 'text-content-secondary dark:text-content-secondary'
393
+ }
394
+ >
395
+ {selectedOption ? selectedOption.label : placeholder}
396
+ </span>
397
+
398
+ {/* Chevron icon */}
399
+ <ChevronUpDownIcon className={iconClasses} />
400
+ </button>
401
+
402
+ {/* Hidden input for forms */}
403
+ {name && (
404
+ <input
405
+ type="hidden"
406
+ name={name}
407
+ value={selectedValue !== undefined ? String(selectedValue) : ''}
408
+ />
409
+ )}
410
+
411
+ {/* Menu */}
412
+ {isOpen && (
413
+ <div ref={menuRef} className={finalMenuClasses} role="listbox">
414
+ {/* Menu Header - Opcional según Figma */}
415
+ {menuHeader && (
416
+ <div className="flex items-center gap-0.5 px-6 py-0.5 rounded-[5px]">
417
+ <span className="text-[10px] font-bold leading-[12px] text-content-tertiary dark:text-content-tertiary">
418
+ {menuHeader}
419
+ </span>
420
+ </div>
421
+ )}
422
+
423
+ {/* Empty state */}
424
+ {options.length === 0 && (
425
+ <div className="px-2 py-1.5 text-[10px] leading-[12px] text-content-secondary dark:text-content-secondary">
426
+ No hay opciones disponibles
427
+ </div>
428
+ )}
429
+
430
+ {/* Options */}
431
+ {options.map((option, index) => (
432
+ <div
433
+ key={option.value}
434
+ className={getMenuItemClasses(option, index)}
435
+ onClick={() => handleSelect(option)}
436
+ onMouseEnter={() => setFocusedIndex(index)}
437
+ role="option"
438
+ aria-selected={option.value === selectedValue}
439
+ aria-disabled={option.disabled}
440
+ >
441
+ {/* Check icon for selected item */}
442
+ <div className="w-4 flex items-center justify-center">
443
+ {option.value === selectedValue && <CheckIcon className={checkIconClasses} />}
444
+ </div>
445
+
446
+ {/* Custom icon if provided */}
447
+ {option.icon && <span className="flex-shrink-0 w-4 h-4">{option.icon}</span>}
448
+
449
+ {/* Label */}
450
+ <span className="flex-1 text-left">{option.label}</span>
451
+ </div>
452
+ ))}
453
+ </div>
454
+ )}
455
+ </div>
456
+ );
457
+ };