-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
964e0d7
commit cd299c9
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |