Sha256: 5b7ba9802766fb950dcbedab0f0868e0ec1384a0980c9da4ceb34c84b0742643

Contents?: true

Size: 1.01 KB

Versions: 24

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Ariadne
  # Creates a ariadne-rounded label that resembles a medicine pill.
  class PillComponent < Ariadne::Component
    DEFAULT_TAG = :span
    TAG_OPTIONS = [DEFAULT_TAG].freeze

    DEFAULT_CLASSES = "ariadne-flex-shrink-0 ariadne-inline-block ariadne-px-2 ariadne-py-0.5 ariadne-text-xs ariadne-font-medium ariadne-rounded-full"

    # @example Default
    #
    #   <%= render(Ariadne::PillComponent.new(color: "FF0000")) { "Admin" } %>
    #
    # @param tag [Symbol, String] The rendered tag name.
    # @param color [String] The hex color of the pill.
    # @param classes [String] <%= link_to_classes_docs %>
    # @param attributes [Hash] <%= link_to_attributes_docs %>
    def initialize(tag: DEFAULT_TAG, color:, classes: "", attributes: {})
      @tag = check_incoming_tag(DEFAULT_TAG, tag)
      @classes = class_names(
        DEFAULT_CLASSES,
        classes
      )

      @attributes = attributes
      @attributes["style"] = "background-color: ##{color};"
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.12 app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.12-x86_64-linux app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.12-x86_64-darwin app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.12-x64-mingw32 app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.12-x64-mingw-ucrt app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.12-arm64-darwin app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.12-aarch64-linux app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.11 app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.11-x86_64-linux app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.11-x86_64-darwin app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.11-x64-mingw32 app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.11-x64-mingw-ucrt app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.11-arm64-darwin app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.11-aarch64-linux app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.10 app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.10-x86_64-linux app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.10-x86_64-darwin app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.10-x64-mingw32 app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.10-x64-mingw-ucrt app/components/ariadne/pill_component.rb
ariadne_view_components-0.0.10-arm64-darwin app/components/ariadne/pill_component.rb