Skip to content

Commit

Permalink
feat: divider组件新增props (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
vickyYE authored Jul 26, 2022
1 parent e4516de commit e5d8da4
Show file tree
Hide file tree
Showing 7 changed files with 427 additions and 102 deletions.
53 changes: 26 additions & 27 deletions src/packages/divider/demo.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
import React from 'react'
import { Divider } from './divider'
import { Cell } from '../cell/cell'

const DividerDemo = () => {
return (
<>
<div className="demo">
<h2>基础用法</h2>
<Cell>
<Divider />
</Cell>
<Divider />
<h2>展示文本</h2>
<Cell>
<Divider>文本</Divider>
</Cell>
<Divider>文本</Divider>
<h2>内容位置</h2>
<Cell>
<Divider contentPosition="left">文本</Divider>
</Cell>
<Cell>
<Divider contentPosition="right">文本</Divider>
</Cell>
<Divider contentPosition="left">文本</Divider>
<Divider contentPosition="right">文本</Divider>
<h2>虚线</h2>
<Cell>
<Divider dashed>文本</Divider>
</Cell>
<Divider dashed>文本</Divider>
<h2>自定义样式</h2>
<Cell>
<Divider
styles={{
color: '#1989fa',
borderColor: '#1989fa',
padding: '0 16px',
}}
>
文本
</Divider>
</Cell>
<Divider
styles={{
color: '#1989fa',
borderColor: '#1989fa',
padding: '0 16px',
}}
>
文本
</Divider>
<h2>垂直分割线</h2>
<div style={{ fontSize: '14px', marginLeft: '27px', color: '#909ca4' }}>
文本
<Divider direction="vertical" />
<a href="#/Divider" style={{ color: '#1989fa' }}>
链接
</a>
<Divider direction="vertical" />
<a href="#/Divider" style={{ color: '#1989fa' }}>
链接
</a>
</div>
</div>
</>
)
Expand Down
25 changes: 17 additions & 8 deletions src/packages/divider/divider.scss
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
.nut-divider {
display: flex;
align-items: center;
font-size: 14px;
color: #909ca4;
margin: 8px 0;
width: 100%;
font-size: $divider-text-font-size;
color: $divider-text-color;
margin: $divider-margin;
// width: 100%;

&::before,
&::after {
content: '';
border: 1px solid currentColor;
border-width: 1px 0 0;
border: $divider-line-height solid currentColor;
border-width: $divider-line-height 0 0;
height: $divider-line-height;
flex: 1;
}

&.nut-divider__center,
&.nut-divider__left,
&.nut-divider__right {
&::before {
margin-right: 8px;
margin-right: $divider-before-margin-right;
}

&::after {
margin-left: 8px;
margin-left: $divider-after-margin-left;
}
}

Expand Down Expand Up @@ -51,4 +52,12 @@
transform: scaleY(0.5);
}
}
&.nut-divider__vertical {
position: relative;
top: $divider-vertical-top;
display: inline-block;
height: $divider-vertical-height;
border-left: 1px solid $divider-vertical-border-left;
margin: $divider-vertical-margin;
}
}
38 changes: 28 additions & 10 deletions src/packages/divider/divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,52 @@ import React, { FunctionComponent } from 'react'
import classNames from 'classnames'
import bem from '@/utils/bem'

