@tamagui/tooltip 1.88.13 → 1.89.0-1706308641099

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Nate Wienert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,168 @@
1
+ import "@tamagui/polyfill-dev";
2
+ import { FloatingDelayGroup, useDelayGroup, useDelayGroupContext, useDismiss, useFloating, useFocus, useHover, useInteractions, useRole } from "@floating-ui/react";
3
+ import { useEvent } from "@tamagui/core";
4
+ import { FloatingOverrideContext } from "@tamagui/floating";
5
+ import { getSize } from "@tamagui/get-token";
6
+ import { withStaticProperties } from "@tamagui/helpers";
7
+ import { PopoverAnchor, PopoverArrow, PopoverContent, PopoverContext, PopoverTrigger } from "@tamagui/popover";
8
+ import { Popper, PopperContentFrame, usePopperContext } from "@tamagui/popper";
9
+ import { useControllableState } from "@tamagui/use-controllable-state";
10
+ import * as React from "react";
11
+ import { jsx } from "react/jsx-runtime";
12
+ const TOOLTIP_SCOPE = "tooltip",
13
+ TooltipContent = PopperContentFrame.extractable(React.forwardRef(({
14
+ __scopeTooltip,
15
+ ...props
16
+ }, ref) => {
17
+ const popper = usePopperContext(__scopeTooltip || TOOLTIP_SCOPE),
18
+ padding = props.padding ?? props.size ?? popper.size ?? getSize("$true", {
19
+ shift: -2
20
+ });
21
+ return /* @__PURE__ */jsx(PopoverContent, {
22
+ __scopePopover: __scopeTooltip || TOOLTIP_SCOPE,
23
+ componentName: "Tooltip",
24
+ disableRemoveScroll: !0,
25
+ disableFocusScope: !0,
26
+ ...(!props.unstyled && {
27
+ padding
28
+ }),
29
+ ref,
30
+ ...props
31
+ });
32
+ })),
33
+ TooltipArrow = React.forwardRef((props, ref) => {
34
+ const {
35
+ __scopeTooltip,
36
+ ...rest
37
+ } = props;
38
+ return /* @__PURE__ */jsx(PopoverArrow, {
39
+ __scopePopper: __scopeTooltip || TOOLTIP_SCOPE,
40
+ componentName: "Tooltip",
41
+ ref,
42
+ ...rest
43
+ });
44
+ }),
45
+ TooltipGroup = ({
46
+ children,
47
+ delay
48
+ }) => /* @__PURE__ */jsx(FloatingDelayGroup, {
49
+ delay: React.useMemo(() => delay, [JSON.stringify(delay)]),
50
+ children
51
+ }),
52
+ TooltipComponent = React.forwardRef(function (props, ref) {
53
+ const {
54
+ children,
55
+ delay: delayProp,
56
+ restMs = typeof delayProp > "u" ? 500 : typeof delayProp == "number" ? delayProp : 0,
57
+ onOpenChange: onOpenChangeProp,
58
+ focus,
59
+ open: openProp,
60
+ __scopeTooltip,
61
+ ...restProps
62
+ } = props,
63
+ triggerRef = React.useRef(null),
64
+ [hasCustomAnchor, setHasCustomAnchor] = React.useState(!1),
65
+ {
66
+ delay: delayGroup,
67
+ setCurrentId
68
+ } = useDelayGroupContext(),
69
+ delay = delayProp ?? delayGroup,
70
+ [open, setOpen] = useControllableState({
71
+ prop: openProp,
72
+ defaultProp: !1,
73
+ onChange: onOpenChangeProp
74
+ }),
75
+ id = props.groupId,
76
+ onOpenChange = useEvent(open2 => {
77
+ open2 && setCurrentId(id), setOpen(open2);
78
+ }),
79
+ useFloatingFn = props2 => {
80
+ const floating = useFloating({
81
+ ...props2,
82
+ open,
83
+ onOpenChange
84
+ }),
85
+ {
86
+ getReferenceProps,
87
+ getFloatingProps
88
+ } = useInteractions([useHover(floating.context, {
89
+ delay,
90
+ restMs
91
+ }), useFocus(floating.context, focus), useRole(floating.context, {
92
+ role: "tooltip"
93
+ }), useDismiss(floating.context), useDelayGroup(floating.context, {
94
+ id
95
+ })]);
96
+ return {
97
+ ...floating,
98
+ open,
99
+ getReferenceProps,
100
+ getFloatingProps
101
+ };
102
+ },
103
+ useFloatingContext = React.useCallback(useFloatingFn, [id, delay, open, restMs, focus ? JSON.stringify(focus) : 0]),
104
+ onCustomAnchorAdd = React.useCallback(() => setHasCustomAnchor(!0), []),
105
+ onCustomAnchorRemove = React.useCallback(() => setHasCustomAnchor(!1), []),
106
+ contentId = React.useId(),
107
+ smallerSize = props.unstyled ? null : getSize("$true", {
108
+ shift: -2,
109
+ bounds: [0]
110
+ });
111
+ return (
112
+ // TODO: FloatingOverrideContext might also need to be scoped
113
+ /* @__PURE__ */
114
+ jsx(FloatingOverrideContext.Provider, {
115
+ value: useFloatingContext,
116
+ children: /* @__PURE__ */jsx(Popper, {
117
+ __scopePopper: __scopeTooltip || TOOLTIP_SCOPE,
118
+ size: smallerSize?.key,
119
+ allowFlip: !0,
120
+ stayInFrame: !0,
121
+ ...restProps,
122
+ children: /* @__PURE__ */jsx(PopoverContext.Provider, {
123
+ contentId,
124
+ triggerRef,
125
+ sheetBreakpoint: !1,
126
+ open,
127
+ scope: __scopeTooltip || TOOLTIP_SCOPE,
128
+ onOpenChange: setOpen,
129
+ onOpenToggle: voidFn,
130
+ hasCustomAnchor,
131
+ onCustomAnchorAdd,
132
+ onCustomAnchorRemove,
133
+ children
134
+ })
135
+ })
136
+ })
137
+ );
138
+ }),
139
+ TooltipTrigger = React.forwardRef(function (props, ref) {
140
+ const {
141
+ __scopeTooltip,
142
+ ...rest
143
+ } = props;
144
+ return /* @__PURE__ */jsx(PopoverTrigger, {
145
+ ...rest,
146
+ __scopePopover: __scopeTooltip || TOOLTIP_SCOPE,
147
+ ref
148
+ });
149
+ }),
150
+ TooltipAnchor = React.forwardRef(function (props, ref) {
151
+ const {
152
+ __scopeTooltip,
153
+ ...rest
154
+ } = props;
155
+ return /* @__PURE__ */jsx(PopoverAnchor, {
156
+ ...rest,
157
+ __scopePopover: __scopeTooltip || TOOLTIP_SCOPE,
158
+ ref
159
+ });
160
+ }),
161
+ Tooltip2 = withStaticProperties(TooltipComponent, {
162
+ Anchor: TooltipAnchor,
163
+ Arrow: TooltipArrow,
164
+ Content: TooltipContent,
165
+ Trigger: TooltipTrigger
166
+ }),
167
+ voidFn = () => {};
168
+ export { Tooltip2 as Tooltip, TooltipGroup };
@@ -0,0 +1,79 @@
1
+ import { useDelayGroupContext } from "@floating-ui/react";
2
+ import { getSpace } from "@tamagui/get-token";
3
+ import { Paragraph } from "@tamagui/text";
4
+ import * as React from "react";
5
+ import { Tooltip, TooltipGroup } from "./Tooltip.mjs";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ const TooltipSimple = React.forwardRef(({
8
+ label,
9
+ children,
10
+ contentProps,
11
+ disabled,
12
+ ...tooltipProps
13
+ }, ref) => {
14
+ let context;
15
+ try {
16
+ context = useDelayGroupContext();
17
+ } catch {}
18
+ const child = React.Children.only(children),
19
+ contents = /* @__PURE__ */jsxs(Tooltip, {
20
+ offset: 15,
21
+ restMs: 40,
22
+ delay: 40,
23
+ ...tooltipProps,
24
+ ...(disabled ? {
25
+ open: !1
26
+ } : null),
27
+ children: [/* @__PURE__ */jsx(Tooltip.Trigger, {
28
+ ...(typeof label == "string" && {
29
+ "aria-label": label
30
+ }),
31
+ asChild: "except-style",
32
+ children: ref && React.isValidElement(child) ? React.cloneElement(child, {
33
+ ref
34
+ }) : child
35
+ }), /* @__PURE__ */jsxs(Tooltip.Content, {
36
+ zIndex: 1e9,
37
+ enterStyle: {
38
+ x: 0,
39
+ y: -8,
40
+ opacity: 0,
41
+ scale: 0.93
42
+ },
43
+ exitStyle: {
44
+ x: 0,
45
+ y: -8,
46
+ opacity: 0,
47
+ scale: 0.93
48
+ },
49
+ x: 0,
50
+ scale: 1,
51
+ y: 0,
52
+ elevation: "$1",
53
+ opacity: 1,
54
+ paddingVertical: getSpace(tooltipProps.size || "$true", {
55
+ shift: -4
56
+ }),
57
+ animateOnly: ["transform", "opacity"],
58
+ animation: ["quicker", {
59
+ opacity: {
60
+ overshootClamping: !0
61
+ }
62
+ }],
63
+ ...contentProps,
64
+ children: [/* @__PURE__ */jsx(Tooltip.Arrow, {}), /* @__PURE__ */jsx(Paragraph, {
65
+ size: "$3",
66
+ children: label
67
+ })]
68
+ })]
69
+ });
70
+ return context ? contents : /* @__PURE__ */jsx(TooltipGroup, {
71
+ delay: defaultTooltipDelay,
72
+ children: contents
73
+ });
74
+ }),
75
+ defaultTooltipDelay = {
76
+ open: 3e3,
77
+ close: 100
78
+ };
79
+ export { TooltipSimple };
@@ -0,0 +1,2 @@
1
+ export * from "./Tooltip.mjs";
2
+ export * from "./TooltipSimple.mjs";
@@ -0,0 +1,168 @@
1
+ import "@tamagui/polyfill-dev";
2
+ import { FloatingDelayGroup, useDelayGroup, useDelayGroupContext, useDismiss, useFloating, useFocus, useHover, useInteractions, useRole } from "@floating-ui/react";
3
+ import { useEvent } from "@tamagui/core";
4
+ import { FloatingOverrideContext } from "@tamagui/floating";
5
+ import { getSize } from "@tamagui/get-token";
6
+ import { withStaticProperties } from "@tamagui/helpers";
7
+ import { PopoverAnchor, PopoverArrow, PopoverContent, PopoverContext, PopoverTrigger } from "@tamagui/popover";
8
+ import { Popper, PopperContentFrame, usePopperContext } from "@tamagui/popper";
9
+ import { useControllableState } from "@tamagui/use-controllable-state";
10
+ import * as React from "react";
11
+ import { jsx } from "react/jsx-runtime";
12
+ const TOOLTIP_SCOPE = "tooltip",
13
+ TooltipContent = PopperContentFrame.extractable(React.forwardRef(({
14
+ __scopeTooltip,
15
+ ...props
16
+ }, ref) => {
17
+ const popper = usePopperContext(__scopeTooltip || TOOLTIP_SCOPE),
18
+ padding = props.padding ?? props.size ?? popper.size ?? getSize("$true", {
19
+ shift: -2
20
+ });
21
+ return /* @__PURE__ */jsx(PopoverContent, {
22
+ __scopePopover: __scopeTooltip || TOOLTIP_SCOPE,
23
+ componentName: "Tooltip",
24
+ disableRemoveScroll: !0,
25
+ disableFocusScope: !0,
26
+ ...(!props.unstyled && {
27
+ padding
28
+ }),
29
+ ref,
30
+ ...props
31
+ });
32
+ })),
33
+ TooltipArrow = React.forwardRef((props, ref) => {
34
+ const {
35
+ __scopeTooltip,
36
+ ...rest
37
+ } = props;
38
+ return /* @__PURE__ */jsx(PopoverArrow, {
39
+ __scopePopper: __scopeTooltip || TOOLTIP_SCOPE,
40
+ componentName: "Tooltip",
41
+ ref,
42
+ ...rest
43
+ });
44
+ }),
45
+ TooltipGroup = ({
46
+ children,
47
+ delay
48
+ }) => /* @__PURE__ */jsx(FloatingDelayGroup, {
49
+ delay: React.useMemo(() => delay, [JSON.stringify(delay)]),
50
+ children
51
+ }),
52
+ TooltipComponent = React.forwardRef(function (props, ref) {
53
+ const {
54
+ children,
55
+ delay: delayProp,
56
+ restMs = typeof delayProp > "u" ? 500 : typeof delayProp == "number" ? delayProp : 0,
57
+ onOpenChange: onOpenChangeProp,
58
+ focus,
59
+ open: openProp,
60
+ __scopeTooltip,
61
+ ...restProps
62
+ } = props,
63
+ triggerRef = React.useRef(null),
64
+ [hasCustomAnchor, setHasCustomAnchor] = React.useState(!1),
65
+ {
66
+ delay: delayGroup,
67
+ setCurrentId
68
+ } = useDelayGroupContext(),
69
+ delay = delayProp ?? delayGroup,
70
+ [open, setOpen] = useControllableState({
71
+ prop: openProp,
72
+ defaultProp: !1,
73
+ onChange: onOpenChangeProp
74
+ }),
75
+ id = props.groupId,
76
+ onOpenChange = useEvent(open2 => {
77
+ open2 && setCurrentId(id), setOpen(open2);
78
+ }),
79
+ useFloatingFn = props2 => {
80
+ const floating = useFloating({
81
+ ...props2,
82
+ open,
83
+ onOpenChange
84
+ }),
85
+ {
86
+ getReferenceProps,
87
+ getFloatingProps
88
+ } = useInteractions([useHover(floating.context, {
89
+ delay,
90
+ restMs
91
+ }), useFocus(floating.context, focus), useRole(floating.context, {
92
+ role: "tooltip"
93
+ }), useDismiss(floating.context), useDelayGroup(floating.context, {
94
+ id
95
+ })]);
96
+ return {
97
+ ...floating,
98
+ open,
99
+ getReferenceProps,
100
+ getFloatingProps
101
+ };
102
+ },
103
+ useFloatingContext = React.useCallback(useFloatingFn, [id, delay, open, restMs, focus ? JSON.stringify(focus) : 0]),
104
+ onCustomAnchorAdd = React.useCallback(() => setHasCustomAnchor(!0), []),
105
+ onCustomAnchorRemove = React.useCallback(() => setHasCustomAnchor(!1), []),
106
+ contentId = React.useId(),
107
+ smallerSize = props.unstyled ? null : getSize("$true", {
108
+ shift: -2,
109
+ bounds: [0]
110
+ });
111
+ return (
112
+ // TODO: FloatingOverrideContext might also need to be scoped
113
+ /* @__PURE__ */
114
+ jsx(FloatingOverrideContext.Provider, {
115
+ value: useFloatingContext,
116
+ children: /* @__PURE__ */jsx(Popper, {
117
+ __scopePopper: __scopeTooltip || TOOLTIP_SCOPE,
118
+ size: smallerSize?.key,
119
+ allowFlip: !0,
120
+ stayInFrame: !0,
121
+ ...restProps,
122
+ children: /* @__PURE__ */jsx(PopoverContext.Provider, {
123
+ contentId,
124
+ triggerRef,
125
+ sheetBreakpoint: !1,
126
+ open,
127
+ scope: __scopeTooltip || TOOLTIP_SCOPE,
128
+ onOpenChange: setOpen,
129
+ onOpenToggle: voidFn,
130
+ hasCustomAnchor,
131
+ onCustomAnchorAdd,
132
+ onCustomAnchorRemove,
133
+ children
134
+ })
135
+ })
136
+ })
137
+ );
138
+ }),
139
+ TooltipTrigger = React.forwardRef(function (props, ref) {
140
+ const {
141
+ __scopeTooltip,
142
+ ...rest
143
+ } = props;
144
+ return /* @__PURE__ */jsx(PopoverTrigger, {
145
+ ...rest,
146
+ __scopePopover: __scopeTooltip || TOOLTIP_SCOPE,
147
+ ref
148
+ });
149
+ }),
150
+ TooltipAnchor = React.forwardRef(function (props, ref) {
151
+ const {
152
+ __scopeTooltip,
153
+ ...rest
154
+ } = props;
155
+ return /* @__PURE__ */jsx(PopoverAnchor, {
156
+ ...rest,
157
+ __scopePopover: __scopeTooltip || TOOLTIP_SCOPE,
158
+ ref
159
+ });
160
+ }),
161
+ Tooltip2 = withStaticProperties(TooltipComponent, {
162
+ Anchor: TooltipAnchor,
163
+ Arrow: TooltipArrow,
164
+ Content: TooltipContent,
165
+ Trigger: TooltipTrigger
166
+ }),
167
+ voidFn = () => {};
168
+ export { Tooltip2 as Tooltip, TooltipGroup };
@@ -0,0 +1,79 @@
1
+ import { useDelayGroupContext } from "@floating-ui/react";
2
+ import { getSpace } from "@tamagui/get-token";
3
+ import { Paragraph } from "@tamagui/text";
4
+ import * as React from "react";
5
+ import { Tooltip, TooltipGroup } from "./Tooltip.mjs";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ const TooltipSimple = React.forwardRef(({
8
+ label,
9
+ children,
10
+ contentProps,
11
+ disabled,
12
+ ...tooltipProps
13
+ }, ref) => {
14
+ let context;
15
+ try {
16
+ context = useDelayGroupContext();
17
+ } catch {}
18
+ const child = React.Children.only(children),
19
+ contents = /* @__PURE__ */jsxs(Tooltip, {
20
+ offset: 15,
21
+ restMs: 40,
22
+ delay: 40,
23
+ ...tooltipProps,
24
+ ...(disabled ? {
25
+ open: !1
26
+ } : null),
27
+ children: [/* @__PURE__ */jsx(Tooltip.Trigger, {
28
+ ...(typeof label == "string" && {
29
+ "aria-label": label
30
+ }),
31
+ asChild: "except-style",
32
+ children: ref && React.isValidElement(child) ? React.cloneElement(child, {
33
+ ref
34
+ }) : child
35
+ }), /* @__PURE__ */jsxs(Tooltip.Content, {
36
+ zIndex: 1e9,
37
+ enterStyle: {
38
+ x: 0,
39
+ y: -8,
40
+ opacity: 0,
41
+ scale: 0.93
42
+ },
43
+ exitStyle: {
44
+ x: 0,
45
+ y: -8,
46
+ opacity: 0,
47
+ scale: 0.93
48
+ },
49
+ x: 0,
50
+ scale: 1,
51
+ y: 0,
52
+ elevation: "$1",
53
+ opacity: 1,
54
+ paddingVertical: getSpace(tooltipProps.size || "$true", {
55
+ shift: -4
56
+ }),
57
+ animateOnly: ["transform", "opacity"],
58
+ animation: ["quicker", {
59
+ opacity: {
60
+ overshootClamping: !0
61
+ }
62
+ }],
63
+ ...contentProps,
64
+ children: [/* @__PURE__ */jsx(Tooltip.Arrow, {}), /* @__PURE__ */jsx(Paragraph, {
65
+ size: "$3",
66
+ children: label
67
+ })]
68
+ })]
69
+ });
70
+ return context ? contents : /* @__PURE__ */jsx(TooltipGroup, {
71
+ delay: defaultTooltipDelay,
72
+ children: contents
73
+ });
74
+ }),
75
+ defaultTooltipDelay = {
76
+ open: 3e3,
77
+ close: 100
78
+ };
79
+ export { TooltipSimple };
@@ -0,0 +1,2 @@
1
+ export * from "./Tooltip.mjs";
2
+ export * from "./TooltipSimple.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/tooltip",
3
- "version": "1.88.13",
3
+ "version": "1.89.0-1706308641099",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -33,25 +33,25 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@floating-ui/react": "^0.26.6",
36
- "@tamagui/compose-refs": "1.88.13",
37
- "@tamagui/core": "1.88.13",
38
- "@tamagui/create-context": "1.88.13",
39
- "@tamagui/floating": "1.88.13",
40
- "@tamagui/get-token": "1.88.13",
41
- "@tamagui/helpers": "1.88.13",
42
- "@tamagui/polyfill-dev": "1.88.13",
43
- "@tamagui/popover": "1.88.13",
44
- "@tamagui/popper": "1.88.13",
45
- "@tamagui/stacks": "1.88.13",
46
- "@tamagui/text": "1.88.13",
47
- "@tamagui/use-controllable-state": "1.88.13"
36
+ "@tamagui/compose-refs": "1.89.0-1706308641099",
37
+ "@tamagui/core": "1.89.0-1706308641099",
38
+ "@tamagui/create-context": "1.89.0-1706308641099",
39
+ "@tamagui/floating": "1.89.0-1706308641099",
40
+ "@tamagui/get-token": "1.89.0-1706308641099",
41
+ "@tamagui/helpers": "1.89.0-1706308641099",
42
+ "@tamagui/polyfill-dev": "1.89.0-1706308641099",
43
+ "@tamagui/popover": "1.89.0-1706308641099",
44
+ "@tamagui/popper": "1.89.0-1706308641099",
45
+ "@tamagui/stacks": "1.89.0-1706308641099",
46
+ "@tamagui/text": "1.89.0-1706308641099",
47
+ "@tamagui/use-controllable-state": "1.89.0-1706308641099"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "react": "*",
51
51
  "react-native": "*"
52
52
  },
53
53
  "devDependencies": {
54
- "@tamagui/build": "1.88.13",
54
+ "@tamagui/build": "1.89.0-1706308641099",
55
55
  "react": "^18.2.0",
56
56
  "react-native": "^0.72.6"
57
57
  },