Skip to content

Commit 5bb9884

Browse files
committed
Trial carbon ads in demo site
1 parent 87bbbb9 commit 5bb9884

File tree

8 files changed

+135
-37
lines changed

8 files changed

+135
-37
lines changed

demo/ExampleApp.tsx

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
getOtherDirection,
1313
getPathToCorner,
1414
Mosaic,
15+
MosaicBranch,
1516
MosaicDirection,
1617
MosaicNode,
1718
MosaicParent,
@@ -25,6 +26,7 @@ import { CloseAdditionalControlsButton } from './CloseAdditionalControlsButton';
2526
import '@blueprintjs/core/lib/css/blueprint.css';
2627
import '@blueprintjs/icons/lib/css/blueprint-icons.css';
2728
import '../styles/index.less';
29+
import './carbon.less';
2830
import './example.less';
2931

3032
// tslint:disable no-console
@@ -34,8 +36,6 @@ const gitHubLogo = require('./GitHub-Mark-Light-32px.png');
3436
// tslint:disable-next-line no-var-requires
3537
const { version } = require('../package.json');
3638

37-
let windowCount = 3;
38-
3939
export const THEMES = {
4040
['Blueprint']: 'mosaic-blueprint-theme',
4141
['Blueprint Dark']: classNames('mosaic-blueprint-theme', Classes.DARK),
@@ -69,27 +69,16 @@ export class ExampleApp extends React.PureComponent<{}, ExampleAppState> {
6969
};
7070

7171
render() {
72+
const totalWindowCount = getLeaves(this.state.currentNode).length;
7273
return (
7374
<React.StrictMode>
7475
<div className="react-mosaic-example-app">
7576
{this.renderNavBar()}
7677
<Mosaic<number>
7778
renderTile={(count, path) => (
78-
<MosaicWindow<number>
79-
additionalControls={count === 3 ? additionalControls : EMPTY_ARRAY}
80-
title={`Window ${count}`}
81-
createNode={this.createNode}
82-
path={path}
83-
onDragStart={() => console.log('MosaicWindow.onDragStart')}
84-
onDragEnd={(type) => console.log('MosaicWindow.onDragEnd', type)}
85-
renderToolbar={count === 2 ? () => <div className="toolbar-example">Custom Toolbar</div> : null}
86-
>
87-
<div className="example-window">
88-
<h1>{`Window ${count}`}</h1>
89-
</div>
90-
</MosaicWindow>
79+
<ExampleWindow count={count} path={path} totalWindowCount={totalWindowCount} />
9180
)}
92-
zeroStateView={<MosaicZeroState createNode={this.createNode} />}
81+
zeroStateView={<MosaicZeroState createNode={() => totalWindowCount + 1} />}
9382
value={this.state.currentNode}
9483
onChange={this.onChange}
9584
onRelease={this.onRelease}
@@ -109,8 +98,6 @@ export class ExampleApp extends React.PureComponent<{}, ExampleAppState> {
10998
console.log('Mosaic.onRelease():', currentNode);
11099
};
111100

112-
private createNode = () => ++windowCount;
113-
114101
private autoArrange = () => {
115102
const leaves = getLeaves(this.state.currentNode);
116103

@@ -121,6 +108,7 @@ export class ExampleApp extends React.PureComponent<{}, ExampleAppState> {
121108

122109
private addToTopRight = () => {
123110
let { currentNode } = this.state;
111+
const totalWindowCount = getLeaves(currentNode).length;
124112
if (currentNode) {
125113
const path = getPathToCorner(currentNode, Corner.TOP_RIGHT);
126114
const parent = getNodeAtPath(currentNode, dropRight(path)) as MosaicParent<number>;
@@ -131,9 +119,9 @@ export class ExampleApp extends React.PureComponent<{}, ExampleAppState> {
131119
let second: MosaicNode<number>;
132120
if (direction === 'row') {
133121
first = destination;
134-
second = ++windowCount;
122+
second = totalWindowCount + 1;
135123
} else {
136-
first = ++windowCount;
124+
first = totalWindowCount + 1;
137125
second = destination;
138126
}
139127

@@ -150,7 +138,7 @@ export class ExampleApp extends React.PureComponent<{}, ExampleAppState> {
150138
},
151139
]);
152140
} else {
153-
currentNode = ++windowCount;
141+
currentNode = totalWindowCount + 1;
154142
}
155143

156144
this.setState({ currentNode });
@@ -198,3 +186,44 @@ export class ExampleApp extends React.PureComponent<{}, ExampleAppState> {
198186
);
199187
}
200188
}
189+
190+
interface ExampleWindowProps {
191+
count: number;
192+
path: MosaicBranch[];
193+
totalWindowCount: number;
194+
}
195+
196+
const ExampleWindow = ({ count, path, totalWindowCount }: ExampleWindowProps) => {
197+
const adContainer = React.useRef<HTMLDivElement>(null);
198+
React.useEffect(() => {
199+
if (adContainer.current == null) {
200+
return;
201+
}
202+
203+
const script = document.createElement('script');
204+
205+
script.src = '//cdn.carbonads.com/carbon.js?serve=CEAIEK3E&placement=nomcoptergithubio';
206+
script.async = true;
207+
script.type = 'text/javascript';
208+
script.id = '_carbonads_js';
209+
210+
adContainer.current.appendChild(script);
211+
}, []);
212+
213+
return (
214+
<MosaicWindow<number>
215+
additionalControls={count === 3 ? additionalControls : EMPTY_ARRAY}
216+
title={`Window ${count}`}
217+
createNode={() => totalWindowCount + 1}
218+
path={path}
219+
onDragStart={() => console.log('MosaicWindow.onDragStart')}
220+
onDragEnd={(type) => console.log('MosaicWindow.onDragEnd', type)}
221+
renderToolbar={count === 2 ? () => <div className="toolbar-example">Custom Toolbar</div> : null}
222+
>
223+
<div className="example-window">
224+
<h1>{`Window ${count}`}</h1>
225+
{count === 3 && <div className="ad-container" ref={adContainer} />}
226+
</div>
227+
</MosaicWindow>
228+
);
229+
};

demo/carbon.less

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#carbonads * {
2+
margin: initial;
3+
padding: initial;
4+
}
5+
#carbonads {
6+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue',
7+
Helvetica, Arial, sans-serif;
8+
}
9+
#carbonads {
10+
display: flex;
11+
max-width: 330px;
12+
background-color: hsl(0, 0%, 98%);
13+
box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, 0.1);
14+
z-index: 100;
15+
}
16+
#carbonads a {
17+
color: inherit;
18+
text-decoration: none;
19+
}
20+
#carbonads a:hover {
21+
color: inherit;
22+
}
23+
#carbonads span {
24+
position: relative;
25+
display: block;
26+
overflow: hidden;
27+
}
28+
#carbonads .carbon-wrap {
29+
display: flex;
30+
}
31+
#carbonads .carbon-img {
32+
display: block;
33+
margin: 0;
34+
line-height: 1;
35+
}
36+
#carbonads .carbon-img img {
37+
display: block;
38+
}
39+
#carbonads .carbon-text {
40+
font-size: 13px;
41+
padding: 10px;
42+
margin-bottom: 16px;
43+
line-height: 1.5;
44+
text-align: left;
45+
}
46+
#carbonads .carbon-poweredby {
47+
display: block;
48+
padding: 6px 8px;
49+
background: #f1f1f2;
50+
text-align: center;
51+
text-transform: uppercase;
52+
letter-spacing: 0.5px;
53+
font-weight: 600;
54+
font-size: 8px;
55+
line-height: 1;
56+
border-top-left-radius: 3px;
57+
position: absolute;
58+
bottom: 0;
59+
right: 0;
60+
}

