-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Border panel: Update to display multiple palette origins (#36753)
* Extract color and gradient settings retrieval to custom hook * Update border color to display multiple color palette origins Co-authored-by: Aaron Robertshaw <[email protected]>
- Loading branch information
1 parent
233e5b2
commit df38b3d
Showing
4 changed files
with
136 additions
and
101 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
11 changes: 11 additions & 0 deletions
11
packages/block-editor/src/components/colors-gradients/use-common-single-multiple-selects.js
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,11 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import useSetting from '../use-setting'; | ||
|
||
export default function useCommonSingleMultipleSelects() { | ||
return { | ||
disableCustomColors: ! useSetting( 'color.custom' ), | ||
disableCustomGradients: ! useSetting( 'color.customGradient' ), | ||
}; | ||
} |
107 changes: 107 additions & 0 deletions
107
.../block-editor/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js
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,107 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useMemo } from '@wordpress/element'; | ||
import { _x } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import useSetting from '../use-setting'; | ||
import useCommonSingleMultipleSelects from './use-common-single-multiple-selects'; | ||
|
||
/** | ||
* Retrieves color and gradient related settings. | ||
* | ||
* The arrays for colors and gradients are made up of color palettes from each | ||
* origin i.e. "Core", "Theme", and "User". | ||
* | ||
* @return {Object} Color and gradient related settings. | ||
*/ | ||
export default function useMultipleOriginColorsAndGradients() { | ||
const colorGradientSettings = useCommonSingleMultipleSelects(); | ||
const customColors = useSetting( 'color.palette.custom' ); | ||
const themeColors = useSetting( 'color.palette.theme' ); | ||
const defaultColors = useSetting( 'color.palette.default' ); | ||
const shouldDisplayDefaultColors = useSetting( 'color.defaultPalette' ); | ||
|
||
colorGradientSettings.colors = useMemo( () => { | ||
const result = []; | ||
if ( themeColors && themeColors.length ) { | ||
result.push( { | ||
name: _x( | ||
'Theme', | ||
'Indicates this palette comes from the theme.' | ||
), | ||
colors: themeColors, | ||
} ); | ||
} | ||
if ( | ||
shouldDisplayDefaultColors && | ||
defaultColors && | ||
defaultColors.length | ||
) { | ||
result.push( { | ||
name: _x( | ||
'Default', | ||
'Indicates this palette comes from WordPress.' | ||
), | ||
colors: defaultColors, | ||
} ); | ||
} | ||
if ( customColors && customColors.length ) { | ||
result.push( { | ||
name: _x( | ||
'Custom', | ||
'Indicates this palette comes from the theme.' | ||
), | ||
colors: customColors, | ||
} ); | ||
} | ||
return result; | ||
}, [ defaultColors, themeColors, customColors ] ); | ||
|
||
const customGradients = useSetting( 'color.gradients.custom' ); | ||
const themeGradients = useSetting( 'color.gradients.theme' ); | ||
const defaultGradients = useSetting( 'color.gradients.default' ); | ||
const shouldDisplayDefaultGradients = useSetting( | ||
'color.defaultGradients' | ||
); | ||
colorGradientSettings.gradients = useMemo( () => { | ||
const result = []; | ||
if ( themeGradients && themeGradients.length ) { | ||
result.push( { | ||
name: _x( | ||
'Theme', | ||
'Indicates this palette comes from the theme.' | ||
), | ||
gradients: themeGradients, | ||
} ); | ||
} | ||
if ( | ||
shouldDisplayDefaultGradients && | ||
defaultGradients && | ||
defaultGradients.length | ||
) { | ||
result.push( { | ||
name: _x( | ||
'Default', | ||
'Indicates this palette comes from WordPress.' | ||
), | ||
gradients: defaultGradients, | ||
} ); | ||
} | ||
if ( customGradients && customGradients.length ) { | ||
result.push( { | ||
name: _x( | ||
'Custom', | ||
'Indicates this palette is created by the user.' | ||
), | ||
gradients: customGradients, | ||
} ); | ||
} | ||
return result; | ||
}, [ customGradients, themeGradients, defaultGradients ] ); | ||
|
||
return colorGradientSettings; | ||
} |
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