Skip to content

Commit 79c5d55

Browse files
committed
feat: Add noScroll props.
1 parent 494b135 commit 79c5d55

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Demo extends React.Component {
5353
### Props
5454

5555
```ts
56-
export interface ICodePreviewProps {
56+
ICodePreviewProps extends ISplitProps {
5757
prefixCls?: string;
5858
style?: React.CSSProperties;
5959
/**
@@ -80,6 +80,10 @@ export interface ICodePreviewProps {
8080
* Whether to display the preview interface.
8181
*/
8282
noPreview?: boolean;
83+
/**
84+
* Preview area does not display scroll bars
85+
*/
86+
noScroll?: boolean;
8387
/**
8488
* Dependent component
8589
*/

src/index.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
margin-bottom: 16px;
1111
background-color: #fff;
1212
max-height: 420px;
13+
min-height: 12px;
14+
&-noScroll {
15+
max-height: initial;
16+
}
1317
&-bordered {
1418
box-shadow: 0 0 0 1px rgba(16, 22, 26, 0.1), 0 0 0 rgba(16, 22, 26, 0), 0 1px 1px rgba(16, 22, 26, 0.2);
1519
}

src/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export interface ICodePreviewProps extends ISplitProps {
3737
* Whether to display the preview interface.
3838
*/
3939
noPreview?: boolean;
40+
/**
41+
* Preview area does not display scroll bars
42+
*/
43+
noScroll?: boolean;
4044
/**
4145
* Dependent component
4246
*/
@@ -143,13 +147,14 @@ export default class CodePreview extends React.PureComponent<ICodePreviewProps,
143147
});
144148
}
145149
public render() {
146-
const { style, prefixCls, className, code, dependencies, bordered, noCode, noPreview, bgWhite, ...otherProps } = this.props;
150+
const { style, prefixCls, className, code, dependencies, bordered, noCode, noPreview, noScroll, bgWhite, ...otherProps } = this.props;
147151
const isOneItem = (!noCode && !noPreview) ? false : (!noCode || !noPreview);
148152
let visiable = this.state.width === 1 ? false : [isOneItem ? 1 : 2];
149153
return (
150154
<Split
151155
visiable={visiable}
152156
className={classnames(className, prefixCls, {
157+
[`${prefixCls}-noScroll`]: noScroll,
153158
[`${prefixCls}-OneItem`]: isOneItem,
154159
[`${prefixCls}-bordered`]: bordered,
155160
[`${prefixCls}-fullScreen`]: this.state.fullScreen,

website/App.tsx

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import React from 'react';
22
import { Switch, Divider, Button } from 'uiw';
33
import Markdown from './Markdown';
44
import GithubCorner from './GithubCorner';
5-
import CodePreview from '../src';
65
import DocumentStr from '../README.md'; // @ts-ignore
6+
import CodePreview from '../src';
77
import styles from './App.module.less';
88

99
const code = `import { Button, Divider, Icon } from 'uiw';
1010
1111
ReactDOM.render(
1212
<div>
1313
<Button type="primary">主要按钮</Button>
14+
<Button type="dark">暗按钮</Button><br /><br /><br /><br /><br /><br />
1415
<Button type="dark">暗按钮</Button>
1516
</div>,
1617
_mount_
@@ -20,14 +21,18 @@ ReactDOM.render(
2021
interface IAppState {
2122
bgWhite: boolean;
2223
noCode: boolean;
24+
noScroll: boolean;
2325
noPreview: boolean;
26+
bordered: boolean;
2427
}
2528

2629
export default class App extends React.PureComponent<{}, IAppState> {
2730
public state = {
2831
bgWhite: false,
2932
noCode: false,
33+
noScroll: false,
3034
noPreview: false,
35+
bordered: true,
3136
}
3237
private handleChange(keyName: string,e: React.ChangeEvent<HTMLInputElement>) {
3338
const state = { ...this.state,[`${keyName}`]: e.target.checked }
@@ -42,8 +47,9 @@ export default class App extends React.PureComponent<{}, IAppState> {
4247
<h1 className={styles.title}>React Code Preview</h1>
4348
<CodePreview
4449
code={code}
45-
// style={{ maxHeight: 230 }}
4650
dependencies={{ Button }}
51+
bordered={this.state.bordered}
52+
noScroll={this.state.noScroll}
4753
bgWhite={this.state.bgWhite}
4854
noCode={this.state.noCode}
4955
noPreview={this.state.noPreview}
@@ -57,25 +63,43 @@ export default class App extends React.PureComponent<{}, IAppState> {
5763
checked={this.state.bgWhite}
5864
onChange={this.handleChange.bind(this, 'bgWhite')}
5965
>
60-
背景 `bgWhite`
66+
背景 `bgWhite={this.state.bgWhite.toString()}`
6167
</Switch>
62-
<Divider type="vertical" />
68+
<br />
6369
<Switch
6470
data-checked="显示"
6571
data-unchecked="隐藏"
6672
checked={this.state.noCode}
6773
onChange={this.handleChange.bind(this, 'noCode')}
6874
>
69-
是否显示代码 `noCode`
75+
是否显示代码 `noCode={this.state.noCode.toString()}`
7076
</Switch>
71-
<Divider type="vertical" />
77+
<br />
7278
<Switch
7379
data-checked="显示"
7480
data-unchecked="隐藏"
7581
checked={this.state.noPreview}
7682
onChange={this.handleChange.bind(this, 'noPreview')}
7783
>
78-
是否显示实例预览 `noPreview`
84+
是否显示实例预览 `noPreview={this.state.noPreview.toString()}`
85+
</Switch>
86+
<br />
87+
<Switch
88+
data-checked="显示"
89+
data-unchecked="隐藏"
90+
checked={this.state.noScroll}
91+
onChange={this.handleChange.bind(this, 'noScroll')}
92+
>
93+
是否显示滚动条 `noScroll={this.state.noScroll.toString()}`
94+
</Switch>
95+
<br />
96+
<Switch
97+
data-checked="显示"
98+
data-unchecked="隐藏"
99+
checked={this.state.bordered}
100+
onChange={this.handleChange.bind(this, 'bordered')}
101+
>
102+
是否显示边框 `bordered={this.state.bordered.toString()}`
79103
</Switch>
80104
</div>
81105
<Markdown source={DocumentStrSource} />

0 commit comments

Comments
 (0)