Skip to content

Add strata_link_to and strata_button_to view helpers#359

Merged
MichaelCrawfordNava merged 4 commits into
mainfrom
cael/uswds-button-helpers
May 28, 2026
Merged

Add strata_link_to and strata_button_to view helpers#359
MichaelCrawfordNava merged 4 commits into
mainfrom
cael/uswds-button-helpers

Conversation

@MichaelCrawfordNava

Copy link
Copy Markdown
Contributor

Changes

  • Adds Strata::LinksHelper with strata_link_to. Defaults to a pure passthrough to Rails' link_to. Pass as: :button to opt into USWDS button styling, with the same :variant, :size, :inverse keywords as ButtonComponent.
  • Adds Strata::ButtonsHelper with strata_button_to. Wraps Rails' button_to and always applies USWDS button styling — button_to is unambiguously about producing a CSRF-protected form-wrapped button.
  • Both modules included via Strata::ApplicationHelper so the helpers are auto-available in any view rendered by Strata-using controllers.
  • New docs/strata-view-helpers.md with full usage docs.
  • Registers the new doc in docs/README.md and CLAUDE.md.
  • docs/uswds-components.md "Button" section now cross-links to the new helpers doc.
  • Updates ButtonComponent / ButtonGroupComponent doc 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:

  • Why strata_link_to has an :as switch and a passthrough default. An earlier iteration had strata_link_to always apply button styling, which was misleading — `link_to` shouldn't always imply button. The :as discriminator makes the styling explicit and leaves room for future treatments (e.g., as: :external).
  • Why two modules instead of one. `strata_link_to` has a passthrough mode that produces a plain link, so it doesn't belong in a "Buttons" module. Splitting by topic matches the engine's existing one-module-per-helper pattern (DateHelper, CasesHelper, TasksHelper).
  • Why there's no 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.
  • Validation behavior: strata_link_to raises ArgumentError when :variant / :size / :inverse are passed without as: :button. Catches the "forgot to opt in" mistake; without this check the styling would silently disappear. Also raises on an unrecognized :as value (currently :button is 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

$ make lint-ci
355 files inspected, no offenses detected

$ make test
1401 examples, 0 failures

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: :button mode (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, preserved button_to options (:method, :params), validation, and that the output class string matches ButtonComponent.css_classes for the same keywords.

MichaelCrawfordNava and others added 2 commits May 26, 2026 12:02
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: :button opt-in styling + validation).
  • Introduces Strata::ButtonsHelper#strata_button_to (always USWDS-styled) and includes both helpers via Strata::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.

Comment thread docs/uswds-components.md Outdated
Comment thread docs/strata-view-helpers.md Outdated
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>
@MichaelCrawfordNava MichaelCrawfordNava marked this pull request as ready for review May 27, 2026 23:42

@lamroger-nava lamroger-nava left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm cool with this - are there any places we can use this immediately? Oh nvm - it's in the next PR

Base automatically changed from cael/uswds-button-component to main May 28, 2026 01:03
@MichaelCrawfordNava

Copy link
Copy Markdown
Contributor Author

@claude will you please merge main into this branch and resolve conflicts?

@claude

claude Bot commented May 28, 2026

Copy link
Copy Markdown

Claude finished @MichaelCrawfordNava's task in 4m 3s —— View job


Merged origin/main into cael/uswds-button-helpers

  • Fetch latest from origin (had to --unshallow first — initial fetch was shallow with no common ancestor)
  • Merge origin/main into the branch
  • Resolve conflicts in 4 files
  • Run make lint-ci — clean (355 files, 0 offenses)
  • Run make test — green (1401 examples, 0 failures)
  • Push merge commit 374de10

Conflict resolutions

Main brought in #358 as a single squashed commit (3e34ee2 Add uswds button and buttongroup components) that overlapped with this branch's button work. Resolutions:

  • app/components/strata/us/button_component.rb — docstring-only conflict. Kept HEAD: it documents the new strata_link_to / strata_button_to helpers added in this PR, which is the whole point.
  • app/components/strata/us/button_group_component.rb — docstring-only conflict in the @example. Kept HEAD: shows the new strata_link_to ..., as: :button form.
  • app/previews/strata/us/button_group_component_preview.rb — adopted origin/main's template-backed approach. Main moved from inline html_safe class-string examples to sibling default.html.erb / segmented.html.erb templates (which were also added by the merge), because nested render calls don't work inside slot blocks in a Lookbook preview method. The template approach is cleaner and uses ButtonComponent directly.
  • docs/uswds-components.md — kept HEAD's helper-aware structure (recommends helpers for link_to/button_to, css_classes for form.button / f.submit), and brought back the FormBuilder#submit example block from origin/main since that detail is still accurate and useful.
    • Branch: cael/uswds-button-helpers • Merge commit: 374de10

…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
@MichaelCrawfordNava MichaelCrawfordNava merged commit 96977c9 into main May 28, 2026
2 checks passed
@MichaelCrawfordNava MichaelCrawfordNava deleted the cael/uswds-button-helpers branch May 28, 2026 01:42
@MichaelCrawfordNava MichaelCrawfordNava linked an issue May 28, 2026 that may be closed by this pull request
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

USWDS Button Component

3 participants