Skip to content

Commit a0164db

Browse files
committed
first commit
0 parents  commit a0164db

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vscode

README.md

Whitespace-only changes.

index.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module.exports = function ({ addUtilities, theme }) {
2+
const breakpoints = theme('screens');
3+
const userColors = theme('backgroundColorsByBreakpoint', {});
4+
const allColors = theme('colors');
5+
6+
// Function to resolve Tailwind color classes to actual color codes
7+
// Without this, only rgb values would have to be used instead of
8+
// tailwind colors like 'red-500' or 'gray-100', etc
9+
const resolveColor = (colorName) => {
10+
const [color, shade] = colorName.split('-');
11+
return allColors[color] && allColors[color][shade]
12+
? allColors[color][shade]
13+
: colorName;
14+
};
15+
16+
const defaultColors = {
17+
DEFAULT: 'black',
18+
sm: '#a3e635',
19+
md: '#f59e0b',
20+
lg: '#ea580c',
21+
xl: '#991b1b',
22+
'2xl': '#881337',
23+
};
24+
25+
// Merge user-defined colors with defaults, in order to override
26+
// default colors with user-defined colors.
27+
const finalColors = { ...defaultColors, ...userColors };
28+
29+
let newUtilities = {
30+
'.bg-breakpoint': {
31+
backgroundColor: finalColors.DEFAULT,
32+
},
33+
};
34+
35+
Object.entries(breakpoints).forEach(([breakpoint]) => {
36+
if (finalColors[breakpoint]) {
37+
const colorCode = resolveColor(finalColors[breakpoint]);
38+
if (!newUtilities[`@screen ${breakpoint}`]) {
39+
newUtilities[`@screen ${breakpoint}`] = {};
40+
}
41+
newUtilities[`@screen ${breakpoint}`]['.bg-breakpoint'] = {
42+
backgroundColor: colorCode,
43+
};
44+
}
45+
});
46+
47+
addUtilities(newUtilities, ['responsive']);
48+
};

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "tailwindcss-bg-breakpoint",
3+
"version": "1.0.0",
4+
"description": "A customizable Tailwind CSS plugin that responsively changes the background color based on screen size.",
5+
"main": "index.js",
6+
"author": "tuffstuff9",
7+
"license": "MIT",
8+
"repository": {
9+
"type": "git",
10+
"url": ""
11+
},
12+
"homepage": "",
13+
"bugs": "",
14+
"peerDependencies": {
15+
"tailwindcss": "^1.0 || ^2.0 || ^3.0"
16+
}
17+
}

0 commit comments

Comments
 (0)