Skip to content

Commit

Permalink
✨🥔 Components: Expose ButtonComponent#danger variant (#1596)
Browse files Browse the repository at this point in the history
* ✨🥔 `Components`: Expose ButtonComponent#danger variant

- #1187

As part of #1592 I needed
a Button that used the `dange` variant and all the turbo-y goodness.

So I pulled a variant into the `ButtonComponent`; and then we can search
for `--danger` and purge them.
  • Loading branch information
zspencer authored Jun 25, 2023
1 parent 51ff6f3 commit 9697967
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/components/button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
class ButtonComponent < ApplicationComponent
SCHEME_MAPPINGS = {
primary: :primary_classes,
secondary: :secondary_classes
secondary: :secondary_classes,
danger: :danger_classes
}.with_indifferent_access.freeze

def initialize(
Expand Down Expand Up @@ -61,6 +62,7 @@ def base_classes
"shadow-sm",
"ring-1",
"ring-inset",
"text-center",
"no-underline",
"focus-visible:outline",
"focus-visible:outline-2",
Expand All @@ -79,6 +81,15 @@ def secondary_classes
]
end

def danger_classes
[
"bg-danger-500",
"hover:bg-danger-700",
"active:bg-danger-200",
"text-white"
]
end

def primary_classes
[
"bg-purple-600",
Expand Down
6 changes: 6 additions & 0 deletions spec/components/button_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,11 @@
expect(output.at_css("span").text).to eq("Some label")
end
end

context "when the scheme is `:danger`" do
let(:component) { described_class.new(**params.merge({scheme: :danger})) }

it { expect(output.at_css(".bg-danger-500")).to be_present }
end
end
end

0 comments on commit 9697967

Please sign in to comment.