Skip to content

Commit 1af49ae

Browse files
committed
✨ Update example & make previewable on StackBlitz
1 parent b2285b4 commit 1af49ae

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

examples/active-class-name/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ Nullstack [Context](https://nullstack.app/context)'s [Router](https://nullstack.
44

55
## Deploy your own
66

7-
Deploy it now with [Vercel](https://vercel.com):
7+
Deploy it now with [Vercel](https://vercel.com) or preview on [StackBlitz](https://stackblitz.com):
88

99
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/GuiDevloper/nullstack-examples/tree/main/examples/active-class-name&project-name=active-class-name&repo-name=active-class-name&demo-title=Nullstack+activeClassName&demo-description=Nullstack+example+of+active+class+name&demo-url=https://github.com/GuiDevloper/nullstack-examples/tree/main/examples/active-class-name&demo-image=https://nullstack.app/image-1200x630.png)
10+
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/fork/github/GuiDevloper/nullstack-examples/tree/main/examples/active-class-name?title=Nullstack+ActiveClassName)
1011

1112
## How to use
1213

examples/active-class-name/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@
77
"start": "npx nullstack start",
88
"build": "npx nullstack build",
99
"vercel-build": "npm run build && npx nullstack-adapt-vercel"
10+
},
11+
"stackblitz": {
12+
"installDependencies": false,
13+
"startCommand": "npm i [email protected] -D && nullstack-adapt-babel && npm start",
14+
"compileTrigger": "save"
1015
}
1116
}
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
import { NullstackClientContext } from 'nullstack'
1+
import { NullstackClientContext, NullstackFunctionalComponent } from 'nullstack'
22

3-
type ActiveLinkProps = Partial<NullstackClientContext> & {
3+
type ActiveLinkProps = JSX.AllElements['a'] & {
44
href: string
5-
class?: string
65
}
76

8-
function ActiveLink(context: ActiveLinkProps) {
9-
const { href, children, router } = context
7+
function ActiveLink({
8+
href,
9+
children,
10+
router,
11+
class: currentClasses,
12+
...otherAttributes
13+
}: NullstackClientContext<ActiveLinkProps>) {
1014
const activeClass = router.path === href ? ' active' : ''
11-
const classes = `${context.class}${activeClass}`
15+
const classes = `${currentClasses}${activeClass}`
1216
return (
13-
<a href={href} class={classes}>
17+
<a href={href} class={classes} {...otherAttributes}>
1418
{children}
1519
</a>
1620
)
1721
}
1822

19-
export default ActiveLink
23+
export default ActiveLink as NullstackFunctionalComponent<ActiveLinkProps>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { NullstackClientContext } from 'nullstack'
1+
import { NullstackClientContext, NullstackFunctionalComponent } from 'nullstack'
22

3-
function Dynamic({ router }: Partial<NullstackClientContext>) {
3+
function Dynamic({ router }: NullstackClientContext) {
44
const cleanRoute = router.path.replace('/', '')
55
return <p>Hello, I'm the {cleanRoute} page</p>
66
}
77

8-
export default Dynamic
8+
export default Dynamic as NullstackFunctionalComponent<Record<string, any>>

0 commit comments

Comments
 (0)