Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/assets/stylesheets/cfa_ui_components.tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ a:visited {
@apply bg-white border-2 text-black;
}

.btn--destructive {
@apply bg-white border-2 border-red-700 text-red-700;
}

.btn--small {
@apply px-3 py-2;
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/button_link_component.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= link_to @label, @url, class: "btn btn--large #{@button_style}" %>
<%= button_to @label, @url, class: "btn btn--large #{@button_style}", method: @method, form: {data: {turbo: @turbo}} %>
23 changes: 14 additions & 9 deletions app/components/button_link_component.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# frozen_string_literal: true

class ButtonLinkComponent < ViewComponent::Base
def initialize(label:, url:, style: :primary)
def initialize(label:, url:, style: :primary, method: :get, turbo: true)
@label = label
@url = url
@button_style = case style
when :primary
"btn--primary"
when :secondary
"btn--secondary"
else
raise ArgumentError("Invalid button style")
end
@button_style =
case style
when :primary
"btn--primary"
when :secondary
"btn--secondary"
when :destructive
"btn--destructive"
else
raise ArgumentError("Invalid button style")
end
@method = method
@turbo = turbo
end
end
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ en:
back: Go back
continue: Continue
decline: Decline
remove: Remove
first_name: First name
last_name: Last name
submit: Submit
1 change: 1 addition & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ es:
back: Regresa
continue: Continuar
decline: Rechazar
remove: Eliminar
first_name: Primer nombre
last_name: Apellido
submit: Enviar
6 changes: 5 additions & 1 deletion test/components/previews/button_link_component_preview.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
class ButtonLinkComponentPreview < ViewComponent::Preview
def primary
render(ButtonLinkComponent.new(label: I18n.t("continue"), url: "/continue"))
render(ButtonLinkComponent.new(label: I18n.t("continue"), url: "https://www.google.com", turbo: false))
end

def secondary
render(ButtonLinkComponent.new(label: I18n.t("decline"), url: "/decline", style: :secondary))
end

def destructive
render(ButtonLinkComponent.new(label: I18n.t("remove"), url: "/destroy", style: :destructive, method: :post))
end
end