Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use flex center to get rid of modal blur #108

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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