@cypress-design/react-tooltip 0.0.1 → 0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @cypress-design/react-tooltip
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#53](https://github.com/cypress-io/cypress-design/pull/53) [`a9a616b`](https://github.com/cypress-io/cypress-design/commit/a9a616bc4684252fcd71e4a82d2141bdfbea32bc) Thanks [@elevatebart](https://github.com/elevatebart)! - - add a default font color when light and dark mode are used
8
+ - add disabled prop to tooltip
9
+
10
+ * [#51](https://github.com/cypress-io/cypress-design/pull/51) [`ccd8f9a`](https://github.com/cypress-io/cypress-design/commit/ccd8f9a8feb624c0a52deaa9754c76969f43fc1e) Thanks [@elevatebart](https://github.com/elevatebart)! - in the build asset, add a comment containing all used windicss classes in the component
11
+
12
+ ## 0.1.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#44](https://github.com/cypress-io/cypress-design/pull/44) [`2fdaf6b`](https://github.com/cypress-io/cypress-design/commit/2fdaf6be6f81a2a851761258347ed213577c5b26) Thanks [@elevatebart](https://github.com/elevatebart)! - Add missing descriptions of props in button, tooltip, checkbox
17
+
18
+ ## 0.0.2
19
+
20
+ ### Patch Changes
21
+
22
+ - [#39](https://github.com/cypress-io/cypress-design/pull/39) [`1b383f3`](https://github.com/cypress-io/cypress-design/commit/1b383f3d149948bf2cc062d3baa17d5ce032f07e) Thanks [@elevatebart](https://github.com/elevatebart)! - fix file path of sourcemaps
23
+
3
24
  ## 0.0.1
4
25
 
5
26
  ### Patch Changes
@@ -5,10 +5,12 @@ import Tooltip from './Tooltip'
5
5
  export default ({
6
6
  color = 'light',
7
7
  placement,
8
+ disabled,
8
9
  tabIndex,
9
10
  }: {
10
11
  color?: 'light' | 'dark'
11
12
  placement?: Placement
13
+ disabled?: boolean
12
14
  tabIndex?: number
13
15
  } = {}) => (
14
16
  <div className="center flex flex-col items-center gap-20">
@@ -18,6 +20,7 @@ export default ({
18
20
  color={color}
19
21
  placement={placement}
20
22
  tabIndex={tabIndex}
23
+ disabled={disabled}
21
24
  >
22
25
  <div>Hover Me (dynamic: {placement?.toString()})</div>
23
26
  </Tooltip>
@@ -29,6 +32,7 @@ export default ({
29
32
  key={placement}
30
33
  color={color}
31
34
  tabIndex={tabIndex}
35
+ disabled={disabled}
32
36
  popper={
33
37
  <div className="bg-jade-200 text-gray-800 p-4">
34
38
  Popover ({placement})
package/Tooltip.tsx CHANGED
@@ -17,12 +17,26 @@ import {
17
17
  } from '@floating-ui/react-dom-interactions'
18
18
 
19
19
  export interface TooltipProps {
20
+ /**
21
+ * Where the tooltip should be placed relative to the target.
22
+ */
20
23
  placement?: Placement
24
+ /**
25
+ * background color of the tooltip.
26
+ */
21
27
  color?: 'light' | 'dark'
22
28
  className?: string
23
29
  tabIndex?: number | string
24
30
  children?: React.ReactNode
31
+ /**
32
+ * The content of the tooltip.
33
+ */
25
34
  popper?: React.ReactNode
35
+ /**
36
+ * Disable the tooltip.
37
+ * This hides the popper and makes the tooltip inactive.
38
+ */
39
+ disabled?: boolean
26
40
  }
27
41
 
28
42
  const ROTATE_MAP = {
@@ -34,7 +48,15 @@ const ROTATE_MAP = {
34
48
 
35
49
  export const Tooltip: React.FC<
36
50
  TooltipProps & React.HTMLProps<HTMLDivElement>
37
- > = ({ placement, color = 'light', className, children, popper, ...rest }) => {
51
+ > = ({
52
+ placement,
53
+ color = 'light',
54
+ className,
55
+ children,
56
+ popper,
57
+ disabled,
58
+ ...rest
59
+ }) => {
38
60
  const arrowRef = React.useRef(null)
39
61
  const [open, setOpen] = React.useState(false)
40
62
 
@@ -71,13 +93,18 @@ export const Tooltip: React.FC<
71
93
  const { getReferenceProps, getFloatingProps } = useInteractions([
72
94
  useHover(context, {
73
95
  handleClose: safePolygon(),
96
+ enabled: !disabled,
97
+ }),
98
+ useFocus(context, {
99
+ enabled: !disabled,
74
100
  }),
75
- useFocus(context),
76
101
  useRole(context, { role: 'tooltip' }),
77
102
  useDismiss(context),
78
103
  ])
79
104
 
80
- const placementSide = calculatedPlacement.split('-')[0]
105
+ const placementSide = calculatedPlacement.split(
106
+ '-'
107
+ )[0] as keyof typeof ROTATE_MAP
81
108
  const arrowRotate = ROTATE_MAP[placementSide]
82
109
 
83
110
  let arrowXRule = 'left',
@@ -105,7 +132,7 @@ export const Tooltip: React.FC<
105
132
  {children}
106
133
  </div>
107
134
  <FloatingPortal>
108
- {open && (
135
+ {open && !disabled && (
109
136
  <div
110
137
  {...getFloatingProps({
111
138
  ref: floating,
package/dist/Tooltip.d.ts CHANGED
@@ -1,12 +1,26 @@
1
1
  import * as React from 'react';
2
2
  import { Placement } from '@floating-ui/react-dom-interactions';
3
3
  export interface TooltipProps {
4
+ /**
5
+ * Where the tooltip should be placed relative to the target.
6
+ */
4
7
  placement?: Placement;
8
+ /**
9
+ * background color of the tooltip.
10
+ */
5
11
  color?: 'light' | 'dark';
6
12
  className?: string;
7
13
  tabIndex?: number | string;
8
14
  children?: React.ReactNode;
15
+ /**
16
+ * The content of the tooltip.
17
+ */
9
18
  popper?: React.ReactNode;
19
+ /**
20
+ * Disable the tooltip.
21
+ * This hides the popper and makes the tooltip inactive.
22
+ */
23
+ disabled?: boolean;
10
24
  }
11
25
  export declare const Tooltip: React.FC<TooltipProps & React.HTMLProps<HTMLDivElement>>;
12
26
  export default Tooltip;
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../Tooltip.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EACL,SAAS,EAaV,MAAM,qCAAqC,CAAA;AAE5C,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;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