# typed: false # frozen_string_literal: true module Ariadne module UI module Combobox class Component < BaseComponent option :placement, default: proc { "bottom" } option :show_search, default: proc { :no } option :size, default: proc { :md } option :clamped, default: proc { false } option :changed_action, optional: true option :filter_placeholder, default: proc { "Filter…" } renders_many :options, Ariadne::UI::Combobox::Option::Component # behind the scenes, an item is just a very specific type of option renders_many :items, Ariadne::UI::Combobox::Item::Component renders_one :button, Ariadne::UI::Button::Component accepts_html_attributes do |html_attrs| html_attrs[:data] = { controller: "ariadne-ui-input-filter #{stimulus_name}", "#{stimulus_name}-placement-value": placement, "#{stimulus_name}-clamped-value": clamped, } if changed_action html_attrs[:data][:action] = "#{stimulus_name}:changed->#{changed_action}" end end accepts_html_attributes_for :input, autocomplete: "off", autofocus: true, type: "search", placeholder: proc { @filter_placeholder }, data: { "ariadne-ui-input-filter-target": "input", "#{stimulus_name}-target": "searchInput", "action": "ariadne-ui-input-filter#handleInput", } def initialize(**options) super validate! end def choices? items? || options? end def choices items.presence || options end private def validate! # raise ArgumentError, "Must provide only `options` or `items`, not both" if items? && options? end style :popover do base do [ "ariadne-fixed", "ariadne-max-w-[90vw]", "ariadne-z-20", "ariadne-scroll", "ariadne-scrollbar-trigger", "ariadne-rounded-lg", "ariadne-shadow-lg", "ariadne-background", "dark:ariadne-bg-zinc-900", ] end variants do size do sm { "ariadne-w-36" } md { "ariadne-w-52" } lg { "ariadne-w-96" } end end end style :options do base do ["ariadne-overflow-auto", "ariadne-p-2"] end end end end end end