@mijadesign/nut-mcp 1.0.0-alpha.0
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 +147 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16 -0
- package/dist/services/aliases.service.d.ts +1 -0
- package/dist/services/aliases.service.js +19 -0
- package/dist/services/doc-parser.service.d.ts +3 -0
- package/dist/services/doc-parser.service.js +162 -0
- package/dist/services/index.services.d.ts +3 -0
- package/dist/services/index.services.js +71 -0
- package/dist/services/paths.service.d.ts +5 -0
- package/dist/services/paths.service.js +18 -0
- package/dist/tools/base.tool.d.ts +8 -0
- package/dist/tools/base.tool.js +27 -0
- package/dist/tools/get-component-doc.tool.d.ts +12 -0
- package/dist/tools/get-component-doc.tool.js +40 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/list-components.tool.d.ts +8 -0
- package/dist/tools/list-components.tool.js +32 -0
- package/dist/tools/search-components.tool.d.ts +12 -0
- package/dist/tools/search-components.tool.js +61 -0
- package/dist/types/index.d.ts +33 -0
- package/dist/types/index.js +1 -0
- package/docs/docs/aliases.json +59 -0
- package/docs/docs/components/base/button/index.md +415 -0
- package/docs/docs/components/base/cell/index.md +279 -0
- package/docs/docs/components/base/configprovider/index.md +215 -0
- package/docs/docs/components/base/image/index.md +282 -0
- package/docs/docs/components/base/overlay/index.md +288 -0
- package/docs/docs/components/dentry/cascader/index.md +1080 -0
- package/docs/docs/components/dentry/checkbox/index.md +842 -0
- package/docs/docs/components/dentry/datepicker/index.md +489 -0
- package/docs/docs/components/dentry/form/index.md +457 -0
- package/docs/docs/components/dentry/input/index.md +257 -0
- package/docs/docs/components/dentry/picker/index.md +621 -0
- package/docs/docs/components/dentry/radio/index.md +364 -0
- package/docs/docs/components/dentry/searchbar/index.md +317 -0
- package/docs/docs/components/dentry/selector/index.md +295 -0
- package/docs/docs/components/dentry/switch/index.md +300 -0
- package/docs/docs/components/dentry/textarea/index.md +231 -0
- package/docs/docs/components/dentry/uploader/index.md +745 -0
- package/docs/docs/components/exhibition/collapse/index.md +339 -0
- package/docs/docs/components/exhibition/swiper/index.md +385 -0
- package/docs/docs/components/exhibition/tag/index.md +253 -0
- package/docs/docs/components/feedback/dialog/index.md +306 -0
- package/docs/docs/components/feedback/drag/index.md +164 -0
- package/docs/docs/components/feedback/empty/index.md +211 -0
- package/docs/docs/components/feedback/infiniteloading/index.md +397 -0
- package/docs/docs/components/feedback/noticebar/index.md +175 -0
- package/docs/docs/components/feedback/popup/index.md +563 -0
- package/docs/docs/components/feedback/pulltorefresh/index.md +254 -0
- package/docs/docs/components/feedback/toast/index.md +355 -0
- package/docs/docs/components/layout/divider/index.md +162 -0
- package/docs/docs/components/layout/grid/index.md +386 -0
- package/docs/docs/components/layout/space/index.md +196 -0
- package/docs/docs/components/nav/tabs/index.md +955 -0
- package/docs/docs/components-index.json +233 -0
- package/package.json +34 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
---
|
|
2
|
+
order: 12
|
|
3
|
+
demoUrl: 'https://frontend.mishudata.com/mobile/demo/#/feedback/pages/pulltorefresh/index'
|
|
4
|
+
group:
|
|
5
|
+
title: 操作反馈
|
|
6
|
+
order: 6
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# PullToRefresh 下拉刷新 <Badge>2.0.0</Badge>
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
在列表中通过手指下拉刷新加载新内容的交互操作。
|
|
13
|
+
|
|
14
|
+
## 引入
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { PullToRefresh } from '@mijadesign/mjui-react-taro'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 示例代码
|
|
21
|
+
|
|
22
|
+
### 基础用法
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { PullToRefresh, Toast } from '@mijadesign/mjui-react-taro'
|
|
27
|
+
import React, { useState } from 'react'
|
|
28
|
+
|
|
29
|
+
const Demo1 = () => {
|
|
30
|
+
const [list] = useState([1, 2, 3, 4, 5, 6, 7])
|
|
31
|
+
const [show, SetShow] = useState(false)
|
|
32
|
+
const [toastMsg, SetToastMsg] = useState('')
|
|
33
|
+
const toastShow = (msg: any) => {
|
|
34
|
+
SetToastMsg(msg)
|
|
35
|
+
SetShow(true)
|
|
36
|
+
}
|
|
37
|
+
return (
|
|
38
|
+
<>
|
|
39
|
+
<PullToRefresh
|
|
40
|
+
style={{
|
|
41
|
+
backgroundColor: `var(--nutui-gray-3)`,
|
|
42
|
+
color: 'var(--nutui-gray-7)',
|
|
43
|
+
}}
|
|
44
|
+
onRefresh={() =>
|
|
45
|
+
new Promise((resolve) => {
|
|
46
|
+
toastShow('😊')
|
|
47
|
+
resolve('done')
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
renderIcon={(status) => {
|
|
51
|
+
return (
|
|
52
|
+
<>
|
|
53
|
+
{(status === 'canRelease' || status === 'refreshing') && (
|
|
54
|
+
<img
|
|
55
|
+
alt=""
|
|
56
|
+
style={{ height: '26px', width: '36px' }}
|
|
57
|
+
src="https://img10.360buyimg.com/imagetools/jfs/t1/230454/20/14523/223/65fab2d1F379c3968/ac35992443abab0c.png"
|
|
58
|
+
/>
|
|
59
|
+
)}
|
|
60
|
+
</>
|
|
61
|
+
)
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
{list.map((item) => (
|
|
65
|
+
<div
|
|
66
|
+
style={{
|
|
67
|
+
textAlign: 'center',
|
|
68
|
+
height: '50px',
|
|
69
|
+
lineHeight: '50px',
|
|
70
|
+
}}
|
|
71
|
+
key={item}
|
|
72
|
+
>
|
|
73
|
+
{item}
|
|
74
|
+
</div>
|
|
75
|
+
))}
|
|
76
|
+
</PullToRefresh>
|
|
77
|
+
<Toast
|
|
78
|
+
type="text"
|
|
79
|
+
visible={show}
|
|
80
|
+
content={toastMsg}
|
|
81
|
+
onClose={() => {
|
|
82
|
+
SetShow(false)
|
|
83
|
+
}}
|
|
84
|
+
/>
|
|
85
|
+
</>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default Demo1
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
> 在 PullToRefresh 组件内部采用 Selector API 获得父滚动元素的 scrollTop 值会带来下拉卡顿的性能问题。因此需要在 PullRefresh 组件外部判断 scrollTop 值,在页面中使用 usePageScroll() 钩子获得 scrollTop 值,在 ScrollView 组件内监听 onScroll 事件获得 scrollTop 值。
|
|
94
|
+
|
|
95
|
+
### ScrollView
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
import { Cell, PullToRefresh, Toast } from '@mijadesign/mjui-react-taro'
|
|
100
|
+
import { ScrollView } from '@tarojs/components'
|
|
101
|
+
import React, { useState } from 'react'
|
|
102
|
+
|
|
103
|
+
const Demo2 = () => {
|
|
104
|
+
const [list] = useState([1, 2, 3, 4, 5, 6, 7])
|
|
105
|
+
const [show, SetShow] = useState(false)
|
|
106
|
+
const [toastMsg, SetToastMsg] = useState('')
|
|
107
|
+
const toastShow = (msg: any) => {
|
|
108
|
+
SetToastMsg(msg)
|
|
109
|
+
SetShow(true)
|
|
110
|
+
}
|
|
111
|
+
const [scrollTop, setScrollTop] = useState(0)
|
|
112
|
+
return (
|
|
113
|
+
<>
|
|
114
|
+
<ScrollView
|
|
115
|
+
style={{ height: '150px' }}
|
|
116
|
+
scrollY
|
|
117
|
+
onScrollEnd={(e) => {
|
|
118
|
+
// scrollTop > 0, PullToRefresh 不触发 touchmove 事件。
|
|
119
|
+
if (e.detail?.scrollTop) {
|
|
120
|
+
setScrollTop(e.detail?.scrollTop)
|
|
121
|
+
}
|
|
122
|
+
}}
|
|
123
|
+
>
|
|
124
|
+
<PullToRefresh
|
|
125
|
+
style={{ padding: '0 16px' }}
|
|
126
|
+
scrollTop={scrollTop}
|
|
127
|
+
onRefresh={() =>
|
|
128
|
+
new Promise((resolve) => {
|
|
129
|
+
toastShow('😊')
|
|
130
|
+
resolve('done')
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
>
|
|
134
|
+
{list.map((item) => (
|
|
135
|
+
<Cell key={item}>{item}</Cell>
|
|
136
|
+
))}
|
|
137
|
+
</PullToRefresh>
|
|
138
|
+
</ScrollView>
|
|
139
|
+
<Toast
|
|
140
|
+
type="text"
|
|
141
|
+
visible={show}
|
|
142
|
+
content={toastMsg}
|
|
143
|
+
onClose={() => {
|
|
144
|
+
SetShow(false)
|
|
145
|
+
}}
|
|
146
|
+
/>
|
|
147
|
+
</>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export default Demo2
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
### 深色背景-反白模式:type='primary'
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
```tsx
|
|
160
|
+
import { PullToRefresh, Toast } from '@mijadesign/mjui-react-taro'
|
|
161
|
+
import React, { useState } from 'react'
|
|
162
|
+
|
|
163
|
+
const Demo1 = () => {
|
|
164
|
+
const [list] = useState([1, 2, 3, 4, 5, 6, 7])
|
|
165
|
+
const [show, SetShow] = useState(false)
|
|
166
|
+
const [toastMsg, SetToastMsg] = useState('')
|
|
167
|
+
const toastShow = (msg: any) => {
|
|
168
|
+
SetToastMsg(msg)
|
|
169
|
+
SetShow(true)
|
|
170
|
+
}
|
|
171
|
+
return (
|
|
172
|
+
<>
|
|
173
|
+
<PullToRefresh
|
|
174
|
+
type="primary"
|
|
175
|
+
onRefresh={() =>
|
|
176
|
+
new Promise((resolve) => {
|
|
177
|
+
toastShow('😊')
|
|
178
|
+
resolve('done')
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
renderIcon={(status) => {
|
|
182
|
+
return (
|
|
183
|
+
<>
|
|
184
|
+
{(status === 'canRelease' || status === 'refreshing') && (
|
|
185
|
+
<img
|
|
186
|
+
alt=""
|
|
187
|
+
style={{ height: '26px', width: '36px' }}
|
|
188
|
+
src="https://img14.360buyimg.com/imagetools/jfs/t1/186707/25/42738/223/65fab272F0965554b/eae33de2f17909b8.png"
|
|
189
|
+
/>
|
|
190
|
+
)}
|
|
191
|
+
</>
|
|
192
|
+
)
|
|
193
|
+
}}
|
|
194
|
+
>
|
|
195
|
+
{list.map((item) => (
|
|
196
|
+
<div
|
|
197
|
+
style={{
|
|
198
|
+
textAlign: 'center',
|
|
199
|
+
height: '50px',
|
|
200
|
+
lineHeight: '50px',
|
|
201
|
+
}}
|
|
202
|
+
key={item}
|
|
203
|
+
>
|
|
204
|
+
{item}
|
|
205
|
+
</div>
|
|
206
|
+
))}
|
|
207
|
+
</PullToRefresh>
|
|
208
|
+
<Toast
|
|
209
|
+
type="text"
|
|
210
|
+
visible={show}
|
|
211
|
+
content={toastMsg}
|
|
212
|
+
onClose={() => {
|
|
213
|
+
SetShow(false)
|
|
214
|
+
}}
|
|
215
|
+
/>
|
|
216
|
+
</>
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export default Demo1
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## PullToRefresh
|
|
225
|
+
|
|
226
|
+
### Props
|
|
227
|
+
|
|
228
|
+
| 属性 | 说明 | 类型 | 默认值 |
|
|
229
|
+
| --- | --- | --- | --- |
|
|
230
|
+
| canReleaseText | 释放的提示文案 | `ReactNode` | `松手刷新` |
|
|
231
|
+
| completeText | 完成时的提示文案 | `ReactNode` | `刷新成功` |
|
|
232
|
+
| completeDelay | 完成后延迟消失的时间,单位为 ms | `number` | `500` |
|
|
233
|
+
| disabled | 是否禁用下拉刷新 | `boolean` | `false` |
|
|
234
|
+
| catchMove | 是否禁止滚动 | `boolean` | `false` |
|
|
235
|
+
| headHeight | 头部提示内容区的高度,单位为 px | `number` | `40` |
|
|
236
|
+
| scrollTop | 可滚动的父元素的 scrollTop | `number` | `0` |
|
|
237
|
+
| pullingText | 下拉的提示文案 | `ReactNode` | `下拉刷新` |
|
|
238
|
+
| refreshingText | 刷新时的提示文案 | `ReactNode` | `刷新中` |
|
|
239
|
+
| renderIcon | 根据下拉状态,自定义下拉提示图标 | `ReactNode` | `<Loading />` |
|
|
240
|
+
| renderText | 根据下拉状态,自定义下拉提示文案 | `ReactNode` | `-` |
|
|
241
|
+
| threshold | 触发刷新需要下拉多少距离,单位为 px | `number` | `60` |
|
|
242
|
+
| onRefresh | 触发刷新时的处理函数 | `() => Promise<any>` | `-` |
|
|
243
|
+
|
|
244
|
+
## 主题定制
|
|
245
|
+
|
|
246
|
+
### 样式变量
|
|
247
|
+
|
|
248
|
+
组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 [ConfigProvider 组件](#/zh-CN/component/configprovider)。
|
|
249
|
+
|
|
250
|
+
| 名称 | 说明 | 默认值 |
|
|
251
|
+
| --- | --- | --- |
|
|
252
|
+
| \--nutui-pulltorefresh-icon-width | 下拉时icon宽度 | `36px` |
|
|
253
|
+
| \--nutui-pulltorefresh-icon-height | 下拉时icon高度 | `26px` |
|
|
254
|
+
| \--nutui-pulltorefresh-color-primary | 深色背景模式 | `$color-primay` |
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
---
|
|
2
|
+
order: 15
|
|
3
|
+
demoUrl: 'https://frontend.mishudata.com/mobile/demo/#/feedback/pages/toast/index'
|
|
4
|
+
group:
|
|
5
|
+
title: 操作反馈
|
|
6
|
+
order: 6
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Toast 吐司 <Badge>2.0.0</Badge>
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
用于轻提示。
|
|
13
|
+
|
|
14
|
+
> 当前组件 Taro 环境暂不支持函数式调用,推荐使用 Taro.API 使用原生组件 https://taro-docs.jd.com/taro/docs/apis/ui/interaction/showToast
|
|
15
|
+
|
|
16
|
+
## 引入
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { Toast } from '@mijadesign/mjui-react-taro';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 基础用法
|
|
23
|
+
|
|
24
|
+
### 文字提示
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import React, { useState } from 'react'
|
|
29
|
+
import { Cell, Toast } from '@mijadesign/mjui-react-taro'
|
|
30
|
+
|
|
31
|
+
const Demo1 = () => {
|
|
32
|
+
const [state, setState] = useState({
|
|
33
|
+
content: 'toast',
|
|
34
|
+
duration: 0,
|
|
35
|
+
icon: 'text',
|
|
36
|
+
title: '',
|
|
37
|
+
})
|
|
38
|
+
const [showToast, setShowToast] = useState(false)
|
|
39
|
+
|
|
40
|
+
const openToast = (icon: string, content: string, duration?: number, title?: string) => {
|
|
41
|
+
const changeState = Object.assign(state, {
|
|
42
|
+
content,
|
|
43
|
+
duration,
|
|
44
|
+
icon,
|
|
45
|
+
title,
|
|
46
|
+
})
|
|
47
|
+
setState(changeState)
|
|
48
|
+
}
|
|
49
|
+
return (
|
|
50
|
+
<>
|
|
51
|
+
<Toast
|
|
52
|
+
content={state.content}
|
|
53
|
+
duration={state.duration}
|
|
54
|
+
icon={state.icon}
|
|
55
|
+
title={state.title}
|
|
56
|
+
visible={showToast}
|
|
57
|
+
onClose={() => {
|
|
58
|
+
setShowToast(false)
|
|
59
|
+
}}
|
|
60
|
+
/>
|
|
61
|
+
<Cell
|
|
62
|
+
title="Text文字提示"
|
|
63
|
+
onClick={() => {
|
|
64
|
+
openToast('text', '网络失败,请稍后再试~')
|
|
65
|
+
setShowToast(true)
|
|
66
|
+
}}
|
|
67
|
+
/>
|
|
68
|
+
<Cell
|
|
69
|
+
title="Toast 标题提示"
|
|
70
|
+
onClick={() => {
|
|
71
|
+
openToast('text', '网络失败,请稍后再试~', undefined, '标题提示')
|
|
72
|
+
setShowToast(true)
|
|
73
|
+
}}
|
|
74
|
+
/>
|
|
75
|
+
<Cell
|
|
76
|
+
title="Success 成功提示"
|
|
77
|
+
onClick={() => {
|
|
78
|
+
openToast('success', '成功提示')
|
|
79
|
+
setShowToast(true)
|
|
80
|
+
}}
|
|
81
|
+
/>
|
|
82
|
+
<Cell
|
|
83
|
+
title="Error 失败提示"
|
|
84
|
+
onClick={() => {
|
|
85
|
+
openToast('fail', '失败提示')
|
|
86
|
+
setShowToast(true)
|
|
87
|
+
}}
|
|
88
|
+
/>
|
|
89
|
+
<Cell
|
|
90
|
+
title=" Warning 警告提示"
|
|
91
|
+
onClick={() => {
|
|
92
|
+
openToast('warn', '警告提示')
|
|
93
|
+
setShowToast(true)
|
|
94
|
+
}}
|
|
95
|
+
/>
|
|
96
|
+
<Cell
|
|
97
|
+
title=" Loading 加载提示"
|
|
98
|
+
onClick={() => {
|
|
99
|
+
openToast('loading', '加载中')
|
|
100
|
+
setShowToast(true)
|
|
101
|
+
}}
|
|
102
|
+
/>
|
|
103
|
+
</>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
export default Demo1
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 函数调用
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
import React from 'react'
|
|
115
|
+
import { Cell, Toast } from '@mijadesign/mjui-react-taro'
|
|
116
|
+
|
|
117
|
+
const Demo5 = () => {
|
|
118
|
+
return (
|
|
119
|
+
<>
|
|
120
|
+
<Cell
|
|
121
|
+
title="函数调用"
|
|
122
|
+
onClick={() => {
|
|
123
|
+
Toast.show('test', {
|
|
124
|
+
title: '函数调用',
|
|
125
|
+
content: '函数调用',
|
|
126
|
+
position: 'middle',
|
|
127
|
+
lockScroll: true,
|
|
128
|
+
onClose: () => {
|
|
129
|
+
console.log('close')
|
|
130
|
+
},
|
|
131
|
+
})
|
|
132
|
+
}}
|
|
133
|
+
/>
|
|
134
|
+
<Cell
|
|
135
|
+
title="函数调用"
|
|
136
|
+
onClick={() => {
|
|
137
|
+
Toast.show('test', {
|
|
138
|
+
content:
|
|
139
|
+
'函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用函数调用',
|
|
140
|
+
position: 'middle',
|
|
141
|
+
lockScroll: true,
|
|
142
|
+
onClose: () => {
|
|
143
|
+
console.log('close')
|
|
144
|
+
},
|
|
145
|
+
})
|
|
146
|
+
}}
|
|
147
|
+
/>
|
|
148
|
+
</>
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
export default Demo5
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 设置展示时长
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
```tsx
|
|
159
|
+
import React, { useState } from 'react'
|
|
160
|
+
import { Cell, Toast } from '@mijadesign/mjui-react-taro'
|
|
161
|
+
|
|
162
|
+
const Demo3 = () => {
|
|
163
|
+
const [state, setState] = useState({
|
|
164
|
+
content: 'toast',
|
|
165
|
+
duration: 2,
|
|
166
|
+
icon: 'text',
|
|
167
|
+
title: '',
|
|
168
|
+
})
|
|
169
|
+
const [showToast, setShowToast] = useState(false)
|
|
170
|
+
|
|
171
|
+
const openToast = (icon: string, content: string, duration?: number, title?: string) => {
|
|
172
|
+
const changeState = Object.assign(state, {
|
|
173
|
+
content,
|
|
174
|
+
duration,
|
|
175
|
+
icon,
|
|
176
|
+
title,
|
|
177
|
+
})
|
|
178
|
+
setState(changeState)
|
|
179
|
+
}
|
|
180
|
+
return (
|
|
181
|
+
<>
|
|
182
|
+
<Toast
|
|
183
|
+
content={state.content}
|
|
184
|
+
duration={state.duration}
|
|
185
|
+
icon={state.icon}
|
|
186
|
+
title={state.title}
|
|
187
|
+
visible={showToast}
|
|
188
|
+
onClose={() => {
|
|
189
|
+
setShowToast(false)
|
|
190
|
+
}}
|
|
191
|
+
/>
|
|
192
|
+
<Cell
|
|
193
|
+
title="展示时长为10秒"
|
|
194
|
+
onClick={() => {
|
|
195
|
+
openToast('text', '设置展示时长为10秒', 10)
|
|
196
|
+
setShowToast(true)
|
|
197
|
+
}}
|
|
198
|
+
/>
|
|
199
|
+
<Cell
|
|
200
|
+
title="隐藏Toast"
|
|
201
|
+
onClick={() => {
|
|
202
|
+
setShowToast(false)
|
|
203
|
+
}}
|
|
204
|
+
/>
|
|
205
|
+
</>
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
export default Demo3
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### 自定义 Icon
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
import React, { useState } from 'react'
|
|
217
|
+
import { Cell, Toast } from '@mijadesign/mjui-react-taro'
|
|
218
|
+
|
|
219
|
+
const Demo4 = () => {
|
|
220
|
+
const [state, setState] = useState({
|
|
221
|
+
content: 'toast',
|
|
222
|
+
duration: 2,
|
|
223
|
+
icon: 'text',
|
|
224
|
+
title: '',
|
|
225
|
+
})
|
|
226
|
+
const [showToast, setShowToast] = useState(false)
|
|
227
|
+
|
|
228
|
+
const openToast = (icon: string, content: string, duration?: number, title?: string) => {
|
|
229
|
+
const changeState = Object.assign(state, {
|
|
230
|
+
content,
|
|
231
|
+
duration,
|
|
232
|
+
icon,
|
|
233
|
+
title,
|
|
234
|
+
})
|
|
235
|
+
setState(changeState)
|
|
236
|
+
}
|
|
237
|
+
return (
|
|
238
|
+
<>
|
|
239
|
+
<Toast
|
|
240
|
+
content={state.content}
|
|
241
|
+
duration={state.duration}
|
|
242
|
+
icon={state.icon}
|
|
243
|
+
title={state.title}
|
|
244
|
+
visible={showToast}
|
|
245
|
+
onClose={() => {
|
|
246
|
+
setShowToast(false)
|
|
247
|
+
}}
|
|
248
|
+
/>
|
|
249
|
+
<Cell
|
|
250
|
+
title="自定义 Icon"
|
|
251
|
+
onClick={() => {
|
|
252
|
+
openToast('text', '设置icon为JD', 2, 'JD')
|
|
253
|
+
setShowToast(true)
|
|
254
|
+
}}
|
|
255
|
+
/>
|
|
256
|
+
</>
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
export default Demo4
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### 换行截断方式
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
```tsx
|
|
267
|
+
import React, { useState } from 'react'
|
|
268
|
+
import { Cell, Toast, ToastWordBreak } from '@mijadesign/mjui-react-taro'
|
|
269
|
+
|
|
270
|
+
const Demo5 = () => {
|
|
271
|
+
const [state, setState] = useState<{
|
|
272
|
+
content: string
|
|
273
|
+
wordBreak: ToastWordBreak
|
|
274
|
+
}>({
|
|
275
|
+
content: `Let's try hello world hhhhhhhhhh ABCDEFGHIJKLMN here.`,
|
|
276
|
+
wordBreak: 'break-all',
|
|
277
|
+
})
|
|
278
|
+
const [show, setShow] = useState(false)
|
|
279
|
+
return (
|
|
280
|
+
<>
|
|
281
|
+
<Toast
|
|
282
|
+
content={state.content}
|
|
283
|
+
visible={show}
|
|
284
|
+
icon="text"
|
|
285
|
+
onClose={() => {
|
|
286
|
+
setShow(false)
|
|
287
|
+
}}
|
|
288
|
+
wordBreak={state.wordBreak}
|
|
289
|
+
/>
|
|
290
|
+
<Cell.Group>
|
|
291
|
+
<Cell title="换行时截断单词" onClick={() => setShow(true)} />
|
|
292
|
+
<Cell
|
|
293
|
+
title="换行时不截断单词"
|
|
294
|
+
onClick={() => {
|
|
295
|
+
setState({
|
|
296
|
+
content: `Let's try hello world hhhhhhhhhh ABCDEFGHIJKLMN here.`,
|
|
297
|
+
wordBreak: 'break-word',
|
|
298
|
+
})
|
|
299
|
+
setShow(true)
|
|
300
|
+
}}
|
|
301
|
+
/>
|
|
302
|
+
</Cell.Group>
|
|
303
|
+
</>
|
|
304
|
+
)
|
|
305
|
+
}
|
|
306
|
+
export default Demo5
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## Toast
|
|
311
|
+
|
|
312
|
+
### Props
|
|
313
|
+
|
|
314
|
+
| 属性 | 说明 | 类型 | 默认值 |
|
|
315
|
+
| --- | --- | --- | --- |
|
|
316
|
+
| content | 消息文本内容 | `string` \| `React.ReactNode` | `-` |
|
|
317
|
+
| duration | 展示时长(秒),值为 0 时,toast 不会自动消失(loading类型默认为0) | `number` | `2.5` |
|
|
318
|
+
| title | 标题 | `string` | `-` |
|
|
319
|
+
| position | toast展示位置 | `top` \| `center` \| `bottom` | `center` |
|
|
320
|
+
| contentClassName | 自定义内容区类名 | `string` | `-` |
|
|
321
|
+
| contentStyle | 自定义内容区样式 | `React.CSSProperties` | `-` |
|
|
322
|
+
| icon | 自定义图标,对应icon组件,支持图片链接 | `string` | `-` |
|
|
323
|
+
| size | 文案尺寸,三选一 | `small` \| `base` \| `large` | `base` |
|
|
324
|
+
| closeOnOverlayClick | 是否在点击遮罩层后关闭提示 | `boolean` | `false` |
|
|
325
|
+
| lockScroll | 背景是否锁定 | `boolean` | `false` |
|
|
326
|
+
| type | 弹框类型 可选值(text、success、fail、warn、loading) | `string` | `text` |
|
|
327
|
+
| visible | 弹窗是否显示开关 | `boolean` | `false` |
|
|
328
|
+
| wordBreak | 换行截断方式 | `normal \| break-all \| break-word ` | `break-word` |
|
|
329
|
+
| onClose | 关闭时触发的事件 | `Function` | `null` |
|
|
330
|
+
|
|
331
|
+
### Methods
|
|
332
|
+
| 方法名 | 说明 | 类型 |
|
|
333
|
+
| --- | --- | --- |
|
|
334
|
+
| Toast.show | 打开 Toast | (id: string, options: ToastOptions) => void |
|
|
335
|
+
| Toast.hide | 关闭 Toast | (id: string) => void |
|
|
336
|
+
|
|
337
|
+
ToastOptions 是 ToastProps 的子集,包含如下属性:msg, title, type, duration
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
## 主题定制
|
|
341
|
+
|
|
342
|
+
### 样式变量
|
|
343
|
+
|
|
344
|
+
组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 [ConfigProvider 组件](#/zh-CN/component/configprovider)。
|
|
345
|
+
|
|
346
|
+
| 名称 | 说明 | 默认值 |
|
|
347
|
+
| --- | --- | --- |
|
|
348
|
+
| \--nutui-toast-font-color | `toast`文字颜色 | `$color-white` |
|
|
349
|
+
| \--nutui-toast-inner-bg-color | `toast`内容区背景色 | `$color-mask` |
|
|
350
|
+
| \--nutui-toast-inner-border-radius | `toast`内容区圆角值 | `$radius-2` |
|
|
351
|
+
| \--nutui-toast-inner-padding | `toast`内容区padding值 | `16px 24px` |
|
|
352
|
+
| \--nutui-toast-inner-text-align | `toast`内容区文本对齐方式 | `center` |
|
|
353
|
+
| \--nutui-toast-inner-top | `toast`内容区自定义高度 | `50%` |
|
|
354
|
+
| \--nutui-toast-text-font-size | `toast`内容文字大小 | `$font-size-3` |
|
|
355
|
+
| \--nutui-toast-title-font-size | `toast`标题文字大小 | `$font-size-3` |
|