-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
870 additions
and
491 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,46 @@ | ||
# Modern.js Package | ||
# Openify | ||
|
||
## Setup | ||
> 方便 React 弹窗类使用的工具 | ||
Install the dependencies: | ||
## 快速上手 | ||
|
||
```bash | ||
pnpm run install | ||
``` | ||
|
||
## Get Started | ||
|
||
Run and debug the module: | ||
### 安装依赖 | ||
|
||
```bash | ||
pnpm run dev | ||
npm install openify | ||
# or | ||
yarn add openify | ||
# or | ||
pnpm add openify | ||
``` | ||
|
||
Run test cases: | ||
|
||
```bash | ||
pnpm run test | ||
### 使用`openify`开发组件 | ||
|
||
```tsx | ||
export type MyModalProps = OpenableProps<xxx> & { | ||
/** your props **/ | ||
}; | ||
|
||
const MyModal = openify( | ||
({ visible, onClose, afterClose, ... }: MyModalProps) => { | ||
// your code here | ||
return ( | ||
<Modal {/** your props **/}> | ||
{/** your content here **/} | ||
</Modal> | ||
); | ||
}, | ||
); | ||
|
||
export default MyModal; | ||
``` | ||
|
||
Build the module for production: | ||
### 使用 open 方法 | ||
|
||
```bash | ||
pnpm run build | ||
``` | ||
|
||
Enable optional features: | ||
|
||
```bash | ||
pnpm run new | ||
``` | ||
|
||
Other commands: | ||
|
||
```bash | ||
pnpm run lint # Lint and fix source files | ||
pnpm run change # Add a new changeset | ||
pnpm run bump # Update version and changelog via changeset | ||
pnpm run release # Release the package | ||
```tsx | ||
export default function MyApp() { | ||
return <Button onClick={() => MyModal.open()}>打开弹窗</Button>; | ||
} | ||
``` | ||
|
||
For more information, see the [Modern.js Module documentation](https://modernjs.dev/module-tools/en). | ||
## [在线文档](https://asurance.github.io/openify/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, { createRef, forwardRef, useImperativeHandle } from 'react'; | ||
import { Button, Modal, Space } from '@arco-design/web-react'; | ||
import { OpenableProps, openify } from 'openify'; | ||
|
||
import '@arco-design/web-react/dist/css/arco.css'; | ||
|
||
type MyModalProps = OpenableProps<void> & { | ||
title: string; | ||
}; | ||
|
||
type MyModalRef = { | ||
close: () => void; | ||
}; | ||
|
||
const MyModal = openify( | ||
forwardRef<MyModalRef, MyModalProps>( | ||
({ visible, onClose, afterClose, title }: MyModalProps, ref) => { | ||
useImperativeHandle( | ||
ref, | ||
() => ({ | ||
close() { | ||
onClose(); | ||
}, | ||
}), | ||
[], | ||
); | ||
return ( | ||
<Modal | ||
title={title} | ||
visible={visible} | ||
afterClose={afterClose} | ||
closable={false} | ||
> | ||
静态打开 | ||
</Modal> | ||
); | ||
}, | ||
), | ||
); | ||
|
||
export default () => ( | ||
<Space> | ||
<Button | ||
onClick={() => { | ||
const ref = createRef<MyModalRef>(); | ||
MyModal.open({ title: '标题', ref }); | ||
setTimeout(() => { | ||
ref.current?.close(); | ||
}, 1000); | ||
}} | ||
> | ||
打开弹窗 | ||
</Button> | ||
</Space> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { createContext, useContext } from 'react'; | ||
import { Button, Modal, Space } from '@arco-design/web-react'; | ||
import { OpenableProps, openify } from 'openify'; | ||
|
||
import '@arco-design/web-react/dist/css/arco.css'; | ||
|
||
const myContext = createContext('默认内容'); | ||
|
||
type MyModalProps = OpenableProps<void> & { | ||
title: string; | ||
}; | ||
|
||
const MyModal = openify( | ||
({ visible, onClose, afterClose, title }: MyModalProps) => { | ||
const context = useContext(myContext); | ||
return ( | ||
<Modal | ||
title={title} | ||
visible={visible} | ||
onOk={onClose} | ||
onCancel={onClose} | ||
afterClose={afterClose} | ||
> | ||
{context} | ||
</Modal> | ||
); | ||
}, | ||
); | ||
|
||
const MyModalWithContext = openify(MyModal, { | ||
bindToComponent: false, | ||
renderHook: node => { | ||
return ( | ||
<myContext.Provider value="context提供内容">{node}</myContext.Provider> | ||
); | ||
}, | ||
}); | ||
|
||
export default () => ( | ||
<myContext.Provider value="context提供内容"> | ||
<Space> | ||
<Button onClick={() => MyModal.open({ title: '弹窗' })}>打开弹窗</Button> | ||
<Button onClick={() => MyModalWithContext.open({ title: '弹窗' })}> | ||
打开弹窗 | ||
</Button> | ||
</Space> | ||
</myContext.Provider> | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import { Drawer } from '@arco-design/web-react'; | ||
import { OpenableProps, openify } from 'openify'; | ||
|
||
import '@arco-design/web-react/dist/css/arco.css'; | ||
|
||
type MyDrawerProps = OpenableProps<void> & { | ||
title: string; | ||
}; | ||
|
||
const MyDrawer = openify( | ||
({ visible, onClose, afterClose, title }: MyDrawerProps) => { | ||
return ( | ||
<Drawer | ||
title={title} | ||
visible={visible} | ||
onOk={onClose} | ||
onCancel={onClose} | ||
afterClose={afterClose} | ||
> | ||
抽屉内容 | ||
</Drawer> | ||
); | ||
}, | ||
); | ||
|
||
export default MyDrawer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["close-by-ref", "context"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# 如果由外部主动关闭 | ||
|
||
```tsx | ||
import React, { createRef, forwardRef, useImperativeHandle } from 'react'; | ||
import { Button, Modal, Space } from '@arco-design/web-react'; | ||
import { OpenableProps, openify } from 'openify'; | ||
|
||
import '@arco-design/web-react/dist/css/arco.css'; | ||
|
||
type MyModalProps = OpenableProps<void> & { | ||
title: string; | ||
}; | ||
|
||
type MyModalRef = { | ||
close: () => void; | ||
}; | ||
|
||
const MyModal = openify( | ||
forwardRef<MyModalRef, MyModalProps>( | ||
({ visible, onClose, afterClose, title }: MyModalProps, ref) => { | ||
useImperativeHandle( | ||
ref, | ||
() => ({ | ||
close() { | ||
onClose(); | ||
}, | ||
}), | ||
[], | ||
); | ||
return ( | ||
<Modal | ||
title={title} | ||
visible={visible} | ||
afterClose={afterClose} | ||
closable={false} | ||
> | ||
静态打开 | ||
</Modal> | ||
); | ||
}, | ||
), | ||
); | ||
|
||
export default () => ( | ||
<Space> | ||
<Button | ||
onClick={() => { | ||
const ref = createRef<MyModalRef>(); | ||
MyModal.open({ title: '标题', ref }); | ||
setTimeout(() => { | ||
ref.current?.close(); | ||
}, 1000); | ||
}} | ||
> | ||
打开弹窗 | ||
</Button> | ||
</Space> | ||
); | ||
``` |
Oops, something went wrong.