Skip to content

Commit

Permalink
Add Loading component
Browse files Browse the repository at this point in the history
  • Loading branch information
davidalejandroaguilar committed Aug 16, 2024
1 parent 964e0d7 commit cd299c9
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lib/phlexy_ui/loading.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

module PhlexyUI
class Loading < Base
def initialize(*, as: :span, **)
super(*, **)
@as = as
end

def view_template(&)
generate_classes!(
component_html_class: :loading,
modifiers_map: LOADING_MODIFIERS_MAP,
base_modifiers:,
options:
).then do |classes|
public_send(as, class: classes, **options, &)
end
end

private

LOADING_MODIFIERS_MAP = {
# "sm:loading-spinner"
# "md:loading-spinner"
# "lg:loading-spinner"
spinner: "loading-spinner",
# "sm:loading-dots"
# "md:loading-dots"
# "lg:loading-dots"
dots: "loading-dots",
# "sm:loading-ring"
# "md:loading-ring"
# "lg:loading-ring"
ring: "loading-ring",
# "sm:loading-ball"
# "md:loading-ball"
# "lg:loading-ball"
ball: "loading-ball",
# "sm:loading-bars"
# "md:loading-bars"
# "lg:loading-bars"
bars: "loading-bars",
# "sm:loading-infinity"
# "md:loading-infinity"
# "lg:loading-infinity"
infinity: "loading-infinity"
}.freeze
end
end
27 changes: 27 additions & 0 deletions spec/lib/phlexy_ui/loading_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "spec_helper"

describe PhlexyUI::Loading do
subject(:output) { render described_class.new }

describe "rendering a full loading" do
let(:component) do
Class.new(Phlex::HTML) do
def view_template(&)
render PhlexyUI::Loading.new
end
end
end

subject(:output) do
render component.new
end

it "is expected to match the formatted HTML" do
expected_html = html <<~HTML
<span class="loading"></span>
HTML

is_expected.to eq(expected_html)
end
end
end

0 comments on commit cd299c9

Please sign in to comment.