Modal
Modals are used to display content in a layer above the main application, often requiring user interaction before returning to the main content.
Showcase
<LnxModal title="This is the title" @open="..." <-- Emitted when the modal dialog is opened @close="..." <-- Emitted when the modal dialog is closed > <template #default="{ open, close }">Open extra-long dialog </template> <template #icon></template> <template #content="{ close }"> The content of the modal goes here. </template> <template #actions="{ close }"> A secondary action Another action Close </template> </LnxModal>
When to use
- To interrupt the user for a decision they must take before going on, like confirming a deletion.
- For short tasks that don't need their own page.
- Not for information that can wait: show it on the page instead.
Examples
Confirmation
The default slot holds the element that opens the modal, and gets open() and close(). The actions slot gets close() too.
vue
<LnxModal title="Delete project?">
<template #default="{ open }">
<LnxButton variant="danger" @click="open()">Delete project</LnxButton>
</template>
<template #content>
The project and all its files will be deleted. This can't be undone.
</template>
<template #actions="{ close }">
<LnxButton variant="grayscale" mode="clear" @click="close()">Cancel</LnxButton>
<LnxButton variant="danger" @click="close()">Delete</LnxButton>
</template>
</LnxModal>1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
Closing from the overlay
By default the modal only closes from its buttons or with Esc. allow-close-on-overlay-click also closes it when the user clicks outside.
vue
<LnxModal title="What's new" allow-close-on-overlay-click>
<template #default="{ open }">
<LnxButton mode="outline" @click="open()">See what's new</LnxButton>
</template>
<template #content>
Buttons and fields now share the same size variables.
</template>
</LnxModal>1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
API
Props
| Prop | Type | Description |
|---|---|---|
title | string | Title of the modal Default: `` |
hide-close-button | boolean | Hide the close button in the top right corner Default: false |
allow-close-on-overlay-click | boolean | Allow closing the modal when clicking on the overlay Default: false |
Events
| Event | Payload | Description |
|---|---|---|
open | void | Emitted when the modal dialog is opened |
close | void | Emitted when the modal dialog is closed |
Slots
| Slot | Scope | Description |
|---|---|---|
default | open: () => void, close: () => void | Opener element |
icon | — | Shown next to the title of the modal |
content | close: () => void | The main content of the modal |
actions | close: () => void | Some actions to show at the end of the dialog |