fix: resolve texts add and delete flow
This commit is contained in:
@@ -26,7 +26,6 @@
|
||||
</header>
|
||||
|
||||
<style>
|
||||
/* Header */
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
|
||||
@@ -4,15 +4,16 @@
|
||||
|
||||
interface Props {
|
||||
text: string;
|
||||
id: number;
|
||||
ondelete: () => void;
|
||||
}
|
||||
|
||||
let { text = $bindable(), ondelete }: Props = $props();
|
||||
let { text = $bindable(), id, ondelete }: Props = $props();
|
||||
</script>
|
||||
|
||||
<div class="text-item">
|
||||
<input type="text" bind:value={text} />
|
||||
<Button icon={IconCross} type="danger" on:click={ondelete} />
|
||||
<Button icon={IconCross} type="danger" onclick={() => ondelete(id)} />
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -10,11 +10,16 @@
|
||||
let text: string = $state("");
|
||||
|
||||
function addText() {
|
||||
console.log(text);
|
||||
let trimmed = text.trim();
|
||||
if (trimmed.length !== 0) {
|
||||
textsState.addText(trimmed);
|
||||
}
|
||||
text = "";
|
||||
}
|
||||
|
||||
function deleteText(id: number) {}
|
||||
function deleteText(id: number) {
|
||||
textsState.removeText(id);
|
||||
}
|
||||
</script>
|
||||
|
||||
<Card title="Тексты панелей">
|
||||
@@ -24,13 +29,12 @@
|
||||
</InputGroup>
|
||||
<div class="texts-list">
|
||||
{#each textsState.texts as { text, id } (id)}
|
||||
<TextInlineEdit {text} ondelete={() => deleteText(id)} />
|
||||
<TextInlineEdit {id} {text} ondelete={() => deleteText(id)} />
|
||||
{/each}
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<style>
|
||||
/* Texts List */
|
||||
.texts-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
interface Props {
|
||||
icon: Component;
|
||||
onclick: MouseEventHandler<HTMLButtonElement>;
|
||||
disabled?: boolean;
|
||||
label?: string;
|
||||
type?: "primary" | "secondary" | "danger" | "outline";
|
||||
onclick: MouseEventHandler<HTMLButtonElement>;
|
||||
}
|
||||
|
||||
let { icon: Icon, disabled = false, label, type = "primary", onclick }: Props = $props();
|
||||
let { icon: Icon, onclick, disabled = false, label = "", type = "primary" }: Props = $props();
|
||||
</script>
|
||||
|
||||
<button
|
||||
|
||||
@@ -24,7 +24,7 @@ function createTextsState(): TextsState {
|
||||
nextId++;
|
||||
},
|
||||
removeText(id: number) {
|
||||
texts.filter((textItem) => textItem.id === id);
|
||||
texts = texts.filter((textItem) => textItem.id !== id);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user