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

Set item widths with CSS class instead of calculated inline style #158

Open
swashbuck opened this issue Jan 8, 2025 · 1 comment · May be fixed by #159
Open

Set item widths with CSS class instead of calculated inline style #158

swashbuck opened this issue Jan 8, 2025 · 1 comment · May be fixed by #159
Assignees

Comments

@swashbuck
Copy link
Contributor

swashbuck commented Jan 8, 2025

Subject of the issue

Currently, item widths are set as inline width styles.

style={(_columns && hasColumnLayout) ?
{ width: `${100 / _columns}%` } :
null}

This results in the width being set as an inline style.

<div class="hotgrid__item" role="listitem" style="width: 33.3333%;">

This would be easier to override in a custom theme if a class was used instead. For example, when the component is set to use 3 columns, add has-3-columns to the component__widget. The styles would then determine how wide each item should be. For example:

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

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.

@swashbuck swashbuck changed the title Set item widths with CSS class instead of calculated inline width Set item widths with CSS class instead of calculated inline style Jan 8, 2025
@oliverfoster
Copy link
Member

oliverfoster commented Jan 9, 2025

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

Instead you could use the styling:

.hotgrid__item {
   width: var(--adapt-hotgrid-item-width);
}

Set the CSS variable value in the view:

this.el.style.setProperty('--adapt-hotgrid-item-width', `${100 / _columns}%`);

This effectively sets the style attribute using CSS classes in a way that can be overridden with custom CSS.

@guywillis guywillis self-assigned this Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants