-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat: Add css classes from json block definitions #8377
feat: Add css classes from json block definitions #8377
Conversation
core/block_svg.ts
Outdated
let classesToAdd = ''; | ||
|
||
if (Array.isArray(json['classes'])) { | ||
classesToAdd = json['classes'].join(' '); | ||
} else { | ||
classesToAdd = json['classes']; | ||
} | ||
|
||
this.addClass(classesToAdd); |
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 you can simplify this using a ternary operator.
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.
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 agree, thanks for pointing that out! Updated that and formatted using npm run format
.
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.
Sweetness! Thank you for the fix this looks great =) I'll get this merged once CI passes.
The basics
The details
This PR overrides the
jsonInit
method in theBlockSvg
class to get the css class names from theclasses
field and apply the same using theaddClass
method.Fixes #8271