Skip to content

Commit fee1df3

Browse files
committed
fix: Fixed some edge cases for the hooks.
1 parent 77612b5 commit fee1df3

File tree

10 files changed

+72
-10
lines changed

10 files changed

+72
-10
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### Changelog
2+
3+
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
4+
5+
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6+
7+
#### 0.0.1
8+
9+
- feat: initial commit + Added the use-hotkeys hook. [`fe858db`](https://github.com/Blankeos/bagon-hooks/commit/fe858db9cd1b626886bcb3b0e95cb798ebb15cee)
10+
- Format [`5b9e02a`](https://github.com/Blankeos/bagon-hooks/commit/5b9e02a0fd0cc7eeff8a6c078410dca0fa85639c)
11+
- chore: Changed formatting. [`f7e9f2b`](https://github.com/Blankeos/bagon-hooks/commit/f7e9f2b205091ddf0caff29693c7ba8aa60d654a)
File renamed without changes.

dev/pages/index/+title.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import getTitle from 'dev/utils/get-title';
2+
3+
export const title = getTitle('Home');

dev/styles/app.css

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
@import url('../fonts/geist.css');
2+
3+
@tailwind base;
4+
@tailwind components;
5+
@tailwind utilities;
6+
7+
@layer base {
8+
:root {
9+
/* Dark/Light Agnostic Colors */
10+
--primary: 206 73% 64%; /* hsl(206 73% 64%) */
11+
--primary-foreground: 204 100% 79%; /* hsl(204 100% 79%) */
12+
--primary-secondary: 53 80% 67%; /* hsl(53 80% 67%) */
13+
14+
--background: 240 10% 4%; /* hsl(240 10% 4%) */
15+
16+
--muted: 0 0% 96.1%; /* hsl(0 0% 96.1%) */
17+
18+
--typography: 0 0% 25%; /* hsl(0 0% 25%) */
19+
20+
/* Static Colors */
21+
--static-white: 240 100% 98%; /* hsl(240 100% 98%) */
22+
}
23+
24+
.dark {
25+
26+
}
27+
}
28+
29+
body {
30+
margin: 0;
31+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
32+
'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
33+
-webkit-font-smoothing: antialiased;
34+
-moz-osx-font-smoothing: grayscale;
35+
36+
font-family: 'Geist', sans-serif;
37+
38+
@apply bg-primary;
39+
@apply text-typography;
40+
}
41+
42+
code {
43+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
44+
}

dev/utils/get-title.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const TITLE_TEMPLATE = '%s | Bagon Hooks';
2+
3+
export default function getTitle(title: string = 'Home') {
4+
return TITLE_TEMPLATE.replace('%s', title);
5+
}

src/use-click-outside/use-click-outside.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ const DEFAULT_EVENTS = ['mousedown', 'touchstart'];
44

55
/**
66
* A hook that listens to click events outside of a specified element or elements.
7-
*
8-
* @example
9-
*
107
*/
118
export function useClickOutside<T extends HTMLElement = any>(
129
handler: () => void,
@@ -23,7 +20,6 @@ export function useClickOutside<T extends HTMLElement = any>(
2320
const [ref, setRef] = createSignal<T>();
2421

2522
createEffect(() => {
26-
console.log(ref, 'wowowow');
2723
const listener = (event: any) => {
2824
const { target } = event ?? {};
2925
if (Array.isArray(nodes)) {

src/use-idle/use-idle.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Accessor, createEffect, createSignal, mergeProps, onCleanup } from 'solid-js';
1+
import { createEffect, createSignal, mergeProps, onCleanup } from 'solid-js';
22

33
const DEFAULT_EVENTS: (keyof DocumentEventMap)[] = [
44
'keypress',
@@ -20,7 +20,7 @@ const DEFAULT_OPTIONS = {
2020
* @param options - An options object to configure the hook.
2121
*/
2222
export function useIdle(
23-
timeout: Accessor<number>,
23+
timeout: number,
2424
options?: Partial<{ events: (keyof DocumentEventMap)[]; initialState: boolean }>,
2525
) {
2626
const _options = mergeProps(DEFAULT_OPTIONS, options);
@@ -38,15 +38,15 @@ export function useIdle(
3838

3939
timer = window.setTimeout(() => {
4040
setIdle(true);
41-
}, timeout());
41+
}, timeout);
4242
};
4343

4444
_options.events.forEach(event => document.addEventListener(event, handleEvents));
4545

4646
// Start the timer immediately instead of waiting for the first event to happen
4747
timer = window.setTimeout(() => {
4848
setIdle(true);
49-
}, timeout());
49+
}, timeout);
5050

5151
onCleanup(() => {
5252
_options.events.forEach(event => document.removeEventListener(event, handleEvents));

src/use-network/use-network.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function useNetwork() {
4747
onMount(() => {
4848
const onlineListener = () => setStatus({ online: true, ...getConnection() });
4949
const offlineListener = () => setStatus({ online: false, ...getConnection() });
50+
window.addEventListener('online', onlineListener);
5051
window.addEventListener('offline', offlineListener);
5152

5253
onCleanup(() => {

src/use-resize-observer/use-resize-observer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function useElementSize<T extends HTMLElement = any>(options?: ResizeObse
8787

8888
return {
8989
ref,
90-
width: createMemo(() => rectStore.rect.width),
91-
height: createMemo(() => rectStore.rect.height),
90+
width: createMemo(() => rectStore?.rect?.width),
91+
height: createMemo(() => rectStore?.rect?.height),
9292
};
9393
}

src/use-toggle/use-toggle.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { createMemo, createSignal } from 'solid-js';
22

33
/**
44
* A hook that toggles between two or multiple values (by implementing a common state pattern).
5+
*
6+
* Dev Note: Personally this can be called `useCycle` instead since it cycles through the options.
57
*/
68
export function useToggle<T = boolean>(options: readonly T[] = [false, true] as any) {
79
const [_options, _setOptions] = createSignal<typeof options>(options);

0 commit comments

Comments
 (0)