Skip to content

Commit 624ff0d

Browse files
move prism local, and start vanillats
1 parent 2b1c45d commit 624ff0d

File tree

7 files changed

+153
-19
lines changed

7 files changed

+153
-19
lines changed

deploy.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env bash
2+
git checkout master
3+
npm run build-prod
24

35
exists=`git show-ref refs/heads/gh-pages`
4-
if ! [ -n "$exists" ]; then
5-
echo 'branch exists!'
6-
git checkout -b "gh-pages"
7-
else
8-
git checkout "gh-pages"
6+
if [ -n "$exists" ]; then
7+
git branch -D gh-pages
98
fi
9+
git branch -D gh-pages
1010

11-
git merge master
11+
git checkout --orphan gh-pages
1212
git add dist/* -f
13-
git commit -a -m 'build files'
14-
git push origin gh-pages
13+
git commit -m "build files"
14+
git push -f origin gh-pages
1515
git checkout master

examples/IComponent.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface IComponent {
2+
destroy: ()=>void
3+
show: ()=>void
4+
}

examples/SolarPopup.ts

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import {ModalBackground} from './ModalBackground'
2+
import {IComponent} from "vanilla-typescript"
3+
import {constants} from "./constants"
4+
import './SolarPopup.pcss'
5+
6+
/**
7+
* A Popup that can take any content
8+
*
9+
* Features
10+
* Closes in response to [ESC] keypress, submit events.
11+
* Adds modal background that fades in with CSS3 transitions
12+
* Popup itself slides in with CSS3 transitions
13+
*
14+
* @constructor
15+
*/
16+
export default class SolarPopup implements IComponent {
17+
destroyBoundWithThis = this.destroy.bind(this)
18+
modalBackground = new ModalBackground()
19+
private hostElement: HTMLElement
20+
private child: HTMLElement
21+
22+
constructor(child: HTMLElement) {
23+
this.child = child
24+
}
25+
26+
27+
/**
28+
* Shows
29+
* @param {Element} child we need to keep the reference to keep custom functionality in the child
30+
*/
31+
show() {
32+
33+
const tempElement:HTMLElement = document.createElement('DIV')
34+
35+
tempElement.innerHTML =
36+
`<article class='solar-popup' data-is-initialising="true">
37+
<a class='close'><!--&#x274c;-->&#x2716;</a>
38+
<div class="childContainer"></div>
39+
</article>`
40+
tempElement.querySelector(".childContainer").appendChild(this.child)
41+
42+
this.hostElement = <HTMLElement>tempElement.firstChild
43+
document.body.appendChild(this.hostElement)
44+
let currentWidth = window.getComputedStyle(document.querySelector("p"))
45+
46+
this.modalBackground.render()
47+
48+
setTimeout(() => {
49+
//this triggers a css change
50+
//let currentWidth = window.getComputedStyle(document.querySelector("p")) }, 50)
51+
this.hostElement.dataset["isInitialising"] = "false"
52+
})
53+
this.addListeners()
54+
}
55+
56+
addListeners() {
57+
const closeElement = this.hostElement.querySelector('a')
58+
closeElement.addEventListener('click', this.destroyBoundWithThis)
59+
this.hostElement.classList.remove('offscreen')
60+
61+
document.addEventListener('keyup', function (event) {
62+
if (event.keyCode === constants.KEYS.ESC) {
63+
this.destroyBoundWithThis()
64+
}
65+
}.bind(this))
66+
67+
this.hostElement.addEventListener('submit', function (event) {
68+
this.destroyBoundWithThis()
69+
event.preventDefault()
70+
}.bind(this))
71+
72+
73+
// handle the first child submit button click, close popup by default
74+
// this is a convention that gets popup to behave in sensible way
75+
const submitBtn = this.hostElement.querySelector('button[type="submit"]')
76+
if (submitBtn) {
77+
submitBtn.addEventListener("click", this.destroyBoundWithThis)
78+
}
79+
}
80+
81+
destroy() {
82+
//vistual indicator for this element and delegate to the modal
83+
this.hostElement.dataset["isDestructing"] = "true"
84+
this.modalBackground.destroy()
85+
setTimeout(function () {
86+
this.hostElement.parentElement.removeChild(this.hostElement)
87+
}.bind(this), constants.TRANSITION_TIMES)
88+
}
89+
}
90+
91+

index.html

