@councilbox/councilbox-ui 1.0.1 → 2.0.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.
Files changed (137) hide show
  1. package/dist/HOCs/useDynamicStyles.js +99 -0
  2. package/dist/HOCs/useRipple.js +91 -0
  3. package/dist/build-index.js +8 -0
  4. package/dist/components/1.Introduction.stories.mdx +2 -1
  5. package/dist/components/2.Changelog.stories.mdx +3 -0
  6. package/dist/components/3.Guide.stories.mdx +56 -0
  7. package/dist/components/Accordion/Accordion.css +39 -1
  8. package/dist/components/Accordion/Accordion.js +84 -45
  9. package/dist/components/Accordion/Accordion.stories.js +4 -2
  10. package/dist/components/Accordion/AccordionOld.css +16 -0
  11. package/dist/components/Accordion/AccordionOld.js +115 -0
  12. package/dist/components/Accordion/DesignAccordion.stories.js +38 -0
  13. package/dist/components/Alert/Alert.css +5 -0
  14. package/dist/components/Alert/Alert.js +17 -6
  15. package/dist/components/Avatar/Avatar.css +3 -3
  16. package/dist/components/Avatar/Avatar.js +36 -20
  17. package/dist/components/Avatar/AvatarOld.js +138 -0
  18. package/dist/components/Avatar/DesignAvatar.stories.js +1 -1
  19. package/dist/components/Block/Block.js +17 -2
  20. package/dist/components/ButtonBasic/ButtonBasic.css +264 -20
  21. package/dist/components/ButtonBasic/ButtonBasic.js +85 -110
  22. package/dist/components/ButtonBasic/ButtonBasicOld.css +41 -0
  23. package/dist/components/ButtonBasic/ButtonBasicOld.js +231 -0
  24. package/dist/components/Checkbox/Checkbox.css +101 -22
  25. package/dist/components/Checkbox/Checkbox.js +119 -63
  26. package/dist/components/Checkbox/CheckboxOld.css +31 -0
  27. package/dist/components/Checkbox/CheckboxOld.js +112 -0
  28. package/dist/components/DragDrop/DragDrop.js +24 -9
  29. package/dist/components/DrawerPanel/DesignDrawerPanel.js +4 -2
  30. package/dist/components/DrawerPanel/DrawerPanel.css +76 -36
  31. package/dist/components/DrawerPanel/DrawerPanel.js +137 -115
  32. package/dist/components/DrawerPanel/DrawerPanelOld.css +56 -0
  33. package/dist/components/DrawerPanel/DrawerPanelOld.js +233 -0
  34. package/dist/components/DropDown/DesignDropDown.stories.js +146 -17
  35. package/dist/components/DropDown/DropDown.css +96 -1
  36. package/dist/components/DropDown/DropDown.js +308 -82
  37. package/dist/components/DropDown/DropDown.stories.js +1 -0
  38. package/dist/components/DropDown/DropDownOld.css +3 -0
  39. package/dist/components/DropDown/DropDownOld.js +186 -0
  40. package/dist/components/DropDown/PopoverPlayground.css +22 -0
  41. package/dist/components/DropDown/PopoverPlayground.js +235 -0
  42. package/dist/components/EnhancedTable/EnhancedTable.js +5 -6
  43. package/dist/components/FabButton/DesignFabButton.stories.js +3 -1
  44. package/dist/components/FabButton/FabButton.js +25 -5
  45. package/dist/components/Grid/DesignGrid.stories.js +9 -3
  46. package/dist/components/Grid/Grid.css +325 -0
  47. package/dist/components/Grid/Grid.js +57 -16
  48. package/dist/components/Grid/GridItem.js +31 -13
  49. package/dist/components/Grid/GridItemOld.js +43 -0
  50. package/dist/components/Grid/GridOld.css +0 -0
  51. package/dist/components/Grid/GridOld.js +53 -0
  52. package/dist/components/Header/Header.js +95 -116
  53. package/dist/components/IconButton/DesignIconButton.stories.js +22 -2
  54. package/dist/components/IconButton/IconButton.css +121 -1
  55. package/dist/components/IconButton/IconButton.js +98 -53
  56. package/dist/components/IconButton/IconButtonOld.css +0 -0
  57. package/dist/components/IconButton/IconButtonOld.js +138 -0
  58. package/dist/components/IconButtonSquare/IconButtonSquare.js +20 -90
  59. package/dist/components/IconButtonSquare/IconButtonSquareOld.css +43 -0
  60. package/dist/components/IconButtonSquare/IconButtonSquareOld.js +133 -0
  61. package/dist/components/InputAutocomplete/InputAutocomplete.css +109 -0
  62. package/dist/components/InputAutocomplete/InputAutocomplete.js +382 -76
  63. package/dist/components/InputAutocomplete/InputAutocomplete.stories.js +118 -6
  64. package/dist/components/InputAutocomplete/InputAutocompleteOld.css +5 -0
  65. package/dist/components/InputAutocomplete/InputAutocompleteOld.js +178 -0
  66. package/dist/components/InputPassword/InputPassword.js +10 -20
  67. package/dist/components/InputText/InputText.css +442 -1
  68. package/dist/components/InputText/InputText.js +298 -239
  69. package/dist/components/InputText/InputText.stories.js +12 -3
  70. package/dist/components/InputText/InputTextOld.css +10 -0
  71. package/dist/components/InputText/InputTextOld.js +340 -0
  72. package/dist/components/InputTextArea/DesignInputTextArea.stories.js +30 -4
  73. package/dist/components/InputTextArea/InputTextArea.js +13 -6
  74. package/dist/components/LoadingSection/LoadingSection.css +44 -2
  75. package/dist/components/LoadingSection/LoadingSection.js +63 -9
  76. package/dist/components/MenuItem/DesignMenuItem.stories.js +1 -0
  77. package/dist/components/MenuItem/MenuItem.css +35 -6
  78. package/dist/components/MenuItem/MenuItem.js +99 -50
  79. package/dist/components/MenuItem/MenuItemOld.js +139 -0
  80. package/dist/components/MenuLateralLeft/MenuLateralLeft.js +60 -40
  81. package/dist/components/MenuLateralRight/MenuLateralRight.js +23 -8
  82. package/dist/components/Modal/DesignModal.stories.js +54 -0
  83. package/dist/components/Modal/Modal.css +81 -2
  84. package/dist/components/Modal/Modal.js +112 -80
  85. package/dist/components/Modal/Modal.stories.js +13 -2
  86. package/dist/components/Modal/ModalOld.css +3 -0
  87. package/dist/components/Modal/ModalOld.js +230 -0
  88. package/dist/components/PaginationFooter/DesignPaginationFooter.stories.js +9 -1
  89. package/dist/components/PaginationFooter/PaginationFooter.css +73 -0
  90. package/dist/components/PaginationFooter/PaginationFooter.js +45 -87
  91. package/dist/components/RadioButton/Radio.css +115 -16
  92. package/dist/components/RadioButton/Radio.js +70 -94
  93. package/dist/components/RadioButton/Radio.stories.js +42 -18
  94. package/dist/components/RadioButton/RadioOld.css +31 -0
  95. package/dist/components/RadioButton/RadioOld.js +142 -0
  96. package/dist/components/Ripple/DesignRipple.js +77 -0
  97. package/dist/components/Ripple/Ripple.stories.js +45 -0
  98. package/dist/components/Scrollbar/Scrollbar.js +21 -6
  99. package/dist/components/SelectInput/DesignSelectInput.js +62 -23
  100. package/dist/components/SelectInput/SelectInput.css +128 -10
  101. package/dist/components/SelectInput/SelectInput.js +265 -244
  102. package/dist/components/SelectInput/SelectInputOld.css +17 -0
  103. package/dist/components/SelectInput/SelectInputOld.js +325 -0
  104. package/dist/components/Stars/Stars.css +28 -28
  105. package/dist/components/Stars/Stars.js +22 -12
  106. package/dist/components/Stepper/Stepper.css +1 -0
  107. package/dist/components/Stepper/Stepper.js +81 -24
  108. package/dist/components/Table/DesignTable.stories.js +1 -0
  109. package/dist/components/Table/Table.css +56 -53
  110. package/dist/components/Table/Table.js +55 -75
  111. package/dist/components/Table/TableOld.css +79 -0
  112. package/dist/components/Table/TableOld.js +165 -0
  113. package/dist/components/Tabs/DesignTabs.js +37 -12
  114. package/dist/components/Tabs/Tabs.css +39 -4
  115. package/dist/components/Tabs/Tabs.js +194 -30
  116. package/dist/components/Tabs/Tabs.stories.js +8 -1
  117. package/dist/components/Tabs/TabsOld.js +92 -0
  118. package/dist/components/Tag/Tag.js +19 -9
  119. package/dist/components/Toggle/Toggle.css +122 -3
  120. package/dist/components/Toggle/Toggle.js +95 -68
  121. package/dist/components/Tooltip/DesignTooltip.stories.js +48 -0
  122. package/dist/components/Tooltip/Tooltip.css +75 -0
  123. package/dist/components/Tooltip/Tooltip.js +126 -0
  124. package/dist/components/Tooltip/Tooltip.stories.js +40 -0
  125. package/dist/components/Typography/Typography.css +9 -0
  126. package/dist/components/Typography/Typography.js +30 -21
  127. package/dist/components/Typography/TypographyOld.js +132 -0
  128. package/dist/styles/colorConsts.css +24 -0
  129. package/dist/styles/main.css +41 -49
  130. package/dist/styles/scpacingConsts.css +26 -0
  131. package/dist/styles/zIndexConsts.css +9 -0
  132. package/dist/testing/TestAutocomplete.js +369 -0
  133. package/dist/testing/TestComponents.js +3 -114
  134. package/dist/testing/TestDropdown.js +225 -0
  135. package/dist/utils/autoDetectScroll.js +127 -0
  136. package/dist/utils/index.js +141 -0
  137. package/package.json +2 -1
