@lumx/react 3.0.5 → 3.0.6-alpha.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/index.d.ts +11 -5
- package/index.js +12 -10
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/autocomplete/Autocomplete.tsx +3 -3
- package/src/components/dropdown/Dropdown.tsx +1 -1
- package/src/components/popover/Popover.stories.tsx +70 -0
- package/src/components/popover/Popover.tsx +17 -7
package/index.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ interface AutocompleteProps extends GenericProps, HasTheme {
|
|
|
66
66
|
* Whether the dropdown should fit to the anchor width or not.
|
|
67
67
|
* @see {@link DropdownProps#fitToAnchorWidth}
|
|
68
68
|
*/
|
|
69
|
-
fitToAnchorWidth?:
|
|
69
|
+
fitToAnchorWidth?: DropdownProps['fitToAnchorWidth'];
|
|
70
70
|
/**
|
|
71
71
|
* The error related to the component.
|
|
72
72
|
* @see {@link TextFieldProps#error}
|
|
@@ -182,7 +182,7 @@ interface AutocompleteProps extends GenericProps, HasTheme {
|
|
|
182
182
|
* Only the props not managed by the Autocomplete can be set.
|
|
183
183
|
* @see {@link TextFieldProps}
|
|
184
184
|
*/
|
|
185
|
-
textFieldProps?: TextFieldProps
|
|
185
|
+
textFieldProps?: Partial<TextFieldProps>;
|
|
186
186
|
}
|
|
187
187
|
/**
|
|
188
188
|
* Autocomplete component.
|
|
@@ -717,6 +717,12 @@ interface Offset {
|
|
|
717
717
|
* Popover elevation index.
|
|
718
718
|
*/
|
|
719
719
|
declare type Elevation = 1 | 2 | 3 | 4 | 5;
|
|
720
|
+
declare const AnchorWidthOptions: {
|
|
721
|
+
readonly MAX_WIDTH: "maxWidth";
|
|
722
|
+
readonly MIN_WIDTH: "minWidth";
|
|
723
|
+
readonly WIDTH: "width";
|
|
724
|
+
};
|
|
725
|
+
declare type AnchorWidthOption = ValueOf<typeof AnchorWidthOptions>;
|
|
720
726
|
/**
|
|
721
727
|
* Defines the props of the component.
|
|
722
728
|
*/
|
|
@@ -733,8 +739,8 @@ interface PopoverProps extends GenericProps {
|
|
|
733
739
|
closeOnEscape?: boolean;
|
|
734
740
|
/** Shadow elevation. */
|
|
735
741
|
elevation?: Elevation;
|
|
736
|
-
/**
|
|
737
|
-
fitToAnchorWidth?: boolean;
|
|
742
|
+
/** manage popover size to not be bigger (`width` & `maxWidth`) or smaller (`width`, `minWidth`, `true`) than the anchor. */
|
|
743
|
+
fitToAnchorWidth?: AnchorWidthOption | boolean;
|
|
738
744
|
/** Shrink popover if even after flipping there is not enough space. */
|
|
739
745
|
fitWithinViewportHeight?: boolean;
|
|
740
746
|
/** Element to focus when opening the popover. */
|
|
@@ -796,7 +802,7 @@ interface DropdownProps extends GenericProps {
|
|
|
796
802
|
* Whether the dropdown should fit to the anchor width (if dropdown is smaller) or not.
|
|
797
803
|
* @see {@link PopoverProps#fitToAnchorWidth}
|
|
798
804
|
*/
|
|
799
|
-
fitToAnchorWidth?:
|
|
805
|
+
fitToAnchorWidth?: PopoverProps['fitToAnchorWidth'];
|
|
800
806
|
/**
|
|
801
807
|
* Whether the dropdown should shrink to fit within the viewport height or not.
|
|
802
808
|
* @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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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), {}, {
|