@selfcommunity/react-ui 0.11.0-alpha.112 → 0.11.0-alpha.113
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/TagAutocomplete/TagAutocomplete.js +4 -3
- package/lib/cjs/shared/TagChip/index.d.ts +5 -0
- package/lib/cjs/shared/TagChip/index.js +6 -2
- package/lib/esm/components/TagAutocomplete/TagAutocomplete.js +4 -3
- package/lib/esm/shared/TagChip/index.d.ts +5 -0
- package/lib/esm/shared/TagChip/index.js +7 -3
- package/lib/umd/react-ui.js +1 -1
- package/package.json +3 -3
|
@@ -88,10 +88,11 @@ 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(
|
|
91
|
+
const results = yield fetchTags('');
|
|
92
92
|
const match = results.find((t) => t.id === Number(defaultValue));
|
|
93
|
-
if (match)
|
|
93
|
+
if (match) {
|
|
94
94
|
setValue(match);
|
|
95
|
+
}
|
|
95
96
|
}
|
|
96
97
|
});
|
|
97
98
|
loadDefault();
|
|
@@ -116,7 +117,7 @@ const TagAutocomplete = (inProps) => {
|
|
|
116
117
|
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
118
|
const matches = (0, match_1.default)(option.name, inputValue);
|
|
118
119
|
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) })));
|
|
120
|
+
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
121
|
}, renderInput: (params) => {
|
|
121
122
|
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
123
|
} }, 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
|
-
|
|
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,11 @@ 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(
|
|
89
|
+
const results = yield fetchTags('');
|
|
90
90
|
const match = results.find((t) => t.id === Number(defaultValue));
|
|
91
|
-
if (match)
|
|
91
|
+
if (match) {
|
|
92
92
|
setValue(match);
|
|
93
|
+
}
|
|
93
94
|
}
|
|
94
95
|
});
|
|
95
96
|
loadDefault();
|
|
@@ -114,7 +115,7 @@ const TagAutocomplete = (inProps) => {
|
|
|
114
115
|
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
116
|
const matches = match(option.name, inputValue);
|
|
116
117
|
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) })));
|
|
118
|
+
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
119
|
}, renderInput: (params) => {
|
|
119
120
|
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
121
|
} }, 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
|
-
|
|
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
|
}
|