This repository was archived by the owner on Sep 11, 2021. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The old customization API tried to be as minimal as possible but in my own experience dogfooding it it fell apart extremely quickly.
This PR replaces that customization API with a new one that is basically just CSS, and as a result has no limits on flexibility.
Here's how it works, taken from the updated docs:
Customizing the default styles
You can customize the default styles applied by this plugin in the
theme.customForms.default
section of your
tailwind.config.js
file.Each form element can be customized under the
input
,textarea
,select
,multiselect
,checkbox
, andradio
keys respectively.The configuration format is the same CSS-in-JS syntax used to author Tailwind plugins, so you are free to customize or add any CSS properties you like.
See the default options used by the plugin for a complete reference of styles that are applied
out of the box.
Customizing the select, checkbox, and radio icons
Providing a carefully encoded SVG data URI to the
backgroundImage
property can be a bit cumbersome, so to make icon customization easier this plugin allows you to provide a normal unencoded SVG using a specialicon
property instead:You can also switch to a different icon for different states, like if you wanted to change the checkmark on hover:
Checkbox and radio icons are automatically hidden unless the elements are
:checked
, so you don't need to include that pseudo-selector in your configuration when using the specialicon
property.Customizing the icon color
If you are happy with the default icons and just want to customize the color, you can use the special
iconColor
property to customize the color without re-specifying the entire SVG:You can also change the
iconColor
for different states:Just like with the
icon
property, you don't need to worry about including the:checked
pseudo-selector for checkboxes and radios.If you are using a custom icon and still want to use the
iconColor
property to make it easy to change the color without re-specifying your entire custom SVG, define your custom icon as a callback that receives the icon color:Disabling a default style
Although we've tried to make the default styles as neutral as possible while still looking well-designed, sometimes one of the styles we're providing out-of-the-box might be too opinionated for your project and painful to simply override.
If you'd like to completely unset one of the default styles, explicitly set that property to
undefined
to prevent the plugin from including that property in the final CSS:Configuring multiple elements at once
Often you'll want to set the same defaults for several different elements, and duplicating all of those styles can be a little verbose.
To specify styles for multiple elements at the same time, simply provide all of the elements you'd like to style as a comma-separated list:
Adding modifier classes
You'll often need multiple form element styles in a single project, for example light form controls that are meant for light backgrounds, and dark form controls for dark backgrounds.
This plugin lets you create "modifiers" for your form classes by adding extra top-level keys in the
theme.customForms
section of your config file.For example, this configuration adds a
dark
modifier:This generates extra classes like
form-input-dark
,form-textarea-dark
,form-select-dark
, etc.It's important to note that modifiers are not automatically merged with the default styles and
are designed to be used with the multi-class modifier pattern.
That means you should always include the default class for an element when using a modifier:
This makes it easy to create modifiers that serve different purposes that can still be composed.
For example, here we're configuring a
dark
color modifier, and asm
size modifier:By using the multi-class pattern, we can combine these modifiers in our HTML to produce form
elements that are both dark and small, without creating any new classes: