Skip to content

Commit a4c1a17

Browse files
introduce basic docs layout and zoomable images
1 parent 51ec501 commit a4c1a17

19 files changed

Lines changed: 432 additions & 9 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function App() {
4141

4242
It will work with your build system, the language of your choice and style processing.
4343

44-
![screen example](img/screen-example.png)
44+
![screen example](documentation/rcv/static/screen-example.png)
4545

4646
# Demo functions
4747

documentation/rcv/package-lock.json

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

documentation/rcv/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
},
1414
"dependencies": {
1515
"gatsby": "^2.0.76",
16+
"marked": "^0.6.0",
17+
"prismjs": "^1.15.0",
1618
"react": "^16.5.1",
1719
"react-dom": "^16.5.1"
1820
},
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.centered {
2+
display: flex;
3+
align-items: center;
4+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import './Centered.css'
3+
4+
export function Centered({children}) {
5+
return (
6+
<div className="centered">
7+
{children}
8+
</div>
9+
)
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.image img {
2+
max-width: 100%;
3+
max-height: 100%;
4+
}
5+
6+
.image {
7+
height: 100%;
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react"
2+
3+
import {withPrefix} from 'gatsby'
4+
5+
import {Zoomable} from "./Zoomable";
6+
7+
import './Image.css'
8+
9+
export function Image({path, description}) {
10+
return (
11+
<Zoomable>
12+
<div className="image">
13+
<img src={withPrefix(path)} alt={description}/>
14+
</div>
15+
</Zoomable>
16+
)
17+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
body {
2+
margin: 0;
3+
padding: 0;
4+
font-family: Verdana, serif;
5+
6+
--rcv-doc-left-gap: 48px;
7+
}
8+
9+
.layout {
10+
display: grid;
11+
grid-template-rows: 56px 1fr;
12+
height: 100vh;
13+
}
14+
15+
.layout .tool-name {
16+
font-size: 18px;
17+
}
18+
19+
.layout .guide-label {
20+
color: #cccccc;
21+
font-size: 14px;
22+
margin-left: 16px;
23+
}
24+
25+
.layout .top-panel {
26+
display: flex;
27+
align-items: center;
28+
padding-left: var(--rcv-doc-left-gap);
29+
background-color: #5b6271;
30+
color: white;
31+
}
32+
33+
.layout .content-panel {
34+
padding-left: var(--rcv-doc-left-gap);
35+
overflow: auto;
36+
}
37+
38+
.layout .zoomed-in-overlay,
39+
.layout .zoomed-in-content {
40+
position: fixed;
41+
top: 0;
42+
right: 0;
43+
left: 0;
44+
bottom: 0;
45+
}
46+
47+
.layout .zoomed-in-overlay {
48+
background-color: #000;
49+
opacity: 0.5;
50+
z-index: 1000;
51+
}
52+
53+
.layout .zoomed-in-content {
54+
display: flex;
55+
align-items: center;
56+
justify-content: center;
57+
58+
opacity: 1;
59+
margin: 24px;
60+
61+
z-index: 1001;
62+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import React from 'react'
2+
3+
import {zoomListeners} from "./ZoomListeners";
4+
5+
import './Layout.css';
6+
7+
export class Layout extends React.Component {
8+
state = {
9+
zoomedIn: undefined
10+
}
11+
12+
render() {
13+
const {children} = this.props
14+
15+
return (
16+
<div className="layout">
17+
<div className="top-panel">
18+
<div className="tool-name">React Component Viewer</div>
19+
<div className="guide-label">guide</div>
20+
</div>
21+
22+
<div className="content-panel">
23+
{children}
24+
</div>
25+
26+
{this.renderZoomedIn()}
27+
</div>
28+
)
29+
}
30+
31+
renderZoomedIn() {
32+
const {zoomedIn} = this.state
33+
34+
if (!zoomedIn) {
35+
return null
36+
}
37+
38+
return (
39+
<>
40+
<div className="zoomed-in-overlay" onClick={this.onZoomOverlayClick}/>
41+
<div className="zoomed-in-content" onClick={this.onZoomOverlayClick}>
42+
{zoomedIn}
43+
</div>
44+
</>
45+
)
46+
}
47+
48+
onZoomOverlayClick = (e) => {
49+
console.log('onZoomOverlayClick')
50+
51+
e.preventDefault()
52+
this.removeZoom()
53+
}
54+
55+
onZoomIn = (rendered) => {
56+
this.setState({zoomedIn: rendered})
57+
}
58+
59+
onKeyDown = (e) => {
60+
if (e.code === 'Escape') {
61+
this.removeZoom()
62+
}
63+
}
64+
65+
removeZoom = () => {
66+
this.setState({zoomedIn: undefined})
67+
}
68+
69+
componentDidMount() {
70+
zoomListeners.addListener(this.onZoomIn)
71+
document.addEventListener('keydown', this.onKeyDown)
72+
}
73+
74+
componentWillUnmount() {
75+
zoomListeners.removeListener(this.onZoomIn)
76+
document.removeEventListener('keydown', this.onKeyDown)
77+
}
78+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as React from 'react'
2+
3+
import Prism from 'prismjs'
4+
5+
import 'prismjs/components/prism-typescript'
6+
import 'prismjs/plugins/line-highlight/prism-line-highlight'
7+
8+
import 'prismjs/themes/prism.css'
9+
import 'prismjs/plugins/line-highlight/prism-line-highlight.css'
10+
11+
const marked = require('marked')
12+
13+
export class MarkdownBlock extends React.Component {
14+
render() {
15+
const {markdown} = this.props
16+
17+
return (
18+
<div className="MarkdownBlock" dangerouslySetInnerHTML={{__html: htmlFromVarValue(markdown)}}/>
19+
)
20+
}
21+
22+
componentDidMount() {
23+
Prism.highlightAll()
24+
}
25+
26+
componentDidUpdate() {
27+
Prism.highlightAll()
28+
}
29+
}
30+
31+
export function htmlFromVarValue(value) {
32+
return marked(value.trim())
33+
}

0 commit comments

Comments
 (0)