Skip to content

Add examples #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
npm-debug.log
package-lock.json
site
6 changes: 3 additions & 3 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const meow = require('meow')
const { pkg } = require('read-pkg-up').sync()
const open = require('opn')

require('update-notifier')({
pkg: require('../package.json')
}).notify()
const x0Pkg = require('../package.json')

require('update-notifier')({ pkg: x0Pkg }).notify()

const cli = meow(`
Usage:
Expand Down
7 changes: 7 additions & 0 deletions examples/basic/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react'

const App = props => (
<h1>Hello</h1>
)

export default App
20 changes: 20 additions & 0 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# x0 basic example

```sh
npm install
```

## Dev Server

```sh
npm start
```

Editing `App.js` will live update in the development server.

## Static Build

```sh
npm run build
```
1 change: 1 addition & 0 deletions examples/basic/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><title></title><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><meta name="description"/></head><body><div id="app"><h1>Hello</h1></div></body></html>
12 changes: 12 additions & 0 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "x0-basic-example",
"private": true,
"scripts": {
"start": "x0 dev App.js -o",
"build": "x0 build App.js > index.html",
"test": "x0 build App.js"
},
"dependencies": {
"rx0": "^1.0.6"
}
}
19 changes: 19 additions & 0 deletions examples/bundle/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import { createProvider } from 'refunk'

const dec = state => ({ count: state.count - 1 })
const inc = state => ({ count: state.count + 1 })

const App = props => (
<div>
<h1>hi Hello {props.count}</h1>
<button onClick={e => props.update(dec)}>
-
</button>
<button onClick={e => props.update(inc)}>
+
</button>
</div>
)

export default createProvider()(App)
24 changes: 24 additions & 0 deletions examples/bundle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

# x0 bundle example

```sh
npm install
```

## Dev Server

```sh
npm start
```

Editing `App.js` will live update in the development server.

## Static Build

```sh
npm run build
```

This should save a `bundle.js` file which will rehydrate state in the `index.html`.

To view the output app, run a local server in the `site/` directory.
19 changes: 19 additions & 0 deletions examples/bundle/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "x0-bundle-example",
"private": true,
"scripts": {
"start": "x0 dev App.js -o",
"build": "x0 build App.js --out-dir ./site",
"test": "x0 build App.js"
},
"dependencies": {
"refunk": "^1.0.0-2",
"rx0": "^1.0.6"
},
"x0": {
"title": "x0 Bundle Example",
"description": "Just a simple example",
"css": "*{box-sizing:border-box}body{font-family:-apple-system,BlinkMacSystemFont,sans-serif;margin:0}",
"count": 16
}
}
7 changes: 7 additions & 0 deletions examples/configuration/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react'

const App = props => (
<h1>Hello</h1>
)

export default App
22 changes: 22 additions & 0 deletions examples/configuration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# x0 configuration example

```sh
npm install
```

## Dev Server

```sh
npm start
```

Editing `App.js` will live update in the development server.

## Static Build

```sh
npm run build
```

Edit the `x0` field in `package.json` to change the configuration.
1 change: 1 addition & 0 deletions examples/configuration/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><title>x0 Configuration Example</title><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><meta name="description" content="Just a simple example"/><style>*{box-sizing:border-box}body{font-family:-apple-system,BlinkMacSystemFont,sans-serif;margin:0}</style></head><body><div id="app"><h1>Hello</h1></div></body></html>
17 changes: 17 additions & 0 deletions examples/configuration/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "x0-configuration-example",
"private": true,
"scripts": {
"start": "x0 dev App.js -o",
"build": "x0 build App.js > index.html",
"test": "x0 build App.js"
},
"dependencies": {
"rx0": "^1.0.6"
},
"x0": {
"title": "x0 Configuration Example",
"description": "Just a simple example",
"css": "*{box-sizing:border-box}body{font-family:-apple-system,BlinkMacSystemFont,sans-serif;margin:0}"
}
}
19 changes: 19 additions & 0 deletions examples/custom-html/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import { createProvider } from 'refunk'

const dec = state => ({ count: state.count - 1 })
const inc = state => ({ count: state.count + 1 })

const App = props => (
<div>
<h1>hi Hello {props.count}</h1>
<button onClick={e => props.update(dec)}>
-
</button>
<button onClick={e => props.update(inc)}>
+
</button>
</div>
)

export default createProvider()(App)
19 changes: 19 additions & 0 deletions examples/custom-html/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# x0 custom HTML example

```sh
npm install
```

## Dev Server

```sh
npm start
```

## Static Build

```sh
npm run build
```

15 changes: 15 additions & 0 deletions examples/custom-html/Root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import { Html } from 'rx0'

const css = `*{box-sizing:border-box}
body{font-family:-apple-system,BlinkMacSystemFont,sans-serif;margin:0}`

const Root = props => (
<Html
{...props}
title='x0 HTML'
css={css}
/>
)

export default Root
18 changes: 18 additions & 0 deletions examples/custom-html/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "x0-html-example",
"private": true,
"scripts": {
"start": "x0 dev App.js -o",
"build": "x0 build App.js --html Root.js --out-dir ./site",
"test": "x0 build App.js --html Root.js"
},
"dependencies": {
"refunk": "^1.0.0-2",
"rx0": "^1.0.6"
},
"x0": {
"title": "x0 HTML Example",
"description": "Just a simple example",
"count": 16
}
}
41 changes: 41 additions & 0 deletions examples/cxs/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react'
import cxs from 'cxs/component'

const Root = cxs('div')({
padding: '48px'
})

const Heading = cxs('h1')({
fontSize: '48px',
margin: 0
})

const Button = cxs('button')(props => ({
display: 'inline-block',
fontFamily: 'inherit',
fontSize: '14px',
paddingTop: '6px',
paddingBottom: '6px',
paddingLeft: '12px',
paddingRight: '12px',
border: 0,
borderRadius: '4px',
color: 'white',
backgroundColor: props.color,
WebkitAppearance: 'none'
}))

Button.defaultProps = {
color: '#07c'
}

const App = props => (
<Root>
<Heading>Hello CXS</Heading>
<Button>
Beep
</Button>
</Root>
)

export default App
20 changes: 20 additions & 0 deletions examples/cxs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# x0 CXS example

```sh
npm install
```

## Dev Server

```sh
npm start
```

## Static Build

```sh
npm run build
```

When building static, CSS will be added to a `<style>` tag in the head.
20 changes: 20 additions & 0 deletions examples/cxs/Root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import { Html } from 'rx0'
import cxs from 'cxs'

const basecss = `*{box-sizing:border-box}
body{font-family:-apple-system,BlinkMacSystemFont,sans-serif;margin:0}`

const Root = props => {
const css = basecss + cxs.css()

return (
<Html
{...props}
title='x0 CXS'
css={css}
/>
)
}

export default Root
13 changes: 13 additions & 0 deletions examples/cxs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "x0-cxs-example",
"private": true,
"scripts": {
"start": "x0 dev App.js -o",
"build": "x0 build App.js --html Root.js --out-dir ./site",
"test": "x0 build App.js --html Root.js"
},
"dependencies": {
"cxs": "^6.0.0",
"rx0": "^1.0.6"
}
}
Loading