Skip to content

Commit

Permalink
feat(share-sheet): add new component (#3559)
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-zsd committed Aug 26, 2020
1 parent 4a479f6 commit 13e82ea
Show file tree
Hide file tree
Showing 20 changed files with 686 additions and 8 deletions.
6 changes: 4 additions & 2 deletions example/app.json
Expand Up @@ -50,7 +50,8 @@
"pages/skeleton/index",
"pages/divider/index",
"pages/empty/index",
"pages/calendar/index"
"pages/calendar/index",
"pages/share-sheet/index"
],
"window": {
"navigationBarBackgroundColor": "#f8f8f8",
Expand Down Expand Up @@ -123,7 +124,8 @@
"van-dropdown-menu": "./dist/dropdown-menu/index",
"van-dropdown-item": "./dist/dropdown-item/index",
"van-skeleton": "./dist/skeleton/index",
"van-calendar": "./dist/calendar/index"
"van-calendar": "./dist/calendar/index",
"van-share-sheet": "./dist/share-sheet/index"
},
"sitemapLocation": "sitemap.json"
}
4 changes: 4 additions & 0 deletions example/config.js
Expand Up @@ -115,6 +115,10 @@ export default [
path: '/overlay',
title: 'Overlay 遮罩层',
},
{
path: '/share-sheet',
title: 'ShareSheet 分享面板',
},
{
path: '/swipe-cell',
title: 'SwipeCell 滑动单元格',
Expand Down
82 changes: 82 additions & 0 deletions example/pages/share-sheet/index.js
@@ -0,0 +1,82 @@
import Page from '../../common/page';
import Toast from '../../dist/toast/toast';

Page({
data: {
show: {
basic: false,
withDesc: false,
multiLine: false,
customIcon: false,
},
options: [
{ name: '微信', icon: 'wechat' },
{ name: '微博', icon: 'weibo' },
{ name: '复制链接', icon: 'link' },
{ name: '分享海报', icon: 'poster' },
{ name: '二维码', icon: 'qrcode' },
],

multiLineOptions: [
[
{ name: '微信', icon: 'wechat' },
{ name: '微博', icon: 'weibo' },
{ name: 'QQ', icon: 'qq' },
],
[
{ name: '复制链接', icon: 'link' },
{ name: '分享海报', icon: 'poster' },
{ name: '二维码', icon: 'qrcode' },
],
],

customIconOptions: [
{
name: '名称',
icon: 'https://img.yzcdn.cn/vant/custom-icon-fire.png',
},
{
name: '名称',
icon: 'https://img.yzcdn.cn/vant/custom-icon-light.png',
},
{
name: '名称',
icon: 'https://img.yzcdn.cn/vant/custom-icon-water.png',
},
],

optionsWithDesc: [
{ name: '微信', icon: 'wechat' },
{ name: '微博', icon: 'weibo' },
{
name: '复制链接',
icon: 'link',
description: '描述信息',
},
{ name: '分享海报', icon: 'poster' },
{ name: '二维码', icon: 'qrcode' },
],
},

onShowShareSheet(event) {
this.setData({
[`show.${event.target.dataset.type}`]: true,
});
},

onClose() {
this.setData({
show: {
basic: false,
withDesc: false,
multiLine: false,
customIcon: false,
},
});
},

onSelect(event) {
Toast(event.detail.name);
this.onClose();
},
});
3 changes: 3 additions & 0 deletions example/pages/share-sheet/index.json
@@ -0,0 +1,3 @@
{
"navigationBarTitleText": "Card 商品卡片"
}
45 changes: 45 additions & 0 deletions example/pages/share-sheet/index.wxml
@@ -0,0 +1,45 @@
<demo-block card title="基础用法">
<van-cell is-link title="显示分享面板" data-type="basic" bind:click="onShowShareSheet" />
<van-share-sheet
show="{{ show.basic }}"
title="立即分享给好友"
options="{{ options }}"
bind:close="onClose"
bind:select="onSelect"
/>
</demo-block>

<demo-block card title="展示多行选项">
<van-cell is-link title="显示分享面板" data-type="multiLine" bind:click="onShowShareSheet" />
<van-share-sheet
show="{{ show.multiLine }}"
title="立即分享给好友"
options="{{ multiLineOptions }}"
bind:close="onClose"
bind:select="onSelect"
/>
</demo-block>

<demo-block card title="自定义图标">
<van-cell is-link title="显示分享面板" data-type="customIcon" bind:click="onShowShareSheet" />
<van-share-sheet
show="{{ show.customIcon }}"
options="{{ customIconOptions }}"
bind:close="onClose"
bind:select="onSelect"
/>
</demo-block>

<demo-block card title="展示描述信息">
<van-cell is-link title="显示分享面板" data-type="withDesc" bind:click="onShowShareSheet" />
<van-share-sheet
show="{{ show.withDesc }}"
title="立即分享给好友"
options="{{ optionsWithDesc }}"
description="描述信息"
bind:close="onClose"
bind:select="onSelect"
/>
</demo-block>

<van-toast id="van-toast" />
13 changes: 13 additions & 0 deletions example/pages/share-sheet/index.wxss
@@ -0,0 +1,13 @@
.container {
height: 100vh;
background-color: #fff;
}

.tag,
.button {
margin-right: 5px;
}

.van-card__footer {
margin-top: 5px;
}
9 changes: 9 additions & 0 deletions example/project.config.json
Expand Up @@ -374,12 +374,21 @@
"id": -1,
"name": "index-bar",
"pathName": "pages/index-bar/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "empty",
"pathName": "pages/empty/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "pages/share-sheet/index",
"pathName": "pages/share-sheet/index",
"query": "",
"scene": null
}
]
Expand Down
22 changes: 16 additions & 6 deletions packages/common/style/mixins/hairline.less
@@ -1,29 +1,39 @@
@import '../var.less';

