feat: add autofill and onClose params in notification service api (#7162)

This PR add autofill and onClose params in notification service api for better user experiences.

[Related PR in blocksuite](https://github.com/toeverything/blocksuite/pull/7230)
This commit is contained in:
akumatus
2024-06-07 02:48:36 +00:00
parent 79e1e8dd2f
commit 38dde7f5b7

View File

@@ -169,14 +169,19 @@ export function patchNotificationService(
confirmText, confirmText,
placeholder, placeholder,
cancelText, cancelText,
autofill,
abort, abort,
}) => { }) => {
return new Promise<string | null>(resolve => { return new Promise<string | null>(resolve => {
let value = ''; let value = autofill || '';
const description = ( const description = (
<div> <div>
<span style={{ marginBottom: 12 }}>{toReactNode(message)}</span> <span style={{ marginBottom: 12 }}>{toReactNode(message)}</span>
<Input placeholder={placeholder} onChange={e => (value = e)} /> <Input
placeholder={placeholder}
defaultValue={value}
onChange={e => (value = e)}
/>
</div> </div>
); );
openConfirmModal({ openConfirmModal({
@@ -189,7 +194,6 @@ export function patchNotificationService(
cancelButtonOptions: { cancelButtonOptions: {
children: cancelText ?? 'Cancel', children: cancelText ?? 'Cancel',
}, },
onConfirm: () => { onConfirm: () => {
resolve(value); resolve(value);
}, },
@@ -229,9 +233,12 @@ export function patchNotificationService(
onClick: notification.action.onClick, onClick: notification.action.onClick,
} }
: undefined, : undefined,
onDismiss: notification.onClose,
}, },
{ {
duration: notification.duration || 0, duration: notification.duration || 0,
onDismiss: notification.onClose,
onAutoClose: notification.onClose,
} }
); );