Skip to content

Commit 876479f

Browse files
committed
docs: Updated examples.
1 parent 50b9743 commit 876479f

File tree

11 files changed

+96
-61
lines changed

11 files changed

+96
-61
lines changed

dev/components/examples/example-base.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ export function ExampleBase(props: FlowProps<ExampleBaseProps>) {
1515
<div class="flex h-full max-h-[500px] w-full flex-col items-start gap-y-3 overflow-hidden rounded-lg bg-white p-5">
1616
<div class="flex w-full items-center justify-between">
1717
<h2 class="text-xl font-bold">{props.title}</h2>
18-
<button
19-
class={`flex h-8 w-8 items-center justify-center rounded-md border transition active:scale-95 ${viewing() === 'code' ? 'bg-background text-white' : ''}`}
20-
onClick={() => {
21-
setViewing(viewing() === 'code' ? 'result' : 'code');
22-
}}
23-
>
24-
<IconCode class="h-4 w-4" />
25-
</button>
18+
<div class="flex items-center gap-x-2">
19+
<button
20+
class={`flex h-8 w-8 items-center justify-center rounded-md border transition active:scale-95 ${viewing() === 'code' ? 'bg-background text-white' : ''}`}
21+
onClick={() => {
22+
setViewing(viewing() === 'code' ? 'result' : 'code');
23+
}}
24+
>
25+
<IconCode class="h-4 w-4" />
26+
</button>
27+
</div>
2628
</div>
2729

2830
<div class="text-sm text-opacity-70">{props.description}</div>
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
```tsx
2-
const ref = useClickOutside(() => {
2+
import { useClickOutside } from 'bagon-hooks';
3+
4+
export function App() {
5+
const ref = useClickOutside(() => {
36
console.log('Clicked outside!');
4-
});
7+
});
58

6-
return (
7-
<div ref={ref}>
8-
</div>;
9-
)
9+
return <div ref={ref}>Click outside of me.</div>;
10+
}
1011
```
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
```tsx
2-
const [count, { decrement, increment, reset, set }] = useCounter(5, { min: 1, max: 10 });
2+
import { useCounter } from 'bagon-hooks';
33

4-
return (
4+
export function App() {
5+
const [count, { decrement, increment, reset, set }] = useCounter(5, { min: 1, max: 10 });
6+
return (
57
<div>
6-
{count()}
7-
<button onClick={decrement}>-</button>
8-
<button onClick={increment}>+</button>
9-
10-
<button onClick={reset}>
11-
Reset
12-
</button>
13-
14-
<button
15-
onClick={() => set(Math.floor(Math.random() * 10))}
16-
>
17-
Set (To Random)
18-
</button>
19-
</div>;
20-
)
8+
{count()}
9+
<button onClick={decrement}>-</button>
10+
<button onClick={increment}>+</button>
11+
<button onClick={reset}>Reset</button>
12+
<button onClick={() => set(Math.floor(Math.random() * 10))}>Set (To Random)</button>
13+
</div>
14+
);
15+
}
2116
```

dev/components/examples/use-document-title/use-document-title.example.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ export function UseDocumentTitleExample() {
2323
code={<Code components={components} />}
2424
>
2525
<div class="flex h-full w-full flex-col items-center justify-center gap-x-1 rounded-md border p-3 py-10 text-center text-sm">
26-
<div class="flex items-center gap-x-2">
27-
<Kbd activated={title() === 'Home'}>Home</Kbd>
28-
<Kbd activated={title() === 'About'}>About</Kbd>
29-
<Kbd activated={title() === 'Awesome'}>Awesome</Kbd>
26+
<div class="flex flex-col items-center gap-y-7">
27+
<div class="flex items-center gap-x-2">
28+
<Kbd activated={title() === 'Home'}>Home</Kbd>
29+
<Kbd activated={title() === 'About'}>About</Kbd>
30+
<Kbd activated={title() === 'Awesome'}>Awesome</Kbd>
31+
</div>
3032
<button onClick={_cycle}>Toggle</button>
3133
</div>
3234
</div>

dev/components/examples/use-favicon/use-favicon.example.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ import { IconSolidJS, IconX } from 'dev/icons';
66
import { createSignal } from 'solid-js';
77
import { useMDXComponents } from 'solid-jsx';
88

9+
/** Improved Bagon implementation - You can choose to set it when you want. */
910
export function UseFaviconExample() {
10-
const [currentIcon, setCurrentIcon] = createSignal<'solid' | 'x' | undefined>(); // Not relevant, just for visuals
11+
const [currentIcon, setCurrentIcon] = createSignal<'solid' | 'x' | undefined>(); // Not important (Just for visuals)
1112

12-
// OLD Implementation:
13-
// const [favicon, setFavicon] = createSignal('https://docs.solidjs.com/favicon.svg');
14-
15-
// IMPROVED Implementation:
16-
const [_favicon, setFavicon] = useFavicon();
13+
const [_favicon, setFavicon] = useFavicon(); // The secret is: just don't pass an accessor in the hook.
1714

1815
const setXFavicon = () => {
1916
setCurrentIcon('x');
@@ -64,3 +61,19 @@ export function UseFaviconExample() {
6461
</ExampleBase>
6562
);
6663
}
64+
65+
/** Based on Mantine's implementation - it always runs onMount. */
66+
export function UseFaviconExampleMantine() {
67+
const [favicon, setFavicon] = createSignal('https://docs.solidjs.com/favicon.svg');
68+
const setXFavicon = () => setFavicon('https://x.com/favicon.ico');
69+
const setSolidFavicon = () => setFavicon('https://docs.solidjs.com/favicon.svg');
70+
71+
useFavicon(favicon); // Will always run at the start.
72+
73+
return (
74+
<>
75+
<button onClick={setXFavicon}>Use X Favicon</button>
76+
<button onClick={setSolidFavicon}>Use SolidJS Favicon</button>
77+
</>
78+
);
79+
}
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
```tsx
2-
useHotkeys([
3-
['mod+a', () => alert('Ctrl+Shift+A pressed')],
4-
['mod+Enter', () => alert('Alt+Shift+A pressed')],
5-
['shift+g', () => alert('Alt+A pressed')],
6-
]);
2+
import { useHotkeys } from 'bagon-hooks';
3+
4+
export function App() {
5+
useHotkeys([
6+
['mod+a', () => alert('Ctrl+Shift+A pressed')],
7+
['mod+Enter', () => alert('Alt+Shift+A pressed')],
8+
['shift+g', () => alert('Alt+A pressed')],
9+
]);
10+
11+
return <></>;
12+
}
713
```
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
```tsx
2-
const id = useId();
2+
import { useId } from 'bagon-hooks';
33

4-
return <div>Random ID: {id()}</div>;
4+
export function UseIdExample() {
5+
const id = useId();
6+
return (
7+
<div class="flex h-full w-full items-center justify-center gap-x-1 rounded-md border p-3 py-10 text-center text-sm">
8+
Random ID: <span class="rounded-md bg-neutral-300 px-1.5 py-0.5">{id()}</span>
9+
</div>
10+
);
11+
}
512
```

dev/components/examples/use-keyboard/use-keyboard.code.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
```tsx
2+
import { createStore } from "solid-js/store";
3+
import { useKeyboard } from "bagon-hooks";
4+
25
function KeyboardExample() {
36
const [store, setStore] = createStore({ a: false, b: false, c: false, d: false });
47

dev/components/examples/use-local-storage-store/use-local-storage-store.example.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export function UseLocalStorageStoreExample() {
2121
title="useLocalStorageStore"
2222
description={
2323
<>
24-
(Improvement) A hook that allows using value from the localStorage as a store. The hook
25-
works exactly the same way as createStore, but also writes the value to the localStorage.
26-
It even works between tabs!
24+
(Improvement) A hook that allows using value from the localStorage as a store for complex
25+
and efficient state management. The hook works exactly the same way as createStore, but
26+
also writes the value to the localStorage. It even works between tabs!
2727
<br />
2828
<br />
2929
To test, try changing the value with two tabs open.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
```tsx
2-
const os = useOs();
2+
import { useOs } from 'bagon-hooks';
33

4-
return (
5-
<div>
6-
Current OS: {os()}
7-
</div>;
8-
)
4+
export function App() {
5+
const os = useOs();
6+
7+
return <div>Current OS: {os()}</div>;
8+
}
99
```

0 commit comments

Comments
 (0)