-
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Tailwindcss Plugins #32
Comments
I was about to ask how to use tailwindcss plugins like the ones in tailwindUI (@tailwindcss/forms) , then i saw this. I will await the outcome of this, as i wanted to try using tailwind-UI with twind |
Awesome tool, support for Tailwind UI would be great ❤️ |
We hope that we can achieve that. |
Eager to use tailwindcss/forms! |
@thelinuxlich @joshua1 You could try https://github.com/tw-in-js/twind-forms |
After thinking about this and porting tailwindlabs some plugins (@twind/forms, @twind/aspect-ratio and @twind/line-clamp) I'm leaning towards a new module which would create a twind configuration from a tailwind config: import { setup } from 'twind'
import { compat } from 'twind/compat'
setup(
compat({
// Tailwind config
plugins: [
// List of tailwind plugins
]
})
) Or even: import { setup } from 'twind/compat'
setup({
// Tailwind config
plugins: [
// List of tailwind plugins
]
}) |
I love the concept! I hope that you consider exposing the mapper. |
Hello, how would you adapt https://github.com/stormwarning/tailwindcss-capsize ? |
Twind's primary developer mentioned a code refactoring in this comment (to align the typography plugin with others, and to hook into the autocompletion VSCode / Typescript extension): tw-in-js/typography#2 (comment) So I guess the developer uses some sort of template / scaffolding for creating such plugins. It would be great if a "create" Yarn / NPM utility was available to easily kick-start Twind plugins based on Tailwind ones :) |
All plugins are written the same in principle. Whether they are core, supplementary or custom. Furthermore they are all just functions that get called when certain keywords are picked up by the compiler. See here for docs: https://twind.dev/docs/handbook/advanced/plugins.html#plugins-without-arguments With regards capsize, the principle is the same, so something like: import { setup } from 'twind'
setup({
plugins: {
'capsize': ([font, size, lineHeight]) => {
return computeCapsize(font, size, lineHeight);
},
},
}) Where |
Any updates on the compat API? If not, what's the manual process of converting a tailwindcss plugin into a twind plugin? I'm new to tailwindcss and twind, but might be able to help with implementing a compatibility layer depending on the size and scope of such a project. If I'm unable, that information might inspire someone else to take on this feature. Edit: I'm going to just switch to using the latest next release, it has a preset for the tailwindcss forms plugin that should meet my needs. |
Honestly I do not believe it will happen any time soon. For now I try to provide the most common tailwind plugins as presets. |
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. ⓘ |
#490 was opened so this should probably be reopened. I have an interest in seeing this supported for https://jsx.email |
Tailwindcss Plugin Documentation
Benefits
Supporting plain tailwindcss plugins would allow users to re-use existing plugins and prevent introducing a new plugin API.
Plugin API
addUtilities()
, for registering new utility stylesWe can convert the CSS-in-JS object using
twind/css
. For each top-level key extract the plugin name and register it's definiton as a twind plugin.addUtilities()
accepts several options. We should discuss if support for these is required for an initial release.To be fully compatible we should support prefix and important configuration settings.
addComponents()
, for registering new component stylesWorks just like
addUtilities()
but adds the generated classes into the component layer. We could increase the presedence for these to simulate a component layer.addBase()
, for registering new base stylesThis should add the generated classes to the preflight. They should not be hashed or prefixed.
addVariant()
, for registering custom variantsAllows you to register your own custom variants that can be used just like the built-in hover, focus, active, etc. variants.
e()
, for escaping strings meant to be used in class namesAlready implemented in
util.ts
asescape
.prefix()
, for manually applying the user's configured prefix to parts of a selectorThe prefix function will prefix all classes in a selector and ignore non-classes, so it's totally safe to pass complex selectors like this one
theme()
, for looking up values in the user's theme configurationAllow to access the theme. Already implemented within the theme resolver.
variants()
, for looking up values in the user's variants configurationThis may be no-op as twind supports all variants for every directive.
config()
, for looking up values in the user's Tailwind configurationProvides access to the default configuration.
postcss
, for doing low-level manipulation with PostCSS directlyThis may never be available as twind is not using postcss. On accessing the property an error should be thrown.
Registering Plugins
setup
must support an array of functions:Challenges
Plugins depend on 'tailwindcss/plugin'
This could be solved setting up the bundler to alias
tailwindcss/plugin
totwind/plugin
. Preact has a good guide how to do that.Most plugins are written in CJS
Importing plugins may work in bundler environment. But if used directly in the browser this may not work.
Many plugins use lodash (bundle size)
This is not really a challenge but points more to how using plugins could increase the bundle size.
The text was updated successfully, but these errors were encountered: