@widergy/energy-ui 3.172.2 → 3.173.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 (42) hide show
  1. package/CHANGELOG.md +20 -6
  2. package/dist/components/UTDataCategory/README.md +3 -1
  3. package/dist/components/UTDataCategory/UTDataCategory.stories.js +405 -0
  4. package/dist/components/UTDataCategory/components/MainAction/index.js +47 -0
  5. package/dist/components/UTDataCategory/constants.js +6 -2
  6. package/dist/components/UTDataCategory/index.js +46 -16
  7. package/dist/components/UTDataCategory/styles.module.scss +11 -0
  8. package/dist/components/UTDataElement/README.md +15 -2
  9. package/dist/components/UTDataElement/UTDataElement.stories.js +29 -1
  10. package/dist/components/UTDataElement/index.js +96 -49
  11. package/dist/components/UTDataElement/styles.module.scss +5 -0
  12. package/dist/components/UTDataElement/theme.js +11 -9
  13. package/dist/components/UTRadioGroup/UTRadioGroup.stories.js +124 -4
  14. package/dist/components/UTRadioGroup/versions/V1/components/Radio/index.js +12 -6
  15. package/dist/components/UTRadioGroup/versions/V1/constants.js +1 -0
  16. package/dist/components/UTRadioGroup/versions/V1/index.js +23 -7
  17. package/dist/components/UTRadioGroup/versions/V1/styles.module.scss +5 -0
  18. package/dist/components/UTRadioGroup/versions/V1/utils.js +40 -0
  19. package/dist/constants/Palette.js +18 -2
  20. package/dist/esm/components/UTDataCategory/README.md +3 -1
  21. package/dist/esm/components/UTDataCategory/UTDataCategory.stories.js +400 -0
  22. package/dist/esm/components/UTDataCategory/components/MainAction/index.js +40 -0
  23. package/dist/esm/components/UTDataCategory/constants.js +5 -1
  24. package/dist/esm/components/UTDataCategory/index.js +48 -18
  25. package/dist/esm/components/UTDataCategory/styles.module.scss +11 -0
  26. package/dist/esm/components/UTDataElement/README.md +15 -2
  27. package/dist/esm/components/UTDataElement/UTDataElement.stories.js +28 -0
  28. package/dist/esm/components/UTDataElement/index.js +98 -51
  29. package/dist/esm/components/UTDataElement/styles.module.scss +5 -0
  30. package/dist/esm/components/UTDataElement/theme.js +12 -10
  31. package/dist/esm/components/UTRadioGroup/UTRadioGroup.stories.js +123 -3
  32. package/dist/esm/components/UTRadioGroup/versions/V1/components/Radio/index.js +12 -6
  33. package/dist/esm/components/UTRadioGroup/versions/V1/constants.js +1 -0
  34. package/dist/esm/components/UTRadioGroup/versions/V1/index.js +25 -9
  35. package/dist/esm/components/UTRadioGroup/versions/V1/styles.module.scss +5 -0
  36. package/dist/esm/components/UTRadioGroup/versions/V1/utils.js +34 -0
  37. package/dist/esm/constants/Palette.js +17 -1
  38. package/dist/esm/utils/colorUtils.js +15 -0
  39. package/dist/esm/utils/hooks/useCSSVariables/constants.js +1 -0
  40. package/dist/utils/colorUtils.js +16 -1
  41. package/dist/utils/hooks/useCSSVariables/constants.js +1 -0
  42. package/package.json +1 -1
@@ -8,6 +8,7 @@ A versatile data component that can be customized with various themes, sizes, ic
8
8
  | ------------------ | ----------------- | ------------ | ------------------------------------------------------------------ |
9
9
  | action | object | | Action configuration for button or switch. See Action Types below. |
10
10
  | area | bool | `false` | Specifies whether the component has a background area. |
11
+ | areaProps | object | `{}` | Customizes the area background. Supports `colorTheme` (any `COLOR_THEMES` value) and `shade` (`'01'`–`'05'`). Only applies when `area` is `true`. |
11
12
  | badge | string \| number | | Displays a badge with text or number. |
12
13
  | badgeProps | object | `{}` | Additional props for customizing the badge. |
13
14
  | children | element | | Collapsible content displayed below the main component. |
@@ -69,7 +70,7 @@ The values of `paddingVertical` and `spacing` must be one of the following:
69
70
 
70
71
  ## Collapsible Content
71
72
 
72
- If the component has any `children`, it will automatically become collapsible with a chevron button to expand/collapse the content.
73
+ If the component has any `children`, it will automatically become collapsible. Clicking anywhere on the title/data area expands/collapses the content; the chevron next to the title is only a visual indicator of the current state. Clicks on `action` (button or switch) don't affect the toggle since it sits outside that clickable area.
73
74
 
74
75
  ## Examples
75
76
 
@@ -134,4 +135,16 @@ If the component has any `children`, it will automatically become collapsible wi
134
135
 
135
136
  ```javascript
136
137
  <UTDataElement area title="Highlighted Item" Data="Important information" Icon="IconStar" />
137
- ```
138
+ ```
139
+
140
+ ### With Custom Area Style
141
+
142
+ ```javascript
143
+ <UTDataElement
144
+ area
145
+ areaProps={{ colorTheme: 'accent', shade: '01' }}
146
+ title="Custom Area"
147
+ Data="Custom background color and shade"
148
+ Icon="IconStar"
149
+ />
150
+ ```
@@ -168,6 +168,18 @@ export default {
168
168
  }
169
169
  }
170
170
  },
171
+ areaProps: {
172
+ control: false,
173
+ description: "Personaliza el fondo del área. Acepta `colorTheme` (cualquier valor de COLOR_THEMES) y `shade` ('01'–'05'). Solo aplica cuando `area` es `true`.",
174
+ table: {
175
+ defaultValue: {
176
+ summary: '{}'
177
+ },
178
+ type: {
179
+ summary: 'object'
180
+ }
181
+ }
182
+ },
171
183
  action: {
172
184
  control: false,
173
185
  description: 'Configuración de la acción principal del elemento.',
@@ -526,6 +538,22 @@ export const AreaMode = {
526
538
  },
527
539
  name: 'Modo Área'
528
540
  };
541
+ export const AreaModeCustomProps = {
542
+ args: {
543
+ title: 'Área con Color Personalizado',
544
+ Data: mockDataContent,
545
+ Icon: 'IconPalette',
546
+ area: true,
547
+ areaProps: {
548
+ colorTheme: 'accent',
549
+ shade: '01'
550
+ },
551
+ orientation: ORIENTATION.HORIZONTAL,
552
+ paddingVertical: PADDING.MEDIUM,
553
+ spacing: SPACING.MEDIUM
554
+ },
555
+ name: 'Modo Área — Color Personalizado'
556
+ };
529
557
  export const SmallPadding = {
530
558
  args: {
531
559
  title: 'Padding Pequeño',
@@ -1,17 +1,17 @@
1
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 { bool, element, object, number, objectOf, oneOfType, string } from 'prop-types';
3
- import React, { useCallback, useMemo, useRef, useState, Fragment } from 'react';
2
+ import { bool, element, object, number, objectOf, oneOfType, shape, string } from 'prop-types';
3
+ import React, { useCallback, useEffect, useMemo, useRef, useState, Fragment } from 'react';
4
4
  import isEmpty from 'lodash/isEmpty';
5
5
  import isString from 'lodash/isString';
6
6
  import isFinite from 'lodash/isFinite';
7
7
  import UTTooltip from '../UTTooltip';
8
8
  import UTBadge from '../UTBadge';
9
9
  import UTLabel from '../UTLabel';
10
+ import UTTouchableWithoutFeedback from '../UTTouchableWithoutFeedback';
10
11
  import WithTheme from '../WithTheme';
11
12
  import UTIcon from '../UTIcon';
12
13
  import { capitalize, isUTIcon, isUTLabel } from '../../utils/componentUtils';
13
14
  import { mergeMultipleClassNames } from '../../utils/classesUtils';
14
- import UTButton from '../UTButton';
15
15
  import { TEST_IDS } from '../../constants/testIds';
16
16
  import { retrieveStyle } from './theme';
17
17
  import styles from './styles.module.scss';
@@ -32,6 +32,7 @@ const UTDataElement = _ref => {
32
32
  Data,
33
33
  dataProps = {},
34
34
  dataTestId,
35
+ expanded = false,
35
36
  forceShowBadge = false,
36
37
  Icon,
37
38
  iconProps = {},
@@ -45,35 +46,67 @@ const UTDataElement = _ref => {
45
46
  transitionDuration = ANIMATION.TRANSITION_DURATION
46
47
  } = _ref;
47
48
  const classes = useMemo(() => mergeMultipleClassNames(styles, theme, classNames), [classNames, theme]);
48
- const [isCollapsed, setIsCollapsed] = useState(true);
49
+ const [isCollapsed, setIsCollapsed] = useState(!expanded);
49
50
  const [isTransitioning, setIsTransitioning] = useState(false);
50
- const [contentHeight, setContentHeight] = useState('0px');
51
+ const [contentHeight, setContentHeight] = useState(expanded ? 'none' : '0px');
51
52
  const childrenRef = useRef(null);
53
+ const hasMountedRef = useRef(false);
54
+ const transitionTimeoutRef = useRef(null);
55
+ const transitionFrameRef = useRef(null);
56
+ const clearPendingTransition = useCallback(() => {
57
+ if (transitionTimeoutRef.current) {
58
+ clearTimeout(transitionTimeoutRef.current);
59
+ transitionTimeoutRef.current = null;
60
+ }
61
+ if (transitionFrameRef.current) {
62
+ cancelAnimationFrame(transitionFrameRef.current);
63
+ transitionFrameRef.current = null;
64
+ }
65
+ }, []);
66
+ const prepareContentTransition = useCallback(() => {
67
+ if (!childrenRef.current) return false;
68
+ clearPendingTransition();
69
+ setContentHeight("".concat(childrenRef.current.scrollHeight, "px"));
70
+ setIsTransitioning(true);
71
+ return true;
72
+ }, [clearPendingTransition]);
73
+ const openContent = useCallback(() => {
74
+ if (!prepareContentTransition()) return;
75
+ setIsCollapsed(false);
76
+ transitionTimeoutRef.current = setTimeout(() => {
77
+ setIsTransitioning(false);
78
+ setContentHeight('none');
79
+ }, transitionDuration);
80
+ }, [prepareContentTransition, transitionDuration]);
81
+ const closeContent = useCallback(() => {
82
+ if (!prepareContentTransition()) return;
83
+ transitionFrameRef.current = requestAnimationFrame(() => {
84
+ setContentHeight('0px');
85
+ setIsCollapsed(true);
86
+ transitionTimeoutRef.current = setTimeout(() => setIsTransitioning(false), transitionDuration);
87
+ });
88
+ }, [prepareContentTransition, transitionDuration]);
89
+ useEffect(() => clearPendingTransition, []);
52
90
  const toggleCollapsed = useCallback(() => {
53
- if (isCollapsed) {
54
- if (childrenRef.current) {
55
- const height = childrenRef.current.scrollHeight;
56
- setContentHeight("".concat(height, "px"));
57
- setIsTransitioning(true);
58
- setIsCollapsed(false);
59
- setTimeout(() => {
60
- setIsTransitioning(false);
61
- setContentHeight('none');
62
- }, transitionDuration);
63
- }
64
- } else if (childrenRef.current) {
65
- const height = childrenRef.current.scrollHeight;
66
- setContentHeight("".concat(height, "px"));
67
- setIsTransitioning(true);
68
- requestAnimationFrame(() => {
69
- setContentHeight('0px');
70
- setIsCollapsed(true);
71
- setTimeout(() => setIsTransitioning(false), transitionDuration);
72
- });
91
+ if (isCollapsed) openContent();else closeContent();
92
+ }, [isCollapsed, openContent, closeContent]);
93
+ useEffect(() => {
94
+ if (!hasMountedRef.current) {
95
+ hasMountedRef.current = true;
96
+ return;
73
97
  }
74
- }, [isCollapsed]);
98
+ if (expanded) openContent();else closeContent();
99
+ }, [expanded, openContent, closeContent]);
100
+ const handleInfoKeyDown = useCallback(event => {
101
+ if (event.target === event.currentTarget && (event.key === 'Enter' || event.key === ' ')) {
102
+ event.preventDefault();
103
+ toggleCollapsed();
104
+ }
105
+ }, [toggleCollapsed]);
106
+ const stopDataPropagation = useCallback(event => event.stopPropagation(), []);
75
107
  const IconComponent = isUTIcon(Icon) ? UTIcon : Icon;
76
- const DataComponent = isUTLabel(Data) ? /*#__PURE__*/React.createElement(UTLabel, dataProps, Data) : Data;
108
+ const isDataLabel = isUTLabel(Data);
109
+ const DataComponent = isDataLabel ? /*#__PURE__*/React.createElement(UTLabel, dataProps, Data) : Data;
77
110
  const showBadge = forceShowBadge || isString(badge) && !isEmpty(badge) || isFinite(badge);
78
111
  const {
79
112
  tooltip: titleTooltip
@@ -84,18 +117,7 @@ const UTDataElement = _ref => {
84
117
  const infoClasses = "".concat(classes.info, " ").concat(orientation === ORIENTATION.VERTICAL && classes.vertical);
85
118
  const iconCollapseButtonClasses = "".concat(classes.iconCollapseButton, " ").concat(isCollapsed && classes.collapsed);
86
119
  const childrenClasses = "".concat(classes.children, " ").concat(isCollapsed ? classes.childrenCollapsed : classes.childrenExpanded, " ").concat(isTransitioning ? classes.childrenTransitioning : classes.childrenStatic);
87
- return /*#__PURE__*/React.createElement("div", {
88
- className: "".concat(classes.container, " ").concat(area ? classes.area : '', " ").concat(classes["padding".concat(capitalize(paddingVertical))]),
89
- "data-testid": dataTestId ? "".concat(dataTestId, ".").concat(dataElement.container) : undefined
90
- }, /*#__PURE__*/React.createElement("div", {
91
- className: contentClasses
92
- }, IconComponent && /*#__PURE__*/React.createElement(IconComponent, _extends({
93
- name: Icon,
94
- colorTheme: "gray",
95
- size: "var(--UT-dataElement-icon-size, 1.5rem)"
96
- }, iconProps)), /*#__PURE__*/React.createElement("div", {
97
- className: infoClasses
98
- }, (prefix || title || showBadge) && /*#__PURE__*/React.createElement("div", {
120
+ const infoContent = /*#__PURE__*/React.createElement(React.Fragment, null, (prefix || title || showBadge || children) && /*#__PURE__*/React.createElement("div", {
99
121
  className: classes.topInfo
100
122
  }, prefix && /*#__PURE__*/React.createElement(UTLabel, _extends({
101
123
  colorTheme: "gray"
@@ -104,21 +126,41 @@ const UTDataElement = _ref => {
104
126
  content: titleTooltip
105
127
  } : {}, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(UTLabel, _extends({
106
128
  colorTheme: "gray"
107
- }, titleProps), title))), showBadge && /*#__PURE__*/React.createElement(UTBadge, _extends({
129
+ }, titleProps), title))), children && /*#__PURE__*/React.createElement(UTIcon, {
130
+ className: iconCollapseButtonClasses,
131
+ colorTheme: "gray",
132
+ name: "IconChevronUp",
133
+ size: "var(--UT-dataElement-chevron-icon-size, 1.25rem)",
134
+ dataTestId: dataTestId ? "".concat(dataTestId, ".").concat(dataElement.collapseButton) : undefined
135
+ }), showBadge && /*#__PURE__*/React.createElement(UTBadge, _extends({
108
136
  colorTheme: "accent",
109
137
  className: classes.badge
110
- }, badgeProps), forceShowBadge ? null : badge)), DataComponent && DataComponent), action && /*#__PURE__*/React.createElement(MainAction, _extends({
111
- dataTestId: dataTestId
112
- }, action)), children && /*#__PURE__*/React.createElement(UTButton, {
113
- classNames: {
114
- icon: iconCollapseButtonClasses
115
- },
116
- Icon: "IconChevronUp",
138
+ }, badgeProps), forceShowBadge ? null : badge)), DataComponent && (isDataLabel ? DataComponent :
139
+ /*#__PURE__*/
140
+ // Sin role="button": este div solo corta la propagación del click/keydown hacia el toggle de colapso, no es un control propio.
141
+ React.createElement("div", {
142
+ onClick: stopDataPropagation,
143
+ onKeyDown: stopDataPropagation
144
+ }, DataComponent)));
145
+ return /*#__PURE__*/React.createElement("div", {
146
+ className: "".concat(classes.container, " ").concat(area ? classes.area : '', " ").concat(classes["padding".concat(capitalize(paddingVertical))]),
147
+ "data-testid": dataTestId ? "".concat(dataTestId, ".").concat(dataElement.container) : undefined
148
+ }, /*#__PURE__*/React.createElement("div", {
149
+ className: contentClasses
150
+ }, IconComponent && /*#__PURE__*/React.createElement(IconComponent, _extends({
151
+ name: Icon,
152
+ colorTheme: "gray",
153
+ size: "var(--UT-dataElement-icon-size, 1.5rem)"
154
+ }, iconProps)), children ? /*#__PURE__*/React.createElement(UTTouchableWithoutFeedback, {
155
+ className: "".concat(infoClasses, " ").concat(classes.clickable),
117
156
  onClick: toggleCollapsed,
118
- size: "small",
119
- variant: "text",
120
- dataTestId: dataTestId ? "".concat(dataTestId, ".").concat(dataElement.collapseButton) : undefined
121
- })), children && /*#__PURE__*/React.createElement("div", {
157
+ onKeyDown: handleInfoKeyDown,
158
+ "aria-expanded": !isCollapsed
159
+ }, infoContent) : /*#__PURE__*/React.createElement("div", {
160
+ className: infoClasses
161
+ }, infoContent), action && /*#__PURE__*/React.createElement(MainAction, _extends({
162
+ dataTestId: dataTestId
163
+ }, action))), children && /*#__PURE__*/React.createElement("div", {
122
164
  style: {
123
165
  maxHeight: contentHeight
124
166
  },
@@ -130,6 +172,10 @@ const UTDataElement = _ref => {
130
172
  UTDataElement.propTypes = {
131
173
  action: object,
132
174
  area: bool,
175
+ areaProps: shape({
176
+ colorTheme: string,
177
+ shade: string
178
+ }),
133
179
  badge: string,
134
180
  badgeProps: object,
135
181
  classes: objectOf(string),
@@ -137,6 +183,7 @@ UTDataElement.propTypes = {
137
183
  Data: oneOfType([element, string]),
138
184
  dataProps: object,
139
185
  dataTestId: string,
186
+ expanded: bool,
140
187
  forceShowBadge: bool,
141
188
  Icon: oneOfType([element, string]),
142
189
  iconProps: object,
@@ -33,6 +33,7 @@
33
33
  }
34
34
 
35
35
  .info {
36
+ align-items: stretch;
36
37
  display: flex;
37
38
  flex: 1;
38
39
  flex-direction: row;
@@ -40,6 +41,10 @@
40
41
  justify-content: space-between;
41
42
  }
42
43
 
44
+ .clickable {
45
+ cursor: pointer;
46
+ }
47
+
43
48
  .vertical {
44
49
  flex-direction: column;
45
50
  grid-gap: var(--UT-dataElement-content-gap-y, 0.5rem);
@@ -1,20 +1,22 @@
1
- import { COLOR_THEMES } from '../../constants/Palette';
2
- export const backgroundColor = (theme, area) => {
3
- var _theme$Palette;
4
- const colorTheme = COLOR_THEMES.light;
5
- const actionPaletteColors = ((_theme$Palette = theme.Palette) === null || _theme$Palette === void 0 ? void 0 : _theme$Palette.actions) || theme.Palette;
6
- const paletteColors = theme.Palette;
7
- const areaColor = actionPaletteColors[colorTheme] || paletteColors[colorTheme];
1
+ import { COLOR_THEMES, COLOR_SHADES, VALID_PALETTE_COLOR_THEMES } from '../../constants/Palette';
2
+ export const backgroundColor = function (theme, area) {
3
+ var _theme$Palette, _theme$Palette2;
4
+ let areaProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5
+ const requestedColorTheme = areaProps.colorTheme || COLOR_THEMES.light;
6
+ const colorTheme = VALID_PALETTE_COLOR_THEMES.has(requestedColorTheme) ? requestedColorTheme : COLOR_THEMES.light;
7
+ const areaColor = ((_theme$Palette = theme.Palette) === null || _theme$Palette === void 0 || (_theme$Palette = _theme$Palette.actions) === null || _theme$Palette === void 0 ? void 0 : _theme$Palette[colorTheme]) || ((_theme$Palette2 = theme.Palette) === null || _theme$Palette2 === void 0 ? void 0 : _theme$Palette2[colorTheme]);
8
+ const shade = areaProps.shade || (COLOR_THEMES.light === colorTheme ? COLOR_SHADES.shade03 : COLOR_SHADES.shade01);
8
9
  return {
9
- backgroundColor: area ? areaColor['03'] : 'transparent'
10
+ backgroundColor: area ? areaColor === null || areaColor === void 0 ? void 0 : areaColor[shade] : 'transparent'
10
11
  };
11
12
  };
12
13
  export const retrieveStyle = _ref => {
13
14
  let {
14
15
  area,
15
- theme
16
+ theme,
17
+ areaProps
16
18
  } = _ref;
17
- const areaBackgroundColor = backgroundColor(theme, area);
19
+ const areaBackgroundColor = backgroundColor(theme, area, areaProps);
18
20
  return {
19
21
  area: {
20
22
  ...areaBackgroundColor,
@@ -2,7 +2,7 @@ function _extends() { return _extends = Object.assign ? Object.assign.bind() : f
2
2
  import React from 'react';
3
3
  import { useArgs } from '@storybook/preview-api';
4
4
  import { joinArgTypes } from 'stories/utils';
5
- import { SPACING } from '../UTCheckbox/versions/V1/constants';
5
+ import { SPACING } from './versions/V1/constants';
6
6
  import { RADIO_VARIANTS } from './versions/V1/components/Radio/constants';
7
7
  import UTRadioGroup from '.';
8
8
  const defaultOptions = [{
@@ -312,6 +312,102 @@ export default {
312
312
  eq: 'V1'
313
313
  }
314
314
  },
315
+ area: {
316
+ control: 'boolean',
317
+ description: 'Muestra un área de fondo alrededor del grupo de opciones (V1 only).',
318
+ table: {
319
+ defaultValue: {
320
+ summary: 'false'
321
+ },
322
+ type: {
323
+ summary: 'bool'
324
+ }
325
+ },
326
+ if: {
327
+ arg: 'version',
328
+ eq: 'V1'
329
+ }
330
+ },
331
+ areaProps: {
332
+ control: 'object',
333
+ description: 'Personalización del área de fondo: `colorTheme`, `shade`, `borderColorTheme`, `borderShade` (V1 only). Sin `colorTheme` no se agrega fondo; sin `borderColorTheme` no se agrega borde.',
334
+ table: {
335
+ defaultValue: {
336
+ summary: 'undefined'
337
+ },
338
+ type: {
339
+ summary: 'object'
340
+ }
341
+ },
342
+ if: {
343
+ arg: 'version',
344
+ eq: 'V1'
345
+ }
346
+ },
347
+ iconProps: {
348
+ control: 'object',
349
+ description: 'Props adicionales para el ícono de cada opción (V1 only).',
350
+ table: {
351
+ defaultValue: {
352
+ summary: 'undefined'
353
+ },
354
+ type: {
355
+ summary: 'object'
356
+ }
357
+ },
358
+ if: {
359
+ arg: 'version',
360
+ eq: 'V1'
361
+ }
362
+ },
363
+ iconSelectedProps: {
364
+ control: 'object',
365
+ description: 'Props adicionales para el ícono de la opción seleccionada, sobrescriben `iconProps` (V1 only).',
366
+ table: {
367
+ defaultValue: {
368
+ summary: 'undefined'
369
+ },
370
+ type: {
371
+ summary: 'object'
372
+ }
373
+ },
374
+ if: {
375
+ arg: 'version',
376
+ eq: 'V1'
377
+ }
378
+ },
379
+ nameProps: {
380
+ control: 'object',
381
+ description: 'Props adicionales para el UTLabel del nombre de cada opción (V1 only).',
382
+ table: {
383
+ defaultValue: {
384
+ summary: 'undefined'
385
+ },
386
+ type: {
387
+ summary: 'object'
388
+ }
389
+ },
390
+ if: {
391
+ arg: 'version',
392
+ eq: 'V1'
393
+ }
394
+ },
395
+ nameSelectedProps: {
396
+ control: 'object',
397
+ description: 'Props adicionales para el UTLabel del nombre de la opción seleccionada, sobrescriben `nameProps` (V1 only).',
398
+ table: {
399
+ defaultValue: {
400
+ summary: 'undefined'
401
+ },
402
+ type: {
403
+ summary: 'object'
404
+ }
405
+ },
406
+ if: {
407
+ arg: 'version',
408
+ eq: 'V1'
409
+ }
410
+ },
315
411
  dataTestId: {
316
412
  control: 'text',
317
413
  description: 'ID de prueba para el elemento raíz.',
@@ -419,8 +515,8 @@ export const Playground = {
419
515
  options: defaultOptions,
420
516
  title: 'Selecciona una opción',
421
517
  value: '',
422
- horizontalSpacing: 'medium',
423
- verticalSpacing: 'medium',
518
+ horizontalSpacing: SPACING.MEDIUM,
519
+ verticalSpacing: SPACING.MEDIUM,
424
520
  reversed: false,
425
521
  required: false,
426
522
  disabled: false,
@@ -476,6 +572,30 @@ export const V1ButtonVariant = {
476
572
  },
477
573
  name: 'V1 - Variante Button'
478
574
  };
575
+ export const V1WithArea = {
576
+ render: V1Template,
577
+ args: {
578
+ version: 'V1',
579
+ options: defaultOptions,
580
+ title: 'Opciones con Área de Fondo',
581
+ value: '',
582
+ area: true,
583
+ areaProps: {
584
+ colorTheme: 'light',
585
+ borderColorTheme: 'gray'
586
+ },
587
+ iconProps: {
588
+ colorTheme: 'dark'
589
+ },
590
+ iconSelectedProps: {
591
+ colorTheme: 'accent'
592
+ },
593
+ nameSelectedProps: {
594
+ weight: 'bold'
595
+ }
596
+ },
597
+ name: 'V1 - Con Área de Fondo'
598
+ };
479
599
 
480
600
  // V0 Stories
481
601
  export const V0Basic = {
@@ -2,6 +2,7 @@ function _extends() { return _extends = Object.assign ? Object.assign.bind() : f
2
2
  import React from 'react';
3
3
  import MaterialRadio from '@material-ui/core/Radio';
4
4
  import { object, bool, func, string } from 'prop-types';
5
+ import UTTouchableWithoutFeedback from '../../../../../UTTouchableWithoutFeedback';
5
6
  import UTIcon from '../../../../../UTIcon';
6
7
  import UTLabel from '../../../../../UTLabel';
7
8
  import WithTheme from '../../../../../WithTheme';
@@ -14,18 +15,20 @@ const Radio = _ref => {
14
15
  descriptionProps = {},
15
16
  disabled,
16
17
  icon,
18
+ iconProps = {},
19
+ iconSelectedProps = {},
17
20
  name,
18
21
  nameProps = {},
22
+ nameSelectedProps = {},
19
23
  onChange,
20
24
  prefix,
21
25
  selected,
22
26
  suffix,
23
27
  variant = RADIO_VARIANTS.DEFAULT
24
28
  } = _ref;
25
- return /*#__PURE__*/React.createElement("div", {
29
+ return /*#__PURE__*/React.createElement(UTTouchableWithoutFeedback, {
26
30
  className: classes.root,
27
- onClick: () => !disabled && onChange(),
28
- role: "button"
31
+ onClick: () => !disabled && onChange()
29
32
  }, variant === RADIO_VARIANTS.DEFAULT && /*#__PURE__*/React.createElement(MaterialRadio, {
30
33
  checked: selected,
31
34
  onChange: onChange,
@@ -33,11 +36,11 @@ const Radio = _ref => {
33
36
  disabled: disabled
34
37
  }), /*#__PURE__*/React.createElement("div", {
35
38
  className: classes.content
36
- }, icon && /*#__PURE__*/React.createElement(UTIcon, {
39
+ }, icon && /*#__PURE__*/React.createElement(UTIcon, _extends({
37
40
  name: icon,
38
41
  colorTheme: selected ? 'accent' : 'dark',
39
42
  size: ICON_SIZES[variant]
40
- }), /*#__PURE__*/React.createElement("div", {
43
+ }, iconProps, selected ? iconSelectedProps : {})), /*#__PURE__*/React.createElement("div", {
41
44
  className: classes.contentContainer
42
45
  }, /*#__PURE__*/React.createElement("div", {
43
46
  className: classes.content
@@ -45,7 +48,7 @@ const Radio = _ref => {
45
48
  colorTheme: "gray"
46
49
  }, prefix), name && /*#__PURE__*/React.createElement(UTLabel, _extends({
47
50
  colorTheme: selected ? 'accent' : 'dark'
48
- }, nameProps), name), suffix && /*#__PURE__*/React.createElement(UTLabel, {
51
+ }, nameProps, selected ? nameSelectedProps : {}), name), suffix && /*#__PURE__*/React.createElement(UTLabel, {
49
52
  colorTheme: "gray",
50
53
  variant: "small",
51
54
  weight: "medium"
@@ -63,8 +66,11 @@ Radio.propTypes = {
63
66
  descriptionProps: object,
64
67
  disabled: bool,
65
68
  icon: string,
69
+ iconProps: object,
70
+ iconSelectedProps: object,
66
71
  name: string,
67
72
  nameProps: object,
73
+ nameSelectedProps: object,
68
74
  onChange: func,
69
75
  prefix: string,
70
76
  selected: bool,
@@ -1,4 +1,5 @@
1
1
  export const SPACING = {
2
+ NONE: 'none',
2
3
  SMALL: 'small',
3
4
  MEDIUM: 'medium'
4
5
  };
@@ -1,6 +1,6 @@
1
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
2
  import React, { useMemo } from 'react';
3
- import { arrayOf, bool, func, objectOf, shape, string, object } from 'prop-types';
3
+ import { arrayOf, bool, func, objectOf, oneOf, shape, string, object } from 'prop-types';
4
4
  import RadioGroup from '@material-ui/core/RadioGroup';
5
5
  import { buttonTypes } from '../../../../types/buttonTypes';
6
6
  import UTFieldLabel from '../../../UTFieldLabel';
@@ -9,19 +9,25 @@ import { formatErrorToValidation } from '../../../UTValidation/utils';
9
9
  import UTValidation from '../../../UTValidation';
10
10
  import Radio from './components/Radio';
11
11
  import styles from './styles.module.scss';
12
- import { NO_CATEGORY } from './constants';
12
+ import { getAreaStyle } from './utils';
13
+ import { NO_CATEGORY, SPACING } from './constants';
13
14
  const UTRadioGroup = _ref => {
14
15
  let {
15
16
  actions,
17
+ area,
18
+ areaProps,
16
19
  classNames = {},
17
20
  dataTestId,
18
21
  descriptionProps,
19
22
  disabled,
20
23
  error,
21
24
  errorDataTestId,
22
- horizontalSpacing = 'medium',
25
+ horizontalSpacing = SPACING.MEDIUM,
26
+ iconProps,
27
+ iconSelectedProps,
23
28
  itemDataTestId,
24
29
  nameProps,
30
+ nameSelectedProps,
25
31
  onChange = () => {},
26
32
  options,
27
33
  required,
@@ -29,7 +35,7 @@ const UTRadioGroup = _ref => {
29
35
  title,
30
36
  value = null,
31
37
  variant,
32
- verticalSpacing = 'medium'
38
+ verticalSpacing = SPACING.MEDIUM
33
39
  } = _ref;
34
40
  const categorizedOptions = useMemo(() => {
35
41
  const optionsGrouped = options.reduce((groupedOptions, option) => {
@@ -52,11 +58,13 @@ const UTRadioGroup = _ref => {
52
58
  });
53
59
  }, [options]);
54
60
  const validationData = useMemo(() => error && formatErrorToValidation(error), [error]);
61
+ const areaStyle = useMemo(() => getAreaStyle(area, areaProps), [area, areaProps]);
55
62
  return /*#__PURE__*/React.createElement("div", {
56
- className: "".concat(styles.container, " ").concat(classNames.root),
57
- "data-testid": dataTestId
63
+ className: "".concat(styles.container, " ").concat(classNames.root || ''),
64
+ "data-testid": dataTestId,
65
+ style: areaStyle
58
66
  }, title && /*#__PURE__*/React.createElement("div", {
59
- className: "".concat(styles.headerContainer, " ").concat(classNames.header)
67
+ className: "".concat(styles.headerContainer, " ").concat(classNames.header || '')
60
68
  }, title && /*#__PURE__*/React.createElement(UTFieldLabel, {
61
69
  actions: actions,
62
70
  required: required
@@ -77,8 +85,11 @@ const UTRadioGroup = _ref => {
77
85
  dataTestId: itemDataTestId ? "".concat(itemDataTestId, ".category_").concat(catIndex, ".").concat(index) : null,
78
86
  descriptionProps: descriptionProps,
79
87
  disabled: item.disabled || disabled,
88
+ iconProps: iconProps,
89
+ iconSelectedProps: iconSelectedProps,
80
90
  key: item.value,
81
91
  nameProps: nameProps,
92
+ nameSelectedProps: nameSelectedProps,
82
93
  onChange: () => onChange(item.value),
83
94
  reversed: reversed,
84
95
  selected: item.value === value,
@@ -92,15 +103,20 @@ const UTRadioGroup = _ref => {
92
103
  };
93
104
  UTRadioGroup.propTypes = {
94
105
  actions: arrayOf(buttonTypes),
106
+ area: bool,
107
+ areaProps: object,
95
108
  classNames: objectOf(string),
96
109
  dataTestId: string,
97
110
  descriptionProps: object,
98
111
  disabled: bool,
99
112
  error: string,
100
113
  errorDataTestId: string,
101
- horizontalSpacing: string,
114
+ horizontalSpacing: oneOf(Object.values(SPACING)),
115
+ iconProps: object,
116
+ iconSelectedProps: object,
102
117
  itemDataTestId: string,
103
118
  nameProps: object,
119
+ nameSelectedProps: object,
104
120
  onChange: func,
105
121
  options: arrayOf(shape({
106
122
  category: string,
@@ -115,6 +131,6 @@ UTRadioGroup.propTypes = {
115
131
  title: string,
116
132
  value: string,
117
133
  variant: string,
118
- verticalSpacing: string
134
+ verticalSpacing: oneOf(Object.values(SPACING))
119
135
  };
120
136
  export default UTRadioGroup;