-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathselect-control.tsx
More file actions
59 lines (58 loc) · 1.41 KB
/
select-control.tsx
File metadata and controls
59 lines (58 loc) · 1.41 KB
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
import { forwardRef } from '@wordpress/element';
import { Field, Select } from '../primitives';
import { SelectControlSizeContext } from './context';
import { Item } from './item';
import type { SelectControlProps } from './types';
/**
* A complete select field with integrated label and description.
*/
export const SelectControl = forwardRef<
HTMLButtonElement,
SelectControlProps
>( function SelectControl(
{
className,
children,
items,
label,
description,
details,
hideLabelFromVision,
size = 'default',
triggerContent,
...restProps
},
ref
) {
return (
<Field.Root className={ className }>
<Field.Label hideFromVision={ hideLabelFromVision }>
{ label }
</Field.Label>
<Select.Root items={ items } { ...restProps }>
<Select.Trigger ref={ ref } size={ size }>
{ triggerContent }
</Select.Trigger>
<Select.Popup>
<SelectControlSizeContext.Provider value={ size }>
{ children ||
items?.map( ( item ) => (
<Item
key={ item.value }
value={ item.value }
label={ item.label }
disabled={ item.disabled }
>
{ item.label }
</Item>
) ) }
</SelectControlSizeContext.Provider>
</Select.Popup>
</Select.Root>
{ description && (
<Field.Description>{ description }</Field.Description>
) }
{ details && <Field.Details>{ details }</Field.Details> }
</Field.Root>
);
} );