Tailwind Resolver - A resolveConfig() alternative for Tailwind v4 #19151
0xstern
started this conversation in
Show and tell
Replies: 1 comment
|
Hello! This is an excellent contribution to the Tailwind v4 ecosystem. The Key Benefits for the Community:
Implementation Example: // Chart.js integration with resolved theme values
import { defaultTheme } from 'tailwind-resolver';
const chartConfig = {
type: 'bar',
data: {
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
datasets: [{
label: 'Sales',
data: [65, 59, 80, 81],
backgroundColor: defaultTheme.colors.primary[500],
borderColor: defaultTheme.colors.primary[700],
borderWidth: defaultTheme.spacing(0.5)
}]
},
options: {
scales: {
y: {
grid: {
color: defaultTheme.colors.gray[200]
}
}
}
}
};Migration Path for v3 Users: import resolveConfig from 'tailwindcss/resolveConfig';
import tailwindConfig from './tailwind.config.js';
const theme = resolveConfig(tailwindConfig).theme;
import { defaultTheme } from 'tailwind-resolver';
// Use defaultTheme.colors, defaultTheme.spacing(), etc.Additional Use Cases:
This library effectively bridges the CSS-first approach of Tailwind v4 with the practical needs of JavaScript runtime environments. The conflict detection and TypeScript support make it production-ready for complex applications. Great work on addressing this community need! |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I built a tool that bridges the gap between Tailwind v4's
@themevariables and JavaScript runtime environments like Chart.js, Canvas, D3, or any library that needs access to your design tokens.For v3 users: This is a
resolveConfig()alternative for Tailwind v4, since v4's CSS-first approach means the old config-based approach no longer works.Tailwind v4 uses CSS variables (
--color-primary-500) which work great in CSS but are problematic when you need theme values in JavaScript. You can't use var(--color-primary) in Chart.js datasets or Canvas contexts.tailwind-resolverparses your Tailwind files and generates fully-typed TypeScript interfaces plus runtime objects with all your theme values resolved to actual strings.What it does
spacing(4)function that replicates Tailwind'scalc(var(--spacing) * N)behaviorExample usage
Features worth mentioning
@importresolution - handles complex file structures automatically[data-theme='dark'].compactwork correctlyInstallation
GitHub: https://github.com/0xstern/tailwind-resolver
The library is MIT licensed and open to contributions. I'd love to hear feedback from the community, especially if anyone has edge cases or feature requests.
All reactions