mirror of
https://github.com/manyfold3d/manyfold.git
synced 2026-10-22 11:42:19 -05:00
34 lines
989 B
Ruby
34 lines
989 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Components::BaseButton < Components::Base
|
|
include Phlex::Rails::Helpers::ButtonTo
|
|
|
|
def initialize(label:, href:, variant:, icon: nil, method: nil, icon_only: false, aria_label: nil, confirm: nil, data: {}, nofollow: nil, target: nil)
|
|
@icon = icon
|
|
@label = label
|
|
@href = href
|
|
@variant = variant
|
|
@method = method
|
|
@icon_only = icon_only
|
|
@aria_label = aria_label
|
|
@confirm = confirm
|
|
@data = data
|
|
@nofollow = nofollow
|
|
@target = target
|
|
end
|
|
|
|
def view_template
|
|
helper(@href, method: @method, class: "btn btn-#{@variant}", rel: (@nofollow ? "nofollow" : nil), aria: {label: @aria_label || (@icon_only ? @label : nil)}, data: {confirm: @confirm}.merge(@data), target: @target) do
|
|
if @icon
|
|
Icon(icon: @icon, label: @label)
|
|
whitespace
|
|
end
|
|
span(class: @icon_only ? "visually-hidden" : nil) { @label }
|
|
end
|
|
end
|
|
|
|
def helper(*args)
|
|
raise NotImplementedError
|
|
end
|
|
end
|