@overlastic/react 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -174
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,183 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://overlastic.vercel.app/" target="blank">
|
|
3
|
+
<img src="https://github.com/hairyf/overlastic/raw/master/docs/public/circle.svg" width="120" alt="Nest Logo" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
<p align="center">
|
|
8
|
+
A create modal | dialog | popup promise deferred library
|
|
9
|
+
</p>
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/@overlastic/react"><img src="https://img.shields.io/npm/v/@overlastic/react.svg" alt="NPM Version" /></a>
|
|
13
|
+
<a href="https://www.npmjs.com/@overlastic/react"><img src="https://img.shields.io/npm/l/@overlastic/react.svg" alt="Package License" /></a>
|
|
14
|
+
<a href="https://www.npmjs.com/@overlastic/react"><img src="https://img.shields.io/npm/dm/@overlastic/react.svg" alt="NPM Downloads" /></a>
|
|
15
|
+
</p>
|
|
6
16
|
|
|
7
|
-
|
|
8
|
-
```sh
|
|
9
|
-
pnpm add @overlastic/react
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
With yarn:
|
|
13
|
-
```sh
|
|
14
|
-
yarn add @overlastic/react
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Usage
|
|
18
|
-
|
|
19
|
-
### Step 1: Define Component
|
|
20
|
-
|
|
21
|
-
```tsx
|
|
22
|
-
// overlay.tsx
|
|
23
|
-
export function Component(props) {
|
|
24
|
-
const { visible, resolve, reject } = useOverlayDefine({
|
|
25
|
-
// Duration of overlay duration, helps prevent premature component destruction
|
|
26
|
-
duration: 200,
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<div className={visible && 'is--visible'}>
|
|
31
|
-
<span onClick={() => resolve(`${props.title}:confirmed`)}> Confirm </span>
|
|
32
|
-
</div>
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### Step 2: Create Overlay
|
|
38
|
-
|
|
39
|
-
You can convert the component into a modal dialog box by using the `defineOverlay` method, which allows you to call it in Javascript / Typescript.
|
|
40
|
-
```ts
|
|
41
|
-
import { defineOverlay } from '@overlastic/react'
|
|
42
|
-
import { Component } from './overlay'
|
|
43
|
-
|
|
44
|
-
// Convert to imperative callback
|
|
45
|
-
const callback = defineOverlay(Component)
|
|
46
|
-
// Call the component and get the resolve callback value
|
|
47
|
-
const value = await callback({ title: 'callbackOverlay' })
|
|
48
|
-
// value === "callbackOverlay:confirmed"
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
You can also directly call the component through `renderOverlay`, bypassing the `defineOverlay` method.
|
|
52
|
-
|
|
53
|
-
```ts
|
|
54
|
-
import { renderOverlay } from '@overlastic/react'
|
|
55
|
-
import { Component } from './overlay'
|
|
56
|
-
|
|
57
|
-
const value = await renderOverlay(Component, {
|
|
58
|
-
title: 'useOverlayDefine'
|
|
59
|
-
})
|
|
60
|
-
// value === "useOverlayDefine:confirmed"
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Injection Holder
|
|
64
|
-
|
|
65
|
-
In addition to using `defineOverlay` and `renderOverlay` to create popup components, you can also use useOverlayHolder to create popup components within a component and inherit the current context of the application.
|
|
66
|
-
|
|
67
|
-
```tsx
|
|
68
|
-
import { useOverlayHolder } from '@overlastic/react'
|
|
69
|
-
import { OverlayComponent } from './overlay'
|
|
70
|
-
|
|
71
|
-
export function Main() {
|
|
72
|
-
// Use useOverlayHolder(Component) to create a component holder that supports the current context.
|
|
73
|
-
const [holder, overlayApi] = useOverlayHolder(OverlayComponent)
|
|
74
|
-
|
|
75
|
-
function open() {
|
|
76
|
-
// Open the popup component
|
|
77
|
-
overlayApi()
|
|
78
|
-
.then((result) => {})
|
|
79
|
-
}
|
|
80
|
-
return (
|
|
81
|
-
<>
|
|
82
|
-
<div onClick={open}> open </div>
|
|
83
|
-
{/* Mount the holder */}
|
|
84
|
-
{holder}
|
|
85
|
-
</>
|
|
86
|
-
)
|
|
87
|
-
}
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## Define Component
|
|
91
|
-
|
|
92
|
-
Components created using `@overlastic/react` support both imperative and declarative methods of calling. In addition to imperative methods, these components can also be used in JSX.
|
|
17
|
+
## Description
|
|
93
18
|
|
|
94
|
-
|
|
19
|
+
Create messages or dialog overlays using Overlastic in React APP.
|
|
95
20
|
|
|
96
|
-
|
|
97
|
-
// If using Typescript, use PropsWithOverlays to define props type
|
|
98
|
-
import type { PropsWithOverlays } from '@overlastic/react'
|
|
99
|
-
import { useOverlayDefine } from '@overlastic/react'
|
|
21
|
+
## Installation
|
|
100
22
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// pass props to useOverlayDefine for processing
|
|
104
|
-
props
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
return (
|
|
108
|
-
<div className={visible && 'is--visible'}>
|
|
109
|
-
...
|
|
110
|
-
</div>
|
|
111
|
-
)
|
|
112
|
-
}
|
|
23
|
+
```bash
|
|
24
|
+
$ npm install --save @overlastic/react
|
|
113
25
|
```
|
|
114
26
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
```tsx
|
|
118
|
-
import { useState } from 'react'
|
|
119
|
-
import { Component } from './overlay'
|
|
120
|
-
|
|
121
|
-
export function Main() {
|
|
122
|
-
const [visible, setVisible] = useState(false)
|
|
123
|
-
|
|
124
|
-
function openOverlay() {
|
|
125
|
-
setVisible(true)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function onResolve(value) {
|
|
129
|
-
setVisible(false)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function onReject(value) {
|
|
133
|
-
setVisible(false)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return (
|
|
137
|
-
<Component visible={visible} onResolve={onResolve} onReject={onReject} />
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
```
|
|
27
|
+
## Quick Start
|
|
141
28
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
```jsx
|
|
145
|
-
function Component(props: { onOn?: Function, onNook?: Function, open: boolean }) {
|
|
146
|
-
const { visible, resolve, reject } = useOverlayDefine({
|
|
147
|
-
events: { resolve: 'onOk', reject: 'onNook' },
|
|
148
|
-
model: 'open',
|
|
149
|
-
props,
|
|
150
|
-
})
|
|
151
|
-
// ...
|
|
152
|
-
}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
## Customized
|
|
156
|
-
|
|
157
|
-
You can use `@overlastic/react` to modify existing components or component libraries
|
|
158
|
-
|
|
159
|
-
Take [antd(drawer)](https://ant.design/components/drawer-cn) as an example:
|
|
160
|
-
|
|
161
|
-
```tsx
|
|
162
|
-
import type { PropsWithOverlays } from '@overlastic/react'
|
|
163
|
-
import { useOverlayDefine } from '@overlastic/react'
|
|
164
|
-
import { Button, Drawer } from 'antd'
|
|
165
|
-
|
|
166
|
-
function MyDrawer(props: PropsWithOverlays<{ title: string }>) {
|
|
167
|
-
const { visible, resolve, reject } = useOverlayDefine({
|
|
168
|
-
duration: 200,
|
|
169
|
-
props,
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
return (
|
|
173
|
-
<Drawer title={props.title} onClose={reject} open={visible}>
|
|
174
|
-
{/* Custom contents.... */}
|
|
175
|
-
<Button type="primary" onClick={() => resolve(`${props.title}:confirmed`)}>
|
|
176
|
-
Confirm
|
|
177
|
-
</Button>
|
|
178
|
-
</Drawer>
|
|
179
|
-
)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export default MyDrawer
|
|
183
|
-
```
|
|
29
|
+
[Overview & Tutorial](https://overlastic.vercel.app/en/react/)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@overlastic/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/hairyf/overlastic#readme",
|
|
7
7
|
"repository": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"pascal-case": "3.1.2",
|
|
33
33
|
"react": "^18.3.1",
|
|
34
34
|
"react-dom": "^18.3.1",
|
|
35
|
-
"@overlastic/core": "^0.5.
|
|
35
|
+
"@overlastic/core": "^0.5.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/react": "^18.3.2",
|