feat: Add css classes from json block definitions#8377
Merged
BeksOmega merged 3 commits intoRaspberryPiFoundation:rc/v12.0.0from Jul 17, 2024
Merged
Conversation
BeksOmega
suggested changes
Jul 16, 2024
core/block_svg.ts
Outdated
Comment on lines
+1728
to
+1736
| let classesToAdd = ''; | ||
|
|
||
| if (Array.isArray(json['classes'])) { | ||
| classesToAdd = json['classes'].join(' '); | ||
| } else { | ||
| classesToAdd = json['classes']; | ||
| } | ||
|
|
||
| this.addClass(classesToAdd); |
Contributor
There was a problem hiding this comment.
I think you can simplify this using a ternary operator.
Suggested change
| let classesToAdd = ''; | |
| if (Array.isArray(json['classes'])) { | |
| classesToAdd = json['classes'].join(' '); | |
| } else { | |
| classesToAdd = json['classes']; | |
| } | |
| this.addClass(classesToAdd); | |
| this.addClass(Array.isArray(json['classes']) ? json['classes'].join(' ') : json['classes']); |
You'll probably need to run npm run format in the root directory after applying this change to handle the line wrapping.
Contributor
Author
There was a problem hiding this comment.
I agree, thanks for pointing that out! Updated that and formatted using npm run format.
BeksOmega
approved these changes
Jul 16, 2024
Contributor
BeksOmega
left a comment
There was a problem hiding this comment.
Sweetness! Thank you for the fix this looks great =) I'll get this merged once CI passes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The basics
The details
This PR overrides the
jsonInitmethod in theBlockSvgclass to get the css class names from theclassesfield and apply the same using theaddClassmethod.Fixes #8271