-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathsplit-button.tsx
54 lines (51 loc) · 1.66 KB
/
split-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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React, { FC } from 'react'
import { filterBy, filterByType } from '../common/component-utils'
import { EbayButton } from '../ebay-button'
import { EbayMenuButton, EbayMenuButtonItem, EbayMenuButtonSeparator } from '../ebay-menu-button'
import { Props } from './types'
const EbaySplitButton: FC<Props> = ({
a11yMenuText,
children,
type,
bodyState,
a11yButtonLoadingText,
onCollapse,
onExpand,
onSelect = () => {},
onChange = () => {},
ref,
...rest
}) => {
const menuItemComponents: FC[] = [EbayMenuButtonItem, EbayMenuButtonSeparator]
const buttonLabel = filterBy(children, el => !menuItemComponents.includes(el.type as any))
const menuItems = filterByType(children, menuItemComponents)
return (
<span className="split-button">
<EbayButton
aria-label={bodyState === 'loading' ? a11yButtonLoadingText : undefined}
{...rest}
split="start"
bodyState={bodyState === 'expand' ? undefined : bodyState}
>
{buttonLabel}
</EbayButton>
<EbayMenuButton
priority={rest.priority}
disabled={rest.disabled}
transparent={rest.transparent}
size={rest.size}
type={type}
split="end"
reverse
a11yText={a11yMenuText}
onCollapse={onCollapse}
onExpand={onExpand}
onSelect={onSelect}
onChange={onChange}
>
{menuItems}
</EbayMenuButton>
</span>
)
}
export default EbaySplitButton