Defining Custom Spacing Scale with extendTailwindMerge
#494
-
Hi everyone, I'm trying to define a custom spacing scale in a Here’s how I’m overriding the spacing: {
theme: {
spacing: {
/* Spacing */
"sp-1": "var(--fui-sp-1)",
"sp-2": "var(--fui-sp-2)",
"sp-3": "var(--fui-sp-3)",
"sp-4": "var(--fui-sp-4)",
"sp-5": "var(--fui-sp-5)",
"sp-6": "var(--fui-sp-6)",
"sp-7": "var(--fui-sp-7)",
"sp-8": "var(--fui-sp-8)",
"sp-9": "var(--fui-sp-9)",
/* Sizing */
"s-1": "var(--fui-s-1)",
"s-2": "var(--fui-s-2)",
"s-3": "var(--fui-s-3)",
"s-4": "var(--fui-s-4)",
"s-5": "var(--fui-s-5)",
"s-6": "var(--fui-s-6)",
"s-7": "var(--fui-s-7)",
"s-8": "var(--fui-s-8)",
"s-9": "var(--fui-s-9)",
"s-10": "var(--fui-s-10)",
},
},
} The goal is to make Has anyone successfully configured custom spacing scales in Thanks in advance! 😊 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I too am having the same issue. I want to use t-shirt sizing for spacing values. Here is my custom config, but this is not working. This is my first time trying to customize twMerge. Any ideas?
|
Beta Was this translation helpful? Give feedback.
-
So my goal was to be able to use t-shirt sizing to spacing values in Tailwind. The reason I was doing this was to integrate https://utopia.fyi/ for fluid type and spacing. The text scale works as is, but I was having trouble with the spacings. Here is the config file that I used to extend twMerge:
So far, it even seems to be working with the weird utility classes that Utopia requires, such as 'm-sm-lg' and py-2xl-4xl'. So this:
Returns this |
Beta Was this translation helpful? Give feedback.
Hey @jeniabrook and @jkinley! 👋
Thanks for your patience! You basically figured it out already. tailwind-merge sometimes supports the theme scale and sometimes only the class group. It's a bit confusing indeed, but all for bundle size reasons because all this code needs to be sent to the browser.
If you want to have T-shirt sizes in the spacing scale, you can also do this:
That will allow all T-shirt sizes and even values like
123xl
or0.5md
.