Skip to content

Commit

Permalink
chore: tweaks on implementation details
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 committed Aug 4, 2024
1 parent a3895f5 commit 5e5ee4f
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/lib/components/command/Item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
let acted = false;
beforeNavigate(({ complete }) => {
complete.then(acted ? callback : null);
acted && complete.then(callback);
});
</script>

Expand All @@ -57,29 +57,30 @@
{:else if item.type === "link"}

<Command.Item onSelect={() => acted = true} asChild let:action let:attrs>
{@const highlighted = attrs["data-selected"]}
<!-- eslint-disable-next-line no-unused-vars -->
{@const _ = (browser && attrs["data-selected"] && preloadData(item.href))}
<a href={item.href} use:action {...attrs} class:selected={attrs["data-selected"]}>
{@const _ = (browser && highlighted && preloadData(item.href))}
<a href={item.href} use:action {...attrs} class:highlighted>
{item.text}
</a>
</Command.Item>

{:else if item.type === "cmd"}

<Command.Item onSelect={value => item.callback(value).then(() => acted = true)} asChild let:action let:attrs>
<button use:action {...attrs} class:selected={attrs["data-selected"]}>
<Command.Item onSelect={value => (async () => item.callback(value))().finally(callback)} asChild let:action let:attrs>
<button use:action {...attrs} class:highlighted={attrs["data-selected"]}>
{item.text}
</button>
</Command.Item>

{/if}

<style>
a, button {
--uno: block w-full rounded-md p-2 -mx-2;
}
a, button {
--uno: block w-full rounded-md p-2 -mx-2;
}
.selected {
--uno: bg-white/5;
}
.highlighted {
--uno: bg-white/5;
}
</style>

0 comments on commit 5e5ee4f

Please sign in to comment.