@@ -9,9 +9,9 @@ var _react = _interopRequireDefault(require("react"));
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
- require("../../styles/main.css");
12
+ var _reactDom = require("react-dom");
13
13
 
14
- var _Autocomplete = _interopRequireDefault(require("@mui/material/Autocomplete"));
14
+ require("../../styles/main.css");
15
15
 
16
16
  require("./InputAutocomplete.css");
17
17
 
@@ -19,7 +19,17 @@ var _InputText = _interopRequireDefault(require("../InputText/InputText"));
19
19
 
20
20
  var _MenuItem = _interopRequireDefault(require("../MenuItem/MenuItem"));
21
21
 
22
- var _excluded = ["width", "id", "className", "onChange", "label", "disabled", "error", "helper", "success", "helperText", "fullWidth", "sx", "endAdornment", "variant", "required"];
22
+ var _IconButton = _interopRequireDefault(require("../IconButton/IconButton"));
23
+
24
+ var _useDynamicStyles2 = _interopRequireDefault(require("../../HOCs/useDynamicStyles"));
25
+
26
+ var _LoadingSection = _interopRequireDefault(require("../LoadingSection/LoadingSection"));
27
+
28
+ var _autoDetectScroll = require("../../utils/autoDetectScroll");
29
+
30
+ var _utils = require("../../utils");
31
+
32
+ var _excluded = ["children", "className", "onChange", "onInputChange", "label", "value", "inputValue", "style", "styles", "sx", "loadingText", "loading", "prefixClass", "options", "getOptionLabel", "clearable", "getOptionSelected", "defaultValue", "filterOptions", "freeSolo", "clearOnBlur", "selectOnFocus"];
23
33
 
