@mezzanine-ui/react 0.7.4 → 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.
@@ -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 };
@@ -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
 
@@ -1,10 +1,9 @@
1
1
  import { Ref } from 'react';
2
- import { SelectMode } from '@mezzanine-ui/core/select';
3
2
  import { TextFieldProps } from '../TextField';
4
3
  import { SelectValue } from './typings';
5
4
  import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
6
5
  export declare type SelectTriggerInputProps = Omit<NativeElementPropsWithoutKeyAndRef<'input'>, 'autoComplete' | 'children' | 'defaultValue' | 'disabled' | 'readOnly' | 'required' | 'type' | 'value' | `aria-${'autocomplete' | 'disabled' | 'haspopup' | 'multiline' | 'readonly' | 'required'}`>;
7
- export interface SelectTriggerProps extends Omit<TextFieldProps, 'active' | 'children' | 'defaultChecked' | 'suffix'> {
6
+ export interface SelectTriggerBaseProps extends Omit<TextFieldProps, 'active' | 'children' | 'defaultChecked' | 'suffix'> {
8
7
  /**
9
8
  * Controls the chevron icon layout.
10
9
  */
@@ -13,6 +12,10 @@ export interface SelectTriggerProps extends Omit<TextFieldProps, 'active' | 'chi
13
12
  * force hide suffixAction icons
14
13
  */
15
14
  forceHideSuffixActionIcon?: boolean;
15
+ /**
16
+ * The ref for SelectTrigger root.
17
+ */
18
+ innerRef?: Ref<HTMLDivElement>;
16
19
  /**
17
20
  * Other props you may provide to input element.
18
21
  */
@@ -21,10 +24,6 @@ export interface SelectTriggerProps extends Omit<TextFieldProps, 'active' | 'chi
21
24
  * The ref object for input element.
22
25
  */
23
26
  inputRef?: Ref<HTMLInputElement>;
24
- /**
25
- * Controls the layout of trigger.
26
- */
27
- mode?: SelectMode;
28
27
  /**
29
28
  * The click handler for the cross icon on tags
30
29
  */
@@ -38,17 +37,46 @@ export interface SelectTriggerProps extends Omit<TextFieldProps, 'active' | 'chi
38
37
  * Provide if you have a customize value rendering logic.
39
38
  * By default will have a comma between values.
40
39
  */
41
- renderValue?: (value: SelectValue[]) => string;
40
+ renderValue?: (value: SelectValue[] | SelectValue | null) => string;
42
41
  /**
43
42
  * Whether the input is required.
44
43
  * @default false
45
44
  */
46
45
  required?: boolean;
46
+ }
47
+ export declare type SelectTriggerMultipleProps = SelectTriggerBaseProps & {
48
+ /**
49
+ * Controls the layout of trigger.
50
+ */
51
+ mode: 'multiple';
47
52
  /**
48
53
  * The value of selection.
49
54
  * @default undefined
50
55
  */
51
56
  value?: SelectValue[];
52
- }
53
- declare const SelectTrigger: import("react").ForwardRefExoticComponent<SelectTriggerProps & import("react").RefAttributes<HTMLDivElement>>;
57
+ /**
58
+ * Provide if you have a customize value rendering logic.
59
+ * By default will have a comma between values.
60
+ */
61
+ renderValue?: (value: SelectValue[]) => string;
62
+ };
63
+ export declare type SelectTriggerSingleProps = SelectTriggerBaseProps & {
64
+ /**
65
+ * Controls the layout of trigger.
66
+ */
67
+ mode?: 'single';
68
+ /**
69
+ * The value of selection.
70
+ * @default undefined
71
+ */
72
+ value?: SelectValue | null;
73
+ /**
74
+ * Provide if you have a customize value rendering logic.
75
+ * By default will have a comma between values.
76
+ */
77
+ renderValue?: (value: SelectValue | null) => string;
78
+ };
79
+ export declare type SelectTriggerComponentProps = SelectTriggerMultipleProps | SelectTriggerSingleProps;
80
+ export declare type SelectTriggerProps = Omit<SelectTriggerComponentProps, 'innerRef'>;
81
+ declare const SelectTrigger: import("react").ForwardRefExoticComponent<Pick<SelectTriggerComponentProps, "disabled" | "placeholder" | "readOnly" | "required" | "size" | "value" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "active" | "clearable" | "error" | "fullWidth" | "onClear" | "suffixActionIcon" | "forceHideSuffixActionIcon" | "inputProps" | "inputRef" | "onTagClose" | "renderValue" | "mode"> & import("react").RefAttributes<HTMLDivElement>>;
54
82
  export default SelectTrigger;
@@ -7,21 +7,45 @@ import TextField from '../TextField/TextField.js';
7
7
  import Tag from '../Tag/Tag.js';
8
8
  import cx from 'clsx';
9
9
 
