a11yist/app/helpers/application_helper.rb
david bf03407bb9
Some checks failed
/ Run tests (push) Successful in 1m41s
/ Build, push and deploy image (push) Has been cancelled
/ Run system tests (push) Has been cancelled
more beautiful button and export
2024-11-17 19:00:52 +01:00

64 lines
2 KiB
Ruby

# frozen_string_literal: true
module ApplicationHelper
include Pagy::Frontend
delegate :filter_params, to: :controller
def multilang_form_field(form, attribute, as: :text_field)
return form.send(as, "#{attribute}_de")
col_width = as == :rich_text_area ? 12 : 12 / I18n.available_locales.count
tag.div(class: "row") do
fields = I18n.available_locales.map { _1.to_s.split("-").first }.map do |lang|
tag.div(class: "col-lg-#{col_width}") do
form.send(as, "#{attribute}_#{lang}")
end
end
safe_join(fields)
end
end
def safe_display(value, &block)
return if value.blank?
yield(value)
end
def current_page_displayed(page)
@current_page&.id == page.id ? "open" : nil
end
def turbo_stream_toast(content, alert)
turbo_stream.append("toasts", partial: "layouts/toast", locals: { content:, alert: })
end
def dropdown_menu(items, klass: "")
tag.details(class: "details-dropdown #{klass}") do
tag.summary do
tag.div(class: "details-dropdown-trigger") do
tag.div(tag.i(class: "bi bi-three-dots-vertical"), class: "btn btn-outline-secondary")
end
end +
tag.div(class: "details-dropdown-content bg-secondary") do
tag.div(class: "list-group") do
safe_join(items.map do |item|
c = "list-group-item list-group-item-action #{ item[:color] ? " list-group-item-#{item[:color]}" : "list-group-item-secondary"}"
text = item[:icon] ? tag.i(class: "bi bi-#{item[:icon]} me-2") + " #{item[:text]}".html_safe : item[:text]
case item[:method]
when nil, :get
link_to(text, item[:href], class: "#{c}")
else
button_to(text,
item[:href],
method: item[:method],
class: "#{c}",
data: { turbo_confirm: item[:confirm] })
end
end)
end
end
end
end
end