# typed: false # frozen_string_literal: true module Ariadne module UI module Combobox class Component < Ariadne::BaseComponent option :size, default: proc { :md } option :placement, default: proc { "bottom" } option :clamped, default: proc { false } option :changed_action, optional: true renders_one :list, lambda { |**options| options[:as_menu] = true Ariadne::UI::List::Component.new(**options) } renders_one :button, Ariadne::UI::Button::Component accepts_html_attributes do |html_attrs| html_attrs[:data] ||= {} html_attrs[:data] = { controller: "#{stimulus_name} #{html_attrs[:data].delete(:controller)}".strip, "#{stimulus_name}-target": "wrapper", "#{stimulus_name}-placement-value": placement, "#{stimulus_name}-clamped-value": clamped, }.merge(html_attrs[:data]) if changed_action html_attrs[:data][:action] = "#{stimulus_name}:changed->#{changed_action}" end end def initialize(**options) super validate! end private def validate! # raise ArgumentError, "Must provide only `options` or `items`, not both" if items? && options? end accepts_styles :popover 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-bg-foreground", "dark:ariadne-bg-foreground-dark", "ariadne-text-content", "dark:ariadne-text-content-dark", ] end variants do size do sm { "ariadne-w-36" } md { "ariadne-w-52" } lg { "ariadne-w-96" } full { "ariadne-w-full" } none {} # let the child decide how big its menu ought to be end end end style :options do base do ["ariadne-overflow-auto", "ariadne-p-2"] end end end end end end