Skip to content

Commit d924fd8

Browse files
committed
βž• Add: Gradient Border snippet
1 parent 0fe93b9 commit d924fd8

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: "Gradient Border"
3+
description: "Add gradient to border"
4+
logo: "react.png"
5+
---
6+
7+
```js
8+
import React from "react";
9+
// add classNames conditionally
10+
import cx from "clsx";
11+
12+
const colors = [
13+
"from-yellow-400 via-red-500 to-pink-500",
14+
"from-purple-400 via-pink-500 to-red-500",
15+
"from-yellow-100 via-yellow-300 to-yellow-500",
16+
"from-green-400 to-blue-500",
17+
"from-green-500 to-green-700",
18+
"from-gray-500 via-gray-100 to-gray-500",
19+
];
20+
21+
export const GradientBorder = () => {
22+
const [colorIndex, setColorIndex] = React.useState(0);
23+
24+
const gradientColor = colors[colorIndex];
25+
26+
return (
27+
<div>
28+
<div
29+
className={cx(
30+
"flex justify-center w-56 p-1 rounded-md h-14 bg-gradient-to-r ",
31+
gradientColor
32+
)}
33+
role="button"
34+
>
35+
<div className="flex items-center justify-center flex-grow text-white bg-black rounded">
36+
<p>Gradient Border</p>
37+
</div>
38+
</div>
39+
<div className="flex mt-10 space-x-4 rounded">
40+
{colors.map((color, index) => {
41+
return (
42+
<div
43+
key={index}
44+
className={cx(
45+
"h-6 w-6 rounded cursor-pointer transform ring-1 ring-offset-2 ring-white ring-offset-black bg-gradient-to-r ",
46+
color,
47+
{
48+
"ring-opacity-100": colorIndex === index,
49+
"ring-opacity-0 hover:ring-opacity-50": colorIndex !== index,
50+
}
51+
)}
52+
onClick={() => setColorIndex(index)}
53+
></div>
54+
);
55+
})}
56+
</div>
57+
</div>
58+
);
59+
};
60+
```
61+
62+
[Live Demo](http://manuarora.in/demos/demo/borderGradient)
63+
[Source Code](https://github.com/manuarora700/portfolio-website/tree/master/pages/demos/demo/borderGradient)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from "react";
2+
import cx from "clsx";
3+
4+
const colors = [
5+
"from-yellow-400 via-red-500 to-pink-500",
6+
"from-purple-400 via-pink-500 to-red-500",
7+
"from-yellow-100 via-yellow-300 to-yellow-500",
8+
"from-green-400 to-blue-500",
9+
"from-green-500 to-green-700",
10+
"from-gray-500 via-gray-100 to-gray-500",
11+
];
12+
13+
export default function GradientBorder() {
14+
const [colorIndex, setColorIndex] = React.useState(0);
15+
16+
const gradientColor = colors[colorIndex];
17+
18+
return (
19+
<div className="flex flex-col justify-center items-center bg-black h-screen transition duration-500">
20+
<div
21+
className={cx(
22+
"flex justify-center w-56 p-1 rounded-md h-14 bg-gradient-to-r ",
23+
gradientColor
24+
)}
25+
role="button"
26+
>
27+
<div className="flex items-center justify-center flex-grow text-white bg-black rounded">
28+
<p>Gradient Border</p>
29+
</div>
30+
</div>
31+
<div className="flex mt-10 space-x-4 rounded">
32+
{colors.map((color, index) => {
33+
return (
34+
<div
35+
key={index}
36+
className={cx(
37+
"h-6 w-6 rounded cursor-pointer transform ring-1 ring-offset-2 ring-white ring-offset-black bg-gradient-to-r transition duration-500",
38+
color,
39+
{
40+
"ring-opacity-100": colorIndex === index,
41+
"ring-opacity-0 hover:ring-opacity-50": colorIndex !== index,
42+
}
43+
)}
44+
onClick={() => setColorIndex(index)}
45+
></div>
46+
);
47+
})}
48+
</div>
49+
</div>
50+
);
51+
}

β€Žpages/demos/index.jsβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ export default function Demos() {
4747
link="demos/demo/toast"
4848
description="A reusable react toast notification"
4949
/>
50+
<DemosCard
51+
title="Border Gradient"
52+
link="demos/demo/borderGradient"
53+
description="Add gradients to border"
54+
/>
5055
</div>
5156
</div>
5257
</Container>

β€Žpublic/sitemap.xmlβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
<loc>https://manuarora.in/blog/top-5-nextjs-resources</loc>
3737
</url>
3838

39+
<url>
40+
<loc>https://manuarora.in/snippets/gradient-border</loc>
41+
</url>
42+
3943
<url>
4044
<loc>https://manuarora.in/snippets/gradient-text</loc>
4145
</url>

0 commit comments

Comments
Β (0)