Skip to content

Commit 24b4c17

Browse files
Merge remote-tracking branch 'origin/main' into cael/uswds-button-adoption
# Conflicts: # app/components/strata/flows/task_list_component.html.erb # app/components/strata/flows/task_section_component.rb # app/components/strata/us/card_component.rb # app/previews/strata/us/button_group_component_preview.rb # app/previews/strata/us/card_component_preview.rb # app/previews/strata/us/card_group_component_preview.rb # app/views/strata/application_forms/index.html.erb # app/views/strata/shared/_form_buttons.html.erb # app/views/strata/tasks/index.html.erb # docs/strata-view-helpers.md # docs/uswds-components.md # spec/dummy/app/views/passport_application_forms/show.html.erb # spec/dummy/app/views/sample_application_forms/_form_buttons.html.erb # spec/dummy/app/views/sample_application_forms/new.html.erb # spec/dummy/app/views/sample_application_forms/review.html.erb # spec/dummy/app/views/tasks/details/_passport_photo_task.html.erb # spec/dummy/app/views/tasks/details/_passport_verify_info_task.html.erb # spec/dummy/app/views/tasks/show.html.erb
2 parents d6f999c + 96977c9 commit 24b4c17

5 files changed

Lines changed: 33 additions & 26 deletions

File tree

app/previews/strata/us/button_group_component_preview.rb

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,12 @@ class ButtonGroupComponentPreview < Lookbook::Preview
77
layout "strata/component_preview"
88

99
# @label Default
10-
def default
11-
render Strata::US::ButtonGroupComponent.new do |group|
12-
group.with_item do
13-
%(<button class="#{Strata::US::ButtonComponent.css_classes}">Save</button>).html_safe
14-
end
15-
group.with_item do
16-
%(<button class="#{Strata::US::ButtonComponent.css_classes(variant: :outline)}">Cancel</button>).html_safe
17-
end
18-
end
19-
end
10+
# Renders via the sibling `default.html.erb` template — nested `render` calls don't work inside slot blocks in a Lookbook preview method.
11+
def default; end
2012

2113
# @label Segmented
22-
def segmented
23-
render Strata::US::ButtonGroupComponent.new(segmented: true) do |group|
24-
group.with_item do
25-
%(<button class="#{Strata::US::ButtonComponent.css_classes}">Map</button>).html_safe
26-
end
27-
group.with_item do
28-
%(<button class="#{Strata::US::ButtonComponent.css_classes}">Satellite</button>).html_safe
29-
end
30-
group.with_item do
31-
%(<button class="#{Strata::US::ButtonComponent.css_classes}">Hybrid</button>).html_safe
32-
end
33-
end
34-
end
14+
# Renders via the sibling `segmented.html.erb` template — nested `render` calls don't work inside slot blocks in a Lookbook preview method.
15+
def segmented; end
3516
end
3617
end
3718
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<%= render Strata::US::ButtonGroupComponent.new do |group| %>
2+
<% group.with_item do %>
3+
<%= render(Strata::US::ButtonComponent.new) { "Save" } %>
4+
<% end %>
5+
<% group.with_item do %>
6+
<%= render(Strata::US::ButtonComponent.new(variant: :outline)) { "Cancel" } %>
7+
<% end %>
8+
<% end %>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<%= render Strata::US::ButtonGroupComponent.new(segmented: true) do |group| %>
2+
<% group.with_item do %>
3+
<%= render(Strata::US::ButtonComponent.new) { "Map" } %>
4+
<% end %>
5+
<% group.with_item do %>
6+
<%= render(Strata::US::ButtonComponent.new) { "Satellite" } %>
7+
<% end %>
8+
<% group.with_item do %>
9+
<%= render(Strata::US::ButtonComponent.new) { "Hybrid" } %>
10+
<% end %>
11+
<% end %>

docs/strata-view-helpers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Strata ships a small set of Rails view helpers that wrap common Rails primitives and apply USWDS-aware styling. They're auto-included in any view rendered through Strata-using controllers (via `Strata::ApplicationHelper`), so you can use them without explicit `include` calls.
44

5-
## Components
5+
## Helpers
66

77
1. [`strata_link_to`](#strata_link_to) — Rails `link_to` with opt-in styling treatments
88
2. [`strata_button_to`](#strata_button_to) — Rails `button_to` with USWDS button styling

docs/uswds-components.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,16 @@ Any other keyword arguments are forwarded as HTML attributes on the rendered ele
164164

165165
### Helpers and `css_classes`
166166

167-
For Rails-rendered tags (`link_to`, `button_to`, `form.button`, `f.submit`), use the Strata view helpers — `strata_link_to ..., as: :button` and `strata_button_to` — instead of rendering this component. See [strata-view-helpers.md](./strata-view-helpers.md).
167+
For `link_to` and `button_to` call sites, use the Strata view helpers — `strata_link_to ..., as: :button` and `strata_button_to` — instead of rendering this component. See [strata-view-helpers.md](./strata-view-helpers.md).
168168

169-
The class-method helper `Strata::US::ButtonComponent.css_classes(variant:, size:, inverse:)` returns the bare USWDS class string and is the single source of truth used by all of the above. Reach for it when neither the component nor the view helpers fit.
169+
For `form.button`, a non-Strata `f.submit`, or any other call site where Rails owns the tag and no helper fits, use the class-method helper `Strata::US::ButtonComponent.css_classes(variant:, size:, inverse:)` directly. It returns the bare USWDS class string and is the single source of truth used by the component, the helpers, and `FormBuilder#submit`.
170+
171+
The Strata form builder's `f.submit` already delegates to this helper internally and accepts the same `:variant` and `:big` options:
172+
173+
```erb
174+
<%= f.submit "Save draft", variant: :outline %>
175+
<%= f.submit "Apply", big: true %>
176+
```
170177

171178
---
172179

0 commit comments

Comments
 (0)