module Coco module App module Elements class Button < Coco::Button SIZES = [:xs, :sm, :md, :lg, nil] SIZE_ALIASES = { default: [:sm, {xl: :md}] } THEMES = [ "primary", "text-primary", "secondary", "text-secondary", "positive", "text-positive", "negative", "text-negative", "warning", "text-warning", "info", "text-info", "toolbar", "toolbar-floating", "text-toolbar", "neutral-dark", "neutral-light", "text-neutral-light", "text-neutral-dark", "blank", nil ] DEFAULT_THEME = "primary" accepts_option :size, from: SIZES, default: :md accepts_option :theme, from: THEMES, default: DEFAULT_THEME accepts_option :variant renders_one :dropdown, types: { content: ->(&block) { block.call }, confirmation: ->(**kwargs) do set_option_value(:confirm, true) Coco::App::Elements::ConfirmPanel.new(**kwargs) end } before_initialize do |kwargs| if kwargs.key?(:modal) modal_name = (kwargs[:modal] == true) ? "default" : kwargs[:modal] kwargs[:data] = kwargs.fetch(:data, {}).merge(coco_modal_data_attributes(modal_name)) kwargs.delete(:modal) end if kwargs.key?(:frame) turbo_data = {turbo: true, turbo_frame: kwargs[:frame]} kwargs[:data] = kwargs.fetch(:data, {}).merge(turbo_data) kwargs.delete(:frame) end kwargs end before_render do if confirm? && !dropdown? with_confirmation do |confirm| confirm.with_text { "Are you sure?" } confirm.with_button { "Yes, continue" } end end end def with_dropdown(...) with_dropdown_content(...) end def with_confirmation(...) with_dropdown_confirmation(...) end class << self include Coco::BaseHelper end end end end end