Skip to content

Commit

Permalink
优化ts声明
Browse files Browse the repository at this point in the history
  • Loading branch information
asurance committed Jul 7, 2024
1 parent 7499ae5 commit 37cd300
Show file tree
Hide file tree
Showing 19 changed files with 305 additions and 234 deletions.
18 changes: 14 additions & 4 deletions demos/ant-design.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import { Button, Drawer, DrawerProps, Modal, ModalProps, Space } from 'antd';
type OpenModalProps = OpenableProps<void> &
Omit<ModalProps, 'open' | 'onOk' | 'onCancel' | 'afterClose'>;

const openModal = openify<void, OpenModalProps, ModalProps>(Modal, {
transformProps({ visible, onClose, afterClose, ...restProps }) {
const openModal = openify(Modal, {
transformProps({
visible,
onClose,
afterClose,
...restProps
}: OpenModalProps) {
return {
...restProps,
open: visible,
Expand All @@ -20,8 +25,13 @@ const openModal = openify<void, OpenModalProps, ModalProps>(Modal, {
type OpenDrawerProps = OpenableProps<void> &
Omit<DrawerProps, 'open' | 'onClose' | 'afterOpenChange'>;

const openDrawer = openify<void, OpenDrawerProps, DrawerProps>(Drawer, {
transformProps({ visible, onClose, afterClose, ...restProps }) {
const openDrawer = openify(Drawer, {
transformProps({
visible,
onClose,
afterClose,
...restProps
}: OpenDrawerProps) {
return {
...restProps,
open: visible,
Expand Down
18 changes: 14 additions & 4 deletions demos/arco-design.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ import '@arco-design/web-react/dist/css/arco.css';
type OpenModalProps = OpenableProps<void> &
Omit<ModalProps, 'visible' | 'onOk' | 'onCancel' | 'afterClose'>;

const openModal = openify<void, OpenModalProps, ModalProps>(Modal, {
transformProps({ visible, onClose, afterClose, ...restProps }) {
const openModal = openify(Modal, {
transformProps({
visible,
onClose,
afterClose,
...restProps
}: OpenModalProps) {
return {
...restProps,
visible,
Expand All @@ -29,8 +34,13 @@ const openModal = openify<void, OpenModalProps, ModalProps>(Modal, {
type OpenDrawerProps = OpenableProps<void> &
Omit<DrawerProps, 'visible' | 'onOk' | 'onCancel' | 'afterClose'>;

const openDrawer = openify<void, OpenDrawerProps, DrawerProps>(Drawer, {
transformProps({ visible, onClose, afterClose, ...restProps }) {
const openDrawer = openify(Drawer, {
transformProps({
visible,
onClose,
afterClose,
...restProps
}: OpenDrawerProps) {
return {
...restProps,
visible,
Expand Down
13 changes: 2 additions & 11 deletions demos/close-by-ref.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import React, {
RefAttributes,
createRef,
forwardRef,
useImperativeHandle,
} from 'react';
import React, { createRef, forwardRef, useImperativeHandle } from 'react';
import { Button, Modal, Space } from '@douyinfe/semi-ui';
import { OpenableProps, openify } from 'openify';

Expand Down Expand Up @@ -39,11 +34,7 @@ const MyModal = forwardRef<MyModalRef, MyModalProps>(
},
);

const openMyModal = openify<
void,
MyModalProps & RefAttributes<MyModalRef>,
MyModalProps
>(MyModal);
const openMyModal = openify(MyModal);

export default () => (
<Space>
Expand Down
17 changes: 7 additions & 10 deletions demos/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ const MyModal = ({ visible, onClose, afterClose, title }: MyModalProps) => {
);
};

const openMyModalDefault = openify<void, MyModalProps, MyModalProps>(MyModal);
const openMyModalDefault = openify(MyModal);

const openMyModalWithRenderHook = openify<void, MyModalProps, MyModalProps>(
MyModal,
{
renderHook: node => {
return (
<myContext.Provider value="context提供内容">{node}</myContext.Provider>
);
},
const openMyModalWithRenderHook = openify(MyModal, {
renderHook: node => {
return (
<myContext.Provider value="context提供内容">{node}</myContext.Provider>
);
},
);
});

export default () => (
<myContext.Provider value="context提供内容">
Expand Down
2 changes: 1 addition & 1 deletion demos/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const MyModal = ({ visible, onClose, afterClose }: MyModalProps) => {
);
};

const openModal = openify<void, MyModalProps, MyModalProps>(MyModal);
const openModal = openify(MyModal);

export default () => (
<Button onClick={() => openModal({ title: '自定义弹窗' })}>自定义弹窗</Button>
Expand Down
6 changes: 1 addition & 5 deletions demos/mydrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ const MyAsyncModal = ({
);
};

export const openMyAsyncModal = openify<
void,
MyAsyncModalProps,
MyAsyncModalProps
>(MyAsyncModal);
export const openMyAsyncModal = openify(MyAsyncModal);

export default MyAsyncModal;
2 changes: 1 addition & 1 deletion demos/promisify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const MyModal = ({ visible, onClose, afterClose, id }: MyModalProps) => {
);
};

const openMyModal = openify<Value, MyModalProps, MyModalProps>(MyModal);
const openMyModal = openify(MyModal);

export default () => {
const [taskId, setTaskId] = useState('');
Expand Down
62 changes: 33 additions & 29 deletions demos/semi-design.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,45 @@ import { SideSheetReactProps } from '@douyinfe/semi-ui/lib/es/sideSheet';
type OpenModalProps = OpenableProps<void> &
Omit<ModalReactProps, 'visible' | 'onOk' | 'onCancel' | 'afterClose'>;

const openModal = openify<void, OpenModalProps, ModalReactProps>(
Modal as ComponentType<ModalReactProps>,
{
transformProps({ visible, onClose, afterClose, ...restProps }) {
return {
...restProps,
visible,
onOk: onClose,
onCancel: onClose,
afterClose,
};
},
const openModal = openify(Modal as ComponentType<ModalReactProps>, {
transformProps({
visible,
onClose,
afterClose,
...restProps
}: OpenModalProps) {
return {
...restProps,
visible,
onOk: onClose,
onCancel: onClose,
afterClose,
};
},
);
});

type OpenSideSheetProps = OpenableProps<void> &
Omit<SideSheetReactProps, 'visible' | 'onCancel' | 'afterVisibleChange'>;

const openSideSheet = openify<void, OpenSideSheetProps, SideSheetReactProps>(
SideSheet as ComponentType<SideSheetReactProps>,
{
transformProps({ visible, onClose, afterClose, ...restProps }) {
return {
...restProps,
visible,
onCancel: onClose,
afterVisibleChange: isVisible => {
if (!isVisible) {
afterClose();
}
},
};
},
const openSideSheet = openify(SideSheet as ComponentType<SideSheetReactProps>, {
transformProps({
visible,
onClose,
afterClose,
...restProps
}: OpenSideSheetProps) {
return {
...restProps,
visible,
onCancel: onClose,
afterVisibleChange: isVisible => {
if (!isVisible) {
afterClose();
}
},
};
},
);
});

export default () => (
<Space>
Expand Down
2 changes: 1 addition & 1 deletion demos/static-call.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const MyModal = ({ visible, onClose, afterClose, title }: MyModalProps) => {
);
};

const openMyModal = openify<void, MyModalProps, MyModalProps>(MyModal);
const openMyModal = openify(MyModal);

export default () => (
<Space>
Expand Down
13 changes: 2 additions & 11 deletions docs/guide/Q&A/close-by-ref.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# 如果由外部主动关闭

```tsx
import React, {
RefAttributes,
createRef,
forwardRef,
useImperativeHandle,
} from 'react';
import React, { createRef, forwardRef, useImperativeHandle } from 'react';
import { Button, Modal, Space } from '@douyinfe/semi-ui';
import { OpenableProps, openify } from 'openify';

Expand Down Expand Up @@ -42,11 +37,7 @@ const MyModal = forwardRef<MyModalRef, MyModalProps>(
},
);

const openMyModal = openify<
void,
MyModalProps & RefAttributes<MyModalRef>,
MyModalProps
>(MyModal);
const openMyModal = openify(MyModal);

export default () => (
<Space>
Expand Down
17 changes: 7 additions & 10 deletions docs/guide/Q&A/context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,15 @@ const MyModal = ({ visible, onClose, afterClose, title }: MyModalProps) => {
);
};

const openMyModalDefault = openify<void, MyModalProps, MyModalProps>(MyModal);
const openMyModalDefault = openify(MyModal);

const openMyModalWithRenderHook = openify<void, MyModalProps, MyModalProps>(
MyModal,
{
renderHook: node => {
return (
<myContext.Provider value="context提供内容">{node}</myContext.Provider>
);
},
const openMyModalWithRenderHook = openify(MyModal, {
renderHook: node => {
return (
<myContext.Provider value="context提供内容">{node}</myContext.Provider>
);
},
);
});

export default () => (
<myContext.Provider value="context提供内容">
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/feature/error.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const MyModal = ({ visible, onClose, afterClose }: MyModalProps) => {
);
};

const openModal = openify<void, MyModalProps, MyModalProps>(MyModal);
const openModal = openify(MyModal);

export default () => (
<Button onClick={() => openModal({ title: '自定义弹窗' })}>自定义弹窗</Button>
Expand Down
Loading

0 comments on commit 37cd300

Please sign in to comment.