-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMediaControl.js
More file actions
executable file
·47 lines (44 loc) · 1.4 KB
/
Copy pathMediaControl.js
File metadata and controls
executable file
·47 lines (44 loc) · 1.4 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
// WordPress dependencies.
const { useContext } = wp.element;
const { MediaUpload } = wp.blockEditor;
const { BaseControl, Button } = wp.components;
const { __ } = wp.i18n;
const { withInstanceId } = wp.compose;
const MediaControl = ({ label, value, onChange, ...restProps }) => {
const id = 'inspector-media-control-' + restProps.instanceId;
const buttonStyle = {
display: 'block',
width: 200,
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden'
};
return (
<BaseControl>
<label htmlFor={ id } className="components-base-control__label">{ label }</label>
<div className="components-panel__row" style={ { marginTop: 0 } }>
<MediaUpload
onSelect={ ({ id, url }) => onChange({ id, url }) }
render={ ({ open }) => (
<>
<Button
id={ id }
onClick={ open }
style={ buttonStyle }
isLink>{ value ? value.url.split(/[\\/]/).pop() : __('Media Library') }</Button>
<Button
disabled={ !value }
icon="no-alt"
onClick={ () => onChange(null) }
label={ __('Remove') }
/>
</>
) }
value={ value ? value.id : null }
{ ...restProps }
/>
</div>
</BaseControl>
);
};
export default withInstanceId(MediaControl);