Sha256: 83d2105d3e8f9d8c1d199513345191f9728d7fca606ccc30bb66dfd4976d33f2
Contents?: true
Size: 1.91 KB
Versions: 6
Compression:
Stored size: 1.91 KB
Contents
# typed: false # frozen_string_literal: true module Ariadne module Form module Select class Component < Ariadne::Form::BaseInputComponent option :name option :label, default: proc { false } option :changed_action, optional: true Choice = Data.define(:name, :value, :selected) attr_reader :choices accepts_html_attributes do |html_attrs| html_attrs[:data] ||= {} if changed_action html_attrs[:data][:action] = "#{changed_action}" end end def initialize(**) super @choices = [] end def with_choice(name:, value:, selected: false) @choices << Choice.new(name:, value:, selected:) end def selected_choice @selected_choice ||= @choices.find(&:selected) end def selected?(choice) choice == selected_choice end # def before_render # raise # @selected_choice = @choices.select { |choice| choice.selected } # raise ArgumentError, "Can only have one selected choice" if @selected_choice.length > 1 # @selected_choice = @selected_choice.first if @selected_choice.blank? # end style do base do end end style :select do base do [] end end style :label do base do [ "ariadne-text-sm", "ariadne-font-medium", "ariadne-leading-none", "peer-disabled:ariadne-cursor-not-allowed", "peer-disabled:ariadne-opacity-70", "ariadne-block", "ariadne-mb-2", "ariadne-text-sm", "ariadne-font-medium", "ariadne-text-gray-900", "ariadne-dark:text-white", ] end end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems