mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
feat(core): add starAFFiNE and issueFeedback modal (#5718)
close TOV-482 https://github.com/toeverything/AFFiNE/assets/102217452/da1f74bc-4b8d-4d7f-987d-f53da98d92fe
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
export * from './confirm-modal';
|
||||
export * from './modal';
|
||||
export * from './overlay-modal';
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Button } from '../button';
|
||||
import { Input, type InputProps } from '../input';
|
||||
import { ConfirmModal, type ConfirmModalProps } from './confirm-modal';
|
||||
import { Modal, type ModalProps } from './modal';
|
||||
import { OverlayModal, type OverlayModalProps } from './overlay-modal';
|
||||
|
||||
export default {
|
||||
title: 'UI/Modal',
|
||||
@@ -65,5 +66,38 @@ const ConfirmModalTemplate: StoryFn<ConfirmModalProps> = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const OverlayModalTemplate: StoryFn<OverlayModalProps> = () => {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button onClick={() => setOpen(true)}>Open Overlay Modal</Button>
|
||||
<OverlayModal
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
title="Modal Title"
|
||||
description="Modal description"
|
||||
confirmButtonOptions={{
|
||||
type: 'primary',
|
||||
}}
|
||||
topImage={
|
||||
<div
|
||||
style={{
|
||||
width: '400px',
|
||||
height: '300px',
|
||||
background: '#66ccff',
|
||||
opacity: 0.1,
|
||||
color: '#fff',
|
||||
}}
|
||||
></div>
|
||||
}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const Confirm: StoryFn<ModalProps> =
|
||||
ConfirmModalTemplate.bind(undefined);
|
||||
|
||||
export const Overlay: StoryFn<ModalProps> =
|
||||
OverlayModalTemplate.bind(undefined);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { cssVar } from '@toeverything/theme';
|
||||
import { style } from '@vanilla-extract/css';
|
||||
|
||||
export const title = style({
|
||||
padding: '20px 24px 8px 24px',
|
||||
fontSize: cssVar('fontH6'),
|
||||
fontFamily: cssVar('fontFamily'),
|
||||
fontWeight: '600',
|
||||
lineHeight: '26px',
|
||||
});
|
||||
|
||||
export const content = style({
|
||||
padding: '0px 24px 8px',
|
||||
fontSize: cssVar('fontBase'),
|
||||
lineHeight: '24px',
|
||||
fontWeight: 400,
|
||||
});
|
||||
|
||||
export const footer = style({
|
||||
padding: '20px 24px',
|
||||
display: 'flex',
|
||||
justifyContent: 'flex-end',
|
||||
gap: '20px',
|
||||
});
|
||||
|
||||
export const gotItBtn = style({
|
||||
fontWeight: 500,
|
||||
});
|
||||
|
||||
export const buttonText = style({
|
||||
color: cssVar('pureWhite'),
|
||||
textDecoration: 'none',
|
||||
cursor: 'pointer',
|
||||
':visited': {
|
||||
color: cssVar('pureWhite'),
|
||||
},
|
||||
});
|
||||
102
packages/frontend/component/src/ui/modal/overlay-modal.tsx
Normal file
102
packages/frontend/component/src/ui/modal/overlay-modal.tsx
Normal file
@@ -0,0 +1,102 @@
|
||||
import { DialogTrigger } from '@radix-ui/react-dialog';
|
||||
import { cssVar } from '@toeverything/theme';
|
||||
import { memo, useCallback } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import { Button, type ButtonProps } from '../button';
|
||||
import { Modal, type ModalProps } from './modal';
|
||||
import * as styles from './overlay-modal.css';
|
||||
|
||||
const defaultContentOptions: ModalProps['contentOptions'] = {
|
||||
style: {
|
||||
padding: 0,
|
||||
overflow: 'hidden',
|
||||
boxShadow: cssVar('menuShadow'),
|
||||
},
|
||||
};
|
||||
const defaultOverlayOptions: ModalProps['overlayOptions'] = {
|
||||
style: {
|
||||
background: cssVar('white80'),
|
||||
backdropFilter: 'blur(2px)',
|
||||
},
|
||||
};
|
||||
|
||||
export interface OverlayModalProps extends ModalProps {
|
||||
to?: string;
|
||||
external?: boolean;
|
||||
topImage?: React.ReactNode;
|
||||
confirmText?: string;
|
||||
confirmButtonOptions?: ButtonProps;
|
||||
onConfirm?: () => void;
|
||||
cancelText?: string;
|
||||
cancelButtonOptions?: ButtonProps;
|
||||
withoutCancelButton?: boolean;
|
||||
}
|
||||
|
||||
export const OverlayModal = memo(function OverlayModal({
|
||||
open,
|
||||
topImage,
|
||||
onOpenChange,
|
||||
title,
|
||||
description,
|
||||
onConfirm,
|
||||
to,
|
||||
external,
|
||||
confirmButtonOptions,
|
||||
cancelButtonOptions,
|
||||
withoutCancelButton,
|
||||
contentOptions = defaultContentOptions,
|
||||
overlayOptions = defaultOverlayOptions,
|
||||
// FIXME: we need i18n
|
||||
cancelText = 'Cancel',
|
||||
confirmText = 'Confirm',
|
||||
width = 400,
|
||||
}: OverlayModalProps) {
|
||||
const handleConfirm = useCallback(() => {
|
||||
onOpenChange?.(false);
|
||||
onConfirm?.();
|
||||
}, [onOpenChange, onConfirm]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
contentOptions={contentOptions}
|
||||
overlayOptions={overlayOptions}
|
||||
open={open}
|
||||
width={width}
|
||||
onOpenChange={onOpenChange}
|
||||
withoutCloseButton
|
||||
>
|
||||
{topImage}
|
||||
<div className={styles.title}>{title}</div>
|
||||
<div className={styles.content}>{description}</div>
|
||||
<div className={styles.footer}>
|
||||
{!withoutCancelButton ? (
|
||||
<DialogTrigger asChild>
|
||||
<Button {...cancelButtonOptions}>{cancelText}</Button>
|
||||
</DialogTrigger>
|
||||
) : null}
|
||||
|
||||
{to ? (
|
||||
external ? (
|
||||
//FIXME: we need a more standardized way to implement this link with other click events
|
||||
<a href={to} target="_blank" rel="noreferrer">
|
||||
<Button onClick={handleConfirm} {...confirmButtonOptions}>
|
||||
{confirmText}
|
||||
</Button>
|
||||
</a>
|
||||
) : (
|
||||
<Link to={to}>
|
||||
<Button onClick={handleConfirm} {...confirmButtonOptions}>
|
||||
{confirmText}
|
||||
</Button>
|
||||
</Link>
|
||||
)
|
||||
) : (
|
||||
<Button onClick={handleConfirm} {...confirmButtonOptions}>
|
||||
{confirmText}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user