export type ContentPositionType = 'left' | 'center' | 'right'
export type DirectionType = 'horizontal' | 'vertical'
export interface DividerProps {
contentPosition: string
contentPosition: ContentPositionType
dashed: boolean
hairline: boolean
styles?: React.CSSProperties
className?: string
direction?: DirectionType
}
const defaultProps = {
contentPosition: 'center',
dashed: false,
hairline: true,
direction: 'horizontal',
} as DividerProps
export const Divider: FunctionComponent<
Partial<DividerProps> & React.HTMLAttributes<HTMLDivElement>
> = (props) => {
const { children, contentPosition, dashed, hairline, styles, className } = {
const {
children,
contentPosition,
dashed,
hairline,
styles,
className,
direction,
} = {
...defaultProps,
...props,
}
const dividerBem = bem('divider')
const classes = classNames({
[dividerBem()]: true,
[dividerBem('center')]: children,
[dividerBem('left')]: contentPosition === 'left',
[dividerBem('right')]: contentPosition === 'right',
[dividerBem('dashed')]: dashed,
[dividerBem('hairline')]: hairline,
})
const classes =
direction === 'horizontal'
? classNames({
[dividerBem()]: true,
[dividerBem('center')]: children,
[dividerBem('left')]: contentPosition === 'left',
[dividerBem('right')]: contentPosition === 'right',
[dividerBem('dashed')]: dashed,
[dividerBem('hairline')]: hairline,
})
: classNames({
[dividerBem()]: true,
[dividerBem('vertical')]: direction === 'vertical',
})
return (
<div className={`${classes} ${className || ''}`} style={styles}>
{children}
Expand Down
160 changes: 127 additions & 33 deletions src/packages/divider/doc.en-US.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,165 @@
# Divider 分割线
# Divider

### 介绍
### Intro

用于将内容分隔为多个区域。
Separate content into multiple areas.

### 安装
### Install

```js
import { Divider } from '@nutui/nutui-react';
```

## 代码演示
### Basic Usage

### 基础用法
Default render one horizontal divider line.

默认渲染一条水平分割线。
:::demo

```jsx
<Divider />
```tsx
import React from "react";
import { Divider } from '@nutui/nutui-react';

const App = () => {
return (
<>
<Divider />
</>
);
};
export default App;
```
:::


### With Text

### 展示文本
Insert text into divider with default slot.

通过插槽在可以分割线中间插入内容。
:::demo

```jsx
<Divider>文本</Divider>
```tsx
import React from "react";
import { Divider } from '@nutui/nutui-react';

const App = () => {
return (
<>
<Divider>Text</Divider>
</>
);
};
export default App;
```
:::


### 内容位置
### Content Position

通过 contentPosition 指定内容所在位置。
Set Content Position with `contentPosition` attribute.

```jsx
<Divider contentPosition="left">文本</Divider>
<Divider contentPosition="right">文本</Divider>
:::demo

```tsx
import React from "react";
import { Divider } from '@nutui/nutui-react';

const App = () => {
return (
<>
<Divider contentPosition="left">Text</Divider>
<Divider contentPosition="right">Text</Divider>
</>
);
};
export default App;
```
:::

### 虚线

添加 dashed 属性使分割线渲染为虚线。
### Dashed

```jsx
<Divider dashed>文本</Divider>
Render dashed divider line with `dashed` attribute.

:::demo

```tsx
import React from "react";
import { Divider } from '@nutui/nutui-react';

const App = () => {
return (
<>
<Divider dashed>Text</Divider>
</>
);
};
export default App;
```
:::


### Custom Style

User can custom divider style with `styles` attribute.

:::demo

```tsx
import React from "react";
import { Divider } from '@nutui/nutui-react';

const App = () => {
return (
<>
<Divider styles={{ color: '#1989fa', borderColor: '#1989fa', padding: '0 16px' }}>Text</Divider>
</>
);
};
export default App;
```
:::

### 自定义样式
### Vertical Divider

可以直接通过 styles 属性设置分割线的样式。
:::demo

```jsx
<Divider styles={{ color: '#1989fa', borderColor: '#1989fa', padding: '0 16px' }}>文本</Divider>
```tsx
import React from "react";
import { Divider } from '@nutui/nutui-react';

const App = () => {
return (
<>
<div>
文本
<Divider direction="vertical" />
<a href="#" style={{ color: '#1989fa' }}>Link</a>
<Divider direction="vertical" />
<a href="#" style={{ color: '#1989fa' }}>Link</a>
</div>
</>
);
};
export default App;
```
:::


## API

### Props

| 参数 | 说明 | 类型 | 默认值 |
| Attribute | Description | Type | Default |
| --------------- | ----------------------------- | ------- | ------ |
| dashed | 是否使用虚线 | Boolean | false |
| hairline | 是否使用 0.5px 线 | Boolean | true |
| contentPosition | 内容位置,可选值为 left right | String | center |
| styles | 修改自定义样式 | css | - |
| dashed | Whether to use dashed border | Boolean | false |
| hairline | Whether to use hairline | Boolean | true |
| contentPosition | Content position, can be set to left or right | String | center |
| styles | Modify custom styles | CSS | - |
| direction | The direction of divider, can be set to horizontal or vertical | String | 'horizontal' |

### Slots

| 名称 | 说明 |
| Name | Description |
| ------- | ---- |
| default | 内容 |
| default | Default slot |
Loading

0 comments on commit e5d8da4

Please sign in to comment.