-
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.
Fixes #450
- Loading branch information
Showing
18 changed files
with
138 additions
and
38 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
<%= render Elements::Forms::TextFieldComponent.new(field_name: :email, label: helpers.t('contact_email.edit.fields.email.label'), form:, container_classes: 'mb-4') %> | ||
<%= render Elements::Forms::TextFieldComponent.new(field_name: :email, label: helpers.t('contact_email.edit.fields.email.label'), tooltip: helpers.t('contact_email.edit.fields.email.tooltip_html'), form:, container_classes: 'mb-4') %> |
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
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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
<%= form.label field_name, label_text, class: classes %> | ||
<%= form.label field_name, label_text, class: classes %> | ||
<%= render Elements::TooltipComponent.new(tooltip:) %> |
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
2 changes: 1 addition & 1 deletion
2
app/components/elements/forms/textarea_field_component.html.erb
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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module Elements | ||
# Component for rendering a tooltip. | ||
class TooltipComponent < ApplicationComponent | ||
def initialize(tooltip: nil) | ||
# The tooltip can include a trailing \n that isn't rendered in the HTML but does make for ugly source markup | ||
@tooltip = tooltip&.chomp | ||
super() | ||
end | ||
|
||
def call | ||
helpers.info_icon( | ||
fill: true, | ||
classes: 'px-2 tooltip-info', | ||
data: { | ||
bs_html: true, | ||
bs_template: tooltip_template, | ||
bs_toggle: 'tooltip', | ||
bs_title: tooltip, | ||
bs_trigger: 'click focus', | ||
tooltips_target: 'icon' | ||
} | ||
) | ||
end | ||
|
||
private | ||
|
||
attr_reader :tooltip | ||
|
||
def render? | ||
tooltip.present? | ||
end | ||
|
||
def tooltip_template | ||
<<~HTML.squish | ||
<div class="tooltip tooltip-shift-right" role="tooltip"> | ||
<div class="tooltip-arrow"></div> | ||
<div class="tooltip-inner text-start"></div> | ||
</div> | ||
HTML | ||
end | ||
end | ||
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
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
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,26 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
import * as bootstrap from 'bootstrap' | ||
|
||
export default class extends Controller { | ||
static targets = ['icon'] | ||
|
||
iconTargetConnected (target) { | ||
const tooltip = new bootstrap.Tooltip(target) | ||
|
||
target.addEventListener('show.bs.tooltip', () => this.hideAllExcept(target)) | ||
|
||
return tooltip | ||
} | ||
|
||
// Hide all tooltips (e.g., when switching tabs) | ||
hideAll (_event) { | ||
this.iconTargets.forEach(iconTarget => bootstrap.Tooltip.getInstance(iconTarget).hide()) | ||
} | ||
|
||
// Display only one tooltip on the page at a time | ||
hideAllExcept (target) { | ||
this.iconTargets | ||
.filter(iconTarget => iconTarget !== target) | ||
.forEach(iconTarget => bootstrap.Tooltip.getInstance(iconTarget).hide()) | ||
} | ||
} |
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
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