demo/example.less

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,16 @@ body {
6868
.example-window {
6969
height: 100%;
7070
padding: 20px;
71-
text-align: center;
71+
display: flex;
72+
align-items: center;
73+
flex-direction: column;
74+
75+
.ad-container {
76+
display: flex;
77+
justify-content: center;
78+
align-items: center;
79+
80+
flex: 1;
81+
height: 0;
82+
}
7283
}

docs/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/app.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!doctype html> <html> <head> <meta charset=utf-8> <meta http-equiv=X-UA-Compatible content="IE=edge"> <meta name=viewport content="width=device-width,initial-scale=1"> <title>React Mosaic</title> </head> <body> <div id=app></div> <script type="text/javascript" src="vendor.js"></script><script type="text/javascript" src="app.js"></script></body> </html>
1+
<!doctype html> <html> <head> <meta charset=utf-8 /> <meta http-equiv=X-UA-Compatible content="IE=edge"/> <meta name=viewport content="width=device-width,initial-scale=1"/> <title>React Mosaic</title> </head> <body> <div id=app></div> <script type="text/javascript" src="vendor.js"></script><script type="text/javascript" src="app.js"></script></body> </html>

docs/vendor.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webpack/index-template.html

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
<!--
2-
-->
31
<!DOCTYPE html>
42
<html>
5-
<head>
6-
<meta charset="utf-8">
7-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
8-
<meta name="viewport" content="width=device-width, initial-scale=1">
9-
<title>React Mosaic</title>
10-
</head>
11-
<body>
12-
<div id="app"></div>
13-
</body>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<title>React Mosaic</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
</body>
1412
</html>

0 commit comments

Comments
 (0)