-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
585548b
commit e827bd9
Showing
5 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@zag-js/editable": minor | ||
--- | ||
|
||
Add `api.valueText` that returns the current value or placeholder if empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<script lang="ts"> | ||
import * as editable from "@zag-js/editable" | ||
import { normalizeProps, useMachine } from "@zag-js/svelte" | ||
import { editableControls } from "@zag-js/shared" | ||
import { useControls } from "$lib/use-controls.svelte" | ||
const controls = useControls(editableControls) | ||
const [snapshot, send] = useMachine(editable.machine({ id: "1" }), { | ||
context: controls.context, | ||
}) | ||
const api = $derived(editable.connect(snapshot, send, normalizeProps)) | ||
</script> | ||
|
||
<main class="editable"> | ||
<div {...api.rootProps}> | ||
<div {...api.areaProps}> | ||
<input data-testid="input" {...api.inputProps} /> | ||
<span data-testid="preview" {...api.previewProps}>{api.valueText}</span> | ||
</div> | ||
<div {...api.controlProps}> | ||
{#if !api.editing} | ||
<button data-testid="edit-button" {...api.editTriggerProps}> Edit </button> | ||
{/if} | ||
{#if api.editing} | ||
<button data-testid="save-button" {...api.submitTriggerProps}> Save </button> | ||
<button data-testid="cancel-button" {...api.cancelTriggerProps}> Cancel </button> | ||
{/if} | ||
</div> | ||
</div> | ||
</main> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters