# frozen_string_literal: true module Ariadne # Add a general description of component here # Add additional usage considerations or best practices that may aid the user to use the component correctly. # @accessibility Add any accessibility considerations class SlideoverComponent < Ariadne::Component DEFAULT_TAG = :div TAG_OPTIONS = [DEFAULT_TAG].freeze DIRECTION_Y_DOWN = :yd DIRECTION_X_LEFT = :xl VALID_DIRECTIONS = [DIRECTION_Y_DOWN, DIRECTION_X_LEFT].freeze DEFAULT_CLASSES = "ariadne-flex ariadne-flex-col" DEFAULT_BUTTON_CLASSES = "ariadne-inline-flex ariadne-items-center ariadne-shadow-sm ariadne-px-4 ariadne-py-1.5 ariadne-pb-2 ariadne-text-sm ariadne-leading-5 ariadne-font-medium ariadne-rounded-full " + Ariadne::ButtonComponent::SCHEME_CLASS_MAPPINGS[:default] renders_one :open_button, lambda { |selected: false, classes: "", attributes: {}| actual_classes = merge_class_names(DEFAULT_BUTTON_CLASSES, classes, selected ? "" : BASE_HIDDEN_CLASS) attributes[:id] ||= "btnOpen" attributes[:"data-slideover-component-target"] ||= "slidePanel" attributes[:"data-action"] ||= "click->slideover-component#toggle" attributes[:type] ||= "submit" Ariadne::ButtonComponent.new(classes: actual_classes, attributes: attributes) } renders_one :close_button, lambda { |selected: false, classes: "", attributes: {}| actual_classes = merge_class_names(DEFAULT_BUTTON_CLASSES, classes, selected ? "" : BASE_HIDDEN_CLASS) attributes[:id] ||= "btnClose" attributes[:"data-slideover-component-target"] ||= "slidePanel" attributes[:"data-action"] ||= "click->slideover-component#toggle" attributes[:type] ||= "submit" Ariadne::ButtonComponent.new(classes: actual_classes, attributes: attributes) } # @example Default # # <%= render(Ariadne::SlideoverComponent.new(direction: Ariadne::SlideoverComponent::DIRECTION_Y_DOWN)) { "Example" } %> # # @param tag [Symbol, String] The rendered tag name. # @param direction [Symbol] <%= one_of(Ariadne::SlideoverComponent::VALID_DIRECTIONS) %> # @param open_text [String] The text to use to open the slideover. # @param close_text [String] The text to use to close the slideover. # @param classes [String] <%= link_to_classes_docs %> # @param attributes [Hash] <%= link_to_attributes_docs %> def initialize(tag: DEFAULT_TAG, direction:, open_text: "Open", close_text: "Close", classes: "", attributes: {}) @tag = check_incoming_tag(DEFAULT_TAG, tag) @classes = merge_class_names( DEFAULT_CLASSES, classes, ) @direction = fetch_or_raise(VALID_DIRECTIONS, direction) @open_text = open_text @close_text = close_text @attributes = attributes @attributes[:"data-controller"] = "slideover-component" @attributes[:"data-slideover-component-target"] = "expandWrapper" end end end