@@ -6,13 +6,16 @@ import {
6
6
SelectControl ,
7
7
ToolbarButton ,
8
8
ToolbarGroup ,
9
- Notice
9
+ Notice ,
10
+ CheckboxControl ,
11
+ ColorPalette ,
12
+ BaseControl
10
13
} from '@wordpress/components' ;
11
14
import { useDispatch } from '@wordpress/data' ;
12
15
import { useEffect , useMemo , useState } from '@wordpress/element' ;
13
16
import { edit } from '@wordpress/icons' ;
14
17
import { logo } from '../common/icons' ;
15
-
18
+ import { ASPECT_RATIO_OPTIONS } from '../common/constants' ;
16
19
import { isOptimoleURL } from '../common/utils' ;
17
20
18
21
const Edit = ( props ) => {
@@ -28,8 +31,9 @@ const Edit = ( props ) => {
28
31
setUrl ( value ) ;
29
32
} ;
30
33
31
- const onAspectRatioChange = ( value ) => {
32
- setAttributes ( { aspectRatio : value } ) ;
34
+
35
+ const onAttributeUpdate = ( value , name ) => {
36
+ setAttributes ( { [ name ] : value } ) ;
33
37
} ;
34
38
35
39
const onEdit = ( ) => {
@@ -52,29 +56,18 @@ const Edit = ( props ) => {
52
56
53
57
setError ( true ) ;
54
58
} ) ;
55
-
56
59
} ;
57
60
58
61
useEffect ( ( ) => {
59
62
isOptimoleURL ( attributes . url ) . then ( ( valid ) => {
60
-
61
63
if ( ! valid ) {
62
64
setEditing ( true ) ;
63
65
setError ( true ) ;
64
66
}
65
67
} ) ;
66
68
} , [ attributes . url ] ) ;
67
69
68
- const aspectRatioOptions = useMemo ( ( ) => {
69
- return OMVideoPlayerBlock . aspectRatioOptions . map ( ( value ) => ( {
70
- label : value ,
71
- value : value . replace ( ':' , '/' )
72
- } ) ) ;
73
- } , [ ] ) ;
74
-
75
70
const style = useMemo ( ( ) => {
76
-
77
-
78
71
const style = {
79
72
'--om-primary-color' : attributes . primaryColor ,
80
73
'--om-aspect-ratio' : attributes . aspectRatio
@@ -105,26 +98,51 @@ const Edit = ( props ) => {
105
98
< SelectControl
106
99
value = { attributes . aspectRatio }
107
100
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' ) }
110
115
/>
111
116
112
117
</ PanelBody >
113
118
</ 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 >
128
146
</ >
129
147
) ;
130
148
} ;
@@ -149,11 +167,19 @@ export default {
149
167
} ,
150
168
aspectRatio : {
151
169
type : 'string' ,
152
- default : '16/9 '
170
+ default : 'auto '
153
171
} ,
154
172
primaryColor : {
155
173
type : 'string' ,
156
174
default : '#577BF9'
175
+ } ,
176
+ loop : {
177
+ type : 'boolean' ,
178
+ default : false
179
+ } ,
180
+ hideControls : {
181
+ type : 'boolean' ,
182
+ default : false
157
183
}
158
184
} ,
159
185
edit : Edit ,
0 commit comments