From abd7204495ce951167ee78a5e0e36372c245b0f8 Mon Sep 17 00:00:00 2001 From: John Hooks Date: Sun, 19 May 2024 08:24:01 -0700 Subject: [PATCH] feat: support custom colors for audio player This commit adds block supports for color customization. The block editor color palette is used to select the colors. The colors are stored in the block attributes, though are applied using inline styles of custom CSS properties. This allows the custom colors to be applied to the shadow DOM of the `media-chrome` web components. Fixes: #11 --- docs/planning.md | 5 +++++ src/audio/block.json | 5 +++++ src/audio/edit.tsx | 10 +++++++++- src/audio/player/player.tsx | 13 ++++++++++--- src/audio/save.tsx | 9 ++++++++- src/audio/style.scss | 12 ++++++++++++ src/audio/types.ts | 16 ++++++++++++++++ src/audio/use-style.ts | 36 ++++++++++++++++++++++++++++++++++++ 8 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 src/audio/use-style.ts diff --git a/docs/planning.md b/docs/planning.md index 8285374..10db64f 100644 --- a/docs/planning.md +++ b/docs/planning.md @@ -8,6 +8,11 @@ Replicate the functionality of the audio block. Using the `audio` element. Add a custom UI that replicates the features of the standard `audio` element. +### Color Supports + +- [Block Supports - Color](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color) +- [Theme Supports - Color Palettes](https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-support/#block-color-palettes) + ## Step Three Incrementally add features to expand the functionality. diff --git a/src/audio/block.json b/src/audio/block.json index d2d27d8..f7efabb 100644 --- a/src/audio/block.json +++ b/src/audio/block.json @@ -46,6 +46,11 @@ "supports": { "anchor": true, "align": true, + "color": { + "background": true, + "text": true, + "link": false + }, "spacing": { "margin": true, "padding": true diff --git a/src/audio/edit.tsx b/src/audio/edit.tsx index f9a8f70..e14d917 100644 --- a/src/audio/edit.tsx +++ b/src/audio/edit.tsx @@ -28,6 +28,7 @@ import './editor.scss'; import Caption from './edit/caption.js'; import { Player } from './player/index.js'; import type { Attributes } from './types'; +import useStyle from './use-style.js'; const ALLOWED_MEDIA_TYPES = ['audio']; @@ -114,6 +115,8 @@ function VinylEdit({ className: classes, }); + const style = useStyle(attributes); + if (!src) { return (
@@ -196,7 +199,12 @@ function VinylEdit({ */} - + {isTemporaryAudio && } diff --git a/src/audio/player/player.tsx b/src/audio/player/player.tsx index ba879f4..f640072 100644 --- a/src/audio/player/player.tsx +++ b/src/audio/player/player.tsx @@ -12,11 +12,18 @@ import { } from '../../react/index.js'; import type { Attributes } from '../types'; -type Props = Omit; +type Props = Omit & { + style?: React.CSSProperties; +}; -export default function Player({ loop, preload, src }: Props) { +export default function Player({ loop, preload, src, style }: Props) { return ( - +