@widergy/energy-ui 3.168.0 → 3.170.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.
@@ -17,6 +17,7 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
17
17
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
18
  const ListboxComponent = _ref => {
19
19
  let {
20
+ CustomRow,
20
21
  dataTestId,
21
22
  filteredOptions,
22
23
  handleSelectionChange,
@@ -38,6 +39,7 @@ const ListboxComponent = _ref => {
38
39
  maxHeight: maxHeightValid
39
40
  }
40
41
  }, /*#__PURE__*/_react.default.createElement(_UTCheckList.default, {
42
+ CustomRow: CustomRow,
41
43
  dataTestId: dataTestId,
42
44
  horizontalSpacing: horizontalSpacing,
43
45
  isSimple: !multiple,
@@ -53,6 +55,7 @@ const ListboxComponent = _ref => {
53
55
  }));
54
56
  };
55
57
  ListboxComponent.propTypes = {
58
+ CustomRow: _propTypes.elementType,
56
59
  dataTestId: _propTypes.string,
57
60
  filteredOptions: (0, _propTypes.arrayOf)((0, _propTypes.shape)({
58
61
  name: _propTypes.string,
@@ -30,6 +30,7 @@ const UTSelect = _ref => {
30
30
  autocompleteProps = {},
31
31
  className,
32
32
  clearable = true,
33
+ CustomRow,
33
34
  dataTestId,
34
35
  disabled,
35
36
  disableFilterOptions = false,
@@ -172,6 +173,7 @@ const UTSelect = _ref => {
172
173
  variant: variant
173
174
  }), [alwaysShowPlaceholder, disabled, error, handleInputBlur, handleInputFocus, leftAdornments, placeholder, rightAdornments, searchTerm]);
174
175
  const listBoxProps = (0, _react.useMemo)(() => ({
176
+ CustomRow,
175
177
  dataTestId: listDataTestId,
176
178
  filteredOptions,
177
179
  handleSelectionChange,
@@ -180,7 +182,7 @@ const UTSelect = _ref => {
180
182
  noMatchesText,
181
183
  value,
182
184
  ...listProps
183
- }), [filteredOptions, handleSelectionChange, multiple, noMatchesText, value, listProps]);
185
+ }), [CustomRow, filteredOptions, handleSelectionChange, multiple, noMatchesText, value, listProps]);
184
186
  const noOptionsTextComponent = /*#__PURE__*/_react.default.createElement(_UTLabel.default, {
185
187
  className: _stylesModule.default.noOptionsLabel,
186
188
  colorTheme: "gray"
@@ -227,6 +229,7 @@ UTSelect.propTypes = {
227
229
  autocompleteProps: _propTypes.object,
228
230
  className: _propTypes.string,
229
231
  clearable: _propTypes.bool,
232
+ CustomRow: _propTypes.elementType,
230
233
  dataTestId: _propTypes.string,
231
234
  disabled: _propTypes.bool,
232
235
  disableFilterOptions: _propTypes.bool,
@@ -12,6 +12,7 @@ const UTDotMenu = _ref => {
12
12
  let {
13
13
  className,
14
14
  classNames = DEFAULT_PROPS.classNames,
15
+ dataTestId,
15
16
  disabled,
16
17
  Icon = DEFAULT_PROPS.Icon,
17
18
  menuItemProps,
@@ -21,12 +22,14 @@ const UTDotMenu = _ref => {
21
22
  } = _ref;
22
23
  const [anchorEl, setAnchorEl] = useState(null);
23
24
  return /*#__PURE__*/React.createElement("div", {
24
- className: className
25
+ className: className,
26
+ "data-testid": dataTestId
25
27
  }, /*#__PURE__*/React.createElement(UTButton, {
26
28
  classNames: {
27
29
  icon: classNames.icon,
28
30
  root: classNames.button
29
31
  },
32
+ dataTestId: dataTestId ? "".concat(dataTestId, ".button") : undefined,
30
33
  disabled: disabled,
31
34
  Icon: Icon,
32
35
  onClick: event => setAnchorEl(event.currentTarget),
@@ -44,15 +47,18 @@ const UTDotMenu = _ref => {
44
47
  },
45
48
  ...(menuProps === null || menuProps === void 0 ? void 0 : menuProps.PaperProps)
46
49
  }
47
- }), options.map(option => {
50
+ }), options.map((option, index) => {
48
51
  const {
49
52
  colorTheme,
53
+ dataTestId: optionTestId,
50
54
  icon,
51
55
  iconProps,
52
56
  name,
53
57
  onPress
54
58
  } = option;
59
+ const itemTestId = optionTestId !== null && optionTestId !== void 0 ? optionTestId : dataTestId ? "".concat(dataTestId, ".").concat(index) : undefined;
55
60
  return /*#__PURE__*/React.createElement(MenuItem, _extends({
61
+ "data-testid": itemTestId,
56
62
  key: name,
57
63
  onClick: onPress
58
64
  }, menuItemProps), icon && /*#__PURE__*/React.createElement(UTIcon, _extends({
@@ -70,12 +76,14 @@ UTDotMenu.propTypes = {
70
76
  button: string,
71
77
  icon: string
72
78
  }),
79
+ dataTestId: string,
73
80
  disabled: bool,
74
81
  Icon: oneOfType([elementType, string]),
75
82
  menuItemProps: object,
76
83
  menuProps: object,
77
84
  options: arrayOf(shape({
78
85
  colorTheme: string,
86
+ dataTestId: string,
79
87
  icon: string,
80
88
  iconProps: object,
81
89
  name: string,
@@ -42,6 +42,18 @@ export default {
42
42
  }
43
43
  }
44
44
  },
45
+ dataTestId: {
46
+ control: 'text',
47
+ description: 'Test id del contenedor raíz. El botón trigger recibe automáticamente el valor de esta prop con el sufijo `.button`. ' + 'Cada ítem del menú usa su propio `dataTestId` directamente (sin concatenación con el contenedor).',
48
+ table: {
49
+ defaultValue: {
50
+ summary: 'undefined'
51
+ },
52
+ type: {
53
+ summary: 'string'
54
+ }
55
+ }
56
+ },
45
57
  classNames: {
46
58
  control: false,
47
59
  description: 'Clases personalizadas para el botón trigger. Acepta `button` e `icon`.',
@@ -104,13 +116,13 @@ export default {
104
116
  },
105
117
  options: {
106
118
  control: false,
107
- description: 'Array de opciones del menú. Cada opción puede incluir `icon`, `colorTheme` e `iconProps` para pasar props extra a UTIcon.',
119
+ description: 'Array de opciones del menú. Cada opción puede incluir `icon`, `colorTheme`, `iconProps` para props extra a UTIcon, ' + 'y `dataTestId` para identificar el ítem. El test id del ítem se usa directamente tal como se provee en la opción.',
108
120
  table: {
109
121
  defaultValue: {
110
122
  summary: 'undefined'
111
123
  },
112
124
  type: {
113
- summary: 'arrayOf(shape({ name, onPress, colorTheme?, icon?, iconProps? }))'
125
+ summary: 'arrayOf(shape({ name, onPress, colorTheme?, dataTestId?, icon?, iconProps? }))'
114
126
  }
115
127
  }
116
128
  },
@@ -254,6 +266,33 @@ export const ConIconProps = {
254
266
  }
255
267
  }
256
268
  };
269
+ export const ConTestIds = {
270
+ args: {
271
+ dataTestId: 'section.dotMenu',
272
+ options: [{
273
+ name: 'Editar',
274
+ icon: 'IconPencil',
275
+ dataTestId: 'section.dotMenu.edit'
276
+ }, {
277
+ name: 'Duplicar',
278
+ icon: 'IconCopy',
279
+ dataTestId: 'section.dotMenu.duplicate'
280
+ }, {
281
+ name: 'Eliminar',
282
+ icon: 'IconTrash',
283
+ colorTheme: 'error',
284
+ dataTestId: 'section.dotMenu.delete'
285
+ }]
286
+ },
287
+ name: 'Con test ids',
288
+ parameters: {
289
+ docs: {
290
+ description: {
291
+ story: 'El contenedor recibe `dataTestId="section.dotMenu"` y el botón trigger recibe `"section.dotMenu.button"` automáticamente. ' + 'Cada ítem usa su propio `dataTestId` tal como se provee, sin concatenación con el contenedor.'
292
+ }
293
+ }
294
+ }
295
+ };
257
296
  export const BotonDeshabilitado = {
258
297
  args: {
259
298
  disabled: true,
@@ -14,6 +14,7 @@
14
14
  | autocompleteProps | object | {} | Additional props to pass to the underlying Material-UI Autocomplete component. |
15
15
  | className | string | | Additional CSS class name for the component container. |
16
16
  | clearable | bool | true | Determines whether a button to clear the current selection should be shown. |
17
+ | CustomRow | elementType | | Custom React component to render each option row. Receives `{ item, isChecked }` as props, where `item` is the option object and `isChecked` indicates if the option is selected. |
17
18
  | dataTestId | string | | Test ID for the main input component. |
18
19
  | disabled | bool | false | Disables the select input. |
19
20
  | disableFilterOptions | bool | false | Disables option filtering, showing all options even when typing in the search field. |
@@ -231,6 +232,40 @@ const ReadOnlyExample = () => {
231
232
  };
232
233
  ```
233
234
 
235
+ ### With Custom Row Renderer
236
+
237
+ ```jsx
238
+ import React, { useState } from 'react';
239
+ import UTSelect from './UTSelect';
240
+
241
+ const options = [
242
+ { name: 'Alice', value: '1', subtitle: 'Admin' },
243
+ { name: 'Bob', value: '2', subtitle: 'Editor' },
244
+ { name: 'Carol', value: '3', subtitle: 'Viewer' }
245
+ ];
246
+
247
+ const MyCustomRow = ({ item, isChecked }) => (
248
+ <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
249
+ <span style={{ fontWeight: isChecked ? 'bold' : 'normal' }}>{item.name}</span>
250
+ <span style={{ color: 'gray', fontSize: 12 }}>{item.subtitle}</span>
251
+ </div>
252
+ );
253
+
254
+ const CustomRowExample = () => {
255
+ const [value, setValue] = useState(null);
256
+
257
+ return (
258
+ <UTSelect
259
+ CustomRow={MyCustomRow}
260
+ onChange={setValue}
261
+ options={options}
262
+ placeholder="Select a user"
263
+ value={value}
264
+ />
265
+ );
266
+ };
267
+ ```
268
+
234
269
  ### With Search Term Handling
235
270
 
236
271
  ```jsx
@@ -0,0 +1,13 @@
1
+ import { ArgTypes, Canvas, Description, Meta, Title } from '@storybook/blocks';
2
+
3
+ import * as UTSelectV1Stories from './UTSelectV1.stories.js';
4
+
5
+ <Meta of={UTSelectV1Stories} />
6
+
7
+ <Title>UTSelect V1</Title>
8
+
9
+ <Description of={UTSelectV1Stories} />
10
+
11
+ <Canvas of={UTSelectV1Stories.Playground} withToolbar />
12
+
13
+ <ArgTypes exclude={['classes']} />