@mezzanine-ui/react 0.7.1 → 0.8.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.
Files changed (43) hide show
  1. package/Drawer/Drawer.d.ts +2 -7
  2. package/Drawer/Drawer.js +5 -21
  3. package/Form/useAutoCompleteValueControl.d.ts +2 -2
  4. package/Form/useAutoCompleteValueControl.js +9 -5
  5. package/Form/useSelectValueControl.d.ts +25 -8
  6. package/Form/useSelectValueControl.js +38 -20
  7. package/Icon/Icon.d.ts +4 -0
  8. package/Icon/Icon.js +3 -2
  9. package/Modal/Modal.d.ts +2 -7
  10. package/Modal/Modal.js +8 -57
  11. package/Modal/index.d.ts +1 -0
  12. package/Modal/index.js +1 -0
  13. package/Modal/useModalContainer.d.ts +6 -0
  14. package/Modal/useModalContainer.js +27 -0
  15. package/Select/AutoComplete.js +5 -3
  16. package/Select/Option.js +13 -1
  17. package/Select/Select.d.ts +90 -12
  18. package/Select/Select.js +8 -3
  19. package/Select/SelectTrigger.d.ts +37 -9
  20. package/Select/SelectTrigger.js +29 -5
  21. package/Select/typings.d.ts +2 -2
  22. package/Transition/Transition.d.ts +1 -1
  23. package/Upload/UploadInput.js +2 -0
  24. package/Upload/UploadPicture.d.ts +48 -0
  25. package/Upload/UploadPicture.js +52 -0
  26. package/Upload/UploadPictureBlock.d.ts +13 -0
  27. package/Upload/UploadPictureBlock.js +86 -0
  28. package/Upload/UploadPictureWall.d.ts +71 -0
  29. package/Upload/UploadPictureWall.js +156 -0
  30. package/Upload/UploadPictureWallItem.d.ts +13 -0
  31. package/Upload/UploadPictureWallItem.js +19 -0
  32. package/Upload/index.d.ts +3 -0
  33. package/Upload/index.js +3 -0
  34. package/_internal/SlideFadeOverlay/SlideFadeOverlay.d.ts +21 -0
  35. package/_internal/SlideFadeOverlay/SlideFadeOverlay.js +66 -0
  36. package/_internal/SlideFadeOverlay/index.d.ts +1 -0
  37. package/_internal/SlideFadeOverlay/index.js +1 -0
  38. package/_internal/SlideFadeOverlay/useTopStack.d.ts +1 -0
  39. package/{Modal/useIsTopModal.js → _internal/SlideFadeOverlay/useTopStack.js} +3 -3
  40. package/index.d.ts +3 -4
  41. package/index.js +5 -1
  42. package/package.json +3 -3
  43. package/Modal/useIsTopModal.d.ts +0 -1
@@ -1,13 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { DrawerPlacement } from '@mezzanine-ui/core/drawer';
3
- import { OverlayProps } from '../Overlay';
3
+ import { SlideFadeOverlayProps } from '../_internal/SlideFadeOverlay';
4
4
  import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
