Skip to content

Commit b886d5d

Browse files
author
wec
committed
feat: add select url target
1 parent 5e4fc05 commit b886d5d

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

src/lib/components/modalFormItem.svelte

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
<script lang="ts">
22
import type { Item } from '$lib/types';
3-
import { Button, ButtonGroup, Helper, Input, InputAddon, Label, Modal } from 'flowbite-svelte';
3+
import {
4+
Button,
5+
ButtonGroup,
6+
Checkbox,
7+
Helper,
8+
Input,
9+
InputAddon,
10+
Label,
11+
Modal,
12+
Select
13+
} from 'flowbite-svelte';
414
import { slide } from 'svelte/transition';
515
616
const {
@@ -9,7 +19,18 @@
919
handleClose
1020
}: { isOpen: boolean; item: Item; handleClose: (item: Item | undefined) => void } = $props();
1121
22+
let urlTarget = [
23+
{ value: '_blank', name: 'New tab' },
24+
{ value: '_self', name: 'Current tab' }
25+
];
26+
1227
const form = $derived(item);
28+
29+
$effect(() => {
30+
if (!form.target) {
31+
form.target = '_blank';
32+
}
33+
});
1334
</script>
1435

1536
<Modal open={isOpen} onclose={() => handleClose(undefined)} transition={slide} size="xs">
@@ -34,7 +55,19 @@
3455
/>
3556
</Label>
3657
<div>
37-
<Label for="input-addon" class="mb-2">Icon</Label>
58+
<Label for="url">Url</Label>
59+
<ButtonGroup class="inline-flex w-full items-stretch">
60+
<Input bind:value={form.url} type="text" name="url" placeholder="Url" required />
61+
<Select
62+
selectClass="min-w-30 !rounded-tl-none !rounded-bl-none border-l-0"
63+
bind:value={form.target}
64+
items={urlTarget}
65+
placeholder="Target"
66+
/>
67+
</ButtonGroup>
68+
</div>
69+
<div>
70+
<Label for="icon">Icon</Label>
3871
<ButtonGroup class="inline-flex w-full items-stretch">
3972
<Input bind:value={form.icon} type="text" name="icon" placeholder="URL or Icon name" />
4073
<span class="color-picker">
@@ -56,10 +89,6 @@
5689
>. The color is applied only to the icon from the iconify.
5790
</Helper>
5891
</div>
59-
<Label class="space-y-2">
60-
<span>Url</span>
61-
<Input bind:value={form.url} type="text" name="url" placeholder="Url" required />
62-
</Label>
6392
<Button type="submit" class="w-full">Save</Button>
6493
</form>
6594
</Modal>

src/lib/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ export enum ActionType {
77
export interface Item {
88
id: string;
99
title: string;
10+
url: string;
11+
target?: string;
1012
description?: string;
1113
icon?: string;
1214
iconColor?: string;
13-
url: string;
1415
}
1516

1617
export interface Group {

src/routes/+page.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
i.url = item.url;
103103
i.icon = item.icon;
104104
i.iconColor = item.iconColor;
105+
i.target = item.target;
105106
} else {
106107
group?.items.push(item);
107108
}
@@ -154,7 +155,7 @@
154155
if (editMode) {
155156
return;
156157
}
157-
window.open(item.url, '_blank');
158+
window.open(item.url, item.target ?? '_blank');
158159
};
159160
</script>
160161

0 commit comments

Comments
 (0)