@selfcommunity/react-ui 0.11.0-alpha.113 → 0.11.0-alpha.115
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/lib/cjs/components/CategoryAutocomplete/CategoryAutocomplete.d.ts +1 -1
- package/lib/cjs/components/CategoryAutocomplete/CategoryAutocomplete.js +1 -3
- package/lib/cjs/components/TagAutocomplete/TagAutocomplete.js +13 -8
- package/lib/esm/components/CategoryAutocomplete/CategoryAutocomplete.d.ts +1 -1
- package/lib/esm/components/CategoryAutocomplete/CategoryAutocomplete.js +1 -3
- package/lib/esm/components/TagAutocomplete/TagAutocomplete.js +13 -8
- package/lib/umd/react-ui.js +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AutocompleteProps, TextFieldProps } from '@mui/material';
|
|
2
2
|
import { SCCategoryType } from '@selfcommunity/types';
|
|
3
|
-
export interface CategoryAutocompleteProps extends Pick<AutocompleteProps<SCCategoryType | null, any, any, any>, Exclude<keyof AutocompleteProps<SCCategoryType | null, any, any, any>, 'open' | 'onOpen' | 'onClose' | 'onChange' | 'filterSelectedOptions' | 'disableCloseOnSelect' | 'options' | 'getOptionLabel' | 'value' | 'selectOnFocus' | 'clearOnBlur' | 'blurOnSelect' | 'handleHomeEndKeys' | '
|
|
3
|
+
export interface CategoryAutocompleteProps extends Pick<AutocompleteProps<SCCategoryType | null, any, any, any>, Exclude<keyof AutocompleteProps<SCCategoryType | null, any, any, any>, 'open' | 'onOpen' | 'onClose' | 'onChange' | 'filterSelectedOptions' | 'disableCloseOnSelect' | 'options' | 'getOptionLabel' | 'value' | 'selectOnFocus' | 'clearOnBlur' | 'blurOnSelect' | 'handleHomeEndKeys' | 'noOptionsText' | 'isOptionEqualToValue' | 'renderTags' | 'renderOption' | 'renderInput'>> {
|
|
4
4
|
/**
|
|
5
5
|
* The maximum number of categories that will be visible when not focused.
|
|
6
6
|
* @default 0
|
|
@@ -56,9 +56,6 @@ const CategoryAutocomplete = (inProps) => {
|
|
|
56
56
|
// HOOKS
|
|
57
57
|
const { categories, isLoading } = (0, react_core_1.useSCFetchCategories)({ endpointQueryParams });
|
|
58
58
|
(0, react_1.useEffect)(() => {
|
|
59
|
-
if (value === null) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
59
|
onChange === null || onChange === void 0 ? void 0 : onChange(value);
|
|
63
60
|
}, [value]);
|
|
64
61
|
(0, react_1.useEffect)(() => {
|
|
@@ -83,6 +80,7 @@ const CategoryAutocomplete = (inProps) => {
|
|
|
83
80
|
newValue = value;
|
|
84
81
|
}
|
|
85
82
|
setValue(newValue);
|
|
83
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
86
84
|
};
|
|
87
85
|
// Render
|
|
88
86
|
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ className: classes.root, multiple: multiple, open: open, onOpen: handleOpen, onClose: handleClose, filterSelectedOptions: !checkboxSelect, disableCloseOnSelect: checkboxSelect, options: categories || [], getOptionLabel: (option) => option.name || '', value: value, selectOnFocus: true, clearOnBlur: true, blurOnSelect: true, handleHomeEndKeys: true, clearIcon: null, disabled: disabled || isLoading, noOptionsText: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.categoryAutocomplete.empty", defaultMessage: "ui.categoryAutocomplete.empty" }), onChange: handleChange, isOptionEqualToValue: (option, value) => value.id === option.id, renderTags: (value, getTagProps) => {
|
|
@@ -81,17 +81,19 @@ const TagAutocomplete = (inProps) => {
|
|
|
81
81
|
}
|
|
82
82
|
}, [open, inputValue]);
|
|
83
83
|
(0, react_1.useEffect)(() => {
|
|
84
|
-
|
|
85
|
-
onChange && onChange(value);
|
|
86
|
-
}
|
|
84
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(value);
|
|
87
85
|
}, [value]);
|
|
88
86
|
(0, react_1.useEffect)(() => {
|
|
89
87
|
const loadDefault = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
90
88
|
if (typeof defaultValue === 'string' && defaultValue.trim() !== '') {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
try {
|
|
90
|
+
const res = yield api_services_1.TagService.getSpecificTag(Number(defaultValue));
|
|
91
|
+
if (res) {
|
|
92
|
+
setValue(res);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_UI, e);
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
99
|
});
|
|
@@ -104,7 +106,10 @@ const TagAutocomplete = (inProps) => {
|
|
|
104
106
|
}
|
|
105
107
|
};
|
|
106
108
|
const handleClose = () => setOpen(false);
|
|
107
|
-
const handleChange = (_event, newValue) =>
|
|
109
|
+
const handleChange = (_event, newValue) => {
|
|
110
|
+
setValue(newValue);
|
|
111
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
112
|
+
};
|
|
108
113
|
const filterOptions = (0, react_1.useCallback)((options, state) => {
|
|
109
114
|
const search = state.inputValue.toLowerCase();
|
|
110
115
|
return options.filter((option) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AutocompleteProps, TextFieldProps } from '@mui/material';
|
|
2
2
|
import { SCCategoryType } from '@selfcommunity/types';
|
|
3
|
-
export interface CategoryAutocompleteProps extends Pick<AutocompleteProps<SCCategoryType | null, any, any, any>, Exclude<keyof AutocompleteProps<SCCategoryType | null, any, any, any>, 'open' | 'onOpen' | 'onClose' | 'onChange' | 'filterSelectedOptions' | 'disableCloseOnSelect' | 'options' | 'getOptionLabel' | 'value' | 'selectOnFocus' | 'clearOnBlur' | 'blurOnSelect' | 'handleHomeEndKeys' | '
|
|
3
|
+
export interface CategoryAutocompleteProps extends Pick<AutocompleteProps<SCCategoryType | null, any, any, any>, Exclude<keyof AutocompleteProps<SCCategoryType | null, any, any, any>, 'open' | 'onOpen' | 'onClose' | 'onChange' | 'filterSelectedOptions' | 'disableCloseOnSelect' | 'options' | 'getOptionLabel' | 'value' | 'selectOnFocus' | 'clearOnBlur' | 'blurOnSelect' | 'handleHomeEndKeys' | 'noOptionsText' | 'isOptionEqualToValue' | 'renderTags' | 'renderOption' | 'renderInput'>> {
|
|
4
4
|
/**
|
|
5
5
|
* The maximum number of categories that will be visible when not focused.
|
|
6
6
|
* @default 0
|
|
@@ -54,9 +54,6 @@ const CategoryAutocomplete = (inProps) => {
|
|
|
54
54
|
// HOOKS
|
|
55
55
|
const { categories, isLoading } = useSCFetchCategories({ endpointQueryParams });
|
|
56
56
|
useEffect(() => {
|
|
57
|
-
if (value === null) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
57
|
onChange === null || onChange === void 0 ? void 0 : onChange(value);
|
|
61
58
|
}, [value]);
|
|
62
59
|
useEffect(() => {
|
|
@@ -81,6 +78,7 @@ const CategoryAutocomplete = (inProps) => {
|
|
|
81
78
|
newValue = value;
|
|
82
79
|
}
|
|
83
80
|
setValue(newValue);
|
|
81
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
84
82
|
};
|
|
85
83
|
// Render
|
|
86
84
|
return (_jsx(Root, Object.assign({ className: classes.root, multiple: multiple, open: open, onOpen: handleOpen, onClose: handleClose, filterSelectedOptions: !checkboxSelect, disableCloseOnSelect: checkboxSelect, options: categories || [], getOptionLabel: (option) => option.name || '', value: value, selectOnFocus: true, clearOnBlur: true, blurOnSelect: true, handleHomeEndKeys: true, clearIcon: null, disabled: disabled || isLoading, noOptionsText: _jsx(FormattedMessage, { id: "ui.categoryAutocomplete.empty", defaultMessage: "ui.categoryAutocomplete.empty" }), onChange: handleChange, isOptionEqualToValue: (option, value) => value.id === option.id, renderTags: (value, getTagProps) => {
|
|
@@ -79,17 +79,19 @@ const TagAutocomplete = (inProps) => {
|
|
|
79
79
|
}
|
|
80
80
|
}, [open, inputValue]);
|
|
81
81
|
useEffect(() => {
|
|
82
|
-
|
|
83
|
-
onChange && onChange(value);
|
|
84
|
-
}
|
|
82
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(value);
|
|
85
83
|
}, [value]);
|
|
86
84
|
useEffect(() => {
|
|
87
85
|
const loadDefault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
86
|
if (typeof defaultValue === 'string' && defaultValue.trim() !== '') {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
try {
|
|
88
|
+
const res = yield TagService.getSpecificTag(Number(defaultValue));
|
|
89
|
+
if (res) {
|
|
90
|
+
setValue(res);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
Logger.error(SCOPE_SC_UI, e);
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
});
|
|
@@ -102,7 +104,10 @@ const TagAutocomplete = (inProps) => {
|
|
|
102
104
|
}
|
|
103
105
|
};
|
|
104
106
|
const handleClose = () => setOpen(false);
|
|
105
|
-
const handleChange = (_event, newValue) =>
|
|
107
|
+
const handleChange = (_event, newValue) => {
|
|
108
|
+
setValue(newValue);
|
|
109
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
110
|
+
};
|
|
106
111
|
const filterOptions = useCallback((options, state) => {
|
|
107
112
|
const search = state.inputValue.toLowerCase();
|
|
108
113
|
return options.filter((option) => {
|