Add an eslint rule to use cross-environment SVG primitives#10652
Add an eslint rule to use cross-environment SVG primitives#10652
Conversation
.eslintrc.js
Outdated
| message: 'Deprecated functions must be removed before releasing this version.', | ||
| }, | ||
| { | ||
| selector: 'JSXIdentifier[name=/^(path|svg)$/]', |
There was a problem hiding this comment.
Should we also add <g> and <polygon> that we already have componentized as well?
There was a problem hiding this comment.
Yes, sure.
The eslint rule is too aggressive at the moment, it also catches props named "path"
As Riad mentioned, this rule needs to be updated anyways.
|
Many thanks for opening this PR @youknowriad ❤️ |
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><Path d="M19 7h-1V5h-4v2h-4V5H6v2H5c-1.1 0-2 .9-2 2v10h18V9c0-1.1-.9-2-2-2zm0 10H5V9h14v8z" /></SVG> I personally think that setDefaultBlockName( paragraph.name );
if ( window.wp && window.wp.oldEditor ) {
setFreeformContentHandlerName( classic.name );
}
setUnregisteredTypeHandlerName( missing.name );
...
setDefaultIcon(
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><Path d="M19 7h-1V5h-4v2h-4V5H6v2H5c-1.1 0-2 .9-2 2v10h18V9c0-1.1-.9-2-2-2zm0 10H5V9h14v8z" /></SVG>
); |
|
@Tug if you have some time, you can help to land this one. |
37533b2 to
7f8df8c
Compare
|
This should be ready to ship. I figured out that there is an existing rule in react linting library which we could take advantage of: https://github.com/yannickcr/eslint-plugin-react/blob/HEAD/docs/rules/forbid-elements.md. |
aduth
left a comment
There was a problem hiding this comment.
This white-screens for me (and apparently in Travis) with the following error:
Uncaught TypeError: Cannot read property 'SVG' of undefined
Maybe missing a dependency? (From blocks to components)
Yes, it is an actual issue which @youknowriad raised earlier. I will refactor code to avoid using SVG inside |
7f8df8c to
6efe432
Compare
|
|
||
| function renderIcon( icon ) { | ||
| if ( 'string' === typeof icon ) { | ||
| if ( icon === 'block-default' ) { |
There was a problem hiding this comment.
@jasmussen - is it okay to handle SVG replacement in here?
We want to avoid having a dependency on @wordpress/components inside @wordpress/blocks. My reasoning is as follows: blocks API should be UI agnostic as much as possible, that's why it provides only an icon name. BlockIcon is always used to render an actual icon, so we can be more opinionated here.
There was a problem hiding this comment.
Can you elaborate a little bit? Not sure I understand the context.
There was a problem hiding this comment.
I changed my mind when entertaining with the exisitng implementation. I reverted all change in normalizeIconObject to use default-block dashicon. However, it is replaced with the new nice SVG icon inside BlockEdit. This should behave exactly the same in the UI.
There was a problem hiding this comment.
Ah, gotcha. I don't have strong opinions here, and I would defer to you two for the technical implementation. What matters is:
- We encourage the use of SVG (i.e. make it easy)
- We can provide an icon set even for new blocks, like Dashicons, in the future.
- 3rd party provided SVGs are processed so
roleandfocusableattributes are added.
If those values are upheld, 👍 👍 from me.
There was a problem hiding this comment.
We can provide an icon set even for new blocks, like Dashicons, in the future.
I think it would be convenient to be able to use strings if someone is happy with the default icon set.
3rd party provided SVGs are processed so role and focusable attributes are added.
This is what SVG component does :)
It's no longer the case, see #10652 (comment).
e2e tests pass so I think block icons should be fine as @jorgefilipecosta build an extensive set of assertions for them. It was missing dependency, but I solved it by making |
|
I added fbd3a30 to ensure that fix for the regression (#10987) works with the default SVG icon, too. |
Uses an existing react eslint rule to perform validation. Adds new components to make the existing icons mobile app friendly.
… normalization in BlockIcon Props to @jasmussen for helping to catch it.
fbd3a30 to
0b37479
Compare
…#10652) * Add an eslint rule to use cross-environment SVG primitives * Extend the list of forbidden elements Uses an existing react eslint rule to perform validation. Adds new components to make the existing icons mobile app friendly. * Change the way the default icon for block is set * Ensure that default icon goes through the process of width and height normalization in BlockIcon Props to @jasmussen for helping to catch it.
Still WIP, the idea is to try to force the usage of the SVG primitives instead of the raw components to ensure mobile compatibility.
blocks -> components. Makes me think these primitives should be better in theelementpackage.