@widergy/energy-ui 3.40.0 → 3.41.1

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## [3.41.1](https://github.com/widergy/energy-ui/compare/v3.41.0...v3.41.1) (2024-11-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add UTSelect and UTChecklist fixes ([#525](https://github.com/widergy/energy-ui/issues/525)) ([9547366](https://github.com/widergy/energy-ui/commit/954736685ca149c858d9cec88ed93ba522072f96))
7
+
8
+ # [3.41.0](https://github.com/widergy/energy-ui/compare/v3.40.0...v3.41.0) (2024-11-14)
9
+
10
+
11
+ ### Features
12
+
13
+ * minor adjustments ([163b21e](https://github.com/widergy/energy-ui/commit/163b21ec4d27c7e6185e7ca1fdcc8aac1ee454e3))
14
+ * utbutton props on panel ([1356c81](https://github.com/widergy/energy-ui/commit/1356c81fab15a0252d80b76c2f9d108a61d2bdd7))
15
+
1
16
  # [3.40.0](https://github.com/widergy/energy-ui/compare/v3.39.1...v3.40.0) (2024-11-13)
2
17
 
3
18
 
@@ -25,7 +25,7 @@ const UTBadge = _ref => {
25
25
  const {
26
26
  Component,
27
27
  componentProps
28
- } = (0, _componentUtils.childrenExists)(children) ? {
28
+ } = (0, _componentUtils.valueExists)(children) ? {
29
29
  Component: _UTLabel.default,
30
30
  componentProps: {
31
31
  colorTheme: textColorTheme,
@@ -39,7 +39,7 @@ const retrieveStyle = _ref => {
39
39
  children
40
40
  } = _ref;
41
41
  const baseTheme = baseButtonTheme();
42
- const textTheme = (0, _componentUtils.childrenExists)(children) ? baseTheme.text : {};
42
+ const textTheme = (0, _componentUtils.valueExists)(children) ? baseTheme.text : {};
43
43
  const variantTheme = variantsColorTheme(theme, colorTheme);
44
44
  return {
45
45
  root: {
@@ -92,6 +92,7 @@ const UTBaseInputField = _ref => {
92
92
  }, [error, disabled, readOnly, focused]);
93
93
  return /*#__PURE__*/_react.default.createElement(_TextField.default, _extends({
94
94
  autoComplete: "new-password",
95
+ className: classes.container,
95
96
  disabled: disabled || readOnly,
96
97
  error: error,
97
98
  id: id,
@@ -91,7 +91,7 @@ const retrieveStyle = props => {
91
91
  paddingRight: 0
92
92
  }),
93
93
  '&:hover': {
94
- backgroundColor: variant === 'transparent' && error ? theme.Palette.error['02'] : !readOnly && theme.Palette.light['03']
94
+ backgroundColor: variant === 'gray' ? theme.Palette.light['05'] : variant === 'transparent' && error ? theme.Palette.error['02'] : !readOnly && theme.Palette.light['03']
95
95
  }
96
96
  },
97
97
  inputContainer: {
@@ -6,22 +6,24 @@
6
6
 
7
7
  ## Props
8
8
 
9
- | Name | Type | Default | Description |
10
- | ----------------- | ---------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
11
- | classNames | objectOf(string) | | Custom class names to apply to different elements of the checklist (`root`, `header`, `checkboxesContainer`, `item`, `selectAll`). |
12
- | error | string | | Error message to display. |
13
- | horizontalSpacing | string | medium | Spacing between the checkbox and the title horizontally. |
14
- | isSimple | bool | false | Simplifies the selection process to only allow single checkbox selection. |
15
- | onChange | func.isRequired | | Function to call when the selection changes. |
16
- | options | arrayOf(shape) | | Array of options to be displayed as checkboxes. Each option is an object with `label`, `value`, `disabled`, `checked`, and optionally `category`. |
17
- | required | bool | false | Indicates if the checklist is required. |
18
- | reversed | bool | false | If true, reverses the order of title and checkbox. |
19
- | selectAllLabel | string | | Label for the "Select All" checkbox. |
20
- | showSelectAll | bool | true | Determines whether to show the "Select All" checkbox. |
21
- | title | string | | Title for the checklist. |
22
- | value | arrayOf(string) | [] | Array of selected values. |
23
- | variant | string | | Variant style for the checklist. |
24
- | verticalSpacing | string | medium | Spacing between the checkbox items vertically. |
9
+ | Name | Type | Default | Description |
10
+ | ----------------- | ---------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
11
+ | classNames | objectOf(string) | | Custom class names to apply to different elements of the checklist (`root`, `header`, `checkboxesContainer`, `item`, `selectAll`). |
12
+ | disabled | bool | false | Disables all checkboxes in the checklist when true. |
13
+ | |
14
+ | error | string | | Error message to display. |
15
+ | horizontalSpacing | string | medium | Spacing between the checkbox and the title horizontally. |
16
+ | isSimple | bool | false | Simplifies the selection process to only allow single checkbox selection. |
17
+ | onChange | func.isRequired | | Function to call when the selection changes. |
18
+ | options | arrayOf(shape) | | Array of options to be displayed as checkboxes. Each option is an object with `name`, `value`, `disabled`, `checked`, and optionally `category`. |
19
+ | required | bool | false | Indicates if the checklist is required. |
20
+ | reversed | bool | false | If true, reverses the order of title and checkbox. |
21
+ | selectAllLabel | string | | Label for the "Select All" checkbox. |
22
+ | showSelectAll | bool | true | Determines whether to show the "Select All" checkbox. |
23
+ | title | string | | Title for the checklist. |
24
+ | value | arrayOf(string) | [] | Array of selected values. |
25
+ | variant | string | | Variant style for the checklist. |
26
+ | verticalSpacing | string | medium | Spacing between the checkbox items vertically. |
25
27
 
26
28
  ### Option Object
27
29
 
@@ -44,9 +46,9 @@ import React from 'react';
44
46
  import UTCheckList from './UTCheckList';
45
47
 
46
48
  const options = [
47
- { label: 'Option 1', value: '1' },
48
- { label: 'Option 2', value: '2' },
49
- { label: 'Option 3', value: '3', disabled: true, checked: true }
49
+ { name: 'Option 1', value: '1' },
50
+ { name: 'Option 2', value: '2' },
51
+ { name: 'Option 3', value: '3', disabled: true, checked: true }
50
52
  ];
51
53
 
52
54
  const Example = () => {
@@ -75,10 +77,10 @@ import React from 'react';
75
77
  import UTCheckList from './UTCheckList';
76
78
 
77
79
  const options = [
78
- { label: 'Option 1', value: '1' },
79
- { label: 'Option 2', value: '2', category: 'Group A' },
80
- { label: 'Option 3', value: '3', category: 'Group B', disabled: true },
81
- { label: 'Option 4', value: '4', category: 'Group A' }
80
+ { name: 'Option 1', value: '1' },
81
+ { name: 'Option 2', value: '2', category: 'Group A' },
82
+ { name: 'Option 3', value: '3', category: 'Group B', disabled: true },
83
+ { name: 'Option 4', value: '4', category: 'Group A' }
82
84
  ];
83
85
 
84
86
  const Example = () => {
@@ -113,8 +115,8 @@ const customStyles = {
113
115
 
114
116
  const Example = () => {
115
117
  const options = [
116
- { label: 'Option 1', value: '1' },
117
- { label: 'Option 2', value: '2' }
118
+ { name: 'Option 1', value: '1' },
119
+ { name: 'Option 2', value: '2' }
118
120
  ];
119
121
 
120
122
  const [selectedOptions, setSelectedOptions] = React.useState([]);
@@ -22,6 +22,7 @@ const UTCheckList = _ref => {
22
22
  let {
23
23
  classNames = {},
24
24
  dataTestId,
25
+ disabled,
25
26
  error,
26
27
  horizontalSpacing = 'medium',
27
28
  isSimple = false,
@@ -77,7 +78,8 @@ const UTCheckList = _ref => {
77
78
  if (isSimple) {
78
79
  onChange([receivedValue]);
79
80
  } else {
80
- const newValues = !(value !== null && value !== void 0 && value.includes(receivedValue)) ? [...(value || []), receivedValue] : value.filter(elem => elem !== receivedValue);
81
+ var _value$some;
82
+ const newValues = value !== null && value !== void 0 && (_value$some = value.some) !== null && _value$some !== void 0 && _value$some.call(value, v => v === receivedValue) ? value.filter(elem => elem !== receivedValue) : [...(value || []), receivedValue];
81
83
  onChange(newValues);
82
84
  }
83
85
  }, [value, onChange, isSimple]);
@@ -96,11 +98,12 @@ const UTCheckList = _ref => {
96
98
  })), /*#__PURE__*/_react.default.createElement("div", {
97
99
  className: "".concat(_stylesModule.default.checkboxesContainer, " ").concat(smallVerticalSpacingClass, " ").concat(variant === _constants.BUTTON_VARIANT && _stylesModule.default.buttonVariant, " ").concat(classNames.checkboxesContainer)
98
100
  }, showSelectAll && !isSimple && /*#__PURE__*/_react.default.createElement(_UTCheckbox.default, {
101
+ className: classNames.selectAll,
102
+ disabled: disabled,
99
103
  indeterminate: isIndeterminate,
100
104
  onChange: handleCheckAll,
101
105
  reversed: reversedBasedOnVariant,
102
106
  spacing: horizontalSpacing,
103
- className: classNames.selectAll,
104
107
  title: selectAllLabel,
105
108
  value: areAllSelected,
106
109
  variant: variant,
@@ -117,13 +120,13 @@ const UTCheckList = _ref => {
117
120
  weight: "medium"
118
121
  }, category.toUpperCase()), categoryOptions.map(item => /*#__PURE__*/_react.default.createElement(_UTCheckbox.default, {
119
122
  classNames: classNames.item,
120
- disabled: item.disabled,
123
+ disabled: item.disabled || disabled,
121
124
  isSimple: isSimple,
122
125
  key: item.value,
123
126
  onChange: () => handleChange(item.value),
124
127
  reversed: isSimple ? reversedBasedOnVariant : reversed,
125
128
  spacing: horizontalSpacing,
126
- title: item.label,
129
+ title: item.name,
127
130
  value: (0, _utils2.isChecked)(item, value),
128
131
  variant: variant,
129
132
  version: "V1"
@@ -133,6 +136,7 @@ const UTCheckList = _ref => {
133
136
  UTCheckList.propTypes = {
134
137
  classNames: (0, _propTypes.objectOf)(_propTypes.string),
135
138
  dataTestId: _propTypes.string,
139
+ disabled: _propTypes.bool,
136
140
  error: _propTypes.string,
137
141
  horizontalSpacing: _propTypes.string,
138
142
  isSimple: _propTypes.bool,
@@ -140,7 +144,7 @@ UTCheckList.propTypes = {
140
144
  options: (0, _propTypes.arrayOf)((0, _propTypes.shape)({
141
145
  checked: _propTypes.bool,
142
146
  disabled: _propTypes.bool,
143
- label: _propTypes.string,
147
+ name: _propTypes.string,
144
148
  value: _propTypes.string,
145
149
  category: _propTypes.string
146
150
  })),
@@ -6,7 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.isChecked = exports.getPropValueBasedOnVariant = exports.convertIfIsString = void 0;
7
7
  var _lodash = require("lodash");
8
8
  var _constants = require("../../../UTCheckbox/versions/V1/constants");
9
- const isChecked = (item, inputValue) => inputValue && !!(inputValue !== null && inputValue !== void 0 && inputValue.find(elem => elem === item.value)) || item.disabled && item.checked;
9
+ const isChecked = (item, inputValue) => {
10
+ var _inputValue$some;
11
+ return (inputValue === null || inputValue === void 0 || (_inputValue$some = inputValue.some) === null || _inputValue$some === void 0 ? void 0 : _inputValue$some.call(inputValue, elem => elem === item.value)) || item.disabled && item.checked;
12
+ };
10
13
  exports.isChecked = isChecked;
11
14
  const convertIfIsString = value => (0, _lodash.isString)(value) ? value.length === 0 ? [] : JSON.parse(value.replace(/'/g, '"')) : value;
12
15
  exports.convertIfIsString = convertIfIsString;
@@ -34,11 +34,11 @@ const UTCheckbox = _ref => {
34
34
  withMarkdown
35
35
  } = _ref;
36
36
  const classes = (0, _react.useMemo)(() => (0, _classesUtils.mergeClasses)(theme, classNames), [classNames, theme]);
37
- const iconName = (0, _react.useMemo)(() => indeterminate ? _constants.INDETERMINATE_ICON : value ? _constants.CHECKED_ICON : '', [indeterminate, value]);
37
+ const iconName = (0, _react.useMemo)(() => indeterminate ? _constants.INDETERMINATE_ICON : value === true ? _constants.CHECKED_ICON : '', [indeterminate, value]);
38
38
  const handlePress = (0, _react.useCallback)(() => {
39
- if (!disabled && onChange) onChange(!value);
39
+ if (!disabled && onChange) onChange(value === false);
40
40
  }, [disabled, onChange, value]);
41
- const shouldHighlightLabel = value && variant === _constants.BUTTON_VARIANT;
41
+ const shouldHighlightLabel = value === true && variant === _constants.BUTTON_VARIANT;
42
42
  const touchableProps = {
43
43
  onMouseDown: handlePress,
44
44
  disabled
@@ -9,7 +9,7 @@ const MEDIUM_SPACING = 16;
9
9
  const SMALL_SPACING = 8;
10
10
  const baseCheckBoxTheme = theme => ({
11
11
  container: {
12
- alignItems: 'center',
12
+ alignItems: 'center !important',
13
13
  display: 'flex'
14
14
  },
15
15
  iconContainer: {
@@ -56,7 +56,7 @@ const conditionalStyles = _ref => {
56
56
  })
57
57
  },
58
58
  iconContainer: {
59
- ...((value || indeterminate) && {
59
+ ...((value === true || indeterminate) && {
60
60
  backgroundColor: theme.Palette.accent['04'],
61
61
  borderColor: theme.Palette.accent['04']
62
62
  })
@@ -9,8 +9,8 @@ var _propTypes = require("prop-types");
9
9
  var _reactMarkdown = _interopRequireDefault(require("react-markdown"));
10
10
  var _remarkBreaks = _interopRequireDefault(require("remark-breaks"));
11
11
  var _rehypeRaw = _interopRequireDefault(require("rehype-raw"));
12
- var _componentUtils = require("../../utils/componentUtils");
13
12
  var _classesUtils = require("../../utils/classesUtils");
13
+ var _componentUtils = require("../../utils/componentUtils");
14
14
  var _UTSkeleton = _interopRequireDefault(require("../UTSkeleton"));
15
15
  var _WithTheme = _interopRequireDefault(require("../WithTheme"));
16
16
  var _constants = require("./constants");
@@ -31,7 +31,7 @@ const UTLabel = _ref => {
31
31
  variant,
32
32
  withMarkdown
33
33
  } = _ref;
34
- if (!(0, _componentUtils.childrenExists)(children)) return null;
34
+ if (!(0, _componentUtils.valueExists)(children)) return null;
35
35
  const Component = _constants.VARIANTS[variant] || _constants.VARIANTS[_constants.DEFAULT_PROPS.variant];
36
36
  const classes = (0, _react.useMemo)(() => (0, _classesUtils.mergeClasses)(theme, {
37
37
  className
@@ -4,33 +4,33 @@ Component used for displaying a side panel.
4
4
 
5
5
  ## Props
6
6
 
7
- | Name | Type | Default | Description |
8
- | :-------------------------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9
- | children | node | | Component content |
10
- | classes | object | | Classes returned by UTPanel own[theme](./theme.js#L40) `retrieveStyle` and classes received from props. |
11
- | classNames | object | | Overrides the default panel theme. |
12
- | collapsableHeader | bool | false | Indicates if "header items" section is collapsible. |
13
- | currentStep | number | 1 | Workflow step number used to show the current progress in the UTProgressBar |
14
- | disableScrollbar | bool | false | Render the children without scrollbar |
15
- | HeaderComponent | node | | Custom header to render. |
16
- | headerItems | array | | Array of items (object) to show in "header items" section. Each item should have: "title" - String, "icon" - String, "value" - String |
17
- | headerMainActionButton | object | | Object with header main button details: "callBack" - func // "colorTheme" - string - deafult: 'primary' // "text" - string // "variant" - string - default: 'semitransparent' |
18
- | headerSecondaryActionButton | object | | Object with header secondary button details:<br /> "callBack" - func // "colorTheme" - string - default: "success" // "text" - string // "variant" - string - ddefault: "filled" |
19
- | hideCloseButton | bool | false | Indicates whether the close button is hide or not |
20
- | hideHeader | bool | false | Indicates whether the entire header is hide or not |
21
- | hideMainButton | bool | false | Indicates whether the main (bottom) button is hide or not |
22
- | isWorkflow | bool | false | Indicates if the panel children's content a workflow. This prop activates the progress bar. |
23
- | mainButton | object | | [UTButton props](https://github.com/widergy/Energy-UI/tree/master/src/lib/components/UTButton) |
24
- | modalProps | object | | Material UI[modal props](https://v4.mui.com/api/modal/) |
25
- | onClose | func | | Callback to execute when closing panel. |
26
- | onEndReachedCallback | func | | Callback to execute when reaching the end of the vertical scroll |
27
- | onOpen | func | () => {} | Callback to execute when opening panel. |
28
- | open | bool | | Indicates whether the panel is open or not |
29
- | panelSide | string | | Indicates panel side. |
30
- | perfectScrollbarOptions | object | | [Perfect scrollbar](https://www.npmjs.com/package/react-perfect-scrollbar) props |
31
- | singleHeaderItemsColumn | bool | false | Indicates whether the header items are shown in a single column or not |
32
- | size | string | 'M' | Indicates the size of panel. Currently we have two options:<br /> L -> 800px<br /> M -> 450px |
33
- | stepsCount | Number | | Indicates the total steps in case of workflow |
34
- | subtitle | string | | Subtitle to show |
35
- | title | string | | Title to show |
36
- | titleProps | object | {} | UTLabel props for title. Default props: variant="title2" weight="medium" |
7
+ | Name | Type | Default | Description |
8
+ | :-------------------------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9
+ | children | node | | Component content |
10
+ | classes | object | | Classes returned by UTPanel own[theme](./theme.js#L40) `retrieveStyle` and classes received from props. |
11
+ | classNames | object | | Overrides the default panel theme. headerMainActionButton |
12
+ | collapsableHeader | bool | false | Indicates if "header items" section is collapsible. |
13
+ | currentStep | number | 1 | Workflow step number used to show the current progress in the UTProgressBar |
14
+ | disableScrollbar | bool | false | Render the children without scrollbar |
15
+ | HeaderComponent | node | | Custom header to render. |
16
+ | headerItems | array | | Array of items (object) to show in "header items" section. Each item should have: "title" - String, "icon" - String, "value" - String |
17
+ | headerMainActionButton | object | | Object with header main button details: "colorTheme" - string - deafult: 'primary' // "variant" - string - default: 'semitransparent'<br />// This prop will be spread so that it supports any UTButton props. |
18
+ | headerSecondaryActionButton | object | | Object with header secondary button details: "colorTheme" - string - default: "success" // "variant" - string - default: "filled" // This prop will be spread so that it supports any UTButton props. |
19
+ | hideCloseButton | bool | false | Indicates whether the close button is hide or not |
20
+ | hideHeader | bool | false | Indicates whether the entire header is hide or not |
21
+ | hideMainButton | bool | false | Indicates whether the main (bottom) button is hide or not |
22
+ | isWorkflow | bool | false | Indicates if the panel children's content a workflow. This prop activates the progress bar. |
23
+ | mainButton | object | | [UTButton props](https://github.com/widergy/Energy-UI/tree/master/src/lib/components/UTButton) |
24
+ | modalProps | object | | Material UI[modal props](https://v4.mui.com/api/modal/) |
25
+ | onClose | func | | Callback to execute when closing panel. |
26
+ | onEndReachedCallback | func | | Callback to execute when reaching the end of the vertical scroll |
27
+ | onOpen | func | () => {} | Callback to execute when opening panel. |
28
+ | open | bool | | Indicates whether the panel is open or not |
29
+ | panelSide | string | | Indicates panel side. |
30
+ | perfectScrollbarOptions | object | | [Perfect scrollbar](https://www.npmjs.com/package/react-perfect-scrollbar) props |
31
+ | singleHeaderItemsColumn | bool | false | Indicates whether the header items are shown in a single column or not |
32
+ | size | string | 'M' | Indicates the size of panel. Currently we have two options:<br /> L -> 800px<br /> M -> 450px |
33
+ | stepsCount | Number | | Indicates the total steps in case of workflow |
34
+ | subtitle | string | | Subtitle to show |
35
+ | title | string | | Title to show |
36
+ | titleProps | object | {} | UTLabel props for title. Default props: variant="title2" weight="medium" |
@@ -122,15 +122,13 @@ const UTPanel = _ref => {
122
122
  colorTheme: "gray"
123
123
  }, subtitle))), /*#__PURE__*/_react.default.createElement("div", {
124
124
  className: _stylesModule.default.headerRightArea
125
- }, !(0, _isEmpty.default)(headerSecondaryActionButton) && /*#__PURE__*/_react.default.createElement(_UTButton.default, {
126
- colorTheme: headerSecondaryActionButton.colorTheme || 'primary',
127
- onClick: headerSecondaryActionButton.callBack,
128
- variant: headerSecondaryActionButton.variant || 'semitransparent'
129
- }, headerSecondaryActionButton.text), !(0, _isEmpty.default)(headerMainActionButton) && /*#__PURE__*/_react.default.createElement(_UTButton.default, {
130
- colorTheme: headerMainActionButton.colorTheme || 'success',
131
- onClick: headerMainActionButton.callBack,
132
- variant: headerMainActionButton.variant || 'filled'
133
- }, headerMainActionButton.text)))), !(0, _isEmpty.default)(headerItems) && /*#__PURE__*/_react.default.createElement("div", {
125
+ }, !(0, _isEmpty.default)(headerSecondaryActionButton) && /*#__PURE__*/_react.default.createElement(_UTButton.default, _extends({
126
+ colorTheme: "primary",
127
+ variant: "semitransparent"
128
+ }, headerSecondaryActionButton), headerSecondaryActionButton.text), !(0, _isEmpty.default)(headerMainActionButton) && /*#__PURE__*/_react.default.createElement(_UTButton.default, _extends({
129
+ colorTheme: "success",
130
+ variant: "filled"
131
+ }, headerMainActionButton), headerMainActionButton.text)))), !(0, _isEmpty.default)(headerItems) && /*#__PURE__*/_react.default.createElement("div", {
134
132
  className: "".concat(_stylesModule.default.headerItemsContainer, " \n ").concat(collapseHeader ? _stylesModule.default.expandedContainer : _stylesModule.default.collapsedContainer, " \n ").concat(singleHeaderItemsColumn && _stylesModule.default.singleHeaderItemsColumn || '')
135
133
  }, headerItems.map(_DataItem.default)), /*#__PURE__*/_react.default.createElement("div", {
136
134
  className: "".concat(_stylesModule.default.bodyContainer, " ").concat(classes.bodyContainer)
@@ -10,6 +10,7 @@ var _constants = require("../UTBaseInputField/constants");
10
10
  var _UTBaseInputField = _interopRequireDefault(require("../UTBaseInputField"));
11
11
  var _WithTheme = _interopRequireDefault(require("../WithTheme"));
12
12
  var _theme = require("./theme");
13
+ var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
15
  const UTSearchField = _ref => {
15
16
  let {
@@ -51,6 +52,10 @@ const UTSearchField = _ref => {
51
52
  }] : [];
52
53
  return /*#__PURE__*/_react.default.createElement(_UTBaseInputField.default, {
53
54
  alwaysShowPlaceholder: true,
55
+ classNames: {
56
+ container: "".concat(_stylesModule.default.container, " ").concat(className),
57
+ input: classes.input
58
+ },
54
59
  dataTestId: dataTestId,
55
60
  disabled: disabled,
56
61
  id: id,
@@ -61,10 +66,6 @@ const UTSearchField = _ref => {
61
66
  onFocus: onFocus,
62
67
  placeholder: placeholder,
63
68
  rightAdornments: rightAdornments,
64
- classNames: {
65
- root: className,
66
- input: classes.input
67
- },
68
69
  type: type,
69
70
  value: value,
70
71
  variant: variant
@@ -0,0 +1,3 @@
1
+ .container {
2
+ width: 100%;
3
+ }
@@ -17,7 +17,7 @@
17
17
  | noMatchesText | string | | Text to display when no matches are found in the search. |
18
18
  | onChange | func | | Function to call when the selected value(s) change. |
19
19
  | onChangeSearchTerm | func | | Function to call when the search term changes. |
20
- | options | array | | Array of options to be displayed in the dropdown. Each option is an object with `label` and `value`. |
20
+ | options | array | | Array of options to be displayed in the dropdown. Each option is an object with `name` and `value`. |
21
21
  | placeholder | string | | Placeholder text for the select field. |
22
22
  | prefix | string | | Text to display as a prefix inside the input field. |
23
23
  | readOnly | bool | false | Makes the select field read-only, preventing changes but allowing the dropdown to open. |
@@ -34,7 +34,7 @@ The `options` prop is an array of objects, each representing an option:
34
34
 
35
35
  | Name | Type | Description |
36
36
  | ----- | -------------- | -------------------------------- |
37
- | label | string | Label to display for the option. |
37
+ | name | string | Label to display for the option. |
38
38
  | value | string, number | Value of the option. |
39
39
 
40
40
  ### `withAutoReset`
@@ -60,10 +60,10 @@ import React, { useState } from 'react';
60
60
  import UTSelect from './UTSelect';
61
61
 
62
62
  const options = [
63
- { label: 'Option 1', value: '1' },
64
- { label: 'Option 2', value: '2' },
65
- { label: 'Option 3', value: '3' },
66
- { label: 'Option 4', value: '4' }
63
+ { name: 'Option 1', value: '1' },
64
+ { name: 'Option 2', value: '2' },
65
+ { name: 'Option 3', value: '3' },
66
+ { name: 'Option 4', value: '4' }
67
67
  ];
68
68
 
69
69
  const UTSelectExample = () => {
@@ -40,7 +40,7 @@ const ListboxComponent = _ref => {
40
40
  };
41
41
  ListboxComponent.propTypes = {
42
42
  filteredOptions: (0, _propTypes.arrayOf)((0, _propTypes.shape)({
43
- label: _propTypes.string,
43
+ name: _propTypes.string,
44
44
  value: (0, _propTypes.oneOfType)([_propTypes.string, _propTypes.number])
45
45
  })),
46
46
  handleSelectionChange: _propTypes.func,
@@ -32,10 +32,11 @@ const UTSelect = _ref => {
32
32
  helpText,
33
33
  multiple = false,
34
34
  noMatchesText = 'No hay coincidencias con tu búsqueda',
35
+ noOptionsText = 'No hay opciones disponibles',
35
36
  onChange = () => {},
36
37
  onChangeSearchTerm = () => {},
37
- options,
38
- placeholder = 'Seleccione un elemento',
38
+ options = [],
39
+ placeholder,
39
40
  prefix,
40
41
  readOnly,
41
42
  required,
@@ -46,6 +47,7 @@ const UTSelect = _ref => {
46
47
  withAutoReset = true
47
48
  } = _ref;
48
49
  const optionsSortedByCategory = (0, _react.useMemo)(() => {
50
+ if (!options || options.length === 0) return [];
49
51
  const clonedOptions = (0, _clone.default)(options);
50
52
  const categoryOrder = new Map();
51
53
  clonedOptions.forEach(option => {
@@ -64,11 +66,14 @@ const UTSelect = _ref => {
64
66
  setSortedOptions((0, _utils2.sortOptions)(optionsSortedByCategory, null, multiple));
65
67
  }
66
68
  }, [multiple, onChange, optionsSortedByCategory, value, withAutoReset]);
69
+ (0, _react.useEffect)(() => {
70
+ setSortedOptions((0, _utils2.sortOptions)(optionsSortedByCategory, value, multiple));
71
+ }, []);
67
72
  (0, _react.useEffect)(() => {
68
73
  if (isPopperOpen) setSortedOptions((0, _utils2.sortOptions)(optionsSortedByCategory, value, multiple));
69
- }, [isPopperOpen, optionsSortedByCategory, value, multiple]);
74
+ }, [isPopperOpen]);
70
75
  const validationData = (0, _react.useMemo)(() => error && (0, _utils.formatErrorToValidation)(error), [error]);
71
- const filteredOptions = (0, _react.useMemo)(() => disableFilterOptions ? sortedOptions : sortedOptions.filter(option => option.label.toLowerCase().includes(searchTerm.toLowerCase())), [sortedOptions, searchTerm, disableFilterOptions]);
76
+ const filteredOptions = (0, _react.useMemo)(() => disableFilterOptions ? sortedOptions : sortedOptions.filter(option => option.name.toLowerCase().includes(searchTerm.toLowerCase())), [sortedOptions, searchTerm, disableFilterOptions]);
72
77
  const handleSearchChange = (0, _react.useCallback)(searchValue => {
73
78
  onChangeSearchTerm === null || onChangeSearchTerm === void 0 || onChangeSearchTerm(searchValue);
74
79
  setSearchTerm(searchValue);
@@ -77,10 +82,10 @@ const UTSelect = _ref => {
77
82
  setIsPopperOpen(false);
78
83
  const displayValue = (0, _utils2.getDisplayValue)(inputValue, optionsSortedByCategory, multiple);
79
84
  handleSearchChange(displayValue);
80
- setShowClearButton(!!displayValue);
85
+ setShowClearButton(displayValue !== '');
81
86
  }, [_utils2.getDisplayValue, optionsSortedByCategory, multiple, handleSearchChange]);
82
87
  const handleSelectionChange = newValues => {
83
- const selectedValue = multiple ? newValues : newValues[0] || '';
88
+ const selectedValue = multiple ? newValues : newValues.length > 0 ? newValues[0] : '';
84
89
  onChange(selectedValue);
85
90
  if (!multiple) {
86
91
  var _inputRef$current;
@@ -92,11 +97,9 @@ const UTSelect = _ref => {
92
97
  setShowClearButton(false);
93
98
  handleSearchChange('');
94
99
  setIsPopperOpen(true);
95
- setSortedOptions((0, _utils2.sortOptions)(optionsSortedByCategory, value, multiple));
96
100
  };
97
101
  const handleInputBlur = () => {
98
102
  clearSearchInputValue(value);
99
- setSortedOptions((0, _utils2.sortOptions)(optionsSortedByCategory, value, multiple));
100
103
  };
101
104
  const handleClearSelection = () => {
102
105
  const clearedValue = multiple ? [] : null;
@@ -104,7 +107,6 @@ const UTSelect = _ref => {
104
107
  handleSearchChange('');
105
108
  setShowClearButton(false);
106
109
  setIsPopperOpen(false);
107
- setSortedOptions((0, _utils2.sortOptions)(optionsSortedByCategory, clearedValue, multiple));
108
110
  };
109
111
  const leftAdornments = (0, _react.useMemo)(() => (0, _utils2.getLeftAdornments)({
110
112
  error,
@@ -145,6 +147,10 @@ const UTSelect = _ref => {
145
147
  noMatchesText,
146
148
  value
147
149
  }), [filteredOptions, handleSelectionChange, multiple, noMatchesText, value]);
150
+ const noOptionsTextComponent = /*#__PURE__*/_react.default.createElement(_UTLabel.default, {
151
+ colorTheme: "gray",
152
+ className: _stylesModule.default.noOptionsLabel
153
+ }, noOptionsText);
148
154
  return /*#__PURE__*/_react.default.createElement("div", {
149
155
  className: "".concat(_stylesModule.default.container, " ").concat(className)
150
156
  }, title && /*#__PURE__*/_react.default.createElement(_UTFieldLabel.default, {
@@ -152,10 +158,11 @@ const UTSelect = _ref => {
152
158
  variant: "body"
153
159
  }, title), /*#__PURE__*/_react.default.createElement(_lab.Autocomplete, {
154
160
  disabled: disabled || readOnly,
155
- getOptionLabel: option => option.label,
161
+ getOptionLabel: option => option.name,
156
162
  ListboxComponent: _ListboxComponent.default,
157
163
  ListboxProps: listBoxProps,
158
164
  multiple: multiple,
165
+ noOptionsText: noOptionsTextComponent,
159
166
  onClose: () => setIsPopperOpen(false),
160
167
  onOpen: () => setIsPopperOpen(true),
161
168
  open: isPopperOpen,
@@ -184,10 +191,11 @@ UTSelect.propTypes = {
184
191
  helpText: _propTypes.string,
185
192
  multiple: _propTypes.bool,
186
193
  noMatchesText: _propTypes.string,
194
+ noOptionsText: _propTypes.string,
187
195
  onChange: _propTypes.func,
188
196
  onChangeSearchTerm: _propTypes.func,
189
197
  options: (0, _propTypes.arrayOf)((0, _propTypes.shape)({
190
- label: _propTypes.string,
198
+ name: _propTypes.string,
191
199
  value: (0, _propTypes.oneOfType)([_propTypes.string, _propTypes.number])
192
200
  })),
193
201
  placeholder: _propTypes.string,
@@ -9,22 +9,21 @@ var _clone = _interopRequireDefault(require("lodash/clone"));
9
9
  var _constants = require("../../../UTBaseInputField/constants");
10
10
  var _constants2 = require("../../../UTCheckList/versions/V1/constants");
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- const hasOption = (options, value) => options.some(opt => {
13
- var _opt$subOptions;
14
- return opt.value === value || ((_opt$subOptions = opt.subOptions) === null || _opt$subOptions === void 0 ? void 0 : _opt$subOptions.some(sub => sub.value === value));
15
- });
16
- const shouldReset = (value, options, multiple) => {
17
- if ((0, _array.isEmpty)(options) || (0, _array.isEmpty)(value)) return false;
18
- return multiple ? value.some(val => !hasOption(options, val)) : !hasOption(options, value);
12
+ const shouldResetMultipleSelect = (value, options) => !(0, _array.isEmpty)(value) && ((0, _array.isEmpty)(options) || value.some(el => !options.some(opt => opt.value === el) && !options.some(opt => opt.subOptions && opt.subOptions.some(sub => sub.value === el))));
13
+ const shouldResetSimpleSelect = (value, options) => value && ((0, _array.isEmpty)(options) || !options.some(el => el.value === value) && !options.some(el => el.subOptions && el.subOptions.some(sub => sub.value === value)));
14
+ const shouldReset = (value, options, isMultiple) => {
15
+ if (isMultiple) return shouldResetMultipleSelect(value, options);
16
+ return shouldResetSimpleSelect(value, options);
19
17
  };
20
18
  exports.shouldReset = shouldReset;
21
19
  const getDisplayValue = (inputValue, options, multiple) => {
22
- if (!inputValue) return '';
20
+ if (inputValue === null || inputValue === undefined || inputValue === '') return '';
23
21
  const findLabel = optionValue => {
24
22
  var _options$find;
25
- return ((_options$find = options.find(o => o.value === optionValue)) === null || _options$find === void 0 ? void 0 : _options$find.label) || '';
23
+ return ((_options$find = options.find(o => o.value === optionValue)) === null || _options$find === void 0 ? void 0 : _options$find.name) || '';
26
24
  };
27
- return multiple ? inputValue.map(findLabel).join(', ') : findLabel(inputValue);
25
+ const displayValue = multiple ? inputValue.map(findLabel).join(', ') : findLabel(inputValue);
26
+ return displayValue;
28
27
  };
29
28
  exports.getDisplayValue = getDisplayValue;
30
29
  const getLeftAdornments = _ref => {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isUTIcon = exports.getDefaultColorShade = exports.default = exports.childrenExists = exports.capitalize = void 0;
6
+ exports.valueExists = exports.isUTIcon = exports.getDefaultColorShade = exports.default = exports.capitalize = void 0;
7
7
  var _Palette = require("../constants/Palette");
8
8
  const A_CHAR_CODE = 65;
9
9
  const Z_CHAR_CODE = 90;
@@ -21,8 +21,8 @@ const isUTIcon = icon => typeof icon === 'string';
21
21
  exports.isUTIcon = isUTIcon;
22
22
  const getDefaultColorShade = colorTheme => colorTheme === _Palette.COLOR_THEMES.gray ? _Palette.COLOR_SHADES.shade04 : colorTheme === _Palette.COLOR_THEMES.light ? _Palette.COLOR_SHADES.shade01 : _Palette.COLOR_SHADES.shade05;
23
23
  exports.getDefaultColorShade = getDefaultColorShade;
24
- const childrenExists = children => children !== undefined && children !== null;
25
- exports.childrenExists = childrenExists;
24
+ const valueExists = value => value !== undefined && value !== null;
25
+ exports.valueExists = valueExists;
26
26
  var _default = exports.default = {
27
27
  capitalize,
28
28
  getAvatarColors,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widergy/energy-ui",
3
- "version": "3.40.0",
3
+ "version": "3.41.1",
4
4
  "description": "Widergy Web Components",
5
5
  "author": "widergy",
6
6
  "license": "MIT",