@cloud-ru/ds-tag 1.1.21-preview-06965406.0 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-ru/ds-tag",
3
- "version": "1.1.21-preview-06965406.0",
3
+ "version": "1.2.0",
4
4
  "description": "Пакет компактных меток — компонент Tag (опционально удаляемый или ссылочный) и контейнер TagRow для групп меток с обрезанием по строкам.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,12 +34,13 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "classnames": "^2.5.1",
37
- "@cloud-ru/ds-dropdown": "1.1.11-preview-06965406.0",
38
- "@cloud-ru/ds-icons": "1.7.2",
39
- "@cloud-ru/ds-materials": "2.0.2",
40
- "@cloud-ru/ds-truncate-string": "1.0.18",
41
- "@cloud-ru/ds-utils": "1.3.0",
42
- "@cloud-ru/ds-scroll": "1.0.6"
37
+ "@cloud-ru/ds-materials": "^2.0.2",
38
+ "@cloud-ru/ds-scroll": "^1.0.6",
39
+ "@cloud-ru/ds-truncate-string": "^1.0.19",
40
+ "@cloud-ru/ds-tooltip": "^1.0.18",
41
+ "@cloud-ru/ds-dropdown": "^1.2.0",
42
+ "@cloud-ru/ds-utils": "^1.3.0",
43
+ "@cloud-ru/ds-icons": "^1.7.2"
43
44
  },
44
45
  "publishConfig": {
45
46
  "access": "public"
@@ -1,4 +1,6 @@
1
+ import { WithTooltip } from '@cloud-ru/ds-tooltip';
1
2
  import { withInnerRefSupport } from '@cloud-ru/ds-utils';
3
+ import { useState } from 'react';
2
4
 
3
5
  import { TagLinkProps, TagProps } from '../../types';
4
6
  import { TagBase } from '../TagBase';
@@ -8,8 +10,22 @@ export function isTagLinkProps(props: TagProps): props is TagLinkProps {
8
10
  return 'href' in props && props.href !== undefined;
9
11
  }
10
12
 
11
- export function Tag(props: TagProps) {
12
- return isTagLinkProps(props) ? <TagLink {...props} /> : <TagBase {...props} />;
13
+ export function Tag({ tooltip, ...props }: TagProps) {
14
+ const [restrictOpenTooltip, setRestrictOpenTooltip] = useState(false);
15
+
16
+ return (
17
+ <WithTooltip tooltip={tooltip && { ...tooltip, open: restrictOpenTooltip ? false : tooltip.open }}>
18
+ {isTagLinkProps(props) ? (
19
+ <TagLink {...props} />
20
+ ) : (
21
+ <TagBase
22
+ {...props}
23
+ changeRestrictTooltipState={tooltip ? setRestrictOpenTooltip : undefined}
24
+ hideTruncateTooltip={Boolean(tooltip)}
25
+ />
26
+ )}
27
+ </WithTooltip>
28
+ );
13
29
  }
14
30
 
15
31
  withInnerRefSupport(Tag);
@@ -17,8 +17,10 @@ export function TagBase({
17
17
  className,
18
18
  tabIndex,
19
19
  innerRef,
20
+ changeRestrictTooltipState,
21
+ hideTruncateTooltip,
20
22
  ...rest
21
- }: TagBaseProps) {
23
+ }: TagBaseProps & { changeRestrictTooltipState?: (state: boolean) => void; hideTruncateTooltip: boolean }) {
22
24
  const isRemovable = Boolean(onDelete);
23
25
 
24
26
  return (
@@ -31,13 +33,20 @@ export function TagBase({
31
33
  data-removable={isRemovable}
32
34
  >
33
35
  <span className={styles.textWrapper}>
34
- <TruncateString className={styles.label} text={label} variant={truncateVariant} />
36
+ <TruncateString
37
+ className={styles.label}
38
+ text={label}
39
+ variant={truncateVariant}
40
+ hideTooltip={hideTruncateTooltip}
41
+ />
35
42
  </span>
36
43
  {isRemovable && (
37
44
  <button
38
45
  type='button'
39
46
  className={styles.tagButton}
40
47
  onClick={onDelete}
48
+ onMouseEnter={() => changeRestrictTooltipState?.(true)}
49
+ onMouseLeave={() => changeRestrictTooltipState?.(false)}
41
50
  data-test-id={TEST_IDS.tag.removeButton}
42
51
  tabIndex={tabIndex}
43
52
  >
package/src/types.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { TooltipProps } from '@cloud-ru/ds-tooltip';
1
2
  import { TruncateStringProps } from '@cloud-ru/ds-truncate-string';
2
3
  import { PolymorphicRef, ValueOf, WithSupportProps } from '@cloud-ru/ds-utils';
3
4
  import { ComponentPropsWithoutRef, ElementType, MouseEvent, MouseEventHandler, Ref } from 'react';
@@ -14,11 +15,17 @@ export type LinkProps = {
14
15
  target?: HTMLAnchorElement['target'];
15
16
  };
16
17
 
18
+ export type TagTooltipProps = {
19
+ /** Тултип над тегом */
20
+ tooltip?: TooltipProps;
21
+ };
22
+
17
23
  export type TagRowItem = {
18
24
  id?: string;
19
25
  label: string;
20
26
  appearance?: Appearance;
21
- } & Partial<LinkProps>;
27
+ } & Partial<LinkProps> &
28
+ TagTooltipProps;
22
29
 
23
30
  export type TagRowItemInner = Omit<TagRowItem, 'appearance'> & {
24
31
  appearance: Appearance;
@@ -62,7 +69,9 @@ export type TagLinkProps<T extends ElementType = 'a'> = WithSupportProps<
62
69
  } & Omit<ComponentPropsWithoutRef<T>, keyof CommonTagProps | 'as' | 'ref'>
63
70
  >;
64
71
 
65
- export type TagProps = TagBaseProps | TagLinkProps;
72
+ export type TagWithTooltipProps = (TagBaseProps | TagLinkProps) & TagTooltipProps;
73
+
74
+ export type TagProps = TagWithTooltipProps;
66
75
 
67
76
  export type TagRowProps = WithSupportProps<{
68
77
  items: TagRowItem[];