5
- export interface DrawerProps extends NativeElementPropsWithoutKeyAndRef<'div'>, Pick<OverlayProps, 'container' | 'disableCloseOnBackdropClick' | 'disablePortal' | 'hideBackdrop' | 'invisibleBackdrop' | 'onBackdropClick' | 'onClose' | 'open'> {
6
- /**
7
- * Controls whether to disable closing drawer while escape key down.
8
- * @default false
9
- */
10
- disableCloseOnEscapeKeyDown?: boolean;
5
+ export interface DrawerProps extends Omit<SlideFadeOverlayProps, 'children'>, Pick<NativeElementPropsWithoutKeyAndRef<'div'>, 'children'> {
11
6
  /**
12
7
  * Whether the drawer placement.
13
8
  * @default 'left'
package/Drawer/Drawer.js CHANGED
@@ -1,34 +1,18 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
- import { forwardRef, useState } from 'react';
2
+ import { forwardRef, useMemo } from 'react';
3
3
  import { drawerClasses } from '@mezzanine-ui/core/drawer';
4
- import { useDocumentEscapeKeyDown } from '../hooks/useDocumentEscapeKeyDown.js';
5
- import Overlay from '../Overlay/Overlay.js';
6
- import SlideFade from '../Transition/SlideFade.js';
4
+ import SlideFadeOverlay from '../_internal/SlideFadeOverlay/SlideFadeOverlay.js';
7
5
  import cx from 'clsx';
8
6
 
9
7
  const Drawer = forwardRef((props, ref) => {
10
8
  const { className, children, container, disableCloseOnBackdropClick = false, disableCloseOnEscapeKeyDown = false, disablePortal, hideBackdrop, invisibleBackdrop, onBackdropClick, onClose, open, placement = 'left', ...rest } = props;
11
- const [exited, setExited] = useState(true);
12
- useDocumentEscapeKeyDown(() => {
13
- if (!open || disableCloseOnEscapeKeyDown || !onClose) {
14
- return;
15
- }
16
- return onClose;
17
- }, [
18
- disableCloseOnEscapeKeyDown,
19
- open,
20
- onClose,
21
- ]);
22
- if (!open && exited) {
23
- return null;
24
- }
25
- const slideFadeDirection = {
9
+ const slideFadeDirection = useMemo(() => ({
26
10
  top: 'down',
27
11
  left: 'right',
28
12
  right: 'left',
29
13
  bottom: 'up',
30
- };
31
- return (jsx(Overlay, Object.assign({ className: drawerClasses.overlay, container: container, disableCloseOnBackdropClick: disableCloseOnBackdropClick, disablePortal: disablePortal, hideBackdrop: hideBackdrop, invisibleBackdrop: invisibleBackdrop, onBackdropClick: onBackdropClick, onClose: onClose, open: open, role: "presentation" }, { children: jsx(SlideFade, Object.assign({ ref: ref, direction: slideFadeDirection[placement], in: open, onEntered: () => setExited(false), onExited: () => setExited(true) }, { children: jsx("div", Object.assign({}, rest, { className: cx(drawerClasses.host, drawerClasses[placement], className) }, { children: children }), void 0) }), void 0) }), void 0));
14
+ }), []);
15
+ return (jsx(SlideFadeOverlay, Object.assign({ className: drawerClasses.overlay, container: container, direction: slideFadeDirection[placement], disableCloseOnBackdropClick: disableCloseOnBackdropClick, disableCloseOnEscapeKeyDown: disableCloseOnEscapeKeyDown, disablePortal: disablePortal, hideBackdrop: hideBackdrop, invisibleBackdrop: invisibleBackdrop, onBackdropClick: onBackdropClick, onClose: onClose, open: open, ref: ref }, { children: jsx("div", Object.assign({}, rest, { className: cx(drawerClasses.host, drawerClasses[placement], className) }, { children: children }), void 0) }), void 0));
32
16
  });
33
17
  var Drawer$1 = Drawer;
34
18
 
@@ -17,7 +17,7 @@ export interface AutoCompleteValueControl {
17
17
  options: string[];
18
18
  searchText: string;
19
19
  setSearchText: Dispatch<SetStateAction<string>>;
20
- setValue: Dispatch<SetStateAction<string>>;
21
- value: SelectValue[];
20
+ setValue: (text: string) => void;
21
+ value: SelectValue | null;
22
22
  }
23
23
  export declare function useAutoCompleteValueControl(props: UseAutoCompleteValueControl): AutoCompleteValueControl;
@@ -11,6 +11,10 @@ function useAutoCompleteValueControl(props) {
11
11
  });
12
12
  const [searchText, setSearchText] = useState('');
13
13
  const [focused, setFocused] = useState(false);
14
+ const onChangeValue = useCallback((text) => {
15
+ setValue(text);
16
+ onChange === null || onChange === void 0 ? void 0 : onChange(text);
17
+ }, [setValue, onChange]);
14
18
  const onFocus = useCallback((focus) => {
15
19
  setFocused(focus);
16
20
  /** sync current value */
@@ -21,10 +25,10 @@ function useAutoCompleteValueControl(props) {
21
25
  value,
22
26
  onChange,
23
27
  ]);
24
- const getCurrentInputValue = () => (value ? [{
25
- id: value,
26
- name: value,
27
- }] : []);
28
+ const getCurrentInputValue = () => (value ? {
29
+ id: value,
30
+ name: value,
31
+ } : null);
28
32
  const options = disabledOptionsFilter
29
33
  ? optionsProp
30
34
  : optionsProp.filter((option) => ~option.search(searchText));
@@ -50,7 +54,7 @@ function useAutoCompleteValueControl(props) {
50
54
  options,
51
55
  searchText,
52
56
  setSearchText,
53
- setValue,
57
+ setValue: onChangeValue,
54
58
  value: getCurrentInputValue(),
55
59
  };
56
60
  }
@@ -1,16 +1,33 @@
1
1
  import { MouseEvent } from 'react';
2
2
  import { SelectValue } from '../Select/typings';
