# frozen_string_literal: true module Ariadne # Arranges items as a ariadne-grid. class GridComponent < Ariadne::Component DEFAULT_CLASSES = "ariadne-grid ariadne-gap-6 sm:ariadne-grid-cols-2 lg:ariadne-grid-cols-3" DEFAULT_LINK_COLOR_CLASSES = "focus:ariadne-outline-none focus:ariadne-ring-2 focus:ariadne-ring-offset-2 focus:ariadne-ring-purple-500" # The items to show in the ariadne-grid. renders_many :items, "GridItem" # @example Default # # <%= render(Ariadne::GridComponent.new) { "Example" } %> # # @param classes [String] <%= link_to_classes_docs %> # @param attributes [Hash] <%= link_to_attributes_docs %> def initialize(classes: "", attributes: {}) @classes = class_names( DEFAULT_CLASSES, classes, ) default_attributes = { role: "list" } @attributes = default_attributes.merge(attributes) end # This component is part of `GridComponent` and should not be # used as a standalone component. class GridItem < Ariadne::Component DEFAULT_ITEM_CLASSES = "ariadne-flex ariadne-flex-col ariadne-text-center ariadne-rounded-lg ariadne-shadow text-black-700 ariadne-border-black" DEFAULT_ENTRY_CLASSES = "ariadne-group ariadne-flex-1 ariadne-flex ariadne-flex-col ariadne-p-8 hover:ariadne-text-gray-500" renders_one :entry, lambda { |classes: "", attributes: {}, &block| view_context.capture do actual_classes = class_names(DEFAULT_ENTRY_CLASSES, classes) render(Ariadne::BaseComponent.new(tag: :div, classes: actual_classes, attributes: attributes)) { block&.call } end } DEFAULT_ACTION_LINK_CLASSES = "ariadne-relative ariadne--mr-px ariadne-w-0 ariadne-flex-1 ariadne-inline-flex ariadne-items-center ariadne-justify-center ariadne-py-4 ariadne-text-sm ariadne-font-medium ariadne-border ariadne-border-transparent" DEFAULT_ACTION_LINK_COLORS = "ariadne-h-full hover:ariadne-text-gray-500" renders_many :actions, lambda { |href:, icon:, label:, size: Ariadne::HeroiconComponent::SIZE_DEFAULT, variant: HeroiconsHelper::Icon::VARIANT_SOLID, classes: "", attributes: {}, text_classes: ""| actual_classes = class_names(DEFAULT_ACTION_LINK_CLASSES, DEFAULT_ACTION_LINK_COLORS, classes) render(Ariadne::LinkComponent.new(href: href, classes: actual_classes, attributes: attributes)) do render(Ariadne::HeroiconComponent.new(icon: icon, size: size, variant: variant, text_classes: text_classes)) { label } end } renders_one :link, lambda { |href:, classes: "", attributes: {}| Ariadne::LinkComponent.new(href: href, classes: classes, attributes: attributes) } attr_reader :classes, :attributes def initialize(classes: "", attributes: {}) @classes = class_names(DEFAULT_ITEM_CLASSES, classes) @attributes = attributes end def call render(Ariadne::BaseComponent.new(tag: :div, classes: @classes, attributes: @attributes)) end end end end