Usage
Use a Button or any other component in the default slot of the Modal.
Then, use the #content slot to add the content displayed when the Modal is open.
<template>
<B24Modal>
<B24Button label="Open" />
<template #content>
<Placeholder class="h-48" />
</template>
</B24Modal>
</template>
You can also use the #header, #body and #footer slots to customize the Modal's content.
Title
Use the title prop to set the title of the Modal's header.
<template>
<B24Modal title="Modal with title">
<B24Button label="Open" />
<template #body>
<Placeholder class="h-48" />
</template>
</B24Modal>
</template>
Description
Use the description prop to set the description of the Modal's header.
<template>
<B24Modal
title="Modal with description"
description="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
>
<B24Button label="Open" />
<template #body>
<Placeholder class="h-48" />
</template>
</B24Modal>
</template>
Close
Use the close prop to customize or hide the close button (with false value) displayed in the Modal's header.
You can pass any property from the Button component to customize it.
<template>
<B24Modal
title="Modal with close button"
:close="{
color: 'air-secondary-accent-2',
class: 'rounded-full'
}"
>
<B24Button label="Open" />
<template #body>
<Placeholder class="h-48" />
</template>
</B24Modal>
</template>
#content slot is used as it's a part of the header.Close Icon
Use the close-icon prop to customize the close button Icon.
<script setup lang="ts">
import RocketIcon from '@bitrix24/b24icons-vue/main/RocketIcon'
</script>
<template>
<B24Modal title="Modal with close button" :close-icon="RocketIcon">
<B24Button label="Open" />
<template #body>
<Placeholder class="h-48" />
</template>
</B24Modal>
</template>
Transition
Use the transition prop to control whether the Modal is animated or not. Defaults to true.
<template>
<B24Modal :transition="false" title="Modal without transition">
<B24Button label="Open" />
<template #body>
<Placeholder class="h-48" />
</template>
</B24Modal>
</template>
Overlay
Use the overlay prop to control whether the Modal has an overlay or not. Defaults to true.
<template>
<B24Modal :overlay="false" title="Modal without overlay">
<B24Button label="Open" />
<template #body>
<Placeholder class="h-48" />
</template>
</B24Modal>
</template>
Overlay blur
If you want to disable background blur, you should use the overlayBlur prop.
The overlayBlur prop has 3 options:
auto: (default) when the user has not requested reduced motionon: always use bluroff: do not use blur
<template>
<B24Modal overlay-blur="auto" title="Overlay blur">
<B24Button label="Open" />
<template #body>
<Placeholder class="h-48" />
</template>
</B24Modal>
</template>
Modal
Use the modal prop to control whether the Modal blocks interaction with outside content. Defaults to true.
modal is set to false, the overlay is automatically disabled and outside content becomes interactive.<template>
<B24Modal :modal="false" title="Modal interactive">
<B24Button label="Open" />
<template #body>
<Placeholder class="h-48" />
</template>
</B24Modal>
</template>
Dismissible
Use the dismissible prop to control whether the Modal is dismissible when clicking outside of it or pressing escape. Defaults to true.
close:prevent event will be emitted when the user tries to close it.modal: false with dismissible: false to make the Modal's background interactive without closing it.<template>
<B24Modal :dismissible="false" title="Modal non-dismissible">
<B24Button label="Open" />
<template #body>
<Placeholder class="h-48" />
</template>
</B24Modal>
</template>
Scrollable
Use the scrollable prop to make the Modal's content scrollable within the overlay.
modal: false is not compatible and overlay: false only removes the background.<template>
<B24Modal scrollable title="Modal scrollable">
<B24Button label="Open" />
<template #body>
<Placeholder class="h-full" />
</template>
</B24Modal>
</template>
Fullscreen
Use the fullscreen prop to make the Modal fullscreen.
<template>
<B24Modal fullscreen title="Modal fullscreen">
<B24Button label="Open" />
<template #body>
<Placeholder class="h-full" />
</template>
</B24Modal>
</template>
Examples
Control open state
You can control the open state by using the default-open prop or the v-model:open directive.
defineShortcuts, you can toggle the Modal by pressing O.Programmatic usage
You can use the useOverlay composable to open a Modal programmatically.
App component which uses the OverlayProvider component.First, create a modal component that will be opened programmatically:
close event when the modal is closed or dismissed here. You can emit any data through the close event, however, the event must be emitted in order to capture the return value.Then, use it in your app:
emit('close').Nested modals
You can nest modals within each other.
With footer slot
Use the #footer slot to add content after the Modal's body.
With command palette
You can use a CommandPalette component inside the Modal's content.
API
Props
Slots
Emits
Theme
export default defineAppConfig({
b24ui: {
modal: {
slots: {
overlay: 'fixed inset-0',
content: 'base-mode bg-(--ui-color-bg-content-primary) flex flex-col gap-[20px] focus:outline-none p-[24px] pt-[20px]',
contentWrapper: 'flex flex-col gap-[15px] pt-[4px]',
header: 'flex items-start justify-between gap-[6px]',
wrapper: '',
body: 'flex-1 text-(length:--ui-font-size-md) leading-normal',
footer: 'flex items-center justify-between gap-[10px] border-t border-t-1 border-t-(--ui-color-divider-default) pt-[18px]',
title: 'font-[family-name:var(--ui-font-family-primary)] text-(--b24ui-typography-label-color) font-(--ui-font-weight-medium) mb-0 text-[calc(var(--ui-font-size-2xl)+2px)]/(--ui-font-size-2xl)',
description: 'mt-1 text-(--b24ui-typography-description-color) text-(length:--ui-font-size-sm)',
close: '-mt-[4px]'
},
variants: {
overlayBlur: {
auto: {
overlay: 'motion-safe:backdrop-blur-[2px]'
},
on: {
overlay: 'backdrop-blur-[2px]'
},
off: {
overlay: ''
}
},
transition: {
true: {
overlay: 'motion-safe:data-[state=open]:animate-[fade-in_200ms_ease-out] motion-safe:data-[state=closed]:animate-[fade-out_200ms_ease-in]',
content: 'motion-safe:data-[state=open]:animate-[scale-in_200ms_ease-out] motion-safe:data-[state=closed]:animate-[scale-out_200ms_ease-in]'
}
},
fullscreen: {
true: {
content: 'inset-0'
},
false: {
content: 'w-[calc(100vw-2rem)] max-w-[32rem] rounded-[calc(var(--ui-border-radius-xl)-2px)] shadow-lg',
contentWrapper: ''
}
},
overlay: {
true: {
overlay: 'bg-[#003366]/20'
}
},
scrollable: {
true: {
overlay: 'overflow-y-auto',
content: 'relative'
},
false: {
content: 'fixed',
body: 'overflow-y-auto'
}
},
scrollbarThin: {
true: {
body: 'scrollbar-thin'
}
}
},
compoundVariants: [
{
scrollable: true,
fullscreen: false,
class: {
overlay: 'grid place-items-center p-4 sm:py-8'
}
},
{
scrollable: false,
fullscreen: false,
class: {
content: 'top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 max-h-[calc(100dvh-2rem)] sm:max-h-[calc(100dvh-4rem)]',
contentWrapper: 'overflow-hidden'
}
}
],
defaultVariants: {
scrollbarThin: true,
overlayBlur: 'auto'
}
}
}
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import bitrix24UIPluginVite from '@bitrix24/b24ui-nuxt/vite'
export default defineConfig({
plugins: [
vue(),
bitrix24UIPluginVite({
b24ui: {
modal: {
slots: {
overlay: 'fixed inset-0',
content: 'base-mode bg-(--ui-color-bg-content-primary) flex flex-col gap-[20px] focus:outline-none p-[24px] pt-[20px]',
contentWrapper: 'flex flex-col gap-[15px] pt-[4px]',
header: 'flex items-start justify-between gap-[6px]',
wrapper: '',
body: 'flex-1 text-(length:--ui-font-size-md) leading-normal',
footer: 'flex items-center justify-between gap-[10px] border-t border-t-1 border-t-(--ui-color-divider-default) pt-[18px]',
title: 'font-[family-name:var(--ui-font-family-primary)] text-(--b24ui-typography-label-color) font-(--ui-font-weight-medium) mb-0 text-[calc(var(--ui-font-size-2xl)+2px)]/(--ui-font-size-2xl)',
description: 'mt-1 text-(--b24ui-typography-description-color) text-(length:--ui-font-size-sm)',
close: '-mt-[4px]'
},
variants: {
overlayBlur: {
auto: {
overlay: 'motion-safe:backdrop-blur-[2px]'
},
on: {
overlay: 'backdrop-blur-[2px]'
},
off: {
overlay: ''
}
},
transition: {
true: {
overlay: 'motion-safe:data-[state=open]:animate-[fade-in_200ms_ease-out] motion-safe:data-[state=closed]:animate-[fade-out_200ms_ease-in]',
content: 'motion-safe:data-[state=open]:animate-[scale-in_200ms_ease-out] motion-safe:data-[state=closed]:animate-[scale-out_200ms_ease-in]'
}
},
fullscreen: {
true: {
content: 'inset-0'
},
false: {
content: 'w-[calc(100vw-2rem)] max-w-[32rem] rounded-[calc(var(--ui-border-radius-xl)-2px)] shadow-lg',
contentWrapper: ''
}
},
overlay: {
true: {
overlay: 'bg-[#003366]/20'
}
},
scrollable: {
true: {
overlay: 'overflow-y-auto',
content: 'relative'
},
false: {
content: 'fixed',
body: 'overflow-y-auto'
}
},
scrollbarThin: {
true: {
body: 'scrollbar-thin'
}
}
},
compoundVariants: [
{
scrollable: true,
fullscreen: false,
class: {
overlay: 'grid place-items-center p-4 sm:py-8'
}
},
{
scrollable: false,
fullscreen: false,
class: {
content: 'top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 max-h-[calc(100dvh-2rem)] sm:max-h-[calc(100dvh-4rem)]',
contentWrapper: 'overflow-hidden'
}
}
],
defaultVariants: {
scrollbarThin: true,
overlayBlur: 'auto'
}
}
}
})
]
})