feat: tooltips with tippy.js

This commit is contained in:
Björn Fromme
2024-01-10 13:05:08 +01:00
parent 25c44d3292
commit 7215b3077b
3 changed files with 56 additions and 1 deletions
+36
View File
@@ -0,0 +1,36 @@
import { Controller } from '@hotwired/stimulus'
import tippy from 'tippy.js'
export default class extends Controller {
static targets = ['trigger', 'template']
static values = { content: String, placement: String }
connect() {
let options, element
let placement = this.placementValue ? this.placementValue : 'top'
if (this.hasTemplateTarget) {
options = {
content: this.templateTarget.innerHTML,
placement,
touch: true,
trigger: 'click',
allowHTML: true,
interactive: true,
}
} else {
options = {
content: this.contentValue,
placement,
touch: false,
allowHTML: true,
interactive: true,
}
}
if (this.hasTriggerTarget) {
element = this.triggerTarget
} else {
element = this.element
}
tippy(element, options)
}
}
+2 -1
View File
@@ -3,4 +3,5 @@
@import "components/button.css";
@import "components/datatable.css";
@import "components/datepicker.css";
@import "components/toast.css";
@import "components/toast.css";
@import "components/tooltip.css";
+18
View File
@@ -0,0 +1,18 @@
@import "tippy.js/dist/tippy.css";
.tippy-box {
background-color: theme('colors.primary');
}
.tippy-box[data-placement^='top'] > .tippy-arrow::before {
border-top-color: theme('colors.primary');
}
.tippy-box[data-placement^='bottom'] > .tippy-arrow::before {
border-bottom-color: theme('colors.primary');
}
.tippy-box[data-placement^='left'] > .tippy-arrow::before {
border-left-color: theme('colors.primary');
}
.tippy-box[data-placement^='right'] > .tippy-arrow::before {
border-right-color: theme('colors.primary');
}