@cypress-design/react-tooltip 0.8.0 → 0.9.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.
@@ -2,5 +2,5 @@ $ yarn build:module && yarn build:types
2
2
  $ rollup -c ./rollup.config.mjs
3
3
  
4
4
  ./index.ts → ./dist/index.umd.js, ./dist/index.es.mjs...
5
- created ./dist/index.umd.js, ./dist/index.es.mjs in 47.5s
5
+ created ./dist/index.umd.js, ./dist/index.es.mjs in 21.5s
6
6
  $ tsc --project ./tsconfig.build.json
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @cypress-design/react-tooltip
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#371](https://github.com/cypress-io/cypress-design/pull/371) [`c7851b7`](https://github.com/cypress-io/cypress-design/commit/c7851b7ff4915d1d19e05136723e5939dca9b97b) Thanks [@elevatebart](https://github.com/elevatebart)! - update dependency from '@floating-ui/react-dom-interactions' to '@floating-ui/react'
8
+
9
+ ## 0.8.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#344](https://github.com/cypress-io/cypress-design/pull/344) [`4fcb9f6`](https://github.com/cypress-io/cypress-design/commit/4fcb9f6510557436cb49abbd9542a18d49cb6306) Thanks [@elevatebart](https://github.com/elevatebart)! - fix: accessible-tooltips
14
+
3
15
  ## 0.8.0
4
16
 
5
17
  ### Minor Changes
package/ReadMe.md CHANGED
@@ -22,8 +22,10 @@ import Tooltip from '@cypress-design/react-tooltip'
22
22
 
23
23
  ```jsx live
24
24
  export const comp = () => (
25
- <Tooltip tabIndex="0" popper={<b>popper</b>}>
26
- <span>Focus me</span>
27
- </Tooltip>
25
+ <div>
26
+ <Tooltip className="inline-block" tabIndex="0" popper={<b>popper</b>}>
27
+ <span>Focus me</span>
28
+ </Tooltip>
29
+ </div>
28
30
  )
29
31
  ```
package/Tooltip.tsx CHANGED
@@ -1,5 +1,6 @@
1
1
  import clsx from 'clsx'
2
2
  import * as React from 'react'
3
+ import { createPortal } from 'react-dom'
3
4
  import {
4
5
  Placement,
5
6
  offset,
@@ -14,8 +15,7 @@ import {
14
15
  useRole,
15
16
  useDismiss,
16
17
  safePolygon,
17
- FloatingPortal,
18
- } from '@floating-ui/react-dom-interactions'
18
+ } from '@floating-ui/react'
19
19
 
