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

Expose method to get current active style #14336

Closed
simison opened this issue Mar 8, 2019 · 3 comments
Closed

Expose method to get current active style #14336

simison opened this issue Mar 8, 2019 · 3 comments
Labels
[Feature] Theme Style Variations Related to style variations provided by block themes [Type] Enhancement A suggestion for improvement.

Comments

@simison
Copy link
Member

simison commented Mar 8, 2019

Is your feature request related to a problem? Please describe.

Consider plugin author wanting to show or disable different block sidebar settings depending on active style.

wp-editor's blockStyles component has getActiveStyle method but it isn't exposed to be used outside the package:

/**
* Returns the active style from the given className.
*
* @param {Array} styles Block style variations.
* @param {string} className Class name
*
* @return {Object?} The active style.
*/
export function getActiveStyle( styles, className ) {
for ( const style of new TokenList( className ).values() ) {
if ( style.indexOf( 'is-style-' ) === -1 ) {
continue;
}
const potentialStyleName = style.substring( 9 );
const activeStyle = find( styles, { name: potentialStyleName } );
if ( activeStyle ) {
return activeStyle;
}
}
return find( styles, 'isDefault' );
}

Describe the solution you'd like
Please export utils to modify styles; get lists, get active state, change styles so that plugin authors can build more complex sidebar settings around these features.

Describe alternatives you've considered
It's obviously already possible to use these methods by just copying them directly to block code. Boo code duplication.

@youknowriad
Copy link
Contributor

I agree this should be done, I think we could expose the active style directly in a special prop in the edit/save functions. I think there might be an existing issue about this?

@youknowriad youknowriad added [Type] Enhancement A suggestion for improvement. [Feature] Theme Style Variations Related to style variations provided by block themes labels Mar 8, 2019
@simison
Copy link
Member Author

simison commented Mar 8, 2019

I like that even better. :-)

I'm trying to imagine if there are a situations where plugin author would want to use a setter method?

Perhaps activate different style by default when inserting the block, perhaps by picking the style from previously inserted child block inside the parent block? Or hide some styles by changing some setting at the sidebar?

@youknowriad
Copy link
Contributor

Actually, this is a duplicate of #13506, so let's discuss there instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Theme Style Variations Related to style variations provided by block themes [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants