mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 18:36:51 +08:00
feat(CellGroup): add title slot (#4227)
This commit is contained in:
parent
689a579503
commit
dc6a3c4243
@ -4,11 +4,15 @@ import { BORDER_TOP_BOTTOM } from '../utils/constant';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/types';
|
import { DefaultSlots, ScopedSlot } from '../utils/types';
|
||||||
|
|
||||||
export type CellGroupProps = {
|
export type CellGroupProps = {
|
||||||
title?: string;
|
title?: string;
|
||||||
border: boolean
|
border: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CellGroupSlots = DefaultSlots & {
|
||||||
|
title?: ScopedSlot;
|
||||||
};
|
};
|
||||||
|
|
||||||
const [createComponent, bem] = createNamespace('cell-group');
|
const [createComponent, bem] = createNamespace('cell-group');
|
||||||
@ -16,22 +20,19 @@ const [createComponent, bem] = createNamespace('cell-group');
|
|||||||
function CellGroup(
|
function CellGroup(
|
||||||
h: CreateElement,
|
h: CreateElement,
|
||||||
props: CellGroupProps,
|
props: CellGroupProps,
|
||||||
slots: DefaultSlots,
|
slots: CellGroupSlots,
|
||||||
ctx: RenderContext<CellGroupProps>
|
ctx: RenderContext<CellGroupProps>
|
||||||
) {
|
) {
|
||||||
const Group = (
|
const Group = (
|
||||||
<div
|
<div class={[bem(), { [BORDER_TOP_BOTTOM]: props.border }]} {...inherit(ctx, true)}>
|
||||||
class={[bem(), { [BORDER_TOP_BOTTOM]: props.border }]}
|
|
||||||
{...inherit(ctx, true)}
|
|
||||||
>
|
|
||||||
{slots.default && slots.default()}
|
{slots.default && slots.default()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (props.title) {
|
if (props.title || slots.title) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div class={bem('title')}>{props.title}</div>
|
<div class={bem('title')}>{slots.title ? slots.title() : props.title}</div>
|
||||||
{Group}
|
{Group}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -132,6 +132,13 @@ Vue.use(Cell).use(CellGroup);
|
|||||||
|------|------|------|
|
|------|------|------|
|
||||||
| click | Triggered when click cell | event: Event |
|
| click | Triggered when click cell | event: Event |
|
||||||
|
|
||||||
|
### CellGroup Slots
|
||||||
|
|
||||||
|
| Name | Description |
|
||||||
|
|------|------|
|
||||||
|
| default | Default slot |
|
||||||
|
| title | Custom title |
|
||||||
|
|
||||||
### Cell Slots
|
### Cell Slots
|
||||||
|
|
||||||
| Name | Description |
|
| Name | Description |
|
||||||
|
@ -147,3 +147,10 @@ Vue.use(Cell).use(CellGroup);
|
|||||||
| label | 自定义标题下方描述显示内容 |
|
| label | 自定义标题下方描述显示内容 |
|
||||||
| icon | 自定义左侧图标 |
|
| icon | 自定义左侧图标 |
|
||||||
| right-icon | 自定义右侧按钮,默认为`arrow` |
|
| right-icon | 自定义右侧按钮,默认为`arrow` |
|
||||||
|
|
||||||
|
### CellGroup Slots
|
||||||
|
|
||||||
|
| 名称 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| default | 默认插槽 |
|
||||||
|
| title | 自定义分组标题 |
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// 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`] = `
|
exports[`arrow direction 1`] = `
|
||||||
<div class="van-cell van-cell--clickable"><i class="van-icon van-icon-arrow-down van-cell__right-icon">
|
<div class="van-cell van-cell--clickable"><i class="van-icon van-icon-arrow-down van-cell__right-icon">
|
||||||
<!----></i></div>
|
<!----></i></div>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import Cell from '..';
|
import Cell from '..';
|
||||||
|
import CellGroup from '../../cell-group';
|
||||||
import { mount } from '../../../test/utils';
|
import { mount } from '../../../test/utils';
|
||||||
|
|
||||||
test('click event', () => {
|
test('click event', () => {
|
||||||
@ -56,3 +57,13 @@ test('title-style prop', () => {
|
|||||||
|
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('CellGroup title slot', () => {
|
||||||
|
const wrapper = mount(CellGroup, {
|
||||||
|
scopedSlots: {
|
||||||
|
title: () => 'CustomTitle'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user