@redsift/popovers 9.2.3-patch → 9.2.3
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/coverage/clover.xml +763 -0
- package/coverage/coverage-final.json +53 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/dialog/Dialog.tsx.html +271 -0
- package/coverage/lcov-report/dialog/context.ts.html +97 -0
- package/coverage/lcov-report/dialog/index.html +191 -0
- package/coverage/lcov-report/dialog/index.ts.html +100 -0
- package/coverage/lcov-report/dialog/types.ts.html +241 -0
- package/coverage/lcov-report/dialog/useDialog.tsx.html +346 -0
- package/coverage/lcov-report/dialog/useDialogContext.tsx.html +121 -0
- package/coverage/lcov-report/dialog-content/DialogContent.tsx.html +484 -0
- package/coverage/lcov-report/dialog-content/index.html +146 -0
- package/coverage/lcov-report/dialog-content/index.ts.html +91 -0
- package/coverage/lcov-report/dialog-content/intl/index.html +116 -0
- package/coverage/lcov-report/dialog-content/intl/index.ts.html +106 -0
- package/coverage/lcov-report/dialog-content/styles.ts.html +256 -0
- package/coverage/lcov-report/dialog-content-actions/DialogContentActions.tsx.html +205 -0
- package/coverage/lcov-report/dialog-content-actions/index.html +146 -0
- package/coverage/lcov-report/dialog-content-actions/index.ts.html +91 -0
- package/coverage/lcov-report/dialog-content-actions/styles.ts.html +139 -0
- package/coverage/lcov-report/dialog-content-body/DialogContentBody.tsx.html +232 -0
- package/coverage/lcov-report/dialog-content-body/index.html +146 -0
- package/coverage/lcov-report/dialog-content-body/index.ts.html +91 -0
- package/coverage/lcov-report/dialog-content-body/styles.ts.html +259 -0
- package/coverage/lcov-report/dialog-content-header/DialogContentHeader.tsx.html +280 -0
- package/coverage/lcov-report/dialog-content-header/index.html +146 -0
- package/coverage/lcov-report/dialog-content-header/index.ts.html +91 -0
- package/coverage/lcov-report/dialog-content-header/styles.ts.html +193 -0
- package/coverage/lcov-report/dialog-trigger/DialogTrigger.tsx.html +217 -0
- package/coverage/lcov-report/dialog-trigger/index.html +131 -0
- package/coverage/lcov-report/dialog-trigger/index.ts.html +91 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +341 -0
- package/coverage/lcov-report/popover/Popover.tsx.html +295 -0
- package/coverage/lcov-report/popover/context.ts.html +97 -0
- package/coverage/lcov-report/popover/index.html +191 -0
- package/coverage/lcov-report/popover/index.ts.html +100 -0
- package/coverage/lcov-report/popover/types.ts.html +283 -0
- package/coverage/lcov-report/popover/usePopover.tsx.html +415 -0
- package/coverage/lcov-report/popover/usePopoverContext.tsx.html +121 -0
- package/coverage/lcov-report/popover-content/PopoverContent.tsx.html +229 -0
- package/coverage/lcov-report/popover-content/index.html +146 -0
- package/coverage/lcov-report/popover-content/index.ts.html +94 -0
- package/coverage/lcov-report/popover-content/styles.ts.html +370 -0
- package/coverage/lcov-report/popover-trigger/PopoverTrigger.tsx.html +202 -0
- package/coverage/lcov-report/popover-trigger/index.html +131 -0
- package/coverage/lcov-report/popover-trigger/index.ts.html +91 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/toast/Toast.tsx.html +373 -0
- package/coverage/lcov-report/toast/index.html +161 -0
- package/coverage/lcov-report/toast/index.ts.html +91 -0
- package/coverage/lcov-report/toast/intl/index.html +116 -0
- package/coverage/lcov-report/toast/intl/index.ts.html +106 -0
- package/coverage/lcov-report/toast/styles.ts.html +193 -0
- package/coverage/lcov-report/toast/types.ts.html +217 -0
- package/coverage/lcov-report/toast-container/ToastContainer.tsx.html +217 -0
- package/coverage/lcov-report/toast-container/index.html +161 -0
- package/coverage/lcov-report/toast-container/index.ts.html +94 -0
- package/coverage/lcov-report/toast-container/styles.ts.html +2284 -0
- package/coverage/lcov-report/toast-container/useToast.tsx.html +469 -0
- package/coverage/lcov-report/tooltip/Tooltip.tsx.html +250 -0
- package/coverage/lcov-report/tooltip/context.ts.html +97 -0
- package/coverage/lcov-report/tooltip/index.html +191 -0
- package/coverage/lcov-report/tooltip/index.ts.html +100 -0
- package/coverage/lcov-report/tooltip/types.ts.html +250 -0
- package/coverage/lcov-report/tooltip/useTooltip.tsx.html +358 -0
- package/coverage/lcov-report/tooltip/useTooltipContext.tsx.html +121 -0
- package/coverage/lcov-report/tooltip-content/TooltipContent.tsx.html +313 -0
- package/coverage/lcov-report/tooltip-content/index.html +146 -0
- package/coverage/lcov-report/tooltip-content/index.ts.html +91 -0
- package/coverage/lcov-report/tooltip-content/styles.ts.html +337 -0
- package/coverage/lcov-report/tooltip-trigger/TooltipTrigger.tsx.html +211 -0
- package/coverage/lcov-report/tooltip-trigger/index.html +131 -0
- package/coverage/lcov-report/tooltip-trigger/index.ts.html +91 -0
- package/coverage/lcov.info +1510 -0
- package/coverage/storybook/coverage-storybook.json +58724 -0
- package/dist/package.json +96 -0
- package/index.ts +1 -0
- package/jest.config.js +3 -0
- package/package.json +2 -3
- package/rollup.config.js +13 -0
- package/src/components/dialog/Dialog.stories.tsx +264 -0
- package/src/components/dialog/Dialog.test.tsx +116 -0
- package/src/components/dialog/Dialog.tsx +62 -0
- package/src/components/dialog/context.ts +4 -0
- package/src/components/dialog/index.ts +5 -0
- package/src/components/dialog/types.ts +52 -0
- package/src/components/dialog/useDialog.tsx +87 -0
- package/src/components/dialog/useDialogContext.tsx +12 -0
- package/src/components/dialog-content/DialogContent.stories.tsx +348 -0
- package/src/components/dialog-content/DialogContent.tsx +133 -0
- package/src/components/dialog-content/index.ts +2 -0
- package/src/components/dialog-content/intl/en-US.json +3 -0
- package/src/components/dialog-content/intl/fr-FR.json +3 -0
- package/src/components/dialog-content/intl/index.ts +7 -0
- package/src/components/dialog-content/styles.ts +57 -0
- package/src/components/dialog-content/types.ts +10 -0
- package/src/components/dialog-content-actions/DialogContentActions.test.tsx +68 -0
- package/src/components/dialog-content-actions/DialogContentActions.tsx +40 -0
- package/src/components/dialog-content-actions/index.ts +2 -0
- package/src/components/dialog-content-actions/styles.ts +18 -0
- package/src/components/dialog-content-actions/types.ts +11 -0
- package/src/components/dialog-content-body/DialogContentBody.test.tsx +63 -0
- package/src/components/dialog-content-body/DialogContentBody.tsx +49 -0
- package/src/components/dialog-content-body/index.ts +2 -0
- package/src/components/dialog-content-body/styles.ts +58 -0
- package/src/components/dialog-content-body/types.ts +14 -0
- package/src/components/dialog-content-header/DialogContentHeader.test.tsx +63 -0
- package/src/components/dialog-content-header/DialogContentHeader.tsx +65 -0
- package/src/components/dialog-content-header/index.ts +2 -0
- package/src/components/dialog-content-header/styles.ts +36 -0
- package/src/components/dialog-content-header/types.ts +21 -0
- package/src/components/dialog-trigger/DialogTrigger.tsx +44 -0
- package/src/components/dialog-trigger/index.ts +2 -0
- package/src/components/dialog-trigger/types.ts +9 -0
- package/src/components/popover/Popover.stories.tsx +129 -0
- package/src/components/popover/Popover.test.tsx +102 -0
- package/src/components/popover/Popover.tsx +70 -0
- package/src/components/popover/context.ts +4 -0
- package/src/components/popover/index.ts +5 -0
- package/src/components/popover/types.ts +66 -0
- package/src/components/popover/usePopover.tsx +110 -0
- package/src/components/popover/usePopoverContext.tsx +12 -0
- package/src/components/popover-content/PopoverContent.tsx +48 -0
- package/src/components/popover-content/index.ts +3 -0
- package/src/components/popover-content/styles.ts +95 -0
- package/src/components/popover-content/types.ts +11 -0
- package/src/components/popover-trigger/PopoverTrigger.tsx +39 -0
- package/src/components/popover-trigger/index.ts +2 -0
- package/src/components/popover-trigger/types.ts +9 -0
- package/src/components/toast/Toast.stories.tsx +68 -0
- package/src/components/toast/Toast.test.tsx +63 -0
- package/src/components/toast/Toast.tsx +96 -0
- package/src/components/toast/index.ts +2 -0
- package/src/components/toast/intl/en-US.json +3 -0
- package/src/components/toast/intl/fr-FR.json +3 -0
- package/src/components/toast/intl/index.ts +7 -0
- package/src/components/toast/styles.ts +36 -0
- package/src/components/toast/types.ts +44 -0
- package/src/components/toast-container/ToastContainer.stories.tsx +349 -0
- package/src/components/toast-container/ToastContainer.tsx +44 -0
- package/src/components/toast-container/index.ts +3 -0
- package/src/components/toast-container/styles.ts +733 -0
- package/src/components/toast-container/types.ts +110 -0
- package/src/components/toast-container/useToast.test.tsx +111 -0
- package/src/components/toast-container/useToast.tsx +128 -0
- package/src/components/tooltip/Tooltip.stories.tsx +196 -0
- package/src/components/tooltip/Tooltip.test.tsx +119 -0
- package/src/components/tooltip/Tooltip.tsx +55 -0
- package/src/components/tooltip/context.ts +4 -0
- package/src/components/tooltip/index.ts +5 -0
- package/src/components/tooltip/types.ts +55 -0
- package/src/components/tooltip/useTooltip.tsx +93 -0
- package/src/components/tooltip/useTooltipContext.tsx +12 -0
- package/src/components/tooltip-content/TooltipContent.tsx +76 -0
- package/src/components/tooltip-content/index.ts +2 -0
- package/src/components/tooltip-content/styles.ts +84 -0
- package/src/components/tooltip-content/types.ts +14 -0
- package/src/components/tooltip-trigger/TooltipTrigger.tsx +42 -0
- package/src/components/tooltip-trigger/index.ts +2 -0
- package/src/components/tooltip-trigger/types.ts +9 -0
- package/src/index.ts +16 -0
- package/tsconfig.json +3 -0
- /package/{CONTRIBUTING.md → dist/CONTRIBUTING.md} +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{index.js.map → dist/index.js.map} +0 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { partitionComponents, isComponent } from '@redsift/design-system';
|
|
3
|
+
import { TooltipContent } from '../tooltip-content';
|
|
4
|
+
import { TooltipTrigger } from '../tooltip-trigger';
|
|
5
|
+
|
|
6
|
+
import { TooltipContext } from './context';
|
|
7
|
+
import { TooltipPlacement, TooltipProps } from './types';
|
|
8
|
+
import { useTooltip } from './useTooltip';
|
|
9
|
+
|
|
10
|
+
const COMPONENT_NAME = 'Tooltip';
|
|
11
|
+
const CLASSNAME = 'redsift-tooltip';
|
|
12
|
+
const DEFAULT_PROPS: Partial<TooltipProps> = {
|
|
13
|
+
delay: 500,
|
|
14
|
+
placement: TooltipPlacement.top,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The Tooltip component.
|
|
19
|
+
*/
|
|
20
|
+
export const BaseTooltip: React.FC<TooltipProps> & {
|
|
21
|
+
displayName?: string;
|
|
22
|
+
className?: string;
|
|
23
|
+
} = (props) => {
|
|
24
|
+
const { children, defaultOpen, delay, isOpen, onOpen, placement, tooltipId } =
|
|
25
|
+
props;
|
|
26
|
+
|
|
27
|
+
const tooltip = useTooltip({
|
|
28
|
+
defaultOpen,
|
|
29
|
+
delay,
|
|
30
|
+
placement,
|
|
31
|
+
isOpen,
|
|
32
|
+
onOpen,
|
|
33
|
+
tooltipId,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const [[trigger], [content]] = partitionComponents(
|
|
37
|
+
React.Children.toArray(children),
|
|
38
|
+
[isComponent('TooltipTrigger'), isComponent('TooltipContent')]
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<TooltipContext.Provider value={tooltip}>
|
|
43
|
+
{trigger}
|
|
44
|
+
{content}
|
|
45
|
+
</TooltipContext.Provider>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
BaseTooltip.className = CLASSNAME;
|
|
49
|
+
BaseTooltip.defaultProps = DEFAULT_PROPS;
|
|
50
|
+
BaseTooltip.displayName = COMPONENT_NAME;
|
|
51
|
+
|
|
52
|
+
export const Tooltip = Object.assign(BaseTooltip, {
|
|
53
|
+
Trigger: TooltipTrigger,
|
|
54
|
+
Content: TooltipContent,
|
|
55
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ValueOf } from '@redsift/design-system';
|
|
3
|
+
import { useTooltip } from './useTooltip';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Context props.
|
|
7
|
+
*/
|
|
8
|
+
export type TooltipState = ReturnType<typeof useTooltip> | null;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Component variant.
|
|
12
|
+
*/
|
|
13
|
+
export const TooltipPlacement = {
|
|
14
|
+
top: 'top',
|
|
15
|
+
right: 'right',
|
|
16
|
+
bottom: 'bottom',
|
|
17
|
+
left: 'left',
|
|
18
|
+
'top-start': 'top-start',
|
|
19
|
+
'top-end': 'top-end',
|
|
20
|
+
'right-start': 'right-start',
|
|
21
|
+
'right-end': 'right-end',
|
|
22
|
+
'bottom-start': 'bottom-start',
|
|
23
|
+
'bottom-end': 'bottom-end',
|
|
24
|
+
'left-start': 'left-start',
|
|
25
|
+
'left-end': 'left-end',
|
|
26
|
+
} as const;
|
|
27
|
+
export type TooltipPlacement = ValueOf<typeof TooltipPlacement>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Component props.
|
|
31
|
+
*/
|
|
32
|
+
export interface TooltipProps {
|
|
33
|
+
/** Children. Can only be TooltipTrigger and TooltilContent. */
|
|
34
|
+
children: ReactNode;
|
|
35
|
+
/**
|
|
36
|
+
* Default open status.
|
|
37
|
+
* Used for uncontrolled version.
|
|
38
|
+
*/
|
|
39
|
+
defaultOpen?: boolean;
|
|
40
|
+
/** Delay time (in ms) for the tooltip to show up. */
|
|
41
|
+
delay?: number;
|
|
42
|
+
/** Default placement of the tooltip. */
|
|
43
|
+
placement?: TooltipPlacement;
|
|
44
|
+
/**
|
|
45
|
+
* Whether the component is opened or not.
|
|
46
|
+
* Used for controlled version.
|
|
47
|
+
*/
|
|
48
|
+
isOpen?: boolean;
|
|
49
|
+
/** Method to handle component change. */
|
|
50
|
+
onOpen?: (open: boolean) => void;
|
|
51
|
+
/** Id to the tooltip content. */
|
|
52
|
+
tooltipId?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type StyledTooltipProps = TooltipProps;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
useFloating,
|
|
4
|
+
arrow,
|
|
5
|
+
autoUpdate,
|
|
6
|
+
offset,
|
|
7
|
+
flip,
|
|
8
|
+
safePolygon,
|
|
9
|
+
shift,
|
|
10
|
+
useHover,
|
|
11
|
+
useFocus,
|
|
12
|
+
useDismiss,
|
|
13
|
+
useRole,
|
|
14
|
+
useInteractions,
|
|
15
|
+
} from '@floating-ui/react';
|
|
16
|
+
import { TooltipProps } from './types';
|
|
17
|
+
import { useId } from '@redsift/design-system';
|
|
18
|
+
|
|
19
|
+
export function useTooltip({
|
|
20
|
+
defaultOpen,
|
|
21
|
+
delay,
|
|
22
|
+
placement,
|
|
23
|
+
isOpen: propsIsOpen,
|
|
24
|
+
onOpen,
|
|
25
|
+
tooltipId: propsTooltipId,
|
|
26
|
+
}: Omit<TooltipProps, 'children'>) {
|
|
27
|
+
const arrowRef = useRef(null);
|
|
28
|
+
const [isOpen, setIsOpen] = useState(propsIsOpen ?? defaultOpen);
|
|
29
|
+
|
|
30
|
+
const [_id] = useId();
|
|
31
|
+
const tooltipId = propsTooltipId ?? _id;
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
setIsOpen(propsIsOpen ?? defaultOpen);
|
|
35
|
+
}, [propsIsOpen, defaultOpen]);
|
|
36
|
+
|
|
37
|
+
const handleOpen = useCallback(
|
|
38
|
+
(collapsed: boolean) => {
|
|
39
|
+
if (onOpen) {
|
|
40
|
+
onOpen(collapsed);
|
|
41
|
+
}
|
|
42
|
+
if (propsIsOpen === undefined || propsIsOpen === null) {
|
|
43
|
+
setIsOpen(collapsed);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
[onOpen]
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const data = useFloating({
|
|
50
|
+
placement,
|
|
51
|
+
open: isOpen,
|
|
52
|
+
onOpenChange: handleOpen,
|
|
53
|
+
whileElementsMounted: autoUpdate,
|
|
54
|
+
middleware: [
|
|
55
|
+
offset(8),
|
|
56
|
+
flip({
|
|
57
|
+
fallbackAxisSideDirection: 'start',
|
|
58
|
+
}),
|
|
59
|
+
shift({ padding: 8 }),
|
|
60
|
+
arrow({
|
|
61
|
+
element: arrowRef,
|
|
62
|
+
}),
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const context = data.context;
|
|
67
|
+
|
|
68
|
+
const hover = useHover(context, {
|
|
69
|
+
move: false,
|
|
70
|
+
delay: {
|
|
71
|
+
open: delay,
|
|
72
|
+
close: 0,
|
|
73
|
+
},
|
|
74
|
+
handleClose: safePolygon(),
|
|
75
|
+
});
|
|
76
|
+
const focus = useFocus(context);
|
|
77
|
+
const dismiss = useDismiss(context);
|
|
78
|
+
const role = useRole(context, { role: 'tooltip' });
|
|
79
|
+
|
|
80
|
+
const interactions = useInteractions([hover, focus, dismiss, role]);
|
|
81
|
+
|
|
82
|
+
return React.useMemo(
|
|
83
|
+
() => ({
|
|
84
|
+
isOpen,
|
|
85
|
+
handleOpen,
|
|
86
|
+
...interactions,
|
|
87
|
+
...data,
|
|
88
|
+
arrowRef,
|
|
89
|
+
tooltipId,
|
|
90
|
+
}),
|
|
91
|
+
[isOpen, handleOpen, interactions, data, arrowRef, tooltipId]
|
|
92
|
+
);
|
|
93
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TooltipContext } from './context';
|
|
3
|
+
|
|
4
|
+
export const useTooltipContext = () => {
|
|
5
|
+
const context = React.useContext(TooltipContext);
|
|
6
|
+
|
|
7
|
+
if (context == null) {
|
|
8
|
+
throw new Error('Tooltip components must be wrapped in <Tooltip />');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return context;
|
|
12
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { useMergeRefs, FloatingPortal } from '@floating-ui/react';
|
|
3
|
+
|
|
4
|
+
import { Comp } from '@redsift/design-system';
|
|
5
|
+
import { TooltipContentProps } from './types';
|
|
6
|
+
import { TooltipPlacement, useTooltipContext } from '../tooltip';
|
|
7
|
+
import { StyledTooltipContent } from './styles';
|
|
8
|
+
import classNames from 'classnames';
|
|
9
|
+
|
|
10
|
+
const COMPONENT_NAME = 'TooltipContent';
|
|
11
|
+
const CLASSNAME = 'redsift-tooltip-content';
|
|
12
|
+
const DEFAULT_PROPS: Partial<TooltipContentProps> = {};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The TooltipContent component.
|
|
16
|
+
*/
|
|
17
|
+
export const TooltipContent: Comp<TooltipContentProps, HTMLDivElement> =
|
|
18
|
+
forwardRef((props, ref) => {
|
|
19
|
+
const { children, className, style } = props;
|
|
20
|
+
const {
|
|
21
|
+
getFloatingProps,
|
|
22
|
+
isOpen,
|
|
23
|
+
placement,
|
|
24
|
+
refs,
|
|
25
|
+
strategy,
|
|
26
|
+
x,
|
|
27
|
+
y,
|
|
28
|
+
middlewareData: { arrow: { x: arrowX, y: arrowY } = {} },
|
|
29
|
+
} = useTooltipContext();
|
|
30
|
+
const popoverRef = useMergeRefs([refs.setFloating, ref]);
|
|
31
|
+
|
|
32
|
+
const { arrowRef } = useTooltipContext();
|
|
33
|
+
|
|
34
|
+
const staticSide = {
|
|
35
|
+
top: 'bottom',
|
|
36
|
+
right: 'left',
|
|
37
|
+
bottom: 'top',
|
|
38
|
+
left: 'right',
|
|
39
|
+
}[placement.split('-')[0]];
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<FloatingPortal id="redsift-app-container">
|
|
43
|
+
{isOpen && (
|
|
44
|
+
<StyledTooltipContent
|
|
45
|
+
className={classNames(TooltipContent.className, className)}
|
|
46
|
+
ref={popoverRef}
|
|
47
|
+
style={{
|
|
48
|
+
position: strategy,
|
|
49
|
+
top: y ?? 0,
|
|
50
|
+
left: x ?? 0,
|
|
51
|
+
visibility: x == null ? 'hidden' : 'visible',
|
|
52
|
+
...style,
|
|
53
|
+
}}
|
|
54
|
+
{...getFloatingProps(props)}
|
|
55
|
+
$placement={placement as TooltipPlacement}
|
|
56
|
+
>
|
|
57
|
+
<div
|
|
58
|
+
ref={arrowRef}
|
|
59
|
+
className={`${TooltipContent.className}__arrow`}
|
|
60
|
+
style={{
|
|
61
|
+
left: arrowX != null ? `${arrowX}px` : '',
|
|
62
|
+
top: arrowY != null ? `${arrowY}px` : '',
|
|
63
|
+
[staticSide!]: '-6px',
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
<div className={`${TooltipContent.className}__inner`}>
|
|
67
|
+
{children}
|
|
68
|
+
</div>
|
|
69
|
+
</StyledTooltipContent>
|
|
70
|
+
)}
|
|
71
|
+
</FloatingPortal>
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
TooltipContent.className = CLASSNAME;
|
|
75
|
+
TooltipContent.defaultProps = DEFAULT_PROPS;
|
|
76
|
+
TooltipContent.displayName = COMPONENT_NAME;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
import { baseContainer } from '@redsift/design-system';
|
|
3
|
+
import { TooltipPlacement } from '../tooltip';
|
|
4
|
+
import { StyledTooltipContentProps } from './types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Component style.
|
|
8
|
+
*/
|
|
9
|
+
export const StyledTooltipContent = styled.div<StyledTooltipContentProps>`
|
|
10
|
+
${baseContainer}
|
|
11
|
+
|
|
12
|
+
align-items: center;
|
|
13
|
+
background-color: var(--redsift-color-neutral-white);
|
|
14
|
+
border-radius: 4px;
|
|
15
|
+
box-shadow: 0px 2px 4px -1px rgba(0, 0, 0, 0.2);
|
|
16
|
+
color: var(--redsift-color-neutral-black);
|
|
17
|
+
display: flex;
|
|
18
|
+
filter: drop-shadow(0px 4px 5px rgba(0, 0, 0, 0.14)) drop-shadow(0px 1px 10px rgba(0, 0, 0, 0.12));
|
|
19
|
+
font-family: var(--redsift-typography-tooltip-font-family);
|
|
20
|
+
font-size: var(--redsift-typography-tooltip-font-size);
|
|
21
|
+
font-weight: var(--redsift-typography-tooltip-font-weight);
|
|
22
|
+
line-height: var(--redsift-typography-tooltip-line-height);
|
|
23
|
+
max-width: calc(100vw - 48px);
|
|
24
|
+
padding: 4px 8px;
|
|
25
|
+
z-index: var(--redsift-layout-z-index-tooltip);
|
|
26
|
+
|
|
27
|
+
.redsift-tooltip-content__arrow {
|
|
28
|
+
position: absolute;
|
|
29
|
+
width: 0;
|
|
30
|
+
height: 0;
|
|
31
|
+
border-color: var(--redsift-color-neutral-white);
|
|
32
|
+
border-style: solid;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
${({ $placement }) => {
|
|
36
|
+
switch ($placement) {
|
|
37
|
+
case TooltipPlacement.left:
|
|
38
|
+
case TooltipPlacement['left-end']:
|
|
39
|
+
case TooltipPlacement['left-start']:
|
|
40
|
+
return css`
|
|
41
|
+
.redsift-tooltip-content__arrow {
|
|
42
|
+
border-width: 6px 0 6px 6px;
|
|
43
|
+
border-top-color: transparent;
|
|
44
|
+
border-right-color: transparent;
|
|
45
|
+
border-bottom-color: transparent;
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
case TooltipPlacement.top:
|
|
49
|
+
case TooltipPlacement['top-end']:
|
|
50
|
+
case TooltipPlacement['top-start']:
|
|
51
|
+
return css`
|
|
52
|
+
.redsift-tooltip-content__arrow {
|
|
53
|
+
border-width: 6px 6px 0;
|
|
54
|
+
border-right-color: transparent;
|
|
55
|
+
border-bottom-color: transparent;
|
|
56
|
+
border-left-color: transparent;
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
case TooltipPlacement.right:
|
|
60
|
+
case TooltipPlacement['right-end']:
|
|
61
|
+
case TooltipPlacement['right-start']:
|
|
62
|
+
return css`
|
|
63
|
+
.redsift-tooltip-content__arrow {
|
|
64
|
+
border-width: 6px 6px 6px 0;
|
|
65
|
+
border-top-color: transparent;
|
|
66
|
+
border-bottom-color: transparent;
|
|
67
|
+
border-left-color: transparent;
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
case TooltipPlacement.bottom:
|
|
71
|
+
case TooltipPlacement['bottom-end']:
|
|
72
|
+
case TooltipPlacement['bottom-start']:
|
|
73
|
+
default:
|
|
74
|
+
return css`
|
|
75
|
+
.redsift-tooltip-content__arrow {
|
|
76
|
+
border-width: 0 6px 6px;
|
|
77
|
+
border-top-color: transparent;
|
|
78
|
+
border-right-color: transparent;
|
|
79
|
+
border-left-color: transparent;
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
}
|
|
83
|
+
}}
|
|
84
|
+
`;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComponentProps } from 'react';
|
|
2
|
+
import { ContainerProps, InternalSpacingProps } from '@redsift/design-system';
|
|
3
|
+
import { TooltipPlacement } from '../tooltip';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Component props.
|
|
7
|
+
*/
|
|
8
|
+
export interface TooltipContentProps
|
|
9
|
+
extends ComponentProps<'div'>,
|
|
10
|
+
Omit<ContainerProps, keyof InternalSpacingProps> {}
|
|
11
|
+
|
|
12
|
+
export type StyledTooltipContentProps = TooltipContentProps & {
|
|
13
|
+
$placement: TooltipPlacement;
|
|
14
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { forwardRef, ReactElement } from 'react';
|
|
2
|
+
import { useMergeRefs } from '@floating-ui/react';
|
|
3
|
+
|
|
4
|
+
import { Comp } from '@redsift/design-system';
|
|
5
|
+
import { useTooltipContext } from '../tooltip';
|
|
6
|
+
import { TooltipTriggerProps } from './types';
|
|
7
|
+
|
|
8
|
+
const COMPONENT_NAME = 'TooltipTrigger';
|
|
9
|
+
const CLASSNAME = 'redsift-tooltip-trigger';
|
|
10
|
+
const DEFAULT_PROPS: Partial<TooltipTriggerProps> = {};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The TooltipTrigger component.
|
|
14
|
+
*/
|
|
15
|
+
export const TooltipTrigger: Comp<TooltipTriggerProps, HTMLSpanElement> = forwardRef((props, ref) => {
|
|
16
|
+
const { children } = props;
|
|
17
|
+
|
|
18
|
+
const { getReferenceProps, refs, tooltipId } = useTooltipContext();
|
|
19
|
+
const childrenRef = (children as any).ref;
|
|
20
|
+
const triggerRef = useMergeRefs([refs.setReference, ref, childrenRef]);
|
|
21
|
+
|
|
22
|
+
if (React.isValidElement(children)) {
|
|
23
|
+
return React.cloneElement(children as ReactElement, {
|
|
24
|
+
...getReferenceProps({
|
|
25
|
+
ref: triggerRef,
|
|
26
|
+
...props,
|
|
27
|
+
'aria-describedby': tooltipId,
|
|
28
|
+
...children.props,
|
|
29
|
+
children: children.props.children ?? '',
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<span ref={triggerRef} {...getReferenceProps(props)}>
|
|
36
|
+
{children}
|
|
37
|
+
</span>
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
TooltipTrigger.className = CLASSNAME;
|
|
41
|
+
TooltipTrigger.defaultProps = DEFAULT_PROPS;
|
|
42
|
+
TooltipTrigger.displayName = COMPONENT_NAME;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './components/dialog';
|
|
2
|
+
export * from './components/dialog-content';
|
|
3
|
+
export * from './components/dialog-content-actions';
|
|
4
|
+
export * from './components/dialog-content-body';
|
|
5
|
+
export * from './components/dialog-content-header';
|
|
6
|
+
export * from './components/dialog-trigger';
|
|
7
|
+
export * from './components/popover';
|
|
8
|
+
export * from './components/popover-content';
|
|
9
|
+
export * from './components/popover-trigger';
|
|
10
|
+
export * from './components/toast';
|
|
11
|
+
export * from './components/toast-container';
|
|
12
|
+
export * from './components/tooltip';
|
|
13
|
+
export * from './components/tooltip-content';
|
|
14
|
+
export * from './components/tooltip-trigger';
|
|
15
|
+
|
|
16
|
+
export { useMergeRefs, FloatingPortal } from '@floating-ui/react';
|
package/tsconfig.json
ADDED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|