@snack-uikit/tag 0.12.11-preview-53302b98.0 → 0.12.11
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/CHANGELOG.md +9 -0
- package/README.md +0 -2
- package/dist/cjs/components/Tag/Tag.d.ts +4 -3
- package/dist/cjs/components/Tag/Tag.js +5 -31
- package/dist/cjs/components/TagBase/TagBase.d.ts +8 -3
- package/dist/cjs/components/TagBase/TagBase.js +5 -28
- package/dist/cjs/components/TagLink/TagLink.d.ts +9 -3
- package/dist/cjs/components/TagLink/TagLink.js +1 -0
- package/dist/cjs/components/TagRow/utils.d.ts +1 -1
- package/dist/cjs/components/TagRow/utils.js +14 -15
- package/dist/cjs/helperComponents/TagList/TagList.js +4 -2
- package/dist/cjs/types.d.ts +6 -22
- package/dist/esm/components/Tag/Tag.d.ts +4 -3
- package/dist/esm/components/Tag/Tag.js +5 -27
- package/dist/esm/components/TagBase/TagBase.d.ts +8 -3
- package/dist/esm/components/TagBase/TagBase.js +2 -20
- package/dist/esm/components/TagLink/TagLink.d.ts +9 -3
- package/dist/esm/components/TagLink/TagLink.js +1 -1
- package/dist/esm/components/TagRow/utils.d.ts +1 -1
- package/dist/esm/components/TagRow/utils.js +8 -14
- package/dist/esm/helperComponents/TagList/TagList.js +1 -1
- package/dist/esm/types.d.ts +6 -22
- package/package.json +3 -4
- package/src/components/Tag/Tag.tsx +8 -30
- package/src/components/TagBase/TagBase.tsx +14 -36
- package/src/components/TagLink/TagLink.tsx +12 -5
- package/src/components/TagRow/utils.ts +10 -4
- package/src/helperComponents/TagList/TagList.tsx +1 -1
- package/src/types.ts +6 -28
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.12.11 (2025-03-19)
|
|
7
|
+
|
|
8
|
+
### Only dependencies have been changed
|
|
9
|
+
* [@snack-uikit/icons@0.26.2](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/icons/CHANGELOG.md)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
6
15
|
## 0.12.10 (2025-03-17)
|
|
7
16
|
|
|
8
17
|
### Only dependencies have been changed
|
package/README.md
CHANGED
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
| appearance | enum Appearance: `"neutral"`, `"primary"`, `"red"`, `"orange"`, `"yellow"`, `"green"`, `"blue"`, `"violet"`, `"pink"` | - | Внешний вид |
|
|
19
19
|
| className | `string` | - | CSS-класс |
|
|
20
20
|
| tabIndex | `number` | - | tabIndex кнопки удаления |
|
|
21
|
-
| tooltip | `TooltipProps` | - | Тултип над тегом |
|
|
22
21
|
| onClick | `(e: MouseEvent<HTMLAnchorElement, MouseEvent>) => void` | - | |
|
|
23
22
|
| target | `string` | - | |
|
|
24
23
|
## Tag
|
|
@@ -32,7 +31,6 @@
|
|
|
32
31
|
| appearance | enum Appearance: `"neutral"`, `"primary"`, `"red"`, `"orange"`, `"yellow"`, `"green"`, `"blue"`, `"violet"`, `"pink"` | - | Внешний вид |
|
|
33
32
|
| className | `string` | - | CSS-класс |
|
|
34
33
|
| tabIndex | `number` | - | tabIndex кнопки удаления |
|
|
35
|
-
| tooltip | `TooltipProps` | - | Тултип над тегом |
|
|
36
34
|
| onClick | `(e: MouseEvent<HTMLAnchorElement, MouseEvent>) => void` | - | |
|
|
37
35
|
| target | `string` | - | |
|
|
38
36
|
## TagRow
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { TagBaseProps
|
|
2
|
-
|
|
1
|
+
import { TagBaseProps } from '../TagBase';
|
|
2
|
+
import { TagLinkProps } from '../TagLink';
|
|
3
|
+
export type TagProps = TagBaseProps | TagLinkProps;
|
|
3
4
|
export declare function isTagLinkProps(props: TagProps): props is TagLinkProps;
|
|
4
|
-
export declare function Tag(
|
|
5
|
+
export declare function Tag(props: TagProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,45 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
4
|
-
var t = {};
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
3
|
Object.defineProperty(exports, "__esModule", {
|
|
12
4
|
value: true
|
|
13
5
|
});
|
|
14
6
|
exports.isTagLinkProps = isTagLinkProps;
|
|
15
7
|
exports.Tag = Tag;
|
|
16
8
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
17
|
-
const react_1 = require("react");
|
|
18
|
-
const tooltip_1 = require("@snack-uikit/tooltip");
|
|
19
9
|
const TagBase_1 = require("../TagBase");
|
|
20
10
|
const TagLink_1 = require("../TagLink");
|
|
21
11
|
function isTagLinkProps(props) {
|
|
22
12
|
return 'href' in props && props.href !== undefined;
|
|
23
13
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
tooltip
|
|
30
|
-
} = _a,
|
|
31
|
-
props = __rest(_a, ["tooltip"]);
|
|
32
|
-
const [restrictOpenTooltip, setRestrictOpenTooltip] = (0, react_1.useState)(false);
|
|
33
|
-
const removable = isRemovable(props);
|
|
34
|
-
const TagComponent = isTagLinkProps(props) ? TagLink_1.TagLink : TagBase_1.TagBase;
|
|
35
|
-
const TagWithTooltip = (0, tooltip_1.useElementWithTooltip)({
|
|
36
|
-
Element: TagComponent,
|
|
37
|
-
tooltip: tooltip && Object.assign(Object.assign({}, tooltip), {
|
|
38
|
-
open: removable && restrictOpenTooltip ? false : tooltip.open
|
|
39
|
-
})
|
|
40
|
-
});
|
|
41
|
-
const tagProps = Object.assign(Object.assign({}, props), {
|
|
42
|
-
changeRestrictTooltipState: setRestrictOpenTooltip
|
|
43
|
-
});
|
|
44
|
-
return (0, jsx_runtime_1.jsx)(TagWithTooltip, Object.assign({}, tagProps));
|
|
14
|
+
function Tag(props) {
|
|
15
|
+
if (isTagLinkProps(props)) {
|
|
16
|
+
return (0, jsx_runtime_1.jsx)(TagLink_1.TagLink, Object.assign({}, props));
|
|
17
|
+
}
|
|
18
|
+
return (0, jsx_runtime_1.jsx)(TagBase_1.TagBase, Object.assign({}, props));
|
|
45
19
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { MouseEventHandler } from 'react';
|
|
2
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
+
import { CommonTagProps } from '../../types';
|
|
4
|
+
export type TagBaseProps = WithSupportProps<{
|
|
5
|
+
/** Коллбэк на удаление */
|
|
6
|
+
onDelete?: MouseEventHandler<HTMLButtonElement>;
|
|
7
|
+
}> & CommonTagProps;
|
|
8
|
+
export declare function TagBase({ label, size, appearance, onDelete, className, tabIndex, ...rest }: TagBaseProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -19,7 +19,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
19
19
|
exports.TagBase = TagBase;
|
|
20
20
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
21
21
|
const classnames_1 = __importDefault(require("classnames"));
|
|
22
|
-
const react_1 = require("react");
|
|
23
22
|
const icons_1 = require("@snack-uikit/icons");
|
|
24
23
|
const utils_1 = require("@snack-uikit/utils");
|
|
25
24
|
const constants_1 = require("../../constants");
|
|
@@ -32,46 +31,24 @@ function TagBase(_a) {
|
|
|
32
31
|
appearance = constants_1.APPEARANCE.Neutral,
|
|
33
32
|
onDelete,
|
|
34
33
|
className,
|
|
35
|
-
tabIndex
|
|
36
|
-
changeRestrictTooltipState
|
|
34
|
+
tabIndex
|
|
37
35
|
} = _a,
|
|
38
|
-
rest = __rest(_a, ["label", "size", "appearance", "onDelete", "className", "tabIndex"
|
|
39
|
-
const deleteButtonRef = (0, react_1.useRef)(null);
|
|
40
|
-
const isRemovable = Boolean(onDelete);
|
|
41
|
-
const handleMouseEnter = event => {
|
|
42
|
-
var _a;
|
|
43
|
-
if (!isRemovable) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if ((_a = deleteButtonRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.target)) {
|
|
47
|
-
changeRestrictTooltipState(true);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const handleMouseLeave = () => {
|
|
51
|
-
if (!isRemovable) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
changeRestrictTooltipState(false);
|
|
55
|
-
};
|
|
36
|
+
rest = __rest(_a, ["label", "size", "appearance", "onDelete", "className", "tabIndex"]);
|
|
56
37
|
return (0, jsx_runtime_1.jsxs)("span", Object.assign({}, (0, utils_1.extractSupportProps)(rest), {
|
|
57
38
|
className: (0, classnames_1.default)(styles_module_scss_1.default.tag, className),
|
|
58
39
|
"data-size": size,
|
|
59
40
|
"data-appearance": appearance,
|
|
60
|
-
"data-removable":
|
|
61
|
-
onMouseEnter: handleMouseEnter,
|
|
62
|
-
onMouseLeave: handleMouseLeave,
|
|
41
|
+
"data-removable": Boolean(onDelete),
|
|
63
42
|
children: [(0, jsx_runtime_1.jsx)("span", {
|
|
43
|
+
title: label,
|
|
64
44
|
className: styles_module_scss_1.default.label,
|
|
65
45
|
children: label
|
|
66
|
-
}),
|
|
46
|
+
}), onDelete && (0, jsx_runtime_1.jsx)("button", {
|
|
67
47
|
type: 'button',
|
|
68
48
|
className: styles_module_scss_1.default.tagButton,
|
|
69
49
|
onClick: onDelete,
|
|
70
50
|
"data-test-id": 'tag-remove-button',
|
|
71
51
|
tabIndex: tabIndex,
|
|
72
|
-
onMouseEnter: handleMouseEnter,
|
|
73
|
-
onMouseLeave: handleMouseLeave,
|
|
74
|
-
ref: deleteButtonRef,
|
|
75
52
|
children: size === constants_1.SIZE.Xs ? (0, jsx_runtime_1.jsx)(icons_1.CrossSVG, {
|
|
76
53
|
size: constants_2.ICON_SIZE[size],
|
|
77
54
|
className: styles_module_scss_1.default.icon
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { MouseEvent } from 'react';
|
|
2
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
+
import { CommonTagProps } from '../../types';
|
|
4
|
+
export type TagLinkProps = WithSupportProps<CommonTagProps> & {
|
|
5
|
+
href: string;
|
|
6
|
+
onClick?(e: MouseEvent<HTMLAnchorElement>): void;
|
|
7
|
+
target?: HTMLAnchorElement['target'];
|
|
8
|
+
};
|
|
9
|
+
export declare function TagLink({ label, size, appearance, className, tabIndex, href, onClick, target, ...rest }: TagLinkProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { TagRowItem, TagRowItemInner } from '../../types';
|
|
2
|
-
export declare const mapTagRowItem: ({
|
|
2
|
+
export declare const mapTagRowItem: ({ label, appearance }: TagRowItem) => TagRowItemInner;
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
4
|
-
var t = {};
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
3
|
Object.defineProperty(exports, "__esModule", {
|
|
12
4
|
value: true
|
|
13
5
|
});
|
|
14
6
|
exports.mapTagRowItem = void 0;
|
|
15
7
|
const constants_1 = require("../../constants");
|
|
16
|
-
const mapTagRowItem =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} = _a,
|
|
20
|
-
props = __rest(_a, ["appearance"]);
|
|
21
|
-
return Object.assign(Object.assign({}, props), {
|
|
8
|
+
const mapTagRowItem = _ref => {
|
|
9
|
+
let {
|
|
10
|
+
label,
|
|
22
11
|
appearance
|
|
23
|
-
}
|
|
12
|
+
} = _ref;
|
|
13
|
+
if (appearance) {
|
|
14
|
+
return {
|
|
15
|
+
label,
|
|
16
|
+
appearance
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
label,
|
|
21
|
+
appearance: constants_1.APPEARANCE.Neutral
|
|
22
|
+
};
|
|
24
23
|
};
|
|
25
24
|
exports.mapTagRowItem = mapTagRowItem;
|
|
@@ -18,10 +18,12 @@ function renderTag(size, handleRemoveItem, setRef) {
|
|
|
18
18
|
return (0, jsx_runtime_1.jsx)("div", {
|
|
19
19
|
ref: setRef === null || setRef === void 0 ? void 0 : setRef(item, index),
|
|
20
20
|
className: styles_module_scss_1.default.tagWrapper,
|
|
21
|
-
children: (0, jsx_runtime_1.jsx)(components_1.Tag,
|
|
21
|
+
children: (0, jsx_runtime_1.jsx)(components_1.Tag, {
|
|
22
|
+
label: item.label,
|
|
23
|
+
appearance: item.appearance,
|
|
22
24
|
size: size,
|
|
23
25
|
onDelete: handleRemoveItem === null || handleRemoveItem === void 0 ? void 0 : handleRemoveItem(item)
|
|
24
|
-
}
|
|
26
|
+
})
|
|
25
27
|
}, item.label);
|
|
26
28
|
};
|
|
27
29
|
}
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { MouseEvent
|
|
2
|
-
import {
|
|
3
|
-
import { ValueOf, WithSupportProps } from '@snack-uikit/utils';
|
|
1
|
+
import { MouseEvent } from 'react';
|
|
2
|
+
import { ValueOf } from '@snack-uikit/utils';
|
|
4
3
|
import { APPEARANCE, SIZE } from './constants';
|
|
5
4
|
export type Appearance = ValueOf<typeof APPEARANCE>;
|
|
6
5
|
export type Size = ValueOf<typeof SIZE>;
|
|
@@ -9,17 +8,14 @@ export type LinkProps = {
|
|
|
9
8
|
onClick?(e: MouseEvent<HTMLAnchorElement>): void;
|
|
10
9
|
target?: HTMLAnchorElement['target'];
|
|
11
10
|
};
|
|
12
|
-
export type TagTooltipProps = {
|
|
13
|
-
/** Тултип над тегом */
|
|
14
|
-
tooltip?: TooltipProps;
|
|
15
|
-
};
|
|
16
11
|
export type TagRowItem = {
|
|
17
12
|
label: string;
|
|
18
13
|
appearance?: Appearance;
|
|
19
|
-
} & Partial<LinkProps
|
|
20
|
-
export type TagRowItemInner =
|
|
14
|
+
} & Partial<LinkProps>;
|
|
15
|
+
export type TagRowItemInner = {
|
|
16
|
+
label: string;
|
|
21
17
|
appearance: Appearance;
|
|
22
|
-
}
|
|
18
|
+
} & Partial<LinkProps>;
|
|
23
19
|
export type CommonTagProps = {
|
|
24
20
|
/** Текст */
|
|
25
21
|
label: string;
|
|
@@ -32,15 +28,3 @@ export type CommonTagProps = {
|
|
|
32
28
|
/** tabIndex кнопки удаления */
|
|
33
29
|
tabIndex?: number;
|
|
34
30
|
};
|
|
35
|
-
export type TagBaseProps = WithSupportProps<{
|
|
36
|
-
/** Коллбэк на удаление */
|
|
37
|
-
onDelete?: MouseEventHandler<HTMLButtonElement>;
|
|
38
|
-
}> & CommonTagProps;
|
|
39
|
-
export type TagLinkProps = WithSupportProps<CommonTagProps> & {
|
|
40
|
-
href: string;
|
|
41
|
-
onClick?(e: MouseEvent<HTMLAnchorElement>): void;
|
|
42
|
-
target?: HTMLAnchorElement['target'];
|
|
43
|
-
};
|
|
44
|
-
export type ManageRestrictPopoverProps = {
|
|
45
|
-
changeRestrictTooltipState: (state: boolean) => void;
|
|
46
|
-
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { TagBaseProps
|
|
2
|
-
|
|
1
|
+
import { TagBaseProps } from '../TagBase';
|
|
2
|
+
import { TagLinkProps } from '../TagLink';
|
|
3
|
+
export type TagProps = TagBaseProps | TagLinkProps;
|
|
3
4
|
export declare function isTagLinkProps(props: TagProps): props is TagLinkProps;
|
|
4
|
-
export declare function Tag(
|
|
5
|
+
export declare function Tag(props: TagProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,34 +1,12 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import { useState } from 'react';
|
|
14
|
-
import { useElementWithTooltip } from '@snack-uikit/tooltip';
|
|
15
2
|
import { TagBase } from '../TagBase';
|
|
16
3
|
import { TagLink } from '../TagLink';
|
|
17
4
|
export function isTagLinkProps(props) {
|
|
18
5
|
return 'href' in props && props.href !== undefined;
|
|
19
6
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const [restrictOpenTooltip, setRestrictOpenTooltip] = useState(false);
|
|
26
|
-
const removable = isRemovable(props);
|
|
27
|
-
const TagComponent = isTagLinkProps(props) ? TagLink : TagBase;
|
|
28
|
-
const TagWithTooltip = useElementWithTooltip({
|
|
29
|
-
Element: TagComponent,
|
|
30
|
-
tooltip: tooltip && Object.assign(Object.assign({}, tooltip), { open: removable && restrictOpenTooltip ? false : tooltip.open }),
|
|
31
|
-
});
|
|
32
|
-
const tagProps = Object.assign(Object.assign({}, props), { changeRestrictTooltipState: setRestrictOpenTooltip });
|
|
33
|
-
return _jsx(TagWithTooltip, Object.assign({}, tagProps));
|
|
7
|
+
export function Tag(props) {
|
|
8
|
+
if (isTagLinkProps(props)) {
|
|
9
|
+
return _jsx(TagLink, Object.assign({}, props));
|
|
10
|
+
}
|
|
11
|
+
return _jsx(TagBase, Object.assign({}, props));
|
|
34
12
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { MouseEventHandler } from 'react';
|
|
2
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
+
import { CommonTagProps } from '../../types';
|
|
4
|
+
export type TagBaseProps = WithSupportProps<{
|
|
5
|
+
/** Коллбэк на удаление */
|
|
6
|
+
onDelete?: MouseEventHandler<HTMLButtonElement>;
|
|
7
|
+
}> & CommonTagProps;
|
|
8
|
+
export declare function TagBase({ label, size, appearance, onDelete, className, tabIndex, ...rest }: TagBaseProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -11,30 +11,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import cn from 'classnames';
|
|
14
|
-
import { useRef } from 'react';
|
|
15
14
|
import { CrossSVG } from '@snack-uikit/icons';
|
|
16
15
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
17
16
|
import { APPEARANCE, SIZE } from '../../constants';
|
|
18
17
|
import { ICON_SIZE } from './constants';
|
|
19
18
|
import styles from './styles.module.css';
|
|
20
19
|
export function TagBase(_a) {
|
|
21
|
-
var { label, size = SIZE.Xs, appearance = APPEARANCE.Neutral, onDelete, className, tabIndex
|
|
22
|
-
|
|
23
|
-
const isRemovable = Boolean(onDelete);
|
|
24
|
-
const handleMouseEnter = (event) => {
|
|
25
|
-
var _a;
|
|
26
|
-
if (!isRemovable) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if ((_a = deleteButtonRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.target)) {
|
|
30
|
-
changeRestrictTooltipState(true);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
const handleMouseLeave = () => {
|
|
34
|
-
if (!isRemovable) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
changeRestrictTooltipState(false);
|
|
38
|
-
};
|
|
39
|
-
return (_jsxs("span", Object.assign({}, extractSupportProps(rest), { className: cn(styles.tag, className), "data-size": size, "data-appearance": appearance, "data-removable": isRemovable, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, children: [_jsx("span", { className: styles.label, children: label }), isRemovable && (_jsx("button", { type: 'button', className: styles.tagButton, onClick: onDelete, "data-test-id": 'tag-remove-button', tabIndex: tabIndex, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, ref: deleteButtonRef, children: size === SIZE.Xs ? (_jsx(CrossSVG, { size: ICON_SIZE[size], className: styles.icon })) : (_jsx(CrossSVG, { size: ICON_SIZE[size], className: styles.icon })) }))] })));
|
|
20
|
+
var { label, size = SIZE.Xs, appearance = APPEARANCE.Neutral, onDelete, className, tabIndex } = _a, rest = __rest(_a, ["label", "size", "appearance", "onDelete", "className", "tabIndex"]);
|
|
21
|
+
return (_jsxs("span", Object.assign({}, extractSupportProps(rest), { className: cn(styles.tag, className), "data-size": size, "data-appearance": appearance, "data-removable": Boolean(onDelete), children: [_jsx("span", { title: label, className: styles.label, children: label }), onDelete && (_jsx("button", { type: 'button', className: styles.tagButton, onClick: onDelete, "data-test-id": 'tag-remove-button', tabIndex: tabIndex, children: size === SIZE.Xs ? (_jsx(CrossSVG, { size: ICON_SIZE[size], className: styles.icon })) : (_jsx(CrossSVG, { size: ICON_SIZE[size], className: styles.icon })) }))] })));
|
|
40
22
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { MouseEvent } from 'react';
|
|
2
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
+
import { CommonTagProps } from '../../types';
|
|
4
|
+
export type TagLinkProps = WithSupportProps<CommonTagProps> & {
|
|
5
|
+
href: string;
|
|
6
|
+
onClick?(e: MouseEvent<HTMLAnchorElement>): void;
|
|
7
|
+
target?: HTMLAnchorElement['target'];
|
|
8
|
+
};
|
|
9
|
+
export declare function TagLink({ label, size, appearance, className, tabIndex, href, onClick, target, ...rest }: TagLinkProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -16,5 +16,5 @@ import { APPEARANCE, SIZE } from '../../constants';
|
|
|
16
16
|
import styles from './styles.module.css';
|
|
17
17
|
export function TagLink(_a) {
|
|
18
18
|
var { label, size = SIZE.Xs, appearance = APPEARANCE.Neutral, className, tabIndex, href, onClick, target } = _a, rest = __rest(_a, ["label", "size", "appearance", "className", "tabIndex", "href", "onClick", "target"]);
|
|
19
|
-
return (_jsx("a", Object.assign({}, extractSupportProps(rest), { className: cn(styles.tag, className), "data-size": size, "data-appearance": appearance, tabIndex: tabIndex, href: href, target: target, onClick: onClick, children: _jsx("span", { className: styles.label, children: label }) })));
|
|
19
|
+
return (_jsx("a", Object.assign({}, extractSupportProps(rest), { className: cn(styles.tag, className), "data-size": size, "data-appearance": appearance, tabIndex: tabIndex, href: href, target: target, onClick: onClick, children: _jsx("span", { title: label, className: styles.label, children: label }) })));
|
|
20
20
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { TagRowItem, TagRowItemInner } from '../../types';
|
|
2
|
-
export declare const mapTagRowItem: ({
|
|
2
|
+
export declare const mapTagRowItem: ({ label, appearance }: TagRowItem) => TagRowItemInner;
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
1
|
import { APPEARANCE } from '../../constants';
|
|
13
|
-
export const mapTagRowItem = (
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
export const mapTagRowItem = ({ label, appearance }) => {
|
|
3
|
+
if (appearance) {
|
|
4
|
+
return { label, appearance };
|
|
5
|
+
}
|
|
6
|
+
return {
|
|
7
|
+
label,
|
|
8
|
+
appearance: APPEARANCE.Neutral,
|
|
9
|
+
};
|
|
16
10
|
};
|
|
@@ -4,7 +4,7 @@ import { SIZE } from '../../constants';
|
|
|
4
4
|
import styles from './styles.module.css';
|
|
5
5
|
function renderTag(size, handleRemoveItem, setRef) {
|
|
6
6
|
return function TagRowItem(item, index) {
|
|
7
|
-
return (_jsx("div", { ref: setRef === null || setRef === void 0 ? void 0 : setRef(item, index), className: styles.tagWrapper, children: _jsx(Tag,
|
|
7
|
+
return (_jsx("div", { ref: setRef === null || setRef === void 0 ? void 0 : setRef(item, index), className: styles.tagWrapper, children: _jsx(Tag, { label: item.label, appearance: item.appearance, size: size, onDelete: handleRemoveItem === null || handleRemoveItem === void 0 ? void 0 : handleRemoveItem(item) }) }, item.label));
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
export function TagList({ items, size = SIZE.Xs, onItemRemove, setTagRef }) {
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { MouseEvent
|
|
2
|
-
import {
|
|
3
|
-
import { ValueOf, WithSupportProps } from '@snack-uikit/utils';
|
|
1
|
+
import { MouseEvent } from 'react';
|
|
2
|
+
import { ValueOf } from '@snack-uikit/utils';
|
|
4
3
|
import { APPEARANCE, SIZE } from './constants';
|
|
5
4
|
export type Appearance = ValueOf<typeof APPEARANCE>;
|
|
6
5
|
export type Size = ValueOf<typeof SIZE>;
|
|
@@ -9,17 +8,14 @@ export type LinkProps = {
|
|
|
9
8
|
onClick?(e: MouseEvent<HTMLAnchorElement>): void;
|
|
10
9
|
target?: HTMLAnchorElement['target'];
|
|
11
10
|
};
|
|
12
|
-
export type TagTooltipProps = {
|
|
13
|
-
/** Тултип над тегом */
|
|
14
|
-
tooltip?: TooltipProps;
|
|
15
|
-
};
|
|
16
11
|
export type TagRowItem = {
|
|
17
12
|
label: string;
|
|
18
13
|
appearance?: Appearance;
|
|
19
|
-
} & Partial<LinkProps
|
|
20
|
-
export type TagRowItemInner =
|
|
14
|
+
} & Partial<LinkProps>;
|
|
15
|
+
export type TagRowItemInner = {
|
|
16
|
+
label: string;
|
|
21
17
|
appearance: Appearance;
|
|
22
|
-
}
|
|
18
|
+
} & Partial<LinkProps>;
|
|
23
19
|
export type CommonTagProps = {
|
|
24
20
|
/** Текст */
|
|
25
21
|
label: string;
|
|
@@ -32,15 +28,3 @@ export type CommonTagProps = {
|
|
|
32
28
|
/** tabIndex кнопки удаления */
|
|
33
29
|
tabIndex?: number;
|
|
34
30
|
};
|
|
35
|
-
export type TagBaseProps = WithSupportProps<{
|
|
36
|
-
/** Коллбэк на удаление */
|
|
37
|
-
onDelete?: MouseEventHandler<HTMLButtonElement>;
|
|
38
|
-
}> & CommonTagProps;
|
|
39
|
-
export type TagLinkProps = WithSupportProps<CommonTagProps> & {
|
|
40
|
-
href: string;
|
|
41
|
-
onClick?(e: MouseEvent<HTMLAnchorElement>): void;
|
|
42
|
-
target?: HTMLAnchorElement['target'];
|
|
43
|
-
};
|
|
44
|
-
export type ManageRestrictPopoverProps = {
|
|
45
|
-
changeRestrictTooltipState: (state: boolean) => void;
|
|
46
|
-
};
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Tag",
|
|
7
|
-
"version": "0.12.11
|
|
7
|
+
"version": "0.12.11",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -37,11 +37,10 @@
|
|
|
37
37
|
"scripts": {},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@snack-uikit/dropdown": "0.4.7",
|
|
40
|
-
"@snack-uikit/icons": "0.26.
|
|
40
|
+
"@snack-uikit/icons": "0.26.2",
|
|
41
41
|
"@snack-uikit/scroll": "0.9.5",
|
|
42
|
-
"@snack-uikit/tooltip": "0.17.0",
|
|
43
42
|
"@snack-uikit/utils": "3.8.1",
|
|
44
43
|
"classnames": "2.5.1"
|
|
45
44
|
},
|
|
46
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "e14c6ec6fbc59b086b7ed348403eb1bac740b9c3"
|
|
47
46
|
}
|
|
@@ -1,38 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TagBase, TagBaseProps } from '../TagBase';
|
|
2
|
+
import { TagLink, TagLinkProps } from '../TagLink';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { TagBaseProps, TagLinkProps, TagTooltipProps } from '../../types';
|
|
6
|
-
import { TagBase } from '../TagBase';
|
|
7
|
-
import { TagLink } from '../TagLink';
|
|
8
|
-
|
|
9
|
-
export type TagProps = (TagBaseProps | TagLinkProps) & TagTooltipProps;
|
|
10
|
-
|
|
11
|
-
type ExtractTagProps<T> = T extends JSXElementConstructor<infer P> | ((props: infer P) => JSX.Element) ? P : never;
|
|
4
|
+
export type TagProps = TagBaseProps | TagLinkProps;
|
|
12
5
|
|
|
13
6
|
export function isTagLinkProps(props: TagProps): props is TagLinkProps {
|
|
14
7
|
return 'href' in props && props.href !== undefined;
|
|
15
8
|
}
|
|
16
9
|
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function Tag({ tooltip, ...props }: TagProps) {
|
|
22
|
-
const [restrictOpenTooltip, setRestrictOpenTooltip] = useState(false);
|
|
23
|
-
const removable = isRemovable(props);
|
|
24
|
-
|
|
25
|
-
const TagComponent = isTagLinkProps(props) ? TagLink : TagBase;
|
|
26
|
-
const TagWithTooltip = useElementWithTooltip({
|
|
27
|
-
Element: TagComponent,
|
|
28
|
-
tooltip: tooltip && {
|
|
29
|
-
...tooltip,
|
|
30
|
-
open: removable && restrictOpenTooltip ? false : tooltip.open,
|
|
31
|
-
},
|
|
32
|
-
});
|
|
10
|
+
export function Tag(props: TagProps) {
|
|
11
|
+
if (isTagLinkProps(props)) {
|
|
12
|
+
return <TagLink {...props} />;
|
|
13
|
+
}
|
|
33
14
|
|
|
34
|
-
|
|
35
|
-
typeof TagWithTooltip
|
|
36
|
-
>;
|
|
37
|
-
return <TagWithTooltip {...tagProps} />;
|
|
15
|
+
return <TagBase {...props} />;
|
|
38
16
|
}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import cn from 'classnames';
|
|
2
|
-
import {
|
|
2
|
+
import { MouseEventHandler } from 'react';
|
|
3
3
|
|
|
4
4
|
import { CrossSVG } from '@snack-uikit/icons';
|
|
5
|
-
import { extractSupportProps } from '@snack-uikit/utils';
|
|
5
|
+
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
6
6
|
|
|
7
7
|
import { APPEARANCE, SIZE } from '../../constants';
|
|
8
|
-
import {
|
|
8
|
+
import { CommonTagProps } from '../../types';
|
|
9
9
|
import { ICON_SIZE } from './constants';
|
|
10
10
|
import styles from './styles.module.scss';
|
|
11
11
|
|
|
12
|
-
export type
|
|
12
|
+
export type TagBaseProps = WithSupportProps<{
|
|
13
|
+
/** Коллбэк на удаление */
|
|
14
|
+
onDelete?: MouseEventHandler<HTMLButtonElement>;
|
|
15
|
+
}> &
|
|
16
|
+
CommonTagProps;
|
|
13
17
|
|
|
14
18
|
export function TagBase({
|
|
15
19
|
label,
|
|
@@ -18,52 +22,26 @@ export function TagBase({
|
|
|
18
22
|
onDelete,
|
|
19
23
|
className,
|
|
20
24
|
tabIndex,
|
|
21
|
-
changeRestrictTooltipState,
|
|
22
25
|
...rest
|
|
23
|
-
}:
|
|
24
|
-
const deleteButtonRef = useRef<HTMLButtonElement>(null);
|
|
25
|
-
|
|
26
|
-
const isRemovable = Boolean(onDelete);
|
|
27
|
-
|
|
28
|
-
const handleMouseEnter = (event: MouseEvent<HTMLButtonElement>) => {
|
|
29
|
-
if (!isRemovable) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (deleteButtonRef.current?.contains(event.target as Node)) {
|
|
34
|
-
changeRestrictTooltipState(true);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const handleMouseLeave = () => {
|
|
39
|
-
if (!isRemovable) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
changeRestrictTooltipState(false);
|
|
44
|
-
};
|
|
45
|
-
|
|
26
|
+
}: TagBaseProps) {
|
|
46
27
|
return (
|
|
47
28
|
<span
|
|
48
29
|
{...extractSupportProps(rest)}
|
|
49
30
|
className={cn(styles.tag, className)}
|
|
50
31
|
data-size={size}
|
|
51
32
|
data-appearance={appearance}
|
|
52
|
-
data-removable={
|
|
53
|
-
onMouseEnter={handleMouseEnter}
|
|
54
|
-
onMouseLeave={handleMouseLeave}
|
|
33
|
+
data-removable={Boolean(onDelete)}
|
|
55
34
|
>
|
|
56
|
-
<span className={styles.label}>
|
|
57
|
-
|
|
35
|
+
<span title={label} className={styles.label}>
|
|
36
|
+
{label}
|
|
37
|
+
</span>
|
|
38
|
+
{onDelete && (
|
|
58
39
|
<button
|
|
59
40
|
type='button'
|
|
60
41
|
className={styles.tagButton}
|
|
61
42
|
onClick={onDelete}
|
|
62
43
|
data-test-id='tag-remove-button'
|
|
63
44
|
tabIndex={tabIndex}
|
|
64
|
-
onMouseEnter={handleMouseEnter}
|
|
65
|
-
onMouseLeave={handleMouseLeave}
|
|
66
|
-
ref={deleteButtonRef}
|
|
67
45
|
>
|
|
68
46
|
{size === SIZE.Xs ? (
|
|
69
47
|
<CrossSVG size={ICON_SIZE[size]} className={styles.icon} />
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import cn from 'classnames';
|
|
2
|
+
import { MouseEvent } from 'react';
|
|
2
3
|
|
|
3
|
-
import { extractSupportProps } from '@snack-uikit/utils';
|
|
4
|
+
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
4
5
|
|
|
5
6
|
import { APPEARANCE, SIZE } from '../../constants';
|
|
6
|
-
import {
|
|
7
|
+
import { CommonTagProps } from '../../types';
|
|
7
8
|
import styles from './styles.module.scss';
|
|
8
9
|
|
|
9
|
-
export type
|
|
10
|
+
export type TagLinkProps = WithSupportProps<CommonTagProps> & {
|
|
11
|
+
href: string;
|
|
12
|
+
onClick?(e: MouseEvent<HTMLAnchorElement>): void;
|
|
13
|
+
target?: HTMLAnchorElement['target'];
|
|
14
|
+
};
|
|
10
15
|
|
|
11
16
|
export function TagLink({
|
|
12
17
|
label,
|
|
@@ -18,7 +23,7 @@ export function TagLink({
|
|
|
18
23
|
onClick,
|
|
19
24
|
target,
|
|
20
25
|
...rest
|
|
21
|
-
}:
|
|
26
|
+
}: TagLinkProps) {
|
|
22
27
|
return (
|
|
23
28
|
<a
|
|
24
29
|
{...extractSupportProps(rest)}
|
|
@@ -30,7 +35,9 @@ export function TagLink({
|
|
|
30
35
|
target={target}
|
|
31
36
|
onClick={onClick}
|
|
32
37
|
>
|
|
33
|
-
<span className={styles.label}>
|
|
38
|
+
<span title={label} className={styles.label}>
|
|
39
|
+
{label}
|
|
40
|
+
</span>
|
|
34
41
|
</a>
|
|
35
42
|
);
|
|
36
43
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { APPEARANCE } from '../../constants';
|
|
2
2
|
import { TagRowItem, TagRowItemInner } from '../../types';
|
|
3
3
|
|
|
4
|
-
export const mapTagRowItem = ({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
4
|
+
export const mapTagRowItem = ({ label, appearance }: TagRowItem): TagRowItemInner => {
|
|
5
|
+
if (appearance) {
|
|
6
|
+
return { label, appearance };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
label,
|
|
11
|
+
appearance: APPEARANCE.Neutral,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -20,7 +20,7 @@ function renderTag(size: Size, handleRemoveItem?: (item: TagRowItemInner) => OnD
|
|
|
20
20
|
return function TagRowItem(item: TagRowItemInner, index: number) {
|
|
21
21
|
return (
|
|
22
22
|
<div key={item.label} ref={setRef?.(item, index)} className={styles.tagWrapper}>
|
|
23
|
-
<Tag size={size} onDelete={handleRemoveItem?.(item)}
|
|
23
|
+
<Tag label={item.label} appearance={item.appearance} size={size} onDelete={handleRemoveItem?.(item)} />
|
|
24
24
|
</div>
|
|
25
25
|
);
|
|
26
26
|
};
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { MouseEvent
|
|
1
|
+
import { MouseEvent } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { ValueOf, WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
+
import { ValueOf } from '@snack-uikit/utils';
|
|
5
4
|
|
|
6
5
|
import { APPEARANCE, SIZE } from './constants';
|
|
7
6
|
|
|
@@ -15,20 +14,15 @@ export type LinkProps = {
|
|
|
15
14
|
target?: HTMLAnchorElement['target'];
|
|
16
15
|
};
|
|
17
16
|
|
|
18
|
-
export type TagTooltipProps = {
|
|
19
|
-
/** Тултип над тегом */
|
|
20
|
-
tooltip?: TooltipProps;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
17
|
export type TagRowItem = {
|
|
24
18
|
label: string;
|
|
25
19
|
appearance?: Appearance;
|
|
26
|
-
} & Partial<LinkProps
|
|
27
|
-
TagTooltipProps;
|
|
20
|
+
} & Partial<LinkProps>;
|
|
28
21
|
|
|
29
|
-
export type TagRowItemInner =
|
|
22
|
+
export type TagRowItemInner = {
|
|
23
|
+
label: string;
|
|
30
24
|
appearance: Appearance;
|
|
31
|
-
}
|
|
25
|
+
} & Partial<LinkProps>;
|
|
32
26
|
|
|
33
27
|
export type CommonTagProps = {
|
|
34
28
|
/** Текст */
|
|
@@ -42,19 +36,3 @@ export type CommonTagProps = {
|
|
|
42
36
|
/** tabIndex кнопки удаления */
|
|
43
37
|
tabIndex?: number;
|
|
44
38
|
};
|
|
45
|
-
|
|
46
|
-
export type TagBaseProps = WithSupportProps<{
|
|
47
|
-
/** Коллбэк на удаление */
|
|
48
|
-
onDelete?: MouseEventHandler<HTMLButtonElement>;
|
|
49
|
-
}> &
|
|
50
|
-
CommonTagProps;
|
|
51
|
-
|
|
52
|
-
export type TagLinkProps = WithSupportProps<CommonTagProps> & {
|
|
53
|
-
href: string;
|
|
54
|
-
onClick?(e: MouseEvent<HTMLAnchorElement>): void;
|
|
55
|
-
target?: HTMLAnchorElement['target'];
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export type ManageRestrictPopoverProps = {
|
|
59
|
-
changeRestrictTooltipState: (state: boolean) => void;
|
|
60
|
-
};
|