Skip to content

Commit 936f550

Browse files
v1.0.6
1 parent 2e84bb0 commit 936f550

File tree

8 files changed

+60
-37
lines changed

8 files changed

+60
-37
lines changed

packages/minimal-shared/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# minimal-shared
22

3+
## 1.0.6
4+
5+
_Feb 23, 2025_
6+
7+
- Update `hooks/use-scroll-offset-top`.
8+
- Update `hooks/use-client-rect`.
9+
- Update `hooks/use-popover-hover`.
10+
- Update `utils/refs`.
11+
- Clean devDependencies
12+
13+
---
14+
315
## 1.0.5
416

517
_Jan 1, 2025_

packages/minimal-shared/knip.jsonc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://unpkg.com/knip@5/schema-jsonc.json",
3+
"paths": {
4+
"src/*": ["./src/*"],
5+
},
6+
"project": ["src/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}"],
7+
"ignoreExportsUsedInFile": true,
8+
"ignoreDependencies": [
9+
// ignore dependencies
10+
"chalk",
11+
"es-toolkit",
12+
"internal-eslint-config",
13+
],
14+
"ignore": [
15+
// ignore folders or files
16+
],
17+
}

packages/minimal-shared/package.json

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "minimal-shared",
33
"author": "Minimals",
4-
"version": "1.0.5",
4+
"version": "1.0.6",
55
"description": "Shared hooks and utils used by Minimal UI and Zone UI.",
66
"keywords": [
77
"typescript",
@@ -60,31 +60,27 @@
6060
"test:watch": "vitest",
6161
"lint": "eslint \"**/*.{js,jsx,ts,tsx}\"",
6262
"lint:fix": "eslint --fix \"**/*.{js,jsx,ts,tsx}\"",
63-
"lint:print": "npx eslint --print-config eslint.config.mjs > eslint-current-config.json",
63+
"lint:print": "npx eslint --print-config eslint.config.mjs > eslint-show-config.json",
6464
"clean": "rm -rf node_modules .turbo .next out dist build",
6565
"re:build": "pnpm clean && pnpm install && pnpm test && pnpm build",
6666
"tsc:print": "npx tsc --showConfig"
6767
},
6868
"dependencies": {
69-
"es-toolkit": "^1.31.0"
69+
"es-toolkit": "^1.32.0"
7070
},
7171
"devDependencies": {
7272
"@testing-library/jest-dom": "^6.6.3",
73-
"@testing-library/react": "^16.1.0",
74-
"@types/fs-extra": "^11.0.4",
75-
"@types/node": "^22.10.3",
76-
"@types/react": "18.3.12",
73+
"@testing-library/react": "^16.2.0",
74+
"@types/node": "^22.13.5",
75+
"@types/react": "19.0.10",
7776
"chalk": "^5.4.1",
78-
"fast-glob": "^3.3.2",
79-
"fs-extra": "^11.2.0",
80-
"glob": "^11.0.0",
8177
"internal-eslint-config": "workspace:*",
8278
"internal-ts-config": "workspace:*",
83-
"jsdom": "^25.0.1",
84-
"react": "^18.3.1",
85-
"tsup": "^8.3.5",
86-
"typescript": "^5.7.2",
87-
"vitest": "^2.1.8"
79+
"jsdom": "^26.0.0",
80+
"react": "^19.0.0",
81+
"tsup": "^8.3.6",
82+
"typescript": "^5.7.3",
83+
"vitest": "^3.0.6"
8884
},
8985
"peerDependencies": {
9086
"react": "^18.0.0 || ^19.0.0"

packages/minimal-shared/src/hooks/use-client-rect/use-client-rect.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useRef, useMemo, useState, useEffect, useCallback, useLayoutEffect } fr
77
/**
88
* Custom hook to get the bounding client rect and scroll dimensions of a DOM element.
99
*
10-
* @param {RefObject<HTMLDivElement>} [inputRef] - Optional ref object to the target element.
10+
* @param {RefObject<T | null>} [inputRef] - Optional ref object to the target element.
1111
* @param {string} [eventType] - Optional event type to trigger updates (e.g., 'scroll', 'resize').
1212
* @returns {UseClientRectReturn} - Object containing the bounding rect, scroll dimensions, and ref to the element.
1313
*/
@@ -28,17 +28,17 @@ type DOMRectValue = {
2828
height: number;
2929
};
3030

31-
export type UseClientRectReturn = DOMRectValue &
31+
export type UseClientRectReturn<T> = DOMRectValue &
3232
ScrollElValue & {
33-
elementRef: RefObject<HTMLDivElement>;
33+
elementRef: RefObject<T | null>;
3434
};
3535

