Skip to content

Commit 320b6c7

Browse files
authored
Merge pull request #114 from sylingd/master
web loading, toast hide, other small fixes
2 parents f404d04 + b2d749f commit 320b6c7

File tree

20 files changed

+252
-33
lines changed

20 files changed

+252
-33
lines changed

packages/clipboard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"devDependencies": {
3333
"@types/jest": "^24.0.12",
34-
"@types/rax": "^1.0.6",
34+
"@types/rax": "^1.0.1",
3535
"typescript": "^3.7.5",
3636
"@alib/build-scripts": "^0.1.0",
3737
"build-plugin-rax-component": "^0.2.2",

packages/element/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "universal-element",
33
"author": "rax",
4-
"version": "0.0.4",
4+
"version": "0.0.5",
55
"description": "",
66
"main": "lib/index.js",
77
"files": [
@@ -22,9 +22,11 @@
2222
"engines": {
2323
"npm": ">=3.0.0"
2424
},
25+
"dependencies": {
26+
"universal-env": "^3.0.0"
27+
},
2528
"devDependencies": {
2629
"@alib/build-scripts": "^0.1.0",
27-
"build-plugin-rax-component": "^0.1.0",
28-
"universal-env": "^3.0.0"
30+
"build-plugin-rax-component": "^0.1.0"
2931
}
3032
}

packages/loading/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
加载提示的过渡效果。
44

55
## 支持
6-
<img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px">
6+
<img alt="browser" src="https://gw.alicdn.com/tfs/TB1uYFobGSs3KVjSZPiXXcsiVXa-200-200.svg" width="25px" height="25px" /> <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px">
77

88
## 安装
99

@@ -20,7 +20,7 @@ $ npm install universal-loading --save
2020
#### 参数
2121
| 属性 | 类型 | 默认值 | 必选 | 描述 | 支持 |
2222
| -------- | -------- | ------ | ---- | -------- | --------------------------------------- |
23-
| content | `String` | || 提示中的文字内容 | <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"> |
23+
| content | `String` | || 提示中的文字内容 | <img alt="browser" src="https://gw.alicdn.com/tfs/TB1uYFobGSs3KVjSZPiXXcsiVXa-200-200.svg" width="25px" height="25px" /> <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"> |
2424
| delay | `Number` | `0` | x | 延迟显示,单位 ms | <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> |
2525
| mask | `Boolean` | `false` | x | 是否显示透明蒙层,防止触摸穿透 | <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"> |
2626

packages/loading/demo/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
// @ts-ignore
3+
import { createElement, render } from 'rax';
4+
import DriverUniversal from 'driver-universal';
5+
import View from 'rax-view';
6+
import Text from 'rax-text';
7+
import Loading from '../src/';
8+
9+
const App = () => {
10+
const handleClick = () => {
11+
Loading.show({
12+
content: 'Loading, please wait'
13+
});
14+
setTimeout(() => Loading.hide(), 3000);
15+
};
16+
return (
17+
<View onClick={handleClick}>
18+
<Text>Start loading</Text>
19+
</View>
20+
);
21+
};
22+
23+
render(<App />, document.body, { driver: DriverUniversal });

packages/loading/docs-template/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
加载提示的过渡效果。
44

55
## 支持
6-
__icon_miniapp_mp__ __icon_miniapp_wx__
6+
__icon_web__ __icon_miniapp_mp__ __icon_miniapp_wx__
77

88
## 安装
99

@@ -20,7 +20,7 @@ $ npm install universal-loading --save
2020
#### 参数
2121
| 属性 | 类型 | 默认值 | 必选 | 描述 | 支持 |
2222
| -------- | -------- | ------ | ---- | -------- | --------------------------------------- |
23-
| content | `String` | || 提示中的文字内容 | __icon_miniapp_mp__ __icon_miniapp_wx__ |
23+
| content | `String` | || 提示中的文字内容 | __icon_web__ __icon_miniapp_mp__ __icon_miniapp_wx__ |
2424
| delay | `Number` | `0` | x | 延迟显示,单位 ms | __icon_miniapp_mp__ |
2525
| mask | `Boolean` | `false` | x | 是否显示透明蒙层,防止触摸穿透 | __icon_miniapp_wx__ |
2626

packages/loading/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "universal-loading",
33
"author": "rax",
4-
"version": "1.0.1",
4+
"version": "1.1.0",
55
"description": "",
66
"main": "lib/index.js",
77
"files": [
@@ -33,8 +33,11 @@
3333
"@alib/build-scripts": "^0.1.0",
3434
"@types/rax": "^1.0.1",
3535
"build-plugin-rax-component": "^0.2.0",
36+
"driver-universal": "^3.1.0",
3637
"rax": "^1.1.0",
3738
"rax-test-renderer": "^1.0.0",
39+
"rax-text": "^1.3.1",
40+
"rax-view": "^1.1.2",
3841
"typescript": "^3.7.5"
3942
}
4043
}

packages/loading/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { isMiniApp, isWeChatMiniProgram } from 'universal-env';
1+
import { isMiniApp, isWeChatMiniProgram, isWeb } from 'universal-env';
22
import * as miniAppModule from './miniapp/ali';
33
import * as weChatModule from './miniapp/wechat';
4+
import * as webModule from './web';
45

56
import { Loading } from './types';
67

