Skip to content

Commit

Permalink
Support enabling custom link color from theme.json (#25148)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Sep 9, 2020
1 parent dd252e2 commit 2172f0f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 24 deletions.
14 changes: 0 additions & 14 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,17 +633,3 @@ function gutenberg_extend_settings_custom_units( $settings ) {
return $settings;
}
add_filter( 'block_editor_settings', 'gutenberg_extend_settings_custom_units' );

/**
* Extends block editor settings to determine whether to use custom spacing controls.
* Currently experimental.
*
* @param array $settings Default editor settings.
*
* @return array Filtered editor settings.
*/
function gutenberg_extend_settings_link_color( $settings ) {
$settings['__experimentalEnableLinkColor'] = get_theme_support( 'experimental-link-color' );
return $settings;
}
add_filter( 'block_editor_settings', 'gutenberg_extend_settings_link_color' );
3 changes: 2 additions & 1 deletion lib/experimental-default-theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@
"dropCap": true
},
"color": {
"custom": true
"custom": true,
"link": false
},
"gradient": {
"custom": true
Expand Down
6 changes: 6 additions & 0 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,12 @@ function gutenberg_experimental_global_styles_get_editor_features( $config ) {
}
$features['global']['spacing']['custom'] = true;
}
if ( get_theme_support( 'experimental-link-color' ) ) {
if ( ! isset( $features['global']['color'] ) ) {
$features['global']['color'] = array();
}
$features['global']['color']['link'] = true;
}

return $features;
}
Expand Down
14 changes: 6 additions & 8 deletions packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from '../components/gradients';
import { cleanEmptyObject } from './utils';
import ColorPanel from './color-panel';
import useEditorFeature from '../components/use-editor-feature';

export const COLOR_SUPPORT_KEY = '__experimentalColor';

Expand Down Expand Up @@ -181,12 +182,10 @@ const getLinkColorFromAttributeValue = ( colors, value ) => {
*/
export function ColorEdit( props ) {
const { name: blockName, attributes } = props;
const { colors, gradients, __experimentalEnableLinkColor } = useSelect(
( select ) => {
return select( 'core/block-editor' ).getSettings();
},
[]
);
const isLinkColorEnabled = useEditorFeature( 'color.link' );
const { colors, gradients } = useSelect( ( select ) => {
return select( 'core/block-editor' ).getSettings();
}, [] );

// Shouldn't be needed but right now the ColorGradientsPanel
// can trigger both onChangeColor and onChangeBackground
Expand Down Expand Up @@ -315,8 +314,7 @@ export function ColorEdit( props ) {
? onChangeGradient
: undefined,
},
...( __experimentalEnableLinkColor &&
hasLinkColorSupport( blockName )
...( isLinkColorEnabled && hasLinkColorSupport( blockName )
? [
{
label: __( 'Link Color' ),
Expand Down
1 change: 0 additions & 1 deletion packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ class EditorProvider extends Component {
'__experimentalBlockDirectory',
'__experimentalBlockPatterns',
'__experimentalBlockPatternCategories',
'__experimentalEnableLinkColor',
'__experimentalEnableFullSiteEditing',
'__experimentalEnableFullSiteEditingDemo',
'__experimentalFeatures',
Expand Down

0 comments on commit 2172f0f

Please sign in to comment.