36-
export function useClientRect(
37-
inputRef?: RefObject<HTMLDivElement>,
36+
export function useClientRect<T extends HTMLElement>(
37+
inputRef?: RefObject<T | null>,
3838
eventType?: string
39-
): UseClientRectReturn {
40-
const initialRef = useRef<HTMLDivElement>(null);
41-
const elementRef = inputRef || initialRef;
39+
): UseClientRectReturn<T> {
40+
const localRef = useRef<T>(null);
41+
const elementRef = inputRef || localRef;
4242

4343
const [rect, setRect] = useState<DOMRect | undefined>(undefined);
4444
const [scroll, setScroll] = useState<ScrollElValue | undefined>(undefined);

packages/minimal-shared/src/hooks/use-popover-hover/use-popover-hover.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ import { useRef, useState, useCallback } from 'react';
3535

3636
type UsePopoverHoverReturn<T> = {
3737
open: boolean;
38-
onOpen: () => void;
3938
anchorEl: T | null;
39+
onOpen: () => void;
4040
onClose: () => void;
41-
elementRef: RefObject<T>;
41+
elementRef: RefObject<T | null>;
4242
setOpen: Dispatch<SetStateAction<boolean>>;
4343
};
4444

4545
export function usePopoverHover<T extends HTMLElement>(
4646
inputRef?: RefObject<T>
4747
): UsePopoverHoverReturn<T> {
48-
const initialRef = useRef<T | null>(null);
49-
const elementRef = inputRef || initialRef;
48+
const localRef = useRef<T>(null);
49+
const elementRef = inputRef || localRef;
5050

5151
const [open, setOpen] = useState<boolean>(false);
5252

packages/minimal-shared/src/hooks/use-scroll-offset-top/use-scroll-offset-top.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { MutableRefObject } from 'react';
2-
31
import { act, renderHook } from '@testing-library/react';
42

53
import { useScrollOffsetTop } from './use-scroll-offset-top';
@@ -28,12 +26,12 @@ describe('useScrollOffsetTop()', () => {
2826
};
2927

3028
it(`1. Should return offsetTop as ${highlightText.val('false')} when window.scrollY is less than default value`, () => {
31-
const { result } = renderHook(() => useScrollOffsetTop<HTMLDivElement>(defaultOffset));
29+
const { result } = renderHook(() => useScrollOffsetTop(defaultOffset));
3230
expect(result.current.offsetTop).toBe(false);
3331
});
3432

3533
it(`2. Should update offsetTop to ${highlightText.val('true')} when scroll position is greater than default value`, () => {
36-
const { result } = renderHook(() => useScrollOffsetTop<HTMLDivElement>(defaultOffset));
34+
const { result } = renderHook(() => useScrollOffsetTop(defaultOffset));
3735
setScrollY(defaultOffset + 10);
3836
expect(result.current.offsetTop).toBe(true);
3937
});
@@ -45,10 +43,10 @@ describe('useScrollOffsetTop()', () => {
4543

4644
Object.defineProperty(mockElement, 'offsetTop', { value: elementOffsetTop, writable: false });
4745

48-
const { result } = renderHook(() => useScrollOffsetTop<HTMLDivElement>(0));
46+
const { result } = renderHook(() => useScrollOffsetTop(0));
4947

5048
act(() => {
51-
(result.current.elementRef as MutableRefObject<HTMLDivElement>).current = mockElement;
49+
result.current.elementRef.current = mockElement;
5250
});
5351

5452
setScrollY(elementOffsetTop - 1);
@@ -59,7 +57,7 @@ describe('useScrollOffsetTop()', () => {
5957
});
6058

6159
it(`4. Should update offsetTop to ${highlightText.val('false')} when scroll position is less than default value`, () => {
62-
const { result } = renderHook(() => useScrollOffsetTop<HTMLDivElement>(defaultOffset));
60+
const { result } = renderHook(() => useScrollOffsetTop(defaultOffset));
6361
setScrollY(defaultOffset - 1);
6462
expect(result.current.offsetTop).toBe(false);
6563
});

packages/minimal-shared/src/hooks/use-scroll-offset-top/use-scroll-offset-top.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ import { useRef, useState, useEffect, useCallback } from 'react';
2626

2727
export type UseScrollOffsetTopReturn<T> = {
2828
offsetTop: boolean;
29-
elementRef: RefObject<T>;
29+
elementRef: RefObject<T | null>;
3030
};
3131

3232
export function useScrollOffsetTop<T extends HTMLElement>(
3333
defaultValue: number = 0
3434
): UseScrollOffsetTopReturn<T> {
35-
const elementRef = useRef<T | null>(null);
35+
const elementRef = useRef<T>(null);
3636

3737
const [offsetTop, setOffsetTop] = useState<boolean>(false);
3838

packages/minimal-shared/src/utils/refs/refs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function mergeRefs<T>(refs: (React.Ref<T> | undefined | null)[]): React.R
1515
}
1616
// Handle object refs with 'current' property
1717
else if ('current' in ref) {
18-
(ref as React.MutableRefObject<T | null>).current = value;
18+
(ref as React.RefObject<T | null>).current = value;
1919
}
2020
}
2121
};

0 commit comments

Comments
 (0)