Skip to content

Commit

Permalink
fix: use flex center to get rid of modal blur
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 committed Nov 27, 2023
1 parent ba83dab commit c925b53
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 41 deletions.
76 changes: 40 additions & 36 deletions packages/components/src/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const Modal = forwardRef<HTMLDivElement, ModalProps>(
{
width,
height,
minHeight=194,
minHeight = 194,
title,
description,
withoutCloseButton = false,
Expand All @@ -67,42 +67,46 @@ export const Modal = forwardRef<HTMLDivElement, ModalProps>(
className={clsx(styles.modalOverlay, overlayClassName)}
{...otherOverlayOptions}
/>
<Dialog.Content
className={clsx(styles.modalContent, contentClassName)}
style={{
...assignInlineVars({
[styles.widthVar]: getVar(width, '50vw'),
[styles.heightVar]: getVar(height, 'unset'),
[styles.minHeightVar]: getVar(minHeight, '26px'),
}),
...contentStyle,
}}
{...otherContentOptions}
ref={ref}
>
{withoutCloseButton ? null : (
<Dialog.Close asChild>
<IconButton
className={styles.closeButton}
aria-label="Close"
type="plain"
{...closeButtonOptions}
>
<CloseIcon />
</IconButton>
</Dialog.Close>
)}
{title ? (
<Dialog.Title className={styles.modalHeader}>{title}</Dialog.Title>
) : null}
{description ? (
<Dialog.Description className={styles.modalDescription}>
{description}
</Dialog.Description>
) : null}
<div className={styles.modalContentWrapper}>
<Dialog.Content
className={clsx(styles.modalContent, contentClassName)}
style={{
...assignInlineVars({
[styles.widthVar]: getVar(width, '50vw'),
[styles.heightVar]: getVar(height, 'unset'),
[styles.minHeightVar]: getVar(minHeight, '26px'),
}),
...contentStyle,
}}
{...otherContentOptions}
ref={ref}
>
{withoutCloseButton ? null : (
<Dialog.Close asChild>
<IconButton
className={styles.closeButton}
aria-label="Close"
type="plain"
{...closeButtonOptions}
>
<CloseIcon />
</IconButton>
</Dialog.Close>
)}
{title ? (
<Dialog.Title className={styles.modalHeader}>
{title}
</Dialog.Title>
) : null}
{description ? (
<Dialog.Description className={styles.modalDescription}>
{description}
</Dialog.Description>
) : null}

{children}
</Dialog.Content>
{children}
</Dialog.Content>
</div>
</Dialog.Portal>
</Dialog.Root>
)
Expand Down
15 changes: 10 additions & 5 deletions packages/components/src/modal/styles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ export const modalOverlay = style({
zIndex: 'var(--affine-z-index-modal)',
});

export const modalContentWrapper = style({
position: 'fixed',
inset: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
zIndex: 'var(--affine-z-index-modal)',
});

export const modalContent = style({
vars: {
[widthVar]: '',
Expand All @@ -25,17 +34,13 @@ export const modalContent = style({
fontWeight: '400',
lineHeight: '1.6',
padding: '20px 24px',
position: 'relative',
backgroundColor: 'var(--affine-background-overlay-panel-color)',
boxShadow: 'var(--affine-popover-shadow)',
borderRadius: '12px',
maxHeight: 'calc(100vh - 32px)',
// :focus-visible will set outline
outline: 'none',
position: 'fixed',
zIndex: 'var(--affine-z-index-modal)',
top: ' 50%',
left: '50%',
transform: 'translate(-50%, -50%)',
});

export const closeButton = style({
Expand Down

0 comments on commit c925b53

Please sign in to comment.