@mezzanine-ui/react 0.7.2 → 0.8.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/Form/useAutoCompleteValueControl.d.ts +2 -2
- package/Form/useAutoCompleteValueControl.js +9 -5
- package/Form/useInputWithTagsModeValue.d.ts +37 -0
- package/Form/useInputWithTagsModeValue.js +88 -0
- package/Form/useSelectValueControl.d.ts +25 -8
- package/Form/useSelectValueControl.js +38 -20
- package/Icon/Icon.js +1 -0
- package/Input/Input.d.ts +28 -0
- package/Input/Input.js +26 -3
- package/Select/AutoComplete.js +5 -3
- package/Select/Option.js +13 -1
- package/Select/Select.d.ts +90 -12
- package/Select/Select.js +8 -3
- package/Select/SelectTrigger.d.ts +37 -9
- package/Select/SelectTrigger.js +29 -5
- package/Select/typings.d.ts +2 -2
- package/Table/TableBodyRow.js +4 -3
- package/Table/sorting/useTableSorting.js +2 -1
- package/Upload/UploadInput.js +2 -0
- package/Upload/UploadPicture.d.ts +48 -0
- package/Upload/UploadPicture.js +52 -0
- package/Upload/UploadPictureBlock.d.ts +13 -0
- package/Upload/UploadPictureBlock.js +86 -0
- package/Upload/UploadPictureWall.d.ts +71 -0
- package/Upload/UploadPictureWall.js +156 -0
- package/Upload/UploadPictureWallItem.d.ts +13 -0
- package/Upload/UploadPictureWallItem.js +19 -0
- package/Upload/index.d.ts +3 -0
- package/Upload/index.js +3 -0
- package/index.d.ts +2 -3
- package/index.js +4 -1
- package/package.json +3 -3
|
@@ -17,7 +17,7 @@ export interface AutoCompleteValueControl {
|
|
|
17
17
|
options: string[];
|
|
18
18
|
searchText: string;
|
|
19
19
|
setSearchText: Dispatch<SetStateAction<string>>;
|
|
20
|
-
setValue:
|
|
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
|
-
|
|
26
|
-
|
|
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
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ChangeEvent, KeyboardEvent, RefObject } from 'react';
|
|
2
|
+
import { UseInputControlValueProps } from './useInputControlValue';
|
|
3
|
+
export declare type TagsType = string[] | number[];
|
|
4
|
+
export interface UseInputWithTagsModeValueProps<E extends HTMLInputElement | HTMLTextAreaElement> extends UseInputControlValueProps<E> {
|
|
5
|
+
/**
|
|
6
|
+
* The value of initial tags
|
|
7
|
+
*/
|
|
8
|
+
initialTagsValue?: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Maximum permitted length of the tags
|
|
11
|
+
* @default 3
|
|
12
|
+
*/
|
|
13
|
+
maxTagsLength?: number;
|
|
14
|
+
/**
|
|
15
|
+
* The change event handler of tags
|
|
16
|
+
*/
|
|
17
|
+
onTagsChange?: (tags: TagsType) => void;
|
|
18
|
+
/**
|
|
19
|
+
* The ref object of input element
|
|
20
|
+
*/
|
|
21
|
+
ref: RefObject<E>;
|
|
22
|
+
/**
|
|
23
|
+
* Will skip `onKeyDown` calling if `true`
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
skip?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Maximum length of value on each tag
|
|
29
|
+
* @default 8
|
|
30
|
+
*/
|
|
31
|
+
tagValueMaxLength?: number;
|
|
32
|
+
}
|
|
33
|
+
export declare function useInputWithTagsModeValue<E extends HTMLInputElement | HTMLTextAreaElement>(props: Omit<UseInputWithTagsModeValueProps<E>, 'onChange'>): readonly [{
|
|
34
|
+
readonly tags: string[];
|
|
35
|
+
readonly typingValue: string;
|
|
36
|
+
readonly tagsReachedMax: boolean;
|
|
37
|
+
}, (event: ChangeEvent<E> | null) => void, () => void, (tag: string) => void, (e: KeyboardEvent) => void];
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useRef, useState, useCallback } from 'react';
|
|
2
|
+
import { useInputControlValue } from './useInputControlValue.js';
|
|
3
|
+
|
|
4
|
+
function useInputWithTagsModeValue(props) {
|
|
5
|
+
var _a;
|
|
6
|
+
const { defaultValue, initialTagsValue = [], maxTagsLength, onTagsChange: onChangeProp, ref, skip = false, tagValueMaxLength = 8, } = props;
|
|
7
|
+
const canActive = !skip;
|
|
8
|
+
const activeMaxTagsLength = maxTagsLength || Math.max(3, initialTagsValue.length);
|
|
9
|
+
const tagsSetRef = useRef(new Set(initialTagsValue.map((initialTag) => initialTag.trim())));
|
|
10
|
+
const inputTypeIsNumber = useRef(((_a = ref.current) === null || _a === void 0 ? void 0 : _a.type) === 'number');
|
|
11
|
+
const tagValueTransform = (tag) => (tag.slice(0, tagValueMaxLength).trim());
|
|
12
|
+
const transformNumberTags = (tags) => (tags.map((tag) => Number(tag)));
|
|
13
|
+
const generateUniqueTags = () => (Array
|
|
14
|
+
.from(tagsSetRef.current.values())
|
|
15
|
+
.map((initialTag) => tagValueTransform(initialTag)));
|
|
16
|
+
const [value, setValue] = useInputControlValue({
|
|
17
|
+
defaultValue: canActive ? defaultValue : undefined,
|
|
18
|
+
});
|
|
19
|
+
const [tags, setTags] = useState(generateUniqueTags()
|
|
20
|
+
.slice(0, activeMaxTagsLength));
|
|
21
|
+
const tagsWillOverflow = useCallback(() => (tagsSetRef.current.size === activeMaxTagsLength), []);
|
|
22
|
+
const clearTypingFieldValue = () => {
|
|
23
|
+
if (!canActive)
|
|
24
|
+
return;
|
|
25
|
+
const target = ref.current;
|
|
26
|
+
if (target) {
|
|
27
|
+
const changeEvent = Object.create({});
|
|
28
|
+
changeEvent.target = target;
|
|
29
|
+
changeEvent.currentTarget = target;
|
|
30
|
+
target.value = '';
|
|
31
|
+
setValue(changeEvent);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const onClear = () => {
|
|
35
|
+
if (!canActive)
|
|
36
|
+
return;
|
|
37
|
+
clearTypingFieldValue();
|
|
38
|
+
tagsSetRef.current.clear();
|
|
39
|
+
setTags([]);
|
|
40
|
+
onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp([]);
|
|
41
|
+
};
|
|
42
|
+
const onChange = (event) => {
|
|
43
|
+
if (canActive && event) {
|
|
44
|
+
setValue(event);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const onRemove = (tag) => {
|
|
48
|
+
tagsSetRef.current.delete(tag);
|
|
49
|
+
const numberTag = inputTypeIsNumber.current;
|
|
50
|
+
const newTags = generateUniqueTags();
|
|
51
|
+
setTags(newTags);
|
|
52
|
+
onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(numberTag ? transformNumberTags(newTags) : newTags);
|
|
53
|
+
};
|
|
54
|
+
const onKeyDown = useCallback((e) => {
|
|
55
|
+
var _a;
|
|
56
|
+
if (!canActive)
|
|
57
|
+
return;
|
|
58
|
+
const element = ref.current;
|
|
59
|
+
if (element && (element === null || element === void 0 ? void 0 : element.value) &&
|
|
60
|
+
(e.key === 'Enter' || e.code === 'Enter') &&
|
|
61
|
+
!e.nativeEvent.isComposing &&
|
|
62
|
+
!tagsWillOverflow()) {
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
inputTypeIsNumber.current = ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.type) === 'number';
|
|
65
|
+
const tagsSet = tagsSetRef.current;
|
|
66
|
+
const isNumber = inputTypeIsNumber.current;
|
|
67
|
+
const newTagValue = tagValueTransform(element.value);
|
|
68
|
+
tagsSet.add(newTagValue);
|
|
69
|
+
const newTags = generateUniqueTags();
|
|
70
|
+
setTags(newTags);
|
|
71
|
+
onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(isNumber ? transformNumberTags(newTags) : newTags);
|
|
72
|
+
clearTypingFieldValue();
|
|
73
|
+
}
|
|
74
|
+
}, [tagsWillOverflow]);
|
|
75
|
+
return [
|
|
76
|
+
{
|
|
77
|
+
tags,
|
|
78
|
+
typingValue: value,
|
|
79
|
+
tagsReachedMax: tagsWillOverflow(),
|
|
80
|
+
},
|
|
81
|
+
onChange,
|
|
82
|
+
onClear,
|
|
83
|
+
onRemove,
|
|
84
|
+
onKeyDown,
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { useInputWithTagsModeValue };
|
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
import { MouseEvent } from 'react';
|
|
2
2
|
import { SelectValue } from '../Select/typings';
|
|
3
|
-
export interface
|
|
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
|
|
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
|
|
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
|
|
1
|
+
import isEqual from 'lodash/isEqual';
|
|
2
2
|
import { useControlValueState } from './useControlValueState.js';
|
|
3
3
|
|
|
4
|
-
const equalityFn = (a, b) => (a
|
|
5
|
-
function
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 &&
|
|
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
|
-
|
|
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.js
CHANGED
|
@@ -11,6 +11,7 @@ const Icon = forwardRef(function Icon(props, ref) {
|
|
|
11
11
|
const { definition } = icon;
|
|
12
12
|
const cssVars = toIconCssVars({ color, size });
|
|
13
13
|
const style = {
|
|
14
|
+
'--mzn-icon-cursor': props.onClick || props.onMouseOver ? 'pointer' : 'inherit',
|
|
14
15
|
...cssVars,
|
|
15
16
|
...styleProp,
|
|
16
17
|
};
|
package/Input/Input.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Ref, ChangeEventHandler } from 'react';
|
|
2
2
|
import { InputSize } from '@mezzanine-ui/core/input';
|
|
3
3
|
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
4
|
+
import type { TagsType } from '../Form/useInputWithTagsModeValue';
|
|
4
5
|
import { TextFieldProps } from '../TextField';
|
|
5
6
|
export interface InputProps extends Omit<TextFieldProps, 'active' | 'children' | 'onClear' | 'onKeyDown'> {
|
|
6
7
|
/**
|
|
@@ -15,6 +16,11 @@ export interface InputProps extends Omit<TextFieldProps, 'active' | 'children' |
|
|
|
15
16
|
* The other native props for input element.
|
|
16
17
|
*/
|
|
17
18
|
inputProps?: Omit<NativeElementPropsWithoutKeyAndRef<'input'>, 'defaultValue' | 'disabled' | 'onChange' | 'placeholder' | 'readOnly' | 'required' | 'value' | `aria-${'disabled' | 'multiline' | 'readonly' | 'required'}`>;
|
|
19
|
+
/**
|
|
20
|
+
* The input value mode
|
|
21
|
+
* @default 'default'
|
|
22
|
+
*/
|
|
23
|
+
mode?: 'default' | 'tags';
|
|
18
24
|
/**
|
|
19
25
|
* The change event handler of input element.
|
|
20
26
|
*/
|
|
@@ -38,6 +44,28 @@ export interface InputProps extends Omit<TextFieldProps, 'active' | 'children' |
|
|
|
38
44
|
* @default 'medium'
|
|
39
45
|
*/
|
|
40
46
|
size?: InputSize;
|
|
47
|
+
/**
|
|
48
|
+
* The props for input element with tags mode.
|
|
49
|
+
*/
|
|
50
|
+
tagsProps?: {
|
|
51
|
+
/**
|
|
52
|
+
* The initial value of tags
|
|
53
|
+
*/
|
|
54
|
+
initialTagsValue?: string[];
|
|
55
|
+
/**
|
|
56
|
+
* The position of input field on tags mode
|
|
57
|
+
* @default 'bottom''
|
|
58
|
+
*/
|
|
59
|
+
inputPosition?: 'top' | 'bottom';
|
|
60
|
+
/**
|
|
61
|
+
* Maximum permitted length of the tags
|
|
62
|
+
*/
|
|
63
|
+
maxTagsLength?: number;
|
|
64
|
+
/**
|
|
65
|
+
* The change event handler of input tags value.
|
|
66
|
+
*/
|
|
67
|
+
onTagsChange?: (tags: TagsType) => void;
|
|
68
|
+
};
|
|
41
69
|
/**
|
|
42
70
|
* The value of input.
|
|
43
71
|
*/
|
package/Input/Input.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { forwardRef, useContext, useRef } from 'react';
|
|
3
3
|
import { inputClasses } from '@mezzanine-ui/core/input';
|
|
4
|
+
import { selectClasses } from '@mezzanine-ui/core/select';
|
|
4
5
|
import { useComposeRefs } from '../hooks/useComposeRefs.js';
|
|
5
6
|
import { useInputWithClearControlValue } from '../Form/useInputWithClearControlValue.js';
|
|
7
|
+
import { useInputWithTagsModeValue } from '../Form/useInputWithTagsModeValue.js';
|
|
6
8
|
import TextField from '../TextField/TextField.js';
|
|
9
|
+
import Tag from '../Tag/Tag.js';
|
|
7
10
|
import { FormControlContext } from '../Form/FormControlContext.js';
|
|
8
11
|
import cx from 'clsx';
|
|
9
12
|
|
|
@@ -12,7 +15,9 @@ import cx from 'clsx';
|
|
|
12
15
|
*/
|
|
13
16
|
const Input = forwardRef(function Input(props, ref) {
|
|
14
17
|
const { disabled: disabledFromFormControl, fullWidth: fullWidthFromFormControl, required: requiredFromFormControl, severity, } = useContext(FormControlContext) || {};
|
|
15
|
-
const { className, clearable = false, defaultValue, disabled = disabledFromFormControl || false, error = severity === 'error' || false, fullWidth = fullWidthFromFormControl || false, inputRef: inputRefProp,
|
|
18
|
+
const { className, clearable = false, defaultValue, disabled = disabledFromFormControl || false, error = severity === 'error' || false, fullWidth = fullWidthFromFormControl || false, inputProps, inputRef: inputRefProp, mode = 'default', onChange: onChangeProp, placeholder, prefix, readOnly = false, required = requiredFromFormControl || false, size = 'medium', suffix, tagsProps, value: valueProp, } = props;
|
|
19
|
+
const { initialTagsValue, inputPosition = 'bottom', maxTagsLength, onTagsChange, } = tagsProps || {};
|
|
20
|
+
const tagsMode = mode === 'tags';
|
|
16
21
|
const inputRef = useRef(null);
|
|
17
22
|
const [value, onChange, onClear,] = useInputWithClearControlValue({
|
|
18
23
|
defaultValue,
|
|
@@ -20,9 +25,27 @@ const Input = forwardRef(function Input(props, ref) {
|
|
|
20
25
|
ref: inputRef,
|
|
21
26
|
value: valueProp,
|
|
22
27
|
});
|
|
28
|
+
const [{ tags, tagsReachedMax, }, tagsModeOnChange, tagsModeOnClear, tagsModeOnRemove, onKeyDown,] = useInputWithTagsModeValue({
|
|
29
|
+
defaultValue,
|
|
30
|
+
initialTagsValue,
|
|
31
|
+
maxTagsLength,
|
|
32
|
+
onTagsChange,
|
|
33
|
+
ref: inputRef,
|
|
34
|
+
skip: !tagsMode,
|
|
35
|
+
tagValueMaxLength: inputProps === null || inputProps === void 0 ? void 0 : inputProps.maxLength,
|
|
36
|
+
value: valueProp,
|
|
37
|
+
});
|
|
23
38
|
const composedInputRef = useComposeRefs([inputRefProp, inputRef]);
|
|
39
|
+
const maxLength = () => (tagsMode
|
|
40
|
+
? Math.min((inputProps === null || inputProps === void 0 ? void 0 : inputProps.maxLength) || 8, 8)
|
|
41
|
+
: inputProps === null || inputProps === void 0 ? void 0 : inputProps.maxLength);
|
|
24
42
|
const active = !!value;
|
|
25
|
-
|
|
43
|
+
const mountInput = !tagsMode || !tagsReachedMax;
|
|
44
|
+
return (jsxs(TextField, Object.assign({ ref: ref, active: active, className: cx(inputClasses.host, tagsMode && inputClasses.tagsMode, inputPosition === 'top' && inputClasses.tagsModeInputOnTop, className), clearable: clearable, disabled: disabled, error: error, fullWidth: fullWidth, onClear: tagsMode ? tagsModeOnClear : onClear, prefix: mountInput ? prefix : undefined, suffix: mountInput ? suffix : undefined, size: size }, { children: [tagsMode && (jsx("div", Object.assign({ className: selectClasses.triggerTags }, { children: tags.map((tag) => (jsx(Tag, Object.assign({ closable: true, disabled: disabled, size: size, onClose: (e) => {
|
|
45
|
+
e.stopPropagation();
|
|
46
|
+
tagsModeOnRemove(tag);
|
|
47
|
+
} }, { children: tag }), tag))) }), void 0)),
|
|
48
|
+
mountInput && (jsx("input", Object.assign({}, inputProps, { "aria-disabled": disabled, "aria-multiline": false, "aria-readonly": readOnly, "aria-required": required, disabled: disabled, maxLength: maxLength(), onChange: tagsMode ? tagsModeOnChange : onChange, onKeyDown: tagsMode ? onKeyDown : inputProps === null || inputProps === void 0 ? void 0 : inputProps.onKeyDown, placeholder: placeholder, readOnly: readOnly, ref: composedInputRef, required: required, value: tagsMode ? undefined : value }), void 0))] }), void 0));
|
|
26
49
|
});
|
|
27
50
|
var Input$1 = Input;
|
|
28
51
|
|
package/Select/AutoComplete.js
CHANGED
|
@@ -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
|
|
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
|
|
91
|
-
|
|
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
|
|
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({
|
package/Select/Select.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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
|
|