diff --git a/app/assets/stylesheets/_global.css b/app/assets/stylesheets/_global.css index 68295ad2a..1f1ebb51b 100644 --- a/app/assets/stylesheets/_global.css +++ b/app/assets/stylesheets/_global.css @@ -80,6 +80,7 @@ --z-popup: 10; --z-terminal: 20; --z-tray: 21; + --z-tooltip: 30; /* OKLCH colors: Fixed */ --lch-black: 0% 0 0; diff --git a/app/assets/stylesheets/tooltips.css b/app/assets/stylesheets/tooltips.css index c206e8954..854c7406c 100644 --- a/app/assets/stylesheets/tooltips.css +++ b/app/assets/stylesheets/tooltips.css @@ -1,5 +1,5 @@ @layer components { - .tooltip { + [data-controller^="tooltip"] { --tooltip-delay: 750ms; --tooltip-duration: 150ms; @@ -10,13 +10,23 @@ font-size: var(--text-x-small); font-weight: normal; inset: -1ch auto auto 50%; - max-inline-size: 28ch; + max-inline-size: 50ch; opacity: 0; padding: 0.25ch 1ch; transition: var(--tooltip-duration) ease-out allow-discrete; - transition-property: opacity, translate; - translate: -50% -85%; + transition-property: opacity; + translate: -50% -100%; text-overflow: ellipsis; + + &.orient-right { + inset-inline-start: 0; + translate: 0 -100%; + } + + &.orient-left { + inset-inline-end: 0; + translate: 0 -100%; + } } @media(any-hover: hover) { @@ -27,6 +37,12 @@ opacity: 1; transition-delay: var(--tooltip-delay); translate: -50% -100%; + z-index: var(--z-tooltip); + + &.orient-left, + &.orient-right { + translate: 0 -100%; + } } } } diff --git a/app/javascript/controllers/tooltip_controller.js b/app/javascript/controllers/tooltip_controller.js new file mode 100644 index 000000000..0b242f157 --- /dev/null +++ b/app/javascript/controllers/tooltip_controller.js @@ -0,0 +1,32 @@ +import { Controller } from "@hotwired/stimulus" +import { orient } from "helpers/orientation_helpers" + +export default class extends Controller { + static targets = [ "tooltip" ] + + connect() { + this.element.addEventListener("mouseenter", this.mouseEnter.bind(this)) + this.element.addEventListener("mouseout", this.mouseOut.bind(this)) + } + + disconnect() { + this.element.removeEventListener("mouseenter", this.mouseEnter.bind(this)) + this.element.removeEventListener("mouseout", this.mouseOut.bind(this)) + } + + mouseEnter(event) { + orient(this.#tooltipElement) + } + + mouseOut(event) { + orient(this.#tooltipElement, false) + } + + get #tooltipElement() { + return this.element.querySelector(".for-screen-reader") + } + + get #tooltipText() { + return this.#tooltipElement.innerText + } +} diff --git a/app/views/cards/_collection_settings.html.erb b/app/views/cards/_collection_settings.html.erb index 318eeb70c..b677c3f96 100644 --- a/app/views/cards/_collection_settings.html.erb +++ b/app/views/cards/_collection_settings.html.erb @@ -1,4 +1,4 @@ -<%= link_to edit_collection_path(collection), class: "btn tooltip" do %> +<%= link_to edit_collection_path(collection), class: "btn", data: { controller: "tooltip" } do %> <%= icon_tag "settings" %> Settings for <%= collection.name %> <% end %> diff --git a/app/views/cards/_webhooks.html.erb b/app/views/cards/_webhooks.html.erb index 2bdddaa3d..4ed058479 100644 --- a/app/views/cards/_webhooks.html.erb +++ b/app/views/cards/_webhooks.html.erb @@ -1,4 +1,4 @@ -<%= link_to collection_webhooks_path(collection_id: collection), class: ["btn tooltip", {"btn--reversed": collection.webhooks.any?}] do %> +<%= link_to collection_webhooks_path(collection_id: collection), class: ["btn", {"btn--reversed": collection.webhooks.any?}], data: { controller: "tooltip" } do %> <%= icon_tag "world" %> Webhooks <% end %> diff --git a/app/views/cards/container/_gild.html.erb b/app/views/cards/container/_gild.html.erb index dc4298348..c8e337267 100644 --- a/app/views/cards/container/_gild.html.erb +++ b/app/views/cards/container/_gild.html.erb @@ -1,10 +1,10 @@ <% if card.golden? %> - <%= button_to card_goldness_path(card), method: :delete, class: "btn btn--reversed tooltip" do %> + <%= button_to card_goldness_path(card), method: :delete, class: "btn btn--reversed", data: { controller: "tooltip" } do %> <%= icon_tag "golden-ticket" %> Demote to normal <% end %> <% else %> - <%= button_to card_goldness_path(card), class: "btn tooltip" do %> + <%= button_to card_goldness_path(card), class: "btn", data: { controller: "tooltip" } do %> <%= icon_tag "golden-ticket" %> Promote to golden <% end %> diff --git a/app/views/cards/container/_image.html.erb b/app/views/cards/container/_image.html.erb index de2341aa1..c5827ea3d 100644 --- a/app/views/cards/container/_image.html.erb +++ b/app/views/cards/container/_image.html.erb @@ -1,11 +1,11 @@ <% if card.image.attached? %> - <%= button_to card_image_path(card), method: :delete, class: "btn tooltip" do %> + <%= button_to card_image_path(card), method: :delete, class: "btn", data: { controller: "tooltip" } do %> <%= icon_tag "picture-remove" %> Remove background image <% end %> <% elsif !card.closed? %> <%= form_with model: card, url: card_path(card), data: { controller: "form" } do |form| %> -