| 1 |
import React from 'react'; |
| 2 |
|
| 3 |
import { SelectControl } from '@wordpress/components'; |
| 4 |
import withMetaData from '../../utils/withMetaData'; |
| 5 |
import { |
| 6 |
useBackgroundAppContext, |
| 7 |
usePostBackgroundMessage, |
| 8 |
} from '../../iframe/useBackgroundApp'; |
| 9 |
import { ProxyMessages } from '../../iframe/integratedMessages'; |
| 10 |
|
| 11 |
interface IOption { |
| 12 |
label: string; |
| 13 |
value: string; |
| 14 |
disabled?: boolean; |
| 15 |
} |
| 16 |
|
| 17 |
interface IUISidebarSelectControlProps { |
| 18 |
metaValue?: string; |
| 19 |
metaKey: string; |
| 20 |
setMetaValue?: Function; |
| 21 |
options: IOption[]; |
| 22 |
className: string; |
| 23 |
label: JSX.Element; |
| 24 |
} |
| 25 |
|
| 26 |
const UISidebarSelectControl = (props: IUISidebarSelectControlProps) => { |
| 27 |
const isBackgroundAppReady = useBackgroundAppContext(); |
| 28 |
|
| 29 |
const monitorSidebarMetaChange = usePostBackgroundMessage(); |
| 30 |
|
| 31 |
return ( |
| 32 |
<SelectControl |
| 33 |
value={props.metaValue} |
| 34 |
onChange={content => { |
| 35 |
if (props.setMetaValue) { |
| 36 |
props.setMetaValue(content); |
| 37 |
} |
| 38 |
isBackgroundAppReady && |
| 39 |
monitorSidebarMetaChange({ |
| 40 |
key: ProxyMessages.TrackSidebarMetaChange, |
| 41 |
payload: { |
| 42 |
metaKey: props.metaKey, |
| 43 |
}, |
| 44 |
}); |
| 45 |
}} |
| 46 |
{...props} |
| 47 |
/> |
| 48 |
); |
| 49 |
}; |
| 50 |
|
| 51 |
export default withMetaData(UISidebarSelectControl); |
| 52 |
|