@channel.io/bezier-react 1.11.0 → 1.11.1
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/dist/cjs/components/Tooltip/Tooltip.js +37 -41
- package/dist/cjs/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/cjs/components/Tooltip/Tooltip.types.js.map +1 -1
- package/dist/esm/components/Tooltip/Tooltip.mjs +38 -42
- package/dist/esm/components/Tooltip/Tooltip.mjs.map +1 -1
- package/dist/esm/components/Tooltip/Tooltip.types.mjs.map +1 -1
- package/dist/types/components/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/types/components/Tooltip/Tooltip.types.d.ts +1 -3
- package/dist/types/components/Tooltip/Tooltip.types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Forms/Slider/__snapshots__/Slider.test.tsx.snap +1 -0
- package/src/components/Tooltip/Tooltip.tsx +47 -47
- package/src/components/Tooltip/Tooltip.types.ts +2 -5
|
@@ -113,12 +113,31 @@ function TooltipProvider({
|
|
|
113
113
|
value: contextValue
|
|
114
114
|
}, children));
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* `Tooltip` is a component that shows additional information when the mouse hovers or the keyboard is focused.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
*
|
|
122
|
+
* ```tsx
|
|
123
|
+
* // Anatomy of the Tooltip
|
|
124
|
+
* <TooltipProvider>
|
|
125
|
+
* <Tooltip />
|
|
126
|
+
* </TooltipProvider>
|
|
127
|
+
*
|
|
128
|
+
* // Example of a Tooltip with a button
|
|
129
|
+
* <Tooltip content="Ta-da!">
|
|
130
|
+
* <button>Hover me</button>
|
|
131
|
+
* </Tooltip>
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
const Tooltip = /*#__PURE__*/React.forwardRef(function Tooltip({
|
|
117
135
|
as,
|
|
118
136
|
children,
|
|
119
137
|
defaultShow,
|
|
120
138
|
onShow: onShowProp,
|
|
121
139
|
onHide: onHideProp,
|
|
140
|
+
disabled,
|
|
122
141
|
content,
|
|
123
142
|
description,
|
|
124
143
|
icon,
|
|
@@ -139,13 +158,7 @@ const TooltipImpl = /*#__PURE__*/React.forwardRef(function TooltipImpl({
|
|
|
139
158
|
const delayHide = delayHideProp ?? globalDelayHide;
|
|
140
159
|
const defaultContainer = domUtils.getRootElement();
|
|
141
160
|
const container = givenContainer ?? defaultContainer;
|
|
142
|
-
React.
|
|
143
|
-
return function cleanUp() {
|
|
144
|
-
if (timeoutRef.current) {
|
|
145
|
-
clearTimeout(timeoutRef.current);
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
}, []);
|
|
161
|
+
const shouldBeHidden = React.useMemo(() => disabled || typeUtils.isEmpty(content), [disabled, content]);
|
|
149
162
|
const onShow = React.useCallback(() => {
|
|
150
163
|
setShow(true);
|
|
151
164
|
onShowProp?.();
|
|
@@ -154,7 +167,22 @@ const TooltipImpl = /*#__PURE__*/React.forwardRef(function TooltipImpl({
|
|
|
154
167
|
setShow(false);
|
|
155
168
|
onHideProp?.();
|
|
156
169
|
}, [onHideProp]);
|
|
170
|
+
React.useEffect(function forceHide() {
|
|
171
|
+
if (shouldBeHidden) {
|
|
172
|
+
onHide();
|
|
173
|
+
}
|
|
174
|
+
}, [shouldBeHidden, onHide]);
|
|
175
|
+
React.useEffect(function cleanUpTimeout() {
|
|
176
|
+
return function cleanUp() {
|
|
177
|
+
if (timeoutRef.current) {
|
|
178
|
+
clearTimeout(timeoutRef.current);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}, [shouldBeHidden]);
|
|
157
182
|
const onOpenChange = React.useCallback(open => {
|
|
183
|
+
if (shouldBeHidden) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
158
186
|
if (open) {
|
|
159
187
|
onShow();
|
|
160
188
|
return;
|
|
@@ -170,7 +198,7 @@ const TooltipImpl = /*#__PURE__*/React.forwardRef(function TooltipImpl({
|
|
|
170
198
|
return;
|
|
171
199
|
}
|
|
172
200
|
onHide();
|
|
173
|
-
}, [delayHide, onShow, onHide]);
|
|
201
|
+
}, [shouldBeHidden, delayHide, onShow, onHide]);
|
|
174
202
|
return /*#__PURE__*/React.createElement(index.Root, {
|
|
175
203
|
open: show,
|
|
176
204
|
defaultOpen: defaultShow,
|
|
@@ -195,38 +223,6 @@ const TooltipImpl = /*#__PURE__*/React.forwardRef(function TooltipImpl({
|
|
|
195
223
|
})))));
|
|
196
224
|
});
|
|
197
225
|
|
|
198
|
-
/**
|
|
199
|
-
* `Tooltip` is a component that shows additional information when the mouse hovers or the keyboard is focused.
|
|
200
|
-
*
|
|
201
|
-
* @example
|
|
202
|
-
*
|
|
203
|
-
* ```tsx
|
|
204
|
-
* // Anatomy of the Tooltip
|
|
205
|
-
* <TooltipProvider>
|
|
206
|
-
* <Tooltip />
|
|
207
|
-
* </TooltipProvider>
|
|
208
|
-
*
|
|
209
|
-
* // Example of a Tooltip with a button
|
|
210
|
-
* <Tooltip content="Ta-da!">
|
|
211
|
-
* <button>Hover me</button>
|
|
212
|
-
* </Tooltip>
|
|
213
|
-
* ```
|
|
214
|
-
*/
|
|
215
|
-
const Tooltip = /*#__PURE__*/React.forwardRef(function Tooltip({
|
|
216
|
-
children,
|
|
217
|
-
disabled,
|
|
218
|
-
content,
|
|
219
|
-
...rest
|
|
220
|
-
}, forwardedRef) {
|
|
221
|
-
if (disabled || typeUtils.isEmpty(content)) {
|
|
222
|
-
return children ?? null;
|
|
223
|
-
}
|
|
224
|
-
return /*#__PURE__*/React.createElement(TooltipImpl, Object.assign({
|
|
225
|
-
ref: forwardedRef,
|
|
226
|
-
content: content
|
|
227
|
-
}, rest), children);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
226
|
exports.Tooltip = Tooltip;
|
|
231
227
|
exports.TooltipProvider = TooltipProvider;
|
|
232
228
|
//# sourceMappingURL=Tooltip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","sources":["../../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react'\n\nimport * as TooltipPrimitive from '@radix-ui/react-tooltip'\n\nimport { getRootElement } from '~/src/utils/domUtils'\nimport { createContext } from '~/src/utils/reactUtils'\nimport {\n isBoolean,\n isEmpty,\n} from '~/src/utils/typeUtils'\n\nimport {\n type TooltipImplProps,\n TooltipPosition,\n type TooltipProps,\n type TooltipProviderProps,\n} from './Tooltip.types'\n\nimport * as Styled from './Tooltip.styled'\n\nfunction getSideAndAlign(\n placement: TooltipPosition,\n): Pick<TooltipPrimitive.TooltipContentProps, 'side' | 'align'> {\n switch (placement) {\n case TooltipPosition.TopCenter:\n return {\n side: 'top',\n align: 'center',\n }\n case TooltipPosition.TopLeft:\n return {\n side: 'top',\n align: 'start',\n }\n case TooltipPosition.TopRight:\n return {\n side: 'top',\n align: 'end',\n }\n case TooltipPosition.RightCenter:\n return {\n side: 'right',\n align: 'center',\n }\n case TooltipPosition.RightTop:\n return {\n side: 'right',\n align: 'start',\n }\n case TooltipPosition.RightBottom:\n return {\n side: 'right',\n align: 'end',\n }\n case TooltipPosition.BottomCenter:\n return {\n side: 'bottom',\n align: 'center',\n }\n case TooltipPosition.BottomLeft:\n return {\n side: 'bottom',\n align: 'start',\n }\n case TooltipPosition.BottomRight:\n return {\n side: 'bottom',\n align: 'end',\n }\n case TooltipPosition.LeftCenter:\n return {\n side: 'left',\n align: 'center',\n }\n case TooltipPosition.LeftTop:\n return {\n side: 'left',\n align: 'start',\n }\n case TooltipPosition.LeftBottom:\n return {\n side: 'left',\n align: 'end',\n }\n default:\n // NOTE: should not reach here\n return {\n side: undefined,\n align: undefined,\n }\n }\n}\n\nconst [\n /**\n * NOTE: Custom context use because the radix-ui doesn't support `delayHide`.\n */\n TooltipGlobalContextProvider,\n useTooltipGlobalContext,\n] = createContext<Required<Pick<TooltipProviderProps, 'delayHide'>> | null>(null, 'TooltipProvider')\n\n/**\n * `TooltipProvider` is used to globally provide props to child tooltips.\n *\n * @example\n *\n * ```tsx\n * <TooltipProvider allowHover delayShow={1000}>\n * <Tooltip />\n * </TooltipProvider>\n * ```\n */\nexport function TooltipProvider({\n children,\n allowHover = false,\n delayShow = 300,\n delayHide = 0,\n skipDelayShow = 500,\n}: TooltipProviderProps) {\n const contextValue = useMemo(() => ({\n delayHide,\n }), [delayHide])\n\n return (\n <TooltipPrimitive.Provider\n delayDuration={delayShow}\n skipDelayDuration={skipDelayShow}\n disableHoverableContent={!allowHover}\n >\n <TooltipGlobalContextProvider value={contextValue}>\n { children }\n </TooltipGlobalContextProvider>\n </TooltipPrimitive.Provider>\n )\n}\n\nconst TooltipImpl = forwardRef<HTMLDivElement, TooltipImplProps>(function TooltipImpl({\n as,\n children,\n defaultShow,\n onShow: onShowProp,\n onHide: onHideProp,\n content,\n description,\n icon,\n placement = TooltipPosition.BottomCenter,\n offset = 4,\n container: givenContainer,\n keepInContainer = true,\n allowHover,\n delayShow,\n delayHide: delayHideProp,\n ...rest\n}, forwardedRef) {\n const [show, setShow] = useState<boolean>(defaultShow ?? false)\n const timeoutRef = useRef<NodeJS.Timeout>()\n\n const { delayHide: globalDelayHide } = useTooltipGlobalContext('Tooltip')\n const delayHide = delayHideProp ?? globalDelayHide\n\n const defaultContainer = getRootElement()\n const container = givenContainer ?? defaultContainer\n\n useEffect(function cleanUpTimeout() {\n return function cleanUp() {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n }\n }\n }, [])\n\n const onShow = useCallback(() => {\n setShow(true)\n onShowProp?.()\n }, [onShowProp])\n\n const onHide = useCallback(() => {\n setShow(false)\n onHideProp?.()\n }, [onHideProp])\n\n const onOpenChange = useCallback((open: boolean) => {\n if (open) {\n onShow()\n return\n }\n\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n timeoutRef.current = undefined\n }\n\n if (delayHide > 0) {\n timeoutRef.current = setTimeout(() => {\n onHide()\n }, delayHide)\n return\n }\n\n onHide()\n }, [\n delayHide,\n onShow,\n onHide,\n ])\n\n return (\n <TooltipPrimitive.Root\n open={show}\n defaultOpen={defaultShow}\n delayDuration={delayShow}\n disableHoverableContent={isBoolean(allowHover) ? !allowHover : undefined}\n onOpenChange={onOpenChange}\n >\n <TooltipPrimitive.Trigger asChild>\n { children }\n </TooltipPrimitive.Trigger>\n\n <TooltipPrimitive.Portal container={container}>\n <TooltipPrimitive.Content\n {...rest}\n {...getSideAndAlign(placement)}\n asChild\n ref={forwardedRef}\n sideOffset={offset}\n avoidCollisions={keepInContainer}\n collisionPadding={8}\n hideWhenDetached\n >\n <Styled.TooltipContent forwardedAs={as}>\n <Styled.TextContainer>\n <Styled.Content>\n { content }\n </Styled.Content>\n\n { description && (\n <Styled.Description>\n { description }\n </Styled.Description>\n ) }\n </Styled.TextContainer>\n\n { icon && (\n <Styled.Icon source={icon} />\n ) }\n </Styled.TooltipContent>\n </TooltipPrimitive.Content>\n </TooltipPrimitive.Portal>\n </TooltipPrimitive.Root>\n )\n})\n\n/**\n * `Tooltip` is a component that shows additional information when the mouse hovers or the keyboard is focused.\n *\n * @example\n *\n * ```tsx\n * // Anatomy of the Tooltip\n * <TooltipProvider>\n * <Tooltip />\n * </TooltipProvider>\n *\n * // Example of a Tooltip with a button\n * <Tooltip content=\"Ta-da!\">\n * <button>Hover me</button>\n * </Tooltip>\n * ```\n */\nexport const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(function Tooltip({\n children,\n disabled,\n content,\n ...rest\n}, forwardedRef) {\n if (disabled || isEmpty(content)) {\n return children ?? null\n }\n\n return (\n <TooltipImpl\n ref={forwardedRef}\n content={content}\n {...rest}\n >\n { children }\n </TooltipImpl>\n )\n})\n"],"names":["getSideAndAlign","placement","TooltipPosition","TopCenter","side","align","TopLeft","TopRight","RightCenter","RightTop","RightBottom","BottomCenter","BottomLeft","BottomRight","LeftCenter","LeftTop","LeftBottom","undefined","TooltipGlobalContextProvider","useTooltipGlobalContext","createContext","TooltipProvider","children","allowHover","delayShow","delayHide","skipDelayShow","contextValue","useMemo","React","createElement","TooltipPrimitive","delayDuration","skipDelayDuration","disableHoverableContent","value","TooltipImpl","forwardRef","as","defaultShow","onShow","onShowProp","onHide","onHideProp","content","description","icon","offset","container","givenContainer","keepInContainer","delayHideProp","rest","forwardedRef","show","setShow","useState","timeoutRef","useRef","globalDelayHide","defaultContainer","getRootElement","useEffect","cleanUpTimeout","cleanUp","current","clearTimeout","useCallback","onOpenChange","open","setTimeout","defaultOpen","isBoolean","asChild","Object","assign","ref","sideOffset","avoidCollisions","collisionPadding","hideWhenDetached","Styled","forwardedAs","source","Tooltip","disabled","isEmpty"],"mappings":";;;;;;;;;;AA2BA,SAASA,eAAeA,CACtBC,SAA0B,EACoC;AAC9D,EAAA,QAAQA,SAAS;IACf,KAAKC,6BAAe,CAACC,SAAS;MAC5B,OAAO;AACLC,QAAAA,IAAI,EAAE,KAAK;AACXC,QAAAA,KAAK,EAAE,QAAA;OACR,CAAA;IACH,KAAKH,6BAAe,CAACI,OAAO;MAC1B,OAAO;AACLF,QAAAA,IAAI,EAAE,KAAK;AACXC,QAAAA,KAAK,EAAE,OAAA;OACR,CAAA;IACH,KAAKH,6BAAe,CAACK,QAAQ;MAC3B,OAAO;AACLH,QAAAA,IAAI,EAAE,KAAK;AACXC,QAAAA,KAAK,EAAE,KAAA;OACR,CAAA;IACH,KAAKH,6BAAe,CAACM,WAAW;MAC9B,OAAO;AACLJ,QAAAA,IAAI,EAAE,OAAO;AACbC,QAAAA,KAAK,EAAE,QAAA;OACR,CAAA;IACH,KAAKH,6BAAe,CAACO,QAAQ;MAC3B,OAAO;AACLL,QAAAA,IAAI,EAAE,OAAO;AACbC,QAAAA,KAAK,EAAE,OAAA;OACR,CAAA;IACH,KAAKH,6BAAe,CAACQ,WAAW;MAC9B,OAAO;AACLN,QAAAA,IAAI,EAAE,OAAO;AACbC,QAAAA,KAAK,EA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AAACE,IAAAA,MAAM,EAAErC,IAAAA;AAAK,GAAE,CAET,CACC,CACH,CACJ,CAAC,CAAA;AAE5B,CAAC,CAAC,CAAA;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACasC,OAAO,gBAAG/C,gBAAU,CAA+B,SAAS+C,OAAOA,CAAC;EAC/E9D,QAAQ;EACR+D,QAAQ;EACRzC,OAAO;EACP,GAAGQ,IAAAA;AACL,CAAC,EAAEC,YAAY,EAAE;AACf,EAAA,IAAIgC,QAAQ,IAAIC,iBAAO,CAAC1C,OAAO,CAAC,EAAE;IAChC,OAAOtB,QAAQ,IAAI,IAAI,CAAA;AACzB,GAAA;EAEA,oBACEO,KAAA,CAAAC,aAAA,CAACM,WAAW,EAAAsC,MAAA,CAAAC,MAAA,CAAA;AACVC,IAAAA,GAAG,EAAEvB,YAAa;AAClBT,IAAAA,OAAO,EAAEA,OAAAA;GACLQ,EAAAA,IAAI,CAEN9B,EAAAA,QACS,CAAC,CAAA;AAElB,CAAC;;;;;"}
|
|
1
|
+
{"version":3,"file":"Tooltip.js","sources":["../../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react'\n\nimport * as TooltipPrimitive from '@radix-ui/react-tooltip'\n\nimport { getRootElement } from '~/src/utils/domUtils'\nimport { createContext } from '~/src/utils/reactUtils'\nimport {\n isBoolean,\n isEmpty,\n} from '~/src/utils/typeUtils'\n\nimport {\n TooltipPosition,\n type TooltipProps,\n type TooltipProviderProps,\n} from './Tooltip.types'\n\nimport * as Styled from './Tooltip.styled'\n\nfunction getSideAndAlign(\n placement: TooltipPosition,\n): Pick<TooltipPrimitive.TooltipContentProps, 'side' | 'align'> {\n switch (placement) {\n case TooltipPosition.TopCenter:\n return {\n side: 'top',\n align: 'center',\n }\n case TooltipPosition.TopLeft:\n return {\n side: 'top',\n align: 'start',\n }\n case TooltipPosition.TopRight:\n return {\n side: 'top',\n align: 'end',\n }\n case TooltipPosition.RightCenter:\n return {\n side: 'right',\n align: 'center',\n }\n case TooltipPosition.RightTop:\n return {\n side: 'right',\n align: 'start',\n }\n case TooltipPosition.RightBottom:\n return {\n side: 'right',\n align: 'end',\n }\n case TooltipPosition.BottomCenter:\n return {\n side: 'bottom',\n align: 'center',\n }\n case TooltipPosition.BottomLeft:\n return {\n side: 'bottom',\n align: 'start',\n }\n case TooltipPosition.BottomRight:\n return {\n side: 'bottom',\n align: 'end',\n }\n case TooltipPosition.LeftCenter:\n return {\n side: 'left',\n align: 'center',\n }\n case TooltipPosition.LeftTop:\n return {\n side: 'left',\n align: 'start',\n }\n case TooltipPosition.LeftBottom:\n return {\n side: 'left',\n align: 'end',\n }\n default:\n // NOTE: should not reach here\n return {\n side: undefined,\n align: undefined,\n }\n }\n}\n\nconst [\n /**\n * NOTE: Custom context use because the radix-ui doesn't support `delayHide`.\n */\n TooltipGlobalContextProvider,\n useTooltipGlobalContext,\n] = createContext<Required<Pick<TooltipProviderProps, 'delayHide'>> | null>(null, 'TooltipProvider')\n\n/**\n * `TooltipProvider` is used to globally provide props to child tooltips.\n *\n * @example\n *\n * ```tsx\n * <TooltipProvider allowHover delayShow={1000}>\n * <Tooltip />\n * </TooltipProvider>\n * ```\n */\nexport function TooltipProvider({\n children,\n allowHover = false,\n delayShow = 300,\n delayHide = 0,\n skipDelayShow = 500,\n}: TooltipProviderProps) {\n const contextValue = useMemo(() => ({\n delayHide,\n }), [delayHide])\n\n return (\n <TooltipPrimitive.Provider\n delayDuration={delayShow}\n skipDelayDuration={skipDelayShow}\n disableHoverableContent={!allowHover}\n >\n <TooltipGlobalContextProvider value={contextValue}>\n { children }\n </TooltipGlobalContextProvider>\n </TooltipPrimitive.Provider>\n )\n}\n\n/**\n * `Tooltip` is a component that shows additional information when the mouse hovers or the keyboard is focused.\n *\n * @example\n *\n * ```tsx\n * // Anatomy of the Tooltip\n * <TooltipProvider>\n * <Tooltip />\n * </TooltipProvider>\n *\n * // Example of a Tooltip with a button\n * <Tooltip content=\"Ta-da!\">\n * <button>Hover me</button>\n * </Tooltip>\n * ```\n */\nexport const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(function Tooltip({\n as,\n children,\n defaultShow,\n onShow: onShowProp,\n onHide: onHideProp,\n disabled,\n content,\n description,\n icon,\n placement = TooltipPosition.BottomCenter,\n offset = 4,\n container: givenContainer,\n keepInContainer = true,\n allowHover,\n delayShow,\n delayHide: delayHideProp,\n ...rest\n}, forwardedRef) {\n const [show, setShow] = useState<boolean>(defaultShow ?? false)\n const timeoutRef = useRef<NodeJS.Timeout>()\n\n const { delayHide: globalDelayHide } = useTooltipGlobalContext('Tooltip')\n const delayHide = delayHideProp ?? globalDelayHide\n\n const defaultContainer = getRootElement()\n const container = givenContainer ?? defaultContainer\n\n const shouldBeHidden = useMemo(() => (\n disabled || isEmpty(content)\n ), [\n disabled,\n content,\n ])\n\n const onShow = useCallback(() => {\n setShow(true)\n onShowProp?.()\n }, [onShowProp])\n\n const onHide = useCallback(() => {\n setShow(false)\n onHideProp?.()\n }, [onHideProp])\n\n useEffect(function forceHide() {\n if (shouldBeHidden) {\n onHide()\n }\n }, [\n shouldBeHidden,\n onHide,\n ])\n\n useEffect(function cleanUpTimeout() {\n return function cleanUp() {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n }\n }\n }, [shouldBeHidden])\n\n const onOpenChange = useCallback((open: boolean) => {\n if (shouldBeHidden) {\n return\n }\n\n if (open) {\n onShow()\n return\n }\n\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n timeoutRef.current = undefined\n }\n\n if (delayHide > 0) {\n timeoutRef.current = setTimeout(() => {\n onHide()\n }, delayHide)\n return\n }\n\n onHide()\n }, [\n shouldBeHidden,\n delayHide,\n onShow,\n onHide,\n ])\n\n return (\n <TooltipPrimitive.Root\n open={show}\n defaultOpen={defaultShow}\n delayDuration={delayShow}\n disableHoverableContent={isBoolean(allowHover) ? !allowHover : undefined}\n onOpenChange={onOpenChange}\n >\n <TooltipPrimitive.Trigger asChild>\n { children }\n </TooltipPrimitive.Trigger>\n\n <TooltipPrimitive.Portal container={container}>\n <TooltipPrimitive.Content\n {...rest}\n {...getSideAndAlign(placement)}\n asChild\n ref={forwardedRef}\n sideOffset={offset}\n avoidCollisions={keepInContainer}\n collisionPadding={8}\n hideWhenDetached\n >\n <Styled.TooltipContent forwardedAs={as}>\n <Styled.TextContainer>\n <Styled.Content>\n { content }\n </Styled.Content>\n\n { description && (\n <Styled.Description>\n { description }\n </Styled.Description>\n ) }\n </Styled.TextContainer>\n\n { icon && (\n <Styled.Icon source={icon} />\n ) }\n </Styled.TooltipContent>\n </TooltipPrimitive.Content>\n </TooltipPrimitive.Portal>\n </TooltipPrimitive.Root>\n )\n})\n"],"names":["getSideAndAlign","placement","TooltipPosition","TopCenter","side","align","TopLeft","TopRight","RightCenter","RightTop","RightBottom","BottomCenter","BottomLeft","BottomRight","LeftCenter","LeftTop","LeftBottom","undefined","TooltipGlobalContextProvider","useTooltipGlobalContext","createContext","TooltipProvider","children","allowHover","delayShow","delayHide","skipDelayShow","contextValue","useMemo","React","createElement","TooltipPrimitive","delayDuration","skipDelayDuration","disableHoverableContent","value","Tooltip","forwardRef","as","defaultShow","onShow","onShowProp","onHide","onHideProp","disabled","content","description","icon","offset","container","givenContainer","keepInContainer","delayHideProp","rest","forwardedRef","show","setShow","useState","timeoutRef","useRef","globalDelayHide","defaultContainer","getRootElement","shouldBeHidden","isEmpty","useCallback","useEffect","forceHide","cleanUpTimeout","cleanUp","current","clearTimeout","onOpenChange","open","setTimeout","defaultOpen","isBoolean","asChild","Object","assign","ref","sideOffset","avoidCollisions","collisionPadding","hideWhenDetached","Styled","forwardedAs","source"],"mappings":";;;;;;;;;;AA0BA,SAASA,eAAeA,CACtBC,SAA0B,EACoC;AAC9D,EAAA,QAAQA,SAAS;IACf,KAAKC,6BAAe,CA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J,CAAC,CAAA;AAE5B,CAAC;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.types.js","sources":["../../../../src/components/Tooltip/Tooltip.types.ts"],"sourcesContent":["import { type BezierIcon } from '@channel.io/bezier-icons'\n\nimport {\n type BezierComponentProps,\n type ChildrenProps,\n type ContentProps,\n type DisableProps,\n} from '~/src/types/ComponentProps'\n\n/**\n * An enumeration that determines the position of `Tooltip`.\n */\nexport enum TooltipPosition {\n TopCenter = 'topCenter',\n TopLeft = 'topLeft',\n TopRight = 'topRight',\n RightCenter = 'rightCenter',\n RightTop = 'rightTop',\n RightBottom = 'rightBottom',\n BottomCenter = 'bottomCenter',\n BottomLeft = 'bottomLeft',\n BottomRight = 'bottomRight',\n LeftCenter = 'leftCenter',\n LeftTop = 'leftTop',\n LeftBottom = 'leftBottom',\n}\n\ninterface TooltipProviderOptions {\n /**\n * Keeps the content of the tooltip open on hover. Disabling this feature affects accessibility.\n * @default false\n */\n allowHover?: boolean\n /**\n * The delay from when the mouse enters a tooltip trigger until the tooltip opens.\n * @default 300\n */\n delayShow?: number\n /**\n * The delay from when the mouse leaves a tooltip content until the tooltip hides.\n * @default 0\n */\n delayHide?: number\n /**\n * How much time a user has to enter another trigger without incurring a delay again.\n * @default 500\n */\n skipDelayShow?: number\n}\n\ninterface TooltipOptions {\n /**\n * The open state of the tooltip when it is initially rendered.\n */\n defaultShow?: boolean\n /**\n * An element that sits below the tooltip content.\n */\n description?: React.ReactNode\n /**\n * A decorative icon that sits right of the tooltip content.\n */\n icon?: BezierIcon\n /**\n * Options to determine the location from the trigger.\n * @default TooltipPosition.BottomCenter\n */\n placement?: TooltipPosition\n /**\n * The distance in pixels from the trigger.\n * @default 4\n */\n offset?: number\n /**\n * Specify a container element to portal the content into.\n * @note When placed inside a `Modal`, default value is the container element of `Modal`.\n * @default document.body\n */\n container?: HTMLElement | null\n /**\n * When `true`, overrides the `position` of the tooltip\n * to prevent collisions with boundary edges.\n * @default true\n */\n keepInContainer?: boolean\n /**\n * Keeps the content of the tooltip open on hover. Disabling this feature affects accessibility.\n * Inherits from the nearest `TooltipProvider`.\n * @default false\n */\n allowHover?: boolean\n /**\n * The delay from when the mouse enters a tooltip trigger until the tooltip opens.\n * Inherits from the nearest `TooltipProvider`.\n * @default 300\n */\n delayShow?: number\n /**\n * The delay from when the mouse leaves a tooltip content until the tooltip hides.\n * Inherits from the nearest `TooltipProvider`.\n * @default 0\n */\n delayHide?: number\n /**\n * Callback function to be called when the tooltip is opened.\n */\n onShow?: () => void\n /**\n * Callback function to be called when the tooltip is closed.\n */\n onHide?: () => void\n /**\n * Event handler called when the escape key is down.\n * It can be prevented by calling `event.preventDefault`.\n */\n onEscapeKeyDown?: (event: KeyboardEvent) => void\n /**\n * Event handler called when a pointer event occurs outside the bounds of the component.\n * It can be prevented by calling `event.preventDefault`.\n */\n onPointerDownOutside?: (event: CustomEvent<{ originalEvent: PointerEvent }>) => void\n}\n\nexport interface TooltipProviderProps extends\n ChildrenProps,\n TooltipProviderOptions {}\n\nexport interface
|
|
1
|
+
{"version":3,"file":"Tooltip.types.js","sources":["../../../../src/components/Tooltip/Tooltip.types.ts"],"sourcesContent":["import { type BezierIcon } from '@channel.io/bezier-icons'\n\nimport {\n type BezierComponentProps,\n type ChildrenProps,\n type ContentProps,\n type DisableProps,\n} from '~/src/types/ComponentProps'\n\n/**\n * An enumeration that determines the position of `Tooltip`.\n */\nexport enum TooltipPosition {\n TopCenter = 'topCenter',\n TopLeft = 'topLeft',\n TopRight = 'topRight',\n RightCenter = 'rightCenter',\n RightTop = 'rightTop',\n RightBottom = 'rightBottom',\n BottomCenter = 'bottomCenter',\n BottomLeft = 'bottomLeft',\n BottomRight = 'bottomRight',\n LeftCenter = 'leftCenter',\n LeftTop = 'leftTop',\n LeftBottom = 'leftBottom',\n}\n\ninterface TooltipProviderOptions {\n /**\n * Keeps the content of the tooltip open on hover. Disabling this feature affects accessibility.\n * @default false\n */\n allowHover?: boolean\n /**\n * The delay from when the mouse enters a tooltip trigger until the tooltip opens.\n * @default 300\n */\n delayShow?: number\n /**\n * The delay from when the mouse leaves a tooltip content until the tooltip hides.\n * @default 0\n */\n delayHide?: number\n /**\n * How much time a user has to enter another trigger without incurring a delay again.\n * @default 500\n */\n skipDelayShow?: number\n}\n\ninterface TooltipOptions {\n /**\n * The open state of the tooltip when it is initially rendered.\n */\n defaultShow?: boolean\n /**\n * An element that sits below the tooltip content.\n */\n description?: React.ReactNode\n /**\n * A decorative icon that sits right of the tooltip content.\n */\n icon?: BezierIcon\n /**\n * Options to determine the location from the trigger.\n * @default TooltipPosition.BottomCenter\n */\n placement?: TooltipPosition\n /**\n * The distance in pixels from the trigger.\n * @default 4\n */\n offset?: number\n /**\n * Specify a container element to portal the content into.\n * @note When placed inside a `Modal`, default value is the container element of `Modal`.\n * @default document.body\n */\n container?: HTMLElement | null\n /**\n * When `true`, overrides the `position` of the tooltip\n * to prevent collisions with boundary edges.\n * @default true\n */\n keepInContainer?: boolean\n /**\n * Keeps the content of the tooltip open on hover. Disabling this feature affects accessibility.\n * Inherits from the nearest `TooltipProvider`.\n * @default false\n */\n allowHover?: boolean\n /**\n * The delay from when the mouse enters a tooltip trigger until the tooltip opens.\n * Inherits from the nearest `TooltipProvider`.\n * @default 300\n */\n delayShow?: number\n /**\n * The delay from when the mouse leaves a tooltip content until the tooltip hides.\n * Inherits from the nearest `TooltipProvider`.\n * @default 0\n */\n delayHide?: number\n /**\n * Callback function to be called when the tooltip is opened.\n */\n onShow?: () => void\n /**\n * Callback function to be called when the tooltip is closed.\n */\n onHide?: () => void\n /**\n * Event handler called when the escape key is down.\n * It can be prevented by calling `event.preventDefault`.\n */\n onEscapeKeyDown?: (event: KeyboardEvent) => void\n /**\n * Event handler called when a pointer event occurs outside the bounds of the component.\n * It can be prevented by calling `event.preventDefault`.\n */\n onPointerDownOutside?: (event: CustomEvent<{ originalEvent: PointerEvent }>) => void\n}\n\nexport interface TooltipProviderProps extends\n ChildrenProps,\n TooltipProviderOptions {}\n\nexport interface TooltipProps extends\n BezierComponentProps,\n ChildrenProps<React.ReactElement>,\n ContentProps,\n DisableProps,\n Omit<React.HTMLAttributes<HTMLDivElement>, keyof ContentProps | keyof ChildrenProps>,\n TooltipOptions {}\n"],"names":["TooltipPosition"],"mappings":";;AASA;AACA;AACA;AACYA,IAAAA,eAAe,0BAAfA,eAAe,EAAA;EAAfA,eAAe,CAAA,WAAA,CAAA,GAAA,WAAA,CAAA;EAAfA,eAAe,CAAA,SAAA,CAAA,GAAA,SAAA,CAAA;EAAfA,eAAe,CAAA,UAAA,CAAA,GAAA,UAAA,CAAA;EAAfA,eAAe,CAAA,aAAA,CAAA,GAAA,aAAA,CAAA;EAAfA,eAAe,CAAA,UAAA,CAAA,GAAA,UAAA,CAAA;EAAfA,eAAe,CAAA,aAAA,CAAA,GAAA,aAAA,CAAA;EAAfA,eAAe,CAAA,cAAA,CAAA,GAAA,cAAA,CAAA;EAAfA,eAAe,CAAA,YAAA,CAAA,GAAA,YAAA,CAAA;EAAfA,eAAe,CAAA,aAAA,CAAA,GAAA,aAAA,CAAA;EAAfA,eAAe,CAAA,YAAA,CAAA,GAAA,YAAA,CAAA;EAAfA,eAAe,CAAA,SAAA,CAAA,GAAA,SAAA,CAAA;EAAfA,eAAe,CAAA,YAAA,CAAA,GAAA,YAAA,CAAA;AAAA,EAAA,OAAfA,eAAe,CAAA;AAAA,CAAA,CAAA,EAAA;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React__default, { useMemo, forwardRef, useState, useRef,
|
|
1
|
+
import React__default, { useMemo, forwardRef, useState, useRef, useCallback, useEffect } from 'react';
|
|
2
2
|
import { Provider as $a093c7e1ec25a057$export$2881499e37b75b9a, Root as $a093c7e1ec25a057$export$be92b6f5f03c0fe9, Trigger as $a093c7e1ec25a057$export$41fb9f06171c75f4, Portal as $a093c7e1ec25a057$export$602eac185826482c, Content as $a093c7e1ec25a057$export$7c6e2c02157bb7d2 } from '../../node_modules/@radix-ui/react-tooltip/dist/index.mjs';
|
|
3
3
|
import { getRootElement } from '../../utils/domUtils.mjs';
|
|
4
4
|
import { createContext } from '../../utils/reactUtils.mjs';
|
|
@@ -111,12 +111,31 @@ function TooltipProvider({
|
|
|
111
111
|
value: contextValue
|
|
112
112
|
}, children));
|
|
113
113
|
}
|
|
114
|
-
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* `Tooltip` is a component that shows additional information when the mouse hovers or the keyboard is focused.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
*
|
|
120
|
+
* ```tsx
|
|
121
|
+
* // Anatomy of the Tooltip
|
|
122
|
+
* <TooltipProvider>
|
|
123
|
+
* <Tooltip />
|
|
124
|
+
* </TooltipProvider>
|
|
125
|
+
*
|
|
126
|
+
* // Example of a Tooltip with a button
|
|
127
|
+
* <Tooltip content="Ta-da!">
|
|
128
|
+
* <button>Hover me</button>
|
|
129
|
+
* </Tooltip>
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
const Tooltip = /*#__PURE__*/forwardRef(function Tooltip({
|
|
115
133
|
as,
|
|
116
134
|
children,
|
|
117
135
|
defaultShow,
|
|
118
136
|
onShow: onShowProp,
|
|
119
137
|
onHide: onHideProp,
|
|
138
|
+
disabled,
|
|
120
139
|
content,
|
|
121
140
|
description,
|
|
122
141
|
icon,
|
|
@@ -137,13 +156,7 @@ const TooltipImpl = /*#__PURE__*/forwardRef(function TooltipImpl({
|
|
|
137
156
|
const delayHide = delayHideProp ?? globalDelayHide;
|
|
138
157
|
const defaultContainer = getRootElement();
|
|
139
158
|
const container = givenContainer ?? defaultContainer;
|
|
140
|
-
|
|
141
|
-
return function cleanUp() {
|
|
142
|
-
if (timeoutRef.current) {
|
|
143
|
-
clearTimeout(timeoutRef.current);
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
}, []);
|
|
159
|
+
const shouldBeHidden = useMemo(() => disabled || isEmpty(content), [disabled, content]);
|
|
147
160
|
const onShow = useCallback(() => {
|
|
148
161
|
setShow(true);
|
|
149
162
|
onShowProp?.();
|
|
@@ -152,7 +165,22 @@ const TooltipImpl = /*#__PURE__*/forwardRef(function TooltipImpl({
|
|
|
152
165
|
setShow(false);
|
|
153
166
|
onHideProp?.();
|
|
154
167
|
}, [onHideProp]);
|
|
168
|
+
useEffect(function forceHide() {
|
|
169
|
+
if (shouldBeHidden) {
|
|
170
|
+
onHide();
|
|
171
|
+
}
|
|
172
|
+
}, [shouldBeHidden, onHide]);
|
|
173
|
+
useEffect(function cleanUpTimeout() {
|
|
174
|
+
return function cleanUp() {
|
|
175
|
+
if (timeoutRef.current) {
|
|
176
|
+
clearTimeout(timeoutRef.current);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}, [shouldBeHidden]);
|
|
155
180
|
const onOpenChange = useCallback(open => {
|
|
181
|
+
if (shouldBeHidden) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
156
184
|
if (open) {
|
|
157
185
|
onShow();
|
|
158
186
|
return;
|
|
@@ -168,7 +196,7 @@ const TooltipImpl = /*#__PURE__*/forwardRef(function TooltipImpl({
|
|
|
168
196
|
return;
|
|
169
197
|
}
|
|
170
198
|
onHide();
|
|
171
|
-
}, [delayHide, onShow, onHide]);
|
|
199
|
+
}, [shouldBeHidden, delayHide, onShow, onHide]);
|
|
172
200
|
return /*#__PURE__*/React__default.createElement($a093c7e1ec25a057$export$be92b6f5f03c0fe9, {
|
|
173
201
|
open: show,
|
|
174
202
|
defaultOpen: defaultShow,
|
|
@@ -193,37 +221,5 @@ const TooltipImpl = /*#__PURE__*/forwardRef(function TooltipImpl({
|
|
|
193
221
|
})))));
|
|
194
222
|
});
|
|
195
223
|
|
|
196
|
-
/**
|
|
197
|
-
* `Tooltip` is a component that shows additional information when the mouse hovers or the keyboard is focused.
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
*
|
|
201
|
-
* ```tsx
|
|
202
|
-
* // Anatomy of the Tooltip
|
|
203
|
-
* <TooltipProvider>
|
|
204
|
-
* <Tooltip />
|
|
205
|
-
* </TooltipProvider>
|
|
206
|
-
*
|
|
207
|
-
* // Example of a Tooltip with a button
|
|
208
|
-
* <Tooltip content="Ta-da!">
|
|
209
|
-
* <button>Hover me</button>
|
|
210
|
-
* </Tooltip>
|
|
211
|
-
* ```
|
|
212
|
-
*/
|
|
213
|
-
const Tooltip = /*#__PURE__*/forwardRef(function Tooltip({
|
|
214
|
-
children,
|
|
215
|
-
disabled,
|
|
216
|
-
content,
|
|
217
|
-
...rest
|
|
218
|
-
}, forwardedRef) {
|
|
219
|
-
if (disabled || isEmpty(content)) {
|
|
220
|
-
return children ?? null;
|
|
221
|
-
}
|
|
222
|
-
return /*#__PURE__*/React__default.createElement(TooltipImpl, Object.assign({
|
|
223
|
-
ref: forwardedRef,
|
|
224
|
-
content: content
|
|
225
|
-
}, rest), children);
|
|
226
|
-
});
|
|
227
|
-
|
|
228
224
|
export { Tooltip, TooltipProvider };
|
|
229
225
|
//# sourceMappingURL=Tooltip.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.mjs","sources":["../../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react'\n\nimport * as TooltipPrimitive from '@radix-ui/react-tooltip'\n\nimport { getRootElement } from '~/src/utils/domUtils'\nimport { createContext } from '~/src/utils/reactUtils'\nimport {\n isBoolean,\n isEmpty,\n} from '~/src/utils/typeUtils'\n\nimport {\n type TooltipImplProps,\n TooltipPosition,\n type TooltipProps,\n type TooltipProviderProps,\n} from './Tooltip.types'\n\nimport * as Styled from './Tooltip.styled'\n\nfunction getSideAndAlign(\n placement: TooltipPosition,\n): Pick<TooltipPrimitive.TooltipContentProps, 'side' | 'align'> {\n switch (placement) {\n case TooltipPosition.TopCenter:\n return {\n side: 'top',\n align: 'center',\n }\n case TooltipPosition.TopLeft:\n return {\n side: 'top',\n align: 'start',\n }\n case TooltipPosition.TopRight:\n return {\n side: 'top',\n align: 'end',\n }\n case TooltipPosition.RightCenter:\n return {\n side: 'right',\n align: 'center',\n }\n case TooltipPosition.RightTop:\n return {\n side: 'right',\n align: 'start',\n }\n case TooltipPosition.RightBottom:\n return {\n side: 'right',\n align: 'end',\n }\n case TooltipPosition.BottomCenter:\n return {\n side: 'bottom',\n align: 'center',\n }\n case TooltipPosition.BottomLeft:\n return {\n side: 'bottom',\n align: 'start',\n }\n case TooltipPosition.BottomRight:\n return {\n side: 'bottom',\n align: 'end',\n }\n case TooltipPosition.LeftCenter:\n return {\n side: 'left',\n align: 'center',\n }\n case TooltipPosition.LeftTop:\n return {\n side: 'left',\n align: 'start',\n }\n case TooltipPosition.LeftBottom:\n return {\n side: 'left',\n align: 'end',\n }\n default:\n // NOTE: should not reach here\n return {\n side: undefined,\n align: undefined,\n }\n }\n}\n\nconst [\n /**\n * NOTE: Custom context use because the radix-ui doesn't support `delayHide`.\n */\n TooltipGlobalContextProvider,\n useTooltipGlobalContext,\n] = createContext<Required<Pick<TooltipProviderProps, 'delayHide'>> | null>(null, 'TooltipProvider')\n\n/**\n * `TooltipProvider` is used to globally provide props to child tooltips.\n *\n * @example\n *\n * ```tsx\n * <TooltipProvider allowHover delayShow={1000}>\n * <Tooltip />\n * </TooltipProvider>\n * ```\n */\nexport function TooltipProvider({\n children,\n allowHover = false,\n delayShow = 300,\n delayHide = 0,\n skipDelayShow = 500,\n}: TooltipProviderProps) {\n const contextValue = useMemo(() => ({\n delayHide,\n }), [delayHide])\n\n return (\n <TooltipPrimitive.Provider\n delayDuration={delayShow}\n skipDelayDuration={skipDelayShow}\n disableHoverableContent={!allowHover}\n >\n <TooltipGlobalContextProvider value={contextValue}>\n { children }\n </TooltipGlobalContextProvider>\n </TooltipPrimitive.Provider>\n )\n}\n\nconst TooltipImpl = forwardRef<HTMLDivElement, TooltipImplProps>(function TooltipImpl({\n as,\n children,\n defaultShow,\n onShow: onShowProp,\n onHide: onHideProp,\n content,\n description,\n icon,\n placement = TooltipPosition.BottomCenter,\n offset = 4,\n container: givenContainer,\n keepInContainer = true,\n allowHover,\n delayShow,\n delayHide: delayHideProp,\n ...rest\n}, forwardedRef) {\n const [show, setShow] = useState<boolean>(defaultShow ?? false)\n const timeoutRef = useRef<NodeJS.Timeout>()\n\n const { delayHide: globalDelayHide } = useTooltipGlobalContext('Tooltip')\n const delayHide = delayHideProp ?? globalDelayHide\n\n const defaultContainer = getRootElement()\n const container = givenContainer ?? defaultContainer\n\n useEffect(function cleanUpTimeout() {\n return function cleanUp() {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n }\n }\n }, [])\n\n const onShow = useCallback(() => {\n setShow(true)\n onShowProp?.()\n }, [onShowProp])\n\n const onHide = useCallback(() => {\n setShow(false)\n onHideProp?.()\n }, [onHideProp])\n\n const onOpenChange = useCallback((open: boolean) => {\n if (open) {\n onShow()\n return\n }\n\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n timeoutRef.current = undefined\n }\n\n if (delayHide > 0) {\n timeoutRef.current = setTimeout(() => {\n onHide()\n }, delayHide)\n return\n }\n\n onHide()\n }, [\n delayHide,\n onShow,\n onHide,\n ])\n\n return (\n <TooltipPrimitive.Root\n open={show}\n defaultOpen={defaultShow}\n delayDuration={delayShow}\n disableHoverableContent={isBoolean(allowHover) ? !allowHover : undefined}\n onOpenChange={onOpenChange}\n >\n <TooltipPrimitive.Trigger asChild>\n { children }\n </TooltipPrimitive.Trigger>\n\n <TooltipPrimitive.Portal container={container}>\n <TooltipPrimitive.Content\n {...rest}\n {...getSideAndAlign(placement)}\n asChild\n ref={forwardedRef}\n sideOffset={offset}\n avoidCollisions={keepInContainer}\n collisionPadding={8}\n hideWhenDetached\n >\n <Styled.TooltipContent forwardedAs={as}>\n <Styled.TextContainer>\n <Styled.Content>\n { content }\n </Styled.Content>\n\n { description && (\n <Styled.Description>\n { description }\n </Styled.Description>\n ) }\n </Styled.TextContainer>\n\n { icon && (\n <Styled.Icon source={icon} />\n ) }\n </Styled.TooltipContent>\n </TooltipPrimitive.Content>\n </TooltipPrimitive.Portal>\n </TooltipPrimitive.Root>\n )\n})\n\n/**\n * `Tooltip` is a component that shows additional information when the mouse hovers or the keyboard is focused.\n *\n * @example\n *\n * ```tsx\n * // Anatomy of the Tooltip\n * <TooltipProvider>\n * <Tooltip />\n * </TooltipProvider>\n *\n * // Example of a Tooltip with a button\n * <Tooltip content=\"Ta-da!\">\n * <button>Hover me</button>\n * </Tooltip>\n * ```\n */\nexport const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(function Tooltip({\n children,\n disabled,\n content,\n ...rest\n}, forwardedRef) {\n if (disabled || isEmpty(content)) {\n return children ?? null\n }\n\n return (\n <TooltipImpl\n ref={forwardedRef}\n content={content}\n {...rest}\n >\n { children }\n </TooltipImpl>\n )\n})\n"],"names":["getSideAndAlign","placement","TooltipPosition","TopCenter","side","align","TopLeft","TopRight","RightCenter","RightTop","RightBottom","BottomCenter","BottomLeft","BottomRight","LeftCenter","LeftTop","LeftBottom","undefined","TooltipGlobalContextProvider","useTooltipGlobalContext","createContext","TooltipProvider","children","allowHover","delayShow","delayHide","skipDelayShow","contextValue","useMemo","React","createElement","TooltipPrimitive","delayDuration","skipDelayDuration","disableHoverableContent","value","TooltipImpl","forwardRef","as","defaultShow","onShow","onShowProp","onHide","onHideProp","content","description","icon","offset","container","givenContainer","keepInContainer","delayHideProp","rest","forwardedRef","show","setShow","useState","timeoutRef","useRef","globalDelayHide","defaultContainer","getRootElement","useEffect","cleanUpTimeout","cleanUp","current","clearTimeout","useCallback","onOpenChange","open","setTimeout","defaultOpen","isBoolean","asChild","Object","assign","ref","sideOffset","avoidCollisions","collisionPadding","hideWhenDetached","Styled","forwardedAs","source","Tooltip","disabled","isEmpty"],"mappings":";;;;;;;;AA2BA,SAASA,eAAeA,CACtBC,SAA0B,EACoC;AAC9D,EAAA,QAAQA,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EvB,YAAa;AAClBT,IAAAA,OAAO,EAAEA,OAAAA;GACLQ,EAAAA,IAAI,CAEN9B,EAAAA,QACS,CAAC,CAAA;AAElB,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"Tooltip.mjs","sources":["../../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react'\n\nimport * as TooltipPrimitive from '@radix-ui/react-tooltip'\n\nimport { getRootElement } from '~/src/utils/domUtils'\nimport { createContext } from '~/src/utils/reactUtils'\nimport {\n isBoolean,\n isEmpty,\n} from '~/src/utils/typeUtils'\n\nimport {\n TooltipPosition,\n type TooltipProps,\n type TooltipProviderProps,\n} from './Tooltip.types'\n\nimport * as Styled from './Tooltip.styled'\n\nfunction getSideAndAlign(\n placement: TooltipPosition,\n): Pick<TooltipPrimitive.TooltipContentProps, 'side' | 'align'> {\n switch (placement) {\n case TooltipPosition.TopCenter:\n return {\n side: 'top',\n align: 'center',\n }\n case TooltipPosition.TopLeft:\n return {\n side: 'top',\n align: 'start',\n }\n case TooltipPosition.TopRight:\n return {\n side: 'top',\n align: 'end',\n }\n case TooltipPosition.RightCenter:\n return {\n side: 'right',\n align: 'center',\n }\n case TooltipPosition.RightTop:\n return {\n side: 'right',\n align: 'start',\n }\n case TooltipPosition.RightBottom:\n return {\n side: 'right',\n align: 'end',\n }\n case TooltipPosition.BottomCenter:\n return {\n side: 'bottom',\n align: 'center',\n }\n case TooltipPosition.BottomLeft:\n return {\n side: 'bottom',\n align: 'start',\n }\n case TooltipPosition.BottomRight:\n return {\n side: 'bottom',\n align: 'end',\n }\n case TooltipPosition.LeftCenter:\n return {\n side: 'left',\n align: 'center',\n }\n case TooltipPosition.LeftTop:\n return {\n side: 'left',\n align: 'start',\n }\n case TooltipPosition.LeftBottom:\n return {\n side: 'left',\n align: 'end',\n }\n default:\n // NOTE: should not reach here\n return {\n side: undefined,\n align: undefined,\n }\n }\n}\n\nconst [\n /**\n * NOTE: Custom context use because the radix-ui doesn't support `delayHide`.\n */\n TooltipGlobalContextProvider,\n useTooltipGlobalContext,\n] = createContext<Required<Pick<TooltipProviderProps, 'delayHide'>> | null>(null, 'TooltipProvider')\n\n/**\n * `TooltipProvider` is used to globally provide props to child tooltips.\n *\n * @example\n *\n * ```tsx\n * <TooltipProvider allowHover delayShow={1000}>\n * <Tooltip />\n * </TooltipProvider>\n * ```\n */\nexport function TooltipProvider({\n children,\n allowHover = false,\n delayShow = 300,\n delayHide = 0,\n skipDelayShow = 500,\n}: TooltipProviderProps) {\n const contextValue = useMemo(() => ({\n delayHide,\n }), [delayHide])\n\n return (\n <TooltipPrimitive.Provider\n delayDuration={delayShow}\n skipDelayDuration={skipDelayShow}\n disableHoverableContent={!allowHover}\n >\n <TooltipGlobalContextProvider value={contextValue}>\n { children }\n </TooltipGlobalContextProvider>\n </TooltipPrimitive.Provider>\n )\n}\n\n/**\n * `Tooltip` is a component that shows additional information when the mouse hovers or the keyboard is focused.\n *\n * @example\n *\n * ```tsx\n * // Anatomy of the Tooltip\n * <TooltipProvider>\n * <Tooltip />\n * </TooltipProvider>\n *\n * // Example of a Tooltip with a button\n * <Tooltip content=\"Ta-da!\">\n * <button>Hover me</button>\n * </Tooltip>\n * ```\n */\nexport const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(function Tooltip({\n as,\n children,\n defaultShow,\n onShow: onShowProp,\n onHide: onHideProp,\n disabled,\n content,\n description,\n icon,\n placement = TooltipPosition.BottomCenter,\n offset = 4,\n container: givenContainer,\n keepInContainer = true,\n allowHover,\n delayShow,\n delayHide: delayHideProp,\n ...rest\n}, forwardedRef) {\n const [show, setShow] = useState<boolean>(defaultShow ?? false)\n const timeoutRef = useRef<NodeJS.Timeout>()\n\n const { delayHide: globalDelayHide } = useTooltipGlobalContext('Tooltip')\n const delayHide = delayHideProp ?? globalDelayHide\n\n const defaultContainer = getRootElement()\n const container = givenContainer ?? defaultContainer\n\n const shouldBeHidden = useMemo(() => (\n disabled || isEmpty(content)\n ), [\n disabled,\n content,\n ])\n\n const onShow = useCallback(() => {\n setShow(true)\n onShowProp?.()\n }, [onShowProp])\n\n const onHide = useCallback(() => {\n setShow(false)\n onHideProp?.()\n }, [onHideProp])\n\n useEffect(function forceHide() {\n if (shouldBeHidden) {\n onHide()\n }\n }, [\n shouldBeHidden,\n onHide,\n ])\n\n useEffect(function cleanUpTimeout() {\n return function cleanUp() {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n }\n }\n }, [shouldBeHidden])\n\n const onOpenChange = useCallback((open: boolean) => {\n if (shouldBeHidden) {\n return\n }\n\n if (open) {\n onShow()\n return\n }\n\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n timeoutRef.current = undefined\n }\n\n if (delayHide > 0) {\n timeoutRef.current = setTimeout(() => {\n onHide()\n }, delayHide)\n return\n }\n\n onHide()\n }, [\n shouldBeHidden,\n delayHide,\n onShow,\n onHide,\n ])\n\n return (\n <TooltipPrimitive.Root\n open={show}\n defaultOpen={defaultShow}\n delayDuration={delayShow}\n disableHoverableContent={isBoolean(allowHover) ? !allowHover : undefined}\n onOpenChange={onOpenChange}\n >\n <TooltipPrimitive.Trigger asChild>\n { children }\n </TooltipPrimitive.Trigger>\n\n <TooltipPrimitive.Portal container={container}>\n <TooltipPrimitive.Content\n {...rest}\n {...getSideAndAlign(placement)}\n asChild\n ref={forwardedRef}\n sideOffset={offset}\n avoidCollisions={keepInContainer}\n collisionPadding={8}\n hideWhenDetached\n >\n <Styled.TooltipContent forwardedAs={as}>\n <Styled.TextContainer>\n <Styled.Content>\n { content }\n </Styled.Content>\n\n { description && (\n <Styled.Description>\n { description }\n </Styled.Description>\n ) }\n </Styled.TextContainer>\n\n { icon && (\n <Styled.Icon source={icon} />\n ) }\n </Styled.TooltipContent>\n </TooltipPrimitive.Content>\n </TooltipPrimitive.Portal>\n </TooltipPrimitive.Root>\n )\n})\n"],"names":["getSideAndAlign","placement","TooltipPosition","TopCenter","side","align","TopLeft","TopRight","RightCenter","RightTop","RightBottom","BottomCenter","BottomLeft","BottomRight","LeftCenter","LeftTop","LeftBottom","undefined","TooltipGlobalContextProvider","useTooltipGlobalContext","createContext","TooltipProvider","children","allowHover","delayShow","delayHide","skipDelayShow","contextValue","useMemo","React","createElement","TooltipPrimitive","delayDuration","skipDelayDuration","disableHoverableContent","value","Tooltip","forwardRef","as","defaultShow","onShow","onShowProp","onHide","onHideProp","disabled","content","description","icon","offset","container","givenContainer","keepInContainer","delayHideProp","rest","forwardedRef","show","setShow","useState","timeoutRef","useRef","globalDelayHide","defaultContainer","getRootElement","shouldBeHidden","isEmpty","useCallback","useEffect","forceHide","cleanUpTimeout","cleanUp","current","clearTimeout","onOpenChange","open","setTimeout","defaultOpen","isBoolean","asChild","Object","assign","ref","sideOffset","avoidCollisions","collisionPadding","hideWhenDetached","Styled","forwardedAs","source"],"mappings":";;;;;;;;AA0BA,SAASA,eAAeA,CACtBC,SAA0B,EACoC;AAC9D,EAAA,QAAQA,SAAS;IACf,KAAKC,eAAe,CAACC,SAAS;MAC5B,OAAO;AACLC,QAAAA,IAAI,EAAE,KAAK;AACXC,QAAAA,KAAK,EAAE,QAAA;OACR,CAAA;IACH,KAAKH,eAAe,CAACI,OAAO;MAC1B,OAAO;AACLF,QAAAA,IAAI,EAAE,KAAK;AACXC,QAAAA,KAAK,EAAE,OAAA;OACR,CAAA;IACH,KAAKH,eAAe,CAACK,QAAQ;MAC3B,OAAO;AACLH,QAAAA,IAAI,EAAE,KAAK;AACXC,QAAAA,KAAK,EAAE,KAAA;OACR,CAAA;IACH,KAAKH,eAAe,CAACM,WAAW;MAC9B,OAAO;AACLJ,QAAAA,IAAI,EAAE,OAAO;AACbC,QAAAA,KAAK,EAAE,QAAA;OACR,CAAA;IACH,KAAKH,eAAe,CAACO,QAAQ;MAC3B,OAAO;AACLL,QAAAA,IAAI,EAAE,OAAO;AACbC,QAAAA,KAAK,EAAE,OAAA;OACR,CA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IAC9B4E,OAAO,EAAA,IAAA;AACPG,IAAAA,GAAG,EAAE1B,YAAa;AAClB2B,IAAAA,UAAU,EAAEjC,MAAO;AACnBkC,IAAAA,eAAe,EAAE/B,eAAgB;AACjCgC,IAAAA,gBAAgB,EAAE,CAAE;IACpBC,gBAAgB,EAAA,IAAA;AAAA,GAAA,CAAA,eAEhBvD,cAAA,CAAAC,aAAA,CAACuD,cAAqB,EAAA;AAACC,IAAAA,WAAW,EAAEhD,EAAAA;AAAG,GAAA,eACrCT,cAAA,CAAAC,aAAA,CAACuD,aAAoB,EACnBxD,IAAAA,eAAAA,cAAA,CAAAC,aAAA,CAACuD,OAAc,EACXxC,IAAAA,EAAAA,OACY,CAAC,EAEfC,WAAW,iBACXjB,cAAA,CAAAC,aAAA,CAACuD,WAAkB,QACfvC,WACgB,CAEF,CAAC,EAErBC,IAAI,iBACJlB,cAAA,CAAAC,aAAA,CAACuD,IAAW,EAAA;AAACE,IAAAA,MAAM,EAAExC,IAAAA;AAAK,GAAE,CAET,CACC,CACH,CACJ,CAAC,CAAA;AAE5B,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.types.mjs","sources":["../../../../src/components/Tooltip/Tooltip.types.ts"],"sourcesContent":["import { type BezierIcon } from '@channel.io/bezier-icons'\n\nimport {\n type BezierComponentProps,\n type ChildrenProps,\n type ContentProps,\n type DisableProps,\n} from '~/src/types/ComponentProps'\n\n/**\n * An enumeration that determines the position of `Tooltip`.\n */\nexport enum TooltipPosition {\n TopCenter = 'topCenter',\n TopLeft = 'topLeft',\n TopRight = 'topRight',\n RightCenter = 'rightCenter',\n RightTop = 'rightTop',\n RightBottom = 'rightBottom',\n BottomCenter = 'bottomCenter',\n BottomLeft = 'bottomLeft',\n BottomRight = 'bottomRight',\n LeftCenter = 'leftCenter',\n LeftTop = 'leftTop',\n LeftBottom = 'leftBottom',\n}\n\ninterface TooltipProviderOptions {\n /**\n * Keeps the content of the tooltip open on hover. Disabling this feature affects accessibility.\n * @default false\n */\n allowHover?: boolean\n /**\n * The delay from when the mouse enters a tooltip trigger until the tooltip opens.\n * @default 300\n */\n delayShow?: number\n /**\n * The delay from when the mouse leaves a tooltip content until the tooltip hides.\n * @default 0\n */\n delayHide?: number\n /**\n * How much time a user has to enter another trigger without incurring a delay again.\n * @default 500\n */\n skipDelayShow?: number\n}\n\ninterface TooltipOptions {\n /**\n * The open state of the tooltip when it is initially rendered.\n */\n defaultShow?: boolean\n /**\n * An element that sits below the tooltip content.\n */\n description?: React.ReactNode\n /**\n * A decorative icon that sits right of the tooltip content.\n */\n icon?: BezierIcon\n /**\n * Options to determine the location from the trigger.\n * @default TooltipPosition.BottomCenter\n */\n placement?: TooltipPosition\n /**\n * The distance in pixels from the trigger.\n * @default 4\n */\n offset?: number\n /**\n * Specify a container element to portal the content into.\n * @note When placed inside a `Modal`, default value is the container element of `Modal`.\n * @default document.body\n */\n container?: HTMLElement | null\n /**\n * When `true`, overrides the `position` of the tooltip\n * to prevent collisions with boundary edges.\n * @default true\n */\n keepInContainer?: boolean\n /**\n * Keeps the content of the tooltip open on hover. Disabling this feature affects accessibility.\n * Inherits from the nearest `TooltipProvider`.\n * @default false\n */\n allowHover?: boolean\n /**\n * The delay from when the mouse enters a tooltip trigger until the tooltip opens.\n * Inherits from the nearest `TooltipProvider`.\n * @default 300\n */\n delayShow?: number\n /**\n * The delay from when the mouse leaves a tooltip content until the tooltip hides.\n * Inherits from the nearest `TooltipProvider`.\n * @default 0\n */\n delayHide?: number\n /**\n * Callback function to be called when the tooltip is opened.\n */\n onShow?: () => void\n /**\n * Callback function to be called when the tooltip is closed.\n */\n onHide?: () => void\n /**\n * Event handler called when the escape key is down.\n * It can be prevented by calling `event.preventDefault`.\n */\n onEscapeKeyDown?: (event: KeyboardEvent) => void\n /**\n * Event handler called when a pointer event occurs outside the bounds of the component.\n * It can be prevented by calling `event.preventDefault`.\n */\n onPointerDownOutside?: (event: CustomEvent<{ originalEvent: PointerEvent }>) => void\n}\n\nexport interface TooltipProviderProps extends\n ChildrenProps,\n TooltipProviderOptions {}\n\nexport interface
|
|
1
|
+
{"version":3,"file":"Tooltip.types.mjs","sources":["../../../../src/components/Tooltip/Tooltip.types.ts"],"sourcesContent":["import { type BezierIcon } from '@channel.io/bezier-icons'\n\nimport {\n type BezierComponentProps,\n type ChildrenProps,\n type ContentProps,\n type DisableProps,\n} from '~/src/types/ComponentProps'\n\n/**\n * An enumeration that determines the position of `Tooltip`.\n */\nexport enum TooltipPosition {\n TopCenter = 'topCenter',\n TopLeft = 'topLeft',\n TopRight = 'topRight',\n RightCenter = 'rightCenter',\n RightTop = 'rightTop',\n RightBottom = 'rightBottom',\n BottomCenter = 'bottomCenter',\n BottomLeft = 'bottomLeft',\n BottomRight = 'bottomRight',\n LeftCenter = 'leftCenter',\n LeftTop = 'leftTop',\n LeftBottom = 'leftBottom',\n}\n\ninterface TooltipProviderOptions {\n /**\n * Keeps the content of the tooltip open on hover. Disabling this feature affects accessibility.\n * @default false\n */\n allowHover?: boolean\n /**\n * The delay from when the mouse enters a tooltip trigger until the tooltip opens.\n * @default 300\n */\n delayShow?: number\n /**\n * The delay from when the mouse leaves a tooltip content until the tooltip hides.\n * @default 0\n */\n delayHide?: number\n /**\n * How much time a user has to enter another trigger without incurring a delay again.\n * @default 500\n */\n skipDelayShow?: number\n}\n\ninterface TooltipOptions {\n /**\n * The open state of the tooltip when it is initially rendered.\n */\n defaultShow?: boolean\n /**\n * An element that sits below the tooltip content.\n */\n description?: React.ReactNode\n /**\n * A decorative icon that sits right of the tooltip content.\n */\n icon?: BezierIcon\n /**\n * Options to determine the location from the trigger.\n * @default TooltipPosition.BottomCenter\n */\n placement?: TooltipPosition\n /**\n * The distance in pixels from the trigger.\n * @default 4\n */\n offset?: number\n /**\n * Specify a container element to portal the content into.\n * @note When placed inside a `Modal`, default value is the container element of `Modal`.\n * @default document.body\n */\n container?: HTMLElement | null\n /**\n * When `true`, overrides the `position` of the tooltip\n * to prevent collisions with boundary edges.\n * @default true\n */\n keepInContainer?: boolean\n /**\n * Keeps the content of the tooltip open on hover. Disabling this feature affects accessibility.\n * Inherits from the nearest `TooltipProvider`.\n * @default false\n */\n allowHover?: boolean\n /**\n * The delay from when the mouse enters a tooltip trigger until the tooltip opens.\n * Inherits from the nearest `TooltipProvider`.\n * @default 300\n */\n delayShow?: number\n /**\n * The delay from when the mouse leaves a tooltip content until the tooltip hides.\n * Inherits from the nearest `TooltipProvider`.\n * @default 0\n */\n delayHide?: number\n /**\n * Callback function to be called when the tooltip is opened.\n */\n onShow?: () => void\n /**\n * Callback function to be called when the tooltip is closed.\n */\n onHide?: () => void\n /**\n * Event handler called when the escape key is down.\n * It can be prevented by calling `event.preventDefault`.\n */\n onEscapeKeyDown?: (event: KeyboardEvent) => void\n /**\n * Event handler called when a pointer event occurs outside the bounds of the component.\n * It can be prevented by calling `event.preventDefault`.\n */\n onPointerDownOutside?: (event: CustomEvent<{ originalEvent: PointerEvent }>) => void\n}\n\nexport interface TooltipProviderProps extends\n ChildrenProps,\n TooltipProviderOptions {}\n\nexport interface TooltipProps extends\n BezierComponentProps,\n ChildrenProps<React.ReactElement>,\n ContentProps,\n DisableProps,\n Omit<React.HTMLAttributes<HTMLDivElement>, keyof ContentProps | keyof ChildrenProps>,\n TooltipOptions {}\n"],"names":["TooltipPosition"],"mappings":"AASA;AACA;AACA;AACYA,IAAAA,eAAe,0BAAfA,eAAe,EAAA;EAAfA,eAAe,CAAA,WAAA,CAAA,GAAA,WAAA,CAAA;EAAfA,eAAe,CAAA,SAAA,CAAA,GAAA,SAAA,CAAA;EAAfA,eAAe,CAAA,UAAA,CAAA,GAAA,UAAA,CAAA;EAAfA,eAAe,CAAA,aAAA,CAAA,GAAA,aAAA,CAAA;EAAfA,eAAe,CAAA,UAAA,CAAA,GAAA,UAAA,CAAA;EAAfA,eAAe,CAAA,aAAA,CAAA,GAAA,aAAA,CAAA;EAAfA,eAAe,CAAA,cAAA,CAAA,GAAA,cAAA,CAAA;EAAfA,eAAe,CAAA,YAAA,CAAA,GAAA,YAAA,CAAA;EAAfA,eAAe,CAAA,aAAA,CAAA,GAAA,aAAA,CAAA;EAAfA,eAAe,CAAA,YAAA,CAAA,GAAA,YAAA,CAAA;EAAfA,eAAe,CAAA,SAAA,CAAA,GAAA,SAAA,CAAA;EAAfA,eAAe,CAAA,YAAA,CAAA,GAAA,YAAA,CAAA;AAAA,EAAA,OAAfA,eAAe,CAAA;AAAA,CAAA,CAAA,EAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../../../src/components/Tooltip/Tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAA;AAWd,OAAO,
|
|
1
|
+
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../../../src/components/Tooltip/Tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAA;AAWd,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAC1B,MAAM,iBAAiB,CAAA;AAqFxB;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,UAAkB,EAClB,SAAe,EACf,SAAa,EACb,aAAmB,GACpB,EAAE,oBAAoB,qBAgBtB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,OAAO,qFAwIlB,CAAA"}
|
|
@@ -116,9 +116,7 @@ interface TooltipOptions {
|
|
|
116
116
|
}
|
|
117
117
|
export interface TooltipProviderProps extends ChildrenProps, TooltipProviderOptions {
|
|
118
118
|
}
|
|
119
|
-
export interface
|
|
120
|
-
}
|
|
121
|
-
export interface TooltipProps extends DisableProps, TooltipImplProps {
|
|
119
|
+
export interface TooltipProps extends BezierComponentProps, ChildrenProps<React.ReactElement>, ContentProps, DisableProps, Omit<React.HTMLAttributes<HTMLDivElement>, keyof ContentProps | keyof ChildrenProps>, TooltipOptions {
|
|
122
120
|
}
|
|
123
121
|
export {};
|
|
124
122
|
//# sourceMappingURL=Tooltip.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.types.d.ts","sourceRoot":"","sources":["../../../../src/components/Tooltip/Tooltip.types.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,mCAAkC;AAEnC;;GAEG;AACH,oBAAY,eAAe;IACzB,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,YAAY,iBAAiB;IAC7B,UAAU,eAAe;IACzB,WAAW,gBAAgB;IAC3B,UAAU,eAAe;IACzB,OAAO,YAAY;IACnB,UAAU,eAAe;CAC1B;AAED,UAAU,sBAAsB;IAC9B;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,UAAU,cAAc;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B;;OAEG;IACH,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,eAAe,CAAA;IAC3B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;OAIG;IACH,SAAS,CAAC,EAAE,WAAW,GAAG,IAAI,CAAA;IAC9B;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;IAChD;;;OAGG;IACH,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC;QAAE,aAAa,EAAE,YAAY,CAAA;KAAE,CAAC,KAAK,IAAI,CAAA;CACrF;AAED,MAAM,WAAW,oBAAqB,SACpC,aAAa,EACb,sBAAsB;CAAG;AAE3B,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"Tooltip.types.d.ts","sourceRoot":"","sources":["../../../../src/components/Tooltip/Tooltip.types.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,mCAAkC;AAEnC;;GAEG;AACH,oBAAY,eAAe;IACzB,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,YAAY,iBAAiB;IAC7B,UAAU,eAAe;IACzB,WAAW,gBAAgB;IAC3B,UAAU,eAAe;IACzB,OAAO,YAAY;IACnB,UAAU,eAAe;CAC1B;AAED,UAAU,sBAAsB;IAC9B;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;OA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G"}
|
package/package.json
CHANGED
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
} from '~/src/utils/typeUtils'
|
|
18
18
|
|
|
19
19
|
import {
|
|
20
|
-
type TooltipImplProps,
|
|
21
20
|
TooltipPosition,
|
|
22
21
|
type TooltipProps,
|
|
23
22
|
type TooltipProviderProps,
|
|
@@ -141,12 +140,30 @@ export function TooltipProvider({
|
|
|
141
140
|
)
|
|
142
141
|
}
|
|
143
142
|
|
|
144
|
-
|
|
143
|
+
/**
|
|
144
|
+
* `Tooltip` is a component that shows additional information when the mouse hovers or the keyboard is focused.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
*
|
|
148
|
+
* ```tsx
|
|
149
|
+
* // Anatomy of the Tooltip
|
|
150
|
+
* <TooltipProvider>
|
|
151
|
+
* <Tooltip />
|
|
152
|
+
* </TooltipProvider>
|
|
153
|
+
*
|
|
154
|
+
* // Example of a Tooltip with a button
|
|
155
|
+
* <Tooltip content="Ta-da!">
|
|
156
|
+
* <button>Hover me</button>
|
|
157
|
+
* </Tooltip>
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(function Tooltip({
|
|
145
161
|
as,
|
|
146
162
|
children,
|
|
147
163
|
defaultShow,
|
|
148
164
|
onShow: onShowProp,
|
|
149
165
|
onHide: onHideProp,
|
|
166
|
+
disabled,
|
|
150
167
|
content,
|
|
151
168
|
description,
|
|
152
169
|
icon,
|
|
@@ -168,13 +185,12 @@ const TooltipImpl = forwardRef<HTMLDivElement, TooltipImplProps>(function Toolti
|
|
|
168
185
|
const defaultContainer = getRootElement()
|
|
169
186
|
const container = givenContainer ?? defaultContainer
|
|
170
187
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}, [])
|
|
188
|
+
const shouldBeHidden = useMemo(() => (
|
|
189
|
+
disabled || isEmpty(content)
|
|
190
|
+
), [
|
|
191
|
+
disabled,
|
|
192
|
+
content,
|
|
193
|
+
])
|
|
178
194
|
|
|
179
195
|
const onShow = useCallback(() => {
|
|
180
196
|
setShow(true)
|
|
@@ -186,7 +202,28 @@ const TooltipImpl = forwardRef<HTMLDivElement, TooltipImplProps>(function Toolti
|
|
|
186
202
|
onHideProp?.()
|
|
187
203
|
}, [onHideProp])
|
|
188
204
|
|
|
205
|
+
useEffect(function forceHide() {
|
|
206
|
+
if (shouldBeHidden) {
|
|
207
|
+
onHide()
|
|
208
|
+
}
|
|
209
|
+
}, [
|
|
210
|
+
shouldBeHidden,
|
|
211
|
+
onHide,
|
|
212
|
+
])
|
|
213
|
+
|
|
214
|
+
useEffect(function cleanUpTimeout() {
|
|
215
|
+
return function cleanUp() {
|
|
216
|
+
if (timeoutRef.current) {
|
|
217
|
+
clearTimeout(timeoutRef.current)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}, [shouldBeHidden])
|
|
221
|
+
|
|
189
222
|
const onOpenChange = useCallback((open: boolean) => {
|
|
223
|
+
if (shouldBeHidden) {
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
|
|
190
227
|
if (open) {
|
|
191
228
|
onShow()
|
|
192
229
|
return
|
|
@@ -206,6 +243,7 @@ const TooltipImpl = forwardRef<HTMLDivElement, TooltipImplProps>(function Toolti
|
|
|
206
243
|
|
|
207
244
|
onHide()
|
|
208
245
|
}, [
|
|
246
|
+
shouldBeHidden,
|
|
209
247
|
delayHide,
|
|
210
248
|
onShow,
|
|
211
249
|
onHide,
|
|
@@ -256,41 +294,3 @@ const TooltipImpl = forwardRef<HTMLDivElement, TooltipImplProps>(function Toolti
|
|
|
256
294
|
</TooltipPrimitive.Root>
|
|
257
295
|
)
|
|
258
296
|
})
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* `Tooltip` is a component that shows additional information when the mouse hovers or the keyboard is focused.
|
|
262
|
-
*
|
|
263
|
-
* @example
|
|
264
|
-
*
|
|
265
|
-
* ```tsx
|
|
266
|
-
* // Anatomy of the Tooltip
|
|
267
|
-
* <TooltipProvider>
|
|
268
|
-
* <Tooltip />
|
|
269
|
-
* </TooltipProvider>
|
|
270
|
-
*
|
|
271
|
-
* // Example of a Tooltip with a button
|
|
272
|
-
* <Tooltip content="Ta-da!">
|
|
273
|
-
* <button>Hover me</button>
|
|
274
|
-
* </Tooltip>
|
|
275
|
-
* ```
|
|
276
|
-
*/
|
|
277
|
-
export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(function Tooltip({
|
|
278
|
-
children,
|
|
279
|
-
disabled,
|
|
280
|
-
content,
|
|
281
|
-
...rest
|
|
282
|
-
}, forwardedRef) {
|
|
283
|
-
if (disabled || isEmpty(content)) {
|
|
284
|
-
return children ?? null
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return (
|
|
288
|
-
<TooltipImpl
|
|
289
|
-
ref={forwardedRef}
|
|
290
|
-
content={content}
|
|
291
|
-
{...rest}
|
|
292
|
-
>
|
|
293
|
-
{ children }
|
|
294
|
-
</TooltipImpl>
|
|
295
|
-
)
|
|
296
|
-
})
|
|
@@ -125,13 +125,10 @@ export interface TooltipProviderProps extends
|
|
|
125
125
|
ChildrenProps,
|
|
126
126
|
TooltipProviderOptions {}
|
|
127
127
|
|
|
128
|
-
export interface
|
|
128
|
+
export interface TooltipProps extends
|
|
129
129
|
BezierComponentProps,
|
|
130
130
|
ChildrenProps<React.ReactElement>,
|
|
131
131
|
ContentProps,
|
|
132
|
+
DisableProps,
|
|
132
133
|
Omit<React.HTMLAttributes<HTMLDivElement>, keyof ContentProps | keyof ChildrenProps>,
|
|
133
134
|
TooltipOptions {}
|
|
134
|
-
|
|
135
|
-
export interface TooltipProps extends
|
|
136
|
-
DisableProps,
|
|
137
|
-
TooltipImplProps {}
|