-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
</head>
1111
<body>
1212
<div id="root"></div>
13-
<script src="https://cdn.jsdelivr.net/prism/1.3.0/prism.js" type="text/javascript"></script>
14-
<script src="https://cdn.jsdelivr.net/prism/1.3.0/components/prism-jsx.min.js" type="text/javascript"></script>
15-
<script src="https://cdn.jsdelivr.net/prism/1.3.0/components/prism-typescript.min.js" type="text/javascript"></script>
16-
<script src="https://cdn.jsdelivr.net/prism/1.3.0/components/prism-bash.min.js" type="text/javascript"></script>
17-
<script src="https://cdn.jsdelivr.net/prism/1.3.0/components/prism-html.min.js" type="text/javascript"></script>
1813
<script src="./dist/bundle.js"></script>
1914
</body>
2015
</html>

index.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import React from "react";
22
import { render } from "react-dom";
33

4+
import "prismjs"
5+
import "prismjs/components/prism-typescript"
6+
import "prismjs/components/prism-bash"
7+
import "prismjs/components/prism-jsx"
8+
49
import Presentation from "./presentation";
510

611
render(<Presentation/>, document.getElementById("root"));

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"is-buffer": "^1.1.1",
4444
"markdown-loader": "^0.1.7",
4545
"node-libs-browser": "^2.0.0",
46+
"prismjs": "^1.6.0",
4647
"raw-loader": "^0.5.1",
4748
"rimraf": "^2.4.4",
4849
"style-loader": "^0.13.0",

presentation/index.js

+44-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default class Presentation extends React.Component {
6363
<Deck transition={slideTransition} transitionDuration={500}>
6464
<Slide transition={slideTransition} bgColor="secondary">
6565
<Heading size={1} fit caps lineHeight={1} textColor="tertiary">
66-
TypeScript in 2016
66+
TypeScript in 2017
6767
</Heading>
6868
<Image src={images.ts} margin="40px auto" height="324px"/>
6969
</Slide>
@@ -313,7 +313,7 @@ export default class Presentation extends React.Component {
313313
</Slide>
314314
<Slide transition={slideTransition}>
315315
<heading>End result:</heading>
316-
<Image src={images.basicReactTypescript} margin="0px auto 40px" height="524px"/>
316+
<Image src={images.basicReactTypescript} margin="0px auto 40px" width="800px"/>
317317
</Slide>
318318

319319

@@ -372,15 +372,53 @@ export default class Presentation extends React.Component {
372372
</Slide>
373373
<Slide transition={slideTransition}>
374374
<heading>End result:</heading>
375-
<Image src={images.basicAngular} margin="0px auto 40px" height="524px"/>
375+
<Image src={images.basicAngular} margin="0px auto 40px" width="800px"/>
376376
</Slide>
377+
378+
377379
<Slide transition={slideTransition}>
378380
<Heading size={4}>
379-
Gotchas
381+
Vanilla TypeScript
380382
</Heading>
381-
<Appear><ListItem>To use <code>require(..</code> you need node types: </ListItem></Appear>
382-
<Appear><ListItem>Run <code>npm install @types/node --save-dev</code></ListItem></Appear>
383+
<h3>Creating a cross framework component from scratch</h3>
384+
<CodePane
385+
lang="bash"
386+
source={require("raw!../examples/IComponent.ts")}
387+
margin="20px auto"
388+
/>
389+
<p><a href="https://github.com/quantumjs/vanilla-typescript">https://github.com/quantumjs/vanilla-typescript</a> </p>
390+
<h4>Is this a framework?</h4>
391+
<p>Nope, this is just to provide some little level of common sense to the wild west of vanillajs.</p>
383392
</Slide>
393+
<Slide transition={slideTransition}>
394+
<Heading size={4}>
395+
<a href="https://www.npmjs.com/package/solar-popup">Solar-popup</a>
396+
</Heading>
397+
<CodePane
398+
lang="bash"
399+
source={require("raw!../examples/SolarPopup.ts")}
400+
margin="20px auto"
401+
/>
402+
</Slide>
403+
404+
405+
<Slide transition={slideTransition}>
406+
<h3>Basic component</h3>
407+
<p>app.component.ts</p>
408+
<CodePane
409+
lang="typescript"
410+
source={require("raw!../examples/angular/app.component.ts")}
411+
margin="20px auto"
412+
/>
413+
<p>app.component.html</p>
414+
<CodePane
415+
lang="html"
416+
source={require("raw!../examples/angular/app.component.html")}
417+
margin="20px auto"
418+
/>
419+
</Slide>
420+
421+
384422
<Slide transition={slideTransition}>
385423
<Link href="https://www.youtube.com/channel/UC0XiDgtbFR8ohoGlstuFgGQ">
386424
<Heading size={4}>

0 commit comments

Comments
 (0)