-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from bcomnes/tonic-example
Add tonic example
- Loading branch information
Showing
25 changed files
with
270 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "string-layouts", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"start": "npm run watch", | ||
"build": "npm run clean && siteup", | ||
"clean": "rm -rf public && mkdir -p public", | ||
"watch": "npm run clean && run-p watch:*", | ||
"watch:serve": "browser-sync start --server 'public' --files 'public'", | ||
"watch:siteup": "npm run build -- --watch" | ||
}, | ||
"author": "Bret Comnes <bcomnes@gmail.com> (https://bret.io/)", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@siteup/cli": "../../.", | ||
"@socketsupply/tonic": "^15.1.1", | ||
"mine.css": "^9.0.1", | ||
"tonic-ssr": "github:socketsupply/tonic-ssr#f447a8ae2bec27a526ae489fa8510a1c646f4a66" | ||
}, | ||
"devDependencies": { | ||
"browser-sync": "^2.26.7", | ||
"npm-run-all2": "^6.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Tonic from '@socketsupply/tonic' | ||
import { ChildComponent } from './components/child-component.js' | ||
|
||
Tonic.add(ChildComponent) |
11 changes: 11 additions & 0 deletions
11
examples/tonic-components/src/components/child-component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Tonic from '@socketsupply/tonic' | ||
|
||
export class ChildComponent extends Tonic { | ||
render () { | ||
return this.html` | ||
<div class="child"> | ||
${this.props.value} | ||
</div> | ||
` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Tonic from '@socketsupply/tonic' | ||
|
||
const sleep = t => new Promise(resolve => setTimeout(resolve, t)) | ||
|
||
export class HelloWorld extends Tonic { | ||
stylesheet () { | ||
return ` | ||
hello-world { | ||
border: ${this.props.border}; | ||
} | ||
` | ||
} | ||
|
||
async click () { | ||
// | ||
// Won't do anything on the server, | ||
// will work if rendered in the browser. | ||
// | ||
} | ||
|
||
async render () { | ||
await sleep(200) | ||
|
||
const { | ||
greetings, | ||
lang | ||
} = this.props | ||
|
||
return this.html` | ||
<h1> | ||
${greetings[lang]} | ||
<time-stamp></time-stamp> | ||
</h1> | ||
` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Tonic from '@socketsupply/tonic' | ||
|
||
export class ParentComponent extends Tonic { | ||
render () { | ||
return this.html` | ||
<div class="parent"> | ||
${this.children} | ||
</div> | ||
` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Tonic from '@socketsupply/tonic' | ||
|
||
export class TimeStamp extends Tonic { | ||
render () { | ||
return this.html` | ||
<time> | ||
Tue Jan 26 22:18:05 CET 2021 | ||
</time> | ||
` | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/tonic-components/src/components/wrapper-parent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Tonic } from '@socketsupply/tonic' | ||
|
||
export class WrapperParent extends Tonic { | ||
render () { | ||
return this.html` | ||
<div class="wrapper"> | ||
${this.children} | ||
</div> | ||
` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Tonic from '@socketsupply/tonic' | ||
import { ParentComponent } from './components/layout-parent.js' | ||
|
||
Tonic.add(ParentComponent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@import 'mine.css/dist/mine.css'; | ||
@import 'mine.css/dist/layout.css'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default async function () { | ||
return { | ||
siteName: 'Example site with tonic' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
title: Tonic Components! | ||
--- | ||
# String layout example | ||
|
||
That includes a tonic component | ||
|
||
<wrapper-parent> | ||
<div>Hello!</div> | ||
<div>World</div> | ||
</wrapper-parent> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Tonic } from '@socketsupply/tonic' | ||
import { WrapperParent } from '../components/wrapper-parent.js' | ||
|
||
Tonic.add(WrapperParent) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<child-component value="hello world"></child-component> | ||
|
||
<div>This is just some static html here</div> | ||
|
||
<div><a href="./md-page/">markdown page</a></div> | ||
<div><a href="./ssr-page/">ssr page</a></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Layouts can be a simple as returning a template literal, though you can use | ||
// libraries like uhtml-isomorphic for better DX. | ||
|
||
export default async function RootLayout ({ | ||
title, | ||
siteName, | ||
scripts, | ||
styles, | ||
children | ||
}) { | ||
return /* html */` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>${siteName || ''}${title ? ` | ${title}` : ''}</title> | ||
<meta name="viewport" content="width=device-width, user-scalable=no" /> | ||
${scripts | ||
? scripts.map(script => /* html */`<script src="${script}" type='module'></script>`).join('\n') | ||
: ''} | ||
${styles | ||
? styles.map(style => /* html */`<link rel="stylesheet" href=${style} />`).join('\n') | ||
: ''} | ||
</head> | ||
<body> | ||
<parent-component> | ||
${children} | ||
</parent-component> | ||
</body> | ||
</html> | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Tonic } from '@socketsupply/tonic' | ||
import { TimeStamp } from '../components/time-stamp.js' | ||
import { HelloWorld } from '../components/hello-world.js' | ||
|
||
export class MainComponent extends Tonic { | ||
constructor (props) { | ||
super() | ||
this.props = props | ||
} | ||
|
||
render () { | ||
const greetings = { en: 'Hello' } | ||
|
||
return this.html` | ||
<header> | ||
${String(this.props.timestamp)} | ||
</header> | ||
<main> | ||
<hello-world | ||
id="hello" | ||
lang="en" | ||
border="1px solid red" | ||
greetings="${greetings}" | ||
> | ||
</hello-world> | ||
</main> | ||
<footer> | ||
</footer> | ||
` | ||
} | ||
} | ||
|
||
Tonic.add(TimeStamp) | ||
Tonic.add(HelloWorld) | ||
Tonic.add(MainComponent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'tonic-ssr' | ||
import { MainComponent } from './client.js' | ||
|
||
export default () => { | ||
return (new MainComponent({ | ||
timestamp: 1611695921286 | ||
})).preRender() | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters