Manifest
Instead of using the CSS variable system from the standard Frontend libs, Frontend libs Tailwind includes a system that helps you avoid writing Tailwind classes twice, and allows reusing them between the Block editor and the frontend view.
All the magic happens within the component/block manifests, within the tailwind
key.
Your code editor will help you configure all the manifest options.
The Tailwind manifest configuration consists of a couple of main parts:
base
classesparts
options
-based classescombinations
Base part
These classes should be applied to the main part of your block/component. This does not necessarily mean the top-most element of your component, though.
...
"tailwind": {
"base": {
"twClasses": "font-sans [&>a]:underline"
}
},
...
Editor-only
If needed, you can also separately specify classes that will be applied in the editor.
These will override all the twClasses
.
...
"tailwind": {
"base": {
"twClasses": "absolute top-0 inset-x-0 flex flex-col gap-4",
"twClassesEditor": "flex flex-col gap-4"
}
},
...
Options-based classes
This part of the config allows outputting different classes, based on attributes set in the block/component.
...
"tailwind": {
"options": {
"paragraphSize": {
"twClasses": {
"sm": "text-sm",
"base": "~sm/md:~text-sm/base",
"md": "~sm/md:~text-lg/2xl",
"lg": "~sm/md:~text-xl/3xl"
}
},
"paragraphFontWeight": {
"twClasses": {
"700": "font-bold"
}
}
}
},
...
Editor-only
If needed, you can also separately specify classes that will be applied in the editor.
These will override all the twClasses
.
...
"tailwind": {
"options": {
"columnHide": {
"twClasses": {
"true": "hidden"
},
"twClassesEditor": {
"true": "opacity-50"
}
}
}
},
...
Responsive attributes
If you need an attribute that is allowed to be changed per-breakpoint, do this:
-
When defining an attribute, make it an object and add the default keys
...
"tailwind": {
"attributes": {
"demoSpacing": {
"type": "object",
"default": {
"_default": "base",
"_desktopFirst": false
},
},
}
},
...(change
_default
value and_desktopFirst
as desired) -
Mark the option class as responsive
...
"tailwind": {
"options": {
"demoSpacing": {
"twClasses": {
"sm": "p-4",
"base": "p-8",
"md": "p-12",
"lg": "p-20"
},
"responsive": true
},
}
},
... -
Add the appropriate option component in the admin (use it within the
Responsive
component)
Parts
By default, the options classes are added to the base class. If you want a certain attribute's classes to be added to a part,
specify the part name with the part
property.
...
"tailwind": {
"options": {
"demoSpacing": {
"twClasses": {
"sm": "p-4",
"base": "p-8",
"md": "p-12",
"lg": "p-20"
},
"part": "myPartName"
},
}
},
...