Skip to content

Commit

Permalink
add field group component
Browse files Browse the repository at this point in the history
  • Loading branch information
woylie committed Dec 26, 2023
1 parent 0d06b39 commit e5c549f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
42 changes: 42 additions & 0 deletions lib/doggo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,48 @@ defmodule Doggo do
end
end

@doc """
Use the field group component to visually group multiple inputs in a form.
This component is intended for styling purposes and does not provide semantic
grouping. For semantic grouping of related form elements, use the `<fieldset>`
and `<legend>` HTML elements instead.
## Examples
Visual grouping of inputs:
<.field_group>
<.input field={@form[:given_name]} label="Given name" />
<.input field={@form[:family_name]} label="Family name"/>
</.field_group>
Semantic grouping (for reference):
<fieldset>
<legend>Personal Information</legend>
<.input field={@form[:given_name]} label="Given name" />
<.input field={@form[:family_name]} label="Family name"/>
</fieldset>
"""
@doc type: :component

attr :class, :any,
default: [],
doc: "Additional CSS classes. Can be a string or a list of strings."

attr :rest, :global, doc: "Any additional HTML attributes."

slot :inner_block, required: true

def field_group(assigns) do
~H"""
<div class={["field-group" | List.wrap(@class)]} {@rest}>
<%= render_slot(@inner_block) %>
</div>
"""
end

@doc """
Renders a modal.
Expand Down
28 changes: 28 additions & 0 deletions priv/storybook/components/field_group.story.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule Storybook.Components.FieldGroup do
use PhoenixStorybook.Story, :component

def function, do: &Doggo.field_group/1

def template do
"""
<Phoenix.Component.form for={%{}} as={:story} :let={f}>
<.lsb-variation />
</Phoenix.Component.form>
"""
end

def variations do
[
%Variation{
id: :default,
attributes: %{},
slots: [
"""
<Doggo.input type="text" field={f[:given_name]} label="Given name" />
<Doggo.input type="text" field={f[:family_name]} label="Family name" />
"""
]
}
]
end
end

0 comments on commit e5c549f

Please sign in to comment.