3
- export interface UseSelectValueControl {
4
- defaultValue?: SelectValue[];
5
- mode: string;
6
- onChange?(newOptions: SelectValue[]): any;
3
+ export interface UseSelectBaseValueControl {
7
4
  onClear?(e: MouseEvent<Element>): void;
5
+ onChange?(newOptions: SelectValue[] | SelectValue): any;
8
6
  onClose?(): void;
7
+ }
8
+ export declare type UseSelectMultipleValueControl = UseSelectBaseValueControl & {
9
+ defaultValue?: SelectValue[];
10
+ mode: 'multiple';
11
+ onChange?(newOptions: SelectValue[]): any;
9
12
  value?: SelectValue[];
13
+ };
14
+ export declare type UseSelectSingleValueControl = UseSelectBaseValueControl & {
15
+ defaultValue?: SelectValue;
16
+ mode: 'single';
17
+ onChange?(newOption: SelectValue): any;
18
+ value?: SelectValue | null;
19
+ };
20
+ export declare type UseSelectValueControl = UseSelectMultipleValueControl | UseSelectSingleValueControl;
21
+ export interface SelectBaseValueControl {
22
+ onClear(e: MouseEvent<Element>): void;
10
23
  }
11
- export interface SelectValueControl {
24
+ export declare type SelectMultipleValueControl = SelectBaseValueControl & {
12
25
  onChange: (v: SelectValue | null) => SelectValue[];
13
- onClear(e: MouseEvent<Element>): void;
14
26
  value: SelectValue[];
15
- }
16
- export declare function useSelectValueControl(props: UseSelectValueControl): SelectValueControl;
27
+ };
28
+ export declare type SelectSingleValueControl = SelectBaseValueControl & {
29
+ onChange: (v: SelectValue | null) => SelectValue | null;
30
+ value: SelectValue | null;
31
+ };
32
+ export declare type SelectValueControl = SelectMultipleValueControl | SelectSingleValueControl;
33
+ export declare const useSelectValueControl: (props: UseSelectValueControl) => SelectValueControl;
@@ -1,31 +1,28 @@
1
- import intersectionBy from 'lodash/intersectionBy';
1
+ import isEqual from 'lodash/isEqual';
2
2
  import { useControlValueState } from './useControlValueState.js';
3
3
 
4
- const equalityFn = (a, b) => (a.length === b.length && intersectionBy(a, b, 'id').length === a.length);
5
- function useSelectValueControl(props) {
4
+ const equalityFn = (a, b) => isEqual(a, b);
5
+ function useSelectBaseValueControl(props) {
6
6
  const { defaultValue, mode, onChange, onClear: onClearProp, onClose, value: valueProp, } = props;
7
7
  const [value, setValue] = useControlValueState({
8
- defaultValue: defaultValue || [],
8
+ defaultValue: defaultValue || (mode === 'multiple' ? [] : null),
9
9
  equalityFn,
10
10
  value: valueProp,
11
11
  });
12
12
  return {
13
13
  value,
14
14
  onChange: (chooseOption) => {
15
- if (!chooseOption)
16
- return [];
17
- let newValue = [];
18
- switch (mode) {
19
- case 'single': {
20
- newValue = [chooseOption];
21
- if (typeof onClose === 'function') {
22
- /** single selection should close modal when clicked */
23
- onClose();
24
- }
25
- break;
15
+ var _a;
16
+ if (!chooseOption) {
17
+ if (mode === 'multiple') {
18
+ return [];
26
19
  }
20
+ return null;
21
+ }
22
+ let newValue = mode === 'multiple' ? [] : null;
23
+ switch (mode) {
27
24
  case 'multiple': {
28
- const existedValueIdx = (value !== null && value !== void 0 ? value : []).findIndex((v) => v.id === chooseOption.id);
25
+ const existedValueIdx = ((_a = value) !== null && _a !== void 0 ? _a : []).findIndex((v) => v.id === chooseOption.id);
29
26
  if (~existedValueIdx) {
30
27
  newValue = [
31
28
  ...value.slice(0, existedValueIdx),
@@ -38,22 +35,43 @@ function useSelectValueControl(props) {
38
35
  chooseOption,
39
36
  ];
40
37
  }
38
+ if (typeof onChange === 'function')
39
+ onChange(newValue);
40
+ break;
41
+ }
42
+ default: {
43
+ newValue = chooseOption;
44
+ if (typeof onClose === 'function') {
45
+ /** single selection should close modal when clicked */
46
+ onClose();
47
+ }
48
+ if (typeof onChange === 'function')
49
+ onChange(newValue);
41
50
  break;
42
51
  }
43
52
  }
44
53
  setValue(newValue);
45
- if (typeof onChange === 'function')
46
- onChange(newValue);
47
54
  return newValue;
48
55
  },
49
56
  onClear: (e) => {
50
57
  e.stopPropagation();
51
- setValue([]);
58
+ if (mode === 'multiple') {
59
+ setValue([]);
60
+ }
61
+ else {
62
+ setValue(null);
63
+ }
52
64
  if (typeof onClearProp === 'function') {
53
65
  onClearProp(e);
54
66
  }
55
67
  },
56
68
  };
57
- }
69
+ }
70
+ const useSelectValueControl = (props) => {
71
+ if (props.mode === 'multiple') {
72
+ return useSelectBaseValueControl(props);
73
+ }
74
+ return useSelectBaseValueControl(props);
75
+ };
58
76
 
59
77
  export { useSelectValueControl };
package/Icon/Icon.d.ts CHANGED
@@ -11,6 +11,10 @@ export interface IconProps extends NativeElementPropsWithoutKeyAndRef<'i'> {
11
11
  * The icon provided by `@mezzanine-ui/icons` package.
12
12
  */
13
13
  icon: IconDefinition;
14
+ /**
15
+ * Icon size in px
16
+ */
17
+ size?: number;
14
18
  /**
15
19
  * Whether to spin the icon or not.
16
20
  * @default false
package/Icon/Icon.js CHANGED
@@ -7,9 +7,9 @@ import cx from 'clsx';
7
7
  * The react component for `mezzanine` icon.
8
8
  */
9
9
  const Icon = forwardRef(function Icon(props, ref) {
10
- const { className, color, icon, spin = false, style: styleProp, ...rest } = props;
10
+ const { className, color, icon, size, spin = false, style: styleProp, ...rest } = props;
11
11
  const { definition } = icon;
12
- const cssVars = toIconCssVars({ color });
12
+ const cssVars = toIconCssVars({ color, size });
13
13
  const style = {
14
14
  ...cssVars,
15
15
  ...styleProp,
@@ -17,6 +17,7 @@ const Icon = forwardRef(function Icon(props, ref) {
17
17
  return (jsx("i", Object.assign({}, rest, { ref: ref, "aria-hidden": true, className: cx(iconClasses.host, {
18
18
  [iconClasses.color]: color,
19
19
  [iconClasses.spin]: spin,
20
+ [iconClasses.size]: size,
20
21
  }, className), "data-icon-name": icon.name, style: style }, { children: jsx("svg", Object.assign({}, definition.svg, { focusable: false }, { children: jsx("path", Object.assign({}, definition.path), void 0) }), void 0) }), void 0));
21
22
  });
22
23
  var Icon$1 = Icon;
package/Modal/Modal.d.ts CHANGED
@@ -1,13 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { ModalSeverity, ModalSize } from '@mezzanine-ui/core/modal';
3
+ import { SlideFadeOverlayProps } from '../_internal/SlideFadeOverlay';
3
4
  import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
4
- import { OverlayProps } from '../Overlay';
5
- export interface ModalProps extends NativeElementPropsWithoutKeyAndRef<'div'>, Pick<OverlayProps, 'container' | 'disableCloseOnBackdropClick' | 'disablePortal' | 'hideBackdrop' | 'onBackdropClick' | 'onClose' | 'open'> {
6
- /**
7
- * Controls whether to disable closing modal while escape key down.
8
- * @default false
9
- */
10
- disableCloseOnEscapeKeyDown?: boolean;
5
+ export interface ModalProps extends Omit<SlideFadeOverlayProps, 'children'>, Pick<NativeElementPropsWithoutKeyAndRef<'div'>, 'children'> {
11
6
  /**
12
7
  * Whether to force full screen on any breakpoint.
13
8
  * @default false
package/Modal/Modal.js CHANGED
@@ -1,13 +1,9 @@
1
1
  import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import { modalClasses } from '@mezzanine-ui/core/modal';
3
3
  import { TimesIcon } from '@mezzanine-ui/icons';
4
- import { forwardRef, useState, useLayoutEffect, useEffect } from 'react';
5
- import { useDocumentEscapeKeyDown } from '../hooks/useDocumentEscapeKeyDown.js';
6
- import { lockBodyScroll, allowBodyScroll } from '../utils/scroll-lock.js';
7
- import { useIsTopModal } from './useIsTopModal.js';
4
+ import { forwardRef } from 'react';
8
5
  import { ModalControlContext } from './ModalControl.js';
9
- import Overlay from '../Overlay/Overlay.js';
10
- import SlideFade from '../Transition/SlideFade.js';
6
+ import useModalContainer from './useModalContainer.js';
11
7
  import Icon from '../Icon/Icon.js';
12
8
  import cx from 'clsx';
13
9
 
@@ -15,61 +11,16 @@ import cx from 'clsx';
15
11
  * The react component for `mezzanine` modal.
16
12
  */
17
13
  const Modal = forwardRef(function Modal(props, ref) {
18
- const { children, className, container, disableCloseOnBackdropClick = false, disableCloseOnEscapeKeyDown = false, disablePortal, fullScreen = false, hideBackdrop, hideCloseIcon = false, loading = false, onBackdropClick, onClose, open, severity = 'info', size = 'medium', ...rest } = props;
14
+ const { children, className, container, disableCloseOnBackdropClick = false, disableCloseOnEscapeKeyDown = false, disablePortal = false, fullScreen = false, hideBackdrop = false, hideCloseIcon = false, invisibleBackdrop = false, loading = false, onBackdropClick, onClose, open, severity = 'info', size = 'medium', ...rest } = props;
19
15
  const modalControl = {
20
16
  loading,
21
17
  severity,
22
18
  };
23
- const [exited, setExited] = useState(true);
24
- /**
25
- * Escape keydown close: escape will only close the top modal
26
- */
27
- const isTopModal = useIsTopModal(open);
28
- useDocumentEscapeKeyDown(() => {
29
- if (!open || disableCloseOnEscapeKeyDown || !onClose) {
30
- return;
31
- }
32
- return (event) => {
33
- if (isTopModal()) {
34
- event.stopPropagation();
35
- onClose();
36
- }
37
- };
38
- }, [
39
- disableCloseOnEscapeKeyDown,
40
- isTopModal,
41
- open,
42
- onClose,
43
- ]);
44
- /** lock body scroll */
45
- useLayoutEffect(() => {
46
- if (open) {
47
- lockBodyScroll();
48
- }
49
- }, [open]);
50
- /** unlock body scroll */
51
- useEffect(() => {
52
- function checkAndAllowScroll() {
53
- // wait until dom element unmount, and check if other modal existed
54
- const allModals = document.querySelectorAll('.mzn-modal');
55
- if (!allModals.length) {
56
- allowBodyScroll();
57
- }
58
- }
59
- if (!open && exited) {
60
- checkAndAllowScroll();
61
- }
62
- return (() => {
63
- requestAnimationFrame(checkAndAllowScroll);
64
- });
65
- }, [open, exited]);
66
- if (!open && exited) {
67
- return null;
68
- }
69
- return (jsx(Overlay, Object.assign({ className: modalClasses.overlay, container: container, disableCloseOnBackdropClick: disableCloseOnBackdropClick, disablePortal: disablePortal, hideBackdrop: hideBackdrop, onBackdropClick: onBackdropClick, onClose: onClose, open: open, role: "presentation" }, { children: jsx(ModalControlContext.Provider, Object.assign({ value: modalControl }, { children: jsx(SlideFade, Object.assign({ ref: ref, in: open, direction: "down", onEntered: () => setExited(false), onExited: () => setExited(true) }, { children: jsxs("div", Object.assign({}, rest, { className: cx(modalClasses.host, modalClasses.severity(severity), modalClasses.size(size), {
70
- [modalClasses.fullScreen]: fullScreen,
71
- [modalClasses.withCloseIcon]: !hideCloseIcon,
72
- }, className), role: "dialog" }, { children: [children, !hideCloseIcon && (jsx(Icon, { className: modalClasses.closeIcon, icon: TimesIcon, onClick: onClose }, void 0))] }), void 0) }), void 0) }), void 0) }), void 0));
19
+ const { Container: ModalContainer } = useModalContainer();
20
+ return (jsx(ModalControlContext.Provider, Object.assign({ value: modalControl }, { children: jsx(ModalContainer, Object.assign({ className: modalClasses.overlay, container: container, direction: "down", disableCloseOnBackdropClick: disableCloseOnBackdropClick, disableCloseOnEscapeKeyDown: disableCloseOnEscapeKeyDown, disablePortal: disablePortal, hideBackdrop: hideBackdrop, invisibleBackdrop: invisibleBackdrop, onBackdropClick: onBackdropClick, onClose: onClose, open: open, ref: ref }, { children: jsxs("div", Object.assign({}, rest, { className: cx(modalClasses.host, modalClasses.severity(severity), modalClasses.size(size), {
21
+ [modalClasses.fullScreen]: fullScreen,
22
+ [modalClasses.withCloseIcon]: !hideCloseIcon,
23
+ }, className), role: "dialog" }, { children: [children, !hideCloseIcon && (jsx(Icon, { className: modalClasses.closeIcon, icon: TimesIcon, onClick: onClose }, void 0))] }), void 0) }), void 0) }), void 0));
73
24
  });
74
25
  var Modal$1 = Modal;
75
26
 
package/Modal/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export { ModalActionsProps, default as ModalActions, } from './ModalActions';
3
3
  export { ModalBodyProps, default as ModalBody, } from './ModalBody';
4
4
  export { ModalFooterProps, default as ModalFooter, } from './ModalFooter';
5
5
  export { ModalHeaderProps, default as ModalHeader, } from './ModalHeader';
6
+ export { default as useModalContainer, } from './useModalContainer';
6
7
  export { ModalProps, default, } from './Modal';
package/Modal/index.js CHANGED
@@ -2,4 +2,5 @@ export { default as ModalActions } from './ModalActions.js';
2
2
  export { default as ModalBody } from './ModalBody.js';
3
3
  export { default as ModalFooter } from './ModalFooter.js';
4
4
  export { default as ModalHeader } from './ModalHeader.js';
5
+ export { default as useModalContainer } from './useModalContainer.js';
5
6
  export { default } from './Modal.js';
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { SlideFadeOverlayProps } from '../_internal/SlideFadeOverlay';
3
+ export default function useModalContainer(): {
4
+ Container: import("react").ForwardRefExoticComponent<SlideFadeOverlayProps & import("react").RefAttributes<HTMLDivElement>>;
5
+ defaultOptions: Pick<SlideFadeOverlayProps, "className" | "direction" | "disableCloseOnBackdropClick" | "disableCloseOnEscapeKeyDown" | "disablePortal" | "hideBackdrop" | "invisibleBackdrop" | "open">;
6
+ };
@@ -0,0 +1,27 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { modalClasses } from '@mezzanine-ui/core/modal';
3
+ import { forwardRef } from 'react';
4
+ import SlideFadeOverlay from '../_internal/SlideFadeOverlay/SlideFadeOverlay.js';
5
+
6
+ const defaultOptions = {
7
+ className: modalClasses.overlay,
8
+ direction: 'down',
9
+ disableCloseOnBackdropClick: false,
10
+ disableCloseOnEscapeKeyDown: false,
11
+ disablePortal: false,
12
+ hideBackdrop: false,
13
+ invisibleBackdrop: false,
14
+ open: false,
15
+ };
16
+ const ModalContainer = forwardRef((props, ref) => {
17
+ const { className = defaultOptions.className, children, container, direction = defaultOptions.direction, disableCloseOnBackdropClick = defaultOptions.disableCloseOnBackdropClick, disableCloseOnEscapeKeyDown = defaultOptions.disableCloseOnEscapeKeyDown, disablePortal = defaultOptions.disablePortal, hideBackdrop = defaultOptions.hideBackdrop, invisibleBackdrop = defaultOptions.invisibleBackdrop, onBackdropClick, onClose, open = defaultOptions.open, } = props;
18
+ return (jsx(SlideFadeOverlay, Object.assign({ className: className, container: container, direction: direction, disableCloseOnBackdropClick: disableCloseOnBackdropClick, disableCloseOnEscapeKeyDown: disableCloseOnEscapeKeyDown, disablePortal: disablePortal, hideBackdrop: hideBackdrop, invisibleBackdrop: invisibleBackdrop, onBackdropClick: onBackdropClick, onClose: onClose, open: open, ref: ref }, { children: children }), void 0));
19
+ });
20
+ function useModalContainer() {
21
+ return {
22
+ Container: ModalContainer,
23
+ defaultOptions,
24
+ };
25
+ }
26
+
27
+ export { useModalContainer as default };
@@ -22,7 +22,7 @@ const MENU_ID = 'mzn-select-autocomplete-menu-id';
22
22
  * should considering using the `Select` component with `onSearch` prop.
23
23
  */
24
24
  const AutoComplete = forwardRef(function Select(props, ref) {
25
- var _a, _b;
25
+ var _a;
26
26
  const { disabled: disabledFromFormControl, fullWidth: fullWidthFromFormControl, required: requiredFromFormControl, severity, } = useContext(FormControlContext) || {};
27
27
  const { addable = false, className, disabled = disabledFromFormControl || false, disabledOptionsFilter = false, defaultValue, error = severity === 'error' || false, fullWidth = fullWidthFromFormControl || false, inputRef, inputProps, itemsInView = 4, menuMaxHeight, menuRole = 'listbox', menuSize = 'medium', onChange: onChangeProp, onClear: onClearProp, onInsert, onSearch, options: optionsProp, popperOptions = {}, placeholder = '', prefix, required = requiredFromFormControl || false, size = 'medium', value: valueProp, } = props;
28
28
  const [open, toggleOpen] = useState(false);
@@ -87,8 +87,10 @@ const AutoComplete = forwardRef(function Select(props, ref) {
87
87
  return (jsx(SelectControlContext.Provider, Object.assign({ value: {
88
88
  onChange,
89
89
  value,
90
- } }, { children: jsxs("div", Object.assign({ ref: nodeRef, className: selectClasses.host }, { children: [jsx(SelectTrigger, { ref: composedRef, active: open, className: className, clearable: true, disabled: disabled, error: error, forceHideSuffixActionIcon: true, fullWidth: fullWidth, inputRef: inputRef, mode: "single", onTagClose: onChange, onClear: onClear, prefix: prefix, readOnly: false, required: required, inputProps: resolvedInputProps, size: size, suffixActionIcon: undefined, value: value }, void 0),
91
- jsxs(InputTriggerPopper, Object.assign({ ref: popperRef, anchor: controlRef, className: selectClasses.popper, open: open, sameWidth: true, options: popperOptions }, { children: [jsxs(Menu, Object.assign({ id: MENU_ID, "aria-activedescendant": (_b = (_a = value[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '', itemsInView: itemsInView, maxHeight: menuMaxHeight, role: menuRole, size: menuSize, style: { border: 0 } }, { children: [jsx(Option, Object.assign({ value: searchText }, { children: searchText }), void 0),
90
+ } }, { children: jsxs("div", Object.assign({ ref: nodeRef, className: cx(selectClasses.host, {
91
+ [selectClasses.hostFullWidth]: fullWidth,
92
+ }) }, { children: [jsx(SelectTrigger, { ref: composedRef, active: open, className: className, clearable: true, disabled: disabled, error: error, forceHideSuffixActionIcon: true, fullWidth: fullWidth, inputRef: inputRef, mode: "single", onTagClose: onChange, onClear: onClear, prefix: prefix, readOnly: false, required: required, inputProps: resolvedInputProps, size: size, suffixActionIcon: undefined, value: value }, void 0),
93
+ jsxs(InputTriggerPopper, Object.assign({ ref: popperRef, anchor: controlRef, className: selectClasses.popper, open: open, sameWidth: true, options: popperOptions }, { children: [jsxs(Menu, Object.assign({ id: MENU_ID, "aria-activedescendant": (_a = value === null || value === void 0 ? void 0 : value.id) !== null && _a !== void 0 ? _a : '', itemsInView: itemsInView, maxHeight: menuMaxHeight, role: menuRole, size: menuSize, style: { border: 0 } }, { children: [jsx(Option, Object.assign({ value: searchText }, { children: searchText }), void 0),
92
94
  options.length ? options.map((option) => (jsx(Option, Object.assign({ value: option }, { children: option }), option))) : (jsx(Empty, { children: "\u67E5\u7121\u8CC7\u6599" }, void 0))] }), void 0),
93
95
  addable ? (jsxs("div", Object.assign({ className: selectClasses.autoComplete }, { children: [jsx("input", { type: "text", onChange: (e) => setInsertText(e.target.value), onClick: (e) => e.stopPropagation(), onFocus: (e) => e.stopPropagation(), placeholder: "\u65B0\u589E\u9078\u9805", value: insertText }, void 0),
94
96
  jsx(Icon, { className: cx(selectClasses.autoCompleteIcon, {
package/Select/Option.js CHANGED
@@ -7,7 +7,19 @@ const Option = forwardRef(function Option(props, ref) {
7
7
  const { active: activeProp, children, role = 'option', value, ...rest } = props;
8
8
  const selectControl = useContext(SelectControlContext);
9
9
  const { onChange, value: selectedValue, } = selectControl || {};
10
- const active = Boolean(activeProp || (selectedValue !== null && selectedValue !== void 0 ? selectedValue : []).find((sv) => sv.id === value));
10
+ const getActive = () => {
11
+ if (activeProp) {
12
+ return activeProp;
13
+ }
14
+ if (selectedValue) {
15
+ if (Array.isArray(selectedValue)) {
16
+ return selectedValue.find((sv) => sv.id === value);
17
+ }
18
+ return selectedValue.id === value;
19
+ }
20
+ return false;
21
+ };
22
+ const active = Boolean(getActive());
11
23
  const onSelect = () => {
12
24
  if (typeof onChange === 'function' && value) {
13
25
  onChange({
@@ -6,25 +6,17 @@ import { PopperProps } from '../Popper';
6
6
  import { SelectValue } from './typings';
7
7
  import { PickRenameMulti } from '../utils/general';
8
8
  import { SelectTriggerProps, SelectTriggerInputProps } from './SelectTrigger';
9
- export interface SelectProps extends Omit<SelectTriggerProps, 'active' | 'inputProps' | 'onBlur' | 'onChange' | 'onClick' | 'onFocus' | 'onKeyDown'>, FormElementFocusHandlers, PickRenameMulti<Pick<MenuProps, 'itemsInView' | 'maxHeight' | 'role' | 'size'>, {
9
+ export interface SelectBaseProps extends Omit<SelectTriggerProps, 'active' | 'inputProps' | 'mode' | 'onBlur' | 'onChange' | 'onClick' | 'onFocus' | 'onKeyDown' | 'renderValue' | 'value'>, FormElementFocusHandlers, PickRenameMulti<Pick<MenuProps, 'itemsInView' | 'maxHeight' | 'role' | 'size'>, {
10
10
  maxHeight: 'menuMaxHeight';
11
11
  role: 'menuRole';
12
12
  size: 'menuSize';
13
13
  }>, PickRenameMulti<Pick<PopperProps, 'options'>, {
14
14
  options: 'popperOptions';
15
15
  }>, Pick<MenuProps, 'children'> {
16
- /**
17
- * The default selection
18
- */
19
- defaultValue?: SelectValue[];
20
16
  /**
21
17
  * The other native props for input element.
22
18
  */
23
19
  inputProps?: Omit<SelectTriggerInputProps, 'onBlur' | 'onChange' | 'onFocus' | 'placeholder' | 'role' | 'value' | `aria-${'controls' | 'expanded' | 'owns'}`>;
24
- /**
25
- * The change event handler of input element.
26
- */
27
- onChange?(newOptions: SelectValue[]): any;
28
20
  /**
29
21
  * The search event handler, this prop won't work when mode is `multiple`
30
22
  */
@@ -36,7 +28,7 @@ export interface SelectProps extends Omit<SelectTriggerProps, 'active' | 'inputP
36
28
  /**
37
29
  * To customize rendering select input value
38
30
  */
39
- renderValue?(values: SelectValue[]): string;
31
+ renderValue?(values: SelectValue[] | SelectValue | null): string;
40
32
  /**
41
33
  * Whether the selection is required.
42
34
  * @default false
@@ -47,11 +39,97 @@ export interface SelectProps extends Omit<SelectTriggerProps, 'active' | 'inputP
47
39
  * @default 'medium'
48
40
  */
49
41
  size?: SelectInputSize;
42
+ }
43
+ export declare type SelectMultipleProps = SelectBaseProps & {
44
+ /**
45
+ * The default selection
46
+ */
47
+ defaultValue?: SelectValue[];
48
+ /**
49
+ * Controls the layout of trigger.
50
+ */
51
+ mode: 'multiple';
52
+ /**
53
+ * The change event handler of input element.
54
+ */
55
+ onChange?(newOptions: SelectValue[]): any;
56
+ /**
57
+ * To customize rendering select input value
58
+ */
59
+ renderValue?(values: SelectValue[]): string;
50
60
  /**
51
61
  * The value of selection.
52
62
  * @default undefined
53
63
  */
54
64
  value?: SelectValue[];
55
- }
56
- declare const Select: import("react").ForwardRefExoticComponent<SelectProps & import("react").RefAttributes<HTMLDivElement>>;
65
+ };
66
+ export declare type SelectSingleProps = SelectBaseProps & {
67
+ /**
68
+ * The default selection
69
+ */
70
+ defaultValue?: SelectValue;
71
+ /**
72
+ * Controls the layout of trigger.
73
+ */
74
+ mode?: 'single';
75
+ /**
76
+ * The change event handler of input element.
77
+ */
78
+ onChange?(newOptions: SelectValue): any;
79
+ /**
80
+ * To customize rendering select input value
81
+ */
82
+ renderValue?(values: SelectValue | null): string;
83
+ /**
84
+ * The value of selection.
85
+ * @default undefined
86
+ */
87
+ value?: SelectValue | null;
88
+ };
89
+ export declare type SelectProps = SelectMultipleProps | SelectSingleProps;
90
+ declare const Select: import("react").ForwardRefExoticComponent<(SelectBaseProps & {
91
+ /**
92
+ * The default selection
93
+ */
94
+ defaultValue?: SelectValue[] | undefined;
95
+ /**
96
+ * Controls the layout of trigger.
97
+ */
98
+ mode: 'multiple';
99
+ /**
100
+ * The change event handler of input element.
101
+ */
102
+ onChange?(newOptions: SelectValue[]): any;
103
+ /**
104
+ * To customize rendering select input value
105
+ */
106
+ renderValue?(values: SelectValue[]): string;
107
+ /**
108
+ * The value of selection.
109
+ * @default undefined
110
+ */
111
+ value?: SelectValue[] | undefined;
112
+ } & import("react").RefAttributes<HTMLDivElement>) | (SelectBaseProps & {
113
+ /**
114
+ * The default selection
115
+ */
116
+ defaultValue?: SelectValue | undefined;
117
+ /**
118
+ * Controls the layout of trigger.
119
+ */
120
+ mode?: "single" | undefined;
121
+ /**
122
+ * The change event handler of input element.
123
+ */
124
+ onChange?(newOptions: SelectValue): any;
125
+ /**
126
+ * To customize rendering select input value
127
+ */
128
+ renderValue?(values: SelectValue | null): string;
129
+ /**
130
+ * The value of selection.
131
+ * @default undefined
132
+ */
133
+ value?: SelectValue | null | undefined;
134
+ } & import("react").RefAttributes<HTMLDivElement>)>;
57
135
  export default Select;
package/Select/Select.js CHANGED
@@ -52,9 +52,14 @@ const Select = forwardRef(function Select(props, ref) {
52
52
  const [focused, setFocused] = useState(false);
53
53
  const renderValue = focused && searchable ? () => searchText : renderValueProp;
54
54
  function getPlaceholder() {
55
- var _a;
56
55
  if (focused && searchable) {
57
- return (_a = renderValueProp === null || renderValueProp === void 0 ? void 0 : renderValueProp(value)) !== null && _a !== void 0 ? _a : value.map(({ name }) => name).join(', ');
56
+ if (typeof renderValueProp === 'function') {
57
+ return renderValueProp(value);
58
+ }
59
+ if (value) {
60
+ return value.name;
61
+ }
62
+ return placeholder;
58
63
  }
59
64
  return placeholder;
60
65
  }
@@ -139,7 +144,7 @@ const Select = forwardRef(function Select(props, ref) {
139
144
  onChange,
140
145
  value,
141
146
  } }, { children: jsxs("div", Object.assign({ ref: nodeRef, className: cx(selectClasses.host, fullWidth && selectClasses.hostFullWidth) }, { children: [jsx(SelectTrigger, { ref: composedRef, active: open, className: className, clearable: clearable, disabled: disabled, error: error, fullWidth: fullWidth, inputRef: inputRef, mode: mode, onTagClose: onChange, onClear: onClear, onClick: onClickTextField, onKeyDown: onKeyDownTextField, prefix: prefix, readOnly: !searchable, required: required, inputProps: resolvedInputProps, size: size, suffixActionIcon: suffixActionIcon, value: value, renderValue: renderValue }, void 0),
142
- jsx(InputTriggerPopper, Object.assign({ ref: popperRef, anchor: controlRef, className: selectClasses.popper, open: open, sameWidth: true, options: popperOptions }, { children: jsx(Menu, Object.assign({ id: MENU_ID, "aria-activedescendant": (_b = (_a = value === null || value === void 0 ? void 0 : value[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '', itemsInView: itemsInView, maxHeight: menuMaxHeight, role: menuRole, size: menuSize, style: { border: 0 } }, { children: children }), void 0) }), void 0)] }), void 0) }), void 0));
147
+ jsx(InputTriggerPopper, Object.assign({ ref: popperRef, anchor: controlRef, className: selectClasses.popper, open: open, sameWidth: true, options: popperOptions }, { children: jsx(Menu, Object.assign({ id: MENU_ID, "aria-activedescendant": Array.isArray(value) ? (_b = (_a = value === null || value === void 0 ? void 0 : value[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '' : value === null || value === void 0 ? void 0 : value.id, itemsInView: itemsInView, maxHeight: menuMaxHeight, role: menuRole, size: menuSize, style: { border: 0 } }, { children: children }), void 0) }), void 0)] }), void 0) }), void 0));
143
148
  });
144
149
  var Select$1 = Select;
145
150