tailwindcss-dir icon indicating copy to clipboard operation
tailwindcss-dir copied to clipboard

How to use a specific direction as varient?

Open sarmad4444 opened this issue 5 years ago • 9 comments

How can I achieve something like:

@variant rtl {
    .menu-collapsed {
        @apply border-l;
    }
}

sarmad4444 avatar Mar 04 '20 04:03 sarmad4444

+++++++

rant989 avatar May 25 '20 09:05 rant989

Hi,

This plugin doesn't translate well into CSS (seeing as how you can't @apply variants).

What I did to get around this in my own personal projects, is add a scss mixin:

@mixin ltr {
	[dir='ltr'] & {
		@content;
	}
}

@mixin rtl {
	[dir='rtl'] & {
		@content;
	}
}

.field {
	@include ltr() {
		@apply ml-12;
	}

	@include rtl() {
		@apply mr-12;
	}
}

RonMelkhior avatar May 25 '20 09:05 RonMelkhior

I would like to have this feature too. Are you accepting PRs @RonMelkhior? I wouldn't mind to add it.

jzabala avatar Jun 19 '20 22:06 jzabala

I would like to have this feature too. Are you accepting PRs @RonMelkhior? I wouldn't mind to add it.

Hi!

Do you mean adding variant support in @apply? Or adding some helpers to the PostCSS side?

I'd love to accept a PR for it, but depending on your implementation it might fit better in it's own repo so people who don't use tailwind can enjoy it. If your implementation will be pretty Tailwind-specific then of course :)

RonMelkhior avatar Jun 20 '20 05:06 RonMelkhior

Hi!

Do you mean adding variant support in @apply? Or adding some helpers to the PostCSS side?

I'd love to accept a PR for it, but depending on your implementation it might fit better in it's own repo so people who don't use tailwind can enjoy it. If your implementation will be pretty Tailwind-specific then of course :)

hi @RonMelkhior

My idea is just adding the additional variants (rtl and ltf) to allow what was initially proposed in this issue:

@variant rtl {
    .menu-collapsed {
        @apply border-l;
    }
}

By default I program my styles in ltr and only needs the variant for rtl. What do you think?

jzabala avatar Jun 20 '20 13:06 jzabala

I doubt you can change @variant rtl to work like that since @variant is a Tailwind directive. If it's possible sure but I'd just create a custom PostCSS directive independent of Tailwind

RonMelkhior avatar Jun 20 '20 14:06 RonMelkhior

I doubt you can change @variant rtl to work like that since @variant is a Tailwind directive. If it's possible sure but I'd just create a custom PostCSS directive independent of Tailwind

I think it is not possible right now because only the direction variant is being registered in tailwind. I created a PR to add the other variants. Let me know what do you think 🙂

jzabala avatar Jun 20 '20 20:06 jzabala

Thanks! I'm unfortunately not home until Friday, so I'll only be able to merge it then.

RonMelkhior avatar Jun 20 '20 20:06 RonMelkhior

Thanks! I'm unfortunately not home until Friday, so I'll only be able to merge it then.

Sure, when you have time. Thanks @RonMelkhior

jzabala avatar Jun 20 '20 23:06 jzabala