@selfcommunity/react-ui 0.11.0-alpha.114 → 0.11.0-alpha.116

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.
@@ -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' | 'clearIcon' | 'noOptionsText' | 'isOptionEqualToValue' | 'renderTags' | 'renderOption' | 'renderInput'>> {
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,9 +81,7 @@ const TagAutocomplete = (inProps) => {
81
81
  }
82
82
  }, [open, inputValue]);
83
83
  (0, react_1.useEffect)(() => {
84
- if (value !== null) {
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* () {
@@ -108,7 +106,10 @@ const TagAutocomplete = (inProps) => {
108
106
  }
109
107
  };
110
108
  const handleClose = () => setOpen(false);
111
- const handleChange = (_event, newValue) => setValue(newValue);
109
+ const handleChange = (_event, newValue) => {
110
+ setValue(newValue);
111
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
112
+ };
112
113
  const filterOptions = (0, react_1.useCallback)((options, state) => {
113
114
  const search = state.inputValue.toLowerCase();
114
115
  return options.filter((option) => {
@@ -123,7 +124,7 @@ const TagAutocomplete = (inProps) => {
123
124
  const parts = (0, parse_1.default)(option.name, matches);
124
125
  return ((0, jsx_runtime_1.jsx)("li", Object.assign({}, props, { children: (0, jsx_runtime_1.jsx)(TagChip_1.default, Object.assign({ showDescription: true, disposable: false, tag: option, label: (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: parts.map((part, index) => ((0, jsx_runtime_1.jsx)("span", Object.assign({ style: { fontWeight: part.highlight ? 700 : 400 } }, { children: part.text }), index))) }) }, TagChipProps), option.id) })));
125
126
  }, renderInput: (params) => {
126
- return ((0, jsx_runtime_1.jsx)(material_1.TextField, Object.assign({}, params, TextFieldProps, { InputProps: Object.assign(Object.assign({}, params.InputProps), { autoComplete: 'tags', endAdornment: tags.length > 0 ? ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [loading && (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { color: "inherit", size: 20 }), params.InputProps.endAdornment] })) : null }) })));
127
+ return ((0, jsx_runtime_1.jsx)(material_1.TextField, Object.assign({}, params, TextFieldProps, { InputProps: Object.assign(Object.assign({}, params.InputProps), { autoComplete: 'tags', endAdornment: value || tags.length > 0 ? ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [loading && (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { color: "inherit", size: 20 }), params.InputProps.endAdornment] })) : null }) })));
127
128
  } }, rest)));
128
129
  };
129
130
  exports.default = TagAutocomplete;
@@ -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' | 'clearIcon' | 'noOptionsText' | 'isOptionEqualToValue' | 'renderTags' | 'renderOption' | 'renderInput'>> {
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,9 +79,7 @@ const TagAutocomplete = (inProps) => {
79
79
  }
80
80
  }, [open, inputValue]);
81
81
  useEffect(() => {
82
- if (value !== null) {
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* () {
@@ -106,7 +104,10 @@ const TagAutocomplete = (inProps) => {
106
104
  }
107
105
  };
108
106
  const handleClose = () => setOpen(false);
109
- const handleChange = (_event, newValue) => setValue(newValue);
107
+ const handleChange = (_event, newValue) => {
108
+ setValue(newValue);
109
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
110
+ };
110
111
  const filterOptions = useCallback((options, state) => {
111
112
  const search = state.inputValue.toLowerCase();
112
113
  return options.filter((option) => {
@@ -121,7 +122,7 @@ const TagAutocomplete = (inProps) => {
121
122
  const parts = parse(option.name, matches);
122
123
  return (_jsx("li", Object.assign({}, props, { children: _jsx(TagChip, Object.assign({ showDescription: true, disposable: false, tag: option, label: _jsx(React.Fragment, { children: parts.map((part, index) => (_jsx("span", Object.assign({ style: { fontWeight: part.highlight ? 700 : 400 } }, { children: part.text }), index))) }) }, TagChipProps), option.id) })));
123
124
  }, renderInput: (params) => {
124
- return (_jsx(TextField, Object.assign({}, params, TextFieldProps, { InputProps: Object.assign(Object.assign({}, params.InputProps), { autoComplete: 'tags', endAdornment: tags.length > 0 ? (_jsxs(Fragment, { children: [loading && _jsx(CircularProgress, { color: "inherit", size: 20 }), params.InputProps.endAdornment] })) : null }) })));
125
+ return (_jsx(TextField, Object.assign({}, params, TextFieldProps, { InputProps: Object.assign(Object.assign({}, params.InputProps), { autoComplete: 'tags', endAdornment: value || tags.length > 0 ? (_jsxs(Fragment, { children: [loading && _jsx(CircularProgress, { color: "inherit", size: 20 }), params.InputProps.endAdornment] })) : null }) })));
125
126
  } }, rest)));
126
127
  };
127
128
  export default TagAutocomplete;