Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support enabling custom link color from theme.json #25148

Merged
merged 1 commit into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe there's a better path here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to approve as it is. In its current shape, the other option I can think of is making link a top-level element of features, which doesn't feel great either.

I also wonder if we should do a follow-up PR when we revisit/consolidate the features shape before releasing Gutenberg 9.0. I believe is the first release we include this feature and it'll be good to avoid changing shape later. Left some comments at #20588 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely need a follow-up PR to reshape the paths. That said, I'm not sure if it's before or after Gutenberg 9.0. The important thing is to do it before we make theme.json stable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the first release for these things, 8.9 include one or two features and dropCap is there for a long time.

},
"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' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like how the useEditorFeature simplifies the code. Can't wait to see the same done for presets.

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