mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-24 23:49:14 +08:00
fix(ShareSheet): title slot not work
This commit is contained in:
parent
fc4d89b474
commit
1d07aa88ba
@ -17,6 +17,7 @@ Vue.use(ShareSheet);
|
|||||||
<van-cell title="Show ShareSheet" @click="showShare = true" />
|
<van-cell title="Show ShareSheet" @click="showShare = true" />
|
||||||
<van-share-sheet
|
<van-share-sheet
|
||||||
v-model="showShare"
|
v-model="showShare"
|
||||||
|
title="Share"
|
||||||
:options="options"
|
:options="options"
|
||||||
@select="onSelect"
|
@select="onSelect"
|
||||||
/>
|
/>
|
||||||
@ -47,23 +48,16 @@ export default {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
### Show Title
|
### Multi Line
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-share-sheet
|
<van-share-sheet
|
||||||
v-model="showShare"
|
v-model="showShare"
|
||||||
|
title="Share"
|
||||||
:options="options"
|
:options="options"
|
||||||
title="Share with friends"
|
|
||||||
description="Description"
|
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Multi Line
|
|
||||||
|
|
||||||
```html
|
|
||||||
<van-share-sheet v-model="showShare" :options="options" />
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@ -86,6 +80,17 @@ export default {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Show Description
|
||||||
|
|
||||||
|
```html
|
||||||
|
<van-share-sheet
|
||||||
|
v-model="showShare"
|
||||||
|
:options="options"
|
||||||
|
title="Share"
|
||||||
|
description="Description"
|
||||||
|
/>
|
||||||
|
```
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
### Props
|
### Props
|
||||||
|
@ -23,6 +23,7 @@ Vue.use(ShareSheet);
|
|||||||
<van-cell title="显示分享面板" @click="showShare = true" />
|
<van-cell title="显示分享面板" @click="showShare = true" />
|
||||||
<van-share-sheet
|
<van-share-sheet
|
||||||
v-model="showShare"
|
v-model="showShare"
|
||||||
|
title="立即分享给好友"
|
||||||
:options="options"
|
:options="options"
|
||||||
@select="onSelect"
|
@select="onSelect"
|
||||||
/>
|
/>
|
||||||
@ -53,25 +54,16 @@ export default {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
### 展示面板标题
|
|
||||||
|
|
||||||
通过`title`属性可以设置面板标题,通过`description`属性可以设置标题下方的描述文字
|
|
||||||
|
|
||||||
```html
|
|
||||||
<van-share-sheet
|
|
||||||
v-model="showShare"
|
|
||||||
:options="options"
|
|
||||||
title="立即分享给好友"
|
|
||||||
description="描述信息"
|
|
||||||
/>
|
|
||||||
```
|
|
||||||
|
|
||||||
### 展示多行选项
|
### 展示多行选项
|
||||||
|
|
||||||
当分享选项的数量较多时,可以将`options`定义为数组嵌套的格式,每个子数组会作为一行选项展示
|
当分享选项的数量较多时,可以将`options`定义为数组嵌套的格式,每个子数组会作为一行选项展示
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-share-sheet v-model="showShare" :options="options" />
|
<van-share-sheet
|
||||||
|
v-model="showShare"
|
||||||
|
title="立即分享给好友"
|
||||||
|
:options="options"
|
||||||
|
/>
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@ -119,6 +111,19 @@ export default {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 展示描述信息
|
||||||
|
|
||||||
|
通过`description`属性可以设置标题下方的描述文字
|
||||||
|
|
||||||
|
```html
|
||||||
|
<van-share-sheet
|
||||||
|
v-model="showShare"
|
||||||
|
:options="options"
|
||||||
|
title="立即分享给好友"
|
||||||
|
description="描述信息"
|
||||||
|
/>
|
||||||
|
```
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
### Props
|
### Props
|
||||||
|
@ -4,22 +4,8 @@
|
|||||||
<van-cell is-link :title="t('showSheet')" @click="show.basic = true" />
|
<van-cell is-link :title="t('showSheet')" @click="show.basic = true" />
|
||||||
<van-share-sheet
|
<van-share-sheet
|
||||||
v-model="show.basic"
|
v-model="show.basic"
|
||||||
:options="options"
|
|
||||||
@select="onSelect"
|
|
||||||
/>
|
|
||||||
</demo-block>
|
|
||||||
|
|
||||||
<demo-block :title="t('withTitle')">
|
|
||||||
<van-cell
|
|
||||||
is-link
|
|
||||||
:title="t('showSheet')"
|
|
||||||
@click="show.withTitle = true"
|
|
||||||
/>
|
|
||||||
<van-share-sheet
|
|
||||||
v-model="show.withTitle"
|
|
||||||
:title="t('title')"
|
:title="t('title')"
|
||||||
:options="options"
|
:options="options"
|
||||||
:description="t('description')"
|
|
||||||
@select="onSelect"
|
@select="onSelect"
|
||||||
/>
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
@ -32,6 +18,7 @@
|
|||||||
/>
|
/>
|
||||||
<van-share-sheet
|
<van-share-sheet
|
||||||
v-model="show.multiLine"
|
v-model="show.multiLine"
|
||||||
|
:title="t('title')"
|
||||||
:options="multiLineOptions"
|
:options="multiLineOptions"
|
||||||
@select="onSelect"
|
@select="onSelect"
|
||||||
/>
|
/>
|
||||||
@ -49,6 +36,17 @@
|
|||||||
@select="onSelect"
|
@select="onSelect"
|
||||||
/>
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
|
||||||
|
<demo-block :title="t('withDesc')">
|
||||||
|
<van-cell is-link :title="t('showSheet')" @click="show.withDesc = true" />
|
||||||
|
<van-share-sheet
|
||||||
|
v-model="show.withDesc"
|
||||||
|
:title="t('title')"
|
||||||
|
:options="options"
|
||||||
|
:description="t('description')"
|
||||||
|
@select="onSelect"
|
||||||
|
/>
|
||||||
|
</demo-block>
|
||||||
</demo-section>
|
</demo-section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -66,7 +64,7 @@ export default {
|
|||||||
qrcode: '二维码',
|
qrcode: '二维码',
|
||||||
multiLine: '展示多行选项',
|
multiLine: '展示多行选项',
|
||||||
showSheet: '显示分享面板',
|
showSheet: '显示分享面板',
|
||||||
withTitle: '展示面板标题',
|
withDesc: '展示描述信息',
|
||||||
customIcon: '自定义图标',
|
customIcon: '自定义图标',
|
||||||
description: '描述信息',
|
description: '描述信息',
|
||||||
},
|
},
|
||||||
@ -74,14 +72,14 @@ export default {
|
|||||||
qq: 'QQ',
|
qq: 'QQ',
|
||||||
name: 'Name',
|
name: 'Name',
|
||||||
link: 'Link',
|
link: 'Link',
|
||||||
title: 'Share with friends',
|
title: 'Share',
|
||||||
weibo: 'Weibo',
|
weibo: 'Weibo',
|
||||||
wechat: 'Wechat',
|
wechat: 'Wechat',
|
||||||
poster: 'Poster',
|
poster: 'Poster',
|
||||||
qrcode: 'Qrcode',
|
qrcode: 'Qrcode',
|
||||||
multiLine: 'Multi Line',
|
multiLine: 'Multi Line',
|
||||||
showSheet: 'Show ShareSheet',
|
showSheet: 'Show ShareSheet',
|
||||||
withTitle: 'Show Title',
|
withDesc: 'Show Description',
|
||||||
customIcon: 'Custom Icon',
|
customIcon: 'Custom Icon',
|
||||||
description: 'Description',
|
description: 'Description',
|
||||||
},
|
},
|
||||||
@ -91,7 +89,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
show: {
|
show: {
|
||||||
basic: false,
|
basic: false,
|
||||||
withTitle: false,
|
withDesc: false,
|
||||||
multiLine: false,
|
multiLine: false,
|
||||||
customIcon: false,
|
customIcon: false,
|
||||||
},
|
},
|
||||||
@ -146,7 +144,7 @@ export default {
|
|||||||
onSelect(option) {
|
onSelect(option) {
|
||||||
this.$toast(option.name);
|
this.$toast(option.name);
|
||||||
this.show.basic = false;
|
this.show.basic = false;
|
||||||
this.show.withTitle = false;
|
this.show.withDesc = false;
|
||||||
this.show.multiLine = false;
|
this.show.multiLine = false;
|
||||||
this.show.customIcon = false;
|
this.show.customIcon = false;
|
||||||
},
|
},
|
||||||
|
@ -50,13 +50,13 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
genHeader() {
|
genHeader() {
|
||||||
if (!this.title && !this.description) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const title = this.slots('title') || this.title;
|
const title = this.slots('title') || this.title;
|
||||||
const description = this.slots('description') || this.description;
|
const description = this.slots('description') || this.description;
|
||||||
|
|
||||||
|
if (!title && !description) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={bem('header')}>
|
<div class={bem('header')}>
|
||||||
{title && <h2 class={bem('title')}>{title}</h2>}
|
{title && <h2 class={bem('title')}>{title}</h2>}
|
||||||
@ -76,7 +76,7 @@ export default createComponent({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<img src={this.getIconURL(option.icon)} class={bem('icon')} />
|
<img src={this.getIconURL(option.icon)} class={bem('icon')} />
|
||||||
<span class={bem('name')}>{option.name || ''}</span>
|
{option.name && <span class={bem('name')}>{option.name}</span>}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
@ -23,5 +23,12 @@ 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>
|
||||||
`;
|
`;
|
||||||
|
14
src/share-sheet/test/__snapshots__/index.spec.js.snap
Normal file
14
src/share-sheet/test/__snapshots__/index.spec.js.snap
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`cancel-text prop 1`] = `<button type="button" class="van-share-sheet__cancel">foo</button>`;
|
||||||
|
|
||||||
|
exports[`description prop 1`] = `<span class="van-share-sheet__description">foo</span>`;
|
||||||
|
|
||||||
|
exports[`title & description slot 1`] = `
|
||||||
|
<div class="van-popup van-popup--round van-popup--bottom van-popup--safe-area-inset-bottom van-share-sheet" name="van-popup-slide-bottom">
|
||||||
|
<div class="van-share-sheet__header">
|
||||||
|
<h2 class="van-share-sheet__title">Custom Title</h2><span class="van-share-sheet__description">Custom Description</span>
|
||||||
|
</div>
|
||||||
|
<div class="van-share-sheet__options"></div><button type="button" class="van-share-sheet__cancel">取消</button>
|
||||||
|
</div>
|
||||||
|
`;
|
72
src/share-sheet/test/index.spec.js
Normal file
72
src/share-sheet/test/index.spec.js
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import ShareSheet from '..';
|
||||||
|
import { mount } from '../../../test';
|
||||||
|
|
||||||
|
test('cancel-text prop', () => {
|
||||||
|
const wrapper = mount(ShareSheet, {
|
||||||
|
propsData: {
|
||||||
|
value: true,
|
||||||
|
cancelText: 'foo',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.find('.van-share-sheet__cancel')).toMatchSnapshot();
|
||||||
|
|
||||||
|
wrapper.setProps({ cancelText: '' });
|
||||||
|
expect(wrapper.contains('.van-share-sheet__cancel')).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('description prop', () => {
|
||||||
|
const wrapper = mount(ShareSheet, {
|
||||||
|
propsData: {
|
||||||
|
value: true,
|
||||||
|
description: 'foo',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.find('.van-share-sheet__description')).toMatchSnapshot();
|
||||||
|
|
||||||
|
wrapper.setProps({ description: '' });
|
||||||
|
expect(wrapper.contains('.van-share-sheet__description')).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('select event', () => {
|
||||||
|
const wrapper = mount(ShareSheet, {
|
||||||
|
propsData: {
|
||||||
|
value: true,
|
||||||
|
options: [{ icon: 'wechat', name: 'wechat' }],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.find('.van-share-sheet__option').trigger('click');
|
||||||
|
expect(wrapper.emitted('select')[0]).toEqual([
|
||||||
|
{ icon: 'wechat', name: 'wechat' },
|
||||||
|
0,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('cancel event', () => {
|
||||||
|
const wrapper = mount(ShareSheet, {
|
||||||
|
propsData: {
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.find('.van-share-sheet__cancel').trigger('click');
|
||||||
|
|
||||||
|
expect(wrapper.emitted('input')[0][0]).toEqual(false);
|
||||||
|
expect(wrapper.emitted('cancel')[0]).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('title & description slot', () => {
|
||||||
|
const wrapper = mount(ShareSheet, {
|
||||||
|
propsData: {
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
scopedSlots: {
|
||||||
|
title: () => 'Custom Title',
|
||||||
|
description: () => 'Custom Description',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user