Skip to content

Commit

Permalink
add minimal example
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Apr 8, 2024
1 parent 0f970ef commit 24673dc
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/minimal/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules/
/dist/
16 changes: 16 additions & 0 deletions examples/minimal/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite build && vite preview"
},
"dependencies": {
"@vitejs/plugin-react": "^4.2.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"vike": "^0.4.168",
"vike-react": "^0.4.6",
"vite": "^5.1.1"
},
"type": "module"
}
11 changes: 11 additions & 0 deletions examples/minimal/pages/+config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export { config }

import vikeReact from 'vike-react/config'
import { Layout } from './Layout'

const config = {
// https://vike.dev/Layout
Layout: Layout,
// https://vike.dev/extends
extends: vikeReact
}
14 changes: 14 additions & 0 deletions examples/minimal/pages/Layout.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
body {
margin: 0;
font-family: sans-serif;
}
* {
box-sizing: border-box;
}
a {
text-decoration: none;
}

.navitem {
padding: 3px;
}
69 changes: 69 additions & 0 deletions examples/minimal/pages/Layout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
export { Layout }

import React from 'react'
import './Layout.css'

function Layout({ children }) {
return (
<React.StrictMode>
<PageLayout>
<Sidebar>
<a className="navitem" href="/">
Home
</a>
<a className="navitem" href="/about">
About
</a>
</Sidebar>
<Content>{children}</Content>
</PageLayout>
</React.StrictMode>
)
}

function PageLayout({ children }) {
return (
<div
style={{
display: 'flex',
maxWidth: 900,
margin: 'auto'
}}
>
{children}
</div>
)
}

function Sidebar({ children }) {
return (
<div
style={{
padding: 20,
paddingTop: 42,
flexShrink: 0,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
lineHeight: '1.8em'
}}
>
{children}
</div>
)
}

function Content({ children }) {
return (
<div
style={{
padding: 20,
paddingBottom: 50,
borderLeft: '2px solid #eee',
minHeight: '100vh'
}}
>
{children}
</div>
)
}
12 changes: 12 additions & 0 deletions examples/minimal/pages/about/+Page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default Page

import React from 'react'

function Page() {
return (
<>
<h1>About</h1>
<p>Example of using Vike.</p>
</>
)
}
19 changes: 19 additions & 0 deletions examples/minimal/pages/index/+Page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default Page

import React from 'react'
import { Counter } from './Counter'

function Page() {
return (
<>
<h1>Welcome</h1>
This page is:
<ul>
<li>Rendered to HTML.</li>
<li>
Interactive. <Counter />
</li>
</ul>
</>
)
}
12 changes: 12 additions & 0 deletions examples/minimal/pages/index/Counter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export { Counter }

import React, { useState } from 'react'

function Counter() {
const [count, setCount] = useState(0)
return (
<button type="button" onClick={() => setCount((count) => count + 1)}>
Counter {count}
</button>
)
}
8 changes: 8 additions & 0 deletions examples/minimal/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Minimal example of using `vike-react`.

```bash
git clone git@github.com:vikejs/vike-react
cd vike-react/examples/minimal/
npm install
npm run dev
```
6 changes: 6 additions & 0 deletions examples/minimal/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import react from '@vitejs/plugin-react'
import ssr from 'vike/plugin'

export default {
plugins: [react(), ssr()]
}
21 changes: 21 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24673dc

Please sign in to comment.