Add strata_link_to and strata_button_to view helpers#359
Merged
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>
3 tasks
There was a problem hiding this comment.
Pull request overview
Adds Strata view-helper wrappers around Rails link_to / button_to to standardize USWDS button styling via Strata::US::ButtonComponent.css_classes, with accompanying documentation and helper specs.
Changes:
- Introduces
Strata::LinksHelper#strata_link_to(passthrough by default;as: :buttonopt-in styling + validation). - Introduces
Strata::ButtonsHelper#strata_button_to(always USWDS-styled) and includes both helpers viaStrata::ApplicationHelper. - Adds/updates docs and RSpec coverage for the new helpers, and refreshes component doc comments to reference them.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/helpers/strata/links_helper_spec.rb | Adds RSpec coverage for strata_link_to passthrough, button treatment, class merging, and validation. |
| spec/helpers/strata/buttons_helper_spec.rb | Adds RSpec coverage for strata_button_to structure, modifiers, option forwarding, and css class parity. |
| docs/uswds-components.md | Updates Button docs to point to the new helpers and clarifies when to use css_classes. |
| docs/strata-view-helpers.md | New documentation page describing strata_link_to / strata_button_to usage and behavior. |
| docs/README.md | Registers the new view helpers documentation in the docs index. |
| CLAUDE.md | Adds the new view helpers doc to the SDK-specific docs table. |
| app/helpers/strata/links_helper.rb | Implements strata_link_to with as: treatments and argument validation. |
| app/helpers/strata/buttons_helper.rb | Implements strata_button_to wrapper applying ButtonComponent.css_classes. |
| app/helpers/strata/application_helper.rb | Includes the new helper modules so they’re available in Strata views. |
| app/components/strata/us/button_group_component.rb | Updates inline example to use strata_link_to ..., as: :button. |
| app/components/strata/us/button_component.rb | Updates doc comments to reference the new helpers and positioning of css_classes. |
Addresses CoPilot review feedback on #359: - docs/uswds-components.md: the "Helpers and css_classes" subsection listed form.button and f.submit alongside link_to/button_to as cases for the view helpers, but the helpers only wrap link_to and button_to. Reworded so each tool maps to the call sites it actually covers — helpers for link_to/button_to, css_classes for form.button and non-Strata f.submit. - docs/strata-view-helpers.md: heading was "Components" (confusing alongside the SDK's ViewComponents). Renamed to "Helpers." Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
lamroger-nava
approved these changes
May 28, 2026
Contributor
Author
|
@claude will you please merge main into this branch and resolve conflicts? |
|
Claude finished @MichaelCrawfordNava's task in 4m 3s —— View job Merged
|
…pers # Conflicts: # app/components/strata/us/button_component.rb # app/components/strata/us/button_group_component.rb # app/previews/strata/us/button_group_component_preview.rb # docs/uswds-components.md
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Strata::LinksHelperwithstrata_link_to. Defaults to a pure passthrough to Rails'link_to. Passas: :buttonto opt into USWDS button styling, with the same:variant,:size,:inversekeywords asButtonComponent.Strata::ButtonsHelperwithstrata_button_to. Wraps Rails'button_toand always applies USWDS button styling —button_tois unambiguously about producing a CSRF-protected form-wrapped button.Strata::ApplicationHelperso the helpers are auto-available in any view rendered by Strata-using controllers.docs/strata-view-helpers.mdwith full usage docs.docs/README.mdandCLAUDE.md.docs/uswds-components.md"Button" section now cross-links to the new helpers doc.ButtonComponent/ButtonGroupComponentdoc comments to mention the helpers.Context
Ergonomic wrappers around Rails' link/button primitives. They use
Strata::US::ButtonComponent.css_classes(introduced in the parent PR) as the single source of truth for class strings — so the FormBuilder, the helpers, and any direct caller all produce the same output.Design notes worth flagging for reviewers:
strata_link_tohas an:asswitch and a passthrough default. An earlier iteration hadstrata_link_toalways apply button styling, which was misleading — `link_to` shouldn't always imply button. The:asdiscriminator makes the styling explicit and leaves room for future treatments (e.g.,as: :external).DateHelper,CasesHelper,TasksHelper).strata_button_link_to/strata_link_to_button. `strata_link_to ..., as: :button` covers the button-styled-link case. Avoiding a third helper keeps the surface area small.strata_link_toraisesArgumentErrorwhen:variant/:size/:inverseare passed withoutas: :button. Catches the "forgot to opt in" mistake; without this check the styling would silently disappear. Also raises on an unrecognized:asvalue (currently:buttonis the only allowed treatment).This PR stacks on #358 (
cael/uswds-button-component). The follow-up adoption PR on top migrates all existing call sites to use these helpers.Testing
Test plan:
bundle exec rspec spec/helpers/strata/links_helper_spec.rb— 14 examples cover passthrough mode (plain link, html_options forwarding, block form),as: :buttonmode (each modifier, class merging, html_options, block form, invalid variant), and the validation paths (variant/size/inverse without:as, unknown:as).bundle exec rspec spec/helpers/strata/buttons_helper_spec.rb— 8 examples cover the rendered form/button structure, each modifier, class merging, preservedbutton_tooptions (:method,:params), validation, and that the output class string matchesButtonComponent.css_classesfor the same keywords.