Sha256: 2c96a348a42d75bf03d68565cc0903bd275e34f9f3099172ec63c7d4408acaf4

Contents?: true

Size: 1.29 KB

Versions: 66

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Ariadne
  # Renders a spinning wheel to indicate a loading state
  # Add color using a tailwind text color class
  class SpinnerComponent < Ariadne::Component
    DEFAULT_SIZE = :md
    DEFAULT_CLASSES = "ariadne-animate-spin ariadne-fill-none"
    DEFAULT_ATTRIBUTES = {
      fill: "none",
      viewBox: "0 0 16 16",
      role: "progressbar",
      "aria-valuetext": "Loading...",
      "aria-busy": true,
      "aria-valuemin": "0",
      "aria-valuemax": "100",
    }.freeze

    SIZE_CLASS_MAPPINGS = {
      xs: "ariadne-h-4 ariadne-w-4",
      sm: "ariadne-h-6 ariadne-w-6",
      md: "ariadne-h-8 ariadne-w-8",
      lg: "ariadne-h-10 ariadne-w-10",
      xl: "ariadne-h-12 ariadne-w-12",
    }.freeze

    VALID_SIZES = SIZE_CLASS_MAPPINGS.keys.freeze

    # @example Default
    #
    #   <%= render(Ariadne::SpinnerComponent.new) { } %>
    #
    # @param classes [String] <%= link_to_classes_docs %>
    # @param attributes [Hash] <%= link_to_attributes_docs %>
    def initialize(classes: "", attributes: {}, size: DEFAULT_SIZE)
      @size = fetch_or_raise(VALID_SIZES, size)
      @attributes = DEFAULT_ATTRIBUTES.merge(attributes)
      @classes = merge_class_names(
        DEFAULT_CLASSES,
        SIZE_CLASS_MAPPINGS[size],
        classes,
      )
    end
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.59-x64-mingw-ucrt app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.59-aarch64-linux app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.59-x86_64-darwin app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.59-x86_64-linux app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.59-arm64-darwin app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.59 app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.58-x86_64-darwin app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.58-aarch64-linux app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.58-arm64-darwin app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.58-x64-mingw-ucrt app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.58 app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.58-x86_64-linux app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.57-arm64-darwin app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.57-aarch64-linux app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.57-x86_64-darwin app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.57-x86_64-linux app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.57-x64-mingw-ucrt app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.57 app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.55-x86_64-linux app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.55-arm64-darwin app/components/ariadne/spinner_component.rb