Skip to content

Commit 85cb0d1

Browse files
committed
changes in svg in the sidebar
1 parent f2a1b83 commit 85cb0d1

File tree

7 files changed

+116
-69
lines changed

7 files changed

+116
-69
lines changed

src/assets/icons/home.svg

Lines changed: 3 additions & 10 deletions
Loading

src/assets/icons/placeholder.svg

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/assets/styles/menu.css

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,25 @@
88
--header-height: 80px;
99
--sidebar-width: 16ch;
1010
--timing: 0.42s;
11-
--ease: linear(
12-
0 0%,
13-
0.0036 9.62%,
14-
0.0185 16.66%,
15-
0.0489 23.03%,
16-
0.0962 28.86%,
17-
0.1705 34.93%,
18-
0.269 40.66%,
19-
0.3867 45.89%,
20-
0.5833 52.95%,
21-
0.683 57.05%,
22-
0.7829 62.14%,
23-
0.8621 67.46%,
24-
0.8991 70.68%,
25-
0.9299 74.03%,
26-
0.9545 77.52%,
27-
0.9735 81.21%,
28-
0.9865 85%,
29-
0.9949 89.15%,
30-
1 100%
31-
);
11+
--ease: linear(0 0%,
12+
0.0036 9.62%,
13+
0.0185 16.66%,
14+
0.0489 23.03%,
15+
0.0962 28.86%,
16+
0.1705 34.93%,
17+
0.269 40.66%,
18+
0.3867 45.89%,
19+
0.5833 52.95%,
20+
0.683 57.05%,
21+
0.7829 62.14%,
22+
0.8621 67.46%,
23+
0.8991 70.68%,
24+
0.9299 74.03%,
25+
0.9545 77.52%,
26+
0.9735 81.21%,
27+
0.9865 85%,
28+
0.9949 89.15%,
29+
1 100%);
3230
--sidebar-collapsed: 4rem;
3331
--sidebar-expanded: 16ch;
3432
--icon-size: 1.5rem;
@@ -53,7 +51,6 @@
5351
color: var(--primary);
5452
font-weight: 600;
5553
border-radius: 0.75rem;
56-
margin: 0rem 1rem;
5754
}
5855

5956
[popover] .nav--list__item:hover {
@@ -112,6 +109,10 @@
112109

113110
& .nav--list__item {
114111
padding: 0.25rem;
112+
113+
& .text {
114+
display: none;
115+
}
115116
}
116117
}
117118

@@ -224,6 +225,18 @@
224225
transition: opacity 0.2s;
225226
}
226227

228+
[popover] .nav--list__item a svg,
229+
.menu-button svg {
230+
flex-shrink: 0;
231+
min-width: var(--icon-size);
232+
min-height: var(--icon-size);
233+
}
234+
235+
[popover] .placement-toggle,
236+
.placement-toggle {
237+
display: none !important;
238+
}
239+
227240
@media (max-width: 768px) {
228241
button.hider {
229242
height: 48px;
@@ -397,14 +410,18 @@
397410
opacity: 0;
398411
}
399412
}
400-
}
401413

402-
[data-placement="top"] [popovertarget="nav"]:not(.hider) {
403-
top: 1rem;
404-
right: 1rem;
414+
[popover] .placement-toggle,
415+
.placement-toggle {
416+
display: grid !important;
417+
}
418+
419+
.placement-toggle {
420+
display: grid;
421+
}
405422
}
406423

407-
[data-placement="bottom"] [popovertarget="nav"]:not(.hider) {
424+
[popovertarget="nav"]:not(.hider) {
408425
top: unset;
409426
bottom: 1rem;
410427
left: 1rem;
@@ -473,4 +490,4 @@
473490
[data-debug="false"] .debug-toggle g:first-of-type {
474491
display: block;
475492
}
476-
}
493+
}

