Skip to content

Commit

Permalink
feat: highlight selected variant char
Browse files Browse the repository at this point in the history
  • Loading branch information
mkpoli committed Oct 16, 2024
1 parent 607584d commit 946f581
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/VariantKanji.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ $effect(() => {
<InsertButton color={color} text={traditional} display={`${traditional}=${simplified}`} />
{/each}
{#each Object.entries(GROUPED_VARIANTS) as [key, variants]}
<InsertButtonVariantKanji display={key} variants={variants.map(([display, [compatibility, variantSelector]]) => ([display, selectVariant(compatibility, variantSelector)]))} />
<InsertButtonVariantKanji display={key} variants={variants.map(([display, [compatibility, variantSelector]]) => ([display, selectVariant(compatibility, variantSelector)]))} selection={editor.selectedText} />
{/each}
</div>
</div>
Expand Down
9 changes: 8 additions & 1 deletion src/lib/buttons/InsertButtonVariantKanji.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import tippy, { type Instance as TippyInstance } from "tippy.js";
let {
display,
variants,
selection,
}: {
display: string;
variants: readonly (readonly [display: string, variant: string | null])[];
selection: string;
} = $props();
let instance: TippyInstance | undefined;
Expand All @@ -34,7 +36,7 @@ onMount(() => {
const editor = getContext<Editor>("editor");
</script>

<button bind:this={button} class:active>{display}</button>
<button bind:this={button} class:active class:selected={variants.some(([display, _v]) => selection.includes(display))}>{display}</button>

<div class="variants" bind:this={variantsContainer}>
{#each variants as [display, variant]}
Expand Down Expand Up @@ -77,6 +79,11 @@ const editor = getContext<Editor>("editor");
background-color: #eee;
}
button.selected {
border-color: #765300;
background-color: #fff0cc;
}
.variants {
display: flex;
flex-direction: column;
Expand Down

0 comments on commit 946f581

Please sign in to comment.