fix(Modal/Popover/Slideover)!: rename prevent-close to dismissible + uniformize docs

This commit is contained in:
Benjamin Canac
2024-12-16 13:11:10 +01:00
parent fdaff6630f
commit 6fb426fc17
10 changed files with 148 additions and 73 deletions

View File

@@ -11,7 +11,7 @@ const appConfig = _appConfig as AppConfig & { ui: { drawer: Partial<typeof theme
const drawer = tv({ extend: tv(theme), ...(appConfig.ui?.drawer || {}) })
export interface DrawerProps extends Pick<DrawerRootProps, 'activeSnapPoint' | 'closeThreshold' | 'defaultOpen' | 'direction' | 'dismissible' | 'fadeFromIndex' | 'fixed' | 'modal' | 'nested' | 'direction' | 'open' | 'scrollLockTimeout' | 'shouldScaleBackground' | 'snapPoints'> {
export interface DrawerProps extends Pick<DrawerRootProps, 'activeSnapPoint' | 'closeThreshold' | 'defaultOpen' | 'direction' | 'fadeFromIndex' | 'fixed' | 'modal' | 'nested' | 'direction' | 'open' | 'scrollLockTimeout' | 'shouldScaleBackground' | 'snapPoints'> {
/**
* The element or component this component should render as.
* @defaultValue 'div'
@@ -36,6 +36,11 @@ export interface DrawerProps extends Pick<DrawerRootProps, 'activeSnapPoint' | '
* @defaultValue true
*/
portal?: boolean
/**
* When `false`, the drawer will not close when clicking outside or pressing escape.
* @defaultValue true
*/
dismissible?: boolean
class?: any
ui?: Partial<typeof drawer.slots>
}

View File

@@ -48,10 +48,10 @@ export interface ModalProps extends DialogRootProps {
*/
closeIcon?: string
/**
* When `true`, the modal will not close when clicking outside.
* @defaultValue false
* When `false`, the modal will not close when clicking outside or pressing escape.
* @defaultValue true
*/
preventClose?: boolean
dismissible?: boolean
class?: any
ui?: Partial<typeof modal.slots>
}
@@ -85,7 +85,8 @@ const props = withDefaults(defineProps<ModalProps>(), {
portal: true,
overlay: true,
transition: true,
modal: true
modal: true,
dismissible: true
})
const emits = defineEmits<ModalEmits>()
const slots = defineSlots<ModalSlots>()
@@ -96,7 +97,7 @@ const appConfig = useAppConfig()
const rootProps = useForwardPropsEmits(reactivePick(props, 'open', 'defaultOpen', 'modal'), emits)
const contentProps = toRef(() => props.content)
const contentEvents = computed(() => {
if (props.preventClose) {
if (!props.dismissible) {
return {
pointerDownOutside: (e: Event) => e.preventDefault(),
interactOutside: (e: Event) => e.preventDefault(),

View File

@@ -32,10 +32,10 @@ export interface PopoverProps extends PopoverRootProps, Pick<HoverCardRootProps,
*/
portal?: boolean
/**
* When `true`, the popover will not close when clicking outside.
* @defaultValue false
* When `false`, the popover will not close when clicking outside or pressing escape.
* @defaultValue true
*/
preventClose?: boolean
dismissible?: boolean
class?: any
ui?: Partial<typeof popover.slots>
}
@@ -61,7 +61,8 @@ const props = withDefaults(defineProps<PopoverProps>(), {
portal: true,
mode: 'click',
openDelay: 0,
closeDelay: 0
closeDelay: 0,
dismissible: true
})
const emits = defineEmits<PopoverEmits>()
const slots = defineSlots<PopoverSlots>()
@@ -70,7 +71,7 @@ const pick = props.mode === 'hover' ? reactivePick(props, 'defaultOpen', 'open',
const rootProps = useForwardPropsEmits(pick, emits)
const contentProps = toRef(() => defu(props.content, { side: 'bottom', sideOffset: 8, collisionPadding: 8 }) as PopoverContentProps)
const contentEvents = computed(() => {
if (props.preventClose) {
if (!props.dismissible) {
return {
pointerDownOutside: (e: Event) => e.preventDefault(),
interactOutside: (e: Event) => e.preventDefault(),

View File

@@ -46,10 +46,10 @@ export interface SlideoverProps extends DialogRootProps {
*/
closeIcon?: string
/**
* When `true`, the slideover will not close when clicking outside.
* @defaultValue false
* When `false`, the slideover will not close when clicking outside or pressing escape.
* @defaultValue true
*/
preventClose?: boolean
dismissible?: boolean
class?: any
ui?: Partial<typeof slideover.slots>
}
@@ -84,6 +84,7 @@ const props = withDefaults(defineProps<SlideoverProps>(), {
overlay: true,
transition: true,
modal: true,
dismissible: true,
side: 'right'
})
const emits = defineEmits<SlideoverEmits>()
@@ -95,7 +96,7 @@ const appConfig = useAppConfig()
const rootProps = useForwardPropsEmits(reactivePick(props, 'open', 'defaultOpen', 'modal'), emits)
const contentProps = toRef(() => props.content)
const contentEvents = computed(() => {
if (props.preventClose) {
if (!props.dismissible) {
return {
pointerDownOutside: (e: Event) => e.preventDefault(),
interactOutside: (e: Event) => e.preventDefault(),