Giter Site home page Giter Site logo

Inline plugin global styles about twind HOT 8 CLOSED

tw-in-js avatar tw-in-js commented on August 22, 2024
Inline plugin global styles

from twind.

Comments (8)

tylerforesthauser avatar tylerforesthauser commented on August 22, 2024 1

Done

from twind.

sastan avatar sastan commented on August 22, 2024

Regarding this new (:global)[https://github.com/tw-in-js/twind/blob/main/docs/plugins.md#inject-global-styles] property, is it at all possible to declare global styles from within inline plugins? That would be a nifty way to allow declaration of global styles from virtually anywhere in your app.

Something like this should work:

tw(() => ({     
  ':global': { /* global styles */ },
}))

tw(css({     
  ':global': { /* global styles */ },
}))

With tw.apply this should be possible:

tw(() => ({     
  ':global': { 
   a: tw.apply`text-blue-500`
  },
}))

tw(css({     
  ':global': { 
   a: tw.apply`text-blue-500`
  },
}))

from twind.

tylerforesthauser avatar tylerforesthauser commented on August 22, 2024

That honestly looks amazing but I am having no luck actually getting either of those to output anything at all...

tw(() => ({
  ':global': {
    html: tw('bg-gray-900 text-white'),
  },
}))

Meanwhile, the following does work...

tw(
  css({
    ':global': {
      html: {
        backgroundColor: '#333',
      },
    },
  })
)

And this...

tw(() => ({
  ':global': {
    html: {
      backgroundColor: '#333',
    },
  },
}))

And this...

tw(({ theme }) => ({
  ':global': {
    html: {
      backgroundColor: theme('colors.gray.900'),
    },
  },
}))

from twind.

sastan avatar sastan commented on August 22, 2024

Sorry. My bad. This depends on #85 and is not yet released. You could try the PR package. It's described in the PR

Edit: @tylerforesthauser I'll try to cut a release tomorrow. Could you please describe what you are trying to achieve and I'll add tests to verify the behavior before the release. Sorry. It's late here maybe you already did.

from twind.

sastan avatar sastan commented on August 22, 2024

Your first example (the one that does not work) can not work as tw always returns a string of class names. You'll need to use tw.apply for this which is not yet merged or released. See the component PR #83 and try PR package.

from twind.

tylerforesthauser avatar tylerforesthauser commented on August 22, 2024

No no it's all good. I've got the changes merged into my local repo and I'm using the package from there, so it includes your changes from #85 and the component-api branch. The selector actually works! Just not for nested tw.apply functions.

My end goal is to declare global styles (specifically on the html element) from somewhere other than from preflight.

I realize I entered my code incorrectly in my comment above but I, indeed, used tw.apply.

So to clarify from my comment above, the following examples WORK:

tw(
  css({
    ':global': {
      html: {
        backgroundColor: '#333',
      },
    },
  })
)
tw(() => ({
  ':global': {
    html: {
      backgroundColor: '#333',
    },
  },
}))
tw(({ theme }) => ({
  ':global': {
    html: {
      backgroundColor: theme('colors.gray.900'),
    },
  },
}))

And these examples, however, DO NOT WORK.

tw(() => ({
  ':global': {
    html: tw.apply('bg-gray-900 text-white'),
  },
}))
tw(css({     
  ':global': { 
   html: tw.apply('bg-gray-900 text-white'),
  },
}))

from twind.

sastan avatar sastan commented on August 22, 2024

This should work in #83 (7b446c9)

from twind.

sastan avatar sastan commented on August 22, 2024

@tylerforesthauser This issue has two topics. Using tw.apply in :global and in preflight should now be fixed in #83 . Preflight merging should be a new issue discussing its impact. Could you please create one only for merging preflight styles.

from twind.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.