@@ -11,5 +12,8 @@ if (isMiniApp) {
1112
if (isWeChatMiniProgram) {
1213
Loading = weChatModule;
1314
}
15+
if (isWeb) {
16+
Loading = webModule;
17+
}
1418

1519
export default Loading;

packages/loading/src/web/index.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
let loadingWin: HTMLElement | null = null;
2+
3+
const clsPrefix = "__universal_loading";
4+
5+
const styles = `.${clsPrefix} {
6+
background-color: rgba(0, 0, 0, 0.6);
7+
box-sizing: border-box;
8+
max-width: 80%;
9+
color: #ffffff;
10+
padding: 15px;
11+
position: fixed;
12+
left: 50%;
13+
bottom: 50%;
14+
border-radius: 4px;
15+
text-align: center;
16+
transform: translateX(-50%);
17+
-webkit-transform: translateX(-50%);
18+
z-index: 9999;
19+
outline: none;
20+
}
21+
.${clsPrefix}_circle {
22+
border: 2px solid rgba(200, 200, 200, 0.5);
23+
border-radius: 50%;
24+
position: relative;
25+
height: 40px;
26+
width: 40px;
27+
margin: auto;
28+
}
29+
.${clsPrefix}_circle:after {
30+
content: "";
31+
display: block;
32+
border-radius: 50%;
33+
width: 100%;
34+
height: 100%;
35+
position: absolute;
36+
top: -2px;
37+
left: -2px;
38+
border: 2px solid;
39+
border-color: transparent;
40+
border-left-color: #fff;
41+
box-sizing: content-box;
42+
animation: ${clsPrefix}_roller 1s infinite linear;
43+
}
44+
.${clsPrefix}_text {
45+
margin-top: 6px;
46+
color: #fff;
47+
line-height: 1.5;
48+
font-size: 14px;
49+
text-align: center;
50+
font-weight: normal;
51+
}
52+
@keyframes ${clsPrefix}_roller {
53+
0% {
54+
transform: rotateZ(0);
55+
}
56+
100% {
57+
transform: rotateZ(360deg);
58+
}
59+
}`.replace(/\n/g, "");
60+
61+
/*
62+
* @param message {String}
63+
*/
64+
let styleElement : HTMLElement | null = null;
65+
export function show({ content = "" }): Promise<any> {
66+
if (!styleElement) {
67+
// create a style tag for keyframes
68+
styleElement = document.createElement("style");
69+
styleElement.innerHTML = styles;
70+
document.body.appendChild(styleElement);
71+
}
72+
if (!loadingWin) {
73+
// create loading win
74+
loadingWin = document.createElement("div");
75+
loadingWin.className = clsPrefix;
76+
loadingWin.setAttribute("role", "alert");
77+
// support for ARIA, add tabindex for focus
78+
// https://developer.mozilla.org/zh-CN/docs/Web/HTML/Global_attributes/tabindex
79+
loadingWin.setAttribute("tabindex", "-1");
80+
// add a circle element
81+
const circle = document.createElement("div");
82+
circle.className = `${clsPrefix}_circle`;
83+
loadingWin.appendChild(circle);
84+
// add text element
85+
const text = document.createElement("div");
86+
text.className = `${clsPrefix}_text`;
87+
loadingWin.appendChild(text);
88+
89+
document.body.appendChild(loadingWin);
90+
}
91+
92+
const text = loadingWin.querySelector(`.${clsPrefix}_text`) as HTMLDivElement;
93+
if (content) {
94+
text.style.display = "block";
95+
text.innerText = content;
96+
} else {
97+
text.style.display = "none";
98+
text.innerText = "";
99+
}
100+
101+
return Promise.resolve();
102+
}
103+
104+
export function hide(): Promise<any> {
105+
return new Promise((resolve) => {
106+
setTimeout(() => {
107+
if (loadingWin && loadingWin.parentNode) {
108+
loadingWin.parentNode.removeChild(loadingWin);
109+
}
110+
loadingWin = null;
111+
resolve();
112+
}, 0);
113+
});
114+
}

packages/toast/README-en-US.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ Toast.show('Hi');
3232
| message | `string` | content of the message | - |
3333
| duration | `number` | Time in millisecond before Toast is closed. | 2000 |
3434
| options | `object` | Other options used by WeChat MiniProgram/ByteDance MicroApp, see [docs](https://developers.weixin.qq.com/miniprogram/dev/api/ui/interaction/wx.showToast.html) | {} |
35+
36+
### `Toast.hide()`
37+
38+
#### Support
39+
<img alt="browser" src="https://gw.alicdn.com/tfs/TB1uYFobGSs3KVjSZPiXXcsiVXa-200-200.svg" width="25px" height="25px" /> <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"> <img alt="bytedanceMicroApp" src="https://gw.alicdn.com/tfs/TB1jFtVzO_1gK0jSZFqXXcpaXXa-200-200.svg" width="25px" height="25px">
40+
41+
Hide toast

packages/toast/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ Toast.show('Hi');
3333
| message | `string` | 文字内容 | - |
3434
| duration | `number` | 显示时长,单位为 ms | 2000 |
3535
| options | `object` | 其他参数,微信小程序/字节跳动小程序平台可用配置,参考[文档](https://developers.weixin.qq.com/miniprogram/dev/api/ui/interaction/wx.showToast.html) | {} |
36+
37+
### `Toast.hide()`
38+
39+
#### 支持
40+
<img alt="browser" src="https://gw.alicdn.com/tfs/TB1uYFobGSs3KVjSZPiXXcsiVXa-200-200.svg" width="25px" height="25px" /> <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"> <img alt="bytedanceMicroApp" src="https://gw.alicdn.com/tfs/TB1jFtVzO_1gK0jSZFqXXcpaXXa-200-200.svg" width="25px" height="25px">
41+
42+
隐藏Toast

0 commit comments

Comments
 (0)