-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hovercard for private/public saved sceanrios
- Loading branch information
Showing
6 changed files
with
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
<div | ||
data-controller="hovercard" | ||
data-hovercard-url-value="<%= @path %>" | ||
data-action="mouseenter->hovercard#show mouseleave->hovercard#hide" | ||
> | ||
<%= content %> | ||
|
||
<%# static card %> | ||
<%# should make text optional and setup the @path with turbo see: https://boringrails.com/articles/hovercards-stimulus/ %> | ||
<div class="relative hidden" data-hovercard-target="card"> | ||
<div data-tooltip-arrow class="absolute top-0 left-0 z-50 shadow-lg rounded-lg p-3 min-w-max-content bg-midnight-300 text-midnight-800"> | ||
<div class="flex space-x-3 items-center w-64 text-sm"> | ||
<%= @text %> | ||
</div> | ||
</div> | ||
</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,8 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hovercard | ||
class Component < ApplicationComponent | ||
option :path | ||
option :text, default: proc { "" } | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,35 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
static targets = ["card"]; | ||
static values = { url: String }; | ||
|
||
show() { | ||
if (this.hasCardTarget) { | ||
this.cardTarget.classList.remove("hidden"); | ||
} else { | ||
fetch(this.urlValue) | ||
.then((r) => r.text()) | ||
.then((html) => { | ||
const fragment = document | ||
.createRange() | ||
.createContextualFragment(html); | ||
|
||
this.element.appendChild(fragment); | ||
}); | ||
} | ||
} | ||
|
||
hide() { | ||
if (this.hasCardTarget) { | ||
this.cardTarget.classList.add("hidden"); | ||
} | ||
} | ||
|
||
disconnect() { | ||
if (this.hasCardTarget) { | ||
this.cardTarget.remove(); | ||
} | ||
} | ||
} | ||
|
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