Skip to content

Modal

A generic overlay component for displaying content on top of an application.

Usage

vue
<script setup>
import { Modal, Button } from "fluekit";
import { ref } from "vue";
const visible = ref(false);
</script>
<template>
  <Button @pressed="visible = true">Open Modal</Button>
  <Modal v-model:visible="visible">
    <div class="bg-white p-4 rounded">Content goes here</div>
  </Modal>
</template>

ShowModal (Imperative API)

showModal allows you to open a modal imperatively without needing to manage a visible state variable in your template. This is useful for simple alerts, confirmations, or modals triggered from non-component logic.

Examples

Basic Modal

Alignment

Imperative Modal (showModal)

ts
import { showModal, Button } from "fluekit";
import { h } from "vue";

// Simple text
showModal({
  content: "Hello World",
  alignment: Alignment.center,
});

// Using VNode
const { close } = showModal({
  content: h("div", { class: "modal-box" }, [
    h("h3", "Title"),
    h(Button, { onPressed: () => close() }, () => "Close"),
  ]),
  barrierDismissible: true,
  onClose: () => console.log("Closed"),
});

showModal Options

The showModal function accepts an options object with the following properties:

PropertyTypeDefaultDescription
contentstring | Component | VNode-The content to display in the modal.
contentPropsRecord<string, any>-Props to pass if content is a Component.
onClose() => void-Callback triggered when the modal is requested to close (e.g. barrier tap).
onAfterClose() => void-Callback triggered after the close animation completes.
...ModalPropsModalProps-All standard Modal props are supported (alignment, barrierDismissible, etc.).

The function returns an object with a close method:

ts
const { close } = showModal({ ... });
// later
close();

Props

PropTypeDefaultDescription
visiblebooleanfalseControls the visibility of the modal. Supports v-model.
barrierDismissiblebooleantrueWhether tapping the barrier closes the modal.
barrierColorstring'rgba(0, 0, 0, 0.5)'Color of the background barrier.
alignmentAlignmentAlignment.centerAlignment of the content within the modal.
zIndexnumberuseZIndex()Z-index of the modal.

Events

EventPayloadDescription
update:visiblebooleanEmitted when visibility changes (e.g., barrier tap).
close-Emitted when the modal is closed via barrier tap.

Slots

NameDescription
defaultThe content of the modal.