Class: DaisyUI::Tooltip
- Defined in:
- lib/daisy_ui/tooltip.rb
Constant Summary collapse
- PLACEMENTS =
%i[top bottom left right].freeze
- DEFAULT_STIMULUS_IDENTIFIER =
"daisy-tooltip"- POPOVER_STYLE =
"position:fixed;inset:auto;margin:0;border:0;opacity:1;transform:none;overflow:visible;" \ "pointer-events:none;visibility:hidden"
- ARROW_STYLE =
"position:absolute;width:.625rem;height:.25rem;background:var(--tt-bg);" \ "clip-path:polygon(0 0,100% 0,50% 100%);pointer-events:none"
Constants inherited from Base
Base::BOOLS, Base::COLOR_MODIFIERS
Instance Method Summary collapse
- #content(**options) ⇒ Object
-
#initialize(*modifiers, tip: nil, as: :div, popover_id: nil, stimulus: true, **options) ⇒ Tooltip
constructor
A new instance of Tooltip.
- #view_template ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(*modifiers, tip: nil, as: :div, popover_id: nil, stimulus: true, **options) ⇒ Tooltip
Returns a new instance of Tooltip.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/daisy_ui/tooltip.rb', line 16 def initialize(*modifiers, tip: nil, as: :div, popover_id: nil, stimulus: true, **) @popover = modifiers.include?(:popover) @popover_id = popover_id if @popover @stimulus = stimulus @tip = tip if popover? validate_stimulus! boolean_placements = PLACEMENTS.select { |candidate| [candidate] == true } wire_controller(, modifiers + boolean_placements) end super(*modifiers, as:, **) end |
Instance Method Details
#content(**options) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/daisy_ui/tooltip.rb', line 42 def content(**, &) if popover? @content_rendered = true [:id] ||= popover_id [:popover] = "manual" [:role] ||= "tooltip" [:style] = merge_style([:style], POPOVER_STYLE) merge_stimulus_target(, "content") div(class: component_classes("tooltip-content", options:), **) do span( aria_hidden: "true", data: { stimulus_target_key => "arrow" }, style: ARROW_STYLE ) yield if block_given? end else div(class: component_classes("tooltip-content", options:), **, &) end end |
#view_template ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/daisy_ui/tooltip.rb', line 29 def view_template(&) if popover? public_send(as, class: merge_classes(classes, "after:hidden"), **attributes) do yield self if block_given? content { plain tip } if tip && !@content_rendered end else opts = { class: classes, **attributes } opts[:data_tip] = tip if tip public_send(as, **opts, &) end end |