@lumx/react 3.0.5 → 3.0.6-alpha.2

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.d.ts CHANGED
@@ -63,10 +63,13 @@ interface AutocompleteProps extends GenericProps, HasTheme {
63
63
  */
64
64
  placement?: Placement;
65
65
  /**
66
- * Whether the dropdown should fit to the anchor width or not.
66
+ * Manage dropdown width:
67
+ * - `maxWidth`: dropdown not bigger than anchor
68
+ * - `minWidth` or `true`: dropdown not smaller than anchor
69
+ * - `width`: dropdown equal to the anchor.
67
70
  * @see {@link DropdownProps#fitToAnchorWidth}
68
71
  */
69
- fitToAnchorWidth?: boolean;
72
+ fitToAnchorWidth?: DropdownProps['fitToAnchorWidth'];
70
73
  /**
71
74
  * The error related to the component.
72
75
  * @see {@link TextFieldProps#error}
@@ -182,7 +185,7 @@ interface AutocompleteProps extends GenericProps, HasTheme {
182
185
  * Only the props not managed by the Autocomplete can be set.
183
186
  * @see {@link TextFieldProps}
184
187
  */
185
- textFieldProps?: TextFieldProps;
188
+ textFieldProps?: Partial<TextFieldProps>;
186
189
  }
187
190
  /**
188
191
  * Autocomplete component.
@@ -717,6 +720,12 @@ interface Offset {
717
720
  * Popover elevation index.
718
721
  */
719
722
  declare type Elevation = 1 | 2 | 3 | 4 | 5;
723
+ declare const AnchorWidthOptions: {
724
+ readonly MAX_WIDTH: "maxWidth";
725
+ readonly MIN_WIDTH: "minWidth";
726
+ readonly WIDTH: "width";
727
+ };
728
+ declare type AnchorWidthOption = ValueOf<typeof AnchorWidthOptions>;
720
729
  /**
721
730
  * Defines the props of the component.
722
731
  */
@@ -733,8 +742,13 @@ interface PopoverProps extends GenericProps {
733
742
  closeOnEscape?: boolean;
734
743
  /** Shadow elevation. */
735
744
  elevation?: Elevation;
736
- /** Whether the dropdown should fit to the anchor width (if dropdown is smaller). */
737
- fitToAnchorWidth?: boolean;
745
+ /**
746
+ * Manage popover width:
747
+ * - `maxWidth`: popover not bigger than anchor
748
+ * - `minWidth` or `true`: popover not smaller than anchor
749
+ * - `width`: popover equal to the anchor.
750
+ */
751
+ fitToAnchorWidth?: AnchorWidthOption | boolean;
738
752
  /** Shrink popover if even after flipping there is not enough space. */
739
753
  fitWithinViewportHeight?: boolean;
740
754
  /** Element to focus when opening the popover. */
@@ -793,10 +807,13 @@ interface DropdownProps extends GenericProps {
793
807
  */
794
808
  closeOnEscape?: boolean;
795
809
  /**
796
- * Whether the dropdown should fit to the anchor width (if dropdown is smaller) or not.
810
+ * Manage dropdown width:
811
+ * - `maxWidth`: dropdown not bigger than anchor
812
+ * - `minWidth` or `true`: dropdown not smaller than anchor
813
+ * - `width`: dropdown equal to the anchor.
797
814
  * @see {@link PopoverProps#fitToAnchorWidth}
798
815
  */
799
- fitToAnchorWidth?: boolean;
816
+ fitToAnchorWidth?: PopoverProps['fitToAnchorWidth'];
800
817
  /**
801
818
  * Whether the dropdown should shrink to fit within the viewport height or not.
802
819
  * @see {@link PopoverProps#fitWithinViewportHeight}
package/index.js CHANGED
@@ -16,6 +16,7 @@ import dropRight from 'lodash/dropRight';
16
16
  import partition from 'lodash/partition';
17
17
  import reduce from 'lodash/reduce';
18
18
  import { C as ClickAwayProvider } from './_internal/ClickAwayProvider.js';
19
+ import memoize from 'lodash/memoize';
19
20
  import castArray from 'lodash/castArray';
20
21
  import pick from 'lodash/pick';
21
22
  import isObject from 'lodash/isObject';
@@ -5871,11 +5872,11 @@ const Placement = {
5871
5872
  * Arrow size (in pixel).
5872
5873
  */
5873
5874
  const ARROW_SIZE = 8;
5874
-
5875
- /**
5876
- * Defines the props of the component.
5877
- */
5878
-
5875
+ const AnchorWidthOptions = {
5876
+ MAX_WIDTH: 'maxWidth',
5877
+ MIN_WIDTH: 'minWidth',
5878
+ WIDTH: 'width'
5879
+ };
5879
5880
  /**
5880
5881
  * Component display name.
5881
5882
  */
@@ -5899,7 +5900,7 @@ const DEFAULT_PROPS$g = {
5899
5900
  /**
5900
5901
  * Popper js modifier to fit popover min width to the anchor width.
5901
5902
  */
5902
- const sameWidth = {
5903
+ const sameWidth = memoize(anchorWidthOption => ({
5903
5904
  name: 'sameWidth',
5904
5905
  enabled: true,
5905
5906
  phase: 'beforeWrite',
@@ -5909,16 +5910,16 @@ const sameWidth = {
5909
5910
  state
5910
5911
  } = _ref;
5911
5912
  // eslint-disable-next-line no-param-reassign
5912
- state.styles.popper.minWidth = `${state.rects.reference.width}px`;
5913
+ state.styles.popper[anchorWidthOption] = `${state.rects.reference.width}px`;
5913
5914
  },
5914
5915
  effect(_ref2) {
5915
5916
  let {
5916
5917
  state
5917
5918
  } = _ref2;
5918
5919
  // eslint-disable-next-line no-param-reassign
5919
- state.elements.popper.style.minWidth = `${state.elements.reference.offsetWidth}px`;
5920
+ state.elements.popper.style[anchorWidthOption] = `${state.elements.reference.offsetWidth}px`;
5920
5921
  }
5921
- };
5922
+ }));
5922
5923
 
5923
5924
  /**
5924
5925
  * Popper js modifier to compute max size of the popover.
@@ -6086,7 +6087,8 @@ const Popover = /*#__PURE__*/forwardRef((props, ref) => {
6086
6087
  });
6087
6088
  }
6088
6089
  if (fitToAnchorWidth) {
6089
- modifiers.push(sameWidth);
6090
+ const anchorWidthOption = typeof fitToAnchorWidth === 'string' ? fitToAnchorWidth : AnchorWidthOptions.MIN_WIDTH;
6091
+ modifiers.push(sameWidth(anchorWidthOption));
6090
6092
  }
6091
6093
  if (fitWithinViewportHeight) {
6092
6094
  modifiers.push(_objectSpread2(_objectSpread2({}, maxSize), {}, {