24
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
35
 
@@ -31,97 +41,393 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
31
41
 
32
42
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
33
43
 
44
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
45
+
46
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
47
+
48
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
49
+
50
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
51
+
52
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
53
+
54
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
55
+
34
56
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
35
57
 
36
58
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
37
59
 
38
- var top100Films = [{
39
- label: 'The Shawshank Redemption The Shawshank Redemption',
40
- year: 1994
41
- }, {
42
- label: 'The Godfather',
43
- year: 1972
44
- }, {
45
- label: 'The Godfather: Part II',
46
- year: 1974
47
- }, {
48
- label: 'The Dark Knight',
49
- year: 2008
50
- }, {
51
- label: '12 Angry Men',
52
- year: 1957
53
- }, {
54
- label: "Schindler's List",
55
- year: 1993
56
- }, {
57
- label: 'Pulp Fiction',
58
- year: 1994
59
- }];
60
-
61
60
  var InputAutocomplete = function InputAutocomplete(_ref) {
62
- var width = _ref.width,
63
- id = _ref.id,
61
+ var children = _ref.children,
64
62
  className = _ref.className,
65
63
  onChange = _ref.onChange,
64
+ onInputChange = _ref.onInputChange,
66
65
  label = _ref.label,
67
- disabled = _ref.disabled,
68
- error = _ref.error,
69
- helper = _ref.helper,
70
- success = _ref.success,
71
- helperText = _ref.helperText,
72
- fullWidth = _ref.fullWidth,
66
+ value = _ref.value,
67
+ propInputValue = _ref.inputValue,
68
+ style = _ref.style,
69
+ styles = _ref.styles,
73
70
  sx = _ref.sx,
74
- endAdornment = _ref.endAdornment,
75
- variant = _ref.variant,
76
- required = _ref.required,
71
+ _ref$loadingText = _ref.loadingText,
72
+ loadingText = _ref$loadingText === void 0 ? 'Buscando resultados...' : _ref$loadingText,
73
+ _ref$loading = _ref.loading,
74
+ loading = _ref$loading === void 0 ? false : _ref$loading,
75
+ propPrefixClass = _ref.prefixClass,
76
+ options = _ref.options,
77
+ _ref$getOptionLabel = _ref.getOptionLabel,
78
+ getOptionLabel = _ref$getOptionLabel === void 0 ? function (option) {
79
+ if (!option) {
80
+ return '';
81
+ }
82
+
83
+ if (typeof option === 'string') {
84
+ return option;
85
+ }
86
+
87
+ return option.label || option.text || option.translation || option.value;
88
+ } : _ref$getOptionLabel,
89
+ _ref$clearable = _ref.clearable,
90
+ clearable = _ref$clearable === void 0 ? true : _ref$clearable,
91
+ _ref$getOptionSelecte = _ref.getOptionSelected,
92
+ getOptionSelected = _ref$getOptionSelecte === void 0 ? function (option, valueSelected) {
93
+ return option === valueSelected;
94
+ } : _ref$getOptionSelecte,
95
+ defaultValue = _ref.defaultValue,
96
+ filterOptions = _ref.filterOptions,
97
+ _ref$freeSolo = _ref.freeSolo,
98
+ freeSolo = _ref$freeSolo === void 0 ? false : _ref$freeSolo,
99
+ _ref$clearOnBlur = _ref.clearOnBlur,
100
+ clearOnBlur = _ref$clearOnBlur === void 0 ? true : _ref$clearOnBlur,
101
+ _ref$selectOnFocus = _ref.selectOnFocus,
102
+ selectOnFocus = _ref$selectOnFocus === void 0 ? !freeSolo : _ref$selectOnFocus,
77
103
  props = _objectWithoutProperties(_ref, _excluded);
78
104
 
79
- return /*#__PURE__*/_react.default.createElement(_Autocomplete.default, _extends({
80
- id: id,
81
- className: "".concat(className || ''),
82
- onChange: onChange,
83
- disabled: disabled,
84
- sx: _objectSpread({
85
- minWidth: width || '15rem',
86
- '&.MuiAutocomplete-root .MuiOutlinedInput-root': {
87
- padding: '0'
88
- },
89
- '&.MuiAutocomplete-root .MuiFilledInput-root': {
90
- paddingTop: '0',
91
- paddingLeft: '0'
92
- },
93
- '&.MuiAutocomplete-root .MuiInput-root': {
94
- paddingBottom: '0!important'
95
- },
96
- '&.MuiAutocomplete-root .MuiAutocomplete-inputRoot .MuiAutocomplete-input': {
97
- paddingRight: '2.5rem!important'
105
+ var _useDynamicStyles = (0, _useDynamicStyles2.default)(sx),
106
+ stylesInLine = _useDynamicStyles.stylesInLine,
107
+ dynamicPrefixClass = _useDynamicStyles.prefixClass;
108
+
109
+ var prefixClass = propPrefixClass || dynamicPrefixClass;
110
+
111
+ var _React$useState = _react.default.useState({
112
+ showDropdown: false,
113
+ showSearchInput: false
114
+ }),
115
+ _React$useState2 = _slicedToArray(_React$useState, 2),
116
+ uiState = _React$useState2[0],
117
+ setUIstate = _React$useState2[1];
118
+
119
+ var _React$useState3 = _react.default.useState({
120
+ top: null,
121
+ bottom: null,
122
+ left: '0px',
123
+ width: '0px'
124
+ }),
125
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
126
+ positions = _React$useState4[0],
127
+ setPositions = _React$useState4[1];
128
+
129
+ var _React$useState5 = _react.default.useState(false),
130
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
131
+ isClosing = _React$useState6[0],
132
+ setIsClosing = _React$useState6[1];
133
+
134
+ var _React$useState7 = _react.default.useState(value || null),
135
+ _React$useState8 = _slicedToArray(_React$useState7, 2),
136
+ internalValue = _React$useState8[0],
137
+ setInternalValue = _React$useState8[1];
138
+
139
+ var _React$useState9 = _react.default.useState(propInputValue || value && getOptionLabel(value) || ''),
140
+ _React$useState10 = _slicedToArray(_React$useState9, 2),
141
+ internalInputValue = _React$useState10[0],
142
+ setInternalInputValue = _React$useState10[1];
143
+
144
+ var searchTextRef = _react.default.useRef(freeSolo ? internalInputValue : '');
145
+
146
+ var selectedValue = value !== undefined ? value : internalValue;
147
+ var inputValue = propInputValue !== undefined ? propInputValue : internalInputValue;
148
+
149
+ var selectRef = _react.default.useRef(null);
150
+
151
+ var dropdownRef = _react.default.useRef(null);
152
+
153
+ var inputRef = _react.default.useRef(null);
154
+
155
+ var optionContainerRef = _react.default.useRef(null);
156
+
157
+ var filteredOptions = _react.default.useMemo(function () {
158
+ var newFilteredOptions = options;
159
+ var searchValue = searchTextRef.current;
160
+
161
+ if (searchValue) {
162
+ if (filterOptions) {
163
+ newFilteredOptions = filterOptions(options, {
164
+ inputValue: searchValue
165
+ });
166
+ } else {
167
+ newFilteredOptions = options.filter(function (option) {
168
+ var optionLabel = getOptionLabel(option);
169
+ return optionLabel && searchValue && optionLabel.toLowerCase().includes(searchValue.toLowerCase());
170
+ });
98
171
  }
99
- }, sx),
100
- freeSolo: true,
101
- options: top100Films,
102
- renderInput: function renderInput(params) {
103
- return /*#__PURE__*/_react.default.createElement(_InputText.default, _extends({}, params, {
104
- error: error,
105
- label: label,
106
- helper: helper,
107
- success: success,
108
- helperText: helperText,
109
- endAdornment: endAdornment,
110
- variant: variant,
111
- fullWidth: fullWidth,
112
- required: required,
113
- width: width
172
+ }
173
+
174
+ return newFilteredOptions;
175
+ }, [options, searchTextRef.current]);
176
+
177
+ var _useKeyItemNavigation = (0, _utils.useKeyItemNavigation)({
178
+ containerRef: optionContainerRef
179
+ }),
180
+ handleKeyDown = _useKeyItemNavigation.handleKeyDown;
181
+
182
+ var shouldShowDropdown = uiState.showDropdown && filteredOptions.length > 0 && !isClosing || loading;
183
+
184
+ var closeDropdown = function closeDropdown() {
185
+ setIsClosing(true);
186
+ setTimeout(function () {
187
+ setUIstate(_objectSpread(_objectSpread({}, uiState), {}, {
188
+ showDropdown: false,
189
+ showSearchInput: !clearOnBlur
114
190
  }));
191
+ setIsClosing(false);
192
+
193
+ if (!freeSolo) {
194
+ searchTextRef.current = '';
195
+ }
196
+ }, 150);
197
+ };
198
+
199
+ var updateInputValue = function updateInputValue(e, newValue) {
200
+ if (props.inputValue === undefined) {
201
+ setInternalInputValue(newValue);
202
+ }
203
+
204
+ if (onInputChange) {
205
+ onInputChange(e, newValue);
206
+ }
207
+
208
+ searchTextRef.current = newValue;
209
+ };
210
+
211
+ var updateValue = function updateValue(e, newValue) {
212
+ if (onChange) {
213
+ onChange(e, newValue);
214
+ } else {
215
+ setInternalValue(newValue);
216
+ }
217
+ };
218
+
219
+ var handleOptionClick = function handleOptionClick(e, option) {
220
+ var optionLabel = getOptionLabel(option);
221
+ updateInputValue(e, optionLabel);
222
+ updateValue(e, option);
223
+ closeDropdown();
224
+ };
225
+
226
+ var handleInputChange = function handleInputChange(e) {
227
+ var newValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
228
+ var newInputValue = newValue || e.target.value;
229
+
230
+ if (freeSolo) {
231
+ updateValue(e, newInputValue);
232
+ }
233
+
234
+ updateInputValue(e, newInputValue);
235
+ };
236
+
237
+ var handleInputBlur = function handleInputBlur(e) {
238
+ handleInputChange(e, selectedValue ? getOptionLabel(selectedValue) : '');
239
+
240
+ if (clearOnBlur) {
241
+ if (!freeSolo) {
242
+ handleInputChange(e, selectedValue ? getOptionLabel(selectedValue) : '');
243
+ }
244
+ }
245
+
246
+ closeDropdown();
247
+ };
248
+
249
+ var handleInputFocus = function handleInputFocus(e) {
250
+ if (selectOnFocus) {
251
+ e.target.select();
252
+ }
253
+
254
+ setUIstate(_objectSpread(_objectSpread({}, uiState), {}, {
255
+ showDropdown: true,
256
+ showSearchInput: true
257
+ }));
258
+ };
259
+
260
+ var updateDropdownPosition = function updateDropdownPosition() {
261
+ var _selectRef$current, _selectRef$current2, _selectRef$current2$c;
262
+
263
+ if (selectRef.current && selectRef !== null && selectRef !== void 0 && (_selectRef$current = selectRef.current) !== null && _selectRef$current !== void 0 && _selectRef$current.children[0] && selectRef !== null && selectRef !== void 0 && (_selectRef$current2 = selectRef.current) !== null && _selectRef$current2 !== void 0 && (_selectRef$current2$c = _selectRef$current2.children[0]) !== null && _selectRef$current2$c !== void 0 && _selectRef$current2$c.children[0]) {
264
+ var _selectRef$current3, _selectRef$current3$c, _selectRef$current3$c2;
265
+
266
+ var selectRect = selectRef === null || selectRef === void 0 ? void 0 : (_selectRef$current3 = selectRef.current) === null || _selectRef$current3 === void 0 ? void 0 : (_selectRef$current3$c = _selectRef$current3.children[0]) === null || _selectRef$current3$c === void 0 ? void 0 : (_selectRef$current3$c2 = _selectRef$current3$c.children[0]) === null || _selectRef$current3$c2 === void 0 ? void 0 : _selectRef$current3$c2.getBoundingClientRect();
267
+ var isOverflowingBelow = selectRect.bottom > window.innerHeight / 2;
268
+
269
+ var newPositions = _objectSpread({}, positions);
270
+
271
+ if (isOverflowingBelow) {
272
+ newPositions.bottom = "".concat(window.innerHeight - selectRect.top, "px");
273
+ delete newPositions.top;
274
+ } else {
275
+ delete newPositions.bottom;
276
+ newPositions.top = "".concat(selectRect.bottom, "px");
277
+ }
278
+
279
+ newPositions.left = "".concat(selectRect.left, "px");
280
+ newPositions.width = "".concat(selectRect.width, "px");
281
+ setPositions(_objectSpread({}, newPositions));
282
+ }
283
+ };
284
+
285
+ _react.default.useEffect(function () {
286
+ updateDropdownPosition();
287
+ }, [shouldShowDropdown, document.body.clientHeight > window.innerHeight]);
288
+
289
+ _react.default.useEffect(function () {
290
+ var referenceEl = (0, _autoDetectScroll.unwrapElement)(inputRef.current);
291
+ var ancestors = (0, _autoDetectScroll.getOverflowAncestors)(referenceEl) || [];
292
+ ancestors.forEach(function (ancestor) {
293
+ ancestor.addEventListener('scroll', updateDropdownPosition, {
294
+ passive: true
295
+ });
296
+ ancestor.addEventListener('resize', updateDropdownPosition);
297
+ });
298
+ }, [inputRef.current]);
299
+
300
+ return /*#__PURE__*/_react.default.createElement("div", {
301
+ className: prefixClass("cbx-inputAutocomplete-container ".concat(uiState.showSearchInput ? 'cbx-inputAutocomplete-container-open' : '')),
302
+ style: _objectSpread(_objectSpread(_objectSpread({
303
+ width: props.fullWidth && '100%'
304
+ }, styles), style), stylesInLine),
305
+ id: "cbx-prueba",
306
+ ref: selectRef
307
+ }, /*#__PURE__*/_react.default.createElement(_InputText.default, _extends({
308
+ label: label,
309
+ value: inputValue,
310
+ className: "".concat(className, " cbx-inputPassword-button-spacing"),
311
+ shrink: !!inputValue || !!selectedValue,
312
+ prefixClass: prefixClass,
313
+ fullWidth: props.fullWidth,
314
+ ref: inputRef,
315
+ onKeyDown: function onKeyDown(e) {
316
+ e.preventDefault();
317
+
318
+ if (e.keyCode === 9) {
319
+ closeDropdown();
320
+ }
321
+
322
+ if (e.key === 'Escape') {
323
+ closeDropdown();
324
+ }
325
+
326
+ handleKeyDown(e);
115
327
  },
116
- renderOption: function renderOption(propsOption) {
117
- return /*#__PURE__*/_react.default.createElement(_MenuItem.default, _extends({
118
- fullWidth: fullWidth
119
- }, propsOption), propsOption.key);
328
+ onChange: handleInputChange,
329
+ onClick: handleInputFocus,
330
+ defaultValue: defaultValue,
331
+ InputProps: {
332
+ endAdornment: clearable && inputValue && (loading ? /*#__PURE__*/_react.default.createElement(_LoadingSection.default, {
333
+ size: 20,
334
+ thickness: 3,
335
+ color: "var(--primary)"
336
+ }) : /*#__PURE__*/_react.default.createElement(_IconButton.default, {
337
+ prefixClass: prefixClass,
338
+ className: "cbx-inputAutocomplete-icon-button",
339
+ onClick: function onClick(e) {
340
+ e.stopPropagation();
341
+ e.preventDefault();
342
+ searchTextRef.current = '';
343
+ updateInputValue(e, '');
344
+ updateValue(e, null);
345
+ inputRef.current.focus();
346
+ },
347
+ icon: /*#__PURE__*/_react.default.createElement("i", {
348
+ className: "ri-close-fill",
349
+ tabIndex: "-1"
350
+ })
351
+ }))
352
+ }
353
+ }, props, {
354
+ type: 'autocomplete'
355
+ })), (uiState.showDropdown || loading) && (positions.top || positions.bottom) && /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/_react.default.createElement("div", {
356
+ className: prefixClass('cbx-inputAutocomplete-presentation')
357
+ }, /*#__PURE__*/_react.default.createElement(OutsideClickHandler, {
358
+ excludedRefs: [selectRef, dropdownRef],
359
+ onOutsideClick: function onOutsideClick() {
360
+ handleInputBlur({
361
+ target: {
362
+ value: searchTextRef.current
363
+ }
364
+ });
120
365
  }
121
- }, props));
366
+ }), shouldShowDropdown && /*#__PURE__*/_react.default.createElement("div", {
367
+ className: prefixClass("cbx-inputAutocomplete-options-container ".concat(uiState.showDropdown && !isClosing ? 'cbx-inputAutocomplete-options-container-open' : 'cbx-inputAutocomplete-options-container-close')),
368
+ style: _objectSpread({}, positions),
369
+ onKeyDown: function onKeyDown(e) {
370
+ if (e.keyCode === 9) {
371
+ closeDropdown();
372
+ }
373
+
374
+ if (e.key === 'Escape') {
375
+ closeDropdown();
376
+ }
377
+
378
+ handleKeyDown(e);
379
+ },
380
+ ref: dropdownRef
381
+ }, /*#__PURE__*/_react.default.createElement("ul", {
382
+ className: prefixClass('cbx-inputAutocomplete-options'),
383
+ ref: optionContainerRef
384
+ }, !loading && (filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.map(function (item, index) {
385
+ return /*#__PURE__*/_react.default.createElement(_MenuItem.default, _extends({}, item, {
386
+ value: item.value || getOptionLabel(item),
387
+ key: "".concat(item.value || getOptionLabel(item), "-").concat(index),
388
+ onClick: function onClick(e) {
389
+ handleOptionClick(e, item);
390
+ },
391
+ active: getOptionSelected(item, selectedValue),
392
+ fullWidth: props.fullWidth
393
+ }), getOptionLabel(item));
394
+ })), loading && /*#__PURE__*/_react.default.createElement(_MenuItem.default, {
395
+ fullWidth: props.fullWidth
396
+ }, loadingText)))), document.body));
122
397
  };
123
398
 
124
399
  InputAutocomplete.displayName = "InputAutocomplete";
400
+
401
+ var OutsideClickHandler = function OutsideClickHandler(_ref2) {
402
+ var children = _ref2.children,
403
+ excludedRefs = _ref2.excludedRefs,
404
+ onOutsideClick = _ref2.onOutsideClick;
405
+
406
+ var wrapperRef = _react.default.useRef(null);
407
+
408
+ _react.default.useEffect(function () {
409
+ var handleClickOutside = function handleClickOutside(event) {
410
+ var clickedExcluded = excludedRefs.some(function (ref) {
411
+ return ref.current && ref.current.contains(event.target);
412
+ });
413
+
414
+ if (wrapperRef.current && !wrapperRef.current.contains(event.target) && !clickedExcluded) {
415
+ onOutsideClick(event);
416
+ }
417
+ };
418
+
419
+ document.addEventListener('mousedown', handleClickOutside);
420
+ return function () {
421
+ document.removeEventListener('mousedown', handleClickOutside);
422
+ };
423
+ }, [excludedRefs, onOutsideClick]);
424
+
425
+ return /*#__PURE__*/_react.default.createElement("div", {
426
+ ref: wrapperRef
427
+ }, children);
428
+ };
429
+
430
+ OutsideClickHandler.displayName = "OutsideClickHandler";
125
431
  InputAutocomplete.propTypes = {
126
432
  label: _propTypes.default.string,
127
433
  helper: _propTypes.default.string,
@@ -49,29 +49,141 @@ Template.displayName = "Template";
49
49
  var Default = Template.bind({});
50
50
  exports.Default = Default;
51
51
  Default.args = {
52
- variant: 'outlined'
52
+ variant: 'outlined',
53
+ options: [{
54
+ translation: 'Todo',
55
+ value: 'all'
56
+ }, {
57
+ translation: '4',
58
+ value: 'statute_4166'
59
+ }, {
60
+ translation: '5',
61
+ value: 'statute_4167'
62
+ }, {
63
+ translation: 'DemoTrámite',
64
+ value: 'statute_4194'
65
+ }, {
66
+ translation: 'editado para docu required',
67
+ value: 'statute_4136'
68
+ }, {
69
+ translation: 'Gestión de prueba para tener un ejemplo',
70
+ value: 'statute_4226'
71
+ }, {
72
+ translation: 'ghjghjghj',
73
+ value: 'statute_4243'
74
+ }],
75
+ label: 'procedures'
53
76
  };
54
77
  var Helper = Template.bind({});
55
78
  exports.Helper = Helper;
56
79
  Helper.args = {
57
- value: 'Occaecat',
58
- helper: 'Helper'
80
+ value: 'The Godfather',
81
+ helper: 'Helper',
82
+ variant: 'outlined',
83
+ options: [{
84
+ label: 'The Shawshank Redemption The Shawshank Redemption',
85
+ value: 1994
86
+ }, {
87
+ label: 'The Godfather',
88
+ value: 1972
89
+ }, {
90
+ label: 'The Godfather: Part II',
91
+ value: 1974
92
+ }, {
93
+ label: 'The Dark Knight',
94
+ value: 2008
95
+ }, {
96
+ label: '12 Angry Men',
97
+ value: 1957
98
+ }, {
99
+ label: "Schindler's List",
100
+ value: 1993
101
+ }, {
102
+ label: 'Pulp Fiction',
103
+ value: 1994
104
+ }]
59
105
  };
60
106
  var Success = Template.bind({});
61
107
  exports.Success = Success;
62
108
  Success.args = {
63
109
  value: 'Occaecat',
64
- success: true
110
+ success: true,
111
+ options: [{
112
+ label: 'The Shawshank Redemption The Shawshank Redemption',
113
+ value: 1994
114
+ }, {
115
+ label: 'The Godfather',
116
+ value: 1972
117
+ }, {
118
+ label: 'The Godfather: Part II',
119
+ value: 1974
120
+ }, {
121
+ label: 'The Dark Knight',
122
+ value: 2008
123
+ }, {
124
+ label: '12 Angry Men',
125
+ value: 1957
126
+ }, {
127
+ label: "Schindler's List",
128
+ value: 1993
129
+ }, {
130
+ label: 'Pulp Fiction',
131
+ value: 1994
132
+ }]
65
133
  };
66
134
  var Disabled = Template.bind({});
67
135
  exports.Disabled = Disabled;
68
136
  Disabled.args = {
69
137
  value: 'Occaecat',
70
- disabled: true
138
+ disabled: true,
139
+ options: [{
140
+ label: 'The Shawshank Redemption The Shawshank Redemption',
141
+ value: 1994
142
+ }, {
143
+ label: 'The Godfather',
144
+ value: 1972
145
+ }, {
146
+ label: 'The Godfather: Part II',
147
+ value: 1974
148
+ }, {
149
+ label: 'The Dark Knight',
150
+ value: 2008
151
+ }, {
152
+ label: '12 Angry Men',
153
+ value: 1957
154
+ }, {
155
+ label: "Schindler's List",
156
+ value: 1993
157
+ }, {
158
+ label: 'Pulp Fiction',
159
+ value: 1994
160
+ }]
71
161
  };
72
162
  var ErrorTemplate = Template.bind({});
73
163
  exports.ErrorTemplate = ErrorTemplate;
74
164
  ErrorTemplate.args = {
75
165
  value: 'Occaecat',
76
- error: 'Error'
166
+ error: 'Error',
167
+ options: [{
168
+ label: 'The Shawshank Redemption The Shawshank Redemption',
169
+ value: 1994
170
+ }, {
171
+ label: 'The Godfather',
172
+ value: 1972
173
+ }, {
174
+ label: 'The Godfather: Part II',
175
+ value: 1974
176
+ }, {
177
+ label: 'The Dark Knight',
178
+ value: 2008
179
+ }, {
180
+ label: '12 Angry Men',
181
+ value: 1957
182
+ }, {
183
+ label: "Schindler's List",
184
+ value: 1993
185
+ }, {
186
+ label: 'Pulp Fiction',
187
+ value: 1994
188
+ }]
77
189
  };
@@ -0,0 +1,5 @@
1
+ .cbx-inputAutocomplete-fullwidth ul li {
2
+ width: 100%!important;
3
+ min-width: 100%!important;
4
+ max-width: 100%!important;
5
+ }