Skip to content

Commit 362e208

Browse files
Move classes from utilities to components layer
1 parent 439d9f4 commit 362e208

File tree

3 files changed

+9
-109
lines changed

3 files changed

+9
-109
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Centering an element using Tailwindcss classes can rapidly become verbose.
77

88
## The solution 🚀
9-
Dedicated centering classes that cover the most common situations.
9+
Dedicated centering classes at component layer that cover the most common situations.
1010

1111
## Install the plugin from npm:
1212

index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const plugin = require('tailwindcss/plugin');
22

33
module.exports = plugin(
4-
function ({ addUtilities, theme, variants }) {
4+
function ({ addComponents, theme }) {
55
// If your plugin requires user config,
66
// you can access these options here.
77
// Docs: https://tailwindcss.com/docs/plugins#exposing-options
88
const options = theme('quickCenter');
99

1010
// Add CSS-in-JS syntax to create utility classes.
1111
// Docs: https://tailwindcss.com/docs/plugins#adding-utilities
12-
const utilities = {
12+
const components = {
1313
'.center-absolute-y': {
1414
position: 'absolute',
1515
top: '50%',
@@ -46,14 +46,12 @@ module.exports = plugin(
4646

4747
// Conditionally add utility class based on user configuration.
4848
if (options.YOUR_PLUGIN_CUSTOM_OPTION) {
49-
utilities['.custom-utility-class'] = {
49+
components['.custom-utility-class'] = {
5050
'background-color': 'red',
5151
};
5252
}
5353

54-
addUtilities(utilities, {
55-
variants: variants('quickCenter'),
56-
});
54+
addComponents(components);
5755
},
5856
{
5957
theme: {

test.js

Lines changed: 4 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const merge = require('lodash/merge');
22
const cssMatcher = require('jest-matcher-css');
33
const postcss = require('postcss');
44
const tailwindcss = require('tailwindcss');
5-
const customPlugin = require('./index.js');
5+
const customPlugin = require('./index');
66

77
expect.extend({
88
toMatchCss: cssMatcher,
@@ -25,13 +25,13 @@ function generatePluginCss(overrides) {
2525
};
2626

2727
return postcss(tailwindcss(merge(config, overrides)))
28-
.process('@tailwind utilities', {
28+
.process('@tailwind components', {
2929
from: undefined,
3030
})
3131
.then(({ css }) => css);
3232
}
3333

34-
test('utility classes can be generated', () => {
34+
test('component classes can be generated', () => {
3535
return generatePluginCss().then(css => {
3636
expect(css).toMatchCss(`
3737
.center-absolute-y {
@@ -78,7 +78,7 @@ test('variants can be customized', () => {
7878
},
7979
},
8080
variants: {
81-
quickCenter: ['responsive', 'hover'],
81+
quickCenter: ['hover'],
8282
},
8383
}).then(css => {
8484
expect(css).toMatchCss(`
@@ -114,104 +114,6 @@ test('variants can be customized', () => {
114114
align-items: center;
115115
justify-content: center;
116116
}
117-
.hover\\:center-absolute-y:hover {
118-
position: absolute;
119-
top: 50%;
120-
transform: translateY(-50%);
121-
}
122-
.hover\\:center-absolute-x:hover {
123-
position: absolute;
124-
left: 50%;
125-
transform: translateX(-50%);
126-
}
127-
.hover\\:center-absolute:hover {
128-
position: absolute;
129-
left: 50%;
130-
top: 50%;
131-
transform: translate(-50%, -50%);
132-
}
133-
.hover\\:center-flex-y:hover {
134-
display: flex;
135-
flex-direction: column;
136-
justify-content: center;
137-
}
138-
.hover\\:center-flex-x:hover {
139-
display: flex;
140-
flex-direction: column;
141-
align-items: center;
142-
}
143-
.hover\\:center-flex:hover {
144-
display: flex;
145-
flex-direction: column;
146-
align-items: center;
147-
justify-content: center;
148-
}
149-
@media (min-width: 640px) {
150-
.sm\\:center-absolute-y {
151-
position: absolute;
152-
top: 50%;
153-
transform: translateY(-50%);
154-
}
155-
.sm\\:center-absolute-x {
156-
position: absolute;
157-
left: 50%;
158-
transform: translateX(-50%);
159-
}
160-
.sm\\:center-absolute {
161-
position: absolute;
162-
left: 50%;
163-
top: 50%;
164-
transform: translate(-50%, -50%);
165-
}
166-
.sm\\:center-flex-y {
167-
display: flex;
168-
flex-direction: column;
169-
justify-content: center;
170-
}
171-
.sm\\:center-flex-x {
172-
display: flex;
173-
flex-direction: column;
174-
align-items: center;
175-
}
176-
.sm\\:center-flex {
177-
display: flex;
178-
flex-direction: column;
179-
align-items: center;
180-
justify-content: center;
181-
}
182-
.sm\\:hover\\:center-absolute-y:hover {
183-
position: absolute;
184-
top: 50%;
185-
transform: translateY(-50%);
186-
}
187-
.sm\\:hover\\:center-absolute-x:hover {
188-
position: absolute;
189-
left: 50%;
190-
transform: translateX(-50%);
191-
}
192-
.sm\\:hover\\:center-absolute:hover {
193-
position: absolute;
194-
left: 50%;
195-
top: 50%;
196-
transform: translate(-50%, -50%);
197-
}
198-
.sm\\:hover\\:center-flex-y:hover {
199-
display: flex;
200-
flex-direction: column;
201-
justify-content: center;
202-
}
203-
.sm\\:hover\\:center-flex-x:hover {
204-
display: flex;
205-
flex-direction: column;
206-
align-items: center;
207-
}
208-
.sm\\:hover\\:center-flex:hover {
209-
display: flex;
210-
flex-direction: column;
211-
align-items: center;
212-
justify-content: center;
213-
}
214-
}
215117
`);
216118
});
217119
});

0 commit comments

Comments
 (0)