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

docs(sticky): update code sample #720

Merged
merged 1 commit into from
Aug 4, 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
21 changes: 14 additions & 7 deletions src/sticky/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@ isComponent: true

## 代码演示

### 基础吸顶容器

将内容包裹在 `Sticky` 组件内

<img src="https://tdesign.gtimg.com/miniprogram/readme/sticky.gif" width="375px" height="50%">

```html
<t-sticky offset-top="{{40}}">
<t-button class="box2" theme="danger" t-class="inner-box" size="small">吸顶距离</t-button>
</t-sticky>
```
### 基础吸顶

{{ base }}


### 吸顶距离

{{ offset }}

### 指定容器

{{ container }}



## API

Expand Down
1 change: 1 addition & 0 deletions src/sticky/_example/base/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Component({});
7 changes: 7 additions & 0 deletions src/sticky/_example/base/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"component": true,
"usingComponents": {
"t-button": "tdesign-miniprogram/button/button",
"t-sticky": "tdesign-miniprogram/sticky/sticky"
}
}
3 changes: 3 additions & 0 deletions src/sticky/_example/base/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<t-sticky>
<t-button size="large" theme="primary" t-class="external-class">基础吸顶</t-button>
</t-sticky>
3 changes: 3 additions & 0 deletions src/sticky/_example/base/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.external-class {
width: 208rpx;
}
13 changes: 13 additions & 0 deletions src/sticky/_example/container/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Component({
data: {
container: null,
},

lifetimes: {
ready: function () {
this.setData({
container: () => this.createSelectorQuery().select('.wrapper'),
});
},
},
});
7 changes: 7 additions & 0 deletions src/sticky/_example/container/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"component": true,
"usingComponents": {
"t-button": "tdesign-miniprogram/button/button",
"t-sticky": "tdesign-miniprogram/sticky/sticky"
}
}
5 changes: 5 additions & 0 deletions src/sticky/_example/container/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<view class="wrapper">
<t-sticky container="{{ container }}">
<t-button size="large" t-class="external-class green-button">指定容器</t-button>
</t-sticky>
</view>
15 changes: 15 additions & 0 deletions src/sticky/_example/container/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.wrapper {
width: 100%;
height: 150px;
background-color: rgba(255, 255, 255, 1);
}

.external-class {
width: 208rpx;
margin-left: 512rpx;
}

.green-button {
background-color: rgba(0, 168, 112, 1) !important;
color: #fff !important;
}
1 change: 1 addition & 0 deletions src/sticky/_example/offset/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Component({});
7 changes: 7 additions & 0 deletions src/sticky/_example/offset/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"component": true,
"usingComponents": {
"t-button": "tdesign-miniprogram/button/button",
"t-sticky": "tdesign-miniprogram/sticky/sticky"
}
}
3 changes: 3 additions & 0 deletions src/sticky/_example/offset/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<t-sticky offset-top="{{ 40 }}">
<t-button size="large" theme="danger" t-class="external-class">吸顶距离</t-button>
</t-sticky>
4 changes: 4 additions & 0 deletions src/sticky/_example/offset/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.external-class {
width: 208rpx;
margin-left: 272rpx;
}
5 changes: 4 additions & 1 deletion src/sticky/_example/sticky.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"navigationBarTitleText": "Sticky",
"usingComponents": {
"t-demo": "../../components/demo-block/index"
"t-demo": "../../components/demo-block/index",
"base": "./base",
"offset": "./offset",
"container": "./container"
}
}
30 changes: 0 additions & 30 deletions src/sticky/_example/sticky.less
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
.tdesign-demo-sticky-base {
height: 3000rpx;

.inner-box {
width: 208rpx;
height: 88rpx;
}

.box1 {
margin-left: 32rpx;
}

.box2 {
margin-left: 272rpx;
background-color: rgba(48, 106, 255, 0.6);
}

.box3 {
margin-left: 512rpx;
background-color: rgba(48, 106, 255, 0.3);
}

.box-c {
width: 100%;
height: 150px;
background-color: rgba(255, 255, 255, 1);
}

.green-button {
background-color: rgba(0, 168, 112, 1);
color: #fff;
}
}
12 changes: 1 addition & 11 deletions src/sticky/_example/sticky.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
Page({
data: {
container: null,
},
onLoad() {
this.setData({
// @ts-ignore
container: () => wx.createSelectorQuery().select('.box-c'),
});
},
});
Page({});
16 changes: 4 additions & 12 deletions src/sticky/_example/sticky.wxml
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
<view class="demo tdesign-demo-sticky-base">
<view class="demo-title">Sticky 吸顶</view>
<view class="demo-desc">用于常驻页面顶部的信息、操作展示。</view>
<t-demo title="01 类型" desc="基础吸顶">
<t-sticky>
<t-button class="box1" theme="primary" t-class="inner-box" size="small">基础吸顶</t-button>
</t-sticky>
<t-demo title="01 类型" desc="基础吸顶" padding>
<base />
</t-demo>
<t-demo title="" desc="吸顶距离">
<t-sticky offset-top="{{ 40 }}">
<t-button class="box2" theme="danger" t-class="inner-box" size="small">吸顶距离</t-button>
</t-sticky>
<offset />
</t-demo>
<t-demo title="" desc="指定容器">
<view class="box-c">
<t-sticky container="{{ container }}">
<t-button size="small" class="box3" t-class="inner-box green-button">指定容器</t-button>
</t-sticky>
</view>
<container />
</t-demo>
</view>