mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-08-07 21:19:45 +08:00
feat(ShareSheet): support title、description prop
This commit is contained in:
parent
5080761cfe
commit
68164e64cf
@ -17,7 +17,7 @@ Vue.use(ActionSheet);
|
|||||||
|
|
||||||
### 基础用法
|
### 基础用法
|
||||||
|
|
||||||
`ActionSheet`通过`actions`数组来定义展示的选项,数组的每一项是一个对象,对象属性见文档下方表格。
|
动作面板通过`actions`属性来定义选项,数组的每一项是一个对象,对象格式见文档下方表格。
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-action-sheet v-model="show" :actions="actions" @select="onSelect" />
|
<van-action-sheet v-model="show" :actions="actions" @select="onSelect" />
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
### 介绍
|
### 介绍
|
||||||
|
|
||||||
底部弹起的模态面板,用于展示各分享渠道对应的操作按钮,不包含具体的分享逻辑。2.6 版本开始支持此组件。
|
底部弹起的分享面板,用于展示各分享渠道对应的操作按钮,不含具体的分享逻辑。2.6 版本开始支持此组件。
|
||||||
|
|
||||||
### 引入
|
### 引入
|
||||||
|
|
||||||
@ -17,17 +17,38 @@ Vue.use(ShareSheet);
|
|||||||
|
|
||||||
### 基础用法
|
### 基础用法
|
||||||
|
|
||||||
|
分享面板通过`options`属性来定义分享选项,数组的每一项是一个对象,对象格式见文档下方表格。
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-share-sheet :options="options" />
|
<van-cell @click="showShare = true" />
|
||||||
|
<van-share-sheet
|
||||||
|
v-model="showShare"
|
||||||
|
:options="options"
|
||||||
|
@select="onSelect"
|
||||||
|
/>
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { Toast } from 'vant';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
options: [],
|
showShare: false,
|
||||||
|
options: [
|
||||||
|
{ name: '微信', icon: 'wechat' },
|
||||||
|
{ name: '复制链接', icon: 'link' },
|
||||||
|
{ name: '分享海报', icon: 'poster' },
|
||||||
|
{ name: '二维码', icon: 'qrcode' },
|
||||||
|
],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
onSelect(option) {
|
||||||
|
Toast(option.name);
|
||||||
|
this.showShare = false;
|
||||||
|
},
|
||||||
|
}
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -6,7 +6,39 @@
|
|||||||
:title="t('showSheet')"
|
:title="t('showSheet')"
|
||||||
@click="showBasicSheet = true"
|
@click="showBasicSheet = true"
|
||||||
/>
|
/>
|
||||||
<van-share-sheet v-model="showBasicSheet" :options="options" />
|
<van-share-sheet
|
||||||
|
v-model="showBasicSheet"
|
||||||
|
:options="options"
|
||||||
|
@select="onSelect"
|
||||||
|
/>
|
||||||
|
</demo-block>
|
||||||
|
|
||||||
|
<demo-block :title="t('withTitle')">
|
||||||
|
<van-cell
|
||||||
|
is-link
|
||||||
|
:title="t('showSheet')"
|
||||||
|
@click="showTitleSheet = true"
|
||||||
|
/>
|
||||||
|
<van-share-sheet
|
||||||
|
v-model="showTitleSheet"
|
||||||
|
:title="t('title')"
|
||||||
|
:options="options"
|
||||||
|
:description="t('description')"
|
||||||
|
@select="onSelect"
|
||||||
|
/>
|
||||||
|
</demo-block>
|
||||||
|
|
||||||
|
<demo-block :title="t('multiLine')">
|
||||||
|
<van-cell
|
||||||
|
is-link
|
||||||
|
:title="t('showSheet')"
|
||||||
|
@click="showMultiRowSheet = true"
|
||||||
|
/>
|
||||||
|
<van-share-sheet
|
||||||
|
v-model="showMultiRowSheet"
|
||||||
|
:options="multiLineOptions"
|
||||||
|
@select="onSelect"
|
||||||
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
</demo-section>
|
</demo-section>
|
||||||
</template>
|
</template>
|
||||||
@ -16,23 +48,33 @@ export default {
|
|||||||
i18n: {
|
i18n: {
|
||||||
'zh-CN': {
|
'zh-CN': {
|
||||||
link: '复制链接',
|
link: '复制链接',
|
||||||
|
title: '立即分享给好友',
|
||||||
wechat: '微信',
|
wechat: '微信',
|
||||||
poster: '分享海报',
|
poster: '分享海报',
|
||||||
qrcode: '二维码',
|
qrcode: '二维码',
|
||||||
|
multiLine: '多行展示',
|
||||||
showSheet: '显示分享面板',
|
showSheet: '显示分享面板',
|
||||||
|
withTitle: '展示带标题的面板',
|
||||||
|
description: '描述信息',
|
||||||
},
|
},
|
||||||
'en-US': {
|
'en-US': {
|
||||||
link: 'Link',
|
link: 'Link',
|
||||||
|
title: 'Share with friends',
|
||||||
wechat: 'Wechat',
|
wechat: 'Wechat',
|
||||||
poster: 'Poster',
|
poster: 'Poster',
|
||||||
qrcode: 'Qrcode',
|
qrcode: 'Qrcode',
|
||||||
|
multiLine: 'Multi Line',
|
||||||
showSheet: 'Show ShareSheet',
|
showSheet: 'Show ShareSheet',
|
||||||
|
withTitle: 'Show ShareSheet with title',
|
||||||
|
description: 'Description',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
showBasicSheet: false,
|
showBasicSheet: false,
|
||||||
|
showTitleSheet: false,
|
||||||
|
showMultiRowSheet: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -43,6 +85,24 @@ export default {
|
|||||||
{ name: this.t('poster'), icon: 'poster' },
|
{ name: this.t('poster'), icon: 'poster' },
|
||||||
{ name: this.t('qrcode'), icon: 'qrcode' },
|
{ name: this.t('qrcode'), icon: 'qrcode' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
this.multiLineOptions = [
|
||||||
|
[{ name: this.t('wechat'), icon: 'wechat' }],
|
||||||
|
[
|
||||||
|
{ name: this.t('link'), icon: 'link' },
|
||||||
|
{ name: this.t('poster'), icon: 'poster' },
|
||||||
|
{ name: this.t('qrcode'), icon: 'qrcode' },
|
||||||
|
],
|
||||||
|
];
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
onSelect(option) {
|
||||||
|
this.$toast(option.name);
|
||||||
|
this.showBasicSheet = false;
|
||||||
|
this.showTitleSheet = false;
|
||||||
|
this.showMultiRowSheet = false;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -48,6 +48,22 @@ export default createComponent({
|
|||||||
return icon;
|
return icon;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
genHeader() {
|
||||||
|
if (!this.title && !this.description) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = this.slots('title') || this.title;
|
||||||
|
const description = this.slots('description') || this.description;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class={bem('header')}>
|
||||||
|
{title && <h2 class={bem('title')}>{title}</h2>}
|
||||||
|
{description && <span class={bem('description')}>{description}</span>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
genOptions() {
|
genOptions() {
|
||||||
return (
|
return (
|
||||||
<div class={bem('options')}>
|
<div class={bem('options')}>
|
||||||
@ -89,6 +105,7 @@ export default createComponent({
|
|||||||
safeAreaInsetBottom={this.safeAreaInsetBottom}
|
safeAreaInsetBottom={this.safeAreaInsetBottom}
|
||||||
onInput={this.toggle}
|
onInput={this.toggle}
|
||||||
>
|
>
|
||||||
|
{this.genHeader()}
|
||||||
{this.genOptions()}
|
{this.genOptions()}
|
||||||
{this.genCancelText()}
|
{this.genCancelText()}
|
||||||
</Popup>
|
</Popup>
|
||||||
|
@ -1,9 +1,30 @@
|
|||||||
@import '../style/var';
|
@import '../style/var';
|
||||||
|
|
||||||
.van-share-sheet {
|
.van-share-sheet {
|
||||||
|
&__header {
|
||||||
|
padding: 12px @padding-md @padding-base;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__title {
|
||||||
|
margin-top: @padding-xs;
|
||||||
|
color: @text-color;
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: @font-size-md;
|
||||||
|
line-height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__description {
|
||||||
|
display: block;
|
||||||
|
margin-top: @padding-xs;
|
||||||
|
color: @gray-6;
|
||||||
|
font-size: @font-size-sm;
|
||||||
|
line-height: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
&__options {
|
&__options {
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: 16px 0 16px 24px;
|
padding: @padding-md 0 @padding-md @padding-lg;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
-webkit-overflow-scrolling: touch;
|
-webkit-overflow-scrolling: touch;
|
||||||
|
|
||||||
@ -11,7 +32,8 @@
|
|||||||
// see: https://stackoverflow.com/questions/10054870
|
// see: https://stackoverflow.com/questions/10054870
|
||||||
&::after {
|
&::after {
|
||||||
display: block;
|
display: block;
|
||||||
width: 24px;
|
flex-shrink: 0;
|
||||||
|
width: @padding-lg;
|
||||||
content: '';
|
content: '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,12 +42,12 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-right: 32px;
|
margin-right: @padding-xl;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
|
||||||
&:last-child {
|
&:last-child {
|
||||||
padding-right: 16px;
|
margin-right: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
@ -39,16 +61,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&__name {
|
&__name {
|
||||||
margin-top: 8px;
|
margin-top: @padding-xs;
|
||||||
color: #646566;
|
color: @gray-7;
|
||||||
font-size: 12px;
|
font-size: @font-size-sm;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__cancel {
|
&__cancel {
|
||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
font-size: 16px;
|
font-size: @font-size-lg;
|
||||||
line-height: 48px;
|
line-height: 48px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
background-color: @white;
|
background-color: @white;
|
||||||
@ -57,7 +79,7 @@
|
|||||||
|
|
||||||
&::before {
|
&::before {
|
||||||
display: block;
|
display: block;
|
||||||
height: 8px;
|
height: @padding-xs;
|
||||||
background-color: @background-color;
|
background-color: @background-color;
|
||||||
content: ' ';
|
content: ' ';
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,19 @@ exports[`renders demo correctly 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
<!---->
|
<!---->
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<div role="button" tabindex="0" class="van-cell van-cell--clickable">
|
||||||
|
<div class="van-cell__title"><span>显示分享面板</span></div><i class="van-icon van-icon-arrow van-cell__right-icon">
|
||||||
|
<!----></i>
|
||||||
|
</div>
|
||||||
|
<!---->
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div role="button" tabindex="0" class="van-cell van-cell--clickable">
|
||||||
|
<div class="van-cell__title"><span>显示分享面板</span></div><i class="van-icon van-icon-arrow van-cell__right-icon">
|
||||||
|
<!----></i>
|
||||||
|
</div>
|
||||||
|
<!---->
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@ -584,6 +584,8 @@
|
|||||||
@rate-icon-full-color: #ffd21e;
|
@rate-icon-full-color: #ffd21e;
|
||||||
@rate-icon-disabled-color: #bdbdbd;
|
@rate-icon-disabled-color: #bdbdbd;
|
||||||
|
|
||||||
|
// ShareSheet
|
||||||
|
|
||||||
// Search
|
// Search
|
||||||
@search-padding: 10px @padding-sm;
|
@search-padding: 10px @padding-sm;
|
||||||
@search-background-color: @white;
|
@search-background-color: @white;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user