-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Replace default explicit spacing scale with multiplier system #14857
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
Conversation
| let num = Number(value) | ||
| if (num < 0 || num % 0.25 !== 0 || String(num) !== value) return null | ||
|
|
||
| return `calc(${multiplier} * ${value})` |
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.
If the --spacing var has the inline flag, we could avoid the calc() here since the value would be static anyways.
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.
Lightning CSS will evaluate and minify this for us if the value is inline so I figured we would just not worry about that in our codebase and let Lightning handle 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.
gotcha!
3a7b9ac to
9afac1d
Compare
| <h1>🤠👋</h1> | ||
| <div | ||
| class="flex! sm:block! bg-linear-to-t bg-[var(--my-red)] max-w-[var(--breakpoint-md)] ml-[var(--spacing-1_5)]" | ||
| class="flex! sm:block! bg-linear-to-t bg-[var(--my-red)] max-w-[var(--breakpoint-md)] ml-[var(--breakpoint-md)]" |
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.
Changed this to something else until we work on the codemod for this new spacing stuff.
| if (value === null && candidate.negative && desc.handleNegativeBareValue) { | ||
| value = desc.handleNegativeBareValue(candidate.value) | ||
| if (!value?.includes('/') && candidate.modifier) return | ||
| if (value !== null) return desc.handle(value) | ||
| } | ||
|
|
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 isn't strictly necessary for things to just work but without control over this from spacingUtility, the output of negative values would contain nested calc calls and just looked really ugly and unnecessary:
.-ml-4 {
- margin-left: calc(var(--spacing) * -4);
+ margin-left: calc(calc(var(--spacing) * 4) * -1);
}bacc455 to
4e536cd
Compare
|
can someone tell me how im supposed to use --spacing-2 now without writing the calcs all the time on my own inside components? |
This PR replaces the default spacing scale (
--spacing-*) with a generative system based on a default spacing unit.Instead of the default theme containing values like
--spacing-4,--spacing-6,--spacing-8, etc., instead we just define a single--spacingvalue:Utilities like
px-4are derived from this unit by multiplying it by the value in the utility (4 in this case):The biggest consequence of this change is that every value is available now, rather than just the explicitly configured values.
This means utilities like
px-42will work now, whereas prior to this PR onlypx-40andpx-44were valid utilities. I personally found it very difficult to know which values actually existed at the higher end of the scale without IntelliSense, and in practice even when working with a skilled designer like Steve who helped design Tailwind's default spacing scale, I'd very often need to break out of it to implement a design, and trying to round to a value that was in the scale made the design worse, not better.This PR allows you to use any whole number, as well as decimal numbers that are multiples of
0.25to ensure classes likepx-1.5continue to work. While this means you can now technically do things likept-97.25, I think the presence of the fractional value will be enough of a signal to developers that they are doing something a little unusual, and they can use their judgment as to whether they are making the right decision or not.I'll update this PR with a lot more detail when I have a chance, as there are a few other things to explain like:
--spacing: initialto disable the multiplier