-
Notifications
You must be signed in to change notification settings - Fork 0
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
f5516c8
commit b8c8612
Showing
6 changed files
with
109 additions
and
50 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
30 changes: 25 additions & 5 deletions
30
...tylesheets/components/_button_primary.css → ...lesheets/components/_button_component.css
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 |
---|---|---|
@@ -1,19 +1,39 @@ | ||
.button-primary { | ||
background-color: var(--primary-600); | ||
color: var(--primary-50); | ||
.button { | ||
border-radius: var(--rounded-lg); | ||
letter-spacing: var(--spacing-lg); | ||
font-size: var(--text-sm); | ||
text-transform: uppercase; | ||
border: none; | ||
font-weight: var(--font-bold); | ||
padding: var(--padding-xs) var(--padding-md); | ||
margin-bottom: var(--padding-md); | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.button-primary svg { | ||
.button svg { | ||
padding-left: var(--padding-sm); | ||
} | ||
|
||
|
||
|
||
/* Primary Button */ | ||
.button-primary { | ||
background-color: var(--primary-600); | ||
color: var(--primary-50); | ||
border: none; | ||
} | ||
|
||
.button-primary svg { | ||
fill: var(--primary-300); | ||
} | ||
|
||
/* Secondary Button */ | ||
.button-secondary { | ||
background-color: transparent; | ||
color: var(--primary-100); | ||
border: 2px solid var(--primary-100); | ||
} | ||
|
||
.button-secondary svg { | ||
fill: var(--primary-500); | ||
} |
This file was deleted.
Oops, something went wrong.
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
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,69 @@ | ||
# frozen_string_literal: true | ||
|
||
class ButtonComponent < ViewComponent::Base | ||
include ApplicationHelper | ||
|
||
erb_template <<-ERB | ||
<%= button_to( | ||
@path, | ||
method: @method, | ||
class: button_class, | ||
'aria-label': @aria_label, | ||
data: @data, | ||
form: @form, | ||
) do %> | ||
<%= @label %> | ||
<% if @action %> | ||
<%= svg_icon_tag button_action_icon %> | ||
<% end %> | ||
<% end %> | ||
ERB | ||
|
||
def initialize( | ||
label:, | ||
path:, | ||
method: :get, | ||
class_name: '', | ||
aria_label: nil, | ||
data: { turbo: false }, | ||
form: {}, | ||
button_type: :primary, | ||
action: nil | ||
) | ||
@label = label | ||
@path = path | ||
@method = method | ||
@class_name = class_name | ||
@aria_label = aria_label || label | ||
@data = data | ||
@form = form | ||
@button_type = button_type | ||
@action = action | ||
end | ||
|
||
def button_class | ||
base_class = 'button' | ||
type_class = case @button_type | ||
when :primary | ||
'button-primary' | ||
when :secondary | ||
'button-secondary' | ||
else | ||
'' | ||
end | ||
[base_class, type_class, @class_name].compact.join(' ') | ||
end | ||
|
||
def button_action_icon | ||
case @action | ||
when :add | ||
'icon_plus' | ||
when :edit | ||
'icon_edit' | ||
when :delete | ||
'icon_delete' | ||
else | ||
'' | ||
end | ||
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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class ButtonComponentTest < ViewComponent::TestCase | ||
def test_component_renders_something_useful | ||
# assert_equal( | ||
# %(<span>Hello, components!</span>), | ||
# render_inline(ButtonComponent.new(message: "Hello, components!")).css("span").to_html | ||
# ) | ||
end | ||
end |