src/layouts/Navigation.astro

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
//import Link from "@/components/Link.astro"; // TODO: use Link instead of native a
32
import type { LinkProps } from "@/types";
43
54
interface Props {
@@ -9,28 +8,80 @@ interface Props {
98
const { pages } = Astro.props;
109
1110
const currentPath = Astro.url.pathname;
12-
---
1311
14-
<style>
15-
.iconx {
16-
width: 32px;
17-
height: 32px;
18-
}
19-
</style>
12+
const getGradient = (text: string) => {
13+
// Generate different colors based on text to ensure consistent but unique gradients
14+
const hash = text.split("").reduce((acc, char) => char.charCodeAt(0) + acc, 0);
15+
const hue1 = hash % 360;
16+
const hue2 = (hue1 + 60) % 360;
17+
return `
18+
<linearGradient id="gradient-${text}" x1="0%" y1="0%" x2="100%" y2="100%">
19+
<stop offset="0%" style="stop-color: hsl(${hue1}, 70%, 60%)" />
20+
<stop offset="100%" style="stop-color: hsl(${hue2}, 70%, 60%)" />
21+
</linearGradient>
22+
`;
23+
};
24+
25+
const DefaultIcon = ({ text }: { text: string }) => {
26+
const letter = text.charAt(0).toUpperCase();
27+
return `
28+
<svg width="100%" height="100%" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
29+
<circle cx="12" cy="12" r="10" stroke="url(#gradient-${text})" stroke-width="2" fill="none"></circle>
30+
<text
31+
x="12"
32+
y="12"
33+
text-anchor="middle"
34+
dominant-baseline="central"
35+
fill="url(#gradient-${text})"
36+
font-size="11"
37+
font-weight="600"
38+
font-family="system-ui"
39+
>${letter}</text>
40+
</svg>
41+
`;
42+
};
43+
---
2044

2145
<nav class="nav">
46+
<svg width="0" height="0" style="position: absolute">
47+
<defs>
48+
{pages.map((p) => <Fragment set:html={getGradient(p.name ?? p.title)} />)}
49+
</defs>
50+
</svg>
2251
<ul class="nav--list">
2352
{
2453
pages
2554
.filter((p) => p.isActive)
26-
.map((p) => (
27-
<li class={`nav--list__item ${currentPath === p.path ? "active" : ""}`}>
28-
<a href={p.path}>
29-
<span class="iconx">{p.icon && <p.icon />}</span>
30-
<span class="text">{p.name}</span>
31-
</a>
32-
</li>
33-
))
55+
.map((p) => {
56+
const gradientUrl = `url(#gradient-${p.name ?? p.title})`;
57+
return (
58+
<li class={`nav--list__item ${currentPath === p.path ? "active" : ""}`}>
59+
<a href={p.path}>
60+
<span class="iconx">
61+
{p.icon ? (
62+
<span style={`--icon-gradient: ${gradientUrl}`}>
63+
<p.icon />
64+
</span>
65+
) : (
66+
<Fragment set:html={DefaultIcon({ text: p.name ?? p.title })} />
67+
)}
68+
</span>
69+
<span class="text">{p.name}</span>
70+
</a>
71+
</li>
72+
);
73+
})
3474
}
3575
</ul>
3676
</nav>
77+
78+
<style>
79+
.iconx {
80+
width: 32px;
81+
height: 32px;
82+
}
83+
84+
.iconx :global(svg path) {
85+
fill: var(--icon-gradient);
86+
}
87+
</style>

src/layouts/common/Menu.astro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import "@/assets/styles/menu.css";
33
import HamIcon from "@/assets/icons/ham.svg";
44
import ArrowIcon from "@/assets/icons/arrow.svg";
55
import ToggleIcon from "@/assets/icons/toggle.svg";
6-
//import ArrowLeftIcon from "@/assets/icons/arrow-left.svg";
76
87
import Navigation from "@/layouts/Navigation";
98
import { NavbarLinks } from "@/utils/constants";

src/types/link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ export type LinkProps = {
22
title: string;
33
name?: string;
44
path: string;
5+
icon?: any;
56
isActive: boolean;
6-
icon?: React.FC;
77
};

src/utils/constants.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import HomeIcon from "@/assets/icons/home.svg";
2-
import PlaceholderIcon from "@/assets/icons/placeholder.svg";
32
import RecordIcon from "@/assets/icons/record.svg";
43
import type { LinkProps } from "@/types";
54

@@ -17,28 +16,24 @@ export const NavbarLinks: LinkProps[] = [
1716
name: "About",
1817
title: "About",
1918
path: "/about",
20-
icon: PlaceholderIcon,
2119
isActive: true
2220
},
2321
{
2422
name: "Varnmala",
2523
title: "Varnmala",
2624
path: "/varnmala",
27-
icon: PlaceholderIcon,
2825
isActive: true
2926
},
3027
{
3128
name: "Panel",
3229
title: "Panel",
3330
path: "/panel",
34-
icon: PlaceholderIcon,
3531
isActive: true
3632
},
3733
{
3834
name: "Reader",
3935
title: "Reader",
4036
path: "/reader",
41-
icon: PlaceholderIcon,
4237
isActive: true
4338
},
4439
{
@@ -52,35 +47,30 @@ export const NavbarLinks: LinkProps[] = [
5247
name: "English",
5348
title: "English",
5449
path: "/english",
55-
icon: PlaceholderIcon,
5650
isActive: true
5751
},
5852
{
5953
name: "Typing",
6054
title: "Typing",
6155
path: "/typing",
62-
icon: PlaceholderIcon,
6356
isActive: true
6457
},
6558
{
6659
name: "India",
6760
title: "India Map",
6861
path: "/map",
69-
icon: PlaceholderIcon,
7062
isActive: true
7163
},
7264
{
7365
name: "Letter",
7466
title: "Letter Pad",
7567
path: "/letter",
76-
icon: PlaceholderIcon,
7768
isActive: true
7869
},
7970
{
8071
name: "Feedback",
8172
title: "Feedback Form",
8273
path: "/feedback",
83-
icon: PlaceholderIcon,
8474
isActive: true
8575
}
8676
];

0 commit comments

Comments
 (0)