Last active
October 3, 2023 16:10
-
-
Save sastan/c4d8deb112660498431eaa66887958ce to your computer and use it in GitHub Desktop.
Extract CSS Object from Tailwind classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { create } from 'https://cdn.skypack.dev/twind' | |
const { tw: TW } = create({ preflight: false }) | |
const tw = (...tokens) => { | |
let styles | |
TW(({ css }) => { | |
styles = css(...tokens) | |
styles._ = undefined | |
return '' | |
}) | |
return styles | |
} | |
console.log('styles', tw('text-white')) | |
console.log('styles', tw`text-white bg-black`) | |
console.log('styles', tw`text-white bg-black`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function supports all the advanced Twind syntax like grouping, CSS helper, tailwind extensions.