svelte simple icons
v4.0.1
該軟體包提供了打包為一組 Svelte 組件的 Simple Icons 13.21.0。
使用以下命令將套件安裝在您的專案目錄中:
// with yarn
yarn add @icons-pack/svelte-simple-icons
// with npm
npm add @icons-pack/svelte-simple-icons
所有圖示均從單一檔案匯入,其中 [ICON SLUG] 被大寫的 slug 取代。
編輯代碼沙盒
<!-- Import a specific icon by its slug as: -->
<!-- import { Si[ICON SLUG] } from 'simple-icons'; -->
< script >
import { SiReact , SiSvelte , SiDocker } from " @icons-pack/svelte-simple-icons " ;
</ script >
< SiSvelte color = "#FF3E00" size ={ 90 } />
< SiReactJs color = "#61DAFB" size ={ 50 } />
< SiDocker />
<!-- title default "Svelte" -->
< script >
import { SiSvelte } from " @icons-pack/svelte-simple-icons " ;
</ script >
< SiSvelte title = " My title " />
< script >
import { SiSvelte } from " @icons-pack/svelte-simple-icons " ;
</ script >
< SiSvelte class = " myStyle " />
< style >
.myStyle {
width : 35 px ;
height : 35 px ;
}
</ style >
有時,我們希望動態地向元件提供元件。我們可以透過使用svelte:component
功能和輔助類型SiComponentType
類型定義來做到這一點。
< script lang = " ts " >
import type { SiComponentType } from ' @icons-pack/svelte-simple-icons ' ;
export let icon : SiComponentType ;
export let text : string ;
export let click : () => void = () => console . log ( ' do something ' );
</ script >
< button on:click ={ click }>
< svelte:component
this ={ icon }
title ={ text } <!-- optional , along with size and color properties -->
/>
{ text }
</ button >
< style lang = " scss " >
button {
display : flex ;
flex-direction : row ;
text-decoration : none ;
white-space : nowrap ;
transition : border-color 0.25 s ;
box-shadow : none ;
text-shadow : none ;
}
.icon {
margin : 4 px 4 px 0 0 ;
}
</ style >
如果您只需要幾個圖標,您可以單獨導入它們而不是整個檔案以改進編譯。
< script >
import SiSvelte from " @icons-pack/svelte-simple-icons/icons/SiSvelte.svelte " ;
import SiGithub from " @icons-pack/svelte-simple-icons/icons/SiGithub.svelte " ;
</ script >
< SiGithub />
< SiSvelte />