@mezzanine-ui/react 1.0.0-beta.4 → 1.0.0-beta.5
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/AutoComplete/AutoComplete.js +17 -1
- package/Calendar/Calendar.js +2 -6
- package/Calendar/CalendarCell.d.ts +22 -0
- package/Calendar/CalendarCell.js +6 -2
- package/Calendar/CalendarControls.js +1 -1
- package/Calendar/CalendarDayOfWeek.js +3 -2
- package/Calendar/CalendarDays.js +5 -1
- package/Calendar/CalendarHalfYears.js +13 -7
- package/Calendar/CalendarMonths.js +13 -6
- package/Calendar/CalendarQuarters.js +13 -7
- package/Calendar/CalendarWeeks.js +87 -34
- package/Calendar/CalendarYears.js +13 -12
- package/Calendar/useCalendarControlModifiers.d.ts +1 -1
- package/Calendar/useCalendarControlModifiers.js +12 -12
- package/Calendar/useCalendarControls.d.ts +4 -4
- package/Calendar/useCalendarControls.js +33 -19
- package/Calendar/useRangeCalendarControls.d.ts +8 -8
- package/Calendar/useRangeCalendarControls.js +42 -31
- package/DateRangePicker/useDateRangeCalendarControls.js +8 -2
- package/Dropdown/Dropdown.d.ts +31 -0
- package/Dropdown/Dropdown.js +11 -1
- package/Dropdown/DropdownItem.d.ts +32 -0
- package/Dropdown/DropdownItem.js +112 -10
- package/Dropdown/DropdownItemCard.d.ts +5 -0
- package/Dropdown/DropdownItemCard.js +2 -2
- package/Form/useSelectValueControl.d.ts +3 -4
- package/Form/useSelectValueControl.js +51 -39
- package/Popper/Popper.js +2 -1
- package/Scrollbar/Scrollbar.js +1 -0
- package/Select/Select.d.ts +37 -18
- package/Select/Select.js +165 -51
- package/Select/index.d.ts +8 -9
- package/Select/index.js +3 -3
- package/package.json +4 -4
|
@@ -9,55 +9,67 @@ function useSelectBaseValueControl(props) {
|
|
|
9
9
|
equalityFn,
|
|
10
10
|
value: valueProp,
|
|
11
11
|
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
onChange: (chooseOption) => {
|
|
12
|
+
if (mode === 'multiple') {
|
|
13
|
+
const onChangeMultiple = (chooseOption) => {
|
|
15
14
|
var _a;
|
|
16
15
|
if (!chooseOption) {
|
|
17
|
-
|
|
18
|
-
return [];
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
16
|
+
return [];
|
|
21
17
|
}
|
|
22
|
-
let newValue =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
newValue = [...value, chooseOption];
|
|
34
|
-
}
|
|
35
|
-
if (typeof onChange === 'function')
|
|
36
|
-
onChange(newValue);
|
|
37
|
-
break;
|
|
18
|
+
let newValue = [];
|
|
19
|
+
if (Array.isArray(chooseOption)) {
|
|
20
|
+
newValue = chooseOption;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const existedValueIdx = ((_a = value) !== null && _a !== void 0 ? _a : []).findIndex((v) => v.id === chooseOption.id);
|
|
24
|
+
if (~existedValueIdx) {
|
|
25
|
+
newValue = [
|
|
26
|
+
...value.slice(0, existedValueIdx),
|
|
27
|
+
...value.slice(existedValueIdx + 1),
|
|
28
|
+
];
|
|
38
29
|
}
|
|
39
|
-
|
|
40
|
-
newValue = chooseOption;
|
|
41
|
-
if (typeof onClose === 'function') {
|
|
42
|
-
/** single selection should close modal when clicked */
|
|
43
|
-
onClose();
|
|
44
|
-
}
|
|
45
|
-
if (typeof onChange === 'function')
|
|
46
|
-
onChange(newValue);
|
|
47
|
-
break;
|
|
30
|
+
else {
|
|
31
|
+
newValue = [...value, chooseOption];
|
|
48
32
|
}
|
|
49
33
|
}
|
|
34
|
+
if (typeof onChange === 'function')
|
|
35
|
+
onChange(newValue);
|
|
50
36
|
setValue(newValue);
|
|
51
37
|
return newValue;
|
|
52
|
-
}
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
value: value,
|
|
41
|
+
onChange: onChangeMultiple,
|
|
42
|
+
onClear: (e) => {
|
|
43
|
+
e.stopPropagation();
|
|
44
|
+
setValue([]);
|
|
45
|
+
onChange === null || onChange === void 0 ? void 0 : onChange([]);
|
|
46
|
+
if (typeof onClearProp === 'function') {
|
|
47
|
+
onClearProp(e);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const onChangeSingle = (chooseOption) => {
|
|
53
|
+
if (!chooseOption) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const newValue = chooseOption;
|
|
57
|
+
if (typeof onClose === 'function') {
|
|
58
|
+
/** single selection should close modal when clicked */
|
|
59
|
+
onClose();
|
|
60
|
+
}
|
|
61
|
+
if (typeof onChange === 'function')
|
|
62
|
+
onChange(newValue);
|
|
63
|
+
setValue(newValue);
|
|
64
|
+
return newValue;
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
value: value,
|
|
68
|
+
onChange: onChangeSingle,
|
|
53
69
|
onClear: (e) => {
|
|
54
70
|
e.stopPropagation();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
setValue(null);
|
|
60
|
-
}
|
|
71
|
+
setValue(null);
|
|
72
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(null);
|
|
61
73
|
if (typeof onClearProp === 'function') {
|
|
62
74
|
onClearProp(e);
|
|
63
75
|
}
|
package/Popper/Popper.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { forwardRef, useRef, useImperativeHandle, useEffect, useCallback } from 'react';
|
|
4
|
-
import { useFloating, arrow } from '@floating-ui/react-dom';
|
|
4
|
+
import { useFloating, arrow, autoUpdate } from '@floating-ui/react-dom';
|
|
5
5
|
import { spacingPrefix } from '@mezzanine-ui/system/spacing';
|
|
6
6
|
import { getElement } from '../utils/getElement.js';
|
|
7
7
|
import { useComposeRefs } from '../hooks/useComposeRefs.js';
|
|
@@ -15,6 +15,7 @@ const Popper = forwardRef(function Popper(props, ref) {
|
|
|
15
15
|
const anchorEl = getElement(anchor);
|
|
16
16
|
const floatingReturn = useFloating({
|
|
17
17
|
...options,
|
|
18
|
+
whileElementsMounted: autoUpdate,
|
|
18
19
|
middleware: [
|
|
19
20
|
...((_a = options === null || options === void 0 ? void 0 : options.middleware) !== null && _a !== void 0 ? _a : []),
|
|
20
21
|
(arrow$1 === null || arrow$1 === void 0 ? void 0 : arrow$1.enabled)
|
package/Scrollbar/Scrollbar.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import 'overlayscrollbars/overlayscrollbars.css';
|
|
2
3
|
import { forwardRef, useEffect, useMemo, useCallback } from 'react';
|
|
3
4
|
import { OverlayScrollbars, ClickScrollPlugin } from 'overlayscrollbars';
|
|
4
5
|
import { OverlayScrollbarsComponent } from 'overlayscrollbars-react';
|
package/Select/Select.d.ts
CHANGED
|
@@ -1,33 +1,52 @@
|
|
|
1
|
+
import { DropdownOption, DropdownType } from '@mezzanine-ui/core/dropdown/dropdown';
|
|
1
2
|
import { SelectInputSize } from '@mezzanine-ui/core/select';
|
|
3
|
+
import React, { ReactElement } from 'react';
|
|
2
4
|
import { FormElementFocusHandlers } from '../Form';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
import { SelectTriggerInputProps, SelectTriggerProps, SelectValue } from './typings';
|
|
6
|
+
export interface SelectBaseProps extends Omit<SelectTriggerProps, 'active' | 'inputProps' | 'mode' | 'onBlur' | 'onChange' | 'onClick' | 'onFocus' | 'onKeyDown' | 'onScroll' | 'type' | 'renderValue' | 'value'>, FormElementFocusHandlers {
|
|
7
|
+
/**
|
|
8
|
+
* The children of select (Option components).
|
|
9
|
+
* If `options` is provided, this will be ignored.
|
|
10
|
+
*/
|
|
11
|
+
children?: ReactElement | ReactElement[];
|
|
12
|
+
/**
|
|
13
|
+
* Direct options array for dropdown (supports tree structure).
|
|
14
|
+
* If provided, `children` will be ignored and `type` will be automatically set.
|
|
15
|
+
*/
|
|
16
|
+
options?: DropdownOption[];
|
|
17
|
+
/**
|
|
18
|
+
* The type of dropdown.
|
|
19
|
+
* @default 'default'
|
|
20
|
+
*/
|
|
21
|
+
type?: DropdownType;
|
|
16
22
|
/**
|
|
17
23
|
* The other native props for input element.
|
|
18
24
|
*/
|
|
19
25
|
inputProps?: Omit<SelectTriggerInputProps, 'onBlur' | 'onChange' | 'onFocus' | 'placeholder' | 'role' | 'value' | `aria-${'controls' | 'expanded' | 'owns'}`>;
|
|
26
|
+
/**
|
|
27
|
+
* Whether to disable portal.
|
|
28
|
+
*/
|
|
29
|
+
disablePortal?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The max height of the dropdown list.
|
|
32
|
+
*/
|
|
33
|
+
menuMaxHeight?: number | string;
|
|
20
34
|
/**
|
|
21
35
|
* Popup menu scroll listener
|
|
22
36
|
*/
|
|
23
|
-
|
|
37
|
+
onScroll?: (computed: {
|
|
24
38
|
scrollTop: number;
|
|
25
39
|
maxScrollTop: number;
|
|
26
|
-
}, target:
|
|
40
|
+
}, target: HTMLDivElement) => void;
|
|
27
41
|
/**
|
|
28
42
|
* select input placeholder
|
|
29
43
|
*/
|
|
30
44
|
placeholder?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Whether the input is readonly.
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
readOnly?: boolean;
|
|
31
50
|
/**
|
|
32
51
|
* To customize rendering select input value
|
|
33
52
|
*/
|
|
@@ -54,7 +73,7 @@ export type SelectMultipleProps = SelectBaseProps & {
|
|
|
54
73
|
/**
|
|
55
74
|
* The change event handler of input element.
|
|
56
75
|
*/
|
|
57
|
-
onChange?(newOptions: SelectValue[]):
|
|
76
|
+
onChange?(newOptions: SelectValue[]): void;
|
|
58
77
|
/**
|
|
59
78
|
* To customize rendering select input value
|
|
60
79
|
*/
|
|
@@ -77,7 +96,7 @@ export type SelectSingleProps = SelectBaseProps & {
|
|
|
77
96
|
/**
|
|
78
97
|
* The change event handler of input element.
|
|
79
98
|
*/
|
|
80
|
-
onChange?(newOptions: SelectValue):
|
|
99
|
+
onChange?(newOptions: SelectValue | null): void;
|
|
81
100
|
/**
|
|
82
101
|
* To customize rendering select input value
|
|
83
102
|
*/
|
|
@@ -89,5 +108,5 @@ export type SelectSingleProps = SelectBaseProps & {
|
|
|
89
108
|
value?: SelectValue | null;
|
|
90
109
|
};
|
|
91
110
|
export type SelectProps = SelectMultipleProps | SelectSingleProps;
|
|
92
|
-
declare const Select:
|
|
111
|
+
declare const Select: React.ForwardRefExoticComponent<SelectProps & React.RefAttributes<HTMLDivElement>>;
|
|
93
112
|
export default Select;
|
package/Select/Select.js
CHANGED
|
@@ -1,41 +1,34 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx
|
|
3
|
-
import { forwardRef, useContext, useState, useRef, useCallback, useMemo } from 'react';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
3
|
import { selectClasses } from '@mezzanine-ui/core/select';
|
|
5
4
|
import isArray from 'lodash/isArray';
|
|
5
|
+
import React, { forwardRef, useContext, useState, useCallback, useRef, useMemo, Children } from 'react';
|
|
6
|
+
import { useSelectValueControl } from '../Form/useSelectValueControl.js';
|
|
6
7
|
import { useComposeRefs } from '../hooks/useComposeRefs.js';
|
|
8
|
+
import Option from './Option.js';
|
|
7
9
|
import { SelectControlContext } from './SelectControlContext.js';
|
|
8
|
-
import { useSelectValueControl } from '../Form/useSelectValueControl.js';
|
|
9
|
-
import { useClickAway } from '../hooks/useClickAway.js';
|
|
10
10
|
import SelectTrigger from './SelectTrigger.js';
|
|
11
11
|
import { FormControlContext } from '../Form/FormControlContext.js';
|
|
12
|
-
import
|
|
13
|
-
import Menu from '../Menu/Menu.js';
|
|
12
|
+
import Dropdown from '../Dropdown/Dropdown.js';
|
|
14
13
|
import cx from 'clsx';
|
|
15
14
|
|
|
16
|
-
const MENU_ID = 'mzn-select-menu-id';
|
|
17
15
|
const Select = forwardRef(function Select(props, ref) {
|
|
18
|
-
var _a, _b;
|
|
19
16
|
const { disabled: disabledFromFormControl, fullWidth: fullWidthFromFormControl, required: requiredFromFormControl, severity, } = useContext(FormControlContext) || {};
|
|
20
|
-
const { children, className, clearable = false, defaultValue, disabled = disabledFromFormControl || false, disablePortal = false, error = severity === 'error' || false, fullWidth = fullWidthFromFormControl || false, inputProps, inputRef,
|
|
17
|
+
const { children, className, clearable = false, defaultValue, disabled = disabledFromFormControl || false, disablePortal = false, error = severity === 'error' || false, fullWidth = fullWidthFromFormControl || false, inputProps, inputRef, menuMaxHeight, mode = 'single', onBlur, onChange: onChangeProp, onClear: onClearProp, onFocus, onScroll, options: optionsProp, placeholder = '', prefix, readOnly = false, renderValue, required = requiredFromFormControl || false, size, suffixActionIcon, type = 'default', value: valueProp, } = props;
|
|
21
18
|
const [open, toggleOpen] = useState(false);
|
|
22
|
-
const onOpen = () => {
|
|
19
|
+
const onOpen = useCallback(() => {
|
|
20
|
+
// Prevent opening when readOnly is true
|
|
21
|
+
if (readOnly) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
23
24
|
onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
24
25
|
toggleOpen(true);
|
|
25
|
-
};
|
|
26
|
-
const onClose = () => {
|
|
26
|
+
}, [onFocus, readOnly]);
|
|
27
|
+
const onClose = useCallback(() => {
|
|
27
28
|
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
28
29
|
toggleOpen(false);
|
|
29
|
-
};
|
|
30
|
-
const
|
|
31
|
-
if (open) {
|
|
32
|
-
onClose();
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
onOpen();
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
const { onChange, onClear, value } = useSelectValueControl({
|
|
30
|
+
}, [onBlur]);
|
|
31
|
+
const { onChange, onClear: onClearFromControl, value } = useSelectValueControl({
|
|
39
32
|
defaultValue,
|
|
40
33
|
mode,
|
|
41
34
|
onChange: onChangeProp,
|
|
@@ -43,9 +36,99 @@ const Select = forwardRef(function Select(props, ref) {
|
|
|
43
36
|
onClose,
|
|
44
37
|
value: valueProp,
|
|
45
38
|
});
|
|
39
|
+
// Wrap onClear and delegate to control hook
|
|
40
|
+
const onClear = useCallback((e) => {
|
|
41
|
+
onClearFromControl(e);
|
|
42
|
+
}, [onClearFromControl]);
|
|
46
43
|
const nodeRef = useRef(null);
|
|
47
|
-
const
|
|
48
|
-
|
|
44
|
+
const composedRef = useComposeRefs([ref, nodeRef]);
|
|
45
|
+
// Helper function to recursively add checkbox to all options in tree structure
|
|
46
|
+
const addCheckboxToTreeOptions = useCallback((opts) => {
|
|
47
|
+
return opts.map((opt) => ({
|
|
48
|
+
...opt,
|
|
49
|
+
showCheckbox: true,
|
|
50
|
+
checkSite: 'prefix',
|
|
51
|
+
children: opt.children
|
|
52
|
+
? addCheckboxToTreeOptions(opt.children)
|
|
53
|
+
: undefined,
|
|
54
|
+
}));
|
|
55
|
+
}, []);
|
|
56
|
+
const getAllDescendantIds = useCallback((option) => {
|
|
57
|
+
const ids = new Set();
|
|
58
|
+
const collect = (opt) => {
|
|
59
|
+
ids.add(String(opt.id));
|
|
60
|
+
if (opt.children && opt.children.length > 0) {
|
|
61
|
+
opt.children.forEach(collect);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
collect(option);
|
|
65
|
+
return Array.from(ids);
|
|
66
|
+
}, []);
|
|
67
|
+
const findOptionById = useCallback((id, opts) => {
|
|
68
|
+
for (const opt of opts) {
|
|
69
|
+
if (String(opt.id) === id) {
|
|
70
|
+
return opt;
|
|
71
|
+
}
|
|
72
|
+
if (opt.children) {
|
|
73
|
+
const found = findOptionById(id, opt.children);
|
|
74
|
+
if (found) {
|
|
75
|
+
return found;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}, []);
|
|
81
|
+
// Convert children (Option components) to DropdownOption format
|
|
82
|
+
// Or use provided options directly
|
|
83
|
+
const options = useMemo(() => {
|
|
84
|
+
// If options prop is provided, use it directly
|
|
85
|
+
if (optionsProp) {
|
|
86
|
+
// In tree mode (multiple mode with tree structure), ensure all options have checkbox
|
|
87
|
+
if (mode === 'multiple') {
|
|
88
|
+
const hasTreeStructure = optionsProp.some((opt) => opt.children && opt.children.length > 0);
|
|
89
|
+
if (hasTreeStructure) {
|
|
90
|
+
return addCheckboxToTreeOptions(optionsProp);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return optionsProp;
|
|
94
|
+
}
|
|
95
|
+
// Otherwise, convert children to options
|
|
96
|
+
if (!children)
|
|
97
|
+
return [];
|
|
98
|
+
return Children.toArray(children)
|
|
99
|
+
.filter((child) => {
|
|
100
|
+
var _a;
|
|
101
|
+
return (React.isValidElement(child) &&
|
|
102
|
+
(child.type === Option || ((_a = child.type) === null || _a === void 0 ? void 0 : _a.displayName) === 'Option'));
|
|
103
|
+
})
|
|
104
|
+
.map((child) => {
|
|
105
|
+
const props = child.props;
|
|
106
|
+
return {
|
|
107
|
+
id: props.value,
|
|
108
|
+
name: props.children,
|
|
109
|
+
showCheckbox: mode === 'multiple',
|
|
110
|
+
checkSite: mode === 'multiple' ? 'prefix' : 'suffix',
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}, [children, mode, optionsProp, addCheckboxToTreeOptions]);
|
|
114
|
+
// Determine dropdown type based on options structure and mode
|
|
115
|
+
// Tree mode is only available in multiple mode
|
|
116
|
+
const dropdownType = useMemo(() => {
|
|
117
|
+
if (optionsProp && mode === 'multiple') {
|
|
118
|
+
// If options prop is provided and mode is multiple, check if it has tree structure
|
|
119
|
+
const hasTreeStructure = optionsProp.some((opt) => opt.children && opt.children.length > 0);
|
|
120
|
+
return hasTreeStructure ? 'tree' : type;
|
|
121
|
+
}
|
|
122
|
+
return type;
|
|
123
|
+
}, [optionsProp, type, mode]);
|
|
124
|
+
const dropdownValue = useMemo(() => {
|
|
125
|
+
if (!value)
|
|
126
|
+
return undefined;
|
|
127
|
+
if (Array.isArray(value)) {
|
|
128
|
+
return value.map((v) => String(v.id));
|
|
129
|
+
}
|
|
130
|
+
return String(value.id);
|
|
131
|
+
}, [value]);
|
|
49
132
|
function getPlaceholder() {
|
|
50
133
|
if (typeof renderValue === 'function') {
|
|
51
134
|
return renderValue(value);
|
|
@@ -55,23 +138,15 @@ const Select = forwardRef(function Select(props, ref) {
|
|
|
55
138
|
}
|
|
56
139
|
return placeholder;
|
|
57
140
|
}
|
|
58
|
-
useClickAway(() => {
|
|
59
|
-
if (!open)
|
|
60
|
-
return;
|
|
61
|
-
return () => {
|
|
62
|
-
onClose();
|
|
63
|
-
};
|
|
64
|
-
}, nodeRef, [nodeRef, open, toggleOpen]);
|
|
65
|
-
const onClickTextField = () => {
|
|
66
|
-
if (!disabled) {
|
|
67
|
-
onToggleOpen();
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
141
|
/**
|
|
71
142
|
* keyboard events for a11y
|
|
72
143
|
* (@todo keyboard event map into option selection when menu is opened)
|
|
73
144
|
*/
|
|
74
145
|
const onKeyDownTextField = (evt) => {
|
|
146
|
+
// Prevent keyboard events from opening when readOnly is true
|
|
147
|
+
if (readOnly) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
75
150
|
/** for a11y to open menu via keyboard */
|
|
76
151
|
switch (evt.code) {
|
|
77
152
|
case 'Enter':
|
|
@@ -94,23 +169,62 @@ const Select = forwardRef(function Select(props, ref) {
|
|
|
94
169
|
}
|
|
95
170
|
}
|
|
96
171
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
172
|
+
const handleDropdownSelect = useCallback((option) => {
|
|
173
|
+
if (mode === 'multiple' && dropdownType === 'tree') {
|
|
174
|
+
const onChangeMultiple = onChange;
|
|
175
|
+
const currentValues = Array.isArray(value) ? value : [];
|
|
176
|
+
const allDescendantIds = getAllDescendantIds(option);
|
|
177
|
+
const allDescendantValues = allDescendantIds.map((id) => {
|
|
178
|
+
const foundOption = findOptionById(id, options);
|
|
179
|
+
return {
|
|
180
|
+
id,
|
|
181
|
+
name: (foundOption === null || foundOption === void 0 ? void 0 : foundOption.name) || id,
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
const selectedDescendantIds = allDescendantIds.filter((id) => currentValues.some((v) => String(v.id) === id));
|
|
185
|
+
const allSelected = selectedDescendantIds.length === allDescendantIds.length;
|
|
186
|
+
if (allSelected) {
|
|
187
|
+
// Deselect all descendants in a single update
|
|
188
|
+
const descendantIdSet = new Set(allDescendantIds.map((id) => String(id)));
|
|
189
|
+
const nextValues = currentValues.filter((v) => !descendantIdSet.has(String(v.id)));
|
|
190
|
+
onChangeMultiple(nextValues);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
// Select all descendants that are not yet selected in a single update
|
|
194
|
+
const existingIdSet = new Set(currentValues.map((v) => String(v.id)));
|
|
195
|
+
const valuesToAdd = allDescendantValues.filter((descValue) => !existingIdSet.has(String(descValue.id)));
|
|
196
|
+
const nextValues = [...currentValues, ...valuesToAdd];
|
|
197
|
+
onChangeMultiple(nextValues);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
// Normal selection logic for non-tree mode
|
|
202
|
+
const selectValue = {
|
|
203
|
+
id: String(option.id),
|
|
204
|
+
name: String(option.name),
|
|
205
|
+
};
|
|
206
|
+
if (mode === 'multiple') {
|
|
207
|
+
onChange(selectValue);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
onChange(selectValue);
|
|
211
|
+
onClose();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}, [mode, onChange, onClose, value, dropdownType, getAllDescendantIds, findOptionById, options]);
|
|
215
|
+
const handleVisibilityChange = useCallback((isOpen) => {
|
|
216
|
+
if (isOpen && readOnly) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (isOpen) {
|
|
220
|
+
onOpen();
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
onClose();
|
|
107
224
|
}
|
|
108
|
-
}, [
|
|
225
|
+
}, [onOpen, onClose, readOnly]);
|
|
109
226
|
const resolvedInputProps = {
|
|
110
227
|
...inputProps,
|
|
111
|
-
'aria-controls': MENU_ID,
|
|
112
|
-
'aria-expanded': open,
|
|
113
|
-
'aria-owns': MENU_ID,
|
|
114
228
|
placeholder: getPlaceholder(),
|
|
115
229
|
role: 'combobox',
|
|
116
230
|
};
|
|
@@ -118,7 +232,7 @@ const Select = forwardRef(function Select(props, ref) {
|
|
|
118
232
|
onChange,
|
|
119
233
|
value,
|
|
120
234
|
}), [onChange, value]);
|
|
121
|
-
return (jsx(SelectControlContext.Provider, { value: context, children:
|
|
235
|
+
return (jsx(SelectControlContext.Provider, { value: context, children: jsx("div", { ref: nodeRef, className: cx(selectClasses.host, fullWidth && selectClasses.hostFullWidth), children: jsx(Dropdown, { disabled: readOnly || disabled, disablePortal: disablePortal, maxHeight: menuMaxHeight, mode: mode, onScroll: onScroll, onSelect: handleDropdownSelect, onVisibilityChange: handleVisibilityChange, open: readOnly ? false : open, options: options, sameWidth: true, type: dropdownType, value: dropdownValue, children: jsx(SelectTrigger, { ref: composedRef, active: !readOnly && open, className: className, clearable: clearable, disabled: disabled, error: error, fullWidth: fullWidth, inputRef: inputRef, mode: mode, onTagClose: onChange, onClear: onClear, onKeyDown: onKeyDownTextField, prefix: prefix, readOnly: readOnly, ...(mode === 'single' && renderValue ? { renderValue } : {}), required: required, inputProps: resolvedInputProps, size: size, suffixActionIcon: suffixActionIcon, value: value === null ? undefined : value }) }) }) }));
|
|
122
236
|
});
|
|
123
237
|
|
|
124
238
|
export { Select as default };
|
package/Select/index.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { default as OptionGroup } from '../Menu/MenuItemGroup';
|
|
2
|
+
export type { MenuItemGroupProps as OptionGroupProps } from '../Menu/MenuItemGroup';
|
|
3
|
+
export { default as Option } from './Option';
|
|
4
|
+
export type { OptionProps } from './Option';
|
|
5
|
+
export { default } from './Select';
|
|
6
|
+
export type { SelectProps } from './Select';
|
|
2
7
|
export { SelectControlContext } from './SelectControlContext';
|
|
3
8
|
export { default as SelectTrigger } from './SelectTrigger';
|
|
4
|
-
export type { SelectTriggerProps, SelectTriggerInputProps, } from './SelectTrigger';
|
|
5
9
|
export { default as SelectTriggerTags } from './SelectTriggerTags';
|
|
6
10
|
export type { SelectTriggerTagsProps } from './SelectTriggerTags';
|
|
7
|
-
export type { SelectProps } from './Select';
|
|
8
|
-
export { default } from './Select';
|
|
9
|
-
export { default as Option } from './Option';
|
|
10
|
-
export type { OptionProps } from './Option';
|
|
11
|
-
export { default as OptionGroup } from '../Menu/MenuItemGroup';
|
|
12
|
-
export type { MenuItemGroupProps as OptionGroupProps } from '../Menu/MenuItemGroup';
|
|
13
|
-
export type { TreeSelectProps } from './TreeSelect';
|
|
14
11
|
export { default as TreeSelect } from './TreeSelect';
|
|
12
|
+
export type { TreeSelectProps } from './TreeSelect';
|
|
13
|
+
export * from './typings';
|
package/Select/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
export { default as OptionGroup } from '../Menu/MenuItemGroup.js';
|
|
2
|
+
export { default as Option } from './Option.js';
|
|
3
|
+
export { default } from './Select.js';
|
|
1
4
|
export { SelectControlContext } from './SelectControlContext.js';
|
|
2
5
|
export { default as SelectTrigger } from './SelectTrigger.js';
|
|
3
6
|
export { default as SelectTriggerTags } from './SelectTriggerTags.js';
|
|
4
|
-
export { default } from './Select.js';
|
|
5
|
-
export { default as Option } from './Option.js';
|
|
6
|
-
export { default as OptionGroup } from '../Menu/MenuItemGroup.js';
|
|
7
7
|
export { default as TreeSelect } from './TreeSelect.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mezzanine-ui/react",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
4
|
"description": "React components for mezzanine-ui",
|
|
5
5
|
"author": "Mezzanine",
|
|
6
6
|
"repository": {
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"@floating-ui/dom": "^1.7.4",
|
|
32
32
|
"@floating-ui/react-dom": "^2.1.6",
|
|
33
33
|
"@hello-pangea/dnd": "^18.0.1",
|
|
34
|
-
"@mezzanine-ui/core": "1.0.0-beta.
|
|
35
|
-
"@mezzanine-ui/icons": "1.0.0-beta.
|
|
36
|
-
"@mezzanine-ui/system": "1.0.0-beta.
|
|
34
|
+
"@mezzanine-ui/core": "1.0.0-beta.5",
|
|
35
|
+
"@mezzanine-ui/icons": "1.0.0-beta.5",
|
|
36
|
+
"@mezzanine-ui/system": "1.0.0-beta.5",
|
|
37
37
|
"@tanstack/react-virtual": "^3.13.13",
|
|
38
38
|
"@types/react-transition-group": "^4.4.12",
|
|
39
39
|
"clsx": "^2.1.1",
|