20
20
  export interface TooltipProps {
21
21
  /**
@@ -83,11 +83,8 @@ export const Tooltip: React.FC<
83
83
  }, [forceOpen])
84
84
 
85
85
  const {
86
- x,
87
- y,
88
- reference,
89
- floating,
90
- strategy,
86
+ floatingStyles,
87
+ refs,
91
88
  placement: calculatedPlacement,
92
89
  context,
93
90
  middlewareData: { arrow: { x: arrowX, y: arrowY } = {} },
@@ -109,7 +106,7 @@ export const Tooltip: React.FC<
109
106
  whileElementsMounted: autoUpdate,
110
107
  })
111
108
 
112
- const contextHook = useDismiss(context)
109
+ const dismissHook = useDismiss(context)
113
110
 
114
111
  const { getReferenceProps, getFloatingProps } = useInteractions([
115
112
  useHover(context, {
@@ -120,7 +117,7 @@ export const Tooltip: React.FC<
120
117
  enabled: !disabled && !forceOpen,
121
118
  }),
122
119
  useRole(context, { role: 'tooltip' }),
123
- ...(!forceOpen ? [contextHook] : []),
120
+ ...(!forceOpen ? [dismissHook] : []),
124
121
  ])
125
122
 
126
123
  const placementSide = calculatedPlacement.split(
@@ -166,72 +163,71 @@ export const Tooltip: React.FC<
166
163
  return (
167
164
  <>
168
165
  <div
169
- {...getReferenceProps()}
170
- ref={reference}
166
+ ref={refs.setReference}
171
167
  className={className}
172
168
  {...rest}
169
+ {...getReferenceProps()}
173
170
  >
174
171
  {children}
175
172
  </div>
176
- {disabled ? null : (
177
- <FloatingPortal>
178
- {open && (
179
- <div
180
- {...getFloatingProps({
181
- ref: floating,
182
- style: {
183
- position: strategy,
184
- top: y ?? '',
185
- left: x ?? '',
186
- ...(interactive ? { padding: '16px' } : {}),
187
- },
188
- })}
189
- >
173
+ {disabled
174
+ ? null
175
+ : open
176
+ ? // NOTE: we could have used the "FloatingPortal" component
177
+ // but it fails miserably and the native portal from react 18 is great...
178
+ createPortal(
190
179
  <div
191
- className={clsx('rounded shadow-tooltip border', [
192
- colors.background,
193
- colors.block,
194
- (!x || !y) && 'invisible',
195
- ])}
180
+ ref={refs.setFloating}
181
+ style={{ ...floatingStyles, zIndex: 100 }}
182
+ role="tooltip"
183
+ {...getFloatingProps()}
196
184
  >
197
- <svg
198
- ref={arrowRef}
199
- viewBox="0 0 48 24"
200
- width="24"
201
- height="12"
202
- className={clsx('absolute z-10', colors.svg)}
203
- style={{
204
- transform: `rotate(${arrowRotate}deg)`,
205
- filter:
206
- placementSide === 'bottom' || color === 'dark'
207
- ? 'drop-shadow(0 1px 1px rgba(225, 227, 237, .3))'
208
- : 'drop-shadow(0 1px 1px rgba(225, 227, 237, .8))',
209
- [arrowXRule]: `${arrowX ?? (interactive ? 0 : -16)}px`,
210
- [arrowYRule]: `${
211
- arrowY ? arrowY + 6 : interactive ? 6 : -10
212
- }px`,
213
- }}
214
- fill="none"
215
- >
216
- <rect x="0" y="0" width="48" height="4" strokeWidth="0" />
217
- <path
218
- d="M 0 3 C 12 3 18 18 24 18 C 30 18 36 3 48 3"
219
- strokeWidth="2"
220
- />
221
- </svg>
222
185
  <div
223
- className={clsx(
224
- 'rounded text-[16px] leading-[24px] min-w-[160px] text-center p-[8px] relative z-20',
186
+ className={clsx('rounded shadow-tooltip border', [
225
187
  colors.background,
226
- )}
188
+ colors.block,
189
+ ])}
227
190
  >
228
- {popper}
191
+ <svg
192
+ ref={arrowRef}
193
+ viewBox="0 0 48 24"
194
+ width="24"
195
+ height="12"
196
+ className={clsx('absolute z-10', colors.svg)}
197
+ style={{
198
+ transform: `rotate(${arrowRotate}deg)`,
199
+ filter:
200
+ placementSide === 'bottom' || color === 'dark'
201
+ ? 'drop-shadow(0 1px 1px rgba(225, 227, 237, .3))'
202
+ : 'drop-shadow(0 1px 1px rgba(225, 227, 237, .8))',
203
+ [arrowXRule]: `${arrowX ?? (interactive ? 0 : -16)}px`,
204
+ [arrowYRule]: `${
205
+ arrowY ? arrowY + 6 : interactive ? 6 : -10
206
+ }px`,
207
+ }}
208
+ fill="none"
209
+ >
210
+ <rect x="0" y="0" width="48" height="4" strokeWidth="0" />
211
+ <path
212
+ d="M 0 3 C 12 3 18 18 24 18 C 30 18 36 3 48 3"
213
+ strokeWidth="2"
214
+ />
215
+ </svg>
216
+ <div
217
+ className={clsx(
218
+ 'rounded text-[16px] leading-[24px] min-w-[160px] text-center p-[8px] relative z-20',
219
+ colors.background,
220
+ )}
221
+ >
222
+ <span className="sr-only">Tooltip: </span>
223
+ {popper}
224
+ </div>
229
225
  </div>
230
- </div>
231
- </div>
232
- )}
233
- </FloatingPortal>
234
- )}
226
+ </div>,
227
+ document.body,
228
+ 'cy-tooltip-portal',
229
+ )
230
+ : null}
235
231
  </>
236
232
  )
237
233
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  import * as React from 'react'
4
4
  import { mount } from 'cypress/react18'
5
- import { Placement } from '@floating-ui/react-dom-interactions'
5
+ import type { Placement } from '@floating-ui/react'
6
6
  import assertions from '../assertions'
7
7
  import Tooltip from './Tooltip'
8
8
 
@@ -65,14 +65,16 @@ const TooltipStoryMulti = ({
65
65
  >
66
66
  <div>Hover Me ({placement})</div>
67
67
  </Tooltip>
68
- )
68
+ ),
69
69
  )}
70
70
  </div>
71
71
  )
72
72
 
73
73
  describe('Tooltip', { viewportHeight: 800, viewportWidth: 800 }, () => {
74
74
  function mountStory(
75
- options: { single?: boolean } & Parameters<typeof TooltipStoryMulti>[0] = {}
75
+ options: { single?: boolean } & Parameters<
76
+ typeof TooltipStoryMulti
77
+ >[0] = {},
76
78
  ) {
77
79
  const { single, tabindex = 1, ...rest } = options
78
80
  if (single) {
@@ -90,7 +92,7 @@ describe('Tooltip', { viewportHeight: 800, viewportWidth: 800 }, () => {
90
92
  >
91
93
  Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam,
92
94
  voluptatum.
93
- </Tooltip>
95
+ </Tooltip>,
94
96
  )
95
97
  } else {
96
98
  mount(<TooltipStoryMulti {...rest} tabindex={tabindex} />)
@@ -109,7 +111,7 @@ describe('Tooltip', { viewportHeight: 800, viewportWidth: 800 }, () => {
109
111
  >
110
112
  make sure its open
111
113
  </Tooltip>
112
- </div>
114
+ </div>,
113
115
  )
114
116
  cy.findByText('should be visible').should('be.visible')
115
117
  })
package/dist/Tooltip.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { Placement } from '@floating-ui/react-dom-interactions';
2
+ import { Placement } from '@floating-ui/react';
3
3
  export interface TooltipProps {
4
4
  /**
5
5
  * Where the tooltip should be placed relative to the target.
@@ -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,EAcV,MAAM,qCAAqC,CAAA;AAE5C,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AASD,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAC5B,YAAY,GAAG,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CA8K/C,CAAA;AA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