Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update useColorProps util
  • Loading branch information
oandregal authored and jorgefilipecosta committed Nov 26, 2021
commit b6626c6948eba7fd3ca35eda48a6a42776063454
29 changes: 25 additions & 4 deletions packages/block-editor/src/hooks/use-color-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { useMemo } from '@wordpress/element';

/**
* Internal dependencies
*/
Expand All @@ -24,8 +29,6 @@ import useSetting from '../components/use-setting';
// block support is being skipped for a block but the color related CSS classes
// & styles still need to be generated so they can be applied to inner elements.

const EMPTY_ARRAY = [];

/**
* Provides the CSS class names and inline styles for a block's color support
* attributes.
Expand Down Expand Up @@ -84,8 +87,26 @@ export function getColorClassesAndStyles( attributes ) {
export function useColorProps( attributes ) {
const { backgroundColor, textColor, gradient } = attributes;

const colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;
const gradients = useSetting( 'color.gradients' ) || EMPTY_ARRAY;
const {
palette: solidsPerOrigin,
gradients: gradientsPerOrigin,
} = useSetting( 'color' );
const colors = useMemo(
() => [
...( solidsPerOrigin.custom || [] ),
...( solidsPerOrigin.theme || [] ),
...solidsPerOrigin.default,
],
[ solidsPerOrigin ]
);
const gradients = useMemo(
() => [
...( gradientsPerOrigin.custom || [] ),
...( gradientsPerOrigin.theme || [] ),
...gradientsPerOrigin.default,
],
[ gradientsPerOrigin ]
);

const colorProps = getColorClassesAndStyles( attributes );

Expand Down