mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
chore: bump blocksuite (#7152)
## Features - https://github.com/toeverything/BlockSuite/pull/7208 @pengx17 - https://github.com/toeverything/BlockSuite/pull/7207 @pengx17 - https://github.com/toeverything/BlockSuite/pull/7206 @regischen - https://github.com/toeverything/BlockSuite/pull/7194 @akumatus - https://github.com/toeverything/BlockSuite/pull/7209 @Saul-Mirone ## Bugfix - https://github.com/toeverything/BlockSuite/pull/7205 @fundon - https://github.com/toeverything/BlockSuite/pull/7211 @L-Sun - https://github.com/toeverything/BlockSuite/pull/7210 @fundon ## Refactor ## Misc - https://github.com/toeverything/BlockSuite/pull/7203 @fundon Also added prompt implementation to fix type change issue 
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
ConfirmModal,
|
||||
type ConfirmModalProps,
|
||||
useConfirmModal,
|
||||
usePromptModal,
|
||||
} from './confirm-modal';
|
||||
|
||||
export default {
|
||||
@@ -57,3 +58,20 @@ export const AutoClose = () => {
|
||||
|
||||
return <Button onClick={onConfirm}>Show confirm</Button>;
|
||||
};
|
||||
|
||||
export const Prompt = () => {
|
||||
const openPrompt = usePromptModal();
|
||||
|
||||
const showPrompt = async () => {
|
||||
const value = await openPrompt({
|
||||
placeholder: 'Enter your name',
|
||||
title: 'Give me a string',
|
||||
message: 'What is your name?',
|
||||
});
|
||||
if (value) {
|
||||
alert('your name is ' + value);
|
||||
}
|
||||
};
|
||||
|
||||
return <Button onClick={showPrompt}>Show prompt</Button>;
|
||||
};
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import { DialogTrigger } from '@radix-ui/react-dialog';
|
||||
import clsx from 'clsx';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import type { PropsWithChildren, ReactNode } from 'react';
|
||||
import { createContext, useCallback, useContext, useState } from 'react';
|
||||
|
||||
import type { ButtonProps } from '../button';
|
||||
import { Button } from '../button';
|
||||
import Input from '../input';
|
||||
import type { ModalProps } from './modal';
|
||||
import { Modal } from './modal';
|
||||
import * as styles from './styles.css';
|
||||
@@ -147,6 +149,7 @@ export const ConfirmModalProvider = ({ children }: PropsWithChildren) => {
|
||||
</ConfirmModalContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useConfirmModal = () => {
|
||||
const context = useContext(ConfirmModalContext);
|
||||
if (!context) {
|
||||
@@ -159,3 +162,53 @@ export const useConfirmModal = () => {
|
||||
closeConfirmModal: context.closeConfirmModal,
|
||||
};
|
||||
};
|
||||
|
||||
export const usePromptModal = () => {
|
||||
const { closeConfirmModal, openConfirmModal } = useConfirmModal();
|
||||
const t = useAFFiNEI18N();
|
||||
return useCallback(
|
||||
(props: {
|
||||
confirmText?: string;
|
||||
cancelText?: string;
|
||||
placeholder?: string;
|
||||
message: ReactNode;
|
||||
title: ReactNode;
|
||||
abort?: AbortSignal;
|
||||
}) => {
|
||||
return new Promise<string | null>(resolve => {
|
||||
let value = '';
|
||||
const message = (
|
||||
<div className={styles.promptModalContent}>
|
||||
{props.message}
|
||||
<Input
|
||||
placeholder={props.placeholder}
|
||||
onChange={e => (value = e)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
openConfirmModal({
|
||||
...props,
|
||||
confirmButtonOptions: {
|
||||
children: props.confirmText ?? t['Confirm'](),
|
||||
type: 'primary',
|
||||
},
|
||||
cancelButtonOptions: {
|
||||
children: props.cancelText ?? t['Cancel'](),
|
||||
},
|
||||
description: message,
|
||||
onConfirm: () => {
|
||||
resolve(value);
|
||||
},
|
||||
onCancel: () => {
|
||||
resolve(null);
|
||||
},
|
||||
});
|
||||
props.abort?.addEventListener('abort', () => {
|
||||
resolve(null);
|
||||
closeConfirmModal();
|
||||
});
|
||||
});
|
||||
},
|
||||
[closeConfirmModal, openConfirmModal, t]
|
||||
);
|
||||
};
|
||||
|
||||
@@ -91,3 +91,9 @@ globalStyle(`[data-modal="false"]${modalContentWrapper}`, {
|
||||
globalStyle(`[data-modal="false"] ${modalContent}`, {
|
||||
pointerEvents: 'auto',
|
||||
});
|
||||
|
||||
export const promptModalContent = style({
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: '12px',
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user