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

Dynamic color var #18

Closed
willybahuaud opened this issue Dec 8, 2022 · 1 comment · Fixed by #21
Closed

Dynamic color var #18

willybahuaud opened this issue Dec 8, 2022 · 1 comment · Fixed by #21
Labels
Enhancement New enhancement or feature request.
Milestone

Comments

@willybahuaud
Copy link

willybahuaud commented Dec 8, 2022

Hi !

First: thanks for this block, it's really usefull :)

For the bug:
When I update my color scheme, icon color aren't updated. It's because you assign the value when saving.
So I use the snippet below to force the use of CSS dynamic var, but it's kinda tricky, isn't?

function w_replace_color_value_by_dynamic_color_var( $block_content, $block ) {
  if ( $block['blockName'] === 'outermost/icon-block' ) {
    if ( $block['attrs']['iconColor'] !== $block['attrs']['iconColorValue'] ) {
      $block_content = str_replace(
        $block['attrs']['iconColorValue'],
        sprintf('var(--wp--preset--color--%s)', $block['attrs']['iconColor']),
        $block_content );
    }
  }
  return $block_content;
}
add_filter( 'render_block', 'w_replace_color_value_by_dynamic_color_var', 10, 2 );

What do you think about passing color varname to render instead?

@ndiego ndiego added the Enhancement New enhancement or feature request. label Dec 9, 2022
@ndiego
Copy link
Owner

ndiego commented Dec 9, 2022

Thanks for logging this @willybahuaud. I completely agree with you. It's frustrating when you change colors in the Site Editor, and then the icon colors do not update. The current functionality is the same used by the WordPress core Social Icons block which I used as a rough guide when building the Icon Block but it's obviously not ideal. I will look into a method to resolve this for the next release.

Sidenote, your workaround is impressive. Love it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New enhancement or feature request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants