@cloud-ru/ds-tag 1.0.0
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 +8 -0
- package/LICENSE +201 -0
- package/README.md +142 -0
- package/dist/cjs/components/Tag/Tag.d.ts +3 -0
- package/dist/cjs/components/Tag/Tag.js +15 -0
- package/dist/cjs/components/Tag/index.d.ts +1 -0
- package/dist/cjs/components/Tag/index.js +6 -0
- package/dist/cjs/components/TagBase/TagBase.d.ts +2 -0
- package/dist/cjs/components/TagBase/TagBase.js +18 -0
- package/dist/cjs/components/TagBase/constants.d.ts +2 -0
- package/dist/cjs/components/TagBase/constants.js +9 -0
- package/dist/cjs/components/TagBase/index.d.ts +1 -0
- package/dist/cjs/components/TagBase/index.js +5 -0
- package/dist/cjs/components/TagBase/styles.module.css +300 -0
- package/dist/cjs/components/TagLink/TagLink.d.ts +3 -0
- package/dist/cjs/components/TagLink/TagLink.js +30 -0
- package/dist/cjs/components/TagLink/index.d.ts +1 -0
- package/dist/cjs/components/TagLink/index.js +5 -0
- package/dist/cjs/components/TagRow/TagRow.d.ts +4 -0
- package/dist/cjs/components/TagRow/TagRow.js +16 -0
- package/dist/cjs/components/TagRow/index.d.ts +1 -0
- package/dist/cjs/components/TagRow/index.js +5 -0
- package/dist/cjs/components/TagRow/utils.d.ts +2 -0
- package/dist/cjs/components/TagRow/utils.js +9 -0
- package/dist/cjs/components/index.d.ts +2 -0
- package/dist/cjs/components/index.js +18 -0
- package/dist/cjs/constants.d.ts +32 -0
- package/dist/cjs/constants.js +35 -0
- package/dist/cjs/helperComponents/TagList/TagList.d.ts +11 -0
- package/dist/cjs/helperComponents/TagList/TagList.js +19 -0
- package/dist/cjs/helperComponents/TagList/index.d.ts +1 -0
- package/dist/cjs/helperComponents/TagList/index.js +5 -0
- package/dist/cjs/helperComponents/TagList/styles.module.css +4 -0
- package/dist/cjs/helperComponents/TagMore/TagMore.d.ts +11 -0
- package/dist/cjs/helperComponents/TagMore/TagMore.js +17 -0
- package/dist/cjs/helperComponents/TagMore/index.d.ts +1 -0
- package/dist/cjs/helperComponents/TagMore/index.js +5 -0
- package/dist/cjs/helperComponents/TagMore/styles.module.css +91 -0
- package/dist/cjs/helperComponents/TagRowSimple/TagRowSimple.d.ts +11 -0
- package/dist/cjs/helperComponents/TagRowSimple/TagRowSimple.js +14 -0
- package/dist/cjs/helperComponents/TagRowSimple/index.d.ts +1 -0
- package/dist/cjs/helperComponents/TagRowSimple/index.js +5 -0
- package/dist/cjs/helperComponents/TagRowSimple/styles.module.css +15 -0
- package/dist/cjs/helperComponents/TagRowTruncated/TagRowTruncated.d.ts +12 -0
- package/dist/cjs/helperComponents/TagRowTruncated/TagRowTruncated.js +86 -0
- package/dist/cjs/helperComponents/TagRowTruncated/hooks.d.ts +3 -0
- package/dist/cjs/helperComponents/TagRowTruncated/hooks.js +21 -0
- package/dist/cjs/helperComponents/TagRowTruncated/index.d.ts +1 -0
- package/dist/cjs/helperComponents/TagRowTruncated/index.js +5 -0
- package/dist/cjs/helperComponents/TagRowTruncated/styles.module.css +63 -0
- package/dist/cjs/helperComponents/TagRowTruncated/utils.d.ts +2 -0
- package/dist/cjs/helperComponents/TagRowTruncated/utils.js +8 -0
- package/dist/cjs/helperComponents/index.d.ts +2 -0
- package/dist/cjs/helperComponents/index.js +18 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/style.css +473 -0
- package/dist/cjs/types.d.ts +57 -0
- package/dist/cjs/types.js +2 -0
- package/dist/esm/components/Tag/Tag.d.ts +3 -0
- package/dist/esm/components/Tag/Tag.js +11 -0
- package/dist/esm/components/Tag/index.d.ts +1 -0
- package/dist/esm/components/Tag/index.js +1 -0
- package/dist/esm/components/TagBase/TagBase.d.ts +2 -0
- package/dist/esm/components/TagBase/TagBase.js +12 -0
- package/dist/esm/components/TagBase/constants.d.ts +2 -0
- package/dist/esm/components/TagBase/constants.js +6 -0
- package/dist/esm/components/TagBase/index.d.ts +1 -0
- package/dist/esm/components/TagBase/index.js +1 -0
- package/dist/esm/components/TagBase/styles.module.css +300 -0
- package/dist/esm/components/TagLink/TagLink.d.ts +3 -0
- package/dist/esm/components/TagLink/TagLink.js +24 -0
- package/dist/esm/components/TagLink/index.d.ts +1 -0
- package/dist/esm/components/TagLink/index.js +1 -0
- package/dist/esm/components/TagRow/TagRow.d.ts +4 -0
- package/dist/esm/components/TagRow/TagRow.js +13 -0
- package/dist/esm/components/TagRow/index.d.ts +1 -0
- package/dist/esm/components/TagRow/index.js +1 -0
- package/dist/esm/components/TagRow/utils.d.ts +2 -0
- package/dist/esm/components/TagRow/utils.js +5 -0
- package/dist/esm/components/index.d.ts +2 -0
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/constants.d.ts +32 -0
- package/dist/esm/constants.js +32 -0
- package/dist/esm/helperComponents/TagList/TagList.d.ts +11 -0
- package/dist/esm/helperComponents/TagList/TagList.js +13 -0
- package/dist/esm/helperComponents/TagList/index.d.ts +1 -0
- package/dist/esm/helperComponents/TagList/index.js +1 -0
- package/dist/esm/helperComponents/TagList/styles.module.css +4 -0
- package/dist/esm/helperComponents/TagMore/TagMore.d.ts +11 -0
- package/dist/esm/helperComponents/TagMore/TagMore.js +11 -0
- package/dist/esm/helperComponents/TagMore/index.d.ts +1 -0
- package/dist/esm/helperComponents/TagMore/index.js +1 -0
- package/dist/esm/helperComponents/TagMore/styles.module.css +91 -0
- package/dist/esm/helperComponents/TagRowSimple/TagRowSimple.d.ts +11 -0
- package/dist/esm/helperComponents/TagRowSimple/TagRowSimple.js +8 -0
- package/dist/esm/helperComponents/TagRowSimple/index.d.ts +1 -0
- package/dist/esm/helperComponents/TagRowSimple/index.js +1 -0
- package/dist/esm/helperComponents/TagRowSimple/styles.module.css +15 -0
- package/dist/esm/helperComponents/TagRowTruncated/TagRowTruncated.d.ts +12 -0
- package/dist/esm/helperComponents/TagRowTruncated/TagRowTruncated.js +80 -0
- package/dist/esm/helperComponents/TagRowTruncated/hooks.d.ts +3 -0
- package/dist/esm/helperComponents/TagRowTruncated/hooks.js +17 -0
- package/dist/esm/helperComponents/TagRowTruncated/index.d.ts +1 -0
- package/dist/esm/helperComponents/TagRowTruncated/index.js +1 -0
- package/dist/esm/helperComponents/TagRowTruncated/styles.module.css +63 -0
- package/dist/esm/helperComponents/TagRowTruncated/utils.d.ts +2 -0
- package/dist/esm/helperComponents/TagRowTruncated/utils.js +4 -0
- package/dist/esm/helperComponents/index.d.ts +2 -0
- package/dist/esm/helperComponents/index.js +2 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/style.css +473 -0
- package/dist/esm/types.d.ts +57 -0
- package/dist/esm/types.js +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +46 -0
- package/src/components/Tag/Tag.tsx +15 -0
- package/src/components/Tag/index.ts +1 -0
- package/src/components/TagBase/TagBase.tsx +51 -0
- package/src/components/TagBase/constants.ts +7 -0
- package/src/components/TagBase/index.ts +1 -0
- package/src/components/TagBase/styles.module.scss +169 -0
- package/src/components/TagLink/TagLink.tsx +66 -0
- package/src/components/TagLink/index.ts +1 -0
- package/src/components/TagRow/TagRow.tsx +18 -0
- package/src/components/TagRow/index.ts +1 -0
- package/src/components/TagRow/utils.ts +7 -0
- package/src/components/index.ts +2 -0
- package/src/constants.ts +34 -0
- package/src/helperComponents/TagList/TagList.tsx +33 -0
- package/src/helperComponents/TagList/index.ts +1 -0
- package/src/helperComponents/TagList/styles.module.scss +6 -0
- package/src/helperComponents/TagMore/TagMore.tsx +49 -0
- package/src/helperComponents/TagMore/index.ts +1 -0
- package/src/helperComponents/TagMore/styles.module.scss +68 -0
- package/src/helperComponents/TagRowSimple/TagRowSimple.tsx +23 -0
- package/src/helperComponents/TagRowSimple/index.ts +1 -0
- package/src/helperComponents/TagRowSimple/styles.module.scss +5 -0
- package/src/helperComponents/TagRowTruncated/TagRowTruncated.tsx +139 -0
- package/src/helperComponents/TagRowTruncated/hooks.ts +23 -0
- package/src/helperComponents/TagRowTruncated/index.ts +1 -0
- package/src/helperComponents/TagRowTruncated/styles.module.scss +34 -0
- package/src/helperComponents/TagRowTruncated/utils.ts +7 -0
- package/src/helperComponents/index.ts +2 -0
- package/src/helperComponents/styles/_tagRowLayout.scss +19 -0
- package/src/index.ts +4 -0
- package/src/types.ts +71 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TagRowSimple } from './TagRowSimple.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TagRowSimple } from './TagRowSimple.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.tagRowSimpleWrapper{
|
|
2
|
+
display:flex;
|
|
3
|
+
flex-wrap:wrap;
|
|
4
|
+
align-content:flex-start;
|
|
5
|
+
align-items:flex-start;
|
|
6
|
+
}
|
|
7
|
+
.tagRowSimpleWrapper[data-size=xs]{
|
|
8
|
+
gap:var(--sn-tag-anatomy-size-xs-tagRow-gap, var(--sn-density-spacing-control-wrapper-horizontal-xs, var(--sn-primitive-dimension-8, 8px)));
|
|
9
|
+
}
|
|
10
|
+
.tagRowSimpleWrapper[data-size=s]{
|
|
11
|
+
gap:var(--sn-tag-anatomy-size-s-tagRow-gap, var(--sn-primitive-dimension-2, 2px));
|
|
12
|
+
}
|
|
13
|
+
.tagRowSimpleWrapper[data-size=m]{
|
|
14
|
+
gap:var(--sn-tag-anatomy-size-m-tagRow-gap, var(--sn-primitive-dimension-4, 4px));
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Size, TagRowItemInner } from '../../types.js';
|
|
2
|
+
type TagRowTruncatedProps = {
|
|
3
|
+
items: TagRowItemInner[];
|
|
4
|
+
rowLimit: number;
|
|
5
|
+
moreButtonLabel?: string;
|
|
6
|
+
size: Size;
|
|
7
|
+
className?: string;
|
|
8
|
+
onItemRemove?(item: string): void;
|
|
9
|
+
};
|
|
10
|
+
declare function TagRowTruncatedInner({ items, rowLimit, size, moreButtonLabel, className, onItemRemove, ...rest }: TagRowTruncatedProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare const TagRowTruncated: import("react").MemoExoticComponent<typeof TagRowTruncatedInner>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { extractSupportProps } from '@cloud-ru/ds-utils';
|
|
3
|
+
import cn from 'classnames';
|
|
4
|
+
import { memo, useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { TEST_IDS } from '../../constants.js';
|
|
6
|
+
import { TagList } from '../TagList/index.js';
|
|
7
|
+
import { TagMore } from '../TagMore/index.js';
|
|
8
|
+
import { useResizeObserver } from './hooks.js';
|
|
9
|
+
import styles from './styles.module.css';
|
|
10
|
+
import { getGapWidth } from './utils.js';
|
|
11
|
+
function setTagElement(tag, index, setFirstTagElement, tagsMapRef) {
|
|
12
|
+
return (tagElement) => {
|
|
13
|
+
if (index === 0 && tagElement) {
|
|
14
|
+
setFirstTagElement(tagElement);
|
|
15
|
+
}
|
|
16
|
+
if (tagElement === null) {
|
|
17
|
+
tagsMapRef.current.delete(tag);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
tagsMapRef.current.set(tag, tagElement);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function TagRowTruncatedInner({ items, rowLimit, size, moreButtonLabel = '', className, onItemRemove, ...rest }) {
|
|
25
|
+
const [visibleTags, setVisibleTags] = useState([]);
|
|
26
|
+
const [hiddenTags, setHiddenTags] = useState([]);
|
|
27
|
+
const hiddenRowElementRef = useRef(null);
|
|
28
|
+
const hiddenMoreButtonRef = useRef(null);
|
|
29
|
+
const [firstTagElement, setFirstTagElement] = useState(null);
|
|
30
|
+
const tagsMapRef = useRef(new Map());
|
|
31
|
+
const { width: maxWidth } = useResizeObserver(hiddenRowElementRef.current);
|
|
32
|
+
useResizeObserver(firstTagElement);
|
|
33
|
+
const gapWidth = getGapWidth(hiddenRowElementRef);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (maxWidth < 1) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const newVisibleTags = [];
|
|
39
|
+
const newHiddenTags = [];
|
|
40
|
+
const moreButtonWidth = hiddenMoreButtonRef.current?.offsetWidth || 0;
|
|
41
|
+
let currentRowWidth = 0;
|
|
42
|
+
let currentRowCount = 1;
|
|
43
|
+
let currentRowVisibleTagAmount = 0;
|
|
44
|
+
tagsMapRef.current.forEach((tagElement, tagRowItem) => {
|
|
45
|
+
const tagWidth = tagElement?.offsetWidth || 0;
|
|
46
|
+
const sumRowWidth = currentRowWidth + tagWidth + gapWidth;
|
|
47
|
+
if (currentRowCount > rowLimit) {
|
|
48
|
+
newHiddenTags.push(tagRowItem);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (currentRowCount === rowLimit) {
|
|
52
|
+
if (sumRowWidth + moreButtonWidth > maxWidth) {
|
|
53
|
+
currentRowCount++;
|
|
54
|
+
currentRowVisibleTagAmount = 0;
|
|
55
|
+
newHiddenTags.push(tagRowItem);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
currentRowWidth = sumRowWidth;
|
|
59
|
+
newVisibleTags.push(tagRowItem);
|
|
60
|
+
currentRowVisibleTagAmount++;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (sumRowWidth > maxWidth) {
|
|
64
|
+
currentRowWidth = currentRowVisibleTagAmount ? tagWidth + gapWidth : 0;
|
|
65
|
+
currentRowCount++;
|
|
66
|
+
currentRowVisibleTagAmount = 0;
|
|
67
|
+
newVisibleTags.push(tagRowItem);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
currentRowVisibleTagAmount++;
|
|
71
|
+
currentRowWidth = sumRowWidth;
|
|
72
|
+
newVisibleTags.push(tagRowItem);
|
|
73
|
+
});
|
|
74
|
+
setVisibleTags(newVisibleTags);
|
|
75
|
+
setHiddenTags(newHiddenTags);
|
|
76
|
+
}, [items, rowLimit, maxWidth, gapWidth]);
|
|
77
|
+
const setTagRef = (item, index) => setTagElement(item, index, setFirstTagElement, tagsMapRef);
|
|
78
|
+
return (_jsxs("div", { className: cn(styles.wrapper, className), ...extractSupportProps(rest), "data-size": size, children: [_jsx("div", { className: styles.hiddenRow, ref: hiddenRowElementRef, "data-size": size, children: _jsx(TagList, { items: items, size: size, onItemRemove: onItemRemove, setTagRef: setTagRef }) }), _jsx("div", { className: styles.hiddenMoreButton, children: _jsx(TagMore, { items: items, text: moreButtonLabel, size: size, buttonRef: hiddenMoreButtonRef }) }), _jsxs("div", { className: styles.visibleRow, "data-size": size, "data-test-id": TEST_IDS.tagRow.visibleTagsWrapper, children: [_jsx(TagList, { items: visibleTags, size: size, onItemRemove: onItemRemove }), hiddenTags.length > 0 && (_jsx(TagMore, { items: hiddenTags, text: moreButtonLabel, size: size, onItemRemove: onItemRemove }))] })] }));
|
|
79
|
+
}
|
|
80
|
+
export const TagRowTruncated = memo(TagRowTruncatedInner);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export const useResizeObserver = (element) => {
|
|
3
|
+
const [width, setWidth] = useState(0);
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
if (!element) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
9
|
+
if (element.offsetWidth !== width) {
|
|
10
|
+
setWidth(element.offsetWidth);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
resizeObserver.observe(element);
|
|
14
|
+
return () => resizeObserver.disconnect();
|
|
15
|
+
}, [element, width]);
|
|
16
|
+
return { width };
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TagRowTruncated } from './TagRowTruncated.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TagRowTruncated } from './TagRowTruncated.js';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
.wrapper{
|
|
2
|
+
position:relative;
|
|
3
|
+
overflow:hidden;
|
|
4
|
+
width:100%;
|
|
5
|
+
max-width:100%;
|
|
6
|
+
display:flex;
|
|
7
|
+
flex-wrap:wrap;
|
|
8
|
+
align-content:flex-start;
|
|
9
|
+
align-items:flex-start;
|
|
10
|
+
}
|
|
11
|
+
.wrapper[data-size=xs]{
|
|
12
|
+
gap:var(--sn-tag-anatomy-size-xs-tagRow-gap, var(--sn-density-spacing-control-wrapper-horizontal-xs, var(--sn-primitive-dimension-8, 8px)));
|
|
13
|
+
}
|
|
14
|
+
.wrapper[data-size=s]{
|
|
15
|
+
gap:var(--sn-tag-anatomy-size-s-tagRow-gap, var(--sn-primitive-dimension-2, 2px));
|
|
16
|
+
}
|
|
17
|
+
.wrapper[data-size=m]{
|
|
18
|
+
gap:var(--sn-tag-anatomy-size-m-tagRow-gap, var(--sn-primitive-dimension-4, 4px));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.visibleRow{
|
|
22
|
+
max-width:100%;
|
|
23
|
+
display:flex;
|
|
24
|
+
flex-wrap:wrap;
|
|
25
|
+
align-content:flex-start;
|
|
26
|
+
align-items:flex-start;
|
|
27
|
+
}
|
|
28
|
+
.visibleRow[data-size=xs]{
|
|
29
|
+
gap:var(--sn-tag-anatomy-size-xs-tagRow-gap, var(--sn-density-spacing-control-wrapper-horizontal-xs, var(--sn-primitive-dimension-8, 8px)));
|
|
30
|
+
}
|
|
31
|
+
.visibleRow[data-size=s]{
|
|
32
|
+
gap:var(--sn-tag-anatomy-size-s-tagRow-gap, var(--sn-primitive-dimension-2, 2px));
|
|
33
|
+
}
|
|
34
|
+
.visibleRow[data-size=m]{
|
|
35
|
+
gap:var(--sn-tag-anatomy-size-m-tagRow-gap, var(--sn-primitive-dimension-4, 4px));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.hiddenRow{
|
|
39
|
+
position:absolute;
|
|
40
|
+
top:0;
|
|
41
|
+
left:0;
|
|
42
|
+
width:100%;
|
|
43
|
+
visibility:hidden;
|
|
44
|
+
display:flex;
|
|
45
|
+
flex-wrap:wrap;
|
|
46
|
+
align-content:flex-start;
|
|
47
|
+
align-items:flex-start;
|
|
48
|
+
}
|
|
49
|
+
.hiddenRow[data-size=xs]{
|
|
50
|
+
gap:var(--sn-tag-anatomy-size-xs-tagRow-gap, var(--sn-density-spacing-control-wrapper-horizontal-xs, var(--sn-primitive-dimension-8, 8px)));
|
|
51
|
+
}
|
|
52
|
+
.hiddenRow[data-size=s]{
|
|
53
|
+
gap:var(--sn-tag-anatomy-size-s-tagRow-gap, var(--sn-primitive-dimension-2, 2px));
|
|
54
|
+
}
|
|
55
|
+
.hiddenRow[data-size=m]{
|
|
56
|
+
gap:var(--sn-tag-anatomy-size-m-tagRow-gap, var(--sn-primitive-dimension-4, 4px));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.hiddenMoreButton{
|
|
60
|
+
position:absolute;
|
|
61
|
+
left:0;
|
|
62
|
+
visibility:hidden;
|
|
63
|
+
}
|