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
// removes the box-sizing: border-box whenever it's found
100
102
property ==='box-sizing'&& value ==='border-box',
101
103
// removes the font-family (except inherit) from all the rules
102
104
property ==='font-family'&& value !=='inherit',
103
-
].some(Boolean), // yep, "some" approach is a bit slower because it will evaluate all array conditions anyway, but it's more readable without || operators
105
+
].some(Boolean),
106
+
// preferred way to modify the preflight styles
107
+
modifyPreflightStyles: ({ selectorSet, property, value }) => {
108
+
// let's say you want to override the font family
109
+
if (property ==='font-family'&& value !=='inherit') {
110
+
return'"Open Sans", sans-serif';
111
+
}
112
+
// or body margin
113
+
if (selectorSet.has('body') && property ==='margin') {
114
+
return'0 4px';
115
+
}
116
+
// if you want to remove some property - return null
117
+
if (selectorSet.has('html') && property ==='line-height') {
118
+
returnnull;
119
+
}
120
+
// to keep the property as it is - you may return the original value;
121
+
// but returning undefined would have the same effect,
122
+
// so you may just omit such default return
123
+
return value;
124
+
},
104
125
}),
105
126
],
106
127
};
@@ -199,16 +220,13 @@ const config = {
199
220
?`${ruleSelector} .twp`// some custom transformation for html, :host and body
200
221
:isolateForComponents('.twp')(ruleSelector), // otherwise, transform it as per components strategy (just for example)
201
222
202
-
// just for demo purpose - let's also filter out some properties
203
-
propsFilter: ({ selectorSet, property, value }) =>
// removes the box-sizing: border-box whenever it's found
208
-
property ==='box-sizing'&& value ==='border-box',
209
-
// removes the font-family (except inherit) from all the rules
210
-
property ==='font-family'&& value !=='inherit',
211
-
].some(Boolean), // yep, "some" approach is a bit slower because it will evaluate all array conditions anyway, but it's more readable without || operators
223
+
// just for demo purpose
224
+
modifyPreflightStyles: ({ selectorSet, property, value }) => {
225
+
// let's say you want to override the font family
226
+
if (property ==='font-family'&& value !=='inherit') {
Copy file name to clipboardExpand all lines: demo/tailwind.config.js
+23-2
Original file line number
Diff line number
Diff line change
@@ -23,16 +23,37 @@ module.exports = {
23
23
// ? ruleSelector // keeps the original selector
24
24
// : enableForSelector(".twp")(ruleSelector), // otherwise, transforms selector as per selected behaviour (scoped to .twp)
25
25
26
-
// it's also possible to filter out some properties - return false to remove the property. Any other value (including true and undefined) will leave the prop intact
26
+
// it's also possible to filter out some properties
27
+
// (deprecated - prefer using modifyPreflightStyles instead of propFilter)
27
28
propsFilter: ({ selectorSet, property, value })=>
29
+
// return false to remove the property. Any other value (including true and undefined) will leave the prop intact
// removes the box-sizing: border-box whenever it's found
32
34
property==='box-sizing'&&value==='border-box',
33
35
// removes the font-family (except inherit) from all the rules
34
36
property==='font-family'&&value!=='inherit',
35
-
].some(Boolean),// yep, "some" approach is a bit slower because it will evaluate all array conditions anyway, but it's more readable without || operators
37
+
].some(Boolean),
38
+
// preferred way to modify the preflight styles
39
+
modifyPreflightStyles: ({ selectorSet, property, value })=>{
40
+
// let's say you want to override the font family
41
+
if(property==='font-family'&&value!=='inherit'){
42
+
return'"Open Sans", sans-serif';
43
+
}
44
+
// or body margin
45
+
if(selectorSet.has('body')&&property==='margin'){
46
+
return'0 4px';
47
+
}
48
+
// if you want to remove some property - return null
* {@link https://www.npmjs.com/package/tailwindcss-scoped-preflight#update-your-tailwind-css-configuration isolateForComponents} or write {@link https://www.npmjs.com/package/tailwindcss-scoped-preflight#your-owncustom-isolation-strategy your own}
27
+
* @deprecated prefer using modifyPreflightStyles
25
28
* @param propsFilter - function to filter the preflight CSS properties and values, return false to remove the property. Any other value (including true and undefined) will leave the prop intact
29
+
* @param modifyPreflightStyles - function to modify the preflight CSS properties and their values, return null to remove the property. Any other returned value will be used as a new value for the property. If you don't want to change it - return the old value (provided in argument object as `value`).
0 commit comments