Skip to content

Commit d9f2120

Browse files
committed
[icons] Migrate Card component unplugin-icons → astro-icon
1 parent b48754b commit d9f2120

File tree

4 files changed

+13
-82
lines changed

4 files changed

+13
-82
lines changed

astro.config.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import sitemap from "@astrojs/sitemap";
1313
import partytown from "@astrojs/partytown";
1414
import node from "@astrojs/node";
1515
import react from "@astrojs/react";
16-
import Icons from "unplugin-icons/vite";
1716
import starlightLlmsTxt from "starlight-llms-txt";
1817
import favicons from "astro-favicons";
1918
import icon from "astro-icon";
@@ -177,6 +176,9 @@ export default defineConfig({
177176
"file-text",
178177
"book-open",
179178
"circle-dashed",
179+
"lightning",
180+
"terminal",
181+
"globe-simple",
180182
],
181183
},
182184
}),
@@ -189,7 +191,7 @@ export default defineConfig({
189191
mode: "standalone",
190192
}),
191193
vite: {
192-
plugins: [tailwindcss(), Icons({ compiler: "astro" })],
194+
plugins: [tailwindcss()],
193195
optimizeDeps: {
194196
exclude: ["@rollup/browser"],
195197
},

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@
8787
"starlight-package-managers": "^0.10.0",
8888
"tailwindcss": "^4.0.6",
8989
"unist-util-remove": "^4.0.0",
90-
"unist-util-visit": "^5.0.0",
91-
"unplugin-icons": "^22.1.0"
90+
"unist-util-visit": "^5.0.0"
9291
},
9392
"devDependencies": {
9493
"@astrojs/check": "^0.9.4",

pnpm-lock.yaml

Lines changed: 0 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Card.astro

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
---
2-
// Import specific icons that we want to support
3-
import IconLightning from "~icons/ph/lightning";
4-
import IconTerminal from "~icons/ph/terminal";
5-
import IconFileText from "~icons/ph/file-text";
6-
import IconGlobeSimple from "~icons/ph/globe-simple";
2+
// Import Icon component from astro-icon
3+
import { Icon } from "astro-icon/components";
74
85
interface Props {
96
iconName?: string;
@@ -13,34 +10,19 @@ interface Props {
1310
1411
const { iconName, title, iconProps = {} } = Astro.props;
1512
16-
// Default icon props that will be applied to all icons
17-
const defaultIconProps = {
18-
"font-size": "1.5rem",
19-
"aria-hidden": true,
20-
};
13+
// Extract icon size from props or use default
14+
const iconSize = (iconProps.size as string) || "1.5rem";
2115
22-
// Merge default props with user-provided props (user props take precedence)
23-
const mergedIconProps = { ...defaultIconProps, ...iconProps };
24-
25-
// Map of icon names to components
26-
const iconMap = {
27-
lightning: IconLightning,
28-
terminal: IconTerminal,
29-
"file-text": IconFileText,
30-
"globe-simple": IconGlobeSimple,
31-
} as const;
32-
33-
// Get the icon component based on the iconName
34-
const IconComponent =
35-
iconName && iconName in iconMap ? iconMap[iconName as keyof typeof iconMap] : null;
16+
// Prefix with 'ph:' if not already prefixed
17+
const iconPath = iconName ? (iconName.includes(":") ? iconName : `ph:${iconName}`) : null;
3618
---
3719

3820
<article class="card sl-flex">
3921
<p class="title sl-flex">
4022
{
41-
IconComponent && (
23+
iconPath && (
4224
<span class="icon">
43-
<IconComponent {...mergedIconProps} />
25+
<Icon name={iconPath} size={iconSize} aria-hidden="true" />
4426
</span>
4527
)
4628
}

0 commit comments

Comments
 (0)