View Source Doggo (Doggo v0.5.0)
Collection of Phoenix Components.
Summary
Components
Renders a set of headings that control the visibility of their content sections.
The action bar offers users quick access to primary actions within the application.
The alert component serves as a notification mechanism to provide feedback to the user.
Renders an alert dialog that requires the immediate attention and response of the user.
Renders profile picture, typically to represent a user.
Renders a badge, typically used for drawing attention to elements like notification counts.
Renders a box for a section on the page.
Use the callout to highlight supplementary information related to the main content.
Renders a card in an article
tag, typically used repetitively in a grid or
flex box layout.
Renders a carousel for presenting a sequence of items, such as images or text.
Use the cluster component to visually group children.
Renders a text input with a popup that allows users to select a value from a list of suggestions.
Renders a Date
, DateTime
, or NaiveDateTime
in a <time>
tag.
Renders a DateTime
or NaiveDateTime
in a <time>
tag.
Renders a drawer with a brand
, top
, and bottom
slot.
The fallback component renders a given value unless it is empty, in which case it renders a fallback value instead.
Shows the flash messages as alerts.
Renders a frame with an aspect ratio for images or videos.
Renders a customizable icon using a slot for SVG content.
Renders an icon using an SVG sprite.
Renders an image with an optional caption.
Renders a modal dialog for content such as forms and informational panels.
Renders a header that is specific to the content of the current page.
Renders a list of properties, i.e. key/value pairs.
Renders a group of radio buttons, for example for a toolbar.
Renders a skeleton loader, a placeholder for content that is in the process of loading.
Renders a horizontal or vertical resizable split pane.
Applies a vertical margin between the child elements.
Renders a switch as a button.
Renders a simple table.
Renders tab panels.
Renders a tag, typically used for displaying labels, categories, or keywords.
Renders a Time
, DateTime
, or NaiveDateTime
in a <time>
tag.
Renders a container for a set of controls.
Renders content with a tooltip.
Renders a hierarchical list as a tree.
Renders a tree item within a tree/1
.
Form
Renders the description of an input.
Renders the errors for an input.
Use the field group component to visually group multiple inputs in a form.
Renders a form field including input, label, errors, and description.
Renders the label for an input.
Components
Renders a set of headings that control the visibility of their content sections.
Example
<Doggo.accordion id="dog-breeds">
<:section title="Golden Retriever">
<p>
Friendly, intelligent, great with families. Origin: Scotland. Needs
regular exercise.
</p>
</:section>
<:section title="Siberian Husky">
<p>
Energetic, outgoing, distinctive appearance. Origin: Northeast Asia.
Loves cold climates.
</p>
</:section>
<:section title="Dachshund">
<p>
Playful, stubborn, small size. Origin: Germany. Enjoys sniffing games.
</p>
</:section>
</Doggo.accordion>
Attributes
id
(:string
) (required)expanded
(:atom
) - Defines how the accordion sections are initialized.:all
- All accordion sections are expanded by default.:none
- All accordion sections are hidden by default.:first
- Only the first accordion section is expanded by default.
Defaults to
:all
.heading
(:string
) - The heading level for the section title (trigger). Defaults to"h3"
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.Global attributes are accepted. Any additional HTML attributes.
Slots
section
(required) - Accepts attributes:title
(:string
)
The action bar offers users quick access to primary actions within the application.
It is typically positioned to float above other content.
In Development
The necessary JavaScript for making this component fully functional and accessible will be added in a future version.
Missing features
- Roving tabindex
- Move focus with arrow keys
Example
<Doggo.action_bar>
<:item label="Edit" on_click={JS.push("edit")}>
<Doggo.icon size={:small}><Lucideicons.pencil aria-hidden /></Doggo.icon>
</:item>
<:item label="Move" on_click={JS.push("move")}>
<Doggo.icon size={:small}><Lucideicons.move aria-hidden /></Doggo.icon>
</:item>
<:item label="Archive" on_click={JS.push("archive")}>
<Doggo.icon size={:small}><Lucideicons.archive aria-hidden /></Doggo.icon>
</:item>
</Doggo.action_bar>
Attributes
class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.- Global attributes are accepted. Any additional HTML attributes.
Slots
item
(required) - Accepts attributes:label
(:string
) (required)on_click
(Phoenix.LiveView.JS
) (required)
The alert component serves as a notification mechanism to provide feedback to the user.
For supplementary information that doesn't require the user's immediate
attention, use callout/1
instead.
Examples
Minimal example:
<Doggo.alert id="some-alert"></Doggo.alert>
With title, icon and level:
<Doggo.alert id="some-alert" level={:info} title="Info">
message
<:icon><Heroicon.light_bulb /></:icon>
</Doggo.alert>
Attributes
id
(:string
) (required)level
(:atom
) - Semantic level of the alert. Defaults to:info
.title
(:string
) - An optional title. Defaults tonil
.on_close
(:any
) - JS command to run when the close button is clicked. If not set, no close button is rendered.Defaults to
nil
.close_label
(:any
) - This value will be used as aria label. Consider overriding it in case your app is served in different languages.Defaults to
"close"
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.Global attributes are accepted. Any additional HTML attributes.
Slots
inner_block
(required) - The main content of the alert.icon
- Optional slot to render an icon.
Renders an alert dialog that requires the immediate attention and response of the user.
This component is meant for situations where critical information must be conveyed, and an explicit response is required from the user. It is typically used for confirmation dialogs, warning messages, error notifications, and other scenarios where an immediate decision is necessary.
For non-critical dialogs, such as those containing forms or additional
information, use Doggo.modal/1
instead.
Usage
<Doggo.alert_dialog id="end-session-modal">
<:title>End Training Session Early?</:title>
<p>
Are you sure you want to end the current training session with Bella?
She's making great progress today!
</p>
<:footer>
<Doggo.button phx-click="end-session">
Yes, end session
</Doggo.button>
<Doggo.button phx-click={JS.exec("data-cancel", to: "#end-session-modal")}>
No, continue training
</Doggo.button>
</:footer>
</Doggo.alert_dialog>
To open the dialog, use the show_modal/1
function.
<Doggo.button
phx-click={Doggo.show_modal("end-session-modal")}
aria-haspopup="dialog"
>
show
</Doggo.button>
CSS
To hide the modal when the open
attribute is not set, use the following CSS
styles:
dialog.alert-dialog:not([open]),
dialog.alert-dialog[open="false"] {
display: none;
}
Semantics
While the showModal()
JavaScript function is typically recommended for
managing modal dialog semantics, this component utilizes the open
attribute
to control visibility. This approach is chosen to eliminate the need for
library consumers to add additional JavaScript code. To ensure proper
modal semantics, the aria-modal
attribute is added to the dialog element.
Attributes
id
(:string
) (required)open
(:boolean
) - Initializes the dialog as open. Defaults tofalse
.on_cancel
(Phoenix.LiveView.JS
) - An additionalPhoenix.LiveView.JS
command to execute when the dialog is canceled. This command is executed in addition to closing the dialog. If you only want the dialog to be closed, you don't have to set this attribute.Defaults to
%Phoenix.LiveView.JS{ops: []}
.dismissable
(:boolean
) - When set totrue
, the dialog can be dismissed by clicking a close button or by pressing the escape key.Defaults to
false
.close_label
(:string
) - Aria label for the close button. Defaults to"Close"
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.Global attributes are accepted. Any additional HTML attributes.
Slots
title
(required)inner_block
(required) - The modal body.close
- The content for the 'close' link. Defaults to the word 'close'.footer
Renders profile picture, typically to represent a user.
Example
Minimal example with only the src
attribute:
<Doggo.avatar src="avatar.png" />
Render avatar as a circle:
<Doggo.avatar src="avatar.png" circle />
Use a placeholder image in case the avatar is not set:
<Doggo.avatar src={@user.avatar_url} placeholder={{:src, "fallback.png"}} />
Render an text as the placeholder value:
<Doggo.avatar src={@user.avatar_url} placeholder="A" />
Attributes
src
(:any
) - The URL of the avatar image. Ifnil
, the component will use the value provided in the placeholder attribute.Defaults to
nil
.placeholder
(:any
) - Fallback value to render in case thesrc
attribute isnil
.- For a placeholder image, pass a tuple
{:src, url}
. - For other types of placeholder content, such as text initials or inline SVG, pass the content directly. The component will render this content as-is.
If the placeholder value is set to
nil
, no avatar will be rendered if thesrc
isnil
.Defaults to
nil
.- For a placeholder image, pass a tuple
alt
(:string
) - Use alt text to identify the individual in an avatar if their name or identifier isn't otherwise provided in adjacent text. In contexts where the user's name or identifying information is already displayed alongside the avatar, usealt=""
(the default) to avoid redundancy and treat the avatar as a decorative element for screen readers.Defaults to
""
.size
(:atom
) - Defaults to:normal
.circle
(:boolean
) - Defaults tofalse
.loading
(:string
) - Defaults to"lazy"
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.Global attributes are accepted. Any additional HTML attributes.
Renders a badge, typically used for drawing attention to elements like notification counts.
Examples
<Doggo.badge>8</Doggo.badge>
Attributes
size
(:atom
) - Defaults to:normal
.variant
(:atom
) - Defaults tonil
.
Slots
inner_block
(required)
Renders a box for a section on the page.
Example
Minimal example with only a box body:
<Doggo.box>
<p>This is a box.</p>
</Doggo.box>
With title, banner, action, and footer:
<Doggo.box>
<:title>Profile</:title>
<:banner>
<img src="banner-image.png" alt="" />
</:banner>
<:action>
<Doggo.button_link patch={~p"/profiles/#{@profile}/edit"}>Edit</Doggo.button_link>
</:action>
<p>This is a profile.</p>
<:footer>
<p>Last edited: <%= @profile.updated_at %></p>
</:footer>
</Doggo.box>
Attributes
class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.- Global attributes are accepted. Any additional HTML attributes.
Slots
title
- The title for the box.inner_block
(required) - Slot for the content of the box body.action
- A slot for action buttons related to the box.banner
- A slot that can be used to render a banner image in the header.footer
- An optional slot for the footer.
Use the callout to highlight supplementary information related to the main content.
For information that needs immediate attention of the user, use alert/1
instead.
Example
Standard callout:
<Doggo.callout title="Dog Care Tip">
<p>Regular exercise is essential for keeping your dog healthy and happy.</p>
</Doggo.callout>
Callout with an icon:
<Doggo.callout title="Fun Dog Fact">
<:icon><Heroicons.information_circle /></:icon>
<p>
Did you know? Dogs have a sense of time and can get upset when their
routine is changed.
</p>
</Doggo.callout>
Attributes
id
(:string
) (required)variant
(:atom
) - Defaults to:info
.title
(:string
) - An optional title. Defaults tonil
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.- Global attributes are accepted. Any additional HTML attributes.
Slots
inner_block
(required) - The main content of the alert.icon
- Optional slot to render an icon.
Renders a card in an article
tag, typically used repetitively in a grid or
flex box layout.
Usage
<Doggo.card>
<:image>
<img src="image.png" alt="Picture of a dog dressed in a poncho." />
</:image>
<:header><h2>Dog Fashion Show</h2></:header>
<:main>
The next dog fashion show is coming up quickly. Here's what you need
to look out for.
</:main>
<:footer>
<span>2023-11-15 12:24</span>
<span>Events</span>
</:footer>
</Doggo.card>
Attributes
class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.- Global attributes are accepted. Any additional HTML attributes.
Slots
image
- An optional image slot. The slot content will be rendered within a figure element.header
- The header of the card. You typically want to wrap the header in ah2
orh3
tag, or another header level, depending on the hierarchy on the page.main
- The main content of the card.footer
- A footer of the card, typically containing controls, tags, or meta information.
Renders a carousel for presenting a sequence of items, such as images or text.
In Development
The necessary JavaScript for making this component fully functional and accessible will be added in a future version.
Missing features
- Handle previous/next buttons
- Handle pagination tabs
- Auto rotation
- Disable auto rotation when controls are used
- Disable previous/next button on first/last item.
- Focus management and keyboard support for pagination
Example
<Doggo.carousel label="Our Dogs">
<:previous label="Previous Slide">
<Heroicons.chevron_left />
</:previous>
<:next label="Next Slide">
<Heroicons.chevron_right />
</:next>
<:item label="1 of 3">
<Doggo.image
src="https://github.com/woylie/doggo/blob/main/assets/dog_poncho.jpg?raw=true"
alt="A dog wearing a colorful poncho walks down a fashion show runway."
ratio={{16, 9}}
/>
</:item>
<:item label="2 of 3">
<Doggo.image
src="https://github.com/woylie/doggo/blob/main/assets/dog_poncho.jpg?raw=true"
alt="A dog dressed in a sumptuous, baroque-style costume, complete with jewels and intricate embroidery, parades on an ornate runway at a luxurious fashion show, embodying opulence and grandeur."
ratio={{16, 9}}
/>
</:item>
<:item label="3 of 3">
<Doggo.image
src="https://github.com/woylie/doggo/blob/main/assets/dog_poncho.jpg?raw=true"
alt="A dog adorned in a lavish, flamboyant outfit, including a large feathered hat and elaborate jewelry, struts confidently down a luxurious fashion show runway, surrounded by bright lights and an enthusiastic audience."
ratio={{16, 9}}
/>
</:item>
</Doggo.carousel>
Attributes
id
(:string
) (required)label
(:string
) - A accessibility label for the carousel. Set asaria-label
attribute.You should ensure that either the
label
or thelabelledby
attribute is set.Defaults to
nil
.labelledby
(:string
) - The DOM ID of an element that labels this carousel.Example:
<h3 id="dog-carousel-label">Our Dogs</h3> <.carousel labelledby="dog-carousel-label"></.carousel>
You should ensure that either the
label
or thelabelledby
attribute is set.Defaults to
nil
.carousel_roledescription
(:string
) - Sets thearia-roledescription
attribute to describe the region as a carousel. This value should be translated to the language in which the rest of the page is displayed.Defaults to
"carousel"
.slide_roledescription
(:string
) - Sets thearia-roledescription
attribute to describe a slide. This value should be translated to the language in which the rest of the page is displayed.Defaults to
"slide"
.pagination
(:boolean
) - Defaults tofalse
.pagination_label
(:string
) - Defaults to"Slides"
.pagination_slide_label
(:any
) - 1-arity function that takes the slide number as an argument and returns the aria label for the slide as used in the pagination buttons.Defaults to
&Doggo.slide_label/1
.auto_rotation
(:boolean
) - Defaults tofalse
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.Global attributes are accepted. Any additional HTML attributes.
Slots
inner_block
(required) - Place thecarousel_item/1
component here.previous
- Accepts attributes:label
(:string
)
next
- Accepts attributes:label
(:string
)
item
(required) - Accepts attributes:label
(:string
) - Aria label for the slide, e.g. "1 of 5".
Use the cluster component to visually group children.
Common use cases are groups of buttons, or group of tags.
Example
<Doggo.cluster>
<div>some item</div>
<div>some other item</div>
</Doggo.cluster>
Attributes
class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.- Global attributes are accepted. Any additional HTML attributes.
Slots
inner_block
(required)
Renders a text input with a popup that allows users to select a value from a list of suggestions.
In Development
The necessary JavaScript for making this component fully functional and accessible will be added in a future version.
Missing features
- Showing/hiding suggestions
- Filtering suggestions
- Selecting a value
- Focus management
- Keyboard support
Example
With simple values:
<Doggo.combobox
id="dog-breed-selector"
name="breed"
list_label="Dog breeds"
options={[
"Labrador Retriever",
"German Shepherd",
"Golden Retriever",
"French Bulldog",
"Bulldog"
]}
/>
With label/value pairs:
<Doggo.combobox
id="dog-breed-selector"
name="breed"
list_label="Dog breeds"
options={[
{"Labrador Retriever", "labrador"},
{"German Shepherd", "german_shepherd"},
{"Golden Retriever", "golden_retriever"},
{"French Bulldog", "french_bulldog"},
{"Bulldog", "bulldog"}
]}
/>
With label/value/description tuples:
<Doggo.combobox
id="dog-breed-selector"
name="breed"
list_label="Dog breeds"
options={[
{"Labrador Retriever", "labrador", "Friendly and outgoing"},
{"German Shepherd", "german_shepherd", "Confident and smart"},
{"Golden Retriever", "golden_retriever", "Intelligent and friendly"},
{"French Bulldog", "french_bulldog", "Adaptable and playful"},
{"Bulldog", "bulldog", "Docile and willful"}
]}
/>
Attributes
id
(:string
) (required) - Sets the DOM ID for the input.name
(:string
) (required) - Sets the name for the text input.value
(:string
) - The current input value. The display value for the text input is derived by finding the given value in the list of options.Defaults to
nil
.list_label
(:string
) (required) - Sets the aria label for the list box. For example, if the combobox allows the user to select a country, the list label could be"Countries"
. The value should start with an uppercase letter and be localized.options
(:list
) (required) - A list of available options.- If a list of primitive values is passed, each item serves as both the label and the input value.
- If a list of 2-tuples is passed, the first tuple element serves as label and the second element serves as input value.
- If a list of 3-tuples is passed, the third tuple element serves as an additional description.
Global attributes are accepted. Any additional HTML attributes.
Renders a Date
, DateTime
, or NaiveDateTime
in a <time>
tag.
Examples
By default, the given value is formatted for display with to_string/1
. This:
<Doggo.date value={~D[2023-02-05]} />
Will be rendered as:
<time datetime="2023-02-05">
2023-02-05
</time>
You can also pass a custom formatter function. For example, if you are using ex_cldr_dates_times in your application, you could do this:
<Doggo.date
value={~D[2023-02-05]}
formatter={&MyApp.Cldr.Date.to_string!/1}
/>
Which, depending on your locale, may be rendered as:
<time datetime="2023-02-05">
Feb 2, 2023
</time>
Attributes
value
(:any
) (required) - Either aDate
,DateTime
, orNaiveDateTime
.formatter
(:any
) - A function that takes aDate
as an argument and returns the value formatted for display. Defaults toto_string/1
.title_formatter
(:any
) - When provided, this function is used to format the date value for thetitle
attribute. If the attribute is not set, notitle
attribute will be added.Defaults to
nil
.timezone
(:string
) - If set and the given value is aDateTime
, the value will be shifted to that time zone. This affects both the display value and thedatetime
tag. Note that you need to configure a time zone database for this to work.Defaults to
nil
.
Renders a DateTime
or NaiveDateTime
in a <time>
tag.
Examples
By default, the given value is formatted for display with to_string/1
. This:
<Doggo.datetime value={~U[2023-02-05 12:22:06.003Z]} />
Will be rendered as:
<time datetime="2023-02-05T12:22:06.003Z">
2023-02-05 12:22:06.003Z
</time>
You can also pass a custom formatter function. For example, if you are using ex_cldr_dates_times in your application, you could do this:
<Doggo.datetime
value={~U[2023-02-05 14:22:06.003Z]}
formatter={&MyApp.Cldr.DateTime.to_string!/1}
/>
Which, depending on your locale, may be rendered as:
<time datetime="2023-02-05T14:22:06.003Z">
Feb 2, 2023, 14:22:06 PM
</time>
Attributes
value
(:any
) (required) - Either aDateTime
orNaiveDateTime
.formatter
(:any
) - A function that takes aDateTime
or aNaiveDateTime
as an argument and returns the value formatted for display. Defaults toto_string/1
.title_formatter
(:any
) - When provided, this function is used to format the date time value for thetitle
attribute. If the attribute is not set, notitle
attribute will be added.Defaults to
nil
.precision
(:atom
) - Precision to truncate the given value with. The truncation is applied on both the display value and the value of thedatetime
attribute.Defaults to
nil
.timezone
(:string
) - If set and the given value is aDateTime
, the value will be shifted to that time zone. This affects both the display value and thedatetime
tag. Note that you need to configure a time zone database for this to work.Defaults to
nil
.
Renders a drawer with a brand
, top
, and bottom
slot.
All slots are optional, and you can render any content in them. If you want
to use the drawer as a sidebar, you can use the vertical_nav/1
and
vertical_nav_section/1
components.
Example
Minimal example:
<Doggo.drawer>
<:main>Content</:main>
</Doggo.drawer>
With all slots:
<Doggo.drawer>
<:header>Doggo</:header>
<:main>Content at the top</:main>
<:footer>Content at the bottom</:footer>
</Doggo.drawer>
With navigation and sections:
<Doggo.drawer>
<:header>
<.link navigate={~p"/"}>App</.link>
</:header>
<:main>
<Doggo.vertical_nav label="Main">
<:item>
<.link navigate={~p"/dashboard"}>Dashboard</.link>
</:item>
<:item>
<Doggo.vertical_nav_nested>
<:title>Content</:title>
<:item current_page>
<.link navigate={~p"/posts"}>Posts</.link>
</:item>
<:item>
<.link navigate={~p"/comments"}>Comments</.link>
</:item>
</Doggo.vertical_nav_nested>
</:item>
</.vertical_nav>
<Doggo.vertical_nav_section>
<:title>Search</:title>
<:item><input type="search" placeholder="Search" /></:item>
</Doggo.vertical_nav_section>
</:main>
<:footer>
<Doggo.vertical_nav label="User menu">
<:item>
<.link navigate={~p"/settings"}>Settings</.link>
</:item>
<:item>
<.link navigate={~p"/logout"}>Logout</.link>
</:item>
</Doggo.vertical_nav>
</:footer>
</Doggo.drawer>
Attributes
class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.- Global attributes are accepted. Any additional HTML attributes.
Slots
header
- Optional slot for the brand name or logo.main
- Slot for content that is rendered after the brand, at the start of the side bar.footer
- Slot for content that is rendered at the end of the drawer, potentially pinned to the bottom, if there is enough room.
The fallback component renders a given value unless it is empty, in which case it renders a fallback value instead.
The values nil
, ""
, []
and %{}
are treated as empty values.
This component optionally applies a formatter function to non-empty values.
The primary purpose of this component is to enhance accessibility. In situations where a value in a table column or property list is set to be invisible or not displayed, it's crucial to provide an alternative text for screen readers.
Examples
Render the value of @some_value
if it's available, or display the
default placeholder otherwise:
<Doggo.fallback value={@some_value} />
Apply a formatter function to @some_value
if it is not nil
:
<Doggo.fallback value={@some_value} formatter={&format_date/1} />
Set a custom placeholder and text for screen readers:
<Doggo.fallback
value={@some_value}
placeholder="n/a"
accessibility_text="not available"
/>
Attributes
value
(:any
) (required) - The value to display. If the value isnil
,""
,[]
or%{}
, the placeholder is rendered instead.formatter
(:any
) - A 1-arity function that takes the value and returns the value for display. The formatter function is only applied ifvalue
is not an empty value.Defaults to
nil
.placeholder
(:any
) - The placeholder to render if thevalue
is empty. Defaults to"-"
.accessibility_text
(:string
) - The text for thearia-label
attribute in case thevalue
is empty. Defaults to"not set"
.
Shows the flash messages as alerts.
Hidden attribute
This component uses the hidden
attribute to hide alerts related to
disconnections. If you explicitly set the CSS display
property for the
alert/1
component, it may override the default browser behavior for the
hidden
attribute, in which case you will see these alerts flashing on each
page load. To prevent this, add the following lines to your CSS styles:
[hidden] {
display: none !important;
}
Examples
<Doggo.flash_group flash={@flash} />
Attributes
flash
(:map
) (required) - The map of flash messages.info_title
(:string
) - Alert title for flash messages with level:info
. Defaults to"Success"
.error_title
(:string
) - Alert title for flash messages with level:error
. Defaults to"Error"
.client_error_title
(:string
) - Alert title for disconnection errors. Defaults to"Disconnected"
.client_error_msg
(:string
) - Alert message for disconnection errors. Defaults to"Attempting to reconnect."
.server_error_title
(:string
) - Alert title for server errors. Defaults to"Error"
.server_error_msg
(:string
) - Alert message for server errors. Defaults to"Please wait while we get back on track."
.id
(:string
) - An ID for the container. Defaults to"flash-group"
.class
(:any
) - An optional class name. Defaults tonil
.- Global attributes are accepted. Any additional HTML attributes.
Renders a frame with an aspect ratio for images or videos.
This component is used within the image/1
component.
Example
Rendering an image with the aspect ratio 4:3.
<Doggo.frame ratio={{4, 3}}>
<img src="image.png" alt="An example image illustrating the usage." />
</Doggo.frame>
Rendering an image as a circle.
<Doggo.frame circle>
<img src="image.png" alt="An example image illustrating the usage." />
</Doggo.frame>
Attributes
ratio
(:any
) - Defaults tonil
.circle
(:boolean
) - Defaults tofalse
.
Slots
inner_block
Renders a customizable icon using a slot for SVG content.
This component does not bind you to a specific set of icons. Instead, it provides a slot for inserting SVG content from any icon library you choose
The label
attribute is used to describe the icon and is by default applied
as an aria-label
for accessibility. If label_placement
is set to
:left
or :right
, the text becomes visible alongside the icon.
Examples
Render an icon with text as aria-label
using the heroicons
library:
<Doggo.icon label="report bug"><Heroicons.bug_ant /></.icon>
To display the text visibly:
<Doggo.icon label="report bug" label_placement={:right}>
<Heroicons.bug_ant />
</Doggo.icon>
aria-hidden
Not all icon libraries set the
aria-hidden
attribute by default. Always make sure that it is set on the<svg>
element that the library renders.
Attributes
label
(:string
) - Text that describes the icon. Iflabel_placement
is set to:hidden
, this text is set asaria-label
attribute.Defaults to
nil
.label_placement
(:atom
) - Position of the label relative to the icon. If set to:hidden
, thelabel
text is used asaria-label
attribute.Defaults to
:hidden
.size
(:atom
) - Defaults to:normal
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.Global attributes are accepted. Any additional HTML attributes.
Slots
inner_block
(required) - Slot for the SVG element.
Renders an icon using an SVG sprite.
Examples
Render an icon with text as aria-label
:
<Doggo.icon name="arrow-left" label="Go back" />
To display the text visibly:
<Doggo.icon name="arrow-left" label="Go back" label_placement={:right} />
Attributes
name
(:string
) (required) - Icon name as used in the sprite.sprite_url
(:string
) - The URL of the SVG sprite. Defaults to"/assets/icons/sprite.svg"
.label
(:string
) - Text that describes the icon. Iflabel_placement
is set to:hidden
, this text is set asaria-label
attribute.Defaults to
nil
.label_placement
(:atom
) - Position of the label relative to the icon. If set to:hidden
, thelabel
text is used asaria-label
attribute.Defaults to
:hidden
.size
(:atom
) - Defaults to:normal
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.Global attributes are accepted. Any additional HTML attributes.
Renders an image with an optional caption.
Example
<Doggo.image
src="https://github.com/woylie/doggo/blob/main/assets/dog_poncho.jpg?raw=true"
alt="A dog wearing a colorful poncho walks down a fashion show runway."
ratio={{16, 9}}
>
<:caption>
Spotlight on canine couture: A dog fashion show where four-legged models
dazzle the runway with the latest in pet apparel.
</:caption>
</Doggo.image>
Attributes
src
(:string
) (required) - The URL of the image to render.srcset
(:any
) - A set of image URLs in different sizes. Can be passed as a string or a map.For example, this map:
%{ "1x" => "images/image-1x.jpg", "2x" => "images/image-2x.jpg" }
Will result in this
srcset
:"images/image-1x.jpg 1x, images/image-2x.jpg 2x"
See https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/srcset.
Defaults to
nil
.sizes
(:string
) - Specifies media conditions for the image widths, if thesrcset
attribute uses intrinsic widths.See https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/sizes.
Defaults to
nil
.alt
(:string
) (required) - A text description of the image for screen reader users and those with slow internet. Effective alt text should concisely capture the image's essence and function, considering its context within the content. Aim for clarity and inclusivity without repeating information already conveyed by surrounding text, and avoid starting with "Image of" as screen readers automatically announce image presence.width
(:integer
) - Defaults tonil
.height
(:integer
) - Defaults tonil
.loading
(:string
) - Defaults to"lazy"
.ratio
(:any
) - Defaults tonil
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.Global attributes are accepted. Any additional HTML attributes.
Slots
caption
Renders a modal dialog for content such as forms and informational panels.
This component is appropriate for non-critical interactions. For dialogs
requiring immediate user response, such as confirmations or warnings, use
Doggo.alert_dialog/1
instead.
Usage
There are two primary ways to manage the display of the modal: via URL state
or by setting and removing the open
attribute.
With URL
To toggle the modal visibility based on the URL:
- Use the
:if
attribute to conditionally render the modal when a specific live action matches. - Set the
on_cancel
attribute to patch back to the original URL when the user chooses to close the modal. - Set the
open
attribute to declare the modal's initial visibility state.
Example
<Doggo.modal
:if={@live_action == :show}
id="pet-modal"
on_cancel={JS.patch(~p"/pets")}
open
>
<:title>Show pet</:title>
<p>My pet is called Johnny.</p>
<:footer>
<.link phx-click={JS.exec("data-cancel", to: "#pet-modal")}>
Close
</.link>
</:footer>
</Doggo.modal>
To open the modal, patch or navigate to the URL associated with the live action.
<.link patch={~p"/pets/#{@id}"}>show</.link>
Without URL
To toggle the modal visibility dynamically with the open
attribute:
- Omit the
open
attribute in the template. - Use the
show_modal/1
andhide_modal/1
functions to change the visibility.
Example
<Doggo.modal id="pet-modal">
<:title>Show pet</:title>
<p>My pet is called Johnny.</p>
<:footer>
<.link phx-click={JS.exec("data-cancel", to: "#pet-modal")}>
Close
</.link>
</:footer>
</Doggo.modal>
To open modal, use the show_modal/1
function.
<Doggo.button
phx-click={Doggo.show_modal("pet-modal")}
aria-haspopup="dialog"
>
show
</Doggo.button>
CSS
To hide the modal when the open
attribute is not set, use the following CSS
styles:
dialog.modal:not([open]),
dialog.modal[open="false"] {
display: none;
}
Semantics
While the showModal()
JavaScript function is typically recommended for
managing modal dialog semantics, this component utilizes the open
attribute
to control visibility. This approach is chosen to eliminate the need for
library consumers to add additional JavaScript code. To ensure proper
modal semantics, the aria-modal
attribute is added to the dialog element.
Attributes
id
(:string
) (required)open
(:boolean
) - Initializes the modal as open. Defaults tofalse
.on_cancel
(Phoenix.LiveView.JS
) - An additionalPhoenix.LiveView.JS
command to execute when the dialog is canceled. This command is executed in addition to closing the dialog. If you only want the dialog to be closed, you don't have to set this attribute.Defaults to
%Phoenix.LiveView.JS{ops: []}
.dismissable
(:boolean
) - When set totrue
, the dialog can be dismissed by clicking a close button or by pressing the escape key.Defaults to
true
.close_label
(:string
) - Aria label for the close button. Defaults to"Close"
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.Global attributes are accepted. Any additional HTML attributes.
Slots
title
(required)inner_block
(required) - The modal body.close
- The content for the 'close' link. Defaults to the word 'close'.footer
Renders a header that is specific to the content of the current page.
Unlike a site-wide header, which offers consistent navigation and elements like logos throughout the website or application, this component is meant to describe the unique content of each page. For instance, on an article page, it would display the article's title.
It is typically used as a direct child of the <main>
element.
Example
<main>
<Doggo.page_header title="Puppy Profiles" subtitle="Share Your Pup's Story">
<:action>
<Doggo.button_link patch={~p"/puppies/new"}>Add New Profile</Doggo.button_link>
</:action>
</Doggo.page_header>
<section>
<!-- Content -->
</section>
</main>
Attributes
title
(:string
) (required) - The title for the current page.subtitle
(:string
) - An optional sub title. Defaults tonil
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.- Global attributes are accepted. Any additional HTML attributes.
Slots
action
- A slot for action buttons related to the current page.
Renders a list of properties, i.e. key/value pairs.
Example
<Doggo.property_list>
<:prop label={gettext("Name")}>George</:prop>
<:prop label={gettext("Age")}>42</:prop>
</Doggo.property_list>
Attributes
class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.- Global attributes are accepted. Any additional HTML attributes.
Slots
prop
- A property to be rendered. Accepts attributes:label
(:string
) (required)
Renders a group of radio buttons, for example for a toolbar.
To render radio buttons within a regular form, use input/1
with the
"radio-group"
type instead.
Example
<Doggo.radio_group
id="favorite-dog"
name="favorite-dog"
label="Favorite Dog"
options={[
{"Labrador Retriever", "labrador"},
{"German Shepherd", "german_shepherd"},
{"Golden Retriever", "golden_retriever"},
{"French Bulldog", "french_bulldog"},
{"Beagle", "beagle"}
]}
/>
CSS
To target the wrapper, use an attribute selector:
[role="radio-group"] {}
Attributes
id
(:string
) (required)name
(:string
) (required) - Thename
attribute for theinput
elements.label
(:string
) - A accessibility label for the radio group. Set asaria-label
attribute.You should ensure that either the
label
or thelabelledby
attribute is set.Defaults to
nil
.labelledby
(:string
) - The DOM ID of an element that labels this radio group.Example:
<h3 id="dog-rg-label">Favorite Dog</h3> <.radio_group labelledby="dog-rg-label"></.radio_group>
You should ensure that either the
label
or thelabelledby
attribute is set.Defaults to
nil
.options
(:list
) (required) - A list of options. It can be given a list values or as a list of{label, value}
tuples.value
(:any
) - The currently selected value, which is compared with the option value to determine whether a radio button is checked.Defaults to
nil
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.Global attributes are accepted. Any additional HTML attributes.
Renders a skeleton loader, a placeholder for content that is in the process of loading.
It mimics the layout of the actual content, providing a better user experience during loading phases.
Usage
Render one of several primitive types:
<Doggo.skeleton type={:text_line} />
Combine primitives for complex layouts:
<div class="card-skeleton" aria-busy="true">
<Doggo.skeleton type={:image} />
<Doggo.skeleton type={:text_line} />
<Doggo.skeleton type={:text_line} />
<Doggo.skeleton type={:text_line} />
<Doggo.skeleton type={:rectangle} />
</div>
To modify the primitives for your use cases, you can use custom classes or CSS properties:
<Doggo.skeleton type={:text_line} class="header" />
<Doggo.skeleton type={:image} style="--aspect-ratio: 75%;" />
Aria-busy attribute
When using skeleton loaders, apply aria-busy="true"
to the container element
that contains the skeleton layout. For standalone use, add the attribute
directly to the individual skeleton loader.
Async result component
The easiest way to load data asynchronously and render a skeleton loader is
to use LiveView's
async operations
and Phoenix.Component.async_result/1
.
Assuming you defined a card skeleton component as described above:
<.async_result :let={puppy} assign={@puppy}>
<:loading><.card_skeleton /></:loading>
<:failed :let={_reason}>There was an error loading the puppy.</:failed>
<!-- Card for loaded content -->
</.async_result>
Attributes
type
(:atom
) (required) - Must be one of:text_line
,:text_block
,:image
,:circle
,:rectangle
, or:square
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.- Global attributes are accepted. Any additional HTML attributes.
Renders a horizontal or vertical resizable split pane.
In Development
The necessary JavaScript for making this component fully functional and accessible will be added in a future version.
Missing features
- Resize panes with the mouse
- Resize panes with the keyboard
Examples
Horizontal separator with label:
<Doggo.split_pane
id="sidebar-splitter"
label="Sidebar"
orientation="horizontal"
>
<:primary>One</:primary>
<:secondary>Two</:secondary>
</Doggo.split_pane>
Horizontal separator with visible label:
<Doggo.split_pane id="sidebar-splitter"
labelledby="sidebar-label"
orientation="horizontal"
>
<:primary>
<h2 id="sidebar-label">Sidebar</h2>
<p>One</p>
</:primary>
<:secondary>Two</:secondary>
</Doggo.split_pane>
Nested window splitters:
<Doggo.split_pane
id="sidebar-splitter"
label="Sidebar"
orientation="horizontal"
>
<:primary>One</:primary>
<:secondary>
<Doggo.split_pane
id="filter-splitter"
label="Filters"
orientation="vertical"
>
<:primary>Two</:primary>
<:secondary>Three</:secondary>
</Doggo.split_pane>
</:secondary>
</Doggo.split_pane>
Attributes
label
(:string
) - An accessibility label for the separator if the primary pane has no visible label. If it has a visible label, set thelabelledby
attribute instead.Note that the label should describe the primary pane, not the resize handle.
Defaults to
nil
.labelledby
(:string
) - If the primary pane has a visible label, set this attribute to the DOM ID of that label. Otherwise, provide a label via thelabel
attribute.Defaults to
nil
.id
(:string
) (required)orientation
(:string
) (required) - Must be one of"horizontal"
, or"vertical"
.default_size
(:integer
) (required)min_size
(:integer
) - Defaults to0
.max_size
(:integer
) - Defaults to100
.
Slots
primary
(required)secondary
(required)
Applies a vertical margin between the child elements.
Example
<Doggo.stack>
<div>some block</div>
<div>some other block</div>
</Doggo.stack>
To apply a vertical margin on nested elements as well, set recursive
to
true
.
<Doggo.stack recursive={true}>
<div>
<div>some nested block</div>
<div>another nested block</div>
</div>
<div>some other block</div>
</Doggo.stack>
Attributes
recursive
(:boolean
) - Iftrue
, the stack margins will be applied to nested elements as well. Defaults tofalse
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.- Global attributes are accepted. Any additional HTML attributes.
Slots
inner_block
(required)
Renders a switch as a button.
If you want to render a switch as part of a form, use the input/1
component
with the type "switch"
instead.
Note that this component only renders a button with a label, a state, and
<span>
with the class switch-control
. You will need to style the switch
control span with CSS in order to give it the appearance of a switch.
Examples
<Doggo.switch
label="Subscribe"
checked={true}
phx-click="toggle-subscription"
/>
Attributes
label
(:string
) (required)on_text
(:string
) - Defaults to"On"
.off_text
(:string
) - Defaults to"Off"
.checked
(:boolean
) - Defaults tofalse
.- Global attributes are accepted.
Renders a simple table.
Examples
<Doggo.table id="pets" rows={@pets}>
<:col :let={p} label="name"><%= p.name %></:col>
<:col :let={p} label="age"><%= p.age %></:col>
</Doggo.table>
Attributes
id
(:string
) (required)rows
(:list
) (required) - The list of items to be displayed in rows.caption
(:string
) - Content for the<caption>
element. Defaults tonil
.row_id
(:any
) - Overrides the default function that retrieves the row ID from a stream item. Defaults tonil
.row_click
(:any
) - Sets thephx-click
function attribute for each rowtd
. Expects to be a function that receives a row item as an argument. This does not add thephx-click
attribute to theaction
slot.Example:
row_click={&JS.navigate(~p"/users/#{&1}")}
Defaults to
nil
.row_item
(:any
) - This function is called on the row item before it is passed to the :col and :action slots.Defaults to
&Function.identity/1
.
Slots
col
(required) - For each column to render, add one<:col>
element.<:col :let={pet} label="Name" field={:name} col_style="width: 20%;"> <%= pet.name %> </:col>
Any additional assigns will be added as attributes to the
<td>
elements.Accepts attributes:
label
(:any
) - The content for the header column.col_attrs
(:list
) - If set, a<colgroup>
element is rendered and the attributes are added to the<col>
element of the respective column.
action
- The slot for showing user actions in the last table column. These columns do not receive therow_click
attribute.<:action :let={user}> <.link navigate={~p"/users/#{user}"}>Show</.link> </:action>
Accepts attributes:
label
(:string
) - The content for the header column.col_attrs
(:list
) - If set, a<colgroup>
element is rendered and the attributes are added to the<col>
element of the respective column.
foot
- You can optionally add afoot
. The inner block will be rendered inside atfoot
element.<Flop.Phoenix.table> <:foot> <tr><td>Total: <span class="total"><%= @total %></span></td></tr> </:foot> </Flop.Phoenix.table>
Renders tab panels.
This component is meant for tabs that toggle content panels within the page.
If you want to link to a different view or live action, use
tab_navigation/1
instead.
In Development
The necessary JavaScript for making this component fully functional and accessible will be added in a future version.
Missing features
- Roving tabindex
- Move focus with arrow keys
Example
<Doggo.tabs id="dog-breed-profiles" label="Dog Breed Profiles">
<:panel label="Golden Retriever">
<p>
Friendly, intelligent, great with families. Origin: Scotland. Needs
regular exercise.
</p>
</:panel>
<:panel label="Siberian Husky">
<p>
Energetic, outgoing, distinctive appearance. Origin: Northeast Asia.
Loves cold climates.
</p>
</:panel>
<:panel label="Dachshund">
<p>
Playful, stubborn, small size. Origin: Germany. Enjoys sniffing games.
</p>
</:panel>
</Doggo.tabs>
Attributes
id
(:string
) (required)label
(:string
) - A accessibility label for the tabs. Set asaria-label
attribute.You should ensure that either the
label
or thelabelledby
attribute is set.Do not repeat the word
tab list
or similar in the label, since it is already announced by screen readers.Defaults to
nil
.labelledby
(:string
) - The DOM ID of an element that labels the tabs.Example:
<h3 id="my-tabs-label">Dogs</h3> <Doggo.tabs labelledby="my-tabs-label"></Doggo.tabs>
You should ensure that either the
label
or thelabelledby
attribute is set.Defaults to
nil
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.Global attributes are accepted. Any additional HTML attributes.
Slots
panel
(required) - Accepts attributes:label
(:string
)
Renders a tag, typically used for displaying labels, categories, or keywords.
Examples
Plain tag:
<Doggo.tag>Well-Trained</Doggo.tag>
With icon:
<Doggo.tag>
Puppy
<Doggo.icon><Heroicons.edit /></Doggo.icon>
</Doggo.tag>
With delete button:
<Doggo.tag>
High Energy
<button
phx-click="remove-tag"
phx-value-tag="high-energy"
aria-label="Remove tag"
>
<Doggo.icon><Heroicons.x /></Doggo.icon>
</button>
</Doggo.tag>
Attributes
size
(:atom
) - Defaults to:normal
.variant
(:atom
) - Defaults tonil
.shape
(:atom
) - Defaults tonil
.
Slots
inner_block
(required)
Renders a Time
, DateTime
, or NaiveDateTime
in a <time>
tag.
Examples
By default, the given value is formatted for display with to_string/1
. This:
<Doggo.time value={~T[12:22:06.003Z]} />
Will be rendered as:
<time datetime="12:22:06.003">
12:22:06.003
</time>
You can also pass a custom formatter function. For example, if you are using ex_cldr_dates_times in your application, you could do this:
<Doggo.time
value={~T[12:22:06.003]}
formatter={&MyApp.Cldr.Time.to_string!/1}
/>
Which, depending on your locale, may be rendered as:
<time datetime="14:22:06.003">
14:22:06 PM
</time>
Attributes
value
(:any
) (required) - Either aTime
,DateTime
, orNaiveDateTime
.formatter
(:any
) - A function that takes aTime
,DateTime
, orNaiveDateTime
as an argument and returns the value formatted for display. Defaults toto_string/1
.title_formatter
(:any
) - When provided, this function is used to format the time value for thetitle
attribute. If the attribute is not set, notitle
attribute will be added.Defaults to
nil
.precision
(:atom
) - Precision to truncate the given value with. The truncation is applied on both the display value and the value of thedatetime
attribute.Defaults to
nil
.timezone
(:string
) - If set and the given value is aDateTime
, the value will be shifted to that time zone. This affects both the display value and thedatetime
tag. Note that you need to configure a time zone database for this to work.Defaults to
nil
.
Renders a container for a set of controls.
In Development
The necessary JavaScript for making this component fully functional and accessible will be added in a future version.
Missing features
- Roving tabindex
- Move focus with arrow keys
Example
Direct children of this component can be any types buttons or groups of buttons.
<Doggo.toolbar label="Actions for the dog">
<div role="group">
<button phx-click="feed-dog">
<Doggo.icon label="Feed dog"><Icons.feed /></Doggo.icon>
</button>
<button phx-click="walk-dog">
<Doggo.icon label="Walk dog"><Icons.walk /></Doggo.icon>
</button>
</div>
<div role="group">
<button phx-click="teach-trick">
<Doggo.icon label="Teach a Trick"><Icons.teach /></Doggo.icon>
</button>
<button phx-click="groom-dog">
<Doggo.icon label="Groom dog"><Icons.groom /></Doggo.icon>
</button>
</div>
</Doggo.toolbar>
Attributes
label
(:string
) - A accessibility label for the toolbar. Set asaria-label
attribute.You should ensure that either the
label
or thelabelledby
attribute is set.Do not repeat the word
toolbar
in the label, since it is already announced by screen readers.Defaults to
nil
.labelledby
(:string
) - The DOM ID of an element that labels this tree.Example:
<h3 id="dog-toolbar-label">Dogs</h3> <Doggo.toolbar labelledby="dog-toolbar-label"></Doggo.toolbar>
You should ensure that either the
label
or thelabelledby
attribute is set.Defaults to
nil
.controls
(:string
) - DOM ID of the element that is controlled by this toolbar. For example, if the toolbar provides text formatting options for an editable content area, the values should be the ID of that content area.Defaults to
nil
.Global attributes are accepted. Any additional HTML attributes.
Slots
inner_block
(required) - Place any number of buttons, groups of buttons, toggle buttons, menu buttons, or disclosure buttons here.
Renders content with a tooltip.
There are different ways to render a tooltip. This component renders a <div>
with the tooltip
role, which is hidden unless the element is hovered on or
focused. For example CSS for this kind of tooltip, refer to
ARIA: tooltip role.
A simpler alternative for styled text-only tooltips is to use a data attribute
and the attr
CSS function.
Doggo does not provide a component for that kind of tooltip, since it is
controlled by attributes only. You can check
Pico CSS for an example implementation.
Example
With an inline text:
<p>
Did you know that the
<Doggo.tooltip id="labrador-info">
Labrador Retriever
<:tooltip>
<p><strong>Labrador Retriever</strong></p>
<p>
Labradors are known for their friendly nature and excellent
swimming abilities.
</p>
</:tooltip>
</Doggo.tooltip>
is one of the most popular dog breeds in the world?
</p>
If the inner block contains a link, add the :contains_link
attribute:
<p>
Did you know that the
<Doggo.tooltip id="labrador-info" contains_link>
<.link navigate={~p"/labradors"}>Labrador Retriever</.link>
<:tooltip>
<p><strong>Labrador Retriever</strong></p>
<p>
Labradors are known for their friendly nature and excellent
swimming abilities.
</p>
</:tooltip>
</Doggo.tooltip>
is one of the most popular dog breeds in the world?
</p>
Attributes
id
(:string
) (required)contains_link
(:boolean
) - Iffalse
, the component setstabindex="0"
on the element wrapping the inner block, so that the tooltip can be made visible by focusing the element.If the inner block already contains an element that is focusable, such as a link or a button, set this attribute to
true
.Defaults to
false
.
Slots
inner_block
(required)tooltip
(required)
Renders a hierarchical list as a tree.
A good use case for this component is a folder structure. For navigation and other menus, a regular nested list should be preferred.
In Development
The necessary JavaScript for making this component fully functional and accessible will be added in a future version.
Missing features
- Expand and collapse nodes
- Select nodes
- Navigate tree with arrow keys
Example
<Doggo.tree label="Dogs">
<Doggo.tree_item>
Breeds
<:items>
<Doggo.tree_item>Golden Retriever</Doggo.tree_item>
<Doggo.tree_item>Labrador Retriever</Doggo.tree_item>
</:items>
</Doggo.tree_item>
<Doggo.tree_item>
Characteristics
<:items>
<Doggo.tree_item>Playful</Doggo.tree_item>
<Doggo.tree_item>Loyal</Doggo.tree_item>
</:items>
</Doggo.tree_item>
</Doggo.tree>
CSS
To target the wrapper, use an attribute selector:
[role="tree"] {}
Attributes
label
(:string
) - A accessibility label for the tree. Set asaria-label
attribute.You should ensure that either the
label
or thelabelledby
attribute is set.Do not repeat the word
tree
in the label, since it is already announced by screen readers.Defaults to
nil
.labelledby
(:string
) - The DOM ID of an element that labels this tree.Example:
<h3 id="dog-tree-label">Dogs</h3> <.tree labelledby="dog-tree-label"></.tree>
You should ensure that either the
label
or thelabelledby
attribute is set.Defaults to
nil
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.Global attributes are accepted. Any additional HTML attributes.
Slots
inner_block
(required) - Slot for the root nodes of the tree. Use thetree_item/1
component as direct children.
Renders a tree item within a tree/1
.
This component can be used as a direct child of tree/1
or within the items
slot of this component.
In Development
The necessary JavaScript for making this component fully functional and accessible will be added in a future version.
Missing features
- Expand and collapse nodes
- Select nodes
- Navigate tree with arrow keys
Example
<Doggo.tree label="Dogs">
<Doggo.tree_item>
Breeds
<:items>
<Doggo.tree_item>Golden Retriever</Doggo.tree_item>
<Doggo.tree_item>Labrador Retriever</Doggo.tree_item>
</:items>
</Doggo.tree_item>
<Doggo.tree_item>
Characteristics
<:items>
<Doggo.tree_item>Playful</Doggo.tree_item>
<Doggo.tree_item>Loyal</Doggo.tree_item>
</:items>
</Doggo.tree_item>
</Doggo.tree>
Icons can be added before the label:
<Doggo.tree_item> <Heroicon.folder /> Breeds <:items>
<Doggo.tree_item><Heroicon.document /> Golden Retriever</Doggo.tree_item>
<Doggo.tree_item><Heroicon.document /> Labrador Retriever</Doggo.tree_item>
</:items> </Doggo.tree_item>
Slots
items
- Slot for children of this item. Place one or more additionaltree_item/1
components within this slot, or omit if this is a leaf node.inner_block
(required) - Slot for the item label.
Form
Renders the description of an input.
Example
<Doggo.field_description for="name">
max. 100 characters
</Doggo.field_description>
Attributes
for
(:string
) (required) - The ID of the input.
Slots
inner_block
(required)
Renders the errors for an input.
Example
<Doggo.field_errors for="name" errors={["too many characters"]} />
Attributes
for
(:string
) (required) - The ID of the input.errors
(:list
) (required) - A list of errors as strings.
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:
<Doggo.field_group>
<Doggo.input field={@form[:given_name]} label="Given name" />
<Doggo.input field={@form[:family_name]} label="Family name"/>
</Doggo.field_group>
Semantic grouping (for reference):
<fieldset>
<legend>Personal Information</legend>
<Doggo.input field={@form[:given_name]} label="Given name" />
<Doggo.input field={@form[:family_name]} label="Family name"/>
</fieldset>
Attributes
class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.- Global attributes are accepted. Any additional HTML attributes.
Slots
inner_block
(required)
Renders a form field including input, label, errors, and description.
A Phoenix.HTML.FormField
may be passed as argument,
which is used to retrieve the input name, id, and values.
Otherwise all attributes may be passed explicitly.
Types
In addition to all HTML input types, the following type values are also supported:
"select"
- For<select>
elements.
Gettext
To translate field errors using Gettext, configure your Gettext module in
config/config.exs
.
config :doggo, gettext: MyApp.Gettext
Alternatively, pass the Gettext module as an attribute:
<Doggo.input field={@form[:name]} gettext={MyApp.Gettext} />
Label positioning
The component does not provide an attribute to modify label positioning directly. Instead, label positioning should be handled with CSS. If your application requires different label positions, such as horizontal and vertical layouts, it is recommended to add a modifier class to the form.
For example, the default style could position labels above inputs. To place
labels to the left of the inputs in a horizontal form layout, you can add an
is-horizontal
class to the form:
<.form class="is-horizontal">
<!-- inputs -->
</.form>
Then, in your CSS, apply the necessary styles to the .field
class within
forms having the is-horizontal
class:
form.is-horizontal .field {
// styles to position label left of the input
}
The component has a hide_label
attribute to visually hide labels while still
making them accessible to screen readers. If all labels within a form need to
be visually hidden, it may be more convenient to define a
.has-visually-hidden-labels
modifier class for the <form>
.
<.form class="has-visually-hidden-labels">
<!-- inputs -->
</.form>
Ensure to take checkbox and radio labels into consideration when writing the CSS styles.
Examples
<Doggo.input field={@form[:name]} />
<Doggo.input field={@form[:email]} type="email" />
Radio group and checkbox group
The radio-group
and checkbox-group
types allow you to easily render groups
of radio buttons or checkboxes with a single component invocation. The
options
attribute is required for these types and has the same format as
the options for the select
type, except that options may not be nested.
<Doggo.input
field={@form[:email]}
type="checkbox-group"
label="Cuisine"
options={[
{"Mexican", "mexican"},
{"Japanese", "japanese"},
{"Libanese", "libanese"}
]}
/>
Note that the checkbox-group
type renders an additional hidden input with
an empty value before the checkboxes. This ensures that a value exists in case
all checkboxes are unchecked. Consequently, the resulting list value includes
an extra empty string. While Ecto.Changeset.cast/3
filters out empty strings
in array fields by default, you may need to handle the additional empty string
manual in other contexts.
Attributes
id
(:any
) - Defaults tonil
.name
(:any
)label
(:string
) - Required for all types except"hidden"
. Defaults tonil
.hide_label
(:boolean
) - Adds an "is-visually-hidden" class to the<label>
. This option does not apply to checkbox and radio inputs.Defaults to
false
.value
(:any
)type
(:string
) - Defaults to"text"
.field
(Phoenix.HTML.FormField
) - A form field struct, for example: @form[:name].errors
(:list
)validations
(:list
) - A list of HTML input validation attributes (required
,minlength
,maxlength
,min
,max
,pattern
). The attributes are derived automatically from the form.checked_value
(:string
) - The value that is sent when the checkbox is checked. Defaults to"true"
.checked
(:boolean
) - The checked attribute for checkboxes.on_text
(:string
) - The state text for a switch when on. Defaults to"On"
.off_text
(:string
) - The state text for a switch when off. Defaults to"Off"
.prompt
(:string
) - An optional prompt for select elements. Defaults tonil
.options
(:list
) - A list of options.This attribute is supported for the following types:
"select"
"radio-group"
"checkbox-group"
- other text types, date and time types, and the
"range"
type
If this attribute is set for types other than select, radio, and checkbox, a datalist is rendered for the input.
See
Phoenix.HTML.Form.options_for_select/2
for the format. Note that only the select supports nested options.Defaults to
nil
.multiple
(:boolean
) - Sets themultiple
attribute on a select element to allow selecting multiple options.Defaults to
false
.gettext
(:atom
) - The Gettext module to use for translating error messages. This option can also be set globally, see above.Global attributes are accepted. Supports all globals plus:
["accept", "autocomplete", "capture", "cols", "disabled", "form", "list", "max", "maxlength", "min", "minlength", "multiple", "passwordrules", "pattern", "placeholder", "readonly", "required", "rows", "size", "step"]
.
Slots
description
- A field description to render underneath the input.addon_left
- Can be used to render an icon left in the input. Only supported for single-line inputs.addon_right
- Can be used to render an icon left in the input. Only supported for single-line inputs.
Renders the label for an input.
Example
<Doggo.label for="name" required>
Name
</Doggo.label>
Attributes
for
(:string
) - The ID of the input. Defaults tonil
.required
(:boolean
) - If set totrue
, a 'required' mark is rendered. Defaults tofalse
.required_title
(:any
) - Sets thetitle
attribute of the required mark. Defaults to"required"
.visually_hidden
(:boolean
) - Adds an "is-visually-hidden" class to the<label>
. Defaults tofalse
.class
(:any
) - Additional CSS classes. Can be a string or a list of strings. Defaults to[]
.- Global attributes are accepted. Any additional HTML attributes.
Slots
inner_block
(required)
Functions
Hides the modal with the given ID.
Example
<.link phx-click={hide_modal("pet-modal")}>hide</.link>
Shows the modal with the given ID.
Example
<.link phx-click={show_modal("pet-modal")}>show</.link>
Shows the tab with the given index of the tabs/1
component with the given
ID.
Example
Doggo.show_tab("my-tabs", 2)