feat(CellGroup): add title slot (#4227)

This commit is contained in:
neverland 2019-08-25 10:55:01 +08:00 committed by GitHub
parent 689a579503
commit dc6a3c4243
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 9 deletions

View File

@ -4,11 +4,15 @@ import { BORDER_TOP_BOTTOM } from '../utils/constant';
// Types
import { CreateElement, RenderContext } from 'vue/types';
import { DefaultSlots } from '../utils/types';
import { DefaultSlots, ScopedSlot } from '../utils/types';
export type CellGroupProps = {
title?: string;
border: boolean
border: boolean;
};
export type CellGroupSlots = DefaultSlots & {
title?: ScopedSlot;
};
const [createComponent, bem] = createNamespace('cell-group');
@ -16,22 +20,19 @@ const [createComponent, bem] = createNamespace('cell-group');
function CellGroup(
h: CreateElement,
props: CellGroupProps,
slots: DefaultSlots,
slots: CellGroupSlots,
ctx: RenderContext<CellGroupProps>
) {
const Group = (
<div
class={[bem(), { [BORDER_TOP_BOTTOM]: props.border }]}
{...inherit(ctx, true)}
>
<div class={[bem(), { [BORDER_TOP_BOTTOM]: props.border }]} {...inherit(ctx, true)}>
{slots.default && slots.default()}
</div>
);
if (props.title) {
if (props.title || slots.title) {
return (
<div>
<div class={bem('title')}>{props.title}</div>
<div class={bem('title')}>{slots.title ? slots.title() : props.title}</div>
{Group}
</div>
);

View File

@ -132,6 +132,13 @@ Vue.use(Cell).use(CellGroup);
|------|------|------|
| click | Triggered when click cell | event: Event |
### CellGroup Slots
| Name | Description |
|------|------|
| default | Default slot |
| title | Custom title |
### Cell Slots
| Name | Description |

View File

@ -147,3 +147,10 @@ Vue.use(Cell).use(CellGroup);
| label | 自定义标题下方描述显示内容 |
| icon | 自定义左侧图标 |
| right-icon | 自定义右侧按钮,默认为`arrow` |
### CellGroup Slots
| 名称 | 说明 |
|------|------|
| default | 默认插槽 |
| title | 自定义分组标题 |

View File

@ -1,5 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`CellGroup title slot 1`] = `
<div>
<div class="van-cell-group__title">CustomTitle</div>
<div class="van-cell-group van-hairline--top-bottom"></div>
</div>
`;
exports[`arrow direction 1`] = `
<div class="van-cell van-cell--clickable"><i class="van-icon van-icon-arrow-down van-cell__right-icon">
<!----></i></div>

View File

@ -1,4 +1,5 @@
import Cell from '..';
import CellGroup from '../../cell-group';
import { mount } from '../../../test/utils';
test('click event', () => {
@ -56,3 +57,13 @@ test('title-style prop', () => {
expect(wrapper).toMatchSnapshot();
});
test('CellGroup title slot', () => {
const wrapper = mount(CellGroup, {
scopedSlots: {
title: () => 'CustomTitle'
}
});
expect(wrapper).toMatchSnapshot();
});