Skip to content

Commit

Permalink
fix name change
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew committed Jan 19, 2024
1 parent b06f9f1 commit a7edeff
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import SuggestName from "./content-modules/context-free-tools/SuggestName.svelte";
import GetColorsFromString from "./content-modules/context-free-tools/GetColorsFromString.svelte";
import ContentEditable from "./components/ContentEditable.svelte";
const tabs = ["examples", "compare", "eval"] as const;
</script>

Expand Down Expand Up @@ -63,17 +65,10 @@
<span class="italic">Current Pal:</span>
<div class="flex">
<span>✎</span>
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
class=""
on:keyup={(e) => {
// @ts-ignore
colorStore.setCurrentPalName(e.target.textContent);
}}
contenteditable="true"
>
{$colorStore.currentPal.name}
</div>
<ContentEditable
onChange={(x) => colorStore.setCurrentPalName(x)}
value={$colorStore.currentPal.name}
/>
</div>
</div>
<SuggestName />
Expand Down
27 changes: 27 additions & 0 deletions src/components/ContentEditable.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script lang="ts">
export let onChange: (str: string) => void;
export let value: string;
let focused = false;
</script>

{#if focused}
<input
type="text"
bind:value
on:blur={() => {
onChange(value);
focused = false;
}}
on:keyup={(e) => {
if (e.key === "Enter") {
focused = false;
onChange(value);
}
}}
/>
{:else}
<button on:click={() => (focused = true)}>
{value}
</button>
{/if}

0 comments on commit a7edeff

Please sign in to comment.