label
Label with inline edit toggle
Label with inline edit toggle
Загрузка превью…
src/label/c-label-12.vue
<script setup lang="ts">
import { ref } from "vue"
import { Button } from "@/components/ui/button"
import { Field, FieldDescription } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
const isEditing = ref(false)
const value = ref("My Awesome Project")
</script>
<template>
<Field class="w-full max-w-xs">
<Label for="label-inline-edit" class="gap-2">
Project Name
<Button
size="icon-xs"
variant="ghost"
@click="isEditing = !isEditing"
>
<svg
v-if="isEditing"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="lucide lucide-check size-3.5"
>
<path d="M20 6 9 17l-5-5" />
</svg>
<svg
v-else
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="lucide lucide-pencil size-3.5"
>
<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z" />
<path d="m15 5 4 4" />
</svg>
</Button>
</Label>
<Input
v-if="isEditing"
id="label-inline-edit"
:value="value"
autofocus
@input="(e: Event) => (value = (e.target as HTMLInputElement).value)"
/>
<FieldDescription v-else>{{ value }}</FieldDescription>
</Field>
</template>