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

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.
@@ -88,10 +88,15 @@ const TagAutocomplete = (inProps) => {
88
88
  (0, react_1.useEffect)(() => {
89
89
  const loadDefault = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
90
90
  if (typeof defaultValue === 'string' && defaultValue.trim() !== '') {
91
- const results = yield fetchTags(defaultValue);
92
- const match = results.find((t) => t.id === Number(defaultValue));
93
- if (match)
94
- setValue(match);
91
+ try {
92
+ const res = yield api_services_1.TagService.getSpecificTag(Number(defaultValue));
93
+ if (res) {
94
+ setValue(res);
95
+ }
96
+ }
97
+ catch (e) {
98
+ utils_1.Logger.error(Errors_1.SCOPE_SC_UI, e);
99
+ }
95
100
  }
96
101
  });
97
102
  loadDefault();
@@ -116,7 +121,7 @@ const TagAutocomplete = (inProps) => {
116
121
  return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ className: classes.root, open: open, onOpen: handleOpen, onClose: handleClose, options: tags || [], filterOptions: filterOptions, getOptionLabel: (option) => option.name || '', value: value, selectOnFocus: true, clearOnBlur: true, handleHomeEndKeys: true, clearIcon: null, noOptionsText: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.tags.empty", defaultMessage: "ui.composer.layer.audience.tags.empty" }), onChange: handleChange, isOptionEqualToValue: (option, value) => (value === null || value === void 0 ? void 0 : value.id) === (option === null || option === void 0 ? void 0 : option.id), inputValue: inputValue, onInputChange: (_e, newInputValue) => setInputValue(newInputValue), renderOption: (props, option, { inputValue }) => {
117
122
  const matches = (0, match_1.default)(option.name, inputValue);
118
123
  const parts = (0, parse_1.default)(option.name, matches);
119
- return ((0, jsx_runtime_1.jsx)("li", Object.assign({}, props, { children: (0, jsx_runtime_1.jsx)(TagChip_1.default, Object.assign({ 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) })));
124
+ 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) })));
120
125
  }, renderInput: (params) => {
121
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 }) })));
122
127
  } }, rest)));
@@ -72,5 +72,10 @@ export interface TagChipProps {
72
72
  * @default false
73
73
  */
74
74
  ellipsis?: boolean;
75
+ /**
76
+ * If `true`, shows the description of the tag on hover (desktop) or long press (mobile).
77
+ * @default false
78
+ */
79
+ showDescription?: boolean;
75
80
  }
76
81
  export default function TagChip(props: TagChipProps): JSX.Element;
@@ -23,7 +23,7 @@ const Root = (0, material_1.styled)(material_1.Chip, {
23
23
  }));
24
24
  function TagChip(props) {
25
25
  // PROPS
26
- const { tag, clickable = true, disposable = true, label = null, ellipsis = false, onClick = null, onDelete = null, className = null } = props, rest = tslib_1.__rest(props, ["tag", "clickable", "disposable", "label", "ellipsis", "onClick", "onDelete", "className"]);
26
+ const { tag, clickable = true, disposable = true, label = null, ellipsis = false, onClick = null, onDelete = null, className = null, showDescription = false } = props, rest = tslib_1.__rest(props, ["tag", "clickable", "disposable", "label", "ellipsis", "onClick", "onDelete", "className", "showDescription"]);
27
27
  // HANDLERS
28
28
  const handleClick = () => {
29
29
  onClick && onClick(tag.id);
@@ -31,9 +31,13 @@ function TagChip(props) {
31
31
  const handleDelete = () => {
32
32
  onDelete && onDelete(tag.id);
33
33
  };
34
+ const root = ((0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(className, { [classes.ellipsis]: ellipsis }), sx: { backgroundColor: `${tag.color}`, color: (theme) => theme.palette.getContrastText(tag.color) } }, (clickable && { onClick: handleClick }), (disposable && { onDelete: handleDelete }), { label: label ? label : tag.name }, rest)));
34
35
  /**
35
36
  * Renders root object
36
37
  */
37
- return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(className, { [classes.ellipsis]: ellipsis }), sx: { backgroundColor: `${tag.color}`, color: (theme) => theme.palette.getContrastText(tag.color) } }, (clickable && { onClick: handleClick }), (disposable && { onDelete: handleDelete }), { label: label ? label : tag.name }, rest)));
38
+ if (showDescription && tag.description) {
39
+ return ((0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: tag.description, placement: "right", arrow: true }, { children: root })));
40
+ }
41
+ return root;
38
42
  }
39
43
  exports.default = TagChip;
@@ -86,10 +86,15 @@ const TagAutocomplete = (inProps) => {
86
86
  useEffect(() => {
87
87
  const loadDefault = () => __awaiter(void 0, void 0, void 0, function* () {
88
88
  if (typeof defaultValue === 'string' && defaultValue.trim() !== '') {
89
- const results = yield fetchTags(defaultValue);
90
- const match = results.find((t) => t.id === Number(defaultValue));
91
- if (match)
92
- setValue(match);
89
+ try {
90
+ const res = yield TagService.getSpecificTag(Number(defaultValue));
91
+ if (res) {
92
+ setValue(res);
93
+ }
94
+ }
95
+ catch (e) {
96
+ Logger.error(SCOPE_SC_UI, e);
97
+ }
93
98
  }
94
99
  });
95
100
  loadDefault();
@@ -114,7 +119,7 @@ const TagAutocomplete = (inProps) => {
114
119
  return (_jsx(Root, Object.assign({ className: classes.root, open: open, onOpen: handleOpen, onClose: handleClose, options: tags || [], filterOptions: filterOptions, getOptionLabel: (option) => option.name || '', value: value, selectOnFocus: true, clearOnBlur: true, handleHomeEndKeys: true, clearIcon: null, noOptionsText: _jsx(FormattedMessage, { id: "ui.composer.layer.audience.tags.empty", defaultMessage: "ui.composer.layer.audience.tags.empty" }), onChange: handleChange, isOptionEqualToValue: (option, value) => (value === null || value === void 0 ? void 0 : value.id) === (option === null || option === void 0 ? void 0 : option.id), inputValue: inputValue, onInputChange: (_e, newInputValue) => setInputValue(newInputValue), renderOption: (props, option, { inputValue }) => {
115
120
  const matches = match(option.name, inputValue);
116
121
  const parts = parse(option.name, matches);
117
- return (_jsx("li", Object.assign({}, props, { children: _jsx(TagChip, Object.assign({ 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) })));
122
+ 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) })));
118
123
  }, renderInput: (params) => {
119
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 }) })));
120
125
  } }, rest)));
@@ -72,5 +72,10 @@ export interface TagChipProps {
72
72
  * @default false
73
73
  */
74
74
  ellipsis?: boolean;
75
+ /**
76
+ * If `true`, shows the description of the tag on hover (desktop) or long press (mobile).
77
+ * @default false
78
+ */
79
+ showDescription?: boolean;
75
80
  }
76
81
  export default function TagChip(props: TagChipProps): JSX.Element;
@@ -1,6 +1,6 @@
1
1
  import { __rest } from "tslib";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { styled, Chip } from '@mui/material';
3
+ import { styled, Chip, Tooltip } from '@mui/material';
4
4
  import classNames from 'classnames';
5
5
  const PREFIX = 'SCTagChip';
6
6
  const classes = {
@@ -21,7 +21,7 @@ const Root = styled(Chip, {
21
21
  }));
22
22
  export default function TagChip(props) {
23
23
  // PROPS
24
- const { tag, clickable = true, disposable = true, label = null, ellipsis = false, onClick = null, onDelete = null, className = null } = props, rest = __rest(props, ["tag", "clickable", "disposable", "label", "ellipsis", "onClick", "onDelete", "className"]);
24
+ const { tag, clickable = true, disposable = true, label = null, ellipsis = false, onClick = null, onDelete = null, className = null, showDescription = false } = props, rest = __rest(props, ["tag", "clickable", "disposable", "label", "ellipsis", "onClick", "onDelete", "className", "showDescription"]);
25
25
  // HANDLERS
26
26
  const handleClick = () => {
27
27
  onClick && onClick(tag.id);
@@ -29,8 +29,12 @@ export default function TagChip(props) {
29
29
  const handleDelete = () => {
30
30
  onDelete && onDelete(tag.id);
31
31
  };
32
+ const root = (_jsx(Root, Object.assign({ className: classNames(className, { [classes.ellipsis]: ellipsis }), sx: { backgroundColor: `${tag.color}`, color: (theme) => theme.palette.getContrastText(tag.color) } }, (clickable && { onClick: handleClick }), (disposable && { onDelete: handleDelete }), { label: label ? label : tag.name }, rest)));
32
33
  /**
33
34
  * Renders root object
34
35
  */
35
- return (_jsx(Root, Object.assign({ className: classNames(className, { [classes.ellipsis]: ellipsis }), sx: { backgroundColor: `${tag.color}`, color: (theme) => theme.palette.getContrastText(tag.color) } }, (clickable && { onClick: handleClick }), (disposable && { onDelete: handleDelete }), { label: label ? label : tag.name }, rest)));
36
+ if (showDescription && tag.description) {
37
+ return (_jsx(Tooltip, Object.assign({ title: tag.description, placement: "right", arrow: true }, { children: root })));
38
+ }
39
+ return root;
36
40
  }