Skip to content

Commit b7f2adb

Browse files
committed
refactor: add reusable icon component
1 parent a3a07fb commit b7f2adb

File tree

6 files changed

+41
-16
lines changed

6 files changed

+41
-16
lines changed

src/components/Icon.astro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
let { name, width, height } = Astro.props
3+
4+
if (!height) {
5+
height = width
6+
}
7+
8+
if (isNum(width)) {
9+
width = `${width}px`
10+
}
11+
12+
if (isNum(height)) {
13+
height = `${height}px`
14+
}
15+
16+
function isNum(value) {
17+
return !isNaN(value)
18+
}
19+
---
20+
21+
<iconify-icon icon={name} width="none" style={{ width: `${width}`, height: `${height}` }}></iconify-icon>

src/components/Modal.astro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
---
2+
import Icon from '~/components/Icon.astro'
3+
---
4+
15
<div id="modal" class="pointer-events-none fixed top-0 left-0 z-99999 flex h-full w-full items-center justify-center bg-black/20 p-4 opacity-0 backdrop-blur-xs transition-opacity duration-300">
26
<div class="flex max-h-full max-w-full translate-y-5 flex-col rounded-lg bg-white p-4 pb-0 transition-transform duration-300 md:max-w-lg md:min-w-80">
37
<div class="modal-header mb-6"></div>
48
<div class="modal-body overflow-y-auto"></div>
59
<div class="flex items-center justify-center bg-white py-1">
610
<button id="modal-close-btn" class="text-info hover:text-info-dark grid place-items-center transition-colors">
7-
<iconify-icon icon="mdi:close-circle" width="none" style="width: 28px; height: 28px"></iconify-icon>
11+
<Icon name="mdi:close-circle" width="28" />
812
</button>
913
</div>
1014
</div>

src/components/Navbar.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { useI18n, getLocaleFromPath } from '~/i18n/utils'
33
import { getRelativeLocaleUrl } from 'astro:i18n'
44
import { pathnameWithoutBaseAndLocale } from '~/utils/build/pathnameWithoutBaseAndLocale'
5+
import Icon from '~/components/Icon.astro'
56
67
const locale = getLocaleFromPath(Astro.url.pathname)
78
const { t } = useI18n(Astro.url.pathname)
@@ -36,7 +37,7 @@ const navs = [
3637
<div class="group relative hidden h-full items-center gap-2 px-4 font-bold md:flex">
3738
<span class="flex cursor-pointer items-center gap-2">
3839
Language
39-
<iconify-icon icon="mdi:language" class="icon-18"></iconify-icon>
40+
<Icon name="mdi:language" width="20" />
4041
</span>
4142

4243
<div
@@ -65,7 +66,7 @@ const navs = [
6566
}
6667

6768
<div class="flex items-center gap-2 py-2 text-xl">
68-
<iconify-icon icon="mdi:language" class="icon-18"></iconify-icon>
69+
<Icon name="mdi:language" width="20" />
6970
<a href={getRelativeLocaleUrl('zh-tw', pathname)}>華語</a>
7071
<span>|</span>
7172
<a href={getRelativeLocaleUrl('en', pathname)}>English</a>

src/components/agenda/Agenda.astro

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useI18n } from '~/i18n/utils'
33
import Layout from '~/layouts/Layout.astro'
44
import Desktop from './desktop/Desktop.astro'
55
import Mobile from './mobile/Mobile.astro'
6+
import Icon from '~/components/Icon.astro'
67
78
const { t } = useI18n(Astro.url.pathname)
89
const { title, date } = Astro.props
@@ -12,13 +13,13 @@ const { title, date } = Astro.props
1213
<div class="container">
1314
<h1 class="my-8 md:my-12">{t('agenda.title')}</h1>
1415

15-
<div class="mb-8 flex flex-col md:flex-row gap-4">
16+
<div class="mb-8 flex flex-col gap-4 md:flex-row">
1617
<a href="#" class="btn btn-info flex gap-1 px-14!">
17-
<iconify-icon icon="mdi:text-box-edit" width="24" height="24" style="width: 24px; height: 24px"></iconify-icon>
18+
<Icon name="mdi:text-box-edit" width="24" />
1819
<span>{t('agenda.main_note')}</span>
1920
</a>
2021
<a href="#" class="btn btn-info flex gap-1 px-14!">
21-
<iconify-icon icon="mdi:video" width="24" height="24" style="width: 24px; height: 24px"></iconify-icon>
22+
<Icon name="mdi:video" width="24" />
2223
<span>{t('agenda.main_live')}</span>
2324
</a>
2425
</div>

src/pages/visit.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
import Layout from '~/layouts/Layout.astro'
33
import { useI18n } from '~/i18n/utils'
4+
import Icon from '~/components/Icon.astro'
45
56
const { t } = useI18n(Astro.url.pathname)
67
---
@@ -65,7 +66,7 @@ const { t } = useI18n(Astro.url.pathname)
6566
id="visit-tab-publicTransport"
6667
data-tab="publicTransport"
6768
>
68-
<iconify-icon icon="mdi:bus" class="size-5 shrink-0" aria-hidden="true"></iconify-icon>
69+
<Icon name="mdi:bus" width="20" />
6970
<span class="hidden md:inline">{t('visit.transport.tabs.publicTransport')}</span>
7071
</button>
7172
<button
@@ -78,7 +79,7 @@ const { t } = useI18n(Astro.url.pathname)
7879
id="visit-tab-driving"
7980
data-tab="driving"
8081
>
81-
<iconify-icon icon="mdi:car" class="size-5 shrink-0" aria-hidden="true"></iconify-icon>
82+
<Icon name="mdi:car" width="20" />
8283
<span class="hidden md:inline">{t('visit.transport.tabs.drivingLine1')}<span class="whitespace-nowrap">{t('visit.transport.tabs.drivingLine2')}</span></span>
8384
</button>
8485
</div>

src/styles/base.css

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@
1717
@apply font-bold;
1818
}
1919
h1 {
20-
@apply md:text-4xl text-3xl;
20+
@apply text-3xl md:text-4xl;
2121
}
2222
h2 {
23-
@apply md:text-3xl text-2xl;
23+
@apply text-2xl md:text-3xl;
2424
}
2525
h3 {
26-
@apply md:text-2xl text-xl;
26+
@apply text-xl md:text-2xl;
2727
}
2828
h4 {
29-
@apply md:text-xl text-lg;
29+
@apply text-lg md:text-xl;
3030
}
3131
h5 {
32-
@apply md:text-lg text-base;
32+
@apply text-base md:text-lg;
3333
}
3434
p {
3535
@apply leading-8;
@@ -126,9 +126,6 @@
126126
.btn-outline-dark {
127127
@apply border border-neutral-500 text-neutral-500 hover:bg-neutral-500 hover:text-white;
128128
}
129-
.icon-18 {
130-
@apply h-4.5 w-4.5 text-lg;
131-
}
132129
.nav-link {
133130
@apply flex h-full cursor-pointer items-center px-4 text-nowrap transition-[background-color] hover:bg-neutral-500;
134131
}

0 commit comments

Comments
 (0)