-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Social Icons: Add examples for Social Link variations. #62767
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +19 B (0%) Total Size: 1.76 MB
ℹ️ View Unchanged
|
variation.example = { | ||
attributes: { | ||
service: variation.name, | ||
url: '#', | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think adding a viewportWidth
in the example
object would be good as the preview is quite small and scaled down.
A value of 0
results in no scaling which is an option. 150
results in the icon nicely centered but zoomed in and showing some pixelation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be ok to ship this as it is, but the trouble is the preview isn't truly showing what the social icon will look like. For example, the WordPress icon is supposed to look like this:
But the preview is showing this:
This might be why there's no example 😄
I think this is a side effect of how the block has been implemented. The example is showing a social link icon without the social links parent, but the social links block is what provides all the styles at the moment. I have no idea why it was implemented like this, my feeling is that each block should be responsible for providing its own base styles.
A fix would be to refactor the css of the blocks, though lots of care would have to be taken to make sure nothing is broken along the way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another concern is that it generates invalid HTML in the preview area. The li
elements need to be placed as children of ul
or ol
element, but the parent of the li
element is a div
.
If the block itself could know in what context it was being rendered, it might be possible to, for example, wrap it in a Social Links block or remove the li
element, but as far as I know there is no way to do this 🤔
That's a good observation. Maybe supporting a example: {
name: 'core/social-links',
innerBlocks: [
{
name: 'core/social-link',
attributes: { service: variation.name, url: '#' },
},
],
} |
I think this is a good idea. We might be able to ship this PR before that approach is implemented, but I'm hesitant about whether to tolerate invalid markup. |
One drawback I can think of is that if a user selects a different social links style (e.g. 'Huge' size, with 'Pill Shaped' block style), then the preview would show the incorrect style, and it might be quite hard to fix that with the way the social links block is hard coded. Having said that, it already seems to be a problem with other blocks (e.g. if you trying adding a paragraph inside a quote, the preview shows the paragraph with the wrong style). edit: It could be an option like |
Well, at the very least, I am glad this PR started a good discussion around block previews. 😉 The "No preview available" message feels like something is broken, especially when it appears on Core blocks, and this situation with child blocks is relatively common. I have a block that uses a similar approach. I think adding the
I am not sure the example needs to represent the current state of the block when inserted in a specific spot or styled in a specific way by the parent. That sounds like it would get complicated very quickly. As long as it displays a realistic default state for the block, it's a good baseline IMO. |
What?
The variations for the Social Link block do not have the
example
property set, which causes the block inserter to display the messageNo preview available
. This PR fixes that.How?
The following code to adds example content to each variation. I've set
#
for theurl
property since unlinked icons have opacity applied.Testing Instructions
Screenshots or screencast
The preview is not the best, but it's better than displaying no preview at all.