From 9697967ae2bec83b8afcf2ddb7a4ee661b204042 Mon Sep 17 00:00:00 2001 From: Zee <50284+zspencer@users.noreply.github.com> Date: Sun, 25 Jun 2023 12:37:47 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=F0=9F=A5=94=20`Components`:=20Expose?= =?UTF-8?q?=20`ButtonComponent#danger`=20variant=20(#1596)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨🥔 `Components`: Expose ButtonComponent#danger variant - https://github.com/zinc-collective/convene/issues/1187 As part of https://github.com/zinc-collective/convene/pull/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. --- app/components/button_component.rb | 13 ++++++++++++- spec/components/button_component_spec.rb | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/components/button_component.rb b/app/components/button_component.rb index 139c0b9c1..406f7a026 100644 --- a/app/components/button_component.rb +++ b/app/components/button_component.rb @@ -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( @@ -61,6 +62,7 @@ def base_classes "shadow-sm", "ring-1", "ring-inset", + "text-center", "no-underline", "focus-visible:outline", "focus-visible:outline-2", @@ -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", diff --git a/spec/components/button_component_spec.rb b/spec/components/button_component_spec.rb index acbc8d03f..9e044e4d0 100644 --- a/spec/components/button_component_spec.rb +++ b/spec/components/button_component_spec.rb @@ -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