File tree Expand file tree Collapse file tree 17 files changed +88
-85
lines changed Expand file tree Collapse file tree 17 files changed +88
-85
lines changed Original file line number Diff line number Diff line change 28
28
},
29
29
"files" : [
30
30
" components" ,
31
- " public " ,
31
+ " icons " ,
32
32
" scss" ,
33
33
" astro.d.ts" ,
34
34
" astro.js" ,
Original file line number Diff line number Diff line change 1
1
import fs from 'fs'
2
2
3
3
const folders = {
4
- 'public ' : 'dist/public ' ,
4
+ 'src/icons ' : 'dist/icons ' ,
5
5
'src/components' : 'dist/components' ,
6
6
'src/scss' : 'dist/scss'
7
7
}
Original file line number Diff line number Diff line change 1
1
import AccordionComponent from './components/Accordion/Accordion.astro'
2
2
import ButtonComponent from './components/Button/Button.astro'
3
3
import CardComponent from './components/Card/Card.astro'
4
+ import IconComponent from './components/Icon/Icon.astro'
4
5
5
6
export const Accordion = AccordionComponent
6
7
export const Button = ButtonComponent
7
8
export const Card = CardComponent
9
+ export const Icon = IconComponent
Original file line number Diff line number Diff line change 1
1
---
2
2
import type { AccordionProps } from ' ./accordion'
3
+ import Icon from ' ../Icon/Icon.astro'
3
4
4
5
interface Props extends AccordionProps {}
5
6
@@ -9,16 +10,11 @@ const {
9
10
---
10
11
11
12
<ul data-id =" accordion" >
12
- { items .map (item => (
13
+ { items .map (( item : AccordionProps [ ' items ' ][ 0 ]) => (
13
14
<li >
14
15
<div class = " accordion-title" >
15
16
{ item .title }
16
- <img
17
- src = " /icons/arrow-down.svg"
18
- alt = " GitHub"
19
- width = { 15 }
20
- height = { 15 }
21
- />
17
+ <Icon type = " arrow-down" size = { 15 } />
22
18
</div >
23
19
<div class = " accordion-wrapper" >
24
20
<div class = " accordion-content" >
Original file line number Diff line number Diff line change 1
1
<script lang =" ts" >
2
2
import type { AccordionProps } from ' ./accordion'
3
+ import ArrowDown from ' ../../icons/arrow-down.svg?raw'
3
4
4
5
export let items: AccordionProps [' items' ]
5
6
22
23
on:click ={() => toggle (index )}
23
24
>
24
25
{item .title }
25
- <img
26
- src =" /icons/arrow-down.svg"
27
- alt =" GitHub"
28
- width ={15 }
29
- height ={15 }
30
- />
26
+ {@html ArrowDown }
31
27
</div >
32
28
<div class =" accordion-wrapper" >
33
29
<div class =" accordion-content" >
Original file line number Diff line number Diff line change 1
1
import React , { useState } from 'react'
2
2
import type { AccordionProps } from './accordion'
3
+ import ArrowDown from '../../icons/arrow-down.svg?raw'
3
4
import './accordion.scss'
4
5
5
6
export const Accordion = ( { items } : AccordionProps ) => {
@@ -19,15 +20,8 @@ export const Accordion = ({ items }: AccordionProps) => {
19
20
< div
20
21
className = { state [ index ] ? 'accordion-title open' : 'accordion-title' }
21
22
onClick = { ( ) => toggle ( index ) }
22
- >
23
- { item . title }
24
- < img
25
- src = "/icons/arrow-down.svg"
26
- alt = "GitHub"
27
- width = { 15 }
28
- height = { 15 }
29
- />
30
- </ div >
23
+ dangerouslySetInnerHTML = { { __html : `${ item . title } ${ ArrowDown } ` } }
24
+ />
31
25
< div className = "accordion-wrapper" >
32
26
< div className = "accordion-content" >
33
27
< div dangerouslySetInnerHTML = { { __html : item . content } } />
Original file line number Diff line number Diff line change 25
25
align-items : center ;
26
26
cursor : pointer ;
27
27
28
- img {
28
+ svg {
29
29
@include Transition (transform );
30
- filter : brightness (.7 );
30
+ color : #BBB ;
31
+ width : 15px ;
32
+ height : 15px ;
33
+ pointer-events : none ;
31
34
}
32
35
33
36
& .open {
34
- img {
37
+ svg {
35
38
transform : rotate (180deg );
36
39
}
37
40
Original file line number Diff line number Diff line change 1
1
---
2
+ import type { IconProps } from ' ./icon'
3
+
4
+ interface Props extends IconProps {}
5
+
2
6
const {
3
7
type,
4
8
size = 24 ,
5
9
color
6
10
} = Astro .props
7
11
8
- const { default : innerHTML } = await import (` ../../icons/${type }.js ` );
9
-
12
+ const { default : markup } = await import (` ../../icons/${type }.svg?raw ` )
13
+ const icon = markup
14
+ .replace (' width="24"' , ` width=${size } ` )
15
+ .replace (' height="24"' , color
16
+ ? ` height=${size } color=${color } `
17
+ : ` height=${size } ` )
10
18
---
11
19
12
- <svg
13
- width ={ size }
14
- height ={ size }
15
- viewBox =" 0 0 24 24"
16
- color ={ color }
17
- set:html ={ innerHTML }
18
- />
20
+ <Fragment set:html ={ icon } />
Original file line number Diff line number Diff line change 1
1
<script >
2
- export let type
3
- export let size = 24
4
- export let color
2
+ import type { IconProps } from ' ./icon'
5
3
6
- const icon = () => import (` ../../icons/${ type} .js` )
7
- </script >
4
+ import Github from ' ../../icons/github.svg?raw'
5
+ import ArrowDown from ' ../../icons/arrow-down.svg?raw'
6
+
7
+ export let type: IconProps[' type' ]
8
+ export let size: IconProps[' size' ] = 24
9
+ export let color: IconProps[' color' ]
8
10
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 }
11
+ const iconMap = {
12
+ ' github' : Github,
13
+ ' arrow-down' : ArrowDown
14
+ }
15
+
16
+ const icon = iconMap[type]
17
+ .replace (' width="24"' , ` width=${ size} ` )
18
+ .replace (' height="24"' , color
19
+ ? ` height=${ size} color=${ color} `
20
+ : ` height=${ size} ` )
21
+ </script >
17
22
23
+ {@html icon }
Original file line number Diff line number Diff line change 1
- import React , { useState , useEffect } from 'react'
1
+ import React from 'react'
2
+ import type { IconProps } from './icon'
2
3
3
- import github from '../../icons/github'
4
+ import Github from '../../icons/github.svg?raw'
5
+ import ArrowDown from '../../icons/arrow-down.svg?raw'
6
+
7
+ const iconMap = {
8
+ 'github' : Github ,
9
+ 'arrow-down' : ArrowDown
10
+ }
4
11
5
12
export const Icon = ( {
6
13
type,
7
14
size = 24 ,
8
15
color
9
- } ) => {
10
- const [ icon , setIcon ] = useState ( '' )
11
-
12
- useEffect ( ( ) => {
13
- ( async ( ) => {
14
- const icon = ( await import ( `../../icons/ ${ type } .js` ) ) . default ;
16
+ } : IconProps ) => {
17
+ const icon = iconMap [ type ]
18
+ . replace ( 'width="24"' , `width= ${ size } ` )
19
+ . replace ( 'height="24"' , color
20
+ ? `height= ${ size } color= ${ color } `
21
+ : `height= ${ size } ` )
15
22
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
- )
23
+ return < div dangerouslySetInnerHTML = { { __html : icon } } />
29
24
}
30
-
Original file line number Diff line number Diff line change
1
+ export type IconProps = {
2
+ type : string
3
+ size ?: number
4
+ color ?: string
5
+ }
Original file line number Diff line number Diff line change
1
+ /// <reference types="astro/client" />
Original file line number Diff line number Diff line change 2
2
import Layout from ' @static/Layout.astro'
3
3
import ComponentWrapper from ' @static/ComponentWrapper.astro'
4
4
5
+ import Icon from ' @components/Icon/Icon.astro'
5
6
import AstroButton from ' @components/Button/Button.astro'
6
7
import SvelteButton from ' @components/Button/Button.svelte'
7
8
import { Button as ReactButton } from ' @components/Button/Button.tsx'
@@ -43,14 +44,9 @@ import { Button as ReactButton } from '@components/Button/Button.tsx'
43
44
<AstroButton disabled >Disabled</AstroButton >
44
45
</ComponentWrapper >
45
46
46
- <ComponentWrapper title =" Wiht Icon" >
47
+ <ComponentWrapper title =" With Icon" >
47
48
<AstroButton theme =" secondary" >
48
- <img
49
- src =" /icons/github.svg"
50
- alt =" GitHub"
51
- width ={ 20 }
52
- height ={ 20 }
53
- />
49
+ <Icon type =" github" size ={ 20 } />
54
50
With Icon
55
51
</AstroButton >
56
52
</ComponentWrapper >
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import CardWrapper from '@static/CardWrapper.astro'
4
4
5
5
import Button from ' @components/Button/Button.astro'
6
6
import Accordion from ' @components/Accordion/Accordion.astro'
7
+ import Icon from ' @components/Icon/Icon.astro'
7
8
---
8
9
9
10
<Layout >
@@ -22,7 +23,7 @@ import Accordion from '@components/Accordion/Accordion.astro'
22
23
href =" https://github.com/Frontendland/webcoreui" target =" _blank"
23
24
theme =" secondary"
24
25
>
25
- <img src = " /icons/ github.svg " alt = " GitHub " width = { 20 } height ={ 20 } />
26
+ <Icon type = " github" size ={ 20 } />
26
27
GitHub
27
28
</Button >
28
29
</div >
Original file line number Diff line number Diff line change @@ -3,14 +3,21 @@ import { vitePreprocess } from '@astrojs/svelte'
3
3
export default {
4
4
preprocess : vitePreprocess ( ) ,
5
5
onwarn : ( warning , handler ) => {
6
- // Suppress false positive a11y warnings in terminal
6
+ // Suppress false positive warnings in terminal
7
7
// Edit .vscode/settings.json to also suppress warnings in VSCode
8
8
const ignoreWarnings = [
9
9
'a11y-click-events-have-key-events' ,
10
- 'a11y-no-static-element-interactions'
10
+ 'a11y-no-static-element-interactions' ,
11
+ '.accordion-title'
11
12
]
12
13
13
- if ( ignoreWarnings . includes ( warning . code ) ) {
14
+ const warningText = [
15
+ warning . code ,
16
+ warning . message ,
17
+ warning . filename
18
+ ] . join ( ' ' )
19
+
20
+ if ( new RegExp ( ignoreWarnings . join ( '|' ) , 'gi' ) . test ( warningText ) ) {
14
21
return
15
22
}
16
23
You can’t perform that action at this time.
0 commit comments