Skip to content

Commit 74aaf8a

Browse files
committed
Prepare icons component
1 parent b410f72 commit 74aaf8a

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

src/components/Icon/Icon.astro

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
const {
3+
type,
4+
size = 24,
5+
color
6+
} = Astro.props
7+
8+
const { default: innerHTML } = await import(`../../icons/${type}.js`);
9+
10+
---
11+
12+
<svg
13+
width={size}
14+
height={size}
15+
viewBox="0 0 24 24"
16+
color={color}
17+
set:html={innerHTML}
18+
/>

src/components/Icon/Icon.svelte

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script>
2+
export let type
3+
export let size = 24
4+
export let color
5+
6+
const icon = () => import(`../../icons/${type}.js`)
7+
</script>
8+
9+
{#await icon() then module}
10+
<svg
11+
width={size}
12+
height={size}
13+
viewBox="0 0 24 24"
14+
color={color}
15+
>{@html module.default}</svg>
16+
{/await}
17+

src/components/Icon/Icon.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, { useState, useEffect } from 'react'
2+
3+
import github from '../../icons/github'
4+
5+
export const Icon = ({
6+
type,
7+
size = 24,
8+
color
9+
}) => {
10+
const [icon, setIcon] = useState('')
11+
12+
useEffect(() => {
13+
(async () => {
14+
const icon = (await import(`../../icons/${type}.js`)).default;
15+
16+
setIcon(icon)
17+
})()
18+
}, [])
19+
20+
return (
21+
<svg
22+
width={size}
23+
height={size}
24+
viewBox="0 0 24 24"
25+
color={color}
26+
dangerouslySetInnerHTML={{ __html: github }}
27+
/>
28+
)
29+
}
30+

0 commit comments

Comments
 (0)