Skip to content

Commit 61d3670

Browse files
committed
feat: Add renderBar props. #100
1 parent de7e00c commit 61d3670

File tree

2 files changed

+78
-19
lines changed

2 files changed

+78
-19
lines changed

README.md

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,73 @@ class Demo extends React.Component {
375375
ReactDOM.render(<Demo />, _mount_);
376376
```
377377

378+
### 支持自定义拖拽工具栏
379+
380+
<!--rehype:bgWhite=true&codeSandbox=true&codePen=true-->
381+
```jsx
382+
import ReactDOM from 'react-dom';
383+
import Split from '@uiw/react-split';
384+
385+
const Demo = () => (
386+
<div>
387+
<Split
388+
renderBar={({ onMouseDown, ...props }) => {
389+
return (
390+
<div {...props} style={{ boxShadow: 'none', background: 'transparent' }}>
391+
<div onMouseDown={onMouseDown} style={{ backgroundColor: '#ff000057', boxShadow: 'none' }} />
392+
</div>
393+
);
394+
}}
395+
style={{ height: 100, border: '1px solid #d5d5d5', borderRadius: 3 }}
396+
>
397+
<div style={{ minWidth: 60 }}>
398+
test
399+
</div>
400+
<div style={{ minWidth: 80, flex: 1 }}>
401+
Right Pane
402+
</div>
403+
</Split>
404+
</div>
405+
);
406+
ReactDOM.render(<Demo />, _mount_);
407+
```
408+
409+
378410
## Props
379411

380-
| 参数 | 说明 | 类型 | 默认值 |
381-
|--------- |-------- |--------- |-------- |
382-
| visiable | 设置拖拽的工具条,是否可见 | Boolean/Array | `true` |
383-
| disable | 设置拖拽的工具条,禁用 | Boolean/Array | - |
384-
| lineBar | 设置拖拽的工具条,为线条样式。 | Boolean | - |
385-
| mode | 类型,可选值为 `horizontal``vertical` | String | `horizontal` |
386-
| onDragging | 拖拽宽度/高度变化回调函数,宽度或者高度根据 mode 参数来确定 | Function(prePaneSize,<br />nextPaneSize,<br />nextPaneNumber) | - |
387-
| onDragEnd | 拖拽结束的回调函数 | Function(prePaneSize,<br />nextPaneSize,<br />nextPaneNumber) | - |
412+
```ts
413+
export interface SplitProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onDragEnd'> {
414+
style?: React.CSSProperties;
415+
className?: string;
416+
prefixCls?: string;
417+
/**
418+
* 拖拽宽度/高度变化回调函数,宽度或者高度根据 mode 参数来确定
419+
*/
420+
onDragging?: (preSize: number, nextSize: number, paneNumber: number) => void;
421+
/**
422+
* 拖拽结束的回调函数
423+
*/
424+
onDragEnd?: (preSize: number, nextSize: number, paneNumber: number) => void;
425+
/** 支持自定义拖拽工具栏 */
426+
renderBar?: (props: React.HTMLAttributes<HTMLDivElement>) => JSX.Element;
427+
/**
428+
* 设置拖拽的工具条,为线条样式。
429+
*/
430+
lineBar?: boolean;
431+
/**
432+
* 设置拖拽的工具条,是否可见
433+
*/
434+
visiable?: boolean | number[];
435+
/**
436+
* 设置拖拽的工具条,禁用
437+
*/
438+
disable?: boolean | number[];
439+
/**
440+
* 类型,可选值为 `horizontal` 或 `vertical`
441+
*/
442+
mode?: 'horizontal' | 'vertical';
443+
}
444+
```
388445

389446
## Development
390447

src/index.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@ export interface SplitProps extends Omit<React.HTMLAttributes<HTMLDivElement>,
99
* 拖拽宽度/高度变化回调函数,宽度或者高度根据 mode 参数来确定
1010
*/
1111
onDragging?: (preSize: number, nextSize: number, paneNumber: number) => void;
12-
/**
13-
* 拖拽结束的回调函数
14-
*/
12+
/** 拖拽结束的回调函数 */
1513
onDragEnd?: (preSize: number, nextSize: number, paneNumber: number) => void;
16-
/**
17-
* 设置拖拽的工具条,为线条样式。
18-
*/
14+
/** 支持自定义拖拽工具栏 */
15+
renderBar?: (props: React.HTMLAttributes<HTMLDivElement>) => JSX.Element;
16+
/** 设置拖拽的工具条,为线条样式。 */
1917
lineBar?: boolean;
20-
/**
21-
* 设置拖拽的工具条,是否可见
22-
*/
18+
/** 设置拖拽的工具条,是否可见 */
2319
visiable?: boolean | number[];
2420
/**
2521
* 设置拖拽的工具条,禁用
@@ -146,7 +142,7 @@ export default class Split extends React.Component<SplitProps, SplitState> {
146142
this.setState({ dragging: false });
147143
}
148144
render() {
149-
const { prefixCls, className, children, mode, visiable, lineBar, disable, onDragEnd, onDragging, ...other } = this.props;
145+
const { prefixCls, className, children, mode, visiable, renderBar, lineBar, disable, onDragEnd, onDragging, ...other } = this.props;
150146
const { dragging } = this.state;
151147
const cls = [prefixCls, className, `${prefixCls}-${mode}`, dragging ? 'dragging' : null].filter(Boolean)
152148
.join(' ')
@@ -174,9 +170,15 @@ export default class Split extends React.Component<SplitProps, SplitState> {
174170
.join(' ')
175171
.trim();
176172
}
173+
let BarCom = null;
174+
if (idx !== 0 && visiableBar && renderBar) {
175+
BarCom = renderBar({ ...barProps, onMouseDown: this.onMouseDown.bind(this, idx + 1) });
176+
} else if (idx !== 0 && visiableBar) {
177+
BarCom = React.createElement('div', { ...barProps }, <div onMouseDown={this.onMouseDown.bind(this, idx + 1)} />)
178+
}
177179
return (
178180
<React.Fragment>
179-
{idx !== 0 && visiableBar && React.createElement('div', { ...barProps }, <div onMouseDown={this.onMouseDown.bind(this, idx + 1)} />)}
181+
{BarCom}
180182
{React.cloneElement(element, { ...props })}
181183
</React.Fragment>
182184
);

0 commit comments

Comments
 (0)