question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using twind to generate css files using theme/default values.

See original GitHub issue

I have a specific use case, which I believe twind can help with. My problem is that most of my site is using the tailwind pattern, which works well since I control the rendering code - and therefore I can apply classes onto elements. However, a part of my site uses a markdown renderer, and I have some very complex css selectors that are used to render that markdown nicely. I don’t control the DOM generation. However, I would like things like colors and spacings to use some of the values from my twind setup. It thought that the css-in-js section of the docs would cover this, but it doesn’t look like it does (or maybe the docs just need to clarify?)

For example I would like to generate a css string to be included in a .css file that has something like:

var myCssText = `
  .markdown-root > p > a {
    color: ${twind.theme.blue.300}
  }
`

Is this workflow supported and/or documentation explaining how to do this?

I’m also curious how one would specify variants as well where the answer to “what is the css inline style for dark:bg-0?” is not “background: black”, but rather "well, it depends on if your page has dark mode enabled, and that depends on if your theme was set up with darkMode:class or not. So the answer to the question would not necessarily be a style but selector + style.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sastancommented, Jan 25, 2022

This is now possible in twind v1.

import { twind, virtual, css, stringify } from 'twind'
const tw = twind({ /* config */ }, virtual())

const myCssText = css`
  .markdown-root > p > a {
    color: theme(colorsblue.300);
  }
`
// start fresh
tw.clear()
// inject styles
tw(myCssText)
// grep css strings
const cssString = stringify(tw.target)

Please give it a try. Here are some links to get you started:

Closing this for now. Feel free to re-open.

1reaction
sastancommented, Apr 6, 2021

You can combine Daniels solution with the extraction and dark mode support from this example

Read more comments on GitHub >

github_iconTop Results From Across the Web

Theme Configuration - Tailwind CSS
The theme section of your tailwind.config.js file is where you define your project's color palette, type scale, fonts, breakpoints, border radius values, and ......
Read more >
Configuration and Theming - Twind
Twind collects generated CSS rules in sheet to make theme available to the environment. By default Twind uses a speedy (CSSOM) implementation when...
Read more >
ASP.NET and Styles & CSS Embedding - Rick Strahl's Web Log
One thing that really bugs me about ASP.NET is the way it deals with header management especially when working with Themes.
Read more >
Can't load the CSS-Files from assets-folder in Angular
html in the folder. But I wanna use it in the setcard.component.html. Wenn I open the url localhost:4200/setcard/1 then I will get ......
Read more >
RWT Theming - RAP - Developer's Guide
Creating a Theme File (CSS). This section explains the basic rules for writing CSS theme files. Themes are written in CSS using widget...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found