Skip to content

Commit

Permalink
feat: create low-router-preact (#43)
Browse files Browse the repository at this point in the history
* 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
willybrauner authored Sep 7, 2024
1 parent ec503f8 commit 4e31d18
Show file tree
Hide file tree
Showing 142 changed files with 9,727 additions and 3,753 deletions.
4 changes: 2 additions & 2 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
"$schema": "https://unpkg.com/@changesets/config@3.0.3/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [["@wbe/low-router"]],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
Expand Down
90 changes: 90 additions & 0 deletions .changeset/tough-socks-marry.md
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)
```
13 changes: 7 additions & 6 deletions .codesandbox/ci.json
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"
}
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:
run_install: |
args: [--filter "@wbe/*"]
- name: Copy README file to package
uses: canastro/copy-file-action@master
with:
source: "README.md"
target: "packages/low-router/README.md"
# - name: Copy README file to package
# uses: canastro/copy-file-action@master
# with:
# source: "README.md"
# target: "packages/low-router/README.md"

- name: Set up NPM credentials
run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
Expand Down
Loading

0 comments on commit 4e31d18

Please sign in to comment.