-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add spacing tokens and demo #553
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
base: main
Are you sure you want to change the base?
Conversation
And horizontally align more things in tokens.css as with the new spacing tokens.
✅ Deploy Preview for cal-itp-website ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
this is already looking pretty promising.
I'm not 100% sure yet which I think is best
me neither tbh. personally i don't see much/any downside to just using Sass to:
- customize bootstrap to give us all the 8px spacing helpers we need
- compile our own CSS back into a single file
- take advantage of its own nesting
that said, i can live without all that. if we're going to stick to pure CSS my instinct would be to start by defining only the missing spacing increments that we have immediate use for (24px, 80px).
we can try a couple things as we start to lay out mobimart pages and see what feels nicest.
| } | ||
| .text-code { | ||
| font-family: var(--monospace-font-stack); | ||
| font-family: var(--dsdl-monospace-font-stack); |
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.
nice catch 😇
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.
since you're proposing this in #554, lets revert the change here.
| /* SPACING */ | ||
|
|
||
| :root { | ||
| --spacing-1px: 1px; /* Non-relative unit for when we don't want a single pixel stroke to scale */ |
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.
not sure i see the benefit of canonizing this as a CSS variable, but i'm okay with it.
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 did it to stay in sync with how Christine laid out the spec, but I think you're right that we should ditch it. I agree with the general principle (hence not adding variables for the different font weights before).
| --spacing-1px: 1px; /* Non-relative unit for when we don't want a single pixel stroke to scale */ | ||
|
|
||
| --spacing-base: 8; /* Calculated pixel sizes based on this base →→→→→→→→→→→→→ ↓↓↓↓↓ */ | ||
| --spacing-05: calc(var(--spacing-base) * 0.5 / var(--text-base) * 1rem); /* 4px */ |
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 could be missing something but defining a px base and calculating final values in rem makes these conversions feel unnecessarily convoluted.
// alternatives
:root {
--spacing-base: 8px;
--spacing-05: calc(var(--spacing-base) * 0.5); /* 4px */
--spacing-base: 0.5rem;
--spacing-05: calc(var(--spacing-base) * 0.5); /* 4px */
}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 it's convoluted.
The first alternative doesn't work if we want the result units to be rem.
The second alternative I don't like exactly as written because when we base things off of pixel values (as in the text sizing above), I like seeing that number. It could be added via comment, though, OR we could do something like this:
:root {
--spacing-base: calc(8 / var(--text-base) * 1em; /* 8px → 0.5rem */
--spacing-05: calc(var(--spacing-base) * 0.5); /* 0.25rem (4px) */
}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.
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.
Hrmmm. I wonder if that's just how Chrome displays it? I suppose the true test would be does it scale if you change the default text size in the browser prefs. I can double-check this.
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 do know we have discussed this in the past (can't remember where / too lazy to look, maybe Benefits) but rem is important for browser text resizing (e.g. zoom in/out, default text sizes). It scales more appropriately than px or em, leaving our intended designs and layouts in place.
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.
OK found some relevant context from Benefits: cal-itp/benefits#1082
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.
ah. very helpful @thekaveman. thank you!
in my own testing, chrome only displays computed values in px but those values do fluctuate based on the default browser text size when rem is used in the actual declaration.
testing this has me convinced that the simplified calculation below would be sufficient for us.
:root {
--spacing-base: 0.5rem;
--spacing-05: calc(var(--spacing-base) * 0.5); /* 0.25rem (4px) */
}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 also learned that github.com fails to honor non-default browser text sizes completely. i was surprised by this because they've made loads of accessibility improvements over the last few years.
edit: a little poking and a QA with gemini has me convinced that GitHub is making a conscious decision to solely support scaling the entire site on fly in the name of preserving layout precision.
food for thought.
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.
edit: a little poking and a QA with gemini has me convinced that GitHub is making a conscious decision to solely support scaling the entire site on fly in the name of preserving layout precision.
That decision doesn't seem unreasonable to me, in the context of an app with such a heavy UI.
For our products, though, I think we should be more flexible.
I realize now that I didn't include the new |


ℹ️ PR is to base branch
feature/dsdlℹ️Closes #550
This PR adds spacing tokens to the DSDL CSS and adds a chart of them to the demo page.
Review commit-by-commit to avoid seeing some minor cleanup until last.
For discussion at some point
We currently use Bootstrap's spacing utility classes extensively throughout our projects. This new 8px-based spacing system creates a tension with those in projects where we do not use Sass, because there is not a CSS variable for overriding their base
$spacerand adding the additional increments we want would require overriding a Sass map.Generating our own custom spacing utilities would require a massive amount of work to cover all of the same functionality that Bootstrap's offer (margin + padding * six directional options * 14 increments).
The two options I see are:
(not necessarily in order of my preference – I'm not 100% sure yet which I think is best)