-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
8 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useMemo } from '@wordpress/element'; | ||
|
||
import { Attributes } from './types'; | ||
|
||
/** | ||
* @param attributes The audio block attributes. | ||
*/ | ||
export default function useStyle(attributes: Attributes): React.CSSProperties { | ||
const style = useMemo( | ||
() => computeStyle(attributes), | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[attributes.textColor, attributes.backgroundColor, attributes.style] | ||
); | ||
|
||
return style; | ||
} | ||
|
||
export function computeStyle(attributes: Attributes) { | ||
const result: React.CSSProperties = {}; | ||
|
||
if (attributes.backgroundColor) { | ||
result['--vinyl-background-color'] = | ||
`var(--wp--preset--color--${attributes.backgroundColor})`; | ||
} else if (attributes.style?.color?.background) { | ||
result['--vinyl-background-color'] = attributes.style.color.background; | ||
} | ||
|
||
if (attributes.textColor) { | ||
result['--vinyl-text-color'] = | ||
`var(--wp--preset--color--${attributes.textColor})`; | ||
} else if (attributes.style?.color?.text) { | ||
result['--vinyl-text-color'] = attributes.style.color.text; | ||
} | ||
|
||
return result; | ||
} |