Modal
Shows content in a dialog over the page that people must deal with before returning to it.
Default
A title, a description, a body, and actions in the footer.
Invite member
They'll get an email with a link to join your organization.
<.modal
id="modal-default"
title="Invite member"
description="They'll get an email with a link to join your organization."
>
<:trigger :let={attrs}>
<.button label="Invite member" {attrs} />
</:trigger>
<.text_input
id="modal-default-email"
name="email"
value=""
type="email"
label="Email"
/>
<:footer>
<.modal_footer>
<:action>
<.button
label="Cancel"
variant="secondary"
phx-click={JS.dispatch("phx:close-modal", detail: %{id: "modal-default"})}
/>
</:action>
<:action>
<.button label="Send invite" />
</:action>
</.modal_footer>
</:footer>
</.modal>
Header types
Status types add an icon that matches the outcome.
Cache warmed
128 targets were built and uploaded to the cache.
Selective testing is on
Tuist skips tests whose dependencies did not change.
Build minutes almost used up
You've used 90% of this month's build minutes.
Preview upload failed
The upload timed out. Run tuist share again to retry.
<.modal
id="modal-success"
title="Cache warmed"
description="128 targets were built and uploaded to the cache."
header_type="success"
>
<:trigger :let={attrs}>
<.button label="Success" variant="secondary" {attrs} />
</:trigger>
</.modal>
<.modal
id="modal-info"
title="Selective testing is on"
description="Tuist skips tests whose dependencies did not change."
header_type="info"
>
<:trigger :let={attrs}>
<.button label="Info" variant="secondary" {attrs} />
</:trigger>
</.modal>
<.modal
id="modal-warning"
title="Build minutes almost used up"
description="You've used 90% of this month's build minutes."
header_type="warning"
>
<:trigger :let={attrs}>
<.button label="Warning" variant="secondary" {attrs} />
</:trigger>
</.modal>
<.modal
id="modal-error"
title="Preview upload failed"
description="The upload timed out. Run tuist share again to retry."
header_type="error"
>
<:trigger :let={attrs}>
<.button label="Error" variant="secondary" {attrs} />
</:trigger>
</.modal>
Custom icon
The
icon
header type shows the icon from the
:header_icon
slot.
Remove member
Are you sure you want to remove ana from this organization?
<.modal id="modal-custom-icon" title="Remove member" header_type="icon" header_size="small">
<:trigger :let={attrs}>
<.button label="Remove member" variant="destructive" {attrs} />
</:trigger>
<:header_icon><.trash /></:header_icon>
<p>Are you sure you want to remove ana from this organization?</p>
<:footer>
<.modal_footer>
<:action>
<.button
label="Cancel"
variant="secondary"
phx-click={JS.dispatch("phx:close-modal", detail: %{id: "modal-custom-icon"})}
/>
</:action>
<:action>
<.button label="Remove" variant="destructive" />
</:action>
</.modal_footer>
</:footer>
</.modal>
Header sizes
Large is the default and shows the description. Small shows only the title.
Rotate token
Clients that use the current token stop working.
Rotate token
<.modal
id="modal-header-large"
title="Rotate token"
description="Clients that use the current token stop working."
>
<:trigger :let={attrs}>
<.button label="Large header" variant="secondary" {attrs} />
</:trigger>
</.modal>
<.modal id="modal-header-small" title="Rotate token" header_size="small">
<:trigger :let={attrs}>
<.button label="Small header" variant="secondary" {attrs} />
</:trigger>
</.modal>
Guidelines
- Use a modal for a focused task or a confirmation, such as inviting a member or deleting a project. Keep longer flows on their own page.
-
Spread the attributes from the
:triggerslot onto the element that opens the modal:<:trigger :let={attrs}>and then{attrs}on the button. -
Close a modal from your own buttons with
JS.dispatch("phx:close-modal", detail: %{id: id}), or open one from anywhere withphx:open-modal. Escape, a click outside, and the dismiss icon also close it. -
The description only shows when
header_sizeislarge. Usesmallfor short confirmations that need no explanation. -
Match
header_typeto the outcome:success,info,warning, anderroradd a status icon, andiconshows your own icon from the:header_iconslot. -
Put the actions in a
modal_footer, with the main action last. Usetype="stretch"to make the actions fill the footer's width.
API reference
<.modal>
| Attribute | Type | Default | Description |
|---|---|---|---|
|
description
|
string
|
nil
|
Description of the modal. Only visible when header_size is 'large'
|
|
header_size
|
string
|
"large"
|
Size of the header
"small""large"
|
|
header_type
|
string
|
"default"
|
Type of the header
"default""icon""success""info""warning""error"
|
|
id
Required
|
string
|
–
|
The modal's unique identifier.
|
|
on_dismiss
|
string
|
nil
|
Event to emit when the dismiss icon is clicked.
|
|
on_open_change
|
string
|
nil
|
An optional event to fire when the modal is opened or closed.
|
|
title
|
string
|
nil
|
Title of the modal
|
Also accepts global attributes.
| Slot | Description |
|---|---|
|
:footer
|
The modal's footer element.
|
|
:header_button
|
|
|
:header_icon
|
Icon to be rendered in the header when type is 'icon'
|
|
inner_block
|
|
|
:trigger
Required
|
The modal's trigger. Should be a button that accepts the attributes provided by the slot.
|