@@ -12,6 +12,7 @@ import {
12
12
getOtherDirection ,
13
13
getPathToCorner ,
14
14
Mosaic ,
15
+ MosaicBranch ,
15
16
MosaicDirection ,
16
17
MosaicNode ,
17
18
MosaicParent ,
@@ -25,6 +26,7 @@ import { CloseAdditionalControlsButton } from './CloseAdditionalControlsButton';
25
26
import '@blueprintjs/core/lib/css/blueprint.css' ;
26
27
import '@blueprintjs/icons/lib/css/blueprint-icons.css' ;
27
28
import '../styles/index.less' ;
29
+ import './carbon.less' ;
28
30
import './example.less' ;
29
31
30
32
// tslint:disable no-console
@@ -34,8 +36,6 @@ const gitHubLogo = require('./GitHub-Mark-Light-32px.png');
34
36
// tslint:disable-next-line no-var-requires
35
37
const { version } = require ( '../package.json' ) ;
36
38
37
- let windowCount = 3 ;
38
-
39
39
export const THEMES = {
40
40
[ 'Blueprint' ] : 'mosaic-blueprint-theme' ,
41
41
[ 'Blueprint Dark' ] : classNames ( 'mosaic-blueprint-theme' , Classes . DARK ) ,
@@ -69,27 +69,16 @@ export class ExampleApp extends React.PureComponent<{}, ExampleAppState> {
69
69
} ;
70
70
71
71
render ( ) {
72
+ const totalWindowCount = getLeaves ( this . state . currentNode ) . length ;
72
73
return (
73
74
< React . StrictMode >
74
75
< div className = "react-mosaic-example-app" >
75
76
{ this . renderNavBar ( ) }
76
77
< Mosaic < number >
77
78
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 } />
91
80
) }
92
- zeroStateView = { < MosaicZeroState createNode = { this . createNode } /> }
81
+ zeroStateView = { < MosaicZeroState createNode = { ( ) => totalWindowCount + 1 } /> }
93
82
value = { this . state . currentNode }
94
83
onChange = { this . onChange }
95
84
onRelease = { this . onRelease }
@@ -109,8 +98,6 @@ export class ExampleApp extends React.PureComponent<{}, ExampleAppState> {
109
98
console . log ( 'Mosaic.onRelease():' , currentNode ) ;
110
99
} ;
111
100
112
- private createNode = ( ) => ++ windowCount ;
113
-
114
101
private autoArrange = ( ) => {
115
102
const leaves = getLeaves ( this . state . currentNode ) ;
116
103
@@ -121,6 +108,7 @@ export class ExampleApp extends React.PureComponent<{}, ExampleAppState> {
121
108
122
109
private addToTopRight = ( ) => {
123
110
let { currentNode } = this . state ;
111
+ const totalWindowCount = getLeaves ( currentNode ) . length ;
124
112
if ( currentNode ) {
125
113
const path = getPathToCorner ( currentNode , Corner . TOP_RIGHT ) ;
126
114
const parent = getNodeAtPath ( currentNode , dropRight ( path ) ) as MosaicParent < number > ;
@@ -131,9 +119,9 @@ export class ExampleApp extends React.PureComponent<{}, ExampleAppState> {
131
119
let second : MosaicNode < number > ;
132
120
if ( direction === 'row' ) {
133
121
first = destination ;
134
- second = ++ windowCount ;
122
+ second = totalWindowCount + 1 ;
135
123
} else {
136
- first = ++ windowCount ;
124
+ first = totalWindowCount + 1 ;
137
125
second = destination ;
138
126
}
139
127
@@ -150,7 +138,7 @@ export class ExampleApp extends React.PureComponent<{}, ExampleAppState> {
150
138
} ,
151
139
] ) ;
152
140
} else {
153
- currentNode = ++ windowCount ;
141
+ currentNode = totalWindowCount + 1 ;
154
142
}
155
143
156
144
this . setState ( { currentNode } ) ;
@@ -198,3 +186,44 @@ export class ExampleApp extends React.PureComponent<{}, ExampleAppState> {
198
186
) ;
199
187
}
200
188
}
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
+ } ;
0 commit comments