@mezzanine-ui/react 1.0.0-beta.1 → 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/Badge/Badge.js +2 -2
- package/Breadcrumb/BreadcrumbItem.d.ts +1 -1
- 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 +30 -0
- package/Description/Description.js +13 -0
- package/Description/DescriptionContent.d.ts +41 -0
- package/Description/DescriptionContent.js +14 -0
- package/Description/DescriptionGroup.d.ts +13 -0
- package/Description/DescriptionGroup.js +12 -0
- package/Description/DescriptionTitle.d.ts +45 -0
- package/Description/DescriptionTitle.js +17 -0
- package/Description/index.d.ts +8 -0
- package/Description/index.js +4 -0
- package/Dropdown/Dropdown.d.ts +43 -3
- package/Dropdown/Dropdown.js +154 -35
- package/Dropdown/DropdownAction.d.ts +1 -1
- package/Dropdown/DropdownAction.js +1 -4
- package/Dropdown/DropdownItem.d.ts +21 -4
- package/Dropdown/DropdownItem.js +23 -10
- package/Dropdown/DropdownItemCard.d.ts +5 -5
- package/Dropdown/DropdownItemCard.js +11 -10
- package/Dropdown/DropdownStatus.d.ts +2 -2
- 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/FormControlContext.d.ts +2 -2
- package/Form/FormField.d.ts +56 -4
- package/Form/FormField.js +10 -6
- package/Form/FormHintText.d.ts +24 -1
- package/Form/FormHintText.js +4 -4
- package/Form/FormLabel.d.ts +6 -3
- package/Form/FormLabel.js +5 -3
- package/Input/Input.d.ts +29 -3
- package/Input/Input.js +22 -6
- package/Input/PasswordStrengthIndicator/PasswordStrengthIndicator.js +1 -1
- 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 +17 -3
- package/Navigation/Navigation.js +48 -33
- package/Navigation/NavigationFooter.js +4 -2
- package/Navigation/NavigationHeader.d.ts +11 -1
- package/Navigation/NavigationHeader.js +6 -3
- package/Navigation/NavigationOption.d.ts +3 -2
- package/Navigation/NavigationOption.js +45 -26
- package/Navigation/NavigationOptionCategory.js +20 -2
- package/Navigation/context.d.ts +2 -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/Table.d.ts +53 -15
- package/Table/Table.js +178 -82
- package/Table/TableContext.d.ts +18 -42
- package/Table/components/TableActionsCell.d.ts +26 -0
- package/Table/components/TableActionsCell.js +78 -0
- package/Table/components/TableBody.d.ts +2 -5
- package/Table/components/TableBody.js +16 -19
- package/Table/components/TableBulkActions.d.ts +15 -0
- package/Table/components/TableBulkActions.js +26 -0
- package/Table/components/TableCell.d.ts +2 -0
- package/Table/components/TableCell.js +42 -10
- package/Table/components/TableColGroup.js +10 -112
- package/Table/components/TableColumnTitleMenu.d.ts +6 -0
- package/Table/components/TableColumnTitleMenu.js +20 -0
- package/Table/components/TableDragHandleCell.d.ts +2 -0
- package/Table/components/TableDragHandleCell.js +8 -1
- package/Table/components/TableExpandCell.d.ts +2 -0
- package/Table/components/TableExpandCell.js +8 -1
- package/Table/components/TableExpandedRow.js +3 -2
- package/Table/components/TableHeader.d.ts +2 -4
- package/Table/components/TableHeader.js +11 -14
- package/Table/components/TableResizeHandle.js +3 -7
- package/Table/components/TableRow.js +54 -20
- package/Table/components/TableSelectionCell.d.ts +5 -0
- package/Table/components/TableSelectionCell.js +12 -1
- package/Table/components/index.d.ts +1 -0
- package/Table/components/index.js +1 -0
- package/Table/hooks/index.d.ts +1 -1
- package/Table/hooks/index.js +1 -1
- package/Table/hooks/useTableDataSource.d.ts +2 -2
- package/Table/hooks/useTableExpansion.js +0 -6
- package/Table/hooks/useTableFixedOffsets.d.ts +1 -1
- package/Table/hooks/useTableFixedOffsets.js +24 -26
- package/Table/hooks/useTableResizedColumns.d.ts +2 -0
- package/Table/hooks/useTableResizedColumns.js +22 -0
- package/Table/hooks/useTableScroll.d.ts +3 -1
- package/Table/hooks/useTableScroll.js +25 -19
- package/Table/hooks/useTableSelection.js +32 -8
- package/Table/hooks/useTableVirtualization.d.ts +1 -1
- package/Table/index.d.ts +4 -4
- package/Table/index.js +5 -3
- package/Table/utils/calculateColumnWidths.d.ts +28 -0
- package/Table/utils/calculateColumnWidths.js +80 -0
- package/Table/utils/index.d.ts +2 -0
- package/Table/utils/index.js +1 -0
- package/Table/utils/useTableRowSelection.d.ts +5 -5
- package/Table/utils/useTableRowSelection.js +14 -6
- 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 +36 -20
- package/index.js +26 -7
- package/package.json +4 -4
- package/utils/format-number-with-commas.d.ts +4 -0
- package/utils/format-number-with-commas.js +27 -0
- package/utils/parse-number-with-commas.d.ts +4 -0
- package/utils/parse-number-with-commas.js +22 -0
- 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
- package/Table/hooks/useTableColumns.d.ts +0 -8
- package/Table/hooks/useTableColumns.js +0 -91
|
@@ -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/Badge/Badge.js
CHANGED
|
@@ -15,11 +15,11 @@ const isCountVariant = (variant) => [
|
|
|
15
15
|
*/
|
|
16
16
|
const Badge = forwardRef(function Badge(props, ref) {
|
|
17
17
|
const { children, count, className, overflowCount, text, variant, ...rest } = props;
|
|
18
|
-
return (jsxs("div", { className: badgeClasses.container(!!children), children: [jsx("span", { ...rest, ref: ref, className: cx(badgeClasses.host, badgeClasses.variant(variant), { [badgeClasses.hide]: isCountVariant(variant) && count === 0 }, className), children: isCountVariant(variant)
|
|
18
|
+
return (jsxs("div", { className: badgeClasses.container(!!children), children: [children, jsx("span", { ...rest, ref: ref, className: cx(badgeClasses.host, badgeClasses.variant(variant), { [badgeClasses.hide]: isCountVariant(variant) && count === 0 }, className), children: isCountVariant(variant)
|
|
19
19
|
? overflowCount && count > overflowCount
|
|
20
20
|
? `${overflowCount}+`
|
|
21
21
|
: count
|
|
22
|
-
: text })
|
|
22
|
+
: text })] }));
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
export { Badge as default };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const BreadcrumbItem: import("react").ForwardRefExoticComponent<Omit<Omit<import("..").ComponentPropsWithoutKeyAndRef<"button">, "label" | "component" | "current" | "options" | "href" | "target"
|
|
1
|
+
declare const BreadcrumbItem: import("react").ForwardRefExoticComponent<Omit<Omit<import("..").ComponentPropsWithoutKeyAndRef<"button">, "expand" | "label" | "component" | "current" | "options" | "href" | "target"> & (import("./typings").BreadcrumbDropdownItemProps | import("./typings").BreadcrumbItemTextProps | import("./typings").BreadcrumbLinkItemProps), "component"> & {
|
|
2
2
|
component?: import("./typings").BreadcrumbItemComponent | undefined;
|
|
3
3
|
} & import("react").RefAttributes<HTMLElement>>;
|
|
4
4
|
export default BreadcrumbItem;
|
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
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { DescriptionOrientation } from '@mezzanine-ui/core/description';
|
|
3
|
+
import { DescriptionTitleProps } from './DescriptionTitle';
|
|
4
|
+
import { DescriptionContentProps } from './DescriptionContent';
|
|
5
|
+
import { BadgeProps } from '../Badge/typings';
|
|
6
|
+
import { ButtonProps } from '../Button';
|
|
7
|
+
import { ProgressProps } from '../Progress';
|
|
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'> & {
|
|
11
|
+
/**
|
|
12
|
+
* Defines what is rendered as the description content
|
|
13
|
+
*/
|
|
14
|
+
children: ReactElement<DescriptionContentProps> | ReactElement<BadgeProps> | ReactElement<ButtonProps> | ReactElement<ProgressProps> | ReactElement<TagGroupProps>;
|
|
15
|
+
/**
|
|
16
|
+
* Custom class name for description
|
|
17
|
+
*/
|
|
18
|
+
className?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Define the layout direction between the title and the content
|
|
21
|
+
* @default 'horizontal'
|
|
22
|
+
*/
|
|
23
|
+
orientation?: DescriptionOrientation;
|
|
24
|
+
/**
|
|
25
|
+
* title text for description
|
|
26
|
+
*/
|
|
27
|
+
title: string;
|
|
28
|
+
};
|
|
29
|
+
declare const Description: import("react").ForwardRefExoticComponent<DescriptionProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
30
|
+
export default Description;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { descriptionClasses } from '@mezzanine-ui/core/description';
|
|
5
|
+
import DescriptionTitle from './DescriptionTitle.js';
|
|
6
|
+
import cx from 'clsx';
|
|
7
|
+
|
|
8
|
+
const Description = forwardRef(function Description(props, ref) {
|
|
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] }));
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export { Description as default };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IconDefinition } from '@mezzanine-ui/icons';
|
|
2
|
+
import { DescriptionSize, DescriptionContentVariant } from '@mezzanine-ui/core/description';
|
|
3
|
+
interface DescriptionContentBaseProps {
|
|
4
|
+
/**
|
|
5
|
+
* Custom class name for content
|
|
6
|
+
*/
|
|
7
|
+
className?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Content text
|
|
10
|
+
*/
|
|
11
|
+
children: string;
|
|
12
|
+
/**
|
|
13
|
+
* Control the text size of the content
|
|
14
|
+
* @default 'main'
|
|
15
|
+
*/
|
|
16
|
+
size?: DescriptionSize;
|
|
17
|
+
/**
|
|
18
|
+
* Define the style and behavior of the content
|
|
19
|
+
* @default 'normal'
|
|
20
|
+
*/
|
|
21
|
+
variant?: Extract<DescriptionContentVariant, 'normal' | 'statistic' | 'trend-up' | 'trend-down'>;
|
|
22
|
+
/**
|
|
23
|
+
* Custom icon rendered after the content text
|
|
24
|
+
*/
|
|
25
|
+
icon?: never;
|
|
26
|
+
/**
|
|
27
|
+
* Click handler for the icon.
|
|
28
|
+
*/
|
|
29
|
+
onClickIcon?: never;
|
|
30
|
+
}
|
|
31
|
+
interface DescriptionContentWithClickableIcon {
|
|
32
|
+
className?: string;
|
|
33
|
+
children: string;
|
|
34
|
+
size?: DescriptionSize;
|
|
35
|
+
variant: Extract<DescriptionContentVariant, 'with-icon'>;
|
|
36
|
+
icon: IconDefinition;
|
|
37
|
+
onClickIcon?: VoidFunction;
|
|
38
|
+
}
|
|
39
|
+
export type DescriptionContentProps = DescriptionContentBaseProps | DescriptionContentWithClickableIcon;
|
|
40
|
+
declare const DescriptionContent: import("react").ForwardRefExoticComponent<DescriptionContentProps & import("react").RefAttributes<HTMLSpanElement>>;
|
|
41
|
+
export default DescriptionContent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { CaretUpIcon, CaretDownIcon } from '@mezzanine-ui/icons';
|
|
5
|
+
import { descriptionClasses } from '@mezzanine-ui/core/description';
|
|
6
|
+
import Icon from '../Icon/Icon.js';
|
|
7
|
+
import cx from 'clsx';
|
|
8
|
+
|
|
9
|
+
const DescriptionContent = forwardRef(function DescriptionContent(props, ref) {
|
|
10
|
+
const { className, children, icon, onClickIcon, size = 'main', variant = 'normal', } = props;
|
|
11
|
+
return (jsxs("span", { className: cx(descriptionClasses.contentHost, descriptionClasses.contentVariant(variant), descriptionClasses.contentSize(size), className), ref: ref, children: [variant === 'trend-up' && (jsx(Icon, { className: descriptionClasses.contentTrendUp, icon: CaretUpIcon, size: 16 })), variant === 'trend-down' && (jsx(Icon, { className: descriptionClasses.contentTrendDown, icon: CaretDownIcon, size: 16 })), children, variant === 'with-icon' && icon && (jsx(Icon, { className: descriptionClasses.contentIcon, icon: icon, size: 16, onClick: onClickIcon }))] }));
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export { DescriptionContent as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
export interface DescriptionGroupProps {
|
|
3
|
+
/**
|
|
4
|
+
* Custom class name for group
|
|
5
|
+
*/
|
|
6
|
+
className?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Description elements to be grouped and displayed together
|
|
9
|
+
*/
|
|
10
|
+
children: ReactElement[];
|
|
11
|
+
}
|
|
12
|
+
declare const DescriptionGroup: import("react").ForwardRefExoticComponent<DescriptionGroupProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
13
|
+
export default DescriptionGroup;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { descriptionClasses } from '@mezzanine-ui/core/description';
|
|
5
|
+
import cx from 'clsx';
|
|
6
|
+
|
|
7
|
+
const DescriptionGroup = forwardRef(function DescriptionGroup(props, ref) {
|
|
8
|
+
const { className, children } = props;
|
|
9
|
+
return (jsx("div", { className: cx(descriptionClasses.groupHost, className), ref: ref, children: children }));
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export { DescriptionGroup as default };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { IconDefinition } from '@mezzanine-ui/icons';
|
|
2
|
+
import { DescriptionWidthType } from '@mezzanine-ui/core/description';
|
|
3
|
+
import { BadgeDotVariant } from '@mezzanine-ui/core/badge';
|
|
4
|
+
import { Placement } from '@floating-ui/react-dom';
|
|
5
|
+
interface DescriptionTitleBaseProps {
|
|
6
|
+
/**
|
|
7
|
+
* Displays a badge dot alongside the title text
|
|
8
|
+
*/
|
|
9
|
+
badge?: BadgeDotVariant;
|
|
10
|
+
/**
|
|
11
|
+
* Custom class name for title
|
|
12
|
+
*/
|
|
13
|
+
className?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Title text
|
|
16
|
+
*/
|
|
17
|
+
children: string;
|
|
18
|
+
/**
|
|
19
|
+
* Controls the layout width behavior of the title
|
|
20
|
+
* @default 'stretch'
|
|
21
|
+
*/
|
|
22
|
+
widthType?: DescriptionWidthType;
|
|
23
|
+
}
|
|
24
|
+
interface DescriptionTitleWithTooltip {
|
|
25
|
+
/**
|
|
26
|
+
* An icon displayed after the title text
|
|
27
|
+
*/
|
|
28
|
+
icon: IconDefinition;
|
|
29
|
+
/**
|
|
30
|
+
* Text content displayed in a tooltip when hovering over the icon
|
|
31
|
+
*/
|
|
32
|
+
tooltip: string;
|
|
33
|
+
/**
|
|
34
|
+
* Defines the placement of the tooltip relative to the icon
|
|
35
|
+
*/
|
|
36
|
+
tooltipPlacement?: Placement;
|
|
37
|
+
}
|
|
38
|
+
interface DescriptionTitleWithoutTooltip {
|
|
39
|
+
icon?: IconDefinition;
|
|
40
|
+
tooltip?: undefined;
|
|
41
|
+
tooltipPlacement?: undefined;
|
|
42
|
+
}
|
|
43
|
+
export type DescriptionTitleProps = (DescriptionTitleBaseProps & DescriptionTitleWithTooltip) | (DescriptionTitleBaseProps & DescriptionTitleWithoutTooltip);
|
|
44
|
+
declare const DescriptionTitle: import("react").ForwardRefExoticComponent<DescriptionTitleProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
45
|
+
export default DescriptionTitle;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { descriptionClasses } from '@mezzanine-ui/core/description';
|
|
5
|
+
import Badge from '../Badge/Badge.js';
|
|
6
|
+
import Tooltip from '../Tooltip/Tooltip.js';
|
|
7
|
+
import Icon from '../Icon/Icon.js';
|
|
8
|
+
import cx from 'clsx';
|
|
9
|
+
|
|
10
|
+
const DescriptionTitle = forwardRef(function DescriptionTitle(props, ref) {
|
|
11
|
+
const { badge, className, children, icon, tooltip, tooltipPlacement, widthType = 'stretch', } = props;
|
|
12
|
+
return (jsxs("div", { className: cx(descriptionClasses.titleHost, descriptionClasses.titleWidth(widthType), className), ref: ref, children: [badge ? (jsx(Badge, { variant: badge, text: children, className: descriptionClasses.titleText })) : (jsx("span", { className: descriptionClasses.titleText, children: children })), icon ? (tooltip ? (jsx(Tooltip, { title: tooltip, options: {
|
|
13
|
+
placement: tooltipPlacement !== null && tooltipPlacement !== void 0 ? tooltipPlacement : 'top',
|
|
14
|
+
}, children: ({ onMouseEnter, onMouseLeave, ref }) => (jsx(Icon, { ref: ref, icon: icon, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, size: 16 })) })) : (jsx(Icon, { icon: icon, size: 16 }))) : null] }));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export { DescriptionTitle as default };
|