Skip to content

Commit 470d27e

Browse files
committed
feat: initial commit
0 parents  commit 470d27e

File tree

7 files changed

+11919
-0
lines changed

7 files changed

+11919
-0
lines changed

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.npmrc
7+
.pnp.js
8+
9+
# testing
10+
/coverage
11+
12+
# production
13+
/build
14+
/dist
15+
16+
# misc
17+
.DS_Store
18+
*.pem
19+
20+
# debug
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
# local env files
26+
.env
27+
.env.**
28+
29+
# vercel
30+
.vercel
31+
32+
# typescript
33+
*.tsbuildinfo
34+
.env*.local

.npmignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
src/
2+
lib/
3+
dist/
4+
!package-lock.json
5+
.github/
6+
.idea/
7+
.editorconfig
8+
.eslintrc
9+
.gitignore
10+
.prettierrc.json
11+
jest.config.js
12+
tsconfig.json
13+
vite.config.js
14+
release.config.js
15+
**/*.mdj

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
### What
2+
3+
TailwindCSS plugin
4+
5+
### Why
6+
7+
To avoid style conflicts (CSS collisions/interference side effects) when using Tailwind CSS with other UI libraries like Antd, Vuetify etc.
8+
9+
### How
10+
11+
This plugin is limiting the scope of [Tailwind's opinionated preflight styles](https://tailwindcss.com/docs/preflight) to the customizable CSS selector.
12+
So you can control where exactly in DOM to apply these base styles - usually it's your own components (not the 3rd party).
13+
14+
## Installation
15+
16+
```bash
17+
npm i tailwindcss-scoped-preflight
18+
```
19+
20+
## Usage
21+
22+
#### Update your TailwindCSS configuration
23+
24+
```javascript
25+
// # tailwind.config.js
26+
27+
const { scopedPreflightStyles } = require('tailwindcss-scoped-preflight');
28+
29+
/** @type {import("tailwindcss").Config} */
30+
const config = {
31+
// ... your TailwindCSS config
32+
corePlugins: {
33+
preflight: false, // or use the disableCorePreflight option below
34+
},
35+
plugins: [
36+
// ... other plugins
37+
scopedPreflightStyles({
38+
preflightSelector: '.twp', // or .tailwind-preflight or even [data-twp=true] - any valid CSS selector of your choice
39+
disableCorePreflight: true, // or disable it with corePlugins option as shown above
40+
}),
41+
],
42+
};
43+
44+
exports.default = config;
45+
```
46+
47+
> Please note that long preflightSelector will generate more CSS boilerplate - so it's recommended to keep it short
48+
49+
#### Apply the styles wherever you want them to be
50+
51+
* To isolate the opinionated styles within the component
52+
53+
```tsx
54+
// # MyTailwindButton.tsx
55+
56+
import { type PropsWithChildren } from 'react';
57+
58+
export function MyTailwindButton({ children }: PropsWithChildren): ReactElement {
59+
return (
60+
<button className={'twp'}> // this button will have no default border and background because of TailwindCSS
61+
preflight styles
62+
{children}
63+
</button>
64+
);
65+
}
66+
```
67+
68+
* Or make a wrapper to style all its children
69+
70+
```tsx
71+
// # TailwindPreflightStyles
72+
73+
import { type PropsWithChildren } from 'react';
74+
75+
export function TailwindPreflightStyles({ children }: PropsWithChildren): ReactElement {
76+
return (
77+
<div className={'twp'}> // all the children will have default TailwindCSS styles applied, but not components outside of this wrapper
78+
{ children }
79+
</div>
80+
);
81+
}
82+
```

0 commit comments

Comments
 (0)