[new feature] Cell: add size prop (#2086)

This commit is contained in:
neverland 2018-11-14 17:25:14 +08:00 committed by GitHub
parent 469e8191df
commit 0860901ec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 229 additions and 144 deletions

View File

@ -7,39 +7,41 @@
</van-cell-group>
</demo-block>
<demo-block :title="$t('title2')">
<van-cell-group>
<van-cell :value="$t('content')" />
</van-cell-group>
<demo-block :title="$t('largeSize')">
<van-cell :title="$t('cell')" :value="$t('content')" size="large" />
<van-cell :title="$t('cell')" :value="$t('content')" size="large" :label="$t('desc')" />
</demo-block>
<demo-block :title="$t('title3')">
<van-cell-group>
<van-cell :title="$t('cell')" icon="location" />
</van-cell-group>
<demo-block :title="$t('showIcon')">
<van-cell :title="$t('cell')" :value="$t('content')" icon="location" />
</demo-block>
<demo-block :title="$t('title4')">
<van-cell-group>
<van-cell :title="$t('cell')" is-link />
<van-cell :title="$t('cell')" is-link :value="$t('content')" />
<van-cell :title="$t('cell')" is-link arrow-direction="down" :value="$t('content')" />
</van-cell-group>
<demo-block :title="$t('valueOnly')">
<van-cell :value="$t('content')" />
</demo-block>
<demo-block :title="$t('showArrow')">
<van-cell :title="$t('cell')" is-link />
<van-cell :title="$t('cell')" is-link :value="$t('content')" />
<van-cell :title="$t('cell')" is-link arrow-direction="down" :value="$t('content')" />
</demo-block>
<demo-block :title="$t('router')">
<van-cell :title="$t('cell')" is-link url="//youzan.github.io/vant/mobile.html" />
<van-cell :title="$t('cell')" is-link to="index" />
</demo-block>
<demo-block :title="$t('advancedUsage')">
<van-cell-group>
<van-cell :value="$t('content')" icon="shop" is-link>
<template slot="title">
<span class="van-cell-text">{{ $t('cell') }}</span>
<van-tag type="danger">{{ $t('tag') }}</van-tag>
</template>
</van-cell>
<van-cell :title="$t('cell')" icon="location" is-link />
<van-cell :title="$t('cell')">
<van-icon slot="right-icon" name="search" class="van-cell__right-icon" />
</van-cell>
</van-cell-group>
<van-cell :value="$t('content')" icon="shop" is-link>
<template slot="title">
<span class="custom-text">{{ $t('cell') }}</span>
<van-tag type="danger">{{ $t('tag') }}</van-tag>
</template>
</van-cell>
<van-cell :title="$t('cell')" icon="location" is-link />
<van-cell :title="$t('cell')">
<van-icon slot="right-icon" name="search" class="custom-icon" />
</van-cell>
</demo-block>
</demo-section>
</template>
@ -49,15 +51,19 @@ export default {
i18n: {
'zh-CN': {
cell: '单元格',
title2: '只设置 value',
title3: '展示图标',
title4: '展示箭头'
valueOnly: '只设置 value',
showIcon: '展示图标',
showArrow: '展示箭头',
largeSize: '单元格大小',
router: '页面跳转'
},
'en-US': {
cell: 'Cell title',
title2: 'Value only',
title3: 'Left Icon',
title4: 'Link'
valueOnly: 'Value only',
showIcon: 'Left Icon',
showArrow: 'Link',
largeSize: 'Size',
router: 'Router'
}
}
};
@ -65,9 +71,13 @@ export default {
<style lang="less">
.demo-cell {
.van-cell-text {
.custom-text {
margin-right: 5px;
vertical-align: middle;
}
.custom-icon {
line-height: 24px;
}
}
</style>

View File

@ -18,11 +18,12 @@ Vue.use(Cell).use(CellGroup);
</van-cell-group>
```
#### Value only
#### Size
```html
<van-cell-group>
<van-cell value="Content" />
<van-cell title="Cell title" value="Content" size="large" />
<van-cell title="Cell title" value="Content" size="large" label="Description" />
</van-cell-group>
```
@ -34,6 +35,14 @@ Vue.use(Cell).use(CellGroup);
</van-cell-group>
```
#### Value only
```html
<van-cell-group>
<van-cell value="Content" />
</van-cell-group>
```
#### Link
```html
@ -44,19 +53,28 @@ Vue.use(Cell).use(CellGroup);
</van-cell-group>
```
#### Router
```html
<van-cell-group>
<van-cell title="Cell title" is-link url="//youzan.github.io/vant/mobile.html" />
<van-cell title="Cell title" is-link to="index" />
</van-cell-group>
```
#### Advanced Usage
```html
<van-cell-group>
<van-cell value="Content" icon="shop" is-link>
<template slot="title">
<span class="van-cell-text">Cell title</span>
<span class="custom-text">Cell title</span>
<van-tag type="danger">Tag</van-tag>
</template>
</van-cell>
<van-cell title="Cell title" icon="location" is-link />
<van-cell title="Cell title">
<van-icon slot="right-icon" name="search" class="van-cell__right-icon" />
<van-icon slot="right-icon" name="search" class="custom-icon" />
</van-cell>
</van-cell-group>
```
@ -75,6 +93,7 @@ Vue.use(Cell).use(CellGroup);
| title | Title | `String | Number` | - |
| value | Right text | `String | Number` | - |
| label | Description below the title | `String` | - |
| size | Sizecan be set to `large` | `String` | - |
| border | Whether to show inner border | `Boolean` | `true` |
| center | Whether to center content vertically | `Boolean` | `true` |
| url | Link URL | `String` | - |

View File

@ -23,7 +23,7 @@
&__label {
font-size: 12px;
line-height: 1.2;
line-height: 18px;
color: @gray-darker;
}
@ -90,4 +90,13 @@
&--center {
align-items: center;
}
&--large {
padding-top: 12px;
padding-bottom: 12px;
.van-cell__title {
font-size: 16px;
}
}
}

View File

@ -4,6 +4,7 @@
b({
center,
required,
[size]: size,
borderless: !border,
clickable: isLink || clickable
})
@ -50,6 +51,7 @@ export default create({
props: {
icon: String,
size: String,
label: String,
center: Boolean,
isLink: Boolean,

View File

@ -23,97 +23,129 @@ exports[`renders demo correctly 1`] = `
</div>
</div>
<div>
<div class="van-cell-group van-hairline--top-bottom">
<div class="van-cell">
<!---->
<!---->
<div class="van-cell__value van-cell__value--alone"><span>内容</span></div>
<div class="van-cell van-cell--large">
<!---->
<div class="van-cell__title"><span>单元格</span>
<!---->
</div>
<div class="van-cell__value"><span>内容</span></div>
<!---->
</div>
<div class="van-cell van-cell--large">
<!---->
<div class="van-cell__title"><span>单元格</span>
<div class="van-cell__label">描述信息</div>
</div>
<div class="van-cell__value"><span>内容</span></div>
<!---->
</div>
</div>
<div>
<div class="van-cell-group van-hairline--top-bottom">
<div class="van-cell">
<i class="van-icon van-icon-location van-cell__left-icon" style="color:undefined;font-size:undefined;">
<!---->
</i>
<div class="van-cell__title"><span>单元格</span>
<!---->
</div>
<div class="van-cell">
<i class="van-icon van-icon-location van-cell__left-icon" style="color:undefined;font-size:undefined;">
<!---->
</i>
<div class="van-cell__title"><span>单元格</span>
<!---->
</div>
<div class="van-cell__value"><span>内容</span></div>
<!---->
</div>
</div>
<div>
<div class="van-cell-group van-hairline--top-bottom">
<div 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" style="color:undefined;font-size:undefined;">
<!---->
</i>
</div>
<div class="van-cell van-cell--clickable">
<!---->
<div class="van-cell__title"><span>单元格</span>
<!---->
</div>
<div class="van-cell__value"><span>内容</span></div>
<i class="van-icon van-icon-arrow van-cell__right-icon" style="color:undefined;font-size:undefined;">
<!---->
</i>
</div>
<div class="van-cell van-cell--clickable">
<!---->
<div class="van-cell__title"><span>单元格</span>
<!---->
</div>
<div class="van-cell__value"><span>内容</span></div>
<i class="van-icon van-icon-arrow van-cell__right-icon van-cell__right-icon--down" style="color:undefined;font-size:undefined;">
<!---->
</i>
</div>
<div class="van-cell">
<!---->
<!---->
<div class="van-cell__value van-cell__value--alone"><span>内容</span></div>
<!---->
</div>
</div>
<div>
<div class="van-cell-group van-hairline--top-bottom">
<div class="van-cell van-cell--clickable">
<i class="van-icon van-icon-shop van-cell__left-icon" style="color:undefined;font-size:undefined;">
<!---->
</i>
<div class="van-cell__title"><span class="van-cell-text">单元格</span> <span class="van-tag" style="background-color:#f44;">标签</span></div>
<div class="van-cell__value"><span>内容</span></div>
<i class="van-icon van-icon-arrow van-cell__right-icon" style="color:undefined;font-size:undefined;">
<!---->
</i>
</div>
<div class="van-cell van-cell--clickable">
<i class="van-icon van-icon-location van-cell__left-icon" style="color:undefined;font-size:undefined;">
<!---->
</i>
<div class="van-cell__title"><span>单元格</span>
<!---->
</div>
<div class="van-cell van-cell--clickable">
<!---->
<div class="van-cell__title"><span>单元格</span>
<!---->
<i class="van-icon van-icon-arrow van-cell__right-icon" style="color:undefined;font-size:undefined;">
<!---->
</i>
</div>
<div class="van-cell">
<!---->
<i class="van-icon van-icon-arrow van-cell__right-icon" style="color:undefined;font-size:undefined;">
<!---->
<div class="van-cell__title"><span>单元格</span>
<!---->
</div>
</i>
</div>
<div class="van-cell van-cell--clickable">
<!---->
<div class="van-cell__title"><span>单元格</span>
<!---->
<i class="van-cell__right-icon van-icon van-icon-search" style="color:undefined;font-size:undefined;">
<!---->
</i>
</div>
<div class="van-cell__value"><span>内容</span></div>
<i class="van-icon van-icon-arrow van-cell__right-icon" style="color:undefined;font-size:undefined;">
<!---->
</i>
</div>
<div class="van-cell van-cell--clickable">
<!---->
<div class="van-cell__title"><span>单元格</span>
<!---->
</div>
<div class="van-cell__value"><span>内容</span></div>
<i class="van-icon van-icon-arrow van-cell__right-icon van-cell__right-icon--down" style="color:undefined;font-size:undefined;">
<!---->
</i>
</div>
</div>
<div>
<div 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" style="color:undefined;font-size:undefined;">
<!---->
</i>
</div>
<div 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" style="color:undefined;font-size:undefined;">
<!---->
</i>
</div>
</div>
<div>
<div class="van-cell van-cell--clickable">
<i class="van-icon van-icon-shop van-cell__left-icon" style="color:undefined;font-size:undefined;">
<!---->
</i>
<div class="van-cell__title"><span class="custom-text">单元格</span> <span class="van-tag" style="background-color:#f44;">标签</span></div>
<div class="van-cell__value"><span>内容</span></div>
<i class="van-icon van-icon-arrow van-cell__right-icon" style="color:undefined;font-size:undefined;">
<!---->
</i>
</div>
<div class="van-cell van-cell--clickable">
<i class="van-icon van-icon-location van-cell__left-icon" style="color:undefined;font-size:undefined;">
<!---->
</i>
<div class="van-cell__title"><span>单元格</span>
<!---->
</div>
<!---->
<i class="van-icon van-icon-arrow van-cell__right-icon" style="color:undefined;font-size:undefined;">
<!---->
</i>
</div>
<div class="van-cell">
<!---->
<div class="van-cell__title"><span>单元格</span>
<!---->
</div>
<!---->
<i class="custom-icon van-icon van-icon-search" style="color:undefined;font-size:undefined;">
<!---->
</i>
</div>
</div>
</div>

View File

@ -11,7 +11,7 @@ Vue.use(Cell).use(CellGroup);
#### 基础用法
`van-cell-group`组件看成一个容器即可
`Cell`可以单独使用,也可以与`CellGroup`搭配使用。`CellGroup`可以为`Cell`提供上下外边框。
```html
<van-cell-group>
@ -20,52 +20,65 @@ Vue.use(Cell).use(CellGroup);
</van-cell-group>
```
#### 只设置value
只设置`value`时会向左对齐
#### 单元格大小
通过`size`属性可以控制单元格的大小
```html
<van-cell-group>
<van-cell value="内容" />
</van-cell-group>
<van-cell title="单元格" value="内容" size="large" />
<van-cell title="单元格" value="内容" size="large" label="描述信息" />
```
#### 展示图标
通过`icon`属性在标题左侧展示图标
```html
<van-cell-group>
<van-cell title="单元格" icon="location" />
</van-cell-group>
<van-cell title="单元格" icon="location" />
```
#### 只设置 value
只设置`value`时会向左对齐
```html
<van-cell value="内容" />
```
#### 展示箭头
传入`is-link`属性则会在右侧显示箭头,并且可以通过传入`arrow-direction`属性控制箭头方向
```html
<van-cell-group>
<van-cell title="单元格" is-link />
<van-cell title="单元格" is-link value="内容" />
<van-cell title="单元格" is-link arrow-direction="down" value="内容" />
</van-cell-group>
<van-cell title="单元格" is-link />
<van-cell title="单元格" is-link value="内容" />
<van-cell title="单元格" is-link arrow-direction="down" value="内容" />
```
#### 页面跳转
可以通过`url`属性进行页面跳转,或通过`to`属性进行 vue-router 跳转
```html
<van-cell title="单元格" is-link url="//youzan.github.io/vant/mobile.html" />
<van-cell title="单元格" is-link to="index" />
```
#### 高级用法
如以上用法不能满足你的需求,可以使用对应的`slot`来自定义显示的内容
```html
<van-cell-group>
<van-cell value="内容" icon="shop" is-link>
<template slot="title">
<span class="van-cell-text">单元格</span>
<van-tag type="danger">标签</van-tag>
</template>
</van-cell>
<van-cell title="单元格" icon="location" is-link />
<van-cell title="单元格">
<van-icon slot="right-icon" name="search" class="van-cell__right-icon" />
</van-cell>
</van-cell-group>
<van-cell value="内容" icon="shop" is-link>
<template slot="title">
<span class="custom-text">单元格</span>
<van-tag type="danger">标签</van-tag>
</template>
</van-cell>
<van-cell title="单元格" icon="location" is-link />
<van-cell title="单元格">
<van-icon slot="right-icon" name="search" class="custom-icon" />
</van-cell>
```
### CellGroup API
@ -82,10 +95,11 @@ Vue.use(Cell).use(CellGroup);
| title | 左侧标题 | `String | Number` | - | - |
| value | 右侧内容 | `String | Number` | - | - |
| label | 标题下方的描述信息 | `String` | - | - |
| size | 单元格大小,可选值为 `large` | `String` | - | 1.4.4 |
| url | 跳转链接 | `String` | - | - |
| to | 路由跳转对象,同 `vue-router` 的 to | `String | Object` | - | - |
| border | 是否显示内边框 | `Boolean` | `true` | - |
| replace | 跳转时是否替换当前 history | `String` | `false` | - |
| replace | 跳转时是否替换当前页面历史 | `String` | `false` | - |
| clickable | 是否开启点击反馈 | `Boolean` | `false` | - |
| is-link | 是否展示右侧箭头并开启点击反馈 | `Boolean` | `false` | - |
| required | 是否显示表单必填星号 | `Boolean` | `false` | - |
@ -96,14 +110,13 @@ Vue.use(Cell).use(CellGroup);
| 事件名 | 说明 | 参数 |
|------|------|------|
| click | 点击 cell 时触发 | - |
| click | 点击单元格时触发 | - |
### Cell Slot
| 名称 | 说明 |
|------|------|
| - | 自定义显示内容 |
| - | 自定义`value`显示内容 |
| title | 自定义`title`显示内容 |
| icon | 自定义`icon` |
| title | 自定义`title` |
| right-icon | 自定义右侧按钮,默认是`arrow` |

View File

@ -64,7 +64,7 @@ export default {
| info | 图标右上角提示信息 | `String | Number` | - | - |
| url | 跳转链接 | `String` | - | - |
| to | 路由跳转对象,同 `vue-router` 的 to | `String | Object` | - | - |
| replace | 跳转时是否替换当前 history | `String` | `false` | - |
| replace | 跳转时是否替换当前页面历史 | `String` | `false` | - |
#### GoodsActionBigBtn
@ -76,4 +76,4 @@ export default {
| loading | 是否显示为加载状态 | `Boolean` | `false` | - | 1.3.10 |
| url | 跳转链接 | `String` | - | - |
| to | 路由跳转对象,同 `vue-router` 的 to | `String | Object` | - | - |
| replace | 跳转时是否替换当前 history | `String` | `false` | - |
| replace | 跳转时是否替换当前页面历史 | `String` | `false` | - |

View File

@ -88,7 +88,7 @@ export default {
| info | 图标右上角提示信息 | `String | Number` | - | - |
| url | 跳转链接 | `String` | - | - |
| to | 路由跳转对象,同 `vue-router` 的 to | `String | Object` | - | - |
| replace | 跳转时是否替换当前 history | `String` | `false` | - |
| replace | 跳转时是否替换当前页面历史 | `String` | `false` | - |
### TabbarItem Slot