Skip to content

Commit d76e5cc

Browse files
committed
Update the plugin to work with @Property
1 parent a56fd8a commit d76e5cc

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

src/app/globals.css

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
@tailwind base;
22
@tailwind components;
33
@tailwind utilities;
4+
5+
@property --tw-gradient-from-color {
6+
syntax: "<color>";
7+
inherits: false;
8+
initial-value: red;
9+
}
10+
11+
@property --tw-gradient-to-color {
12+
syntax: "<color>";
13+
inherits: false;
14+
initial-value: red;
15+
}

src/app/page.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default function Home() {
77
<div>
88
<h2 className="text-xl font-medium">Gradient on hover button</h2>
99

10-
<button className="mt-4 rounded-lg bg-gray-900 px-6 py-2 text-white hover:bg-gradient-to-t hover:from-gray-900 hover:to-gray-600">
10+
<button className="mt-4 rounded-lg bg-gray-900 px-6 py-2 text-white hover:bg-gradient-to-t hover:from-gray-900 hover:to-gray-500">
1111
Button
1212
</button>
1313
</div>
@@ -30,6 +30,16 @@ export default function Home() {
3030
</button>
3131
</div>
3232
</div>
33+
34+
<div className="mt-16 flex gap-x-16">
35+
<div>
36+
<h2 className="text-xl font-medium">Animated using @property</h2>
37+
38+
<button className="transition-gradient mt-4 rounded-lg bg-gradient-to-t px-6 py-2 text-white duration-500 ease-out from-gray-900 to-gray-900 hover:to-gray-500">
39+
Button
40+
</button>
41+
</div>
42+
</div>
3343
</main>
3444
);
3545
}

tailwind.config.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ const config: Config = {
66
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
77
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
88
],
9-
theme: {},
9+
theme: {
10+
extend: {
11+
transitionProperty: {
12+
gradient: "--tw-gradient-from-color, --tw-gradient-to-color",
13+
},
14+
},
15+
},
1016
corePlugins: {
1117
gradientColorStops: false,
1218
},

tailwind/gradient.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ module.exports = plugin(
3636

3737
return {
3838
"@defaults gradient-color-stops": {},
39-
"--tw-gradient-from": `${toColorValue(
40-
value,
41-
)} var(--tw-gradient-from-position)`,
42-
"--tw-gradient-to": `${transparentToValue} var(--tw-gradient-to-position)`,
39+
"--tw-gradient-from-color": toColorValue(value),
40+
"--tw-gradient-from":
41+
"var(--tw-gradient-from-color) var(--tw-gradient-from-position)",
42+
"--tw-gradient-to-color": transparentToValue,
43+
"--tw-gradient-to":
44+
"var(--tw-gradient-to-color) var(--tw-gradient-to-position)",
4345
"--tw-gradient-stops": `var(--tw-gradient-from), var(--tw-gradient-to)`,
4446
};
4547
},
@@ -65,7 +67,9 @@ module.exports = plugin(
6567

6668
return {
6769
"@defaults gradient-color-stops": {},
68-
"--tw-gradient-to": `${transparentToValue} var(--tw-gradient-to-position)`,
70+
"--tw-gradient-to-color": transparentToValue,
71+
"--tw-gradient-to":
72+
"var(--tw-gradient-to-color) var(--tw-gradient-to-position)",
6973
"--tw-gradient-stops": `var(--tw-gradient-from), ${toColorValue(
7074
value,
7175
)} var(--tw-gradient-via-position), var(--tw-gradient-to)`,
@@ -90,9 +94,9 @@ module.exports = plugin(
9094
{
9195
to: (value) => ({
9296
"@defaults gradient-color-stops": {},
93-
"--tw-gradient-to": `${toColorValue(
94-
value,
95-
)} var(--tw-gradient-to-position)`,
97+
"--tw-gradient-to-color": toColorValue(value),
98+
"--tw-gradient-to":
99+
"var(--tw-gradient-to-color) var(--tw-gradient-to-position)",
96100
}),
97101
},
98102
options,

0 commit comments

Comments
 (0)