Skip to content

Commit 9c14ee7

Browse files
author
wec
committed
icon from url
1 parent 946d3e7 commit 9c14ee7

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/lib/components/dashboard.svelte

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { flip } from 'svelte/animate';
66
import { fade } from 'svelte/transition';
77
import ActionButtons from './actionButtons.svelte';
8-
import { getIds, hasField } from '$lib/helpers';
8+
import { getIds, hasField, isUrlString } from '$lib/helpers';
99
import EmptyItem from './emptyItem.svelte';
1010
import EmptyGroup from './emptyGroup.svelte';
1111
import { newGroup, newItem } from '$lib/factory';
@@ -200,7 +200,15 @@
200200
<div class="flex items-center gap-2">
201201
{#if item.icon}
202202
<div class="h-14 w-14">
203-
<Icon color="gray" icon={item.icon} height={56} />
203+
{#if isUrlString(item.icon)}
204+
<img
205+
src={item.icon}
206+
alt={item.title}
207+
class="h-full w-full rounded-full object-cover"
208+
/>
209+
{:else}
210+
<Icon color="gray" icon={item.icon} height={56} />
211+
{/if}
204212
</div>
205213
{/if}
206214
<div>

src/lib/components/modalFormItem.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
</Label>
3636
<Label class="space-y-2">
3737
<span>Icon</span>
38-
<Input bind:value={form.icon} type="text" name="icon" placeholder="Icon name" />
38+
<Input bind:value={form.icon} type="text" name="icon" placeholder="URL or Icon name" />
3939
<Helper class="text-sm">
40-
Icon name from <a
40+
URL or Icon name from <a
4141
target="_blank"
4242
href="https://icon-sets.iconify.design/"
4343
class="text-primary-600 dark:text-primary-500 font-medium hover:underline">iconify</a

src/lib/helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ export const generateRandomString = (length: number) => {
2828
.toString(36)
2929
.substring(2, 2 + length);
3030
};
31+
32+
export const isUrlString = (str: string): boolean => {
33+
if (!str) {
34+
return false;
35+
}
36+
const urlRegex = /^(ftp|http|https):\/\/[^ "]+$/;
37+
return urlRegex.test(str);
38+
};

0 commit comments

Comments
 (0)