@purpurds/tooltip 7.6.0 → 7.7.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": "@purpurds/tooltip",
3
- "version": "7.6.0",
3
+ "version": "7.7.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "./dist/tooltip.cjs.js",
6
6
  "types": "./dist/tooltip.d.ts",
@@ -17,11 +17,12 @@
17
17
  "dependencies": {
18
18
  "@radix-ui/react-tooltip": "~1.1.8",
19
19
  "classnames": "~2.5.0",
20
- "@purpurds/paragraph": "7.6.0",
21
- "@purpurds/action": "7.6.0",
22
- "@purpurds/button": "7.6.0",
23
- "@purpurds/icon": "7.6.0",
24
- "@purpurds/tokens": "7.6.0"
20
+ "@purpurds/action": "7.7.0",
21
+ "@purpurds/button": "7.7.0",
22
+ "@purpurds/common-types": "7.7.0",
23
+ "@purpurds/icon": "7.7.0",
24
+ "@purpurds/paragraph": "7.7.0",
25
+ "@purpurds/tokens": "7.7.0"
25
26
  },
26
27
  "devDependencies": {
27
28
  "eslint": "9.24.0",
@@ -23,7 +23,7 @@ const meta = {
23
23
  align: "center",
24
24
  position: "top",
25
25
  triggerElement: undefined,
26
- triggerAriaLabel: "Tooltip trigger",
26
+ triggerAriaLabel: "Tooltip about the text that is about to be shown",
27
27
  negative: false,
28
28
  children: "Some tooltip content",
29
29
  },
package/src/tooltip.tsx CHANGED
@@ -1,13 +1,7 @@
1
- import React, {
2
- Children,
3
- type ForwardedRef,
4
- forwardRef,
5
- type HTMLAttributes,
6
- type ReactNode,
7
- useState,
8
- } from "react";
1
+ import React, { Children, forwardRef, type ReactNode, useState } from "react";
9
2
  import { type Size } from "@purpurds/action";
10
3
  import { Button, BUTTON_VARIANT } from "@purpurds/button";
4
+ import type { BaseProps } from "@purpurds/common-types";
11
5
  import { IconInfo } from "@purpurds/icon/info";
12
6
  import { Paragraph, ParagraphVariant } from "@purpurds/paragraph";
13
7
  import { purpurMotionDuration400 } from "@purpurds/tokens";
@@ -24,6 +18,7 @@ export const TOOLTIP_POSITION = {
24
18
  LEFT: "left",
25
19
  RIGHT: "right",
26
20
  } as const;
21
+
27
22
  export type TooltipPosition = (typeof TOOLTIP_POSITION)[keyof typeof TOOLTIP_POSITION];
28
23
 
29
24
  export const TOOLTIP_ALIGN = {
@@ -43,13 +38,12 @@ type WithoutTriggeElement = {
43
38
  triggerAriaLabel: string;
44
39
  };
45
40
 
46
- export type TooltipProps = HTMLAttributes<HTMLDivElement> & {
41
+ export type TooltipProps = Omit<BaseProps, "children"> & {
47
42
  align?: TooltipAlign;
48
43
  buttonSize?: Size;
49
44
  children: ReactNode;
50
45
  negative?: boolean;
51
46
  position?: TooltipPosition;
52
- ["data-testid"]?: string;
53
47
  triggerAriaLabel?: string;
54
48
  triggerElement?: ReactNode;
55
49
  contentClassName?: string;
@@ -57,7 +51,7 @@ export type TooltipProps = HTMLAttributes<HTMLDivElement> & {
57
51
 
58
52
  const rootClassName = "purpur-tooltip";
59
53
 
60
- export const Tooltip = forwardRef(
54
+ export const Tooltip = forwardRef<HTMLButtonElement, TooltipProps>(
61
55
  (
62
56
  {
63
57
  ["data-testid"]: dataTestId,
@@ -71,19 +65,20 @@ export const Tooltip = forwardRef(
71
65
  triggerAriaLabel,
72
66
  triggerElement,
73
67
  ...props
74
- }: TooltipProps,
75
- ref: ForwardedRef<HTMLButtonElement>
68
+ },
69
+ ref
76
70
  ) => {
77
71
  const [isOpen, setIsOpen] = useState(false);
78
- const classes = cx([
72
+ const classes = cx(
79
73
  className,
80
74
  rootClassName,
81
- `${rootClassName}--primary${negative ? "-negative" : ""}`,
82
- ]);
75
+ `${rootClassName}--primary${negative ? "-negative" : ""}`
76
+ );
83
77
  const tooltipButton = (
84
78
  <Button
85
79
  ref={ref}
86
80
  aria-label={triggerAriaLabel}
81
+ aria-expanded={isOpen}
87
82
  variant={BUTTON_VARIANT.TERTIARY_PURPLE}
88
83
  negative={negative}
89
84
  iconOnly
@@ -111,11 +106,11 @@ export const Tooltip = forwardRef(
111
106
  <RadixTooltip.Content
112
107
  side={position}
113
108
  align={align}
114
- className={cx([
109
+ className={cx(
115
110
  contentClassName,
116
111
  `${rootClassName}__content`,
117
- `${rootClassName}__content--primary${negative ? "-negative" : ""}`,
118
- ])}
112
+ `${rootClassName}__content--primary${negative ? "-negative" : ""}`
113
+ )}
119
114
  sideOffset={-5}
120
115
  data-testid={`${dataTestId}-content`}
121
116
  >
@@ -131,10 +126,10 @@ export const Tooltip = forwardRef(
131
126
  children
132
127
  )}
133
128
  <RadixTooltip.Arrow
134
- className={cx([
129
+ className={cx(
135
130
  `${rootClassName}__arrow`,
136
- `${rootClassName}__arrow--primary${negative ? "-negative" : ""}`,
137
- ])}
131
+ `${rootClassName}__arrow--primary${negative ? "-negative" : ""}`
132
+ )}
138
133
  />
139
134
  </RadixTooltip.Content>
140
135
  </RadixTooltip.Portal>