You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generate both global styles and classes by default (tailwindlabs#71)
* feat(option): allow both strategies
* feat: base and class by default
* Refactor
* Update changelog
* Rework readme
Co-authored-by: Jordan Pittman <[email protected]>
Co-authored-by: Jonathan Reinink <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+22-15
Original file line number
Diff line number
Diff line change
@@ -67,22 +67,9 @@ Every element has been normalized/reset to a simple visually consistent style th
67
67
68
68
More customization examples and best practices coming soon.
69
69
70
-
### Using classes instead of element selectors
70
+
### Using classes to style
71
71
72
-
Although we recommend thinking of this plugin as a "form reset" rather than a collection of form component styles, in some cases our default approach may be too heavy-handed, especially when integrating this plugin into existing projects.
73
-
74
-
For situations where the default strategy doesn't work well with your project, you can use the `class` strategy to make all form styling _opt-in_ instead of applied globally:
75
-
76
-
```js
77
-
// tailwind.config.js
78
-
plugins: [
79
-
require("@tailwindcss/forms")({
80
-
strategy:'class',
81
-
}),
82
-
],
83
-
```
84
-
85
-
When using the `class` strategy, form elements do not receive any reset styles by default, and reset styles are added per element using a new set of `form-*` classes generated by the plugin:
72
+
In addition to the global styles, we also generate a set of corresponding classes which can be used to explicitly apply the form styles to an element. This can be useful in situations where you need to make a non-form element, such as a `<div>`, look like a form element.
@@ -115,3 +102,23 @@ Here is a complete table of the provided `form-*` classes for reference:
115
102
|`select[multiple]`|`form-multiselect`|
116
103
|`[type='checkbox']`|`form-checkbox`|
117
104
|`[type='radio']`|`form-radio`|
105
+
106
+
### Using only global styles or only classes
107
+
108
+
Although we recommend thinking of this plugin as a "form reset" rather than a collection of form component styles, in some cases our default approach may be too heavy-handed, especially when integrating this plugin into existing projects.
109
+
110
+
If generating both the global (base) styles and classes doesn't work well with your project, you can use the `strategy` option to limit the plugin to just one of these approaches.
111
+
112
+
```js
113
+
// tailwind.config.js
114
+
plugins: [
115
+
require("@tailwindcss/forms")({
116
+
strategy:'base', // only generate global styles
117
+
strategy:'class', // only generate classes
118
+
}),
119
+
],
120
+
```
121
+
122
+
When using the `base` strategy, form elements are styled globally, and no `form-{name}` classes are generated.
123
+
124
+
When using the `class` strategy, form elements are not styled globally, and instead must be styled using the generated `form-{name}` classes.
0 commit comments