Adopt button component + helpers at existing call sites#360
Conversation
Introduces two new ViewComponents in the Strata::US namespace: - Strata::US::ButtonComponent renders a USWDS-styled <button> or, when given an href:, an <a>. Supports variant, size, inverse, disabled, and type. Exposes a .css_classes class method that returns the bare USWDS class string for use at call sites where Rails owns the element rendering (button_to, link_to, form.button, f.submit). - Strata::US::ButtonGroupComponent renders <ul class="usa-button-group"> with each entry wrapped in <li class="usa-button-group__item">. Supports the segmented variant. Refactors FormBuilder#submit to delegate to ButtonComponent.css_classes and gain a :variant option for non-primary submit buttons; the existing :big option and margin-y-6 spacing are preserved. Includes Lookbook previews, specs, and docs/uswds-components.md sections for both components. Follow-up PRs will add view helpers (strata_link_to / strata_button_to) and migrate existing call sites. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Introduces two view helpers in Strata::ApplicationHelper that wrap Rails' link_to / button_to and apply USWDS styling via Strata::US::ButtonComponent: - strata_link_to (in Strata::LinksHelper) defaults to a pure passthrough to link_to. Pass `as: :button` to opt into button styling, with the same :variant, :size, :inverse keywords as the component. Raises ArgumentError if :variant/:size/:inverse are passed without `as: :button` (catches "forgot to opt in" mistakes) or on an unrecognized :as value. - strata_button_to (in Strata::ButtonsHelper) wraps Rails' button_to and always applies USWDS button styling — button_to is unambiguously about producing a CSRF-protected form-wrapped button. Includes new docs/strata-view-helpers.md, registers it in docs/README.md and CLAUDE.md, and cross-links from the Button section in docs/uswds-components.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Migrates every hand-written usa-button / usa-button-group call site in the engine and dummy app to use the new Strata::US::ButtonComponent, Strata::US::ButtonGroupComponent, strata_link_to, and strata_button_to. - link_to with usa-button class → strata_link_to ..., as: :button - button_to with usa-button class → strata_button_to - form.button / non-Strata f.submit → class: Strata::US::ButtonComponent.css_classes(...) - f.submit "...", class: "usa-button" inside strata_form_with → drop the redundant class (FormBuilder adds it) - <ul class="usa-button-group"> blocks → render Strata::US::ButtonGroupComponent - Inline <button class="usa-button"> in card previews → interpolated ButtonComponent.css_classes (Lookbook nested-render limitation) - Doc-comment examples in card_component.rb updated to reference the new component Also fixes a small markup bug at a few sites that were missing the usa-button-group__item class on the <li> wrappers — the component now guarantees the correct structure. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Migrates existing USWDS button and button-group call sites across the Strata engine and dummy app to use the centralized Strata::US::ButtonComponent / Strata::US::ButtonGroupComponent and the strata_link_to / strata_button_to helpers, reducing repeated class strings and standardizing markup.
Changes:
- Replaces hand-written
usa-button/usa-button-groupmarkup withstrata_link_to,strata_button_to, andStrata::US::ButtonGroupComponentusages. - Updates card docs/comments and Lookbook previews to reference the new button component styling source of truth (
ButtonComponent.css_classes). - Normalizes button group structure so items are consistently wrapped with
usa-button-group__item.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| app/views/strata/shared/_form_buttons.html.erb | Moves form navigation buttons into ButtonGroupComponent + strata_link_to. |
| app/views/strata/tasks/index.html.erb | Migrates “Pick up next task” to strata_button_to. |
| app/views/strata/application_forms/index.html.erb | Migrates “New” action to strata_link_to(..., as: :button). |
| app/components/strata/flows/task_section_component.rb | Uses helpers.strata_link_to for task action buttons. |
| app/components/strata/flows/task_list_component.html.erb | Migrates review/submit action to strata_button_to. |
| app/components/strata/us/card_component.rb | Updates doc-comment example to use ButtonComponent. |
| app/previews/strata/us/card_component_preview.rb | Updates preview footer button markup to use ButtonComponent.css_classes. |
| app/previews/strata/us/card_group_component_preview.rb | Updates preview footer button markup to use ButtonComponent.css_classes. |
| docs/uswds-components.md | Updates Card example to render ButtonComponent directly. |
| spec/dummy/app/views/tasks/details/_passport_verify_info_task.html.erb | Replaces manual <ul>/<li> button group with ButtonGroupComponent + css_classes. |
| spec/dummy/app/views/tasks/details/_passport_photo_task.html.erb | Replaces manual <ul>/<li> button group with ButtonGroupComponent + css_classes. |
| spec/dummy/app/views/tasks/show.html.erb | Migrates “Assign to me” button-styled link to strata_link_to. |
| spec/dummy/app/views/passport_application_forms/show.html.erb | Migrates “Edit application” to strata_link_to(..., as: :button). |
| spec/dummy/app/views/sample_application_forms/review.html.erb | Replaces ad-hoc button group container with ButtonGroupComponent and consistent button classes. |
| spec/dummy/app/views/sample_application_forms/_form_buttons.html.erb | Migrates shared form buttons to ButtonGroupComponent + strata_link_to. |
| spec/dummy/app/views/sample_application_forms/new.html.erb | Migrates initial form buttons to ButtonGroupComponent + strata_link_to. |
|
@claude Please merge main into this branch and resolve conflicts, as needed |
|
Claude finished @MichaelCrawfordNava's task in 3m 48s —— View job Merged
|
…ption # 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
Changes
Migrates every hand-written
usa-button/usa-button-groupcall site in the engine and dummy app to the newStrata::US::ButtonComponent,Strata::US::ButtonGroupComponent,strata_link_to, andstrata_button_to.Net diff: 16 files changed, +72 / -67. Almost entirely mechanical.
Engine:
app/views/strata/shared/_form_buttons.html.erbapp/views/strata/tasks/index.html.erbapp/views/strata/application_forms/index.html.erbapp/components/strata/flows/task_section_component.rbapp/components/strata/flows/task_list_component.html.erbapp/components/strata/us/card_component.rb(doc-comment example)app/previews/strata/us/card_component_preview.rbapp/previews/strata/us/card_group_component_preview.rbdocs/uswds-components.md(Card example)Dummy app:
spec/dummy/app/views/tasks/details/_passport_verify_info_task.html.erbspec/dummy/app/views/tasks/details/_passport_photo_task.html.erbspec/dummy/app/views/tasks/show.html.erbspec/dummy/app/views/passport_application_forms/show.html.erbspec/dummy/app/views/sample_application_forms/review.html.erbspec/dummy/app/views/sample_application_forms/_form_buttons.html.erbspec/dummy/app/views/sample_application_forms/new.html.erbContext
The final-state PR in the three-PR stack — stacks on #359 (
cael/uswds-button-helpers), which stacks on #358 (cael/uswds-button-component).Migration rules applied:
link_to ..., class: "usa-button ..."strata_link_to ..., as: :button, variant: ...button_to ..., class: "usa-button ..."strata_button_to ..., variant: ...form.buttonor non-Strataf.submitwithclass: "usa-button"class: Strata::US::ButtonComponent.css_classes(...)(Rails owns the tag; no helper fits)f.submit "...", class: "usa-button"insidestrata_form_withclass:— FormBuilder already addsusa-button<ul class="usa-button-group">…</ul><button class="usa-button">in card previewscss_classes(Lookbook nested-render limitation —renderinside a slot block doesn't work in Lookbook previews; see the existing comment inlist_component_preview.rb)Drive-by fix: a few
<li>wrappers inside button groups were missing theusa-button-group__itemclass (_form_buttons.html.erbin both engine and dummy app). The component now guarantees the correct structure.No new specs in this PR — adoption is verified by the existing test suite continuing to pass.
Testing
Test plan:
make testpasses — the existing test suite exercises the migrated views and components.make startand browse the dummy app — touched flows include the sample application form (/sample_application_forms/new,/sample_application_forms/:id/review), passport application form (/passport_application_forms/:id), task index/show pages, and the embedded passport task details. Confirm buttons render visually unchanged.