8000 refactor: migrated command palette component to svelte5 · podman-desktop/podman-desktop@381db75 · GitHub
[go: up one dir, main page]

Skip to content

Commit 381db75

Browse files
committed
refactor: migrated command palette com 8000 ponent to svelte5
Signed-off-by: Evzen Gasta <evzen.ml@seznam.cz>
1 parent f810a72 commit 381db75

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

packages/renderer/src/lib/dialogs/CommandPalette.svelte

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,24 @@ const ARROW_DOWN_KEY = 'ArrowDown';
1515
const ARROW_UP_KEY = 'ArrowUp';
1616
const TAB_KEY = 'Tab';
1717
18-
export let display = false;
19-
let inputElement: HTMLInputElement | HTMLTextAreaElement | undefined = undefined;
20-
let outerDiv: HTMLDivElement | undefined = undefined;
21-
let inputValue: string | undefined = '';
22-
let scrollElements: HTMLLIElement[] = [];
23-
24-
let commandInfoItems: CommandInfo[] = [];
25-
let filteredCommandInfoItems: CommandInfo[] = [];
18+
interface Props {
19+
display?: boolean;
20+
}
21+
22+
let { display = false }: Props = $props();
23+
let inputElement: HTMLInputElement | HTMLTextAreaElement | undefined = $state(undefined);
24+
let outerDiv: HTMLDivElement | undefined = $state(undefined);
25+
let inputValue: string | undefined = $state('');
26+
let scrollElements: HTMLLIElement[] = $state([]);
27+
28+
let commandInfoItems: CommandInfo[] = $state([]);
2629
let globalContext: ContextUI;
2730
28-
$: filteredCommandInfoItems = commandInfoItems
29-
.filter(property => isPropertyValidInContext(property.enablement, globalContext))
30-
.filter(item => (inputValue ? item.title?.toLowerCase().includes(inputValue.toLowerCase()) : true));
31+
let filteredCommandInfoItems: CommandInfo[] = $derived(
32+
commandInfoItems
33+
.filter(property => isPropertyValidInContext(property.enablement, globalContext))
34+
.filter(item => (inputValue ? item.title?.toLowerCase().includes(inputValue.toLowerCase()) : true)),
35+
);
3136
3237
let contextsUnsubscribe: Unsubscriber;
3338
@@ -45,7 +50,7 @@ onDestroy(() => {
4550
contextsUnsubscribe?.();
4651
});
4752
48-
let selectedFilteredIndex = 0;
53+
let selectedFilteredIndex = $state(0);
4954
let selectedIndex = 0;
5055
5156
async function handleKeydown(e: KeyboardEvent): Promise<void> {
@@ -178,14 +183,15 @@ async function onInputChange(): Promise<void> {
178183
aria-label="Command palette command input"
179184
type="text"
180185
bind:value={inputValue}
181-
on:input={onInputChange}
186+
oninput={onInputChange}
182187
class="px-1 w-full text-[var(--pd-input-field-focused-text)] bg-[var(--pd-input-field-focused-bg)] border border-[var(--pd-input-field-stroke)] focus:outline-hidden" />
183188
</div>
184189
<ul class="max-h-[50vh] overflow-y-auto flex flex-col">
185190
{#each filteredCommandInfoItems as item, i (item.id)}
186191
<li class="flex w-full flex-row" bind:this={scrollElements[i]} aria-label={item.id}>
187192
<button
188-
on:click={(): Promise<void> => clickOnItem(i)}
193+
onclick={(): Promise<void> => clickOnItem(i)}
194+
aria-label={item.title}
189195
class="text-[var(--pd-dropdown-item-text)] text-left relative my-0.5 mr-2 w-full {i === selectedFilteredIndex
190196
? 'bg-[var(--pd-modal-dropdown-highlight)] selected'
191197
: 'hover:bg-[var(--pd-dropdown-bg)]'} px-1">

0 commit comments

Comments
 (0)
0