Skip to content

Commit

Permalink
Inline editing (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-GG authored Mar 15, 2024
1 parent ea37532 commit d57689a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion resources/views/components/button/wishlist.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@props(['productId' => $product->entity_id ?? null])

<toggler v-slot="{ isOpen, toggle, close }" v-cloak>
<wishlist v-slot="{ wishlists, toggleItem, findItem, addWishlist, isWishlisted }">
<wishlist v-slot="{ wishlists, toggleItem, findItem, addWishlist, isWishlisted, update }">
<div v-on-click-away="close" {{ $attributes->class('w-full') }}>
@include('rapidez-mw::partials.item.button')
<div v-show="isOpen" v-cloak>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/partials/item/add.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="flex flex-col">
<div class="flex flex-col overflow-hidden">
@include('rapidez-mw::partials.item.title')
@include('rapidez-mw::partials.item.view')
</div>
Expand Down
31 changes: 28 additions & 3 deletions resources/views/partials/item/title.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
<span class="text-base text-ct-primary truncate">
@{{ wishlist.title }}
</span>
<toggler :callback="(opened) => {
if (opened) {
$root.$nextTick(() => $root.$refs['editing_' + wishlist.id]?.[0]?.focus())
} else {
update(wishlist.id, wishlist)
}
}">
<div class="flex items-center" slot-scope="{ toggle, close, isOpen }">
<template v-if="!isOpen">
<span class="text-base text-ct-primary truncate peer place-self-start -mt-0.5">
@{{ wishlist.title }}
</span>
<x-heroicon-s-pencil-square
class="pl-2 w-6 h-4 cursor-pointer shrink-0 opacity-0 hover:opacity-100 peer-hover:opacity-50 transition-opacity"
v-on:click="toggle"
/>
</template>
<template v-else>
<input
v-bind:ref="'editing_' + wishlist.id"
class="!font-[inherit] text-base text-ct-primary -mt-0.5 w-full !outline-none"
v-model.lazy="wishlist.title"
v-on-click-away="close"
v-on:keyup.enter="close"
/>
</template>
</div>
</toggler>

0 comments on commit d57689a

Please sign in to comment.