@tamagui/tooltip 1.0.1-beta.57 → 1.0.1-beta.61
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 +12 -11
- package/src/Tooltip.native.tsx +22 -0
- package/src/Tooltip.tsx +183 -0
- package/src/index.tsx +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/tooltip",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.61",
|
|
4
4
|
"sideEffects": true,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"module": "dist/esm",
|
|
9
9
|
"module:jsx": "dist/jsx",
|
|
10
10
|
"files": [
|
|
11
|
+
"src",
|
|
11
12
|
"types",
|
|
12
13
|
"dist"
|
|
13
14
|
],
|
|
@@ -19,15 +20,15 @@
|
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
22
|
"@floating-ui/react-dom-interactions": "^0.5.0",
|
|
22
|
-
"@tamagui/compose-refs": "^1.0.1-beta.
|
|
23
|
-
"@tamagui/core": "^1.0.1-beta.
|
|
24
|
-
"@tamagui/create-context": "^1.0.1-beta.
|
|
25
|
-
"@tamagui/polyfill-dev": "^1.0.1-beta.
|
|
26
|
-
"@tamagui/popover": "^1.0.1-beta.
|
|
27
|
-
"@tamagui/popper": "^1.0.1-beta.
|
|
28
|
-
"@tamagui/stacks": "^1.0.1-beta.
|
|
29
|
-
"@tamagui/text": "^1.0.1-beta.
|
|
30
|
-
"@tamagui/use-controllable-state": "^1.0.1-beta.
|
|
23
|
+
"@tamagui/compose-refs": "^1.0.1-beta.61",
|
|
24
|
+
"@tamagui/core": "^1.0.1-beta.61",
|
|
25
|
+
"@tamagui/create-context": "^1.0.1-beta.61",
|
|
26
|
+
"@tamagui/polyfill-dev": "^1.0.1-beta.61",
|
|
27
|
+
"@tamagui/popover": "^1.0.1-beta.61",
|
|
28
|
+
"@tamagui/popper": "^1.0.1-beta.61",
|
|
29
|
+
"@tamagui/stacks": "^1.0.1-beta.61",
|
|
30
|
+
"@tamagui/text": "^1.0.1-beta.61",
|
|
31
|
+
"@tamagui/use-controllable-state": "^1.0.1-beta.61"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
34
|
"react": "*",
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
"react-native": "*"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
39
|
+
"@tamagui/build": "^1.0.1-beta.61",
|
|
39
40
|
"@types/react-dom": "^18.0.3",
|
|
40
41
|
"@types/react-native": "^0.67.3",
|
|
41
42
|
"react": "*",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { withStaticProperties } from '@tamagui/core'
|
|
2
|
+
|
|
3
|
+
// no output on native for now
|
|
4
|
+
// could have an option to long-press or similar to show in a context menu/drawer
|
|
5
|
+
|
|
6
|
+
const RenderChildren = (props: any) => {
|
|
7
|
+
return props.children
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const RenderNull = (props: any) => {
|
|
11
|
+
return null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Tooltip = withStaticProperties(RenderChildren, {
|
|
15
|
+
Anchor: RenderChildren,
|
|
16
|
+
Arrow: RenderNull,
|
|
17
|
+
Close: RenderNull,
|
|
18
|
+
Content: RenderNull,
|
|
19
|
+
Trigger: RenderChildren,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export const TooltipSimple = RenderChildren
|
package/src/Tooltip.tsx
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import '@tamagui/polyfill-dev'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
FloatingDelayGroup,
|
|
5
|
+
useDelayGroup,
|
|
6
|
+
useDelayGroupContext,
|
|
7
|
+
useDismiss,
|
|
8
|
+
useFloating,
|
|
9
|
+
useFocus,
|
|
10
|
+
useHover,
|
|
11
|
+
useInteractions,
|
|
12
|
+
useRole,
|
|
13
|
+
} from '@floating-ui/react-dom-interactions'
|
|
14
|
+
import { useId, withStaticProperties } from '@tamagui/core'
|
|
15
|
+
import { ScopedProps } from '@tamagui/create-context'
|
|
16
|
+
import {
|
|
17
|
+
PopoverAnchor,
|
|
18
|
+
PopoverArrow,
|
|
19
|
+
PopoverArrowProps,
|
|
20
|
+
PopoverContent,
|
|
21
|
+
PopoverContentProps,
|
|
22
|
+
PopoverTrigger,
|
|
23
|
+
__PopoverProviderInternal,
|
|
24
|
+
usePopoverScope,
|
|
25
|
+
} from '@tamagui/popover'
|
|
26
|
+
import { FloatingOverrideContext, Popper, PopperProps, UseFloatingFn } from '@tamagui/popper'
|
|
27
|
+
import { SizableStackProps } from '@tamagui/stacks'
|
|
28
|
+
import { Paragraph } from '@tamagui/text'
|
|
29
|
+
import * as React from 'react'
|
|
30
|
+
|
|
31
|
+
const TooltipContent = React.forwardRef((props: PopoverContentProps, ref: any) => {
|
|
32
|
+
return <PopoverContent componentName="TooltipContent" pointerEvents="none" ref={ref} {...props} />
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const TooltipArrow = React.forwardRef((props: PopoverArrowProps, ref: any) => {
|
|
36
|
+
return <PopoverArrow componentName="TooltipArrow" ref={ref} {...props} />
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
export type TooltipProps = PopperProps & {
|
|
40
|
+
children?: React.ReactNode
|
|
41
|
+
onOpenChange?: (open: boolean) => void
|
|
42
|
+
groupId?: string
|
|
43
|
+
restMs?: number
|
|
44
|
+
delay?:
|
|
45
|
+
| number
|
|
46
|
+
| {
|
|
47
|
+
open?: number
|
|
48
|
+
close?: number
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const TooltipGroup = FloatingDelayGroup
|
|
53
|
+
|
|
54
|
+
export const Tooltip = withStaticProperties(
|
|
55
|
+
((props: ScopedProps<TooltipProps, 'Popover'>) => {
|
|
56
|
+
const { __scopePopover, children, restMs = 500, delay: delayProp, ...restProps } = props
|
|
57
|
+
const popperScope = usePopoverScope(__scopePopover)
|
|
58
|
+
const triggerRef = React.useRef<HTMLButtonElement>(null)
|
|
59
|
+
const [hasCustomAnchor, setHasCustomAnchor] = React.useState(false)
|
|
60
|
+
const { delay: delayGroup, setCurrentId } = useDelayGroupContext()
|
|
61
|
+
const delay = delayProp ?? delayGroup
|
|
62
|
+
const [open, setOpen] = React.useState(false)
|
|
63
|
+
const id = props.groupId
|
|
64
|
+
|
|
65
|
+
const onOpenChange = React.useCallback(
|
|
66
|
+
(open) => {
|
|
67
|
+
setOpen(open)
|
|
68
|
+
if (open) {
|
|
69
|
+
setCurrentId(id)
|
|
70
|
+
}
|
|
71
|
+
props.onOpenChange?.(open)
|
|
72
|
+
},
|
|
73
|
+
[id, setCurrentId]
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
const useFloatingFn: UseFloatingFn = (props) => {
|
|
77
|
+
const floating = useFloating({
|
|
78
|
+
...props,
|
|
79
|
+
open,
|
|
80
|
+
onOpenChange,
|
|
81
|
+
})
|
|
82
|
+
const { getReferenceProps, getFloatingProps } = useInteractions([
|
|
83
|
+
useHover(floating.context, { delay, restMs }),
|
|
84
|
+
useFocus(floating.context),
|
|
85
|
+
useRole(floating.context, { role: 'tooltip' }),
|
|
86
|
+
useDismiss(floating.context),
|
|
87
|
+
useDelayGroup(floating.context, { id }),
|
|
88
|
+
])
|
|
89
|
+
return {
|
|
90
|
+
...floating,
|
|
91
|
+
getReferenceProps,
|
|
92
|
+
getFloatingProps,
|
|
93
|
+
} as any
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const useFloatingContext = React.useCallback(useFloatingFn, [id, delay, open])
|
|
97
|
+
|
|
98
|
+
const voidFn = React.useCallback(() => {}, [setOpen])
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<FloatingOverrideContext.Provider value={useFloatingContext}>
|
|
102
|
+
{/* default tooltip to a smaller size */}
|
|
103
|
+
<Popper size="$2" {...popperScope} {...restProps}>
|
|
104
|
+
<__PopoverProviderInternal
|
|
105
|
+
scope={__scopePopover}
|
|
106
|
+
contentId={useId()}
|
|
107
|
+
triggerRef={triggerRef}
|
|
108
|
+
open={open}
|
|
109
|
+
onOpenChange={setOpen}
|
|
110
|
+
onOpenToggle={voidFn}
|
|
111
|
+
hasCustomAnchor={hasCustomAnchor}
|
|
112
|
+
onCustomAnchorAdd={React.useCallback(() => setHasCustomAnchor(true), [])}
|
|
113
|
+
onCustomAnchorRemove={React.useCallback(() => setHasCustomAnchor(false), [])}
|
|
114
|
+
modal
|
|
115
|
+
>
|
|
116
|
+
{children}
|
|
117
|
+
</__PopoverProviderInternal>
|
|
118
|
+
</Popper>
|
|
119
|
+
</FloatingOverrideContext.Provider>
|
|
120
|
+
)
|
|
121
|
+
}) as React.FC<TooltipProps>,
|
|
122
|
+
{
|
|
123
|
+
Anchor: PopoverAnchor,
|
|
124
|
+
Arrow: TooltipArrow,
|
|
125
|
+
Content: TooltipContent,
|
|
126
|
+
Trigger: PopoverTrigger,
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
Tooltip.displayName = 'Tooltip'
|
|
131
|
+
|
|
132
|
+
export type TooltipSimpleProps = TooltipProps & {
|
|
133
|
+
label?: React.ReactNode
|
|
134
|
+
children?: React.ReactNode
|
|
135
|
+
contentProps?: SizableStackProps
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export const TooltipSimple: React.FC<TooltipSimpleProps> = ({
|
|
139
|
+
label,
|
|
140
|
+
children,
|
|
141
|
+
contentProps,
|
|
142
|
+
...tooltipProps
|
|
143
|
+
}) => {
|
|
144
|
+
let context
|
|
145
|
+
try {
|
|
146
|
+
context = useDelayGroupContext()
|
|
147
|
+
} catch {
|
|
148
|
+
// ok
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const contents = (
|
|
152
|
+
<Tooltip {...tooltipProps}>
|
|
153
|
+
<Tooltip.Trigger asChild>{children}</Tooltip.Trigger>
|
|
154
|
+
<Tooltip.Content
|
|
155
|
+
enterStyle={{ x: 0, y: -10, opacity: 0, scale: 0.9 }}
|
|
156
|
+
exitStyle={{ x: 0, y: -10, opacity: 0, scale: 0.9 }}
|
|
157
|
+
x={0}
|
|
158
|
+
scale={1}
|
|
159
|
+
y={0}
|
|
160
|
+
elevation="$1"
|
|
161
|
+
opacity={1}
|
|
162
|
+
animation={[
|
|
163
|
+
'bouncy',
|
|
164
|
+
{
|
|
165
|
+
opacity: {
|
|
166
|
+
overshootClamping: true,
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
]}
|
|
170
|
+
{...contentProps}
|
|
171
|
+
>
|
|
172
|
+
<Tooltip.Arrow />
|
|
173
|
+
<Paragraph size="$2">{label}</Paragraph>
|
|
174
|
+
</Tooltip.Content>
|
|
175
|
+
</Tooltip>
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
if (!context) {
|
|
179
|
+
return <TooltipGroup delay={{ open: 3000, close: 100 }}>{contents}</TooltipGroup>
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return contents
|
|
183
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Tooltip'
|