-
Notifications
You must be signed in to change notification settings - Fork 34
/
ebay-tourtip.tsx
89 lines (86 loc) · 2.65 KB
/
ebay-tourtip.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React, { CSSProperties, FC, useRef } from 'react'
import { findComponent } from '../common/component-utils'
import {
Tooltip,
TooltipHost,
TooltipContent,
TooltipProps,
PointerDirection,
useTooltip,
TooltipFooter
} from '../common/tooltip-utils'
import EbayTourtipContent from './ebay-tourtip-content'
import EbayTourtipHost from './ebay-tourtip-host'
import EbayTourtipFooter from './ebay-tourtip-footer'
import EbayTourtipHeading from './ebay-tourtip-heading'
type TourtipProps = Omit<TooltipProps, 'ref'> & {
a11yCloseText: string;
pointer?: PointerDirection;
onExpand?: () => void;
onCollapse?: () => void;
overlayStyle?: CSSProperties;
'aria-label'?: string;
className?: string;
}
const EbayTourtip:FC<TourtipProps> = ({
a11yCloseText,
'aria-label': ariaLabel,
className,
children,
onCollapse,
onExpand,
overlayStyle,
pointer,
...rest
}) => {
const hostRef = useRef()
const {
isExpanded,
collapseTooltip
} = useTooltip({ onExpand, onCollapse, initialExpanded: true, hostRef })
const containerRef = useRef()
const content = findComponent(children, EbayTourtipContent)
if (!content) {
throw new Error(`EbayTourtip: Please use a EbayTourtipContent that defines the content of the tourtip`)
}
const { children: contentChildren, contentProps } = content.props
const host = findComponent(children, EbayTourtipHost)
if (!host) {
throw new Error(`EbayTourtip: Please use a EbayTourtipHost that defines the host of the tourtip`)
}
const heading = findComponent(children, EbayTourtipHeading)
const footer = findComponent(children, EbayTourtipFooter)
return (
<Tooltip
{...rest}
className={className}
type="tourtip"
isExpanded={isExpanded}
ref={containerRef}
>
<TooltipHost
{...host.props}
forwardedRef={hostRef}
aria-label={ariaLabel}
aria-expanded={isExpanded} />
<TooltipContent
{...contentProps}
a11yCloseText={a11yCloseText}
onClose={collapseTooltip}
pointer={pointer}
showCloseButton
style={overlayStyle}
type="tourtip"
>
{heading}
{contentChildren}
{footer && (
<TooltipFooter type="tourtip">
{footer}
</TooltipFooter>
)}
</TooltipContent>
</Tooltip>
)
}
export default EbayTourtip