-
Notifications
You must be signed in to change notification settings - Fork 28
/
ebay-infotip-host.tsx
37 lines (33 loc) · 1.16 KB
/
ebay-infotip-host.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
import React, { ComponentProps, FC, RefObject, ReactNode } from 'react'
import classNames from 'classnames/dedupe'
import { EbayIcon, Icon } from '../ebay-icon'
import { withForwardRef } from '../common/component-utils/forwardRef'
import { Variant } from './types'
type InfotipHostProps = Omit<ComponentProps<'button'>, 'children'> & {
icon?: Icon;
forwardedRef?: RefObject<HTMLAnchorElement & HTMLButtonElement>;
variant?: Variant;
children?: (({ icon }) => ReactNode) | ReactNode
}
const EbayInfotipHost: FC<InfotipHostProps> = ({
icon,
className,
children,
forwardedRef,
variant,
...rest
}) => {
const classPrefix = variant === 'modal' ? 'dialog--mini' : 'infotip'
const buttonIcon = <EbayIcon name={icon} />
const buttonContent = children instanceof Function ? children({ icon: buttonIcon }) : children
return (
<button
{...rest}
className={classNames('icon-btn icon-btn--transparent', className, `${classPrefix}__host`)}
type="button"
ref={forwardedRef}>
{buttonContent || buttonIcon}
</button>
)
}
export default withForwardRef(EbayInfotipHost)