-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create low-router-preact (#43)
* feat: create low-router-preact * feat: improve I18n for size * manage imports * perf: improve by removing if possible * comment logs * feat: Docs * struct: Move examples in there repositiories * repo: Update size limit * fix: preact ssr example sandbox * feat: Install stackBlitz bot * feat: Remove stackBlitz app * feat: Remove jsx * externalize deps * Create type patch * feat: Init react version, but react types are not good * wip * wip * fix: Remove react package * minor * move docs * rename example * update packages * upgrade all packages * update ci * update changeset * add changeset
- Loading branch information
1 parent
ec503f8
commit 4e31d18
Showing
142 changed files
with
9,727 additions
and
3,753 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
--- | ||
"@wbe/low-router-preact": minor | ||
--- | ||
|
||
Low router preact wrapper first release. | ||
|
||
## Usage example | ||
|
||
(check the readme for more information) | ||
|
||
main.tsx: | ||
|
||
```tsx | ||
import { render } from "preact" | ||
import { createBrowserHistory } from "@wbe/wbe-router" | ||
import { Router } from "@wbe/low-router-preact" | ||
|
||
// Prepare the routes list | ||
const routes = [ | ||
{ | ||
name: "home", | ||
path: "/", | ||
action: () => Home, | ||
}, | ||
{ | ||
name: "about", | ||
path: "/about", | ||
action: () => About, | ||
}, | ||
] | ||
|
||
// Pass the routes list as LowRouter param | ||
const router = new LowRouter(routes) | ||
|
||
// Prepare a browser history | ||
const history = createBrowserHistory() | ||
|
||
// Render the app wrapped by the Router | ||
render( | ||
<Router router={router} history={history}> | ||
<App /> | ||
</Router>, | ||
document.getElementById("root"), | ||
) | ||
``` | ||
|
||
App.tsx | ||
|
||
```tsx | ||
import { Link, Stack } from "@wbe/low-router-preact" | ||
|
||
export default function App() { | ||
return ( | ||
<div> | ||
<nav> | ||
<Link to={{ name: "home" }}>{"home"}</Link> | ||
<Link to={{ name: "about" }}>{"about"}</Link> | ||
</nav> | ||
{/* Render current route here */} | ||
<Stack /> | ||
</div> | ||
) | ||
} | ||
``` | ||
|
||
Home.tsx | ||
|
||
```tsx | ||
import { useRef, useImperativeHandle } from "preact/hooks" | ||
|
||
const Home = (props, ref) => { | ||
const rootRef = useRef(null) | ||
|
||
// Each route need to attached name, DOM root, playIn & playOut to the forwarded ref. | ||
// The Stack use this forwarded ref in order to control the component. | ||
useImperativeHandle( | ||
ref, | ||
() => ({ | ||
name: "Home", | ||
root: rootRef.current, | ||
playIn: () => customPlayIn(rootRef.current), | ||
playOut: () => customPlayOut(rootRef.current), | ||
}), | ||
[], | ||
) | ||
return <div ref={rootRef}>Hello home!</div> | ||
} | ||
|
||
export default forwardRef(Home) | ||
``` |
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
{ | ||
"buildCommand": "build", | ||
"packages": ["./packages/*"], | ||
"packages": ["./packages/low-router", "./packages/low-router-preact"], | ||
"sandboxes": [ | ||
"./examples/basic", | ||
"./examples/basic-resolve-sync", | ||
"./examples/compose", | ||
"./examples/custom-path-to-regexp", | ||
"./examples/react-nested-routes" | ||
"/packages/low-router/examples/basic", | ||
"/packages/low-router/examples/basic-resolve-sync", | ||
"/packages/low-router/examples/compose", | ||
"/packages/low-router/examples/custom-path-to-regexp", | ||
"/packages/low-router/examples/react-nested-routes", | ||
"/packages/low-router-preact/examples/example-preact-ssr" | ||
], | ||
"node": "18" | ||
} |
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
Oops, something went wrong.