22import { AstroError } from ' astro/errors'
33
44import Icon from ' ./Icon.astro'
5+ import { Icons } from ' ../../libs/icons'
56
67const asideVariants = [' important' , ' info' , ' note' , ' tip' , ' warning' , ' caution' ] as const
7- const icons = {
8+
9+ type IconName = keyof typeof Icons ;
10+
11+ const defaultIcons: Record <typeof asideVariants [number ], IconName > = {
812 important: ' important' ,
913 info: ' callout_info' ,
1014 note: ' note' ,
@@ -16,9 +20,10 @@ const icons = {
1620interface Props {
1721 type? : (typeof asideVariants )[number ]
1822 title? : string
23+ icon? : string
1924}
2025
21- let { type = ' note' , title } = Astro .props
26+ let { type = ' note' , title, icon } = Astro .props
2227
2328if (! asideVariants .includes (type )) {
2429 throw new AstroError (
@@ -31,14 +36,51 @@ if (!asideVariants.includes(type)) {
3136if (! title ) {
3237 title = type .toUpperCase ()
3338}
39+
40+ // Determine the icon to render
41+ let iconToRender: IconName | undefined
42+ let isEmoji = false
43+
44+ if (icon ) {
45+ // Check if the provided icon is an emoji
46+ const emojiRegex = / \p {Emoji}/ u ; // Unicode property escape for emoji
47+ if (emojiRegex .test (icon )) {
48+ iconToRender = undefined // Set to undefined if it's an emoji, handled by isEmoji
49+ isEmoji = true
50+ } else if (icon in Icons ) {
51+ iconToRender = icon as IconName
52+ } else {
53+ // Fallback to default icon if provided icon name is not found in Icons
54+ console .warn (` Icon "${icon }" not found in icons.ts. Falling back to default icon for type "${type }". ` );
55+ iconToRender = defaultIcons [type ] as IconName ;
56+ }
57+ } else {
58+ iconToRender = defaultIcons [type ] as IconName ;
59+ }
3460---
3561
3662<aside aria-label ={ title } class ={ ` aside aside-${type } ` } >
3763 <p class =' aside-title' >
38- <Icon name ={ icons [type ]} />
64+ { isEmoji ? (
65+ <span class = " aside-icon-emoji" >{ icon } </span >
66+ ) : (
67+ <Icon name = { iconToRender ! } />
68+ )}
3969 <span >{ title } </span >
4070 </p >
4171 <div class =' aside-content' >
4272 <slot />
4373 </div >
4474</aside >
75+
76+ <style >
77+ .aside-icon-emoji {
78+ font-size: 1.5em; /* Adjust size to match SVG icons */
79+ line-height: 1;
80+ display: flex;
81+ align-items: center;
82+ justify-content: center;
83+ }
84+ </style >
85+
86+
0 commit comments