Skip to content
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

Fix: Converted inline item width to CSS variable (fixes #158) #159

Merged
merged 5 commits into from
Jan 28, 2025

Conversation

guywillis
Copy link
Contributor

Fixes: #158

Fix

  • Converted inline item width to CSS variable

@guywillis guywillis added the bug label Jan 14, 2025
@guywillis guywillis self-assigned this Jan 14, 2025
@guywillis guywillis requested a review from swashbuck January 14, 2025 11:40
js/HotgridView.js Outdated Show resolved Hide resolved
@swashbuck
Copy link
Contributor

I guess my issue with the CSS variable approach is that it makes the following difficult:

In a custom theme, if we then needed the items to only be 30% width instead of 33%, we would simply add it to the theme:

.has-3-columns .hotgrid__item {
   width: 30%;
}

This would also make it easier to adjust the width at different breakpoints as we can rely on @media queries in the Less.

@media (min-width: 10rem) and (max-width: 20rem) {
  .has-3-columns .hotgrid__item {
     width: 23%;
  }
}

@oliverfoster
Copy link
Member

oliverfoster commented Jan 14, 2025

Could you explain how you propose to fix this part of my previous comment:

You'd have to specify has-x-columns classes for all of the available x options

Such that all of the correct width values are present with predefined classes:

.has-2-columns .hotgrid__item {
   width: 50%;
}

.has-3-columns .hotgrid__item {
   width: 33%;
}

.has-4-columns .hotgrid__item {
   width: 25%;
}

.has-5-columns .hotgrid__item {
   width: 20%;
}

Would you use a mixin and add all of the possible classes to the less output (2-10 columns?), would you have to manually add more classes if you needed more columns?

Note: We added configuration classes like this a lot on previous components and menus (narrative, cover, blinds, etc) and it's very brittle and limited and irritating to write and understand and change and always adds excess less that isn't used to every project. Width values should be calculated at runtime rather than being predefined, it's easier and simpler.

When adding the class has-x-columns to the component element, a component with has-3-columns would need to switch to has-2-columns and back at the small-medium transition, as columns always collapse to 2/50% width on mobile.

You could add the .has-${_columns}-columns class to the component element, without predefining the class widths, and carry on using the css variables to calculate the widths. This way it would be be possible to calculate the widths at runtime and/or override specific column settings using classes only.

It sounds as though you'd like to change all x column hotgrids in one override whereas the CSS variable implementation is just to switch inline defined widths to class-based widths, which are easier to override without an !important directive.

js/HotgridView.js Outdated Show resolved Hide resolved
@swashbuck
Copy link
Contributor

You'd have to specify has-x-columns classes for all of the available x options

@oliverfoster This doesn't concern me that much as we can always specify "up to" a reasonable amount of options and use a mixin to create the classes. Unused styles are also unavoidable in many cases, so it doesn't bother me to have unused column classes hanging around (like the Vanilla theme's column classes).

Width values should be calculated at runtime rather than being predefined, it's easier and simpler.

I think this is an issue of separating styling from presentation/code. Style values should all live in the theme if possible.

It sounds as though you'd like to change all x column hotgrids in one override whereas the CSS variable implementation is just to switch inline defined widths to class-based widths, which are easier to override without an !important directive.

Yes, classes are much easier to override and changes would most likely be at a global level.

Also, I haven't looked at your recent commit(s). But as long as we have something like has-x-columns as a class, I can work with that for any custom theme work.

Copy link
Contributor

@swashbuck swashbuck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

js/HotgridView.js Outdated Show resolved Hide resolved
Copy link
Contributor

@kirsty-hames kirsty-hames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great thanks 👍 minor comment added regarding trailing space

@oliverfoster oliverfoster merged commit 3c4c988 into master Jan 28, 2025
@oliverfoster oliverfoster deleted the issue/158 branch January 28, 2025 16:34
github-actions bot pushed a commit that referenced this pull request Jan 28, 2025
## [4.6.5](v4.6.4...v4.6.5) (2025-01-28)

### Fix

* Converted inline item width to CSS variable (fixes #158) (#159) ([3c4c988](3c4c988)), closes [#158](#158) [#159](#159)
Copy link

🎉 This PR is included in version 4.6.5 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set item widths with CSS class instead of calculated inline style
4 participants