@bolttech/molecules-dropdown 0.13.0 → 0.15.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.
package/index.cjs CHANGED
@@ -9,6 +9,7 @@ var atomsSelect = require('@bolttech/atoms-select');
9
9
  var atomsIcon = require('@bolttech/atoms-icon');
10
10
  var atomsInput = require('@bolttech/atoms-input');
11
11
  var styled = require('styled-components');
12
+ var uiUtils = require('@bolttech/ui-utils');
12
13
  var reactDom = require('react-dom');
13
14
 
14
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -1652,6 +1653,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1652
1653
  PERFORMANCE OF THIS SOFTWARE.
1653
1654
  ***************************************************************************** */
1654
1655
 
1656
+ function __rest(s, e) {
1657
+ var t = {};
1658
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
1659
+ t[p] = s[p];
1660
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
1661
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
1662
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
1663
+ t[p[i]] = s[p[i]];
1664
+ }
1665
+ return t;
1666
+ }
1667
+
1655
1668
  function __awaiter(thisArg, _arguments, P, generator) {
1656
1669
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1657
1670
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -2414,33 +2427,35 @@ const DropdownOptionsContainer = /*#__PURE__*/styled__default["default"].div.wit
2414
2427
  componentId: "sc-3wugi4-6"
2415
2428
  })(["position:absolute;inset:0;top:100%;"]);
2416
2429
 
2417
- const ReusableDropdownComponent = ({
2418
- id,
2419
- dataTestId,
2420
- label,
2421
- variant: _variant = 'grey',
2422
- required,
2423
- inputValue,
2424
- inputLabel,
2425
- disabled,
2426
- errorMessage,
2427
- onChangeInputValue,
2428
- onChangeInputLabel,
2429
- setShowSelectComponent,
2430
- showSelectComponent,
2431
- setSelectedOptionOnInputValue,
2432
- inputRef,
2433
- placeholder,
2434
- onBlur,
2435
- onFocus
2436
- }) => {
2430
+ const ReusableDropdownComponent = _a => {
2431
+ var {
2432
+ id,
2433
+ dataTestId,
2434
+ label,
2435
+ variant = 'grey',
2436
+ required,
2437
+ inputValue,
2438
+ inputLabel,
2439
+ disabled,
2440
+ errorMessage,
2441
+ onChangeInputValue,
2442
+ onChangeInputLabel,
2443
+ setShowSelectComponent,
2444
+ showSelectComponent,
2445
+ setSelectedOptionOnInputValue,
2446
+ inputRef,
2447
+ placeholder,
2448
+ onBlur,
2449
+ onFocus
2450
+ } = _a,
2451
+ props = __rest(_a, ["id", "dataTestId", "label", "variant", "required", "inputValue", "inputLabel", "disabled", "errorMessage", "onChangeInputValue", "onChangeInputLabel", "setShowSelectComponent", "showSelectComponent", "setSelectedOptionOnInputValue", "inputRef", "placeholder", "onBlur", "onFocus"]);
2437
2452
  const hasError = !!errorMessage;
2438
2453
  // we have to type cast because of jest. when testing it sets the type of useTheme to DefaultTheme
2439
2454
  const theme = /*#__PURE__*/styled.useTheme();
2440
2455
  const sizeIcon = Number(theme.components.dropdown.icon.size.replace(/[^\d.-]+/g, ''));
2441
2456
  return jsxRuntime.jsxs(jsxRuntime.Fragment, {
2442
2457
  children: [jsxRuntime.jsxs(ContainerDropdown, {
2443
- variant: _variant,
2458
+ variant: variant,
2444
2459
  hasValue: inputValue,
2445
2460
  hasError: hasError,
2446
2461
  disabled: disabled,
@@ -2461,13 +2476,13 @@ const ReusableDropdownComponent = ({
2461
2476
  children: "*"
2462
2477
  })]
2463
2478
  }), jsxRuntime.jsx(InputAndIconDropdown, {
2464
- children: jsxRuntime.jsx(atomsInput.InputStyled, {
2479
+ children: jsxRuntime.jsx(atomsInput.InputStyled, Object.assign({
2465
2480
  id: `${id}-input`,
2466
2481
  "data-testid": `${dataTestId}-input`,
2467
2482
  ref: inputRef,
2468
2483
  disabled: disabled,
2469
2484
  value: inputLabel,
2470
- variant: _variant,
2485
+ variant: variant,
2471
2486
  placeholder: placeholder,
2472
2487
  onChange: e => {
2473
2488
  var _a, _b;
@@ -2486,7 +2501,7 @@ const ReusableDropdownComponent = ({
2486
2501
  setShowSelectComponent(false);
2487
2502
  onBlur && onBlur(event);
2488
2503
  }
2489
- })
2504
+ }, uiUtils.applyDataAttributes(props, 'input')))
2490
2505
  })]
2491
2506
  }), jsxRuntime.jsx(ClickableElement, {
2492
2507
  onClick: () => {
@@ -2632,24 +2647,26 @@ function filterOptionsWithHeaders(inputValue, optionList) {
2632
2647
  });
2633
2648
  }
2634
2649
 
2635
- const Dropdown = /*#__PURE__*/react.forwardRef(({
2636
- label,
2637
- variant: _variant = 'grey',
2638
- required,
2639
- optionList,
2640
- disabled,
2641
- errorMessage,
2642
- urlFilterOptions,
2643
- id: _id = 'dropdown-id',
2644
- dataTestId: _dataTestId = 'dropdown-data-testid',
2645
- filterOptionsParam: _filterOptionsParam = filterOptions,
2646
- value,
2647
- onChange,
2648
- onBlur,
2649
- onFocus,
2650
- placeholder
2651
- }, ref) => {
2652
- var _a;
2650
+ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
2651
+ var _b;
2652
+ var {
2653
+ label,
2654
+ variant = 'grey',
2655
+ required,
2656
+ optionList,
2657
+ disabled,
2658
+ errorMessage,
2659
+ urlFilterOptions,
2660
+ id = 'dropdown-id',
2661
+ dataTestId = 'dropdown-data-testid',
2662
+ filterOptionsParam = filterOptions,
2663
+ value,
2664
+ onChange,
2665
+ onBlur,
2666
+ onFocus,
2667
+ placeholder
2668
+ } = _a,
2669
+ props = __rest(_a, ["label", "variant", "required", "optionList", "disabled", "errorMessage", "urlFilterOptions", "id", "dataTestId", "filterOptionsParam", "value", "onChange", "onBlur", "onFocus", "placeholder"]);
2653
2670
  const [showSelectComponent, setShowSelectComponent] = react.useState(false);
2654
2671
  const [currentOptionList, setCurrentOptionList] = react.useState([]);
2655
2672
  const [inputValue, setInputValue] = react.useState('');
@@ -2659,10 +2676,10 @@ const Dropdown = /*#__PURE__*/react.forwardRef(({
2659
2676
  const inputRef = react.useRef(null);
2660
2677
  react.useEffect(() => {
2661
2678
  const normalizeOptionList = () => __awaiter(void 0, void 0, void 0, function* () {
2662
- return yield _filterOptionsParam(inputValue, optionList, urlFilterOptions);
2679
+ return yield filterOptionsParam(inputValue, optionList, urlFilterOptions);
2663
2680
  });
2664
2681
  normalizeOptionList().then(optionsResponse => setCurrentOptionList([...optionsResponse])).catch(error => console.error('An error happens when trying to normalize options', error));
2665
- }, [_filterOptionsParam, optionList, urlFilterOptions, inputValue]);
2682
+ }, [filterOptionsParam, optionList, urlFilterOptions, inputValue]);
2666
2683
  const setSelectedOptionOnInputValue = react.useCallback(() => {
2667
2684
  if (!inputValue && internalSelectedOption) {
2668
2685
  setInputValue((internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value) || '');
@@ -2686,23 +2703,24 @@ const Dropdown = /*#__PURE__*/react.forwardRef(({
2686
2703
  setInternalSelectedOption(currentOptionList.find(option => option.id === value));
2687
2704
  setIsFirstRender(false);
2688
2705
  }, [currentOptionList, isFirstRender, setSelectedOptionOnInputValue, value]);
2689
- return jsxRuntime.jsxs(SectionContainer, {
2706
+ return jsxRuntime.jsxs(SectionContainer, Object.assign({
2690
2707
  onClick: () => {
2691
2708
  var _a;
2692
2709
  return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
2693
2710
  },
2694
- variant: _variant,
2695
- id: `${_id}-container`,
2696
- "data-testid": `${_dataTestId}-container`,
2711
+ variant: variant,
2712
+ id: `${id}-container`,
2713
+ "data-testid": `${dataTestId}-container`,
2697
2714
  style: {
2698
- maxWidth: (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.style.width
2715
+ maxWidth: (_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.style.width
2699
2716
  },
2700
- ref: ref,
2701
- children: [jsxRuntime.jsx(ReusableDropdownComponent, {
2702
- id: _id,
2703
- dataTestId: _dataTestId,
2717
+ ref: ref
2718
+ }, uiUtils.applyDataAttributes(props), {
2719
+ children: [jsxRuntime.jsx(ReusableDropdownComponent, Object.assign({
2720
+ id: id,
2721
+ dataTestId: dataTestId,
2704
2722
  label: label,
2705
- variant: _variant,
2723
+ variant: variant,
2706
2724
  required: required,
2707
2725
  inputValue: inputValue,
2708
2726
  inputLabel: inputLabel,
@@ -2717,10 +2735,10 @@ const Dropdown = /*#__PURE__*/react.forwardRef(({
2717
2735
  onChangeInputLabel: setInputLabel,
2718
2736
  onBlur: onBlur,
2719
2737
  onFocus: onFocus
2720
- }), showSelectComponent && !disabled && jsxRuntime.jsx(DropdownOptionsContainer, {
2721
- children: jsxRuntime.jsx(atomsSelect.Select, {
2722
- id: `${_id}-select`,
2723
- dataTestId: `${_dataTestId}-select`,
2738
+ }, props)), showSelectComponent && !disabled && jsxRuntime.jsx(DropdownOptionsContainer, {
2739
+ children: jsxRuntime.jsx(atomsSelect.Select, Object.assign({
2740
+ id: `${id}-select`,
2741
+ dataTestId: `${dataTestId}-select`,
2724
2742
  onChange: selectedValue => {
2725
2743
  var _a;
2726
2744
  setInputValue(selectedValue.value);
@@ -2733,27 +2751,29 @@ const Dropdown = /*#__PURE__*/react.forwardRef(({
2733
2751
  },
2734
2752
  active: internalSelectedOption,
2735
2753
  options: currentOptionList
2736
- })
2754
+ }, uiUtils.applyDataAttributes(props, 'select')))
2737
2755
  })]
2738
- });
2756
+ }));
2739
2757
  });
2740
2758
 
2741
- const DropdownWithHeaders = /*#__PURE__*/react.forwardRef(({
2742
- label,
2743
- variant: _variant = 'grey',
2744
- required,
2745
- optionList,
2746
- disabled,
2747
- errorMessage,
2748
- urlFilterOptions,
2749
- dataTestId,
2750
- filterOptionsParam: _filterOptionsParam = filterOptionsWithHeaders,
2751
- value,
2752
- onChange,
2753
- onBlur,
2754
- onFocus,
2755
- placeholder
2756
- }, ref) => {
2759
+ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
2760
+ var {
2761
+ label,
2762
+ variant = 'grey',
2763
+ required,
2764
+ optionList,
2765
+ disabled,
2766
+ errorMessage,
2767
+ urlFilterOptions,
2768
+ dataTestId,
2769
+ filterOptionsParam = filterOptionsWithHeaders,
2770
+ value,
2771
+ onChange,
2772
+ onBlur,
2773
+ onFocus,
2774
+ placeholder
2775
+ } = _a,
2776
+ props = __rest(_a, ["label", "variant", "required", "optionList", "disabled", "errorMessage", "urlFilterOptions", "dataTestId", "filterOptionsParam", "value", "onChange", "onBlur", "onFocus", "placeholder"]);
2757
2777
  const [showSelectComponent, setShowSelectComponent] = react.useState(false);
2758
2778
  const [currentOptionList, setCurrentOptionList] = react.useState([]);
2759
2779
  const [inputValue, setInputValue] = react.useState('');
@@ -2763,10 +2783,10 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef(({
2763
2783
  const inputRef = react.useRef(null);
2764
2784
  react.useEffect(() => {
2765
2785
  const normalizeOptionList = () => __awaiter(void 0, void 0, void 0, function* () {
2766
- return yield _filterOptionsParam(inputValue, optionList, urlFilterOptions);
2786
+ return yield filterOptionsParam(inputValue, optionList, urlFilterOptions);
2767
2787
  });
2768
2788
  normalizeOptionList().then(optionsResponse => setCurrentOptionList([...optionsResponse])).catch(error => console.error('An error happens when trying to normalize options', error));
2769
- }, [_filterOptionsParam, optionList, urlFilterOptions, inputValue]);
2789
+ }, [filterOptionsParam, optionList, urlFilterOptions, inputValue]);
2770
2790
  const setSelectedOptionOnInputValue = react.useCallback(() => {
2771
2791
  if (!inputValue && internalSelectedOption) {
2772
2792
  setInputValue((internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value) || '');
@@ -2796,17 +2816,18 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef(({
2796
2816
  })[0] || undefined);
2797
2817
  setIsFirstRender(false);
2798
2818
  }, [currentOptionList, isFirstRender, setSelectedOptionOnInputValue, value]);
2799
- return jsxRuntime.jsxs(SectionContainer, {
2819
+ return jsxRuntime.jsxs(SectionContainer, Object.assign({
2800
2820
  onClick: () => {
2801
2821
  var _a;
2802
2822
  return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
2803
2823
  },
2804
- variant: _variant,
2824
+ variant: variant,
2805
2825
  "data-testid": `${dataTestId}-container`,
2806
- ref: ref,
2807
- children: [jsxRuntime.jsx(ReusableDropdownComponent, {
2826
+ ref: ref
2827
+ }, uiUtils.applyDataAttributes(props), {
2828
+ children: [jsxRuntime.jsx(ReusableDropdownComponent, Object.assign({
2808
2829
  label: label,
2809
- variant: _variant,
2830
+ variant: variant,
2810
2831
  required: required,
2811
2832
  inputValue: inputValue,
2812
2833
  inputLabel: inputLabel,
@@ -2822,8 +2843,8 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef(({
2822
2843
  setSelectedOptionOnInputValue: setSelectedOptionOnInputValue,
2823
2844
  onBlur: onBlur,
2824
2845
  onFocus: onFocus
2825
- }), showSelectComponent && !disabled && jsxRuntime.jsx(DropdownOptionsContainer, {
2826
- children: jsxRuntime.jsx(atomsSelect.SelectWithHeaders, {
2846
+ }, props)), showSelectComponent && !disabled && jsxRuntime.jsx(DropdownOptionsContainer, {
2847
+ children: jsxRuntime.jsx(atomsSelect.SelectWithHeaders, Object.assign({
2827
2848
  dataTestId: `${dataTestId}-select`,
2828
2849
  onChange: selectedValue => {
2829
2850
  var _a;
@@ -2837,9 +2858,9 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef(({
2837
2858
  },
2838
2859
  active: internalSelectedOption,
2839
2860
  options: currentOptionList
2840
- })
2861
+ }, uiUtils.applyDataAttributes(props, 'select')))
2841
2862
  })]
2842
- });
2863
+ }));
2843
2864
  });
2844
2865
 
2845
2866
  exports.Dropdown = Dropdown;
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@bolttech/molecules-dropdown",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "main": "./index.cjs",
5
5
  "type": "commonjs",
6
6
  "types": "./src/index.d.ts",
7
7
  "dependencies": {
8
- "@bolttech/atoms-icon": "0.19.0",
9
- "@bolttech/atoms-input": "0.16.0",
10
- "@bolttech/atoms-select": "0.16.0",
11
- "@edirect/frontend-foundations": "0.0.67",
8
+ "@bolttech/atoms-icon": "0.20.0",
9
+ "@bolttech/atoms-input": "0.18.0",
10
+ "@bolttech/atoms-select": "0.17.0",
11
+ "@bolttech/ui-utils": "0.1.1",
12
+ "@edirect/frontend-foundations": "0.0.69",
12
13
  "jest-styled-components": "7.1.1",
13
14
  "react": "18.2.0",
14
15
  "react-dom": "18.2.0",
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { OptionWithHeaderType, OptionType } from '@bolttech/atoms-select';
3
- export declare const DropdownWithHeaders: import("react").ForwardRefExoticComponent<{
3
+ export declare const DropdownWithHeaders: import("react").ForwardRefExoticComponent<import("@bolttech/ui-utils").DefaultProps & {
4
4
  label: string;
5
5
  placeholder?: string | undefined;
6
6
  disabled?: boolean | undefined;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { OptionType } from '@bolttech/atoms-select';
3
- export declare const Dropdown: import("react").ForwardRefExoticComponent<{
3
+ export declare const Dropdown: import("react").ForwardRefExoticComponent<import("@bolttech/ui-utils").DefaultProps & {
4
4
  label: string;
5
5
  placeholder?: string | undefined;
6
6
  disabled?: boolean | undefined;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { OptionType, OptionWithHeaderType } from '@bolttech/atoms-select';
3
+ import { DefaultProps } from '@bolttech/ui-utils';
3
4
  /**
4
5
  * @typedef {StyleVariants}
5
6
  The string value possibilities to affect the theme
@@ -16,7 +17,7 @@ Default props for Dropdown component
16
17
  @property required - An optional boolean to indicate if the dropdown is required
17
18
  @property variant - An optional string to set the variant of the dropdown
18
19
  */
19
- type DefaultProps = {
20
+ type DefaultDropdownProps = {
20
21
  label: string;
21
22
  placeholder?: string;
22
23
  disabled?: boolean;
@@ -37,7 +38,7 @@ type DefaultProps = {
37
38
  @property setSelectedOption - A function to set the selected option
38
39
  @property selectedOption - An optional object representing the currently selected option
39
40
  */
40
- export type DropdownProps = DefaultProps & {
41
+ export type DropdownProps = DefaultProps & DefaultDropdownProps & {
41
42
  optionList?: OptionType[];
42
43
  /**
43
44
  * An optional function that filters the option list based on input value
@@ -97,7 +98,7 @@ export type DropdownProps = DefaultProps & {
97
98
  @property setSelectedOption - A function to set the selected option
98
99
  @property selectedOption - An optional object representing the currently selected option
99
100
  */
100
- export type DropdownWithHeadersProps = DefaultProps & {
101
+ export type DropdownWithHeadersProps = DefaultProps & DefaultDropdownProps & {
101
102
  optionList?: OptionWithHeaderType[];
102
103
  /**
103
104
  * An optional function that filters the option list based on input value
@@ -167,7 +168,7 @@ export type DropdownWithHeadersProps = DefaultProps & {
167
168
  @property setSelectedOptionOnInputValue - A function to set the selected option based on the input value
168
169
  @property inputRef - A ref to the input element of the dropdown
169
170
  */
170
- export type ReusableDropdownComponentProps = DefaultProps & {
171
+ export type ReusableDropdownComponentProps = DefaultProps & DefaultDropdownProps & {
171
172
  setShowSelectComponent: React.Dispatch<React.SetStateAction<boolean>>;
172
173
  showSelectComponent: boolean;
173
174
  onChangeInputValue: React.Dispatch<React.SetStateAction<string>>;
@@ -1,2 +1,2 @@
1
1
  import { ReusableDropdownComponentProps } from './molecules-dropdown.type';
2
- export declare const ReusableDropdownComponent: ({ id, dataTestId, label, variant, required, inputValue, inputLabel, disabled, errorMessage, onChangeInputValue, onChangeInputLabel, setShowSelectComponent, showSelectComponent, setSelectedOptionOnInputValue, inputRef, placeholder, onBlur, onFocus, }: ReusableDropdownComponentProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const ReusableDropdownComponent: ({ id, dataTestId, label, variant, required, inputValue, inputLabel, disabled, errorMessage, onChangeInputValue, onChangeInputLabel, setShowSelectComponent, showSelectComponent, setSelectedOptionOnInputValue, inputRef, placeholder, onBlur, onFocus, ...props }: ReusableDropdownComponentProps) => import("react/jsx-runtime").JSX.Element;