/
ComboboxListboxGroup.tsx
54 lines (49 loc) · 1.6 KB
/
ComboboxListboxGroup.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 * as React from 'react';
import * as PropTypes from 'prop-types';
import {Box} from '@twilio-paste/box';
import {Text} from '@twilio-paste/text';
import type {ComboboxProps} from '../types';
export interface ComboboxListboxGroupProps extends Pick<ComboboxProps, 'groupLabelTemplate' | 'element'> {
children: NonNullable<React.ReactNode>;
groupName?: string | undefined;
}
const ComboboxListboxGroup = React.forwardRef<HTMLUListElement, ComboboxListboxGroupProps>(
({children, element = 'COMBOBOX', groupName, groupLabelTemplate}, ref) => {
return (
<Box
as="ul"
ref={ref}
element={`${element}_LIST`}
role={!groupName ? 'presentation' : 'group'}
aria-label={groupName}
margin="space0"
padding="space0"
listStyleType="none"
>
{groupName ? (
<Box
as="li"
backgroundColor="colorBackground"
role="presentation"
paddingY="space30"
paddingLeft="space50"
paddingRight="space50"
element={`${element}_GROUPNAME`}
>
<Text as="span" fontWeight="fontWeightBold" color="colorTextWeak" element={`${element}_GROUPNAME_TEXT`}>
{groupLabelTemplate ? groupLabelTemplate(groupName) : groupName}
</Text>
</Box>
) : null}
{children}
</Box>
);
}
);
ComboboxListboxGroup.displayName = 'ComboboxListboxGroup';
ComboboxListboxGroup.propTypes = {
children: PropTypes.node.isRequired,
groupName: PropTypes.string,
element: PropTypes.string,
};
export {ComboboxListboxGroup};