Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Skeleton): theme support five base type #617

Merged
merged 3 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
"t-dropdown-item": "tdesign-miniprogram/dropdown-menu/dropdown-item",
"t-drawer": "tdesign-miniprogram/drawer/drawer",
"t-pull-down-refresh": "tdesign-miniprogram/pull-down-refresh/pull-down-refresh",
"t-skeleton": "tdesign-miniprogram/skeleton/skeleton",
"t-footer": "tdesign-miniprogram/footer/footer",
"t-divider": "tdesign-miniprogram/divider/divider",
"t-empty": "tdesign-miniprogram/empty/empty",
Expand Down
47 changes: 23 additions & 24 deletions src/skeleton/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,28 @@ isComponent: true

## 代码演示

### 基础骨架屏
### 类型
#### 基础骨架屏

<img src="https://tdesign.gtimg.com/miniprogram/readme/skeleton-1.gif" width="375px" height="50%">
{{ theme }}

```html
<t-skeleton
rowCol="{{rowCol}}"
theme="avatar-text"
animation="flashed"
loading
></t-skeleton>
```
#### 宫格骨架屏

{{ grid }}

#### 单元格骨架屏

{{ cell-group }}

#### 图片组合骨架屏

{{ image-group }}

### 动画
#### 渐变加载效果

{{ animation }}

```js
data: {
rowCol: [
{ width: '566rpx', height: '32rpx' },
{ width: '100%', height: '32rpx' },
{ width: '100%', height: '32rpx' },
{ width: '314rpx', height: '32rpx' },
],
},
```

## API

Expand All @@ -48,7 +47,7 @@ data: {
| 名称 | 类型 | 默认值 | 说明 | 必传 |
| ---------------- | ------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---- |
| animation | String | - | 动画效果,有「渐变加载动画」和「闪烁加载动画」两种。值为空则表示没有动画。可选项:gradient/flashed | N |
| external-classes | Array | - | 组件类名,分别用于设置组件外层元素、头像、图片、文本等元素类名。`['t-class', 't-class-avatar', 't-class-image', 't-class-text']` | N |
| loading | Boolean | - | 是否为加载状态,如果是则显示骨架图,如果不是则显示加载完成的内容 | N |
| row-col | Array | [1, 1, 1, { width: '70%' }] | 用于设置行列数量、宽度高度、间距等。【示例一】,`[1, 1, 2]` 表示输出三行骨架图,第一行一列,第二行一列,第三行两列。【示例二】,`[1, 1, { width: '100px' }]` 表示自定义第三行的宽度为 `100px`。【示例三】,`[1, 2, [{ width, height }, { width, height, marginLeft }]]` 表示第三行有两列,且自定义宽度、高度和间距。TS 类型:`SkeletonRowCol`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/skeleton/type.ts) | N |
| theme | String | text | 骨架图风格,有基础、头像组合等两大类。可选项:text/avatar-text | N |
| external-classes | Array | - | 组件类名,分别用于设置组件外层、每一列等元素类名。`['t-class', 't-class-col']` | N |
| loading | Boolean | - | 是否为加载状态,如果是则显示骨架图,如果不是则显示加载完成的内容 | N |
| row-col | Array |- | 用于设置行列数量、宽度高度、间距等。【示例一】,`[1, 1, 2]` 表示输出三行骨架图,第一行一列,第二行一列,第三行两列。【示例二】,`[1, 1, { width: '100px' }]` 表示自定义第三行的宽度为 `100px`。【示例三】,`[1, 2, [{ width, height }, { width, height, marginLeft }]]` 表示第三行有两列,且自定义宽度、高度和间距。TS 类型:`SkeletonRowCol`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/skeleton/type.ts) | N |
| theme | String | text | 骨架图风格,有头像、图片、文本、段落等5大类。可选项:avatar/image/text/paragraph | N |
6 changes: 6 additions & 0 deletions src/skeleton/_example/animation/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Component({
data: {
rowColsAvater: [{ size: '48px', type: 'circle' }],
animation: 'flashed',
},
});
6 changes: 6 additions & 0 deletions src/skeleton/_example/animation/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"t-skeleton": "tdesign-miniprogram/skeleton/skeleton"
}
}
4 changes: 4 additions & 0 deletions src/skeleton/_example/animation/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<view class="group">
<t-skeleton class="group-avatar" rowCol="{{rowColsAvater}}" animation="{{animation}}" loading></t-skeleton>
<t-skeleton class="group-content" theme="paragraph" animation="{{animation}}" loading></t-skeleton>
</view>
12 changes: 12 additions & 0 deletions src/skeleton/_example/animation/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.group {
display: flex;
margin-bottom: 32rpx;
}

.group-avatar {
margin-right: 24rpx;
}

.group-content {
width: 566rpx;
}
17 changes: 17 additions & 0 deletions src/skeleton/_example/cell-group/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Component({
properties: {
theme: {
type: String,
value: 'text',
},
loading: {
type: Boolean,
},
},

data: {
rowColsAvater: [{ size: '48px', type: 'circle' }],
rowColsImage: [{ size: '48px', type: 'rect' }],
rowColsContent: [{ width: '50%' }, { width: '100%' }],
},
});
6 changes: 6 additions & 0 deletions src/skeleton/_example/cell-group/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"t-skeleton": "tdesign-miniprogram/skeleton/skeleton"
}
}
9 changes: 9 additions & 0 deletions src/skeleton/_example/cell-group/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<view class="group">
<t-skeleton class="group-avatar" rowCol="{{rowColsAvater}}" loading="{{loading}}"></t-skeleton>
<t-skeleton class="group-content" rowCol="{{rowColsContent}}" loading="{{loading}}"></t-skeleton>
</view>

<view class="group">
<t-skeleton class="group-avatar" rowCol="{{rowColsImage}}" loading="{{loading}}"></t-skeleton>
<t-skeleton class="group-content" rowCol="{{rowColsContent}}" loading="{{loading}}"></t-skeleton>
</view>
13 changes: 13 additions & 0 deletions src/skeleton/_example/cell-group/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.group {
display: flex;
align-items: center;
margin-bottom: 32rpx;
}

.group-avatar {
margin-right: 24rpx;
}

