diff --git a/docs/site/doc.config.js b/docs/site/doc.config.js index be123d3b8..bd6163591 100644 --- a/docs/site/doc.config.js +++ b/docs/site/doc.config.js @@ -223,6 +223,10 @@ export default { path: '/collapse', title: 'Collapse 折叠面板' }, + { + path: '/divider', + title: 'Divider 分割线' + }, { path: '/image-preview', title: 'ImagePreview 图片预览' @@ -549,6 +553,10 @@ export default { path: '/collapse', title: 'Collapse' }, + { + path: '/divider', + title: 'Divider' + }, { path: '/image-preview', title: 'ImagePreview' diff --git a/src/divider/README.md b/src/divider/README.md new file mode 100644 index 000000000..7b9d74d6e --- /dev/null +++ b/src/divider/README.md @@ -0,0 +1,60 @@ +# Divider + +### Install + +``` javascript +import { Divider } from 'vant'; + +Vue.use(Divider); +``` + +## Usage + +### Basic Usage + +```html + +``` + +### With Text + +```html +Text +``` + +### Content Position + +```html +Text +Text +``` + +### Dashed + +```html +Text +``` + +### Custom Style + +```html + + Text + +``` + +## API + +### Props + +| Attribute | Description | Type | Default | +|------|------|------|------| +| dashed | Whether to use dashed border | `Boolean` | `false` | +| hairline | Whether to use hairline | `Boolean` | `true` | +| content-position | Content position,can be set to `left` `right` | `String` | `center` | + +### Cell Slots + +| Name | Description | +|------|------| +| default | content | diff --git a/src/divider/README.zh-CN.md b/src/divider/README.zh-CN.md new file mode 100644 index 000000000..59903047e --- /dev/null +++ b/src/divider/README.zh-CN.md @@ -0,0 +1,70 @@ +# Divider 分割线 + +### 引入 + +``` javascript +import { Divider } from 'vant'; + +Vue.use(Divider); +``` + +## 代码演示 + +### 基础用法 + +Divider 默认渲染一条水平分割线 + +```html + +``` + +### 展示文字 + +通过插槽在可以分割线中间插入内容 + +```html +文字 +``` + +### 内容位置 + +通过`content-position`指定内容所在位置 + +```html +文字 +文字 +``` + +### 虚线 + +添加`dashed`属性使分割线渲染为虚线 + +```html +文字 +``` + +### 自定义样式 + +可以直接通过`style`属性设置分割线的样式 + +```html + + 文字 + +``` + +## API + +### Props + +| 参数 | 说明 | 类型 | 默认值 | 版本 | +|------|------|------|------|------| +| dashed | 是否使用虚线 | `Boolean` | `false` | - | +| hairline | 是否使用 0.5px 线 | `Boolean` | `true` | - | +| content-position | 内容位置,可选值为`left` `right` | `String` | `center` | - | + +### Slots + +| 名称 | 说明 | +|------|------| +| default | 内容 | diff --git a/src/divider/demo/index.vue b/src/divider/demo/index.vue new file mode 100644 index 000000000..cbad748b4 --- /dev/null +++ b/src/divider/demo/index.vue @@ -0,0 +1,77 @@ + + + + + diff --git a/src/divider/index.less b/src/divider/index.less new file mode 100644 index 000000000..6a840e99f --- /dev/null +++ b/src/divider/index.less @@ -0,0 +1,64 @@ +@import '../style/var'; + +.van-divider { + display: flex; + align-items: center; + margin: @divider-margin; + color: @divider-text-color; + font-size: @divider-font-size; + line-height: @divider-line-height; + border-color: @divider-border-color; + border-style: solid; + border-width: 0; + + &::before, + &::after { + display: block; + flex: 1; + box-sizing: border-box; + height: 1px; + border-color: inherit; + border-style: inherit; + border-width: 1px 0 0; + } + + &::before { + content: ''; + } + + &--hairline { + &::before, + &::after { + transform: scaleY(.5); + } + } + + &--dashed { + border-style: dashed; + } + + &--content-center, + &--content-left, + &--content-right { + &::before { + margin-right: @divider-content-padding; + } + + &::after { + margin-left: @divider-content-padding; + content: ''; + } + } + + &--content-left { + &::before { + max-width: @divider-content-left-width; + } + } + + &--content-right { + &::after { + max-width: @divider-content-right-width; + } + } +} diff --git a/src/divider/index.tsx b/src/divider/index.tsx new file mode 100644 index 000000000..26b7271c1 --- /dev/null +++ b/src/divider/index.tsx @@ -0,0 +1,50 @@ +import { createNamespace } from '../utils'; +import { inherit } from '../utils/functional'; + +// Types +import { CreateElement, RenderContext } from 'vue/types'; +import { DefaultSlots } from '../utils/types'; + +export type DividerProps = { + dashed?: boolean; + hairline: boolean; + borderColor?: string; + contentPosition: 'left' | 'center' | 'right'; +}; + +const [createComponent, bem] = createNamespace('divider'); + +function Divider( + h: CreateElement, + props: DividerProps, + slots: DefaultSlots, + ctx: RenderContext +) { + return ( +
+ {slots.default && slots.default()} +
+ ); +} + +Divider.props = { + dashed: Boolean, + hairline: { + type: Boolean, + default: true + }, + contentPosition: { + type: String, + default: 'center' + } +}; + +export default createComponent(Divider); diff --git a/src/divider/test/__snapshots__/demo.spec.js.snap b/src/divider/test/__snapshots__/demo.spec.js.snap new file mode 100644 index 000000000..db3ddf077 --- /dev/null +++ b/src/divider/test/__snapshots__/demo.spec.js.snap @@ -0,0 +1,32 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders demo correctly 1`] = ` +
+
+
+
+
+
+ 文本 +
+
+
+
+ 文本 +
+
+ 文本 +
+
+
+
+ 文本 +
+
+
+
+ 文本 +
+
+
+`; diff --git a/src/divider/test/demo.spec.js b/src/divider/test/demo.spec.js new file mode 100644 index 000000000..d647cfabc --- /dev/null +++ b/src/divider/test/demo.spec.js @@ -0,0 +1,4 @@ +import Demo from '../demo'; +import demoTest from '../../../test/demo-test'; + +demoTest(Demo); diff --git a/src/index.less b/src/index.less index 745413ffc..4b58c1138 100644 --- a/src/index.less +++ b/src/index.less @@ -13,6 +13,7 @@ @import './image/index'; @import './circle/index'; @import './collapse-item/index'; +@import './divider/index'; @import './list/index'; @import './nav-bar/index'; @import './notice-bar/index'; diff --git a/src/index.ts b/src/index.ts index a86e425a4..74c5564d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,6 +23,7 @@ import CouponCell from './coupon-cell'; import CouponList from './coupon-list'; import DatetimePicker from './datetime-picker'; import Dialog from './dialog'; +import Divider from './divider'; import DropdownItem from './dropdown-item'; import DropdownMenu from './dropdown-menu'; import Field from './field'; @@ -111,6 +112,7 @@ const components = [ CouponList, DatetimePicker, Dialog, + Divider, DropdownItem, DropdownMenu, Field, @@ -204,6 +206,7 @@ export { CouponList, DatetimePicker, Dialog, + Divider, DropdownItem, DropdownMenu, Field, diff --git a/src/style/var.less b/src/style/var.less index 3b14afcb4..b2746bfcc 100644 --- a/src/style/var.less +++ b/src/style/var.less @@ -213,6 +213,16 @@ @dialog-has-title-message-padding-top: 12px; @dialog-confirm-button-text-color: @blue; +// Divider +@divider-margin: 15px 0; +@divider-text-color: @gray-dark; +@divider-font-size: 14px; +@divider-line-height: 24px; +@divider-border-color: @border-color; +@divider-content-padding: 15px; +@divider-content-left-width: 10%; +@divider-content-right-width: 10%; + // DropdownMenu @dropdown-menu-height: 50px; @dropdown-menu-background-color: @white; diff --git a/types/index.d.ts b/types/index.d.ts index 796475a9b..83929b247 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -17,6 +17,7 @@ export class Button extends VanComponent {} export class Card extends VanComponent {} export class Cell extends VanComponent {} export class CellGroup extends VanComponent {} +export class Divider extends VanComponent {} export class SwipeCell extends VanComponent {} export class Checkbox extends VanComponent {} export class CheckboxGroup extends VanComponent {}