Skip to content

Commit 40a73f4

Browse files
authored
fix: Export TooltipProvider as a component (#847)
* fix: Export TooltipProvider as a component * Bump version to 26.2.1
1 parent ec1f638 commit 40a73f4

File tree

6 files changed

+29
-15
lines changed

6 files changed

+29
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Reactist follows [semantic versioning](https://semver.org/) and doesn't introduce breaking changes (API-wise) in minor or patch releases. However, the appearance of a component might change in a minor or patch release so keep an eye on redesigns and make sure your app still looks and feels like you expect it.
44

5+
# 26.2.1
6+
7+
- [Fix] Export `TooltipProvider` as a component
8+
59
# 26.2.0
610

711
- [Feat] Add `TooltipContext` to allow `showTimeout` and `hideTimeout` to be set globally

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"email": "henning@doist.com",
77
"url": "http://doist.com"
88
},
9-
"version": "26.2.0",
9+
"version": "26.2.1",
1010
"license": "MIT",
1111
"homepage": "https://github.com/Doist/reactist#readme",
1212
"repository": {

src/tooltip/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { Tooltip } from './tooltip'
1+
export { Tooltip, TooltipProvider } from './tooltip'
22
export type { TooltipProps } from './tooltip'

src/tooltip/tooltip.stories.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react'
22
import { createPortal } from 'react-dom'
33

4-
import { Tooltip, TooltipContext, TooltipProps } from './tooltip'
4+
import { Tooltip, TooltipProps, TooltipProvider } from './tooltip'
55
import { Button } from '../button'
66
import { Stack } from '../stack'
77
import { TextField } from '../text-field'
@@ -186,19 +186,14 @@ export function TooltipGlobalContext({
186186
showTimeout,
187187
hideTimeout,
188188
}: Required<Pick<TooltipProps, 'showTimeout' | 'hideTimeout'>>) {
189-
const contextValue = React.useMemo(() => ({ showTimeout, hideTimeout }), [
190-
showTimeout,
191-
hideTimeout,
192-
])
193-
194189
return (
195190
<Stack space="medium">
196191
<Text>
197192
<code>{'<TooltipContext>'}</code> can be used to provide global settings to all
198193
tooltips:
199194
</Text>
200195

201-
<TooltipContext.Provider value={contextValue}>
196+
<TooltipProvider showTimeout={showTimeout} hideTimeout={hideTimeout}>
202197
<Box padding="large" display="flex" gap="medium">
203198
<Tooltip content="Click here to begin your journey">
204199
<Button variant="primary">Got it</Button>
@@ -208,7 +203,7 @@ export function TooltipGlobalContext({
208203
<Button variant="secondary">Cancel</Button>
209204
</Tooltip>
210205
</Box>
211-
</TooltipContext.Provider>
206+
</TooltipProvider>
212207
</Stack>
213208
)
214209
}

src/tooltip/tooltip.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,31 @@ import type { TooltipStoreState } from '@ariakit/react'
1313
import styles from './tooltip.module.css'
1414
import type { ObfuscatedClassName } from '../utils/common-types'
1515

16+
const defaultShowTimeout = 500
17+
const defaultHideTimeout = 100
18+
1619
type TooltipContextState = {
1720
showTimeout: number
1821
hideTimeout: number
1922
}
2023

2124
const TooltipContext = React.createContext<TooltipContextState>({
22-
showTimeout: 500,
23-
hideTimeout: 100,
25+
showTimeout: defaultShowTimeout,
26+
hideTimeout: defaultHideTimeout,
2427
})
2528

29+
function TooltipProvider({
30+
showTimeout = defaultShowTimeout,
31+
hideTimeout = defaultHideTimeout,
32+
children,
33+
}: React.PropsWithChildren<{
34+
showTimeout?: number
35+
hideTimeout?: number
36+
}>) {
37+
const value = React.useMemo(() => ({ showTimeout, hideTimeout }), [showTimeout, hideTimeout])
38+
return <TooltipContext.Provider value={value}>{children}</TooltipContext.Provider>
39+
}
40+
2641
interface TooltipProps extends ObfuscatedClassName {
2742
/**
2843
* The element that triggers the tooltip. Generally a button or link.
@@ -154,4 +169,4 @@ function Tooltip({
154169
}
155170

156171
export type { TooltipProps }
157-
export { Tooltip, TooltipContext }
172+
export { Tooltip, TooltipProvider }

0 commit comments

Comments
 (0)