Skip to content

Commit d1af20b

Browse files
committed
update YouTubeLite block functions
1 parent eebebd8 commit d1af20b

File tree

3 files changed

+39
-47
lines changed

3 files changed

+39
-47
lines changed

blocks/YouTubeLite/Block.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,3 @@ public function blockRestApiEndpoints(): void
5353
{
5454
}
5555
}
56-
57-
58-
59-
60-
61-

blocks/YouTubeLite/src/index.jsx

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import metadata from '../block.json';
33
const {registerBlockType} = wp.blocks;
44
const {__} = wp.i18n;
55
const {TextControl, PanelBody} = wp.components;
6-
const {InspectorControls, useBlockProps} = wp.blockEditor || wp.editor;
6+
const {InspectorControls, useBlockProps} = wp.blockEditor;
77

88
function extractId(input) {
99
if (!input) return '';
@@ -23,8 +23,9 @@ function extractId(input) {
2323

2424
const PlaySvg = () => (
2525
<svg xmlns="http://www.w3.org/2000/svg" width="68" height="48" viewBox="0 0 68 48">
26-
<path d="M66.52 7.74a8 8 0 0 0-5.63-5.66C56.7.67 34 .67 34 .67s-22.7 0-26.89 1.41A8 8 0 0 0 1.48 7.74 84.3 84.3 0 0 0 .07 24a84.3 84.3 0 0 0 1.41 16.26 8 8 0 0 0 5.63 5.66C11.3 47.33 34 47.33 34 47.33s22.7 0 26.89-1.41a8 8 0 0 0 5.63-5.66A84.3 84.3 0 0 0 67.93 24a84.3 84.3 0 0 0-1.41-16.26z" fill="#212121" fillOpacity=".8" />
27-
<path d="M45 24 27 14v20" fill="#fff" />
26+
<path fill="#f03"
27+
d="M66.52 7.74c-.78-2.93-2.49-5.41-5.42-6.19C55.79.13 34 0 34 0S12.21.13 6.9 1.55c-2.93.78-4.63 3.26-5.42 6.19C.06 13.05 0 24 0 24s.06 10.95 1.48 16.26c.78 2.93 2.49 5.41 5.42 6.19C12.21 47.87 34 48 34 48s21.79-.13 27.1-1.55c2.93-.78 4.64-3.26 5.42-6.19C67.94 34.95 68 24 68 24s-.06-10.95-1.48-16.26"/>
28+
<path fill="#fff" d="M45 24 27 14v20"/>
2829
</svg>
2930
);
3031

@@ -86,64 +87,57 @@ registerBlockType(
8687
{...blockProps}
8788
role="button"
8889
aria-label={title}
89-
style={{
90-
position: 'relative',
91-
display: 'block',
92-
width: '100%',
93-
backgroundColor: '#000',
94-
overflow: 'hidden',
95-
aspectRatio: aspectRatio || '16/9',
96-
cursor: 'pointer',
97-
}}
9890
>
9991
{thumbnail ? (
10092
<img
10193
src={thumbnail}
10294
alt={title}
103-
style={{width: '100%', height: '100%', objectFit: 'cover', filter: 'brightness(0.8)'}}
10495
/>
10596
) : (
106-
<div style={{color: '#fff', padding: '1rem'}}>{__('Paste a YouTube URL', 'starter-kit')}</div>
97+
<div className="yt-lite__placeholder">
98+
{__('Paste a YouTube URL', 'starter-kit')}
99+
</div>
107100
)}
108101
<div
109102
className="yt-lite__play"
110103
aria-hidden="true"
111-
style={{
112-
position: 'absolute',
113-
top: '50%',
114-
left: '50%',
115-
transform: 'translate(-50%,-50%)',
116-
display: 'flex',
117-
alignItems: 'center',
118-
justifyContent: 'center',
119-
width: '68px',
120-
height: '48px',
121-
borderRadius: '10px',
122-
background: 'rgba(0,0,0,.6)',
123-
}}
124104
>
125105
<PlaySvg />
126106
</div>
127107
</div>
128108
</>
129109
);
130110
},
131-
save: ({attributes}) => {
132-
const {videoId, title, poster, params, aspectRatio} = attributes;
111+
save: (props) => {
112+
const {attributes} = props;
113+
const {videoId, title, poster, params} = attributes;
133114
const thumbnail = poster || (videoId ? `https://i.ytimg.com/vi/${videoId}/hqdefault.jpg` : '');
115+
116+
const {className} = useBlockProps.save();
117+
const blockClass = ['yt-lite', className].filter(Boolean).join(' ').trim();
118+
119+
const blockProps = {
120+
className: blockClass,
121+
'data-video-id': videoId || '',
122+
'data-params': params || 'rel=0',
123+
role: 'button',
124+
'aria-label': title || 'YouTube video',
125+
};
126+
134127
return (
135-
<div
136-
className="yt-lite"
137-
data-video-id={videoId || ''}
138-
data-params={params || 'rel=0'}
139-
role="button"
140-
aria-label={title || 'YouTube video'}
141-
style={{position: 'relative', display: 'block', width: '100%', backgroundColor: '#000', overflow: 'hidden', aspectRatio: aspectRatio || '16/9', cursor: 'pointer'}}
142-
>
128+
<div {...blockProps}>
143129
{thumbnail ? (
144-
<img src={thumbnail} alt={title || 'YouTube video'} loading="lazy" decoding="async" style={{width: '100%', height: '100%', objectFit: 'cover', filter: 'brightness(0.8)'}} />
130+
<img
131+
src={thumbnail}
132+
alt={title || 'YouTube video'}
133+
loading="lazy"
134+
decoding="async"
135+
/>
145136
) : null}
146-
<div className="yt-lite__play" aria-hidden="true" style={{position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%,-50%)', display: 'flex', alignItems: 'center', justifyContent: 'center', width: '68px', height: '48px', borderRadius: '10px', background: 'rgba(0,0,0,.6)'}}>
137+
<div
138+
className="yt-lite__play"
139+
aria-hidden="true"
140+
>
147141
<PlaySvg />
148142
</div>
149143
</div>

blocks/YouTubeLite/src/style.scss

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
width: 100%;
1313
height: 100%;
1414
object-fit: cover;
15-
filter: brightness(0.8);
1615
display: block;
1716
}
1817

@@ -27,5 +26,10 @@
2726
width: 68px;
2827
height: 48px;
2928
border-radius: 10px;
30-
background: rgba(0, 0, 0, .6);
29+
background: #ff0000;
30+
}
31+
32+
.yt-lite__placeholder {
33+
color: #fff;
34+
padding: 1rem;
3135
}

0 commit comments

Comments
 (0)