@widergy/energy-ui 3.168.0 → 3.169.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.
@@ -0,0 +1,733 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ import React, { useState } from 'react';
3
+ import { bool, shape, string } from 'prop-types';
4
+ import { joinArgTypes } from 'stories/utils';
5
+ import UTSelect from '.';
6
+ const CustomRowItem = shape({
7
+ name: string,
8
+ value: string
9
+ });
10
+ const AvatarCustomRow = _ref => {
11
+ let {
12
+ isChecked,
13
+ item
14
+ } = _ref;
15
+ return /*#__PURE__*/React.createElement("div", {
16
+ style: {
17
+ alignItems: 'center',
18
+ display: 'flex',
19
+ gap: 8
20
+ }
21
+ }, /*#__PURE__*/React.createElement("div", {
22
+ style: {
23
+ alignItems: 'center',
24
+ background: isChecked ? '#285AFF' : '#E4E6EA',
25
+ borderRadius: '50%',
26
+ color: isChecked ? '#FFFFFF' : '#091E42',
27
+ display: 'flex',
28
+ fontSize: 12,
29
+ fontWeight: 700,
30
+ height: 28,
31
+ justifyContent: 'center',
32
+ width: 28
33
+ }
34
+ }, item.name[0]), /*#__PURE__*/React.createElement("span", {
35
+ style: {
36
+ fontWeight: isChecked ? 700 : 400
37
+ }
38
+ }, item.name));
39
+ };
40
+ AvatarCustomRow.propTypes = {
41
+ isChecked: bool,
42
+ item: CustomRowItem
43
+ };
44
+ const SimpleCustomRow = _ref2 => {
45
+ let {
46
+ isChecked,
47
+ item
48
+ } = _ref2;
49
+ return /*#__PURE__*/React.createElement("div", {
50
+ style: {
51
+ display: 'flex',
52
+ gap: 8
53
+ }
54
+ }, /*#__PURE__*/React.createElement("span", {
55
+ style: {
56
+ fontWeight: isChecked ? 700 : 400
57
+ }
58
+ }, item.name));
59
+ };
60
+ SimpleCustomRow.propTypes = {
61
+ isChecked: bool,
62
+ item: CustomRowItem
63
+ };
64
+ const OPTIONS = [{
65
+ name: 'Alice García',
66
+ value: '1'
67
+ }, {
68
+ name: 'Bob Martínez',
69
+ value: '2'
70
+ }, {
71
+ name: 'Carol Rodríguez',
72
+ value: '3'
73
+ }, {
74
+ name: 'David López',
75
+ value: '4'
76
+ }, {
77
+ name: 'Elena Sánchez',
78
+ value: '5'
79
+ }];
80
+ const CATEGORIZED_OPTIONS = [{
81
+ name: 'Opción A1',
82
+ value: 'a1',
83
+ category: 'Categoría A'
84
+ }, {
85
+ name: 'Opción A2',
86
+ value: 'a2',
87
+ category: 'Categoría A'
88
+ }, {
89
+ name: 'Opción B1',
90
+ value: 'b1',
91
+ category: 'Categoría B'
92
+ }, {
93
+ name: 'Opción B2',
94
+ value: 'b2',
95
+ category: 'Categoría B'
96
+ }, {
97
+ name: 'Opción C1',
98
+ value: 'c1',
99
+ category: 'Categoría C'
100
+ }];
101
+ const StatefulSelect = args => {
102
+ const [value, setValue] = useState(args.multiple ? [] : null);
103
+ return /*#__PURE__*/React.createElement(UTSelect, _extends({}, args, {
104
+ onChange: setValue,
105
+ value: value
106
+ }));
107
+ };
108
+ export default {
109
+ title: 'Energy-UI/UTSelect/V1',
110
+ component: UTSelect,
111
+ args: {
112
+ clearable: true,
113
+ disabled: false,
114
+ disableFilterOptions: false,
115
+ freeWidth: false,
116
+ multiple: false,
117
+ noMatchesText: 'No hay coincidencias con tu búsqueda',
118
+ noOptionsText: 'No hay opciones disponibles',
119
+ options: OPTIONS,
120
+ placeholder: 'Seleccionar...',
121
+ readOnly: false,
122
+ required: false,
123
+ title: 'Título del campo',
124
+ titleVariant: 'large',
125
+ variant: 'select',
126
+ withAutoReset: true
127
+ },
128
+ argTypes: {
129
+ action: {
130
+ control: 'object',
131
+ description: 'Botón de acción adicional. Objeto con { Icon, onClick, size }.',
132
+ table: {
133
+ defaultValue: {
134
+ summary: 'undefined'
135
+ },
136
+ type: {
137
+ summary: 'object'
138
+ }
139
+ }
140
+ },
141
+ actions: {
142
+ control: false,
143
+ description: 'Array de botones de acción en el área del título.',
144
+ table: {
145
+ defaultValue: {
146
+ summary: 'undefined'
147
+ },
148
+ type: {
149
+ summary: 'array'
150
+ }
151
+ }
152
+ },
153
+ alwaysShowPlaceholder: {
154
+ control: 'boolean',
155
+ description: 'Muestra el placeholder incluso cuando hay un valor seleccionado.',
156
+ table: {
157
+ defaultValue: {
158
+ summary: 'true'
159
+ },
160
+ type: {
161
+ summary: 'boolean'
162
+ }
163
+ }
164
+ },
165
+ autocompleteProps: {
166
+ control: false,
167
+ description: 'Props adicionales para el Autocomplete de MUI.',
168
+ table: {
169
+ defaultValue: {
170
+ summary: '{}'
171
+ },
172
+ type: {
173
+ summary: 'object'
174
+ }
175
+ }
176
+ },
177
+ className: {
178
+ control: false,
179
+ description: 'Clase CSS adicional para el contenedor.',
180
+ table: {
181
+ defaultValue: {
182
+ summary: 'undefined'
183
+ },
184
+ type: {
185
+ summary: 'string'
186
+ }
187
+ }
188
+ },
189
+ clearable: {
190
+ control: 'boolean',
191
+ description: 'Muestra el botón para limpiar la selección.',
192
+ table: {
193
+ defaultValue: {
194
+ summary: 'true'
195
+ },
196
+ type: {
197
+ summary: 'boolean'
198
+ }
199
+ }
200
+ },
201
+ CustomRow: {
202
+ control: false,
203
+ description: 'Componente React personalizado para renderizar cada opción del dropdown. Recibe { item, isChecked } donde item es el objeto de la opción e isChecked indica si está seleccionada.',
204
+ table: {
205
+ defaultValue: {
206
+ summary: 'undefined'
207
+ },
208
+ type: {
209
+ summary: 'elementType'
210
+ }
211
+ }
212
+ },
213
+ dataTestId: {
214
+ control: 'text',
215
+ description: 'Test ID para el input.',
216
+ table: {
217
+ defaultValue: {
218
+ summary: 'undefined'
219
+ },
220
+ type: {
221
+ summary: 'string'
222
+ }
223
+ }
224
+ },
225
+ disabled: {
226
+ control: 'boolean',
227
+ description: 'Deshabilita el select.',
228
+ table: {
229
+ defaultValue: {
230
+ summary: 'false'
231
+ },
232
+ type: {
233
+ summary: 'boolean'
234
+ }
235
+ }
236
+ },
237
+ disableFilterOptions: {
238
+ control: 'boolean',
239
+ description: 'Desactiva el filtrado de opciones al escribir en el campo de búsqueda.',
240
+ table: {
241
+ defaultValue: {
242
+ summary: 'false'
243
+ },
244
+ type: {
245
+ summary: 'boolean'
246
+ }
247
+ }
248
+ },
249
+ error: {
250
+ control: 'text',
251
+ description: 'Mensaje de error a mostrar debajo del input.',
252
+ table: {
253
+ defaultValue: {
254
+ summary: 'undefined'
255
+ },
256
+ type: {
257
+ summary: 'string'
258
+ }
259
+ }
260
+ },
261
+ errorDataTestId: {
262
+ control: false,
263
+ description: 'Test ID para el componente de validación de error.',
264
+ table: {
265
+ defaultValue: {
266
+ summary: 'undefined'
267
+ },
268
+ type: {
269
+ summary: 'string'
270
+ }
271
+ }
272
+ },
273
+ freeWidth: {
274
+ control: 'boolean',
275
+ description: 'Permite que el dropdown tenga ancho libre en lugar de ajustarse al input.',
276
+ table: {
277
+ defaultValue: {
278
+ summary: 'false'
279
+ },
280
+ type: {
281
+ summary: 'boolean'
282
+ }
283
+ }
284
+ },
285
+ helpText: {
286
+ control: 'text',
287
+ description: 'Texto de ayuda mostrado debajo del input.',
288
+ table: {
289
+ defaultValue: {
290
+ summary: 'undefined'
291
+ },
292
+ type: {
293
+ summary: 'string'
294
+ }
295
+ }
296
+ },
297
+ icon: {
298
+ control: 'text',
299
+ description: 'Nombre del ícono a mostrar como adorno izquierdo del input.',
300
+ table: {
301
+ defaultValue: {
302
+ summary: 'undefined'
303
+ },
304
+ type: {
305
+ summary: 'string'
306
+ }
307
+ }
308
+ },
309
+ inputSize: {
310
+ control: {
311
+ type: 'select'
312
+ },
313
+ description: 'Tamaño del input.',
314
+ options: ['small', 'large'],
315
+ table: {
316
+ defaultValue: {
317
+ summary: 'undefined'
318
+ },
319
+ type: {
320
+ summary: joinArgTypes(['small', 'large'])
321
+ }
322
+ }
323
+ },
324
+ itemDataTestId: {
325
+ control: false,
326
+ description: 'Test ID para cada ítem del dropdown.',
327
+ table: {
328
+ defaultValue: {
329
+ summary: 'undefined'
330
+ },
331
+ type: {
332
+ summary: 'string'
333
+ }
334
+ }
335
+ },
336
+ listDataTestId: {
337
+ control: false,
338
+ description: 'Test ID para el contenedor de la lista.',
339
+ table: {
340
+ defaultValue: {
341
+ summary: 'undefined'
342
+ },
343
+ type: {
344
+ summary: 'string'
345
+ }
346
+ }
347
+ },
348
+ listProps: {
349
+ control: false,
350
+ description: 'Props adicionales para el ListboxComponent interno.',
351
+ table: {
352
+ defaultValue: {
353
+ summary: '{}'
354
+ },
355
+ type: {
356
+ summary: 'object'
357
+ }
358
+ }
359
+ },
360
+ multiple: {
361
+ control: 'boolean',
362
+ description: 'Habilita la selección múltiple.',
363
+ table: {
364
+ defaultValue: {
365
+ summary: 'false'
366
+ },
367
+ type: {
368
+ summary: 'boolean'
369
+ }
370
+ }
371
+ },
372
+ noMatchesText: {
373
+ control: 'text',
374
+ description: 'Texto cuando no hay coincidencias en la búsqueda.',
375
+ table: {
376
+ defaultValue: {
377
+ summary: "'No hay coincidencias con tu búsqueda'"
378
+ },
379
+ type: {
380
+ summary: 'string'
381
+ }
382
+ }
383
+ },
384
+ noOptionsText: {
385
+ control: 'text',
386
+ description: 'Texto cuando no hay opciones disponibles.',
387
+ table: {
388
+ defaultValue: {
389
+ summary: "'No hay opciones disponibles'"
390
+ },
391
+ type: {
392
+ summary: 'string'
393
+ }
394
+ }
395
+ },
396
+ onChange: {
397
+ control: false,
398
+ description: 'Callback al cambiar la selección. Recibe el valor seleccionado.',
399
+ table: {
400
+ defaultValue: {
401
+ summary: '() => {}'
402
+ },
403
+ type: {
404
+ summary: 'func'
405
+ }
406
+ }
407
+ },
408
+ onChangeSearchTerm: {
409
+ control: false,
410
+ description: 'Callback al cambiar el término de búsqueda.',
411
+ table: {
412
+ defaultValue: {
413
+ summary: '() => {}'
414
+ },
415
+ type: {
416
+ summary: 'func'
417
+ }
418
+ }
419
+ },
420
+ options: {
421
+ control: 'object',
422
+ description: 'Array de opciones. Cada opción: { name, value, category? }.',
423
+ table: {
424
+ defaultValue: {
425
+ summary: '[]'
426
+ },
427
+ type: {
428
+ summary: 'array'
429
+ }
430
+ }
431
+ },
432
+ placeholder: {
433
+ control: 'text',
434
+ description: 'Texto placeholder del campo.',
435
+ table: {
436
+ defaultValue: {
437
+ summary: 'undefined'
438
+ },
439
+ type: {
440
+ summary: 'string'
441
+ }
442
+ }
443
+ },
444
+ prefix: {
445
+ control: 'text',
446
+ description: 'Texto prefijo dentro del input.',
447
+ table: {
448
+ defaultValue: {
449
+ summary: 'undefined'
450
+ },
451
+ type: {
452
+ summary: 'string'
453
+ }
454
+ }
455
+ },
456
+ readOnly: {
457
+ control: 'boolean',
458
+ description: 'Modo solo lectura: el dropdown puede abrirse pero no puede modificarse.',
459
+ table: {
460
+ defaultValue: {
461
+ summary: 'false'
462
+ },
463
+ type: {
464
+ summary: 'boolean'
465
+ }
466
+ }
467
+ },
468
+ required: {
469
+ control: 'boolean',
470
+ description: 'Muestra el indicador de campo requerido junto al título.',
471
+ table: {
472
+ defaultValue: {
473
+ summary: 'false'
474
+ },
475
+ type: {
476
+ summary: 'boolean'
477
+ }
478
+ }
479
+ },
480
+ suffix: {
481
+ control: 'text',
482
+ description: 'Texto sufijo dentro del input.',
483
+ table: {
484
+ defaultValue: {
485
+ summary: 'undefined'
486
+ },
487
+ type: {
488
+ summary: 'string'
489
+ }
490
+ }
491
+ },
492
+ title: {
493
+ control: 'text',
494
+ description: 'Título mostrado sobre el input.',
495
+ table: {
496
+ defaultValue: {
497
+ summary: 'undefined'
498
+ },
499
+ type: {
500
+ summary: 'string'
501
+ }
502
+ }
503
+ },
504
+ titleVariant: {
505
+ control: {
506
+ type: 'select'
507
+ },
508
+ description: 'Tamaño del título.',
509
+ options: ['large', 'small'],
510
+ table: {
511
+ defaultValue: {
512
+ summary: "'large'"
513
+ },
514
+ type: {
515
+ summary: joinArgTypes(['large', 'small'])
516
+ }
517
+ }
518
+ },
519
+ value: {
520
+ control: false,
521
+ description: 'Valor seleccionado. String para selección simple, array para múltiple.',
522
+ table: {
523
+ defaultValue: {
524
+ summary: 'null'
525
+ },
526
+ type: {
527
+ summary: joinArgTypes(['string', 'array'])
528
+ }
529
+ }
530
+ },
531
+ variant: {
532
+ control: {
533
+ type: 'select'
534
+ },
535
+ description: 'Variante visual del select.',
536
+ options: ['select', 'picker'],
537
+ table: {
538
+ defaultValue: {
539
+ summary: "'select'"
540
+ },
541
+ type: {
542
+ summary: joinArgTypes(['select', 'picker'])
543
+ }
544
+ }
545
+ },
546
+ withAutoReset: {
547
+ control: 'boolean',
548
+ description: 'Resetea el valor seleccionado si la opción deja de estar disponible en options.',
549
+ table: {
550
+ defaultValue: {
551
+ summary: 'true'
552
+ },
553
+ type: {
554
+ summary: 'boolean'
555
+ }
556
+ }
557
+ }
558
+ },
559
+ parameters: {
560
+ controls: {
561
+ exclude: ['classes']
562
+ },
563
+ docs: {
564
+ description: {
565
+ component: 'Componente dropdown de selección single/múltiple basado en MUI Autocomplete. Soporta búsqueda, agrupación por categorías, adornos (prefijo, sufijo, íconos) y renderizado personalizado de opciones vía `CustomRow`.'
566
+ }
567
+ }
568
+ }
569
+ };
570
+ export const Playground = {
571
+ render: args => /*#__PURE__*/React.createElement(StatefulSelect, args),
572
+ name: 'Playground'
573
+ };
574
+ export const SeleccionSimple = {
575
+ render: args => /*#__PURE__*/React.createElement(StatefulSelect, args),
576
+ args: {
577
+ placeholder: 'Seleccioná una opción',
578
+ title: 'Selección simple'
579
+ },
580
+ name: 'Selección simple'
581
+ };
582
+ export const SeleccionMultiple = {
583
+ render: args => /*#__PURE__*/React.createElement(StatefulSelect, args),
584
+ args: {
585
+ multiple: true,
586
+ placeholder: 'Seleccioná una o más opciones',
587
+ title: 'Selección múltiple'
588
+ },
589
+ name: 'Selección múltiple'
590
+ };
591
+ export const ConCategorias = {
592
+ render: args => /*#__PURE__*/React.createElement(StatefulSelect, args),
593
+ args: {
594
+ options: CATEGORIZED_OPTIONS,
595
+ placeholder: 'Seleccioná una opción',
596
+ title: 'Con categorías'
597
+ },
598
+ name: 'Con categorías',
599
+ parameters: {
600
+ docs: {
601
+ description: {
602
+ story: 'Las opciones se agrupan automáticamente por la propiedad `category`. Las opciones seleccionadas se mueven al tope de su categoría al abrir el dropdown.'
603
+ }
604
+ }
605
+ }
606
+ };
607
+ export const ConFilaPersonalizada = {
608
+ render: args => /*#__PURE__*/React.createElement(StatefulSelect, args),
609
+ args: {
610
+ CustomRow: AvatarCustomRow,
611
+ multiple: true,
612
+ placeholder: 'Seleccioná usuarios',
613
+ title: 'Con fila personalizada (CustomRow)'
614
+ },
615
+ name: 'Con fila personalizada (CustomRow)',
616
+ parameters: {
617
+ docs: {
618
+ description: {
619
+ story: 'La prop `CustomRow` recibe un componente React con `{ item, isChecked }` y reemplaza el renderizado por defecto de cada opción del dropdown.'
620
+ }
621
+ }
622
+ }
623
+ };
624
+ export const ConError = {
625
+ render: args => /*#__PURE__*/React.createElement(StatefulSelect, args),
626
+ args: {
627
+ error: 'Este campo es requerido.',
628
+ placeholder: 'Seleccioná una opción',
629
+ required: true,
630
+ title: 'Con error'
631
+ },
632
+ name: 'Con error'
633
+ };
634
+ export const ConTextoDeAyuda = {
635
+ render: args => /*#__PURE__*/React.createElement(StatefulSelect, args),
636
+ args: {
637
+ helpText: 'Podés buscar escribiendo en el campo.',
638
+ placeholder: 'Seleccioná una opción',
639
+ title: 'Con texto de ayuda'
640
+ },
641
+ name: 'Con texto de ayuda'
642
+ };
643
+ export const Deshabilitado = {
644
+ args: {
645
+ disabled: true,
646
+ placeholder: 'Campo deshabilitado',
647
+ title: 'Deshabilitado'
648
+ },
649
+ name: 'Deshabilitado'
650
+ };
651
+ export const SoloLectura = {
652
+ args: {
653
+ placeholder: 'Solo lectura',
654
+ readOnly: true,
655
+ title: 'Solo lectura',
656
+ value: '1'
657
+ },
658
+ name: 'Solo lectura'
659
+ };
660
+ export const SinOpciones = {
661
+ args: {
662
+ options: [],
663
+ placeholder: 'Sin opciones',
664
+ title: 'Sin opciones disponibles'
665
+ },
666
+ name: 'Sin opciones'
667
+ };
668
+ const SingleSelect = () => {
669
+ const [value, setValue] = useState(null);
670
+ return /*#__PURE__*/React.createElement(UTSelect, {
671
+ onChange: setValue,
672
+ options: OPTIONS,
673
+ placeholder: "Selecci\xF3n simple",
674
+ title: "Single",
675
+ value: value
676
+ });
677
+ };
678
+ const MultiSelect = () => {
679
+ const [value, setValue] = useState([]);
680
+ return /*#__PURE__*/React.createElement(UTSelect, {
681
+ multiple: true,
682
+ onChange: setValue,
683
+ options: OPTIONS,
684
+ placeholder: "Selecci\xF3n m\xFAltiple",
685
+ title: "Multiple",
686
+ value: value
687
+ });
688
+ };
689
+ const CustomRowSelect = () => {
690
+ const [value, setValue] = useState([]);
691
+ return /*#__PURE__*/React.createElement(UTSelect, {
692
+ CustomRow: AvatarCustomRow,
693
+ multiple: true,
694
+ onChange: setValue,
695
+ options: OPTIONS,
696
+ placeholder: "Custom row",
697
+ title: "Custom Row",
698
+ value: value
699
+ });
700
+ };
701
+ export const TestSite = {
702
+ render: () => /*#__PURE__*/React.createElement("div", {
703
+ style: {
704
+ display: 'flex',
705
+ flexDirection: 'column',
706
+ gap: 24,
707
+ maxWidth: 400
708
+ }
709
+ }, /*#__PURE__*/React.createElement(SingleSelect, null), /*#__PURE__*/React.createElement(MultiSelect, null), /*#__PURE__*/React.createElement(CustomRowSelect, null), /*#__PURE__*/React.createElement(UTSelect, {
710
+ disabled: true,
711
+ options: OPTIONS,
712
+ placeholder: "Deshabilitado",
713
+ title: "Disabled",
714
+ value: null,
715
+ onChange: () => {}
716
+ }), /*#__PURE__*/React.createElement(UTSelect, {
717
+ error: "Campo requerido",
718
+ options: OPTIONS,
719
+ placeholder: "Con error",
720
+ required: true,
721
+ title: "Error",
722
+ value: null,
723
+ onChange: () => {}
724
+ })),
725
+ name: 'Test Site',
726
+ parameters: {
727
+ docs: {
728
+ description: {
729
+ story: 'Casos de prueba para el Storybook Test Runner: single, múltiple, CustomRow, disabled, error.'
730
+ }
731
+ }
732
+ }
733
+ };