@mezzanine-ui/react 1.0.0-beta.2 → 1.0.0-beta.3
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/Anchor/Anchor.d.ts +51 -18
- package/Anchor/Anchor.js +15 -15
- package/Anchor/AnchorGroup.d.ts +34 -0
- package/Anchor/AnchorGroup.js +37 -0
- package/Anchor/AnchorItem.d.ts +30 -0
- package/Anchor/AnchorItem.js +65 -0
- package/Anchor/index.d.ts +2 -0
- package/Anchor/index.js +1 -0
- package/Anchor/utils.d.ts +13 -0
- package/Anchor/utils.js +95 -0
- package/AutoComplete/AutoComplete.d.ts +194 -0
- package/AutoComplete/AutoComplete.js +419 -0
- package/AutoComplete/index.d.ts +2 -0
- package/AutoComplete/index.js +1 -0
- package/AutoComplete/useAutoCompleteCreation.d.ts +33 -0
- package/AutoComplete/useAutoCompleteCreation.js +201 -0
- package/AutoComplete/useAutoCompleteKeyboard.d.ts +31 -0
- package/AutoComplete/useAutoCompleteKeyboard.js +149 -0
- package/AutoComplete/useAutoCompleteSearch.d.ts +16 -0
- package/AutoComplete/useAutoCompleteSearch.js +69 -0
- package/AutoComplete/useCreationTracker.d.ts +17 -0
- package/AutoComplete/useCreationTracker.js +47 -0
- package/Button/Button.js +13 -11
- package/Button/index.d.ts +1 -1
- package/Button/typings.d.ts +27 -4
- package/Description/Description.d.ts +12 -22
- package/Description/Description.js +4 -24
- package/Dropdown/Dropdown.d.ts +29 -1
- package/Dropdown/Dropdown.js +95 -14
- package/Dropdown/DropdownAction.d.ts +1 -1
- package/Dropdown/DropdownAction.js +1 -4
- package/Dropdown/DropdownItem.d.ts +18 -1
- package/Dropdown/DropdownItem.js +23 -10
- package/Dropdown/DropdownItemCard.js +11 -10
- package/Dropdown/DropdownStatus.js +29 -0
- package/Dropdown/dropdownKeydownHandler.d.ts +2 -1
- package/Dropdown/dropdownKeydownHandler.js +73 -0
- package/Dropdown/highlightText.js +5 -1
- package/Dropdown/shortcutTextHandler.d.ts +24 -0
- package/Dropdown/shortcutTextHandler.js +171 -0
- package/Form/FormField.js +3 -1
- package/Input/Input.d.ts +29 -3
- package/Input/Input.js +22 -6
- package/Modal/Modal.d.ts +103 -11
- package/Modal/Modal.js +14 -9
- package/Modal/ModalBodyForVerification.d.ts +59 -0
- package/Modal/ModalBodyForVerification.js +99 -0
- package/Modal/ModalControl.d.ts +2 -2
- package/Modal/ModalControl.js +1 -1
- package/Modal/ModalFooter.d.ts +119 -1
- package/Modal/ModalFooter.js +15 -3
- package/Modal/ModalHeader.d.ts +26 -7
- package/Modal/ModalHeader.js +33 -7
- package/Modal/index.d.ts +4 -5
- package/Modal/index.js +1 -2
- package/Modal/useModalContainer.d.ts +12 -3
- package/Modal/useModalContainer.js +28 -6
- package/Navigation/CollapsedMenu.d.ts +6 -0
- package/Navigation/CollapsedMenu.js +16 -0
- package/Navigation/Navigation.d.ts +7 -2
- package/Navigation/Navigation.js +33 -33
- package/Navigation/NavigationHeader.d.ts +4 -0
- package/Navigation/NavigationHeader.js +3 -2
- package/Navigation/NavigationOption.d.ts +2 -1
- package/Navigation/NavigationOption.js +28 -3
- package/Navigation/NavigationOptionCategory.js +1 -0
- package/Navigation/useVisibleItems.d.ts +5 -0
- package/Navigation/useVisibleItems.js +54 -0
- package/NotificationCenter/NotificationCenter.d.ts +124 -0
- package/NotificationCenter/NotificationCenter.js +259 -0
- package/NotificationCenter/NotificationCenterDrawer.d.ts +89 -0
- package/NotificationCenter/index.d.ts +3 -0
- package/NotificationCenter/index.js +1 -0
- package/PageFooter/PageFooter.d.ts +19 -9
- package/PageFooter/PageFooter.js +10 -10
- package/PageHeader/PageHeader.js +4 -12
- package/PageToolbar/PageToolbar.d.ts +2 -6
- package/PageToolbar/utils.js +4 -12
- package/Select/index.d.ts +0 -2
- package/Select/index.js +0 -1
- package/Slider/useSlider.js +1 -1
- package/Table/components/TableActionsCell.js +2 -2
- package/Table/components/TableBulkActions.js +1 -19
- package/Table/components/TableRow.js +2 -2
- package/Table/hooks/useTableFixedOffsets.js +6 -6
- package/Table/utils/useTableRowSelection.js +13 -5
- package/Tag/TagGroup.d.ts +3 -0
- package/Tag/index.d.ts +2 -0
- package/Tag/index.js +1 -0
- package/Upload/UploadPictureCard.js +1 -1
- package/index.d.ts +34 -20
- package/index.js +19 -8
- package/package.json +4 -4
- package/Modal/ModalActions.d.ts +0 -9
- package/Modal/ModalActions.js +0 -20
- package/Modal/ModalBody.d.ts +0 -7
- package/Modal/ModalBody.js +0 -14
- package/Notification/Notification.d.ts +0 -54
- package/Notification/Notification.js +0 -76
- package/Notification/index.d.ts +0 -3
- package/Notification/index.js +0 -1
- package/Select/AutoComplete.d.ts +0 -107
- package/Select/AutoComplete.js +0 -114
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Dispatch, KeyboardEvent, KeyboardEventHandler, Ref, SetStateAction } from 'react';
|
|
2
|
+
import { DropdownOption } from '@mezzanine-ui/core/dropdown/dropdown';
|
|
3
|
+
import { SelectValue } from '../Select/typings';
|
|
4
|
+
type UseAutoCompleteKeyboardParams = {
|
|
5
|
+
activeIndex: number | null;
|
|
6
|
+
addable: boolean;
|
|
7
|
+
createSeparators: string[];
|
|
8
|
+
dropdownOptions: DropdownOption[];
|
|
9
|
+
handleBulkCreate: (texts: string[]) => void;
|
|
10
|
+
handleDropdownSelect: (option: DropdownOption) => void;
|
|
11
|
+
inputRef?: Ref<HTMLInputElement>;
|
|
12
|
+
inputPropsOnKeyDown?: KeyboardEventHandler<HTMLInputElement>;
|
|
13
|
+
isMultiple: boolean;
|
|
14
|
+
mode: 'single' | 'multiple';
|
|
15
|
+
onFocus: (focus: boolean) => void;
|
|
16
|
+
open: boolean;
|
|
17
|
+
processBulkCreate: (text: string) => string[];
|
|
18
|
+
searchText: string;
|
|
19
|
+
searchTextExistWithoutOption: boolean;
|
|
20
|
+
setActiveIndex: Dispatch<SetStateAction<number | null>>;
|
|
21
|
+
setListboxHasVisualFocus: (focus: boolean) => void;
|
|
22
|
+
setInsertText: (value: string) => void;
|
|
23
|
+
setSearchText: (value: string) => void;
|
|
24
|
+
toggleOpen: (newOpen: boolean | ((prev: boolean) => boolean)) => void;
|
|
25
|
+
value: SelectValue[] | SelectValue | null | undefined;
|
|
26
|
+
wrappedOnChange: (chooseOption: SelectValue | null) => SelectValue[] | SelectValue | null;
|
|
27
|
+
};
|
|
28
|
+
export declare function useAutoCompleteKeyboard({ activeIndex, addable, createSeparators, dropdownOptions, handleBulkCreate, handleDropdownSelect, inputPropsOnKeyDown, inputRef, mode, onFocus, open, processBulkCreate, searchText, searchTextExistWithoutOption, setActiveIndex, setInsertText, setListboxHasVisualFocus, setSearchText, toggleOpen, value, wrappedOnChange, }: UseAutoCompleteKeyboardParams): {
|
|
29
|
+
handleInputKeyDown: (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { createDropdownKeydownHandler } from '../Dropdown/dropdownKeydownHandler.js';
|
|
3
|
+
|
|
4
|
+
function isMultipleValue(value) {
|
|
5
|
+
return Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
function useAutoCompleteKeyboard({ activeIndex, addable, createSeparators, dropdownOptions, handleBulkCreate, handleDropdownSelect, inputPropsOnKeyDown, inputRef, mode, onFocus, open, processBulkCreate, searchText, searchTextExistWithoutOption, setActiveIndex, setInsertText, setListboxHasVisualFocus, setSearchText, toggleOpen, value, wrappedOnChange, }) {
|
|
8
|
+
const handleKeyDown = useCallback((e) => createDropdownKeydownHandler({
|
|
9
|
+
activeIndex,
|
|
10
|
+
onEnterSelect: (option) => {
|
|
11
|
+
handleDropdownSelect(option);
|
|
12
|
+
if (mode === 'single') {
|
|
13
|
+
toggleOpen(false);
|
|
14
|
+
onFocus(false);
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
onEscape: () => {
|
|
18
|
+
var _a;
|
|
19
|
+
toggleOpen(false);
|
|
20
|
+
setActiveIndex(null);
|
|
21
|
+
setListboxHasVisualFocus(false);
|
|
22
|
+
if (inputRef && typeof inputRef !== 'function') {
|
|
23
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
open,
|
|
27
|
+
options: dropdownOptions,
|
|
28
|
+
setActiveIndex,
|
|
29
|
+
setListboxHasVisualFocus,
|
|
30
|
+
setOpen: (newOpen) => {
|
|
31
|
+
if (newOpen && !open) {
|
|
32
|
+
toggleOpen(true);
|
|
33
|
+
}
|
|
34
|
+
else if (!newOpen && open) {
|
|
35
|
+
toggleOpen(false);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
})(e), [
|
|
39
|
+
activeIndex,
|
|
40
|
+
dropdownOptions,
|
|
41
|
+
handleDropdownSelect,
|
|
42
|
+
inputRef,
|
|
43
|
+
mode,
|
|
44
|
+
onFocus,
|
|
45
|
+
open,
|
|
46
|
+
setActiveIndex,
|
|
47
|
+
setListboxHasVisualFocus,
|
|
48
|
+
toggleOpen,
|
|
49
|
+
]);
|
|
50
|
+
const handleEnterKey = useCallback((e) => {
|
|
51
|
+
if (e.key === 'Enter' && open) {
|
|
52
|
+
if (addable && searchText) {
|
|
53
|
+
const hasSeparator = createSeparators.some((sep) => searchText.includes(sep));
|
|
54
|
+
if (hasSeparator && mode === 'multiple') {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
e.stopPropagation();
|
|
57
|
+
const textsToCreate = processBulkCreate(searchText);
|
|
58
|
+
if (textsToCreate.length > 0) {
|
|
59
|
+
handleBulkCreate(textsToCreate);
|
|
60
|
+
setSearchText('');
|
|
61
|
+
setInsertText('');
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!hasSeparator && searchTextExistWithoutOption) {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
e.stopPropagation();
|
|
68
|
+
const textsToCreate = processBulkCreate(searchText);
|
|
69
|
+
if (textsToCreate.length > 0) {
|
|
70
|
+
handleBulkCreate(textsToCreate);
|
|
71
|
+
setSearchText('');
|
|
72
|
+
setInsertText('');
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (activeIndex === null && dropdownOptions.length > 0) {
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
e.stopPropagation();
|
|
80
|
+
const optionToSelect = dropdownOptions[0];
|
|
81
|
+
if (optionToSelect) {
|
|
82
|
+
handleDropdownSelect(optionToSelect);
|
|
83
|
+
if (mode === 'single') {
|
|
84
|
+
toggleOpen(false);
|
|
85
|
+
onFocus(false);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}, [
|
|
93
|
+
activeIndex,
|
|
94
|
+
addable,
|
|
95
|
+
createSeparators,
|
|
96
|
+
dropdownOptions,
|
|
97
|
+
handleBulkCreate,
|
|
98
|
+
handleDropdownSelect,
|
|
99
|
+
mode,
|
|
100
|
+
onFocus,
|
|
101
|
+
open,
|
|
102
|
+
processBulkCreate,
|
|
103
|
+
searchText,
|
|
104
|
+
searchTextExistWithoutOption,
|
|
105
|
+
setInsertText,
|
|
106
|
+
setSearchText,
|
|
107
|
+
toggleOpen,
|
|
108
|
+
]);
|
|
109
|
+
const handleInputKeyDown = useCallback((e) => {
|
|
110
|
+
if (handleEnterKey(e))
|
|
111
|
+
return;
|
|
112
|
+
if (mode === 'multiple' &&
|
|
113
|
+
isMultipleValue(value) &&
|
|
114
|
+
value.length > 0 &&
|
|
115
|
+
!searchText) {
|
|
116
|
+
if (e.key === 'Backspace') {
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
const lastValue = value[value.length - 1];
|
|
119
|
+
if (lastValue) {
|
|
120
|
+
wrappedOnChange(lastValue);
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (e.key === 'Delete') {
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
const firstValue = value[0];
|
|
127
|
+
if (firstValue) {
|
|
128
|
+
wrappedOnChange(firstValue);
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
handleKeyDown(e);
|
|
134
|
+
inputPropsOnKeyDown === null || inputPropsOnKeyDown === void 0 ? void 0 : inputPropsOnKeyDown(e);
|
|
135
|
+
}, [
|
|
136
|
+
handleEnterKey,
|
|
137
|
+
handleKeyDown,
|
|
138
|
+
inputPropsOnKeyDown,
|
|
139
|
+
mode,
|
|
140
|
+
searchText,
|
|
141
|
+
value,
|
|
142
|
+
wrappedOnChange,
|
|
143
|
+
]);
|
|
144
|
+
return {
|
|
145
|
+
handleInputKeyDown,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export { useAutoCompleteKeyboard };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type UseAutoCompleteSearchParams = {
|
|
2
|
+
asyncData: boolean;
|
|
3
|
+
loading: boolean;
|
|
4
|
+
onSearch?: (input: string) => void | Promise<void>;
|
|
5
|
+
searchDebounceTime: number;
|
|
6
|
+
};
|
|
7
|
+
type RunSearchOptions = {
|
|
8
|
+
immediate?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function useAutoCompleteSearch({ asyncData, loading, onSearch, searchDebounceTime, }: UseAutoCompleteSearchParams): {
|
|
11
|
+
cancelSearch: () => void;
|
|
12
|
+
internalLoading: boolean;
|
|
13
|
+
isLoading: boolean;
|
|
14
|
+
runSearch: (searchValue: string, options?: RunSearchOptions) => void;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import debounce from 'lodash/debounce';
|
|
2
|
+
import { useState, useRef, useCallback, useMemo, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
function useAutoCompleteSearch({ asyncData, loading, onSearch, searchDebounceTime, }) {
|
|
5
|
+
const [internalLoading, setInternalLoading] = useState(false);
|
|
6
|
+
const requestSeqRef = useRef(0);
|
|
7
|
+
const executeSearch = useCallback((searchValue) => {
|
|
8
|
+
if (!onSearch) {
|
|
9
|
+
if (asyncData)
|
|
10
|
+
setInternalLoading(false);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (!asyncData) {
|
|
14
|
+
onSearch(searchValue);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const currentSeq = requestSeqRef.current + 1;
|
|
18
|
+
requestSeqRef.current = currentSeq;
|
|
19
|
+
setInternalLoading(true);
|
|
20
|
+
try {
|
|
21
|
+
const result = onSearch(searchValue);
|
|
22
|
+
const finalize = () => {
|
|
23
|
+
if (requestSeqRef.current === currentSeq) {
|
|
24
|
+
setInternalLoading(false);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
if (result instanceof Promise) {
|
|
28
|
+
result.finally(finalize);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
finalize();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
// Handle synchronous errors that occur before Promise creation
|
|
36
|
+
// Reset loading state to prevent UI from being stuck in loading state
|
|
37
|
+
if (requestSeqRef.current === currentSeq) {
|
|
38
|
+
setInternalLoading(false);
|
|
39
|
+
}
|
|
40
|
+
// Re-throw error to allow calling code to handle it
|
|
41
|
+
// This is necessary because the error occurred synchronously and the caller
|
|
42
|
+
// should be aware of it (e.g., for error logging or user notification)
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}, [asyncData, onSearch]);
|
|
46
|
+
const debouncedSearch = useMemo(() => debounce((value) => executeSearch(value), searchDebounceTime), [executeSearch, searchDebounceTime]);
|
|
47
|
+
useEffect(() => () => debouncedSearch.cancel(), [debouncedSearch]);
|
|
48
|
+
const runSearch = useCallback((searchValue, options) => {
|
|
49
|
+
if (options === null || options === void 0 ? void 0 : options.immediate) {
|
|
50
|
+
debouncedSearch.cancel();
|
|
51
|
+
executeSearch(searchValue);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!searchValue) {
|
|
55
|
+
debouncedSearch.cancel();
|
|
56
|
+
executeSearch(searchValue);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
debouncedSearch(searchValue);
|
|
60
|
+
}, [debouncedSearch, executeSearch]);
|
|
61
|
+
return {
|
|
62
|
+
cancelSearch: debouncedSearch.cancel,
|
|
63
|
+
internalLoading,
|
|
64
|
+
isLoading: asyncData ? internalLoading || loading : loading,
|
|
65
|
+
runSearch,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { useAutoCompleteSearch };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SelectValue } from '../Select/typings';
|
|
2
|
+
type CreationTracker = {
|
|
3
|
+
newlyCreatedIds: Set<string>;
|
|
4
|
+
unselectedCreatedIds: Set<string>;
|
|
5
|
+
allCreatedIds: Set<string>;
|
|
6
|
+
};
|
|
7
|
+
export declare function useCreationTracker(): {
|
|
8
|
+
creationTrackerRef: import("react").RefObject<CreationTracker>;
|
|
9
|
+
filterUnselected: (options: SelectValue[]) => SelectValue<string>[];
|
|
10
|
+
clearUnselected: () => void;
|
|
11
|
+
markCreated: (id: string) => void;
|
|
12
|
+
clearNewlyCreated: (ids?: string[]) => void;
|
|
13
|
+
markUnselected: (ids: string[]) => void;
|
|
14
|
+
isNewlyCreated: (id: string) => boolean;
|
|
15
|
+
isCreated: (id: string) => boolean;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useRef, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
function useCreationTracker() {
|
|
4
|
+
const creationTrackerRef = useRef({
|
|
5
|
+
newlyCreatedIds: new Set(),
|
|
6
|
+
unselectedCreatedIds: new Set(),
|
|
7
|
+
allCreatedIds: new Set(),
|
|
8
|
+
});
|
|
9
|
+
const filterUnselected = useCallback((options) => options.filter((opt) => !creationTrackerRef.current.unselectedCreatedIds.has(opt.id)), [creationTrackerRef]);
|
|
10
|
+
const clearUnselected = useCallback(() => {
|
|
11
|
+
creationTrackerRef.current.unselectedCreatedIds.clear();
|
|
12
|
+
}, []);
|
|
13
|
+
const clearNewlyCreated = useCallback((ids) => {
|
|
14
|
+
if (!ids) {
|
|
15
|
+
creationTrackerRef.current.newlyCreatedIds.clear();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
ids.forEach((id) => {
|
|
19
|
+
creationTrackerRef.current.newlyCreatedIds.delete(id);
|
|
20
|
+
});
|
|
21
|
+
}, []);
|
|
22
|
+
const markCreated = useCallback((id) => {
|
|
23
|
+
creationTrackerRef.current.newlyCreatedIds.add(id);
|
|
24
|
+
creationTrackerRef.current.allCreatedIds.add(id);
|
|
25
|
+
}, []);
|
|
26
|
+
const markUnselected = useCallback((ids) => {
|
|
27
|
+
ids.forEach((id) => {
|
|
28
|
+
if (creationTrackerRef.current.allCreatedIds.has(id)) {
|
|
29
|
+
creationTrackerRef.current.unselectedCreatedIds.add(id);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}, []);
|
|
33
|
+
const isNewlyCreated = useCallback((id) => creationTrackerRef.current.newlyCreatedIds.has(id), []);
|
|
34
|
+
const isCreated = useCallback((id) => creationTrackerRef.current.allCreatedIds.has(id), []);
|
|
35
|
+
return {
|
|
36
|
+
creationTrackerRef,
|
|
37
|
+
filterUnselected,
|
|
38
|
+
clearUnselected,
|
|
39
|
+
markCreated,
|
|
40
|
+
clearNewlyCreated,
|
|
41
|
+
markUnselected,
|
|
42
|
+
isNewlyCreated,
|
|
43
|
+
isCreated,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { useCreationTracker };
|
package/Button/Button.js
CHANGED
|
@@ -4,18 +4,16 @@ import { forwardRef } from 'react';
|
|
|
4
4
|
import { SpinnerIcon } from '@mezzanine-ui/icons';
|
|
5
5
|
import { buttonClasses } from '@mezzanine-ui/core/button';
|
|
6
6
|
import Icon from '../Icon/Icon.js';
|
|
7
|
+
import Tooltip from '../Tooltip/Tooltip.js';
|
|
7
8
|
import cx from 'clsx';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* The react component for `mezzanine` button.
|
|
11
12
|
*/
|
|
12
13
|
const Button = forwardRef(function Button(props, ref) {
|
|
13
|
-
const { children, className, component: Component = 'button', disabled = false, icon, loading = false, onClick, size = 'main', variant = 'base-primary', ...rest } = props;
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
// 判斷 icon 位置
|
|
17
|
-
const hasLeadingIcon = (icon === null || icon === void 0 ? void 0 : icon.position) === 'leading' && !isIconOnly;
|
|
18
|
-
const hasTrailingIcon = (icon === null || icon === void 0 ? void 0 : icon.position) === 'trailing' && !isIconOnly;
|
|
14
|
+
const { children, className, component: Component = 'button', disabled = false, disabledTooltip = false, icon, iconType, loading = false, onClick, size = 'main', tooltipPosition = 'bottom', variant = 'base-primary', ...rest } = props;
|
|
15
|
+
const isIconOnly = iconType === 'icon-only';
|
|
16
|
+
const showTooltip = isIconOnly && !disabledTooltip && Boolean(children);
|
|
19
17
|
// Loading 狀態下的 icon
|
|
20
18
|
const loadingIcon = jsx(Icon, { icon: SpinnerIcon, spin: true, size: 16 });
|
|
21
19
|
// 渲染 icon 內容
|
|
@@ -24,21 +22,25 @@ const Button = forwardRef(function Button(props, ref) {
|
|
|
24
22
|
return loadingIcon;
|
|
25
23
|
}
|
|
26
24
|
if (icon) {
|
|
27
|
-
return jsx(Icon, { icon: icon
|
|
25
|
+
return jsx(Icon, { icon: icon, size: 16 });
|
|
28
26
|
}
|
|
29
27
|
return null;
|
|
30
28
|
};
|
|
31
|
-
|
|
29
|
+
const buttonElement = (tooltipProps) => (jsx(Component, { ...rest, ref: (tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.ref) || ref, "aria-disabled": disabled, className: cx(buttonClasses.host, buttonClasses.variant(variant), buttonClasses.size(size), {
|
|
32
30
|
[buttonClasses.disabled]: disabled,
|
|
33
31
|
[buttonClasses.loading]: loading,
|
|
34
|
-
[buttonClasses.iconLeading]:
|
|
35
|
-
[buttonClasses.iconTrailing]:
|
|
32
|
+
[buttonClasses.iconLeading]: iconType === 'leading',
|
|
33
|
+
[buttonClasses.iconTrailing]: iconType === 'trailing',
|
|
36
34
|
[buttonClasses.iconOnly]: isIconOnly,
|
|
37
35
|
}, className), disabled: disabled, onClick: (event) => {
|
|
38
36
|
if (!disabled && !loading && onClick) {
|
|
39
37
|
onClick(event);
|
|
40
38
|
}
|
|
41
|
-
}, children: loading ? (renderIcon()) : (jsxs(Fragment, { children: [(
|
|
39
|
+
}, onMouseEnter: tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.onMouseEnter, onMouseLeave: tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.onMouseLeave, children: loading ? (renderIcon()) : (jsxs(Fragment, { children: [(iconType === 'leading' || isIconOnly) && renderIcon(), !isIconOnly && children, iconType === 'trailing' && renderIcon()] })) }));
|
|
40
|
+
if (showTooltip) {
|
|
41
|
+
return (jsx(Tooltip, { options: { placement: tooltipPosition }, title: children, children: (tooltipProps) => buttonElement(tooltipProps) }));
|
|
42
|
+
}
|
|
43
|
+
return buttonElement();
|
|
42
44
|
});
|
|
43
45
|
|
|
44
46
|
export { Button as default };
|
package/Button/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PropsWithoutRef, ReactElement, RefAttributes } from 'react';
|
|
2
2
|
import { ButtonComponent, ButtonPropsBase } from './typings';
|
|
3
3
|
import { ButtonProps } from './Button';
|
|
4
|
-
export type {
|
|
4
|
+
export type { ButtonIconType, ButtonGroupOrientation, ButtonSize, ButtonVariant, } from '@mezzanine-ui/core/button';
|
|
5
5
|
export { default as ButtonGroup } from './ButtonGroup';
|
|
6
6
|
export type { ButtonGroupChild, ButtonGroupProps } from './ButtonGroup';
|
|
7
7
|
export type { ButtonComponent, ButtonProps, ButtonPropsBase };
|
package/Button/typings.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { JSXElementConstructor } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { JSXElementConstructor, ReactNode } from 'react';
|
|
2
|
+
import { IconDefinition } from '@mezzanine-ui/icons';
|
|
3
|
+
import { ButtonIconType, ButtonSize, ButtonVariant } from '@mezzanine-ui/core/button';
|
|
4
|
+
import { PopperPlacement } from '../Popper';
|
|
3
5
|
export type ButtonComponent = 'button' | 'a' | JSXElementConstructor<any>;
|
|
4
6
|
export interface ButtonPropsBase {
|
|
5
7
|
/**
|
|
@@ -23,7 +25,28 @@ export interface ButtonPropsBase {
|
|
|
23
25
|
*/
|
|
24
26
|
loading?: boolean;
|
|
25
27
|
/**
|
|
26
|
-
*
|
|
28
|
+
* The icon to display.
|
|
27
29
|
*/
|
|
28
|
-
icon?:
|
|
30
|
+
icon?: IconDefinition;
|
|
31
|
+
/**
|
|
32
|
+
* The type of the icon relative to the text.
|
|
33
|
+
*/
|
|
34
|
+
iconType?: ButtonIconType;
|
|
35
|
+
/**
|
|
36
|
+
* The button text content.
|
|
37
|
+
* When iconType is 'icon-only', children will be used as tooltip content.
|
|
38
|
+
*/
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
/**
|
|
41
|
+
* If true, disable the tooltip for icon-only buttons.
|
|
42
|
+
* Only applies when iconType is 'icon-only'.
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
disabledTooltip?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The position of the tooltip.
|
|
48
|
+
* Only applies when iconType is 'icon-only'.
|
|
49
|
+
* @default 'bottom'
|
|
50
|
+
*/
|
|
51
|
+
tooltipPosition?: PopperPlacement;
|
|
29
52
|
}
|
|
@@ -1,40 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { DescriptionOrientation } from '@mezzanine-ui/core/description';
|
|
2
3
|
import { DescriptionTitleProps } from './DescriptionTitle';
|
|
3
4
|
import { DescriptionContentProps } from './DescriptionContent';
|
|
4
5
|
import { BadgeProps } from '../Badge/typings';
|
|
5
6
|
import { ButtonProps } from '../Button';
|
|
6
7
|
import { ProgressProps } from '../Progress';
|
|
7
|
-
import {
|
|
8
|
-
|
|
8
|
+
import { TagGroupProps } from '../Tag/TagGroup';
|
|
9
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends any ? Omit<T, K> : never;
|
|
10
|
+
export type DescriptionProps = DistributiveOmit<DescriptionTitleProps, 'className' | 'children'> & {
|
|
9
11
|
/**
|
|
10
|
-
*
|
|
12
|
+
* Defines what is rendered as the description content
|
|
11
13
|
*/
|
|
12
|
-
|
|
14
|
+
children: ReactElement<DescriptionContentProps> | ReactElement<BadgeProps> | ReactElement<ButtonProps> | ReactElement<ProgressProps> | ReactElement<TagGroupProps>;
|
|
13
15
|
/**
|
|
14
|
-
*
|
|
16
|
+
* Custom class name for description
|
|
15
17
|
*/
|
|
16
|
-
|
|
17
|
-
variant: Extract<DescriptionContentVariant, 'badge'>;
|
|
18
|
-
badge: BadgeProps;
|
|
19
|
-
} | {
|
|
20
|
-
variant: Extract<DescriptionContentVariant, 'button'>;
|
|
21
|
-
button: ButtonProps;
|
|
22
|
-
} | {
|
|
23
|
-
variant: Extract<DescriptionContentVariant, 'progress'>;
|
|
24
|
-
progress: ProgressProps;
|
|
25
|
-
} | {
|
|
26
|
-
variant: Extract<DescriptionContentVariant, 'tags'>;
|
|
27
|
-
tags: TagProps[];
|
|
28
|
-
};
|
|
18
|
+
className?: string;
|
|
29
19
|
/**
|
|
30
20
|
* Define the layout direction between the title and the content
|
|
31
21
|
* @default 'horizontal'
|
|
32
22
|
*/
|
|
33
23
|
orientation?: DescriptionOrientation;
|
|
34
24
|
/**
|
|
35
|
-
*
|
|
25
|
+
* title text for description
|
|
36
26
|
*/
|
|
37
|
-
|
|
38
|
-
}
|
|
27
|
+
title: string;
|
|
28
|
+
};
|
|
39
29
|
declare const Description: import("react").ForwardRefExoticComponent<DescriptionProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
40
30
|
export default Description;
|
|
@@ -1,33 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
3
|
-
import { forwardRef
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
4
|
import { descriptionClasses } from '@mezzanine-ui/core/description';
|
|
5
5
|
import DescriptionTitle from './DescriptionTitle.js';
|
|
6
|
-
import DescriptionContent from './DescriptionContent.js';
|
|
7
|
-
import Button from '../Button/Button.js';
|
|
8
|
-
import TagGroup from '../Tag/TagGroup.js';
|
|
9
|
-
import Tag from '../Tag/Tag.js';
|
|
10
|
-
import Progress from '../Progress/Progress.js';
|
|
11
|
-
import Badge from '../Badge/Badge.js';
|
|
12
6
|
import cx from 'clsx';
|
|
13
7
|
|
|
14
8
|
const Description = forwardRef(function Description(props, ref) {
|
|
15
|
-
const {
|
|
16
|
-
|
|
17
|
-
switch (contentProps.variant) {
|
|
18
|
-
case 'badge':
|
|
19
|
-
return jsx(Badge, { ...contentProps.badge });
|
|
20
|
-
case 'button':
|
|
21
|
-
return jsx(Button, { ...contentProps.button });
|
|
22
|
-
case 'progress':
|
|
23
|
-
return jsx(Progress, { ...contentProps.progress });
|
|
24
|
-
case 'tags':
|
|
25
|
-
return (jsx(TagGroup, { children: contentProps.tags.map((tagProps, index) => (jsx(Tag, { ...tagProps }, `${tagProps.label}-${index}`))) }));
|
|
26
|
-
default:
|
|
27
|
-
return jsx(DescriptionContent, { ...contentProps });
|
|
28
|
-
}
|
|
29
|
-
}, [contentProps]);
|
|
30
|
-
return (jsxs("div", { className: cx(descriptionClasses.host, descriptionClasses.orientation(orientation), className), ref: ref, children: [jsx(DescriptionTitle, { ...titleProps }), contentComponent] }));
|
|
9
|
+
const { children, className, orientation = 'horizontal', title, ...rest } = props;
|
|
10
|
+
return (jsxs("div", { className: cx(descriptionClasses.host, descriptionClasses.orientation(orientation), className), ref: ref, children: [jsx(DescriptionTitle, { ...rest, children: title }), children] }));
|
|
31
11
|
});
|
|
32
12
|
|
|
33
13
|
export { Description as default };
|
package/Dropdown/Dropdown.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { DropdownInputPosition, DropdownItemSharedProps, DropdownOption, DropdownType } from '@mezzanine-ui/core/dropdown/dropdown';
|
|
2
|
+
import { DropdownInputPosition, DropdownItemSharedProps, DropdownOption, DropdownStatus as DropdownStatusType, DropdownType } from '@mezzanine-ui/core/dropdown/dropdown';
|
|
3
3
|
import { ButtonProps } from '../Button';
|
|
4
4
|
import { InputProps } from '../Input';
|
|
5
5
|
import { PopperPlacement } from '../Popper';
|
|
6
|
+
import { IconDefinition } from '@mezzanine-ui/icons';
|
|
6
7
|
export interface DropdownProps extends DropdownItemSharedProps {
|
|
7
8
|
/**
|
|
8
9
|
* The text of the cancel button.
|
|
@@ -51,6 +52,11 @@ export interface DropdownProps extends DropdownItemSharedProps {
|
|
|
51
52
|
* @default false
|
|
52
53
|
*/
|
|
53
54
|
isMatchInputValue?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* The text to follow for highlighting in dropdown options.
|
|
57
|
+
* If provided, this will be used instead of auto-extracting from children props.
|
|
58
|
+
*/
|
|
59
|
+
followText?: string;
|
|
54
60
|
/**
|
|
55
61
|
* The listbox id of the dropdown.
|
|
56
62
|
*/
|
|
@@ -112,6 +118,12 @@ export interface DropdownProps extends DropdownItemSharedProps {
|
|
|
112
118
|
* The placement of the dropdown.
|
|
113
119
|
*/
|
|
114
120
|
placement?: PopperPlacement;
|
|
121
|
+
/**
|
|
122
|
+
* Custom width for the dropdown.
|
|
123
|
+
* Can be a number (pixels) or a string (e.g., '200px', '50%').
|
|
124
|
+
* If provided, this takes precedence over `sameWidth`.
|
|
125
|
+
*/
|
|
126
|
+
customWidth?: number | string;
|
|
115
127
|
/**
|
|
116
128
|
* Whether to set the same width as its anchor element.
|
|
117
129
|
* @default false
|
|
@@ -134,5 +146,21 @@ export interface DropdownProps extends DropdownItemSharedProps {
|
|
|
134
146
|
* The z-index of the dropdown.
|
|
135
147
|
*/
|
|
136
148
|
zIndex?: number | string;
|
|
149
|
+
/**
|
|
150
|
+
* The status of the dropdown (loading or empty).
|
|
151
|
+
*/
|
|
152
|
+
status?: DropdownStatusType;
|
|
153
|
+
/**
|
|
154
|
+
* The text of the dropdown loading status.
|
|
155
|
+
*/
|
|
156
|
+
loadingText?: string;
|
|
157
|
+
/**
|
|
158
|
+
* The text of the dropdown empty status.
|
|
159
|
+
*/
|
|
160
|
+
emptyText?: string;
|
|
161
|
+
/**
|
|
162
|
+
* The icon of the dropdown empty status.
|
|
163
|
+
*/
|
|
164
|
+
emptyIcon?: IconDefinition;
|
|
137
165
|
}
|
|
138
166
|
export default function Dropdown(props: DropdownProps): import("react/jsx-runtime").JSX.Element;
|