♻️(front) enable custom size on Dialog
We want to have a Dialog that is constrained in width. Thus, introducing this variant enables this possibility and many more in the future.
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
|||||||
import { Div, Button, Box, VerticallyOffCenter } from '@/primitives'
|
import { Div, Button, Box, VerticallyOffCenter } from '@/primitives'
|
||||||
import { text } from './Text'
|
import { text } from './Text'
|
||||||
import { MutableRefObject } from 'react'
|
import { MutableRefObject } from 'react'
|
||||||
|
import { css } from '@/styled-system/css'
|
||||||
|
|
||||||
const StyledModalOverlay = styled(ModalOverlay, {
|
const StyledModalOverlay = styled(ModalOverlay, {
|
||||||
base: {
|
base: {
|
||||||
@@ -48,6 +49,24 @@ const StyledRACDialog = styled(RACDialog, {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const ModalContent = styled('div', {
|
||||||
|
base: {
|
||||||
|
margin: 'auto',
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
size: {
|
||||||
|
full: {
|
||||||
|
width: 'fit-content',
|
||||||
|
maxWidth: '100%',
|
||||||
|
},
|
||||||
|
large: {
|
||||||
|
width: '100%',
|
||||||
|
xl: { width: '1200px' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
export type DialogProps = RACDialogProps & {
|
export type DialogProps = RACDialogProps & {
|
||||||
title?: string
|
title?: string
|
||||||
onClose?: () => void
|
onClose?: () => void
|
||||||
@@ -63,6 +82,7 @@ export type DialogProps = RACDialogProps & {
|
|||||||
onOpenChange?: (isOpen: boolean) => void
|
onOpenChange?: (isOpen: boolean) => void
|
||||||
type?: 'flex'
|
type?: 'flex'
|
||||||
innerRef?: MutableRefObject<HTMLDivElement | null>
|
innerRef?: MutableRefObject<HTMLDivElement | null>
|
||||||
|
size?: 'full' | 'large'
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Dialog = ({
|
export const Dialog = ({
|
||||||
@@ -72,6 +92,7 @@ export const Dialog = ({
|
|||||||
isOpen,
|
isOpen,
|
||||||
onOpenChange,
|
onOpenChange,
|
||||||
innerRef,
|
innerRef,
|
||||||
|
size = 'full',
|
||||||
...dialogProps
|
...dialogProps
|
||||||
}: DialogProps) => {
|
}: DialogProps) => {
|
||||||
const isAlert = dialogProps['role'] === 'alertdialog'
|
const isAlert = dialogProps['role'] === 'alertdialog'
|
||||||
@@ -94,9 +115,16 @@ export const Dialog = ({
|
|||||||
<StyledRACDialog {...dialogProps}>
|
<StyledRACDialog {...dialogProps}>
|
||||||
{({ close }) => (
|
{({ close }) => (
|
||||||
<VerticallyOffCenter>
|
<VerticallyOffCenter>
|
||||||
<Div margin="auto" width="fit-content" maxWidth="full">
|
<ModalContent size={size}>
|
||||||
<Div margin="1rem" pointerEvents="auto">
|
<Div margin="1rem" pointerEvents="auto">
|
||||||
<Box size="sm" type={boxType} ref={innerRef}>
|
<Box
|
||||||
|
size="sm"
|
||||||
|
type={boxType}
|
||||||
|
ref={innerRef}
|
||||||
|
className={css({
|
||||||
|
padding: '1.5rem',
|
||||||
|
})}
|
||||||
|
>
|
||||||
{!!title && (
|
{!!title && (
|
||||||
<Heading
|
<Heading
|
||||||
slot="title"
|
slot="title"
|
||||||
@@ -124,7 +152,7 @@ export const Dialog = ({
|
|||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</Div>
|
</Div>
|
||||||
</Div>
|
</ModalContent>
|
||||||
</VerticallyOffCenter>
|
</VerticallyOffCenter>
|
||||||
)}
|
)}
|
||||||
</StyledRACDialog>
|
</StyledRACDialog>
|
||||||
|
|||||||
Reference in New Issue
Block a user