-
Notifications
You must be signed in to change notification settings - Fork 148
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
[Tidy] Replace custom classNames with BS utility CSS classes #910
Conversation
for more information, see https://pre-commit.ci
View the example dashboards of the current commit live on PyCafe ☕ 🚀Updated on: 2024-12-03 12:20:40 UTC Link: vizro-core/examples/dev/ Link: vizro-core/examples/scratch_dev |
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.
Looks good to me! 🙌
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.
Generally agree with everything you said, although I am probably more pro-bootstrap native than what you suggest. My proposed rule of thumb would be something like: use bootstrap shortcuts as much as possible. But if that's not practical then I agree with what you say 👍
Use Bootstrap classes instead of custom class names when it's unlikely that users will want to customize the HTML element via CSS, or when there is an alternative method for customization.
Agree.
Use custom class names for HTML elements that users are likely to want to customize e.g. all our main containers (page-header, control-panel, right-side, left-side etc.)
These are currently done with id
rather than className
, so we can potentially combine both our custom CSS and bootstrap and a user can still further customise them?
html.Div(id="page-header", classNames="align-items-left ...")
Then in our CSS we just provide any extra bits that we need. We wouldn't do any bootstrap overrides here, just provide extra attributes:
#page-header {
color: red; /* Some attribute not specified in bootstrap */
}
And if a user wanted to change something they would do:
#page-header {
color: red; /* Some attribute not specified in bootstrap */
align-items: right !important; /* Override something specified in boostrap */
}
The only thing that's awkward here is the !important
that's needed, and maybe if that's already used in bootstrap it doesn't even work well in practice? If that's the case then agree with what you say and I'm fine to just do this like:
html.Div(id="page-header")
#page-header {
align-items: left; /* All the things done by the bootstrap styles put here manually */
color: red;
}
Not related to above: Remove any redundant extra div if you see one
Always agree with this 👍
Yes, that's why I wasn't more supportive of using native Bootstrap everywhere. When you use any of Bootstrap's utility classes, they automatically include the For example, if you write: Bootstrap will apply the following CSS:
This forces the user to also use the In our case, it would even be more confusing as our users would then need to inspect elements to differentiate between CSS properties from our static folder and Bootstrap's classes with |
I've already merged this PR, but we can continue discussing our future strategy. I plan to replace all other custom class names with Bootstrap utilities for those elements that users are unlikely to want to customize. For elements where users might want to apply custom styles, I'll leave the class names unchanged for now, pending our discussion above. 👍 |
Description
Our long-term objective is to minimize the use of custom CSS in the static folder, favoring Bootstrap syntax instead. To achieve this, we can replace custom class names with Bootstrap utility CSS classes: https://getbootstrap.com/docs/4.0/utilities/borders/.
This PR shows one example on how to do so. However, I don't recommend replacing all custom class names with Bootstrap shortcuts, as it could make it harder for users to override styles.
Here are my current guidelines:
See example here where we could simplify using BS shortcuts: #910 (comment)
Screenshot
Notice
I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":