twind icon indicating copy to clipboard operation
twind copied to clipboard

Any ways to add prefix for css rules generted by twind

Open colgin opened this issue 3 years ago • 2 comments

code

const classNames = tw`${apply`p-1 text-red-500`}`

// classNames is like  tw-xxxx

I want to add a scope of this rule, like

html[name="abc"] .tw-xxx {
}

What should i do to make this work

colgin avatar Aug 08 '22 10:08 colgin

Try this:

import { css } from 'twind/css';

const cssDirective = css({
  'html[name="abc"] &': apply`p-1 text-red-500`,
});

const className = tw(cssDirective);

Here you can see documents about above.

alker0 avatar Aug 22 '22 23:08 alker0

Thank you for your reply, but i want add a scope for all rules generated by twind, is there an easy way can make this work

colgin avatar Aug 24 '22 05:08 colgin

I'm looking for the same thing, any way possible.

Specifically: .rounded { border-radius: 0.25rem; } should be prefixed like header .rounded { border-radius: 0.25rem; }

tmikaeld avatar Feb 06 '23 12:02 tmikaeld

The closest I've found is: https://twind.style/reference#add-namespacescope-to-all-classes

But I don't think it works as expected? The example given:

defineConfig({
  hash(className) {
    return `.scoped ${className}`
  },
})

Produce CSS:

.\.scoped font-medium { font-weight: 500 }

UPDATE: Scoped tailwind seems to be a fools errand, since now the whole pages tailwind css need to be scoped too or it will interfere with the preciously or after scroped CSS.

tmikaeld avatar Feb 06 '23 13:02 tmikaeld

Hey folks. This issue hasn't received any traction for 90 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it.

stale[bot] avatar Dec 04 '23 01:12 stale[bot]