Skip to content

Commit

Permalink
Add Skeleton component
Browse files Browse the repository at this point in the history
  • Loading branch information
davidalejandroaguilar committed Oct 25, 2024
1 parent 8b5a0c0 commit c2c8e5e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/phlexy_ui/skeleton.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

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

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

private

register_modifiers({})
end
end
35 changes: 35 additions & 0 deletions spec/lib/phlexy_ui/skeleton_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require "spec_helper"

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

describe "rendering a full skeleton" do
let(:component) do
Class.new(Phlex::HTML) do
def view_template(&)
render PhlexyUI::Skeleton.new(
:neutral,
as: :section,
data: {
my: :skeleton
}
) do
"Skeleton"
end
end
end
end

subject(:output) do
render component.new
end

it "is expected to match the formatted HTML" do
expected_html = html <<~HTML
<section class="skeleton" data-my="skeleton">Skeleton</section>
HTML

is_expected.to eq(expected_html)
end
end
end

0 comments on commit c2c8e5e

Please sign in to comment.