.hairline-common() {
position: absolute;
box-sizing: border-box;
transform-origin: center; /* cover wechat button:after default transforn-origin */
content: ' ';
pointer-events: none;
}

.hairline(@border-color: #eee) {
.hairline(@color: @border-color) {
.hairline-common();

top: -50%;
right: -50%;
bottom: -50%;
left: -50%;
border: 0 solid @border-color;
border: 0 solid @color;
transform: scale(0.5);
}

.hairline-bottom(@border-color: #eee, @left: 0, @right: 0) {
.hairline-top(@color: @border-color, @left: 0, @right: 0) {
.hairline-common();

top: 0;
right: @right;
left: @left;
border-top: 1px solid @color;
transform: scaleY(0.5);
}

.hairline-bottom(@color: @border-color, @left: 0, @right: 0) {
.hairline-common();

top: auto;
right: @right;
bottom: 0;
left: @left;
border-bottom: 1px solid @border-color;
border-bottom: 1px solid @color;
transform: scaleY(0.5);
}
21 changes: 21 additions & 0 deletions packages/common/style/var.less
Expand Up @@ -43,6 +43,10 @@
@font-size-md: 14px;
@font-size-lg: 16px;
@font-weight-bold: 500;
@line-height-xs: 14px;
@line-height-sm: 18px;
@line-height-md: 20px;
@line-height-lg: 22px;
@base-font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue',
Helvetica, Segoe UI, Arial, Roboto, 'PingFang SC', 'Hiragino Sans GB',
'Microsoft Yahei', sans-serif;
Expand Down Expand Up @@ -387,6 +391,23 @@
@switch-disabled-opacity: 0.4;
@switch-border: 1px solid rgba(0, 0, 0, 0.1);

// ShareSheet
@share-sheet-header-padding: @padding-sm @padding-md @padding-base;
@share-sheet-title-color: @text-color;
@share-sheet-title-font-size: @font-size-md;
@share-sheet-title-line-height: @line-height-md;
@share-sheet-description-color: @gray-6;
@share-sheet-description-font-size: @font-size-sm;
@share-sheet-description-line-height: 16px;
@share-sheet-icon-size: 48px;
@share-sheet-option-name-color: @gray-7;
@share-sheet-option-name-font-size: @font-size-sm;
@share-sheet-option-description-color: @gray-5;
@share-sheet-option-description-font-size: @font-size-sm;
@share-sheet-cancel-button-font-size: @font-size-lg;
@share-sheet-cancel-button-height: 48px;
@share-sheet-cancel-button-background: @white;

// Search
@search-background-color: @gray-1;
@search-padding: 10px @padding-sm;
Expand Down

0 comments on commit 13e82ea

Please sign in to comment.