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.52 app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.52-x64-mingw-ucrt app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.51-x64-mingw-ucrt app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.51-x86_64-darwin app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.51-arm64-darwin app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.51-aarch64-linux app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.51 app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.51-x86_64-linux app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.50 app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.50-arm64-darwin app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.50-x64-mingw-ucrt app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.50-x86_64-darwin app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.50-x86_64-linux app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.50-aarch64-linux app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.49-aarch64-linux app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.49-x86_64-darwin app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.49-x86_64-linux app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.49-arm64-darwin app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.49-x64-mingw-ucrt app/components/ariadne/spinner_component.rb
ariadne_view_components-0.0.49 app/components/ariadne/spinner_component.rb