Skip to content

Commit 2da36c6

Browse files
committed
add mode options in Demo
1 parent 0c56f16 commit 2da36c6

File tree

5 files changed

+114
-19
lines changed

5 files changed

+114
-19
lines changed

demo/index.less

+25-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
body {
77
font-size: 16px;
8+
overflow: hidden;
89
}
910

1011
ul, li {
@@ -59,8 +60,14 @@ ul, li {
5960

6061
.img-list {
6162
display: flex;
62-
width: 100%;
63+
width: 640px;
64+
height: 500px;
65+
margin: 0 auto;
6366
justify-content: center;
67+
68+
&.hide {
69+
display: none;
70+
}
6471
}
6572

6673
@imgItemWidth: 150px;
@@ -69,7 +76,7 @@ ul, li {
6976
.img-item {
7077
width: @imgItemWidth;
7178
height: @imgItemWidth;
72-
padding: 2px;
79+
padding: 1px;
7380
}
7481

7582
.img-item > img {
@@ -90,4 +97,20 @@ ul, li {
9097
}
9198
.signature {
9299
color: white;
100+
}
101+
.container {
102+
position: relative;
103+
}
104+
.inline-container {
105+
display: none;
106+
width: 600px;
107+
height: 400px;
108+
margin: 0 auto;
109+
110+
&.show {
111+
display: block;
112+
}
113+
}
114+
.options-list {
115+
margin-top: 12px;
93116
}

demo/index.tsx

+76-16
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,42 @@ const img3 = require('./images/tibet-6.jpg');
77
const img4 = require('./images/image4.jpg');
88
const forkImg = require('./images/fork_me_ribbon.svg');
99
import './index.less';
10+
import classNames from 'classnames';
11+
import { Row, Col, Button } from 'antd';
12+
const ButtonGroup = Button.Group;
13+
14+
interface State {
15+
visible: boolean;
16+
activeIndex: number;
17+
mode: 'modal' | 'inline';
18+
}
19+
20+
class App extends React.Component<any, Partial<State>> {
21+
container: HTMLDivElement;
1022

11-
class App extends React.Component<any, any> {
1223
constructor() {
1324
super();
1425

1526
this.state = {
1627
visible: false,
1728
activeIndex: 0,
29+
mode: 'modal',
1830
};
1931
}
2032

33+
handleChangeModal = (e) => {
34+
this.setState({
35+
mode: 'modal',
36+
});
37+
}
38+
39+
handleChangeInline = (e) => {
40+
this.setState({
41+
mode: 'inline',
42+
visible: true,
43+
});
44+
}
45+
2146
render() {
2247
let images = [{
2348
src: img,
@@ -33,12 +58,22 @@ class App extends React.Component<any, any> {
3358
alt: '',
3459
}];
3560

61+
let inline = this.state.mode === 'inline';
62+
63+
let inlineContainerClass = classNames('inline-container', {
64+
show: this.state.visible && inline,
65+
});
66+
67+
let imgListClass = classNames('img-list', {
68+
hide: this.state.visible && inline,
69+
});
70+
3671
return (
3772
<div>
3873
<nav className="navbar navbar-fixed-top">
3974
<div className="container-fluid">
4075
<div className="navbar-brand">
41-
<a>react-viewer</a>
76+
<p>react-viewer</p>
4277
</div>
4378
</div>
4479
</nav>
@@ -47,26 +82,51 @@ class App extends React.Component<any, any> {
4782
</a>
4883
<div className="container">
4984
<h1 className="title">Demo</h1>
50-
<div className="img-list">
51-
{images.map((item, index) => {
52-
return (
53-
<div key={index.toString()} className="img-item">
54-
<img src={item.src} onClick={() => {
55-
this.setState({
56-
visible: true,
57-
activeIndex: index,
58-
});
59-
}}/>
60-
</div>
61-
);
62-
})}
63-
</div>
85+
<Row>
86+
<Col span={6}>
87+
<h2>Options</h2>
88+
<div className="options-list">
89+
<ButtonGroup>
90+
<Button
91+
type={inline ? null : 'primary'}
92+
onClick={this.handleChangeModal}
93+
>
94+
Modal mode
95+
</Button>
96+
<Button
97+
type={inline ? 'primary' : null}
98+
onClick={this.handleChangeInline}
99+
>
100+
Inline mode
101+
</Button>
102+
</ButtonGroup>
103+
</div>
104+
</Col>
105+
<Col span={12}>
106+
<div className={imgListClass}>
107+
{images.map((item, index) => {
108+
return (
109+
<div key={index.toString()} className="img-item">
110+
<img src={item.src} onClick={() => {
111+
this.setState({
112+
visible: true,
113+
activeIndex: index,
114+
});
115+
}}/>
116+
</div>
117+
);
118+
})}
119+
</div>
120+
<div className={inlineContainerClass} ref={ref => {this.container = ref;}}></div>
121+
</Col>
122+
</Row>
64123
<Viewer
65124
visible={this.state.visible}
66125
onClose={() => { this.setState({ visible: false }); } }
67126
images={images}
68127
activeIndex={this.state.activeIndex}
69128
attribute={false}
129+
container={inline ? this.container : null}
70130
/>
71131
</div>
72132
<div className="footer">

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@
5656
"typescript": "^2.1.4",
5757
"webpack": "^1.13.2"
5858
},
59-
"dependencies": {},
59+
"dependencies": {
60+
"antd": "^2.8.3",
61+
"babel-plugin-import": "^1.1.1",
62+
"classnames": "^2.2.5"
63+
},
6064
"pre-commit": [
6165
"lint"
6266
]

webpack.config.doc.js

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ var conf = {
1313
}
1414

1515
module.exports = function (webpackConfig) {
16+
webpackConfig.babel.plugins.push(['import', {
17+
libraryName: 'antd',
18+
style: true,
19+
}]);
1620
webpackConfig.entry = {
1721
index: './demo/index.tsx',
1822
};

webpack.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ var conf = {
1313
}
1414

1515
module.exports = function (webpackConfig) {
16+
webpackConfig.babel.plugins.push(['import', {
17+
libraryName: 'antd',
18+
style: true,
19+
}]);
1620
webpackConfig.entry = {
1721
index: './demo/index.tsx',
1822
};

0 commit comments

Comments
 (0)