Disclosure
An interactive component which expands/collapses content.
Jasmin starred 3 repositories
corvudev/corvu
import { CaretUpDown, X } from '@examples/primitives/disclosure/icons'
import Disclosure from 'corvu/disclosure'
import type { VoidComponent } from 'solid-js'
const DialogExample: VoidComponent = () => {
return (
<div class="mt-8 flex flex-col">
<Disclosure.Root collapseBehavior="hide">
{(props) => (
<>
<div class="flex items-center justify-between space-x-4">
<p class="font-medium">Jasmin starred 3 repositories</p>
<Disclosure.Trigger class="rounded-lg bg-corvu-100 p-1 text-corvu-dark transition-all duration-100 hover:bg-corvu-200 active:translate-y-0.5">
{props.expanded && <X size="20" />}
{!props.expanded && <CaretUpDown size="20" />}
</Disclosure.Trigger>
</div>
<div class="mt-2 rounded-lg bg-corvu-100 px-3 py-2 text-corvu-dark">
corvudev/corvu
</div>
<Disclosure.Content class="mt-1 space-y-1 overflow-hidden corvu-expanded:animate-expand corvu-collapsed:animate-collapse">
<div class="rounded-lg bg-corvu-100 px-3 py-2 text-corvu-dark">
solidjs/solid
</div>
<div class="rounded-lg bg-corvu-100 px-3 py-2 text-corvu-dark">
nitropage/nitropage
</div>
</Disclosure.Content>
</>
)}
</Disclosure.Root>
</div>
)
}
export default DialogExample
/** @type {import('tailwindcss').Config} */
export default {
content: ['./src/**/*.{ts,tsx}'],
theme: {
extend: {
colors: {
corvu: {
50: '#f2f0fe',
100: '#e6e2fd',
200: '#d4cbfb',
light: '#D4C0FF',
300: '#bcacf6',
400: '#a888f1',
500: '#9a6de9',
600: '#8f50dc',
700: '#7e41c3',
accent: '#7250AE',
800: '#63359c',
900: '#52317d',
dark: '#180f23',
1000: '#0C0812',
},
},
animation: {
expand: 'expand 200ms linear',
collapse: 'collapse 200ms linear',
},
keyframes: {
expand: {
'0%': {
opacity: '0',
height: '0px',
},
'100%': {
opacity: '1',
height: 'var(--corvu-collapse-content-height)',
},
},
collapse: {
'100%': {
opacity: '0',
height: '0px',
},
'0%': {
opacity: '1',
height: 'var(--corvu-collapse-content-height)',
},
},
},
},
},
plugins: [require('@corvu/tailwind')],
}
Features
- Supports modal and non-modal modes
- Customizable focus management
- Waits for pending animations before removing the dialog from the DOM
- Pressing the escape key and interacting outside closes the dialog
- Supports nested dialogs
Usage
import Dialog from 'corvu/dialog'
// Or
// import { Root, Trigger, ... } from 'corvu/dialog'
Anatomy
<Dialog.Root>
<Dialog.Trigger />
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Content>
<Dialog.Close />
<Dialog.Label />
<Dialog.Description />
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
Scrolling
By default, corvu prevents scrolling of elements outside of the dialog content while the dialog open. It will also add additional padding to the body to prevent the page from jumping when the scrollbar disappears. There is also a CSS variable called --scrollbar-width
which is present when the scrollbar is hidden. You can use this to prevent any fixed element from jumping:
<header
class="fixed top-0 inset-x-0 z-50"
style={{
'padding-right': 'var(--scrollbar-width, 0)',
}}
>
Header
</header>
Accessibility
Adheres to the Disclosure WAI-ARIA design pattern.
API reference
corvu@0.2.1
Developed and designed by Jasmin