@mezzanine-ui/react 0.7.3 → 0.9.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.
- package/DatePicker/DatePicker.js +1 -1
- package/DateRangePicker/DateRangePicker.js +4 -2
- package/DateTimePicker/DateTimePicker.js +1 -1
- 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 +10 -30
- package/Table/TableExpandedTable.d.ts +11 -0
- package/Table/TableExpandedTable.js +27 -0
- package/Table/TableHeader.js +3 -25
- package/Table/expandable/TableExpandable.d.ts +4 -0
- package/Table/expandable/TableExpandable.js +11 -2
- package/Table/sorting/useTableSorting.js +11 -8
- package/Tabs/useTabsOverflow.js +28 -25
- package/TimePanel/TimePanelColumn.js +6 -5
- package/TimePicker/TimePicker.js +1 -1
- package/index.d.ts +1 -2
- package/index.js +2 -1
- package/package.json +2 -2
package/DatePicker/DatePicker.js
CHANGED
|
@@ -18,7 +18,7 @@ import { FormControlContext } from '../Form/FormControlContext.js';
|
|
|
18
18
|
const DatePicker = forwardRef(function DatePicker(props, ref) {
|
|
19
19
|
const { disabled: disabledFromFormControl, fullWidth: fullWidthFromFormControl, required: requiredFromFormControl, severity, } = useContext(FormControlContext) || {};
|
|
20
20
|
const { defaultDateFormat, getNow, } = useCalendarContext();
|
|
21
|
-
const { calendarProps, className, clearable, defaultValue, disableOnNext, disableOnPrev, disabled = disabledFromFormControl || false, displayMonthLocale, error = severity === 'error' || false, fadeProps, format = defaultDateFormat, fullWidth = fullWidthFromFormControl || false, inputProps, isDateDisabled, isMonthDisabled, isYearDisabled, mode = 'day', onCalendarToggle: onCalendarToggleProp, onChange: onChangeProp, placeholder, popperProps, prefix, readOnly, referenceDate: referenceDateProp, required = requiredFromFormControl || false, size, value: valueProp, ...restTriggerProps } = props;
|
|
21
|
+
const { calendarProps, className, clearable = true, defaultValue, disableOnNext, disableOnPrev, disabled = disabledFromFormControl || false, displayMonthLocale, error = severity === 'error' || false, fadeProps, format = defaultDateFormat, fullWidth = fullWidthFromFormControl || false, inputProps, isDateDisabled, isMonthDisabled, isYearDisabled, mode = 'day', onCalendarToggle: onCalendarToggleProp, onChange: onChangeProp, placeholder, popperProps, prefix, readOnly, referenceDate: referenceDateProp, required = requiredFromFormControl || false, size, value: valueProp, ...restTriggerProps } = props;
|
|
22
22
|
const { onBlur: onBlurProp, onKeyDown: onKeyDownProp, onFocus: onFocusProp, size: inputSize = format.length + 2, ...restInputProp } = inputProps || {};
|
|
23
23
|
const formats = useMemo(() => [
|
|
24
24
|
format,
|
|
@@ -18,7 +18,7 @@ import { FormControlContext } from '../Form/FormControlContext.js';
|
|
|
18
18
|
const DateRangePicker = forwardRef(function DateRangePicker(props, ref) {
|
|
19
19
|
const { disabled: disabledFromFormControl, fullWidth: fullWidthFromFormControl, required: requiredFromFormControl, severity, } = useContext(FormControlContext) || {};
|
|
20
20
|
const { defaultDateFormat, getNow, isBetween, } = useCalendarContext();
|
|
21
|
-
const { calendarProps, className, clearable, defaultValue, disabled = disabledFromFormControl || false, displayMonthLocale, error = severity === 'error' || false, fadeProps, format = defaultDateFormat, fullWidth = fullWidthFromFormControl || false, inputFromPlaceholder, inputFromProps, inputToPlaceholder, inputToProps, isDateDisabled, isMonthDisabled, isYearDisabled, mode = 'day', onCalendarToggle: onCalendarToggleProp, onChange: onChangeProp, popperProps, prefix, readOnly, referenceDate: referenceDateProp, required = requiredFromFormControl || false, size, value: valueProp, } = props;
|
|
21
|
+
const { calendarProps, className, clearable = true, defaultValue, disabled = disabledFromFormControl || false, displayMonthLocale, error = severity === 'error' || false, fadeProps, format = defaultDateFormat, fullWidth = fullWidthFromFormControl || false, inputFromPlaceholder, inputFromProps, inputToPlaceholder, inputToProps, isDateDisabled, isMonthDisabled, isYearDisabled, mode = 'day', onCalendarToggle: onCalendarToggleProp, onChange: onChangeProp, popperProps, prefix, readOnly, referenceDate: referenceDateProp, required = requiredFromFormControl || false, size, value: valueProp, } = props;
|
|
22
22
|
const { onBlur: onFromBlurProp, onKeyDown: onFromKeyDownProp, onFocus: onFromFocusProp, ...restInputFromProps } = inputFromProps || {};
|
|
23
23
|
const { onBlur: onToBlurProp, onKeyDown: onToKeyDownProp, onFocus: onToFocusProp, ...restInputToProps } = inputToProps || {};
|
|
24
24
|
const formats = useMemo(() => [
|
|
@@ -156,7 +156,9 @@ const DateRangePicker = forwardRef(function DateRangePicker(props, ref) {
|
|
|
156
156
|
const [from, to] = internalValue;
|
|
157
157
|
if (from && to) {
|
|
158
158
|
const newValue = onChange([from, to]);
|
|
159
|
-
|
|
159
|
+
if (onChangeProp) {
|
|
160
|
+
onChangeProp(newValue);
|
|
161
|
+
}
|
|
160
162
|
}
|
|
161
163
|
else {
|
|
162
164
|
onChange(valueProp);
|
|
@@ -18,7 +18,7 @@ const DateTimePicker = forwardRef(function DateTimePicker(props, ref) {
|
|
|
18
18
|
const { disabled: disabledFromFormControl, fullWidth: fullWidthFromFormControl, required: requiredFromFormControl, severity, } = useContext(FormControlContext) || {};
|
|
19
19
|
const { defaultDateFormat, defaultTimeFormat, getNow, startOf, } = useCalendarContext();
|
|
20
20
|
const defaultFormat = `${defaultDateFormat} ${defaultTimeFormat}`;
|
|
21
|
-
const { calendarProps, className, clearable, confirmText, defaultValue, disableOnNext, disableOnPrev, disabled = disabledFromFormControl, displayMonthLocale, error = severity === 'error' || false, fadeProps, format = defaultFormat, fullWidth = fullWidthFromFormControl, hideHour, hideMinute, hideSecond, hourPrefix, hourStep, inputProps, isDateDisabled, isMonthDisabled, isYearDisabled, minutePrefix, minuteStep, onChange: onChangeProp, onPanelToggle: onPanelToggleProp, placeholder, popperProps, prefix, readOnly, referenceDate: referenceDateProp, required = requiredFromFormControl, secondPrefix, secondStep, size: sizeProp, value: valueProp, } = props;
|
|
21
|
+
const { calendarProps, className, clearable = true, confirmText, defaultValue, disableOnNext, disableOnPrev, disabled = disabledFromFormControl, displayMonthLocale, error = severity === 'error' || false, fadeProps, format = defaultFormat, fullWidth = fullWidthFromFormControl, hideHour, hideMinute, hideSecond, hourPrefix, hourStep, inputProps, isDateDisabled, isMonthDisabled, isYearDisabled, minutePrefix, minuteStep, onChange: onChangeProp, onPanelToggle: onPanelToggleProp, placeholder, popperProps, prefix, readOnly, referenceDate: referenceDateProp, required = requiredFromFormControl, secondPrefix, secondStep, size: sizeProp, value: valueProp, } = props;
|
|
22
22
|
const { onBlur: onBlurProp, onKeyDown: onKeyDownProp, onFocus: onFocusProp, size: inputSize = format.length + 2, ...restInputProp } = inputProps || {};
|
|
23
23
|
const formats = useMemo(() => [format, defaultFormat], [defaultFormat, format]);
|
|
24
24
|
/** Panel open control */
|
|
@@ -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
|
|
|
@@ -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
|
|
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
|
-
|
|
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;
|
package/Select/SelectTrigger.js
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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
|
|
package/Select/typings.d.ts
CHANGED
|
@@ -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/Table/TableBodyRow.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { forwardRef, useContext, useState, useMemo,
|
|
3
|
-
import { tableClasses } from '@mezzanine-ui/core/table';
|
|
1
|
+
import { jsxs, jsx, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
2
|
+
import { forwardRef, useContext, useState, useMemo, Fragment } from 'react';
|
|
3
|
+
import { tableClasses, getColumnStyle, getCellStyle } from '@mezzanine-ui/core/table';
|
|
4
|
+
import get from 'lodash/get';
|
|
4
5
|
import { TableContext, TableDataContext } from './TableContext.js';
|
|
5
6
|
import TableCell from './TableCell.js';
|
|
7
|
+
import TableExpandedTable from './TableExpandedTable.js';
|
|
6
8
|
import TableRowSelection from './rowSelection/TableRowSelection.js';
|
|
7
9
|
import TableExpandable from './expandable/TableExpandable.js';
|
|
8
10
|
import TableEditRenderWrapper from './editable/TableEditRenderWrapper.js';
|
|
@@ -25,39 +27,17 @@ const TableBodyRow = forwardRef(function TableBodyRow(props, ref) {
|
|
|
25
27
|
var _a, _b;
|
|
26
28
|
return ((_b = (_a = expanding === null || expanding === void 0 ? void 0 : expanding.expandedRowRender) === null || _a === void 0 ? void 0 : _a.call(expanding, rowData)) !== null && _b !== void 0 ? _b : null);
|
|
27
29
|
}, [expanding, rowData]);
|
|
28
|
-
/** styling */
|
|
29
|
-
const getColumnStyle = useCallback((column) => {
|
|
30
|
-
let style = {};
|
|
31
|
-
if (column.width) {
|
|
32
|
-
style = {
|
|
33
|
-
...style,
|
|
34
|
-
width: column.width,
|
|
35
|
-
maxWidth: column.width,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
return style;
|
|
39
|
-
}, []);
|
|
40
|
-
const getCellStyle = useCallback((column) => {
|
|
41
|
-
let style = {};
|
|
42
|
-
if (column.align) {
|
|
43
|
-
style = {
|
|
44
|
-
...style,
|
|
45
|
-
justifyContent: column.align === 'center' ? column.align : `flex-${column.align}`,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return style;
|
|
49
|
-
}, []);
|
|
50
30
|
return (jsxs(Fragment, { children: [jsxs("div", Object.assign({}, rest, { ref: ref, className: cx(tableClasses.bodyRow, {
|
|
51
31
|
[tableClasses.bodyRowHighlight]: selected || expanded,
|
|
52
32
|
}, className), role: "row" }, { children: [rowSelection ? (jsx(TableRowSelection, { role: "gridcell", rowKey: (rowData.key || rowData.id), setChecked: (status) => setSelected(status), showDropdownIcon: false }, void 0)) : null,
|
|
53
|
-
expanding ? (jsx(TableExpandable, { expandable: isExpandable, expanded: expanded, role: "gridcell", setExpanded: setExpanded }, void 0)) : null,
|
|
33
|
+
expanding ? (jsx(TableExpandable, { expandable: isExpandable, expanded: expanded, role: "gridcell", setExpanded: setExpanded, onExpand: (status) => { var _a; return (_a = expanding.onExpand) === null || _a === void 0 ? void 0 : _a.call(expanding, rowData, status); } }, void 0)) : null,
|
|
54
34
|
(columns !== null && columns !== void 0 ? columns : []).map((column, index) => {
|
|
55
35
|
var _a, _b, _c, _d;
|
|
56
|
-
const ellipsis = !!(rowData
|
|
57
|
-
const tooltipTitle = ((_c = (_b = column.renderTooltipTitle) === null || _b === void 0 ? void 0 : _b.call(column, rowData)) !== null && _c !== void 0 ? _c : rowData
|
|
58
|
-
return (jsx("div", Object.assign({ className: cx(tableClasses.bodyRowCellWrapper, column.bodyClassName), style: getColumnStyle(column) }, { children: jsx(TableEditRenderWrapper, Object.assign({}, column, { rowData: rowData }, { children: jsx(TableCell, Object.assign({ ellipsis: ellipsis, forceShownTooltipWhenHovered: column.forceShownTooltipWhenHovered, style: getCellStyle(column), tooltipTitle: tooltipTitle }, { children: ((_d = column.render) === null || _d === void 0 ? void 0 : _d.call(column, column, rowData, index)) || rowData
|
|
36
|
+
const ellipsis = !!(get(rowData, column.dataIndex)) && ((_a = column.ellipsis) !== null && _a !== void 0 ? _a : true);
|
|
37
|
+
const tooltipTitle = ((_c = (_b = column.renderTooltipTitle) === null || _b === void 0 ? void 0 : _b.call(column, rowData)) !== null && _c !== void 0 ? _c : get(rowData, column.dataIndex));
|
|
38
|
+
return (jsx("div", Object.assign({ className: cx(tableClasses.bodyRowCellWrapper, column.bodyClassName), style: getColumnStyle(column) }, { children: jsx(TableEditRenderWrapper, Object.assign({}, column, { rowData: rowData }, { children: jsx(TableCell, Object.assign({ ellipsis: ellipsis, forceShownTooltipWhenHovered: column.forceShownTooltipWhenHovered, style: getCellStyle(column), tooltipTitle: tooltipTitle }, { children: ((_d = column.render) === null || _d === void 0 ? void 0 : _d.call(column, column, rowData, index)) || get(rowData, column.dataIndex) }), void 0) }), void 0) }), `${column.dataIndex}-${column.title}`));
|
|
59
39
|
})] }), void 0),
|
|
60
|
-
renderedExpandedContent ? (jsx(AccordionDetails, Object.assign({ className: expanding.className, expanded: expanded }, { children: renderedExpandedContent }), void 0)) : null] }, void 0));
|
|
40
|
+
renderedExpandedContent ? (jsx(Fragment$1, { children: typeof renderedExpandedContent === 'string' ? (jsx(AccordionDetails, Object.assign({ className: expanding.className, expanded: expanded }, { children: renderedExpandedContent }), void 0)) : (jsx(Fragment$1, { children: renderedExpandedContent.dataSource.length > 0 ? (jsx(AccordionDetails, Object.assign({ className: cx(expanding.className, tableClasses.bodyRowExpandedTableWrapper), expanded: expanded }, { children: jsx(TableExpandedTable, { renderedExpandedContent: renderedExpandedContent }, void 0) }), void 0)) : null }, void 0)) }, void 0)) : null] }, void 0));
|
|
61
41
|
});
|
|
62
42
|
var TableBodyRow$1 = TableBodyRow;
|
|
63
43
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TableDataSource, ExpandedTableColumn } from '@mezzanine-ui/core/table';
|
|
3
|
+
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
4
|
+
export interface TableExpandedTableProps extends NativeElementPropsWithoutKeyAndRef<'div'> {
|
|
5
|
+
renderedExpandedContent: {
|
|
6
|
+
dataSource: TableDataSource[];
|
|
7
|
+
columns?: ExpandedTableColumn[];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
declare const TableExpandedTable: import("react").ForwardRefExoticComponent<TableExpandedTableProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
11
|
+
export default TableExpandedTable;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { forwardRef, useContext } from 'react';
|
|
3
|
+
import { tableClasses, getColumnStyle, getCellStyle } from '@mezzanine-ui/core/table';
|
|
4
|
+
import get from 'lodash/get';
|
|
5
|
+
import { TableDataContext } from './TableContext.js';
|
|
6
|
+
import TableCell from './TableCell.js';
|
|
7
|
+
import TableExpandable from './expandable/TableExpandable.js';
|
|
8
|
+
import cx from 'clsx';
|
|
9
|
+
|
|
10
|
+
const TableExpandedTable = forwardRef(function TableExpandedTable(props, ref) {
|
|
11
|
+
const { renderedExpandedContent, } = props;
|
|
12
|
+
const { columns, } = useContext(TableDataContext) || {};
|
|
13
|
+
return (jsx("div", Object.assign({ className: tableClasses.bodyRowExpandedTable }, { children: renderedExpandedContent.dataSource.map((source) => {
|
|
14
|
+
var _a;
|
|
15
|
+
return (jsxs("div", Object.assign({ ref: ref, className: cx(tableClasses.bodyRow, tableClasses.bodyRowExpandedTableRow), role: "row" }, { children: [jsx(TableExpandable, { showIcon: false }, void 0),
|
|
16
|
+
((_a = (renderedExpandedContent.columns || columns)) !== null && _a !== void 0 ? _a : [])
|
|
17
|
+
.map((column, index) => {
|
|
18
|
+
var _a, _b, _c, _d;
|
|
19
|
+
const ellipsis = !!(get(source, column.dataIndex)) && ((_a = column.ellipsis) !== null && _a !== void 0 ? _a : true);
|
|
20
|
+
const tooltipTitle = ((_c = (_b = column.renderTooltipTitle) === null || _b === void 0 ? void 0 : _b.call(column, source)) !== null && _c !== void 0 ? _c : get(source, column.dataIndex));
|
|
21
|
+
return (jsx("div", Object.assign({ className: cx(tableClasses.bodyRowCellWrapper, column.bodyClassName), style: getColumnStyle((columns !== null && columns !== void 0 ? columns : [])[index]) }, { children: jsx(TableCell, Object.assign({ ellipsis: ellipsis, forceShownTooltipWhenHovered: column.forceShownTooltipWhenHovered, style: getCellStyle((columns !== null && columns !== void 0 ? columns : [])[index]), tooltipTitle: tooltipTitle || '' }, { children: ((_d = column.render) === null || _d === void 0 ? void 0 : _d.call(column, column, source, index)) || get(source, column.dataIndex) }), void 0) }), `${column.dataIndex}-${index}`));
|
|
22
|
+
})] }), (source.key || source.id)));
|
|
23
|
+
}) }), void 0));
|
|
24
|
+
});
|
|
25
|
+
var TableExpandedTable$1 = TableExpandedTable;
|
|
26
|
+
|
|
27
|
+
export { TableExpandedTable$1 as default };
|
package/Table/TableHeader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { forwardRef, useContext
|
|
3
|
-
import { tableClasses } from '@mezzanine-ui/core/table';
|
|
2
|
+
import { forwardRef, useContext } from 'react';
|
|
3
|
+
import { tableClasses, getColumnStyle, getCellStyle } from '@mezzanine-ui/core/table';
|
|
4
4
|
import { TableContext, TableDataContext } from './TableContext.js';
|
|
5
5
|
import { SELECTED_ALL_KEY } from './rowSelection/useTableRowSelection.js';
|
|
6
6
|
import TableCell from './TableCell.js';
|
|
@@ -13,34 +13,12 @@ const TableHeader = forwardRef(function TableHeader(props, ref) {
|
|
|
13
13
|
const { className, ...rest } = props;
|
|
14
14
|
const { rowSelection, expanding, } = useContext(TableContext) || {};
|
|
15
15
|
const { columns, } = useContext(TableDataContext) || {};
|
|
16
|
-
/** styling */
|
|
17
|
-
const getColumnStyle = useCallback((column) => {
|
|
18
|
-
let style = {};
|
|
19
|
-
if (column.width) {
|
|
20
|
-
style = {
|
|
21
|
-
...style,
|
|
22
|
-
width: column.width,
|
|
23
|
-
maxWidth: column.width,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
return style;
|
|
27
|
-
}, []);
|
|
28
|
-
const getCellStyle = useCallback((column) => {
|
|
29
|
-
let style = {};
|
|
30
|
-
if (column.align) {
|
|
31
|
-
style = {
|
|
32
|
-
...style,
|
|
33
|
-
justifyContent: column.align === 'center' ? column.align : `flex-${column.align}`,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
return style;
|
|
37
|
-
}, []);
|
|
38
16
|
return (jsxs("div", Object.assign({ ref: ref }, rest, { className: cx(tableClasses.header, className), role: "rowgroup" }, { children: [rowSelection ? (jsx(TableRowSelection, { rowKey: SELECTED_ALL_KEY, showDropdownIcon: true }, void 0)) : null,
|
|
39
17
|
expanding && !rowSelection ? (jsx(TableExpandable, { showIcon: false }, void 0)) : null,
|
|
40
18
|
(columns !== null && columns !== void 0 ? columns : []).map((column) => {
|
|
41
19
|
var _a;
|
|
42
20
|
return (jsx("div", Object.assign({ className: cx(tableClasses.headerCellWrapper, column.headerClassName), style: getColumnStyle(column) }, { children: jsxs(TableCell, Object.assign({ ellipsis: false, role: "columnheader", style: getCellStyle(column) }, { children: [((_a = column.renderTitle) === null || _a === void 0 ? void 0 : _a.call(column, tableClasses)) || column.title,
|
|
43
|
-
typeof column.sorter === 'function' ? (jsx(TableSortingIcon, { column: column }, void 0)) : null] }), void 0) }), `${column.dataIndex}-${column.title}`));
|
|
21
|
+
typeof column.sorter === 'function' || typeof column.onSorted === 'function' ? (jsx(TableSortingIcon, { column: column }, void 0)) : null] }), void 0) }), `${column.dataIndex}-${column.title}`));
|
|
44
22
|
})] }), void 0));
|
|
45
23
|
});
|
|
46
24
|
var TableHeader$1 = TableHeader;
|
|
@@ -10,6 +10,10 @@ export interface TableExpandableProps extends NativeElementPropsWithoutKeyAndRef
|
|
|
10
10
|
* whether is expanded or not
|
|
11
11
|
*/
|
|
12
12
|
expanded?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Invoked by expanded status changed.
|
|
15
|
+
*/
|
|
16
|
+
onExpand?(status: boolean): void;
|
|
13
17
|
/**
|
|
14
18
|
* toggle expanded
|
|
15
19
|
*/
|
|
@@ -6,10 +6,19 @@ import Icon from '../../Icon/Icon.js';
|
|
|
6
6
|
import cx from 'clsx';
|
|
7
7
|
|
|
8
8
|
const TableExpandable = forwardRef(function TableExpandable(props, ref) {
|
|
9
|
-
const { className, expandable = true, expanded, setExpanded, showIcon = true, ...rest } = props;
|
|
9
|
+
const { className, expandable = true, expanded, onExpand, setExpanded, showIcon = true, ...rest } = props;
|
|
10
|
+
const onClick = () => {
|
|
11
|
+
if (expandable) {
|
|
12
|
+
const nextStatus = !expanded;
|
|
13
|
+
setExpanded === null || setExpanded === void 0 ? void 0 : setExpanded(nextStatus);
|
|
14
|
+
if (onExpand) {
|
|
15
|
+
onExpand(nextStatus);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
10
19
|
return (jsx("div", Object.assign({}, rest, { ref: ref, className: cx(tableClasses.collapseAction, className) }, { children: jsx("div", Object.assign({ className: tableClasses.icon }, { children: showIcon ? (jsx(Icon, { className: cx(tableClasses.icon, {
|
|
11
20
|
[tableClasses.iconClickable]: expandable,
|
|
12
|
-
}), color: expandable ? 'primary' : 'disabled', icon: ChevronDownIcon, onClick:
|
|
21
|
+
}), color: expandable ? 'primary' : 'disabled', icon: ChevronDownIcon, onClick: onClick, style: { transform: `rotate(${expanded ? '180deg' : '0'})` } }, void 0)) : null }), void 0) }), void 0));
|
|
13
22
|
});
|
|
14
23
|
var TableExpandable$1 = TableExpandable;
|
|
15
24
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState, useCallback } from 'react';
|
|
2
2
|
import isEqual from 'lodash/isEqual';
|
|
3
|
+
import get from 'lodash/get';
|
|
3
4
|
import { useControlValueState } from '../../Form/useControlValueState.js';
|
|
4
5
|
import { useLastCallback } from '../../hooks/useLastCallback.js';
|
|
5
6
|
|
|
@@ -50,15 +51,15 @@ function useTableSorting(props) {
|
|
|
50
51
|
}, []);
|
|
51
52
|
const onChange = useLastCallback((opts) => {
|
|
52
53
|
const { dataIndex, sorter, onSorted } = opts;
|
|
54
|
+
const isChosenFromOneToAnother = sortedOn && dataIndex !== sortedOn;
|
|
55
|
+
const nextSortedType = getNextSortedType(isChosenFromOneToAnother ? 'none' : sortedType);
|
|
53
56
|
const onMappingSources = (sources) => {
|
|
54
57
|
setDataSource(sources);
|
|
55
|
-
onSorted === null || onSorted === void 0 ? void 0 : onSorted(
|
|
58
|
+
onSorted === null || onSorted === void 0 ? void 0 : onSorted(dataIndex, nextSortedType);
|
|
56
59
|
};
|
|
57
60
|
// only apply changes when column sorter is given
|
|
58
|
-
if (typeof sorter === 'function') {
|
|
61
|
+
if (typeof sorter === 'function' || typeof onSorted === 'function') {
|
|
59
62
|
// should update next sorted type first
|
|
60
|
-
const isChosenFromOneToAnother = sortedOn && dataIndex !== sortedOn;
|
|
61
|
-
const nextSortedType = getNextSortedType(isChosenFromOneToAnother ? 'none' : sortedType);
|
|
62
63
|
setSortedType(nextSortedType);
|
|
63
64
|
switch (nextSortedType) {
|
|
64
65
|
case 'desc':
|
|
@@ -67,10 +68,12 @@ function useTableSorting(props) {
|
|
|
67
68
|
setSortedOn(dataIndex);
|
|
68
69
|
// getting new source instance (when switch between sorter, should use origin dataSource)
|
|
69
70
|
let newSource = (isChosenFromOneToAnother ? dataSourceProp : dataSource).slice(0);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
if (typeof sorter === 'function') {
|
|
72
|
+
// sort by given sorter
|
|
73
|
+
newSource = newSource.sort((a, b) => (
|
|
74
|
+
// reverse result when sorted type is ascending
|
|
75
|
+
(sorter(get(a, dataIndex), get(b, dataIndex))) * (nextSortedType === 'asc' ? -1 : 1)));
|
|
76
|
+
}
|
|
74
77
|
// map back the data source
|
|
75
78
|
onMappingSources(newSource);
|
|
76
79
|
break;
|
package/Tabs/useTabsOverflow.js
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
|
-
import { useWindowWidth } from '../hooks/useWindowWidth.js';
|
|
3
2
|
|
|
4
3
|
function useTabsOverflow(tabsRef) {
|
|
5
4
|
const [isOverflowing, setIsOverflowing] = useState(false);
|
|
6
5
|
const [scrollState, setScrollState] = useState('begin');
|
|
7
6
|
const isScrollToBegin = scrollState === 'begin';
|
|
8
7
|
const isScrollToEnd = scrollState === 'end';
|
|
9
|
-
const windowWidth = useWindowWidth();
|
|
10
|
-
function handleScrollState() {
|
|
11
|
-
if (tabsRef.current) {
|
|
12
|
-
const offsetRight = tabsRef.current.scrollWidth - tabsRef.current.clientWidth;
|
|
13
|
-
if (tabsRef.current.scrollLeft === 0) {
|
|
14
|
-
setScrollState('begin');
|
|
15
|
-
}
|
|
16
|
-
else if (tabsRef.current.scrollLeft >= offsetRight) {
|
|
17
|
-
setScrollState('end');
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
setScrollState('middle');
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
8
|
function scrollToLeft() {
|
|
25
9
|
if (tabsRef.current) {
|
|
26
10
|
tabsRef.current.scrollTo(0, 0);
|
|
@@ -34,16 +18,35 @@ function useTabsOverflow(tabsRef) {
|
|
|
34
18
|
}
|
|
35
19
|
useEffect(() => {
|
|
36
20
|
if (tabsRef.current) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
21
|
+
const handleOverflowingState = () => {
|
|
22
|
+
if (tabsRef.current) {
|
|
23
|
+
setIsOverflowing(tabsRef.current.scrollWidth > tabsRef.current.clientWidth);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const handleScrollState = () => {
|
|
27
|
+
if (tabsRef.current) {
|
|
28
|
+
const offsetRight = tabsRef.current.scrollWidth - tabsRef.current.clientWidth;
|
|
29
|
+
if (tabsRef.current.scrollLeft === 0) {
|
|
30
|
+
setScrollState('begin');
|
|
31
|
+
}
|
|
32
|
+
else if (tabsRef.current.scrollLeft >= offsetRight) {
|
|
33
|
+
setScrollState('end');
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
setScrollState('middle');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
// init isOverflowing when mounting
|
|
41
|
+
handleOverflowingState();
|
|
42
|
+
window.addEventListener('resize', handleOverflowingState);
|
|
45
43
|
tabsRef.current.addEventListener('scroll', handleScrollState);
|
|
46
|
-
return () => {
|
|
44
|
+
return () => {
|
|
45
|
+
if (tabsRef.current) {
|
|
46
|
+
window.removeEventListener('resize', handleOverflowingState);
|
|
47
|
+
tabsRef.current.removeEventListener('scroll', handleScrollState);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
47
50
|
}
|
|
48
51
|
}, [tabsRef.current]);
|
|
49
52
|
return {
|
|
@@ -20,12 +20,13 @@ const TimePanelColumn = forwardRef(function TimePanelColumn(props, ref) {
|
|
|
20
20
|
};
|
|
21
21
|
const prevetSmoothScrollTo = useRef(true);
|
|
22
22
|
useEffect(() => {
|
|
23
|
-
var _a;
|
|
24
23
|
const activeIndex = units.findIndex(({ value }) => value === activeUnit);
|
|
25
|
-
(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
if (cellsRef.current) {
|
|
25
|
+
cellsRef.current.scrollTo({
|
|
26
|
+
top: activeIndex * cellHeight,
|
|
27
|
+
behavior: prevetSmoothScrollTo.current ? 'auto' : 'smooth',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
29
30
|
prevetSmoothScrollTo.current = false;
|
|
30
31
|
}, [activeUnit, cellHeight, units]);
|
|
31
32
|
return (jsxs("div", Object.assign({ ref: ref, className: timePanelClasses.column }, { children: [prefix && jsx("div", Object.assign({ className: timePanelClasses.columnPrefix }, { children: prefix }), void 0),
|
package/TimePicker/TimePicker.js
CHANGED
|
@@ -17,7 +17,7 @@ import { FormControlContext } from '../Form/FormControlContext.js';
|
|
|
17
17
|
const TimePicker = forwardRef(function TimePicker(props, ref) {
|
|
18
18
|
const { disabled: disabledFromFormControl, fullWidth: fullWidthFromFormControl, required: requiredFromFormControl, severity, } = useContext(FormControlContext) || {};
|
|
19
19
|
const { defaultTimeFormat, } = useCalendarContext();
|
|
20
|
-
const { className, clearable, confirmText, defaultValue, disabled = disabledFromFormControl, error = severity === 'error' || false, format = defaultTimeFormat, fullWidth = fullWidthFromFormControl, hideHour, hideMinute, hideSecond, hourPrefix, hourStep, inputProps, minutePrefix, minuteStep, onChange: onChangeProp, onPanelToggle: onPanelToggleProp, placeholder, popperProps, prefix, readOnly, required = requiredFromFormControl, secondPrefix, secondStep, size: sizeProp, value: valueProp, } = props;
|
|
20
|
+
const { className, clearable = true, confirmText, defaultValue, disabled = disabledFromFormControl, error = severity === 'error' || false, format = defaultTimeFormat, fullWidth = fullWidthFromFormControl, hideHour, hideMinute, hideSecond, hourPrefix, hourStep, inputProps, minutePrefix, minuteStep, onChange: onChangeProp, onPanelToggle: onPanelToggleProp, placeholder, popperProps, prefix, readOnly, required = requiredFromFormControl, secondPrefix, secondStep, size: sizeProp, value: valueProp, } = props;
|
|
21
21
|
const { onBlur: onBlurProp, onKeyDown: onKeyDownProp, onFocus: onFocusProp, size: inputSize = format.length + 2, ...restInputProp } = inputProps || {};
|
|
22
22
|
const formats = useMemo(() => [format], [format]);
|
|
23
23
|
/** Panel open control */
|
package/index.d.ts
CHANGED
|
@@ -43,8 +43,7 @@ export { DropdownProps, default as Dropdown, } from './Dropdown';
|
|
|
43
43
|
export { NavigationItem, NavigationItemProps, NavigationSubMenu, NavigationSubMenuProps, NavigationSubMenuChild, NavigationSubMenuChildren, NavigationChild, NavigationChildren, NavigationProps, default as Navigation, } from './Navigation';
|
|
44
44
|
export { AppBarChild, AppBarChildren, AppBarBrand, AppBarBrandProps, AppBarMain, AppBarMainProps, AppBarSupport, AppBarSupportProps, default as AppBar, } from './AppBar';
|
|
45
45
|
export { PageFooterProps, default as PageFooter, } from './PageFooter';
|
|
46
|
-
export { StepProps, default as
|
|
47
|
-
export { StepperProps, default as Stepper, } from './Stepper';
|
|
46
|
+
export { StepProps, StepperProps, Step, default as Stepper, } from './Stepper';
|
|
48
47
|
/**
|
|
49
48
|
* Data Display
|
|
50
49
|
*/
|
package/index.js
CHANGED
|
@@ -45,7 +45,8 @@ export { default as AppBarMain } from './AppBar/AppBarMain.js';
|
|
|
45
45
|
export { default as AppBarSupport } from './AppBar/AppBarSupport.js';
|
|
46
46
|
export { default as AppBar } from './AppBar/AppBar.js';
|
|
47
47
|
export { default as PageFooter } from './PageFooter/PageFooter.js';
|
|
48
|
-
export { default as Step
|
|
48
|
+
export { default as Step } from './Stepper/Step.js';
|
|
49
|
+
export { default as Stepper } from './Stepper/Stepper.js';
|
|
49
50
|
export { default as AccordionSummary } from './Accordion/AccordionSummary.js';
|
|
50
51
|
export { default as AccordionDetails } from './Accordion/AccordionDetails.js';
|
|
51
52
|
export { default as Accordion } from './Accordion/Accordion.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mezzanine-ui/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "React components for mezzanine-ui",
|
|
5
5
|
"author": "Mezzanine",
|
|
6
6
|
"repository": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"react-dom": "^17.0.1"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@mezzanine-ui/core": "^0.
|
|
35
|
+
"@mezzanine-ui/core": "^0.9.0",
|
|
36
36
|
"@mezzanine-ui/icons": "^0.7.3",
|
|
37
37
|
"@mezzanine-ui/system": "^0.7.0",
|
|
38
38
|
"@popperjs/core": "^2.9.2",
|