10
- const SelectTrigger = forwardRef(function SelectTrigger(props, ref) {
11
- const { active, className, disabled, forceHideSuffixActionIcon, inputProps, inputRef, mode, onTagClose, readOnly, renderValue: renderValueProp, required, size, suffixActionIcon: suffixActionIconProp, value, ...restTextFieldProps } = props;
10
+ function SelectTriggerComponent(props) {
11
+ var _a;
12
+ const { active, className, disabled, forceHideSuffixActionIcon, inputProps, innerRef, inputRef, mode, onTagClose, readOnly, renderValue: renderValueProp, required, size, suffixActionIcon: suffixActionIconProp, value, ...restTextFieldProps } = props;
12
13
  /** Render value to string for input */
13
14
  const renderValue = () => {
14
- var _a, _b;
15
- return ((_b = (_a = renderValueProp === null || renderValueProp === void 0 ? void 0 : renderValueProp(value || [])) !== null && _a !== void 0 ? _a : value === null || value === void 0 ? void 0 : value.map((v) => v.name).join(', ')) !== null && _b !== void 0 ? _b : '');
15
+ if (typeof renderValueProp === 'function') {
16
+ return renderValueProp(value || (mode === 'multiple' ? [] : null));
17
+ }
18
+ if (value) {
19
+ if (Array.isArray(value)) {
20
+ return value.map((v) => v.name).join(', ');
21
+ }
22
+ return value.name;
23
+ }
24
+ return '';
16
25
  };
17
26
  /** Compute suffix action icon */
18
27
  const suffixActionIcon = suffixActionIconProp || (jsx(Icon, { icon: ChevronDownIcon, className: cx(selectClasses.triggerSuffixActionIcon, {
19
28
  [selectClasses.triggerSuffixActionIconActive]: active,
20
29
  }) }, void 0));
21
- return (jsx(TextField, Object.assign({ ref: ref }, restTextFieldProps, { active: !!(value === null || value === void 0 ? void 0 : value.length), className: cx(selectClasses.trigger, className), disabled: disabled, size: size, suffixActionIcon: forceHideSuffixActionIcon ? undefined : suffixActionIcon }, { children: mode === 'multiple' && (value === null || value === void 0 ? void 0 : value.length) ? (jsx("div", Object.assign({ className: selectClasses.triggerTags }, { children: value.map((selection) => (jsx(Tag, Object.assign({ closable: true, disabled: disabled, onClose: (e) => {
30
+ const getTextFieldActive = () => {
31
+ if (value) {
32
+ if (Array.isArray(value)) {
33
+ return !!(value === null || value === void 0 ? void 0 : value.length);
34
+ }
35
+ return !!value;
36
+ }
37
+ return false;
38
+ };
39
+ return (jsx(TextField, Object.assign({ ref: innerRef }, restTextFieldProps, { active: getTextFieldActive(), className: cx(selectClasses.trigger, className), disabled: disabled, size: size, suffixActionIcon: forceHideSuffixActionIcon ? undefined : suffixActionIcon }, { children: mode === 'multiple' && ((_a = value) === null || _a === void 0 ? void 0 : _a.length) ? (jsx("div", Object.assign({ className: selectClasses.triggerTags }, { children: value.map((selection) => (jsx(Tag, Object.assign({ closable: true, disabled: disabled, onClose: (e) => {
22
40
  e.stopPropagation();
23
41
  onTagClose === null || onTagClose === void 0 ? void 0 : onTagClose(selection);
24
42
  }, size: size }, { children: selection.name }), selection.id))) }), void 0)) : (jsx("input", Object.assign({}, inputProps, { ref: inputRef, "aria-autocomplete": "list", "aria-disabled": disabled, "aria-haspopup": "listbox", "aria-readonly": readOnly, "aria-required": required, autoComplete: "false", disabled: disabled, readOnly: readOnly, required: required, type: "search", value: renderValue() }), void 0)) }), void 0));
43
+ }
44
+ const SelectTrigger = forwardRef((props, ref) => {
45
+ if (props.mode === 'multiple') {
46
+ return (jsx(SelectTriggerComponent, Object.assign({}, props, { innerRef: ref }), void 0));
47
+ }
48
+ return (jsx(SelectTriggerComponent, Object.assign({}, props, { innerRef: ref }), void 0));
25
49
  });
26
50
  var SelectTrigger$1 = SelectTrigger;
27
51
 
@@ -6,6 +6,6 @@ export interface TreeSelectOption extends SelectValue {
6
6
  siblings?: TreeSelectOption[];
7
7
  }
8
8
  export interface SelectControl {
9
- value: SelectValue[];
10
- onChange: (v: SelectValue | null) => SelectValue[];
9
+ value: SelectValue[] | SelectValue | null;
10
+ onChange: (v: SelectValue | null) => SelectValue[] | SelectValue | null;
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mezzanine-ui/react",
3
- "version": "0.7.4",
3
+ "version": "0.8.0",
4
4
  "description": "React components for mezzanine-ui",
5
5
  "author": "Mezzanine",
6
6
  "repository": {