Skip to content

Commit 6b0441e

Browse files
committed
Refactor codebase + Add tests
1 parent b5fad77 commit 6b0441e

File tree

4 files changed

+3848
-22
lines changed

4 files changed

+3848
-22
lines changed

index.js

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
1-
module.exports = function (variants) {
2-
return function ({ addUtilities }) {
3-
addUtilities(
4-
{
5-
// Background
6-
// Background Image
1+
var _ = require('lodash')
2+
var flatten = require('flat')
73

8-
// Background Clip
9-
'.bg-clip-border': { backgroundClip: 'border-box' },
10-
'.bg-clip-padding': { backgroundClip: 'padding-box' },
11-
'.bg-clip-content': { backgroundClip: 'content-box' },
12-
'.bg-clip-text': { backgroundClip: 'text' },
4+
module.exports = function () {
5+
return function ({
6+
addUtilities, addComponents, addBase, addVariant,
7+
e, prefix, theme, variants, config,
8+
}) {
9+
const pluginUtilities = {
10+
// '.bg': {},
11+
// '.bg-image': {},
1312

14-
// Background Origin
15-
'.bg-origin-border': { backgroundOrigin: 'border-box' },
16-
'.bg-origin-padding': { backgroundOrigin: 'padding-box' },
17-
'.bg-origin-content': { backgroundOrigin: 'content-box' },
18-
},
19-
variants
20-
)
13+
clip: {
14+
border: { backgroundClip: 'border-box' },
15+
padding: { backgroundClip: 'padding-box' },
16+
content: { backgroundClip: 'content-box' },
17+
text: { backgroundClip: 'text' },
18+
},
19+
origin: {
20+
border: { backgroundOrigin: 'border-box' },
21+
padding: { backgroundOrigin: 'padding-box' },
22+
content: { backgroundOrigin: 'content-box' },
23+
},
24+
}
25+
26+
Object.entries(pluginUtilities).forEach(([ modifier, values ]) => {
27+
const variantName = _.camelCase(`background-${modifier}`)
28+
const utilities = flatten(
29+
{ [`.${e(`bg-${modifier}`)}`]: values },
30+
{ delimiter: '-', maxDepth: 2 },
31+
)
32+
33+
addUtilities(utilities, variants(variantName, ['responsive']))
34+
})
2135
}
2236
}

package.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "tailwindcss-background-extended",
33
"version": "0.1.0",
4+
"scripts": {
5+
"test": "jest"
6+
},
47
"description": "This plugin adds all of the missing background utilities to Tailwind CSS.",
58
"license": "MIT",
69
"main": "index.js",
@@ -16,12 +19,22 @@
1619
"plugin"
1720
],
1821
"author": {
19-
"name" : "Nestor Vera",
20-
"email" : "nestorvera@me.com",
21-
"url" : "https://nestor.rip/"
22+
"name": "Nestor Vera",
23+
"email": "nestorvera@me.com",
24+
"url": "https://nestor.rip/"
2225
},
2326
"bugs": {
2427
"url": "https://github.com/hacknug/tailwindcss-background-extended/issues"
2528
},
26-
"homepage": "https://github.com/hacknug/tailwindcss-background-extended#readme"
29+
"homepage": "https://github.com/hacknug/tailwindcss-background-extended#readme",
30+
"devDependencies": {
31+
"jest": "^24.8.0",
32+
"jest-matcher-css": "^1.0.3",
33+
"postcss": "^7.0.16",
34+
"tailwindcss": "^1.0.1"
35+
},
36+
"dependencies": {
37+
"flat": "^4.1.0",
38+
"lodash": "^4.17.11"
39+
}
2740
}

0 commit comments

Comments
 (0)