.group-content {
width: 566rpx;
}
20 changes: 20 additions & 0 deletions src/skeleton/_example/grid/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Component({
data: {
grid: [
[
{ width: '48px', height: '48px' },
{ width: '48px', height: '48px' },
{ width: '48px', height: '48px' },
{ width: '48px', height: '48px' },
{ width: '48px', height: '48px' },
],
[
{ width: '48px', height: '16px' },
{ width: '48px', height: '16px' },
{ width: '48px', height: '16px' },
{ width: '48px', height: '16px' },
{ width: '48px', height: '16px' },
],
],
},
});
6 changes: 6 additions & 0 deletions src/skeleton/_example/grid/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"t-skeleton": "tdesign-miniprogram/skeleton/skeleton"
}
}
1 change: 1 addition & 0 deletions src/skeleton/_example/grid/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<t-skeleton rowCol="{{grid}}" loading></t-skeleton>
Empty file.
5 changes: 5 additions & 0 deletions src/skeleton/_example/image-group/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Component({
data: {
rowCol: [{ height: '171px' }, 1, { width: '107px' }, [{ width: '93px' }, { width: '32px', marginLeft: '41px' }]],
},
});
6 changes: 6 additions & 0 deletions src/skeleton/_example/image-group/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"t-skeleton": "tdesign-miniprogram/skeleton/skeleton"
}
}
4 changes: 4 additions & 0 deletions src/skeleton/_example/image-group/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<view class="group">
<t-skeleton rowCol="{{rowCol}}" loading></t-skeleton>
<t-skeleton rowCol="{{rowCol}}" loading></t-skeleton>
</view>
4 changes: 4 additions & 0 deletions src/skeleton/_example/image-group/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.group {
display: flex;
justify-content: space-between;
}
7 changes: 6 additions & 1 deletion src/skeleton/_example/skeleton.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"navigationBarTitleText": "Skeleton 骨架屏",
"navigationBarBackgroundColor": "#fff",
"usingComponents": {
"t-demo": "../../components/demo-block/index"
"t-skeleton": "tdesign-miniprogram/skeleton/skeleton",
"theme": "./theme",
"grid": "./grid",
"cell-group": "./cell-group",
"image-group": "./image-group",
"animation": "./animation"
}
}
13 changes: 1 addition & 12 deletions src/skeleton/_example/skeleton.less
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
page {
background-color: #fff;

.skeleton-text {
border-radius: 16rpx;
}

.container-flex {
display: flex;
justify-content: space-between;
.box {
margin: 32rpx;
}

.none-margin {
margin: 0 !important;
}
}
46 changes: 21 additions & 25 deletions src/skeleton/_example/skeleton.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
Page({
data: {
rowCol: [
{ width: '686rpx', height: '32rpx' },
2,
3,
[
{ width: '38rpx', height: '32rpx', marginRight: '20rpx', marginLeft: '20rpx' },
{ width: '38rpx', height: '32rpx' },
],
{ width: '380rpx' },
],
rowCol1: [{ width: '686rpx', height: '32rpx' }, 1, 1, { width: '380rpx', height: '32rpx' }],
rowCol2: [
{ width: '566rpx', height: '32rpx' },
{ width: '100%', height: '32rpx' },
{ width: '100%', height: '32rpx' },
{ width: '314rpx', height: '32rpx' },
],
rowCol3: [
{ width: '332rpx', height: '342rpx' },
{ width: '332rpx', height: '32rpx' },
{ width: '214rpx', height: '32rpx' },
[
{ width: '186rpx', height: '32rpx' },
{ width: '64rpx', height: '32rpx', marginLeft: '82rpx' },
],
themeList: [
{
title: '头像骨架屏',
value: 'avatar',
loading: true,
},
{
title: '图片骨架屏',
value: 'image',
loading: true,
},
{
title: '文本骨架屏',
value: 'text',
loading: true,
},
{
title: '段落骨架屏',
value: 'paragraph',
loading: true,
},
],
},
});
34 changes: 24 additions & 10 deletions src/skeleton/_example/skeleton.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,34 @@
<view class="demo-title">Skeleton 骨架屏</view>
<view class="demo-desc">用于等待加载内容所展示的占位图形组合,有动态效果加载效果,减少用户等待焦虑。</view>
<t-demo title="01 类型">
<view class="demo-section__desc">基础</view>
<t-skeleton rowCol="{{rowCol1}}" loading></t-skeleton>
<view class="demo-section__desc">头像组合</view>
<t-skeleton rowCol="{{rowCol2}}" theme="avatar-text" loading></t-skeleton>
<view class="demo-section__desc">图片组合</view>
<view class="container-flex">
<t-skeleton t-class="none-margin" rowCol="{{rowCol3}}" t-class-text="skeleton-text" loading></t-skeleton>
<t-skeleton t-class="none-margin" rowCol="{{rowCol3}}" t-class-text="skeleton-text" loading></t-skeleton>
<view wx:for="{{themeList}}" wx:for-item="themeItem" wx:key="index">
<view class="demo-section__desc">{{themeItem.title}}</view>
<view class="box">
<theme theme="{{themeItem.value}}" loading="{{themeItem.loading}}" />
</view>
</view>
<view class="demo-section__desc">宫格骨架屏</view>
<view class="box">
<grid />
</view>
<view class="demo-section__desc">单元格骨架屏</view>
<view class="box">
<cell-group loading />
</view>
<view class="demo-section__desc">图片组合骨架屏</view>
<view class="box">
<image-group />
</view>
</t-demo>

<t-demo title="02 动画效果">
<view class="demo-section__desc">渐变加载动画</view>
<t-skeleton rowCol="{{rowCol1}}" animation="gradient" loading></t-skeleton>
<view class="box">
<t-skeleton theme="paragraph" animation="gradient" loading></t-skeleton>
</view>
<view class="demo-section__desc">闪烁加载动画</view>
<t-skeleton rowCol="{{rowCol2}}" theme="avatar-text" animation="flashed" loading></t-skeleton>
<view class="box">
<animation loading />
</view>
</t-demo>
</view>
11 changes: 11 additions & 0 deletions src/skeleton/_example/theme/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Component({
properties: {
theme: {
type: String,
value: 'text',
},
loading: {
type: Boolean,
},
},
});
6 changes: 6 additions & 0 deletions src/skeleton/_example/theme/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"t-skeleton": "tdesign-miniprogram/skeleton/skeleton"
}
}
1 change: 1 addition & 0 deletions src/skeleton/_example/theme/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<t-skeleton theme="{{theme}}" loading="{{loading}}"></t-skeleton>
Empty file.
1 change: 0 additions & 1 deletion src/skeleton/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const props: TdSkeletonProps = {
/** 用于设置行列数量、宽度高度、间距等。【示例一】,`[1, 1, 2]` 表示输出三行骨架图,第一行一列,第二行一列,第三行两列。【示例二】,`[1, 1, { width: '100px' }]` 表示自定义第三行的宽度为 `100px`。【示例三】,`[1, 2, [{ width, height }, { width, height, marginLeft }]]` 表示第三行有两列,且自定义宽度、高度和间距 */
rowCol: {
type: Array,
value: [1, 1, 1, { width: '70%' }],
},
/** 骨架图风格,有基础、头像组合等两大类 */
theme: {
Expand Down
Loading