-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathbutton.tsx
39 lines (34 loc) · 1014 Bytes
/
button.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
import React, { FC } from 'react'
import classNames from 'classnames'
import { excludeComponent, findComponent } from '../common/component-utils'
import { EbayIcon } from '../ebay-icon'
import { SegmentedButtonProps } from './types'
const SegmentedButton: FC<SegmentedButtonProps> = ({
selected,
children,
className,
...rest
}) => {
const icon = findComponent(children, EbayIcon)
const iconWithText = () => {
const text = excludeComponent(children, EbayIcon)
return (
<span className="segmented-buttons__button-cell">
{icon}
<span>{text}</span>
</span>
)
}
return (
<li>
<button
className={classNames('segmented-buttons__button', className)}
aria-current={selected || undefined}
{...rest}
>
{icon ? iconWithText() : children}
</button>
</li>
)
}
export default SegmentedButton