Skip to content

Commit

Permalink
chore: add examples back to repo
Browse files Browse the repository at this point in the history
  • Loading branch information
troch committed Aug 22, 2018
1 parent aee2d47 commit 20c0547
Show file tree
Hide file tree
Showing 65 changed files with 8,050 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@ lerna-debug.log

packages/*/dist
.changelog
.DS_Store
1 change: 1 addition & 0 deletions examples/.gitignore
@@ -0,0 +1 @@
yarn.lock
21 changes: 21 additions & 0 deletions examples/react-new-context-api/.gitignore
@@ -0,0 +1,21 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
2,142 changes: 2,142 additions & 0 deletions examples/react-new-context-api/README.md

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions examples/react-new-context-api/package.json
@@ -0,0 +1,20 @@
{
"name": "react-router5-new-context-api",
"description": "",
"homepage": "https://stackblitz.com/edit/react-router5-new-context-api",
"dependencies": {
"react": "16.4.2",
"react-dom": "16.4.2",
"react-scripts": "1.1.4",
"router5": "6.4.2",
"react-router5": "6.3.0"
},
"version": "0.1.0",
"private": true,
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Binary file added examples/react-new-context-api/public/favicon.ico
Binary file not shown.
41 changes: 41 additions & 0 deletions examples/react-new-context-api/public/index.html
@@ -0,0 +1,41 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->

<title>react-router5-new-context-api</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
15 changes: 15 additions & 0 deletions examples/react-new-context-api/public/manifest.json
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "192x192",
"type": "image/png"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
17 changes: 17 additions & 0 deletions examples/react-new-context-api/src/components/App.js
@@ -0,0 +1,17 @@
import React from 'react'
import Nav from './Nav'
import Main from './Main'

export default function App({ emails }) {
return (
<div className="mail-client">
<aside>
<Nav />
</aside>

<main>
<Main emails={emails} />
</main>
</div>
)
}
41 changes: 41 additions & 0 deletions examples/react-new-context-api/src/components/Compose.js
@@ -0,0 +1,41 @@
import React, { Component } from 'react'
import { routeNode } from 'react-router5'

export default class Compose extends Component {
constructor(props, context) {
super(props, context)
this.state = {
title: '',
message: ''
}
this.updateTitle = this.updateTitle.bind(this)
this.updateMessage = this.updateMessage.bind(this)
}

updateTitle(evt) {
this.setState({ title: evt.target.value, warning: false })
}

updateMessage(evt) {
this.setState({ message: evt.target.value, warning: false })
}

render() {
const { title, message, warning } = this.state

return (
<div className="compose">
<h4>Compose a new message</h4>

<input name="title" value={title} onChange={this.updateTitle} />
<textarea
name="message"
value={message}
onChange={this.updateMessage}
/>

{warning ? <p>Clear inputs before continuing</p> : null}
</div>
)
}
}
23 changes: 23 additions & 0 deletions examples/react-new-context-api/src/components/Inbox.js
@@ -0,0 +1,23 @@
import React from 'react'
import InboxList from './InboxList'
import Message from './Message'
import { RouteNode } from 'react-router5'

function Inbox(props) {
const { route, emails } = props

return (
<div className="inbox">
<InboxList emails={emails} />
{route.name === 'inbox.message' ? (
<Message {...emails[route.params.id]} key={route.params.id} />
) : null}
</div>
)
}

export default (props) => (
<RouteNode nodeName="inbox">
{({ route }) => <Inbox route={route} {...props} />}
</RouteNode>
)
19 changes: 19 additions & 0 deletions examples/react-new-context-api/src/components/InboxItem.js
@@ -0,0 +1,19 @@
import React, { Component } from 'react'
import { Link } from 'react-router5'

function InboxItem({ title, message, id }) {
return (
<li>
<Link
routeName="inbox.message"
routeParams={{id }}
activeClassName="active"
>
<h4>{title}</h4>
<p>{message}</p>
</Link>
</li>
)
}

export default InboxItem
12 changes: 12 additions & 0 deletions examples/react-new-context-api/src/components/InboxList.js
@@ -0,0 +1,12 @@
import React from 'react'
import InboxItem from './InboxItem'

export default function InboxList({
emails
}) {
return (
<ul className="mail-list">
{Object.values(emails).map(mail => <InboxItem {...mail} key={mail.id} />)}
</ul>
)
}
25 changes: 25 additions & 0 deletions examples/react-new-context-api/src/components/Main.js
@@ -0,0 +1,25 @@
import React from 'react'
import { RouteNode } from 'react-router5'
import Inbox from './Inbox'
import Compose from './Compose'
import NotFound from './NotFound'

function Main({ route, emails }) {
const topRouteName = route.name.split('.')[0]

if (topRouteName === 'inbox') {
return <Inbox emails={emails} />
}

if (topRouteName === 'compose') {
return <Compose />
}

return <NotFound />
}

export default (props) => (
<RouteNode nodeName="">
{({ route }) => <Main route={route} {...props} />}
</RouteNode>
)
12 changes: 12 additions & 0 deletions examples/react-new-context-api/src/components/Message.js
@@ -0,0 +1,12 @@
import React from 'react'

export default function Message(props) {
const { title, message } = props

return (
<section className="mail">
<h4>{title}</h4>
<p>{message}</p>
</section>
)
}
26 changes: 26 additions & 0 deletions examples/react-new-context-api/src/components/Nav.js
@@ -0,0 +1,26 @@
import React from 'react'
import { BaseLink, Route } from 'react-router5'

function Nav(props) {
const { router } = props

return (
<nav>
<BaseLink
router={router}
routeName="inbox"
routeOptions={{ reload: true }}
>
Inbox
</BaseLink>
<BaseLink router={router} routeName="compose">
Compose
</BaseLink>
<BaseLink router={router} routeName="contacts">
Contacts
</BaseLink>
</nav>
)
}

export default () => <Route>{({ router }) => <Nav router={router} />}</Route>
5 changes: 5 additions & 0 deletions examples/react-new-context-api/src/components/NotFound.js
@@ -0,0 +1,5 @@
import React from 'react'

export default function NotFound(props) {
return <div className="not-found">Purposely Not found (not a bug)</div>
}
19 changes: 19 additions & 0 deletions examples/react-new-context-api/src/create-router.js
@@ -0,0 +1,19 @@
import createRouter from 'router5'
import loggerPlugin from 'router5/plugins/logger'
import browserPlugin from 'router5/plugins/browser'
import routes from './routes'

export default function configureRouter() {
const router = createRouter(routes, {
defaultRoute: 'inbox'
})
// Plugins
.usePlugin(loggerPlugin)
.usePlugin(
browserPlugin({
useHash: true
})
)

return router
}
22 changes: 22 additions & 0 deletions examples/react-new-context-api/src/data.js
@@ -0,0 +1,22 @@
const emails = {
'1': {
id: '1',
title: 'Why router5?',
message:
'I imagine a lot of developers who will first see router5 will ask themselves the question: is it yet another router? is it any good? Why oh why do people keep writing new routers all the time? It is not always easy to see the potential of something straight away, or understand the motivations behind. I therefore decided to try to tell you more about router5, why I decided to develop an entire new routing solution, and what problems it tries to solve.'
},
'2': {
id: '2',
title: 'Use with React',
message:
'I have just started playing with it. It does make sense to use a flux-like implementation, to provide a layer between the router and view updates.'
},
'3': {
id: '3',
title: 'Compose a new message',
message:
'Click on compose, start to fill title and message fields and then try to navigate away by clicking on app links, or by using the back button.'
}
}

export default emails
17 changes: 17 additions & 0 deletions examples/react-new-context-api/src/index.js
@@ -0,0 +1,17 @@
import ReactDOM from 'react-dom'
import React from 'react'
import App from './components/App'
import { RouteProvider } from 'react-router5'
import createRouter from './create-router'
import emails from './data'
import './style.css'

const router = createRouter()

router.start(() => {
ReactDOM.render((
<RouteProvider router={router}>
<App emails={emails} />
</RouteProvider>
), document.getElementById('root'))
})
6 changes: 6 additions & 0 deletions examples/react-new-context-api/src/routes.js
@@ -0,0 +1,6 @@
export default [
{ name: 'inbox', path: '/inbox' },
{ name: 'inbox.message', path: '/message/:id' },
{ name: 'compose', path: '/compose' },
{ name: 'contacts', path: '/contacts' }
]

0 comments on commit 20c0547

Please sign in to comment.