Skip to content

Commit fc20756

Browse files
committed
Add fieldset group form
1 parent 8bb7053 commit fc20756

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<%= render(Primer::BaseComponent.new(**@system_arguments)) do %>
2+
<%= render(Primer::OpenProject::Fieldset.new(**@fieldset_arguments)) do %>
3+
<%=
4+
render(Primer::Beta::Subhead.new) do |component|
5+
component.with_heading(**@heading_arguments).with_content(@title)
6+
end
7+
%>
8+
<%= render(Primer::Forms::Group.new(**@group_arguments)) %>
9+
<% end %>
10+
<% end %>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# frozen_string_literal: true
2+
3+
module Primer
4+
module Forms
5+
# :nodoc:
6+
class FieldsetGroup < BaseComponent
7+
##
8+
# @param title [String] The title displayed as the heading for the fieldset
9+
# @param inputs [Array<Primer::Forms::Dsl::Input>] Array of form inputs to be grouped
10+
# @param builder [ActionView::Helpers::FormBuilder] The form builder instance
11+
# @param form [Primer::Forms::BaseForm] The form object
12+
# @param layout [Symbol] Layout style for the input group (default: :default_layout)
13+
# @param heading_arguments [Hash] Arguments passed to the heading component
14+
# @option heading_arguments [String] :id The ID for the heading element
15+
# @option heading_arguments [Symbol] :tag The HTML tag for the heading (default: :h3)
16+
# @option heading_arguments [Symbol] :size The size of the heading (default: :medium)
17+
# @param group_arguments [Hash] Arguments passed to the input group component
18+
# @param system_arguments [Hash] Additional system arguments passed to the section wrapper
19+
def initialize( # rubocop:disable Metrics/AbcSize
20+
title:,
21+
inputs:,
22+
builder:,
23+
form:,
24+
layout: Primer::Forms::Group::DEFAULT_LAYOUT,
25+
heading_arguments: {},
26+
group_arguments: {},
27+
**system_arguments
28+
)
29+
super()
30+
31+
@title = title
32+
33+
@heading_arguments = heading_arguments
34+
@heading_arguments[:id] ||= "subhead-#{SecureRandom.uuid}"
35+
@heading_arguments[:tag] ||= :h3
36+
@heading_arguments[:size] ||= :medium
37+
38+
@fieldset_arguments = {
39+
legend_text: @title,
40+
visually_hide_legend: true,
41+
aria: { labelledby: @heading_arguments[:id] }
42+
}
43+
@group_arguments = group_arguments.merge(inputs:, builder:, form:, layout:)
44+
45+
@system_arguments = system_arguments
46+
@system_arguments[:tag] = :section
47+
@system_arguments[:mb] ||= 4
48+
@system_arguments[:aria] ||= {}
49+
@system_arguments[:aria][:labelledby] = @heading_arguments[:id]
50+
@system_arguments[:hidden] = :none if inputs.all?(&:hidden?)
51+
end
52+
end
53+
end
54+
end

0 commit comments

Comments
 (0)