1- <script >
2- import { onMount } from ' svelte' ;
3- import { selectedIcon , isModalOpen , closeIconModal } from ' $lib/stores/iconStore' ;
4-
5- let selectedVersion = ' ' ;
6- let versions = [];
7-
8- $: if ($selectedIcon && $selectedIcon .versions && $selectedIcon .versions .svg ) {
1+ <script lang =" ts" >
2+ import { onMount } from " svelte" ;
3+ import {
4+ selectedIcon ,
5+ closeIconModal ,
6+ } from " $lib/stores/iconStore" ;
7+ import type { IconType } from " $lib/types/icon" ;
8+ import Modal from " ./Modal.svelte" ;
9+ import IconModalHeader from " ./IconModalHeader.svelte" ;
10+ import IconVersions from " ../components/IconVersions.svelte" ;
11+
12+ let selectedVersion = " " as string ;
13+ let versions = [] as string [];
14+
15+ interface Icon {
16+ name: string ;
17+ versions: {
18+ svg: string [];
19+ font: string [];
20+ };
21+ }
22+
23+ $ : if (
24+ $selectedIcon &&
25+ $selectedIcon .versions &&
26+ $selectedIcon .versions .svg
27+ ) {
928 versions = $selectedIcon .versions .svg ;
10- selectedVersion = versions .includes (' original' ) ? ' original' : versions[0 ];
29+ selectedVersion = versions .includes (" original" ) ? " original" : versions [0 ];
1130 }
12-
13- function getIconUrl (icon , version ) {
31+
32+ function getIconUrl(icon : IconType , version : string ) {
1433 return ` https://cdn.jsdelivr.net/gh/devicons/devicon/icons/${icon .name }/${icon .name }-${version }.svg ` ;
1534 }
16-
17- function handleKeydown (e ) {
18- if (e .key === ' Escape' ) {
35+
36+ function handleKeydown(e : KeyboardEvent ) {
37+ if (e .key === " Escape" ) {
1938 closeIconModal ();
2039 }
2140 }
22-
41+
2342 onMount (() => {
24- document .addEventListener (' keydown' , handleKeydown);
43+ document .addEventListener (" keydown" , handleKeydown );
2544 return () => {
26- document .removeEventListener (' keydown' , handleKeydown);
45+ document .removeEventListener (" keydown" , handleKeydown );
2746 };
2847 });
2948 </script >
3049
31- <div class ="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4" on:click |self ={closeIconModal }>
32- <div
33- class =" bg-white dark:bg-gray-800 p-6 rounded-lg shadow-xl max-w-lg w-full max-h-[90vh] overflow-y-auto"
34- role =" dialog"
35- aria-modal =" true"
36- aria-labelledby =" modal-title"
37- >
38- {#if $selectedIcon }
39- <div class =" flex justify-between items-start mb-4" >
40- <h2 id ="modal-title" class ="text-xl font-bold dark:text-white" >{$selectedIcon .name }</h2 >
41- <button
42- class =" text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
43- on:click ={closeIconModal }
44- aria-label =" Close modal"
45- >
46- <svg xmlns =" http://www.w3.org/2000/svg" class =" h-6 w-6" fill =" none" viewBox =" 0 0 24 24" stroke =" currentColor" >
47- <path stroke-linecap =" round" stroke-linejoin =" round" stroke-width =" 2" d =" M6 18L18 6M6 6l12 12" />
48- </svg >
49- </button >
50- </div >
51-
52- <div class =" flex flex-col items-center mb-6" >
53- {#if versions .length > 0 }
54- <div class =" bg-gray-100 dark:bg-gray-700 p-8 rounded-lg mb-4 w-full flex justify-center" >
55- <img
56- src ={getIconUrl ($selectedIcon , selectedVersion )}
57- alt ={` ${$selectedIcon .name } (${selectedVersion }) ` }
58- class =" h-24"
59- />
60- </div >
61-
62- <div class =" w-full" >
63- <label for =" version-select" class =" block text-sm font-medium mb-2 dark:text-gray-200" >Select version:</label >
64- <select
65- id =" version-select"
66- bind:value ={selectedVersion }
67- class =" w-full p-2 border rounded-md dark:bg-gray-700 dark:border-gray-600 dark:text-white"
68- >
69- {#each versions as version }
70- <option value ={version }>{version }</option >
71- {/each }
72- </select >
73- </div >
74- {:else }
75- <p class =" text-gray-500 dark:text-gray-400" >No SVG versions available</p >
76- {/if }
77- </div >
78-
79- {#if $selectedIcon .tags && $selectedIcon .tags .length > 0 }
80- <div class =" mb-4" >
81- <h3 class =" font-medium mb-2 dark:text-white" >Tags:</h3 >
82- <div class =" flex flex-wrap gap-1" >
83- {#each $selectedIcon .tags as tag }
84- <span class ="px-2 py-1 bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 rounded text-sm" >{tag }</span >
85- {/each }
86- </div >
87- </div >
88- {/if }
89-
90- <div class =" pt-4 border-t border-gray-200 dark:border-gray-700" >
91- <button
92- class =" px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors"
93- on:click ={closeIconModal }
94- >
95- Close
96- </button >
97- </div >
98- {/if }
99- </div >
100- </div >
50+ <Modal isOpen ={!! $selectedIcon } onClose ={closeIconModal } title ={$selectedIcon ?.name }>
51+ <IconModalHeader title ={$selectedIcon ?.name } onClose ={closeIconModal } />
52+
53+ {#if $selectedIcon }
54+ <IconVersions
55+ title =" Font versions"
56+ versions ={$selectedIcon ?.versions ?.font || []}
57+ type =" font"
58+ selectedIcon ={$selectedIcon }
59+ />
60+
61+ <IconVersions
62+ title =" SVG versions"
63+ versions ={versions }
64+ type =" svg"
65+ selectedIcon ={$selectedIcon }
66+ getIconUrl ={getIconUrl }
67+ />
68+ {/if }
69+ </Modal >
0 commit comments