Skip to content

Commit 7863447

Browse files
committed
Show pencil on hover editable content
1 parent b9e987e commit 7863447

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<span contenteditable="<%= @editable %>"
2+
class="relative peer <%= css_classes %>"
3+
data-controller="editable-title"
4+
data-editable-title-url-value="<%= @path %>"
5+
data-action="<%= actions %>"
6+
>
7+
<%= @title %>
8+
</span>
9+
<% if @editable %>
10+
<span class="
11+
inline-block
12+
ml-2
13+
invisible
14+
peer-focus:invisible!
15+
peer-hover:visible"
16+
>
17+
<%= heroicon 'pencil', options: { class: 'w-4 h-4 text-midnight-800' } %>
18+
</span>
19+
<% end %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module Collections::Title
2+
class Component < ApplicationComponent
3+
include ButtonHelper
4+
5+
option :path
6+
option :title
7+
option :editable
8+
9+
def css_classes
10+
if @editable
11+
'hover:underline
12+
focus:outline-none
13+
focus:border
14+
focus:rounded-md
15+
focus:px-2'
16+
end
17+
end
18+
19+
def actions
20+
if @editable
21+
'blur->editable-title#update
22+
keydown.enter->editable-title#update'
23+
end
24+
end
25+
end
26+
end

app/views/collections/show.html.erb

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<%- content_for :menu_title do %>
2-
<span contenteditable="<%= @editable %>"
3-
class="relative <%= 'hover:underline hover:decoration-gray-400 hover:decoration-1 focus:outline-none' if can?(:update, @collection) %>"
4-
data-controller="editable-title"
5-
data-editable-title-url-value="<%= collection_path(@collection) %>"
6-
data-action="<%= 'blur->editable-title#update keydown.enter->editable-title#update' if can?(:update, @collection) %>">
7-
<%= @collection.title %>
8-
</span>
2+
<%= render(Collections::Title::Component.new(
3+
path: collection_path(@collection),
4+
title: @collection.title,
5+
editable: @editable
6+
))%>
97
<% end %>
108
<%- content_for :title, "#{@collection.title} - #{t('collections.title')} - #{t('meta.title')}" %>
119
<%= render(partial: "collections/show/block_right_menu", locals: { collection: @collection })%>

0 commit comments

Comments
 (0)