-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from chonla/main
feat: Rename form
- Loading branch information
Showing
7 changed files
with
84 additions
and
15 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
30 changes: 30 additions & 0 deletions
30
cdmm/app/javascript/controllers/editable_label_controller.js
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,30 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
// Connects to data-controller="editable-label" | ||
export default class extends Controller { | ||
static values = { identifier: String, original: String }; | ||
static targets = [ 'textViewer', 'textEditor', 'textEditorInput' ]; | ||
|
||
connect() { | ||
this.openViewer(); | ||
} | ||
|
||
openViewer() { | ||
this.textViewerTarget.classList.remove('hidden'); | ||
this.textEditorTarget.classList.remove('inline-flex'); | ||
this.textEditorTarget.classList.add('hidden'); | ||
} | ||
|
||
openEditor() { | ||
this.textViewerTarget.classList.add('hidden'); | ||
this.textEditorTarget.classList.remove('hidden') | ||
this.textEditorTarget.classList.add('inline-flex'); | ||
this.textEditorInputTarget.focus(); | ||
} | ||
|
||
submit() { | ||
this.textViewerTarget.innerHTML = this.textEditorInputTarget.value; | ||
this.openViewer(); | ||
this.dispatch('changed', { detail: { original: this.originalValue, new: this.textEditorInputTarget.value }, prefix: this.identifierValue }); | ||
} | ||
} |
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,3 @@ | ||
<%= turbo_frame_tag "evaluation_form_title", data: { turbo_cache_control: "no-cache" } do %> | ||
<%= render "shared/editable_title", input_name: :title, text: text, identifier: :title %> | ||
<% end %> |
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,24 @@ | ||
<div data-controller="editable-label" data-editable-label-identifier-value="<%= identifier %>" data-editable-label-original-value="<%= h(text) %>"> | ||
<div class="flex flex-row justify-start items-center space-x-1 flex-nowrap cursor-pointer group" data-editable-label-target="textViewer" data-action="click->editable-label#openEditor"> | ||
<h1 class="underline decoration-dashed decoration-gray-300 decoration-2 noto-serif-thai-bold text-xl md:text-2xl lg:text-3xl leading-normal lg:leading-relaxed"><%= text %></h1> | ||
<div class="text-gray-300 h-6 w-6 block"> | ||
<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M883.626667 300.373333c16.64-16.64 16.64-44.373333 0-60.16l-99.84-99.84c-15.786667-16.64-43.52-16.64-60.16 0l-78.506667 78.08 160 160M128 736V896h160L759.893333 423.68l-160-160L128 736z" fill="currentColor" /></svg> | ||
</div> | ||
</div> | ||
<div class="inline-flex flex-row items-center rounded-md border shadow-sm border-gray-400 p-0 pr-1 space-x-1" data-editable-label-target="textEditor"> | ||
<input type="text" name="<%= input_name %>" class="text-xl md:text-2xl lg:text-3xl border-none outline-none bg-transparent px-2 py-1 focus:outline-none focus:ring-transparent" value="<%= h(text) %>" data-editable-label-target="textEditorInput" /> | ||
<button type="submit" class="text-lime-600 h-6 w-6" data-action="click->editable-label#submit"> | ||
<svg xmlns="https://www.w3.org/2000/svg" viewBox="0 0 24 24"> | ||
<circle cx="12" cy="12" r="12" fill="currentColor" /> | ||
<path d="M7 12l4 4l6 -8" fill="none" stroke-linejoin="round" stroke-width="4" stroke-linecap="round" stroke="white" /> | ||
</svg> | ||
</button> | ||
<button class="h-6 w-6 text-red-600" data-action="click->editable-label#openViewer"> | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> | ||
<circle cx="12" cy="12" r="12" fill="currentColor" /> | ||
<path d="M7 7l10 10" fill="none" stroke-linejoin="round" stroke-width="4" stroke-linecap="round" stroke="white" /> | ||
<path d="M17 7l-10 10" fill="none" stroke-linejoin="round" stroke-width="4" stroke-linecap="round" stroke="white" /> | ||
</svg> | ||
</button> | ||
</div> | ||
</div> |
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 @@ | ||
class AddFormTitle < ActiveRecord::Migration[7.2] | ||
def change | ||
add_column :evaluations, :title, :string | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.