Skip to content

Commit bba2134

Browse files
committed
feat: improve video player & adds block options
1 parent e36dc18 commit bba2134

File tree

5 files changed

+347
-175
lines changed

5 files changed

+347
-175
lines changed

assets/src/video-player/block/VideoPlayerBlock.js

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import {
66
SelectControl,
77
ToolbarButton,
88
ToolbarGroup,
9-
Notice
9+
Notice,
10+
CheckboxControl,
11+
ColorPalette,
12+
BaseControl
1013
} from '@wordpress/components';
1114
import { useDispatch } from '@wordpress/data';
1215
import { useEffect, useMemo, useState } from '@wordpress/element';
1316
import { edit } from '@wordpress/icons';
1417
import { logo } from '../common/icons';
15-
18+
import { ASPECT_RATIO_OPTIONS } from '../common/constants';
1619
import { isOptimoleURL } from '../common/utils';
1720

1821
const Edit = ( props ) => {
@@ -28,8 +31,9 @@ const Edit = ( props ) => {
2831
setUrl( value );
2932
};
3033

31-
const onAspectRatioChange = ( value ) => {
32-
setAttributes({ aspectRatio: value });
34+
35+
const onAttributeUpdate = ( value, name ) => {
36+
setAttributes({ [name]: value });
3337
};
3438

3539
const onEdit = () => {
@@ -52,29 +56,18 @@ const Edit = ( props ) => {
5256

5357
setError( true );
5458
});
55-
5659
};
5760

5861
useEffect( () => {
5962
isOptimoleURL( attributes.url ).then( ( valid ) => {
60-
6163
if ( ! valid ) {
6264
setEditing( true );
6365
setError( true );
6466
}
6567
});
6668
}, [ attributes.url ]);
6769

68-
const aspectRatioOptions = useMemo( () => {
69-
return OMVideoPlayerBlock.aspectRatioOptions.map( ( value ) => ({
70-
label: value,
71-
value: value.replace( ':', '/' )
72-
}) );
73-
}, []);
74-
7570
const style = useMemo( () => {
76-
77-
7871
const style = {
7972
'--om-primary-color': attributes.primaryColor,
8073
'--om-aspect-ratio': attributes.aspectRatio
@@ -105,26 +98,51 @@ const Edit = ( props ) => {
10598
<SelectControl
10699
value={attributes.aspectRatio}
107100
label={OMVideoPlayerBlock.aspectRatioLabel}
108-
options={aspectRatioOptions}
109-
onChange={onAspectRatioChange}
101+
options={ASPECT_RATIO_OPTIONS}
102+
onChange={( value ) => onAttributeUpdate( value, 'aspectRatio' )}
103+
/>
104+
105+
<CheckboxControl
106+
label={OMVideoPlayerBlock.loopLabel}
107+
checked={attributes.loop}
108+
onChange={( value ) => onAttributeUpdate( value, 'loop' )}
109+
/>
110+
111+
<CheckboxControl
112+
label={OMVideoPlayerBlock.hideControlsLabel}
113+
checked={attributes.hideControls}
114+
onChange={( value ) => onAttributeUpdate( value, 'hideControls' )}
110115
/>
111116

112117
</PanelBody>
113118
</InspectorControls>
114-
{! editing && <optimole-video-player video-src={props.attributes.url} style={style}></optimole-video-player>}
115-
{editing && <Placeholder
116-
label={OMVideoPlayerBlock.urlLabel}
117-
className="wp-block-embed"
118-
>
119-
<form onSubmit={onSave}>
120-
<input type="url" id="url" defaultValue={attributes.url} className="wp-block-embed__placeholder-input" onChange={onUrlChange} />
121-
<Button isPrimary type="submit">Save</Button>
122-
</form>
123-
124-
{error && <Notice status="error" isDismissible={false}><span dangerouslySetInnerHTML={{ __html: OMVideoPlayerBlock.invalidUrlError }}/></Notice>}
125-
126-
</Placeholder>
127-
}
119+
<InspectorControls group="styles">
120+
<PanelBody title={OMVideoPlayerBlock.blockTitle} initialOpen={true}>
121+
<BaseControl label={OMVideoPlayerBlock.primaryColorLabel}>
122+
<ColorPalette
123+
clearable={false}
124+
value={attributes.primaryColor}
125+
onChange={( value ) => onAttributeUpdate( value, 'primaryColor' )}
126+
/>
127+
</BaseControl>
128+
</PanelBody>
129+
</InspectorControls>
130+
<div style={{ display: 'flex', width: '100%' }}>
131+
{! editing && <optimole-video-player video-src={props.attributes.url} style={style} loop={attributes.loop} hide-controls={attributes.hideControls}></optimole-video-player>}
132+
{editing && <Placeholder
133+
label={OMVideoPlayerBlock.urlLabel}
134+
className="wp-block-embed"
135+
>
136+
<form onSubmit={onSave}>
137+
<input type="url" id="url" defaultValue={attributes.url} className="wp-block-embed__placeholder-input" onChange={onUrlChange} />
138+
<Button isPrimary type="submit">{OMVideoPlayerBlock.save}</Button>
139+
</form>
140+
141+
{error && <Notice status="error" isDismissible={false}><span dangerouslySetInnerHTML={{ __html: OMVideoPlayerBlock.invalidUrlError }}/></Notice>}
142+
143+
</Placeholder>
144+
}
145+
</div>
128146
</>
129147
);
130148
};
@@ -149,11 +167,19 @@ export default {
149167
},
150168
aspectRatio: {
151169
type: 'string',
152-
default: '16/9'
170+
default: 'auto'
153171
},
154172
primaryColor: {
155173
type: 'string',
156174
default: '#577BF9'
175+
},
176+
loop: {
177+
type: 'boolean',
178+
default: false
179+
},
180+
hideControls: {
181+
type: 'boolean',
182+
default: false
157183
}
158184
},
159185
edit: Edit,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const ASPECT_RATIO_OPTIONS = [
2+
{
3+
value: 'auto',
4+
label: OMVideoPlayerBlock.auto
5+
},
6+
{
7+
value: '16/9',
8+
label: '16:9'
9+
},
10+
{
11+
value: '4/3',
12+
label: '4:3'
13+
},
14+
{
15+
value: '1/1',
16+
label: '1:1'
17+
},
18+
{
19+
value: '9/16',
20+
label: '9:16'
21+
},
22+
{
23+
value: '1/2',
24+
label: '1:2'
25+
},
26+
{
27+
value: '2/1',
28+
label: '2:1'
29+
}
30+
];
31+
32+
export { ASPECT_RATIO_OPTIONS };

assets/src/video-player/style.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
optimole-video-player {
1212
--scrubber-size: 12px;
13-
aspect-ratio: var(--om-aspect-ratio, 16/9);
13+
aspect-ratio: var(--om-aspect-ratio, auto);
1414
overflow: hidden;
1515
position: relative;
1616
display: block;
17+
background-color: #000;
18+
width: 100%;
1719

1820
.optml-vp-hide {
1921
display: none !important;
@@ -48,7 +50,6 @@ optimole-video-player {
4850
top: 0;
4951
bottom: 0;
5052
z-index: 0;
51-
background-color: #000;
5253

5354
.optml-ic {
5455
width: 20px;

0 commit comments

Comments
 (0)