@codefast/ui 0.3.11-canary.1 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +34 -14
- package/dist/components/accordion.d.ts +29 -10
- package/dist/components/accordion.js +38 -37
- package/dist/components/alert-dialog.d.ts +60 -24
- package/dist/components/alert-dialog.js +69 -72
- package/dist/components/alert.d.ts +27 -15
- package/dist/components/alert.js +29 -31
- package/dist/components/aspect-ratio.d.ts +8 -4
- package/dist/components/aspect-ratio.js +7 -5
- package/dist/components/avatar.d.ts +17 -6
- package/dist/components/avatar.js +19 -17
- package/dist/components/badge.d.ts +21 -14
- package/dist/components/badge.js +19 -22
- package/dist/components/breadcrumb.d.ts +35 -12
- package/dist/components/breadcrumb.js +48 -54
- package/dist/components/button-group.d.ts +29 -14
- package/dist/components/button-group.js +27 -32
- package/dist/components/button.d.ts +35 -25
- package/dist/components/button.js +50 -48
- package/dist/components/calendar.d.ts +24 -9
- package/dist/components/calendar.js +92 -98
- package/dist/components/card.d.ts +34 -10
- package/dist/components/card.js +39 -37
- package/dist/components/carousel.d.ts +55 -24
- package/dist/components/carousel.js +113 -130
- package/dist/components/chart.d.ts +72 -36
- package/dist/components/chart.js +154 -166
- package/dist/components/checkbox-cards.d.ts +15 -8
- package/dist/components/checkbox-cards.js +22 -25
- package/dist/components/checkbox-group.d.ts +16 -8
- package/dist/components/checkbox-group.js +19 -19
- package/dist/components/checkbox.d.ts +9 -4
- package/dist/components/checkbox.js +14 -14
- package/dist/components/collapsible.d.ts +14 -6
- package/dist/components/collapsible.js +18 -16
- package/dist/components/command.d.ts +55 -23
- package/dist/components/command.js +70 -85
- package/dist/components/context-menu.d.ts +72 -22
- package/dist/components/context-menu.js +88 -109
- package/dist/components/dialog.d.ts +53 -22
- package/dist/components/dialog.js +71 -85
- package/dist/components/drawer.d.ts +60 -28
- package/dist/components/drawer.js +59 -67
- package/dist/components/dropdown-menu.d.ts +73 -22
- package/dist/components/dropdown-menu.js +95 -112
- package/dist/components/empty.d.ts +37 -15
- package/dist/components/empty.js +43 -45
- package/dist/components/field.d.ts +63 -25
- package/dist/components/field.js +88 -104
- package/dist/components/form.d.ts +37 -15
- package/dist/components/form.js +65 -70
- package/dist/components/hover-card.d.ts +21 -7
- package/dist/components/hover-card.js +24 -24
- package/dist/components/input-group.d.ts +53 -28
- package/dist/components/input-group.js +63 -77
- package/dist/components/input-number.d.ts +28 -7
- package/dist/components/input-number.js +55 -59
- package/dist/components/input-otp.d.ts +24 -10
- package/dist/components/input-otp.js +33 -37
- package/dist/components/input-password.d.ts +12 -5
- package/dist/components/input-password.js +31 -32
- package/dist/components/input-search.d.ts +18 -8
- package/dist/components/input-search.js +43 -41
- package/dist/components/input.d.ts +10 -4
- package/dist/components/input.js +9 -7
- package/dist/components/item.d.ts +69 -32
- package/dist/components/item.js +89 -92
- package/dist/components/kbd.d.ts +13 -5
- package/dist/components/kbd.js +13 -11
- package/dist/components/label.d.ts +9 -4
- package/dist/components/label.js +9 -7
- package/dist/components/menubar.d.ts +80 -23
- package/dist/components/menubar.js +97 -118
- package/dist/components/native-select.d.ts +16 -6
- package/dist/components/native-select.js +25 -26
- package/dist/components/navigation-menu.d.ts +36 -12
- package/dist/components/navigation-menu.js +60 -75
- package/dist/components/pagination.d.ts +35 -14
- package/dist/components/pagination.js +54 -69
- package/dist/components/popover.d.ts +24 -8
- package/dist/components/popover.js +28 -28
- package/dist/components/progress-circle.d.ts +106 -88
- package/dist/components/progress-circle.js +106 -138
- package/dist/components/progress.d.ts +10 -4
- package/dist/components/progress.js +14 -14
- package/dist/components/radio-cards.d.ts +10 -4
- package/dist/components/radio-cards.js +22 -23
- package/dist/components/radio-group.d.ts +13 -5
- package/dist/components/radio-group.js +18 -16
- package/dist/components/radio.d.ts +12 -5
- package/dist/components/radio.js +10 -8
- package/dist/components/resizable.d.ts +18 -7
- package/dist/components/resizable.js +22 -22
- package/dist/components/scroll-area.d.ts +33 -20
- package/dist/components/scroll-area.js +84 -88
- package/dist/components/select.d.ts +50 -16
- package/dist/components/select.js +77 -96
- package/dist/components/separator.d.ts +29 -19
- package/dist/components/separator.js +36 -34
- package/dist/components/sheet.d.ts +62 -29
- package/dist/components/sheet.js +79 -100
- package/dist/components/sidebar.d.ts +160 -66
- package/dist/components/sidebar.js +294 -336
- package/dist/components/skeleton.d.ts +9 -4
- package/dist/components/skeleton.js +8 -6
- package/dist/components/slider.d.ts +13 -4
- package/dist/components/slider.js +34 -40
- package/dist/components/sonner.d.ts +10 -7
- package/dist/components/sonner.js +16 -14
- package/dist/components/spinner.d.ts +12 -5
- package/dist/components/spinner.js +33 -35
- package/dist/components/switch.d.ts +9 -4
- package/dist/components/switch.js +13 -11
- package/dist/components/table.d.ts +37 -11
- package/dist/components/table.js +47 -45
- package/dist/components/tabs.d.ts +21 -7
- package/dist/components/tabs.js +24 -22
- package/dist/components/textarea.d.ts +9 -4
- package/dist/components/textarea.js +8 -6
- package/dist/components/toggle-group.d.ts +24 -9
- package/dist/components/toggle-group.js +41 -42
- package/dist/components/toggle.d.ts +25 -17
- package/dist/components/toggle.js +30 -28
- package/dist/components/tooltip.d.ts +24 -8
- package/dist/components/tooltip.js +29 -32
- package/dist/hooks/use-animated-value.d.ts +4 -1
- package/dist/hooks/use-animated-value.js +57 -36
- package/dist/hooks/use-copy-to-clipboard.d.ts +11 -5
- package/dist/hooks/use-copy-to-clipboard.js +39 -20
- package/dist/hooks/use-is-mobile.d.ts +4 -1
- package/dist/hooks/use-is-mobile.js +21 -1
- package/dist/hooks/use-media-query.d.ts +4 -1
- package/dist/hooks/use-media-query.js +45 -18
- package/dist/hooks/use-mutation-observer.d.ts +6 -2
- package/dist/hooks/use-mutation-observer.js +34 -16
- package/dist/hooks/use-pagination.d.ts +22 -14
- package/dist/hooks/use-pagination.js +100 -49
- package/dist/index.d.ts +69 -130
- package/dist/index.js +11 -11
- package/dist/primitives/checkbox-group.d.ts +105 -83
- package/dist/primitives/checkbox-group.js +111 -84
- package/dist/primitives/input-number.d.ts +51 -40
- package/dist/primitives/input-number.js +483 -350
- package/dist/primitives/input.d.ts +48 -42
- package/dist/primitives/input.js +65 -43
- package/dist/primitives/progress-circle.d.ts +79 -48
- package/dist/primitives/progress-circle.js +154 -105
- package/package.json +6 -7
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/hooks/use-media-query.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Subscribe to a CSS media query and receive its match state.
|
|
3
4
|
*
|
|
@@ -12,4 +13,6 @@
|
|
|
12
13
|
* const isNarrow = useMediaQuery("(max-width: 768px)");
|
|
13
14
|
* ```
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
+
declare function useMediaQuery(query: string): boolean;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { useMediaQuery };
|
|
@@ -1,23 +1,50 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
|
+
//#region src/hooks/use-media-query.ts
|
|
4
|
+
/**
|
|
5
|
+
* Subscribe to a CSS media query and receive its match state.
|
|
6
|
+
*
|
|
7
|
+
* Evaluates the query immediately (when supported) and updates on changes
|
|
8
|
+
* via an event listener.
|
|
9
|
+
*
|
|
10
|
+
* @param query - A valid media query string (e.g., "(max-width: 768px)").
|
|
11
|
+
* @returns true when the media query currently matches; otherwise false.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const isNarrow = useMediaQuery("(max-width: 768px)");
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
3
18
|
function useMediaQuery(query) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
/**
|
|
20
|
+
* State to store whether the query matches.
|
|
21
|
+
* The initial value is calculated based on the current window state.
|
|
22
|
+
*/
|
|
23
|
+
const [matches, setMatches] = useState(() => {
|
|
24
|
+
if (typeof window !== "undefined" && typeof window.matchMedia === "function") return window.matchMedia(query).matches;
|
|
25
|
+
return false;
|
|
26
|
+
});
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (typeof window === "undefined") return;
|
|
29
|
+
/**
|
|
30
|
+
* MediaQueryList to evaluate and observe the provided query.
|
|
31
|
+
*/
|
|
32
|
+
const mediaQueryList = window.matchMedia(query);
|
|
33
|
+
/**
|
|
34
|
+
* Update state when the media query status changes.
|
|
35
|
+
*/
|
|
36
|
+
const onChange = (event) => {
|
|
37
|
+
setMatches(event.matches);
|
|
38
|
+
};
|
|
39
|
+
mediaQueryList.addEventListener("change", onChange);
|
|
40
|
+
/**
|
|
41
|
+
* Remove the event listener on unmount or when the query changes.
|
|
42
|
+
*/
|
|
43
|
+
return () => {
|
|
44
|
+
mediaQueryList.removeEventListener("change", onChange);
|
|
45
|
+
};
|
|
46
|
+
}, [query]);
|
|
47
|
+
return matches;
|
|
22
48
|
}
|
|
49
|
+
//#endregion
|
|
23
50
|
export { useMediaQuery };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/use-mutation-observer.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* Observe DOM mutations on a referenced element and invoke a callback.
|
|
4
6
|
*
|
|
@@ -12,4 +14,6 @@ import type { RefObject } from "react";
|
|
|
12
14
|
*
|
|
13
15
|
* @see [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
|
|
14
16
|
*/
|
|
15
|
-
|
|
17
|
+
declare function useMutationObserver(ref: RefObject<HTMLElement | null>, callback: MutationCallback, options?: MutationObserverInit): void;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { useMutationObserver };
|
|
@@ -1,23 +1,41 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
|
+
//#region src/hooks/use-mutation-observer.ts
|
|
4
|
+
/**
|
|
5
|
+
* Default options for MutationObserver observing common mutation types.
|
|
6
|
+
*/
|
|
3
7
|
const defaultOptions = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
attributes: true,
|
|
9
|
+
characterData: true,
|
|
10
|
+
childList: true,
|
|
11
|
+
subtree: true
|
|
8
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Observe DOM mutations on a referenced element and invoke a callback.
|
|
15
|
+
*
|
|
16
|
+
* Attaches a MutationObserver to the provided element reference with the given
|
|
17
|
+
* options and calls the callback whenever mutations occur.
|
|
18
|
+
*
|
|
19
|
+
* @param ref - Ref to the target HTMLElement to observe.
|
|
20
|
+
* @param callback - Mutation callback invoked with observed records.
|
|
21
|
+
* @param options - Observer configuration. Defaults watch attributes, characterData, childList, subtree.
|
|
22
|
+
* @returns void
|
|
23
|
+
*
|
|
24
|
+
* @see [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
|
|
25
|
+
*/
|
|
9
26
|
function useMutationObserver(ref, callback, options = defaultOptions) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!ref.current) return;
|
|
29
|
+
const observer = new MutationObserver(callback);
|
|
30
|
+
observer.observe(ref.current, options);
|
|
31
|
+
return () => {
|
|
32
|
+
observer.disconnect();
|
|
33
|
+
};
|
|
34
|
+
}, [
|
|
35
|
+
ref,
|
|
36
|
+
callback,
|
|
37
|
+
options
|
|
38
|
+
]);
|
|
22
39
|
}
|
|
40
|
+
//#endregion
|
|
23
41
|
export { useMutationObserver };
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
//#region src/hooks/use-pagination.d.ts
|
|
2
|
+
interface UsePaginationProps {
|
|
3
|
+
/** Current active page number. */
|
|
4
|
+
currentPage: number;
|
|
5
|
+
/** Number of results displayed per page. */
|
|
6
|
+
resultsPerPage: number;
|
|
7
|
+
/**
|
|
8
|
+
* Number of sibling pages to show on each side of the current page.
|
|
9
|
+
* Defaults to 1.
|
|
10
|
+
*/
|
|
11
|
+
siblingPagesCount?: number;
|
|
12
|
+
/** Total number of results across all pages. */
|
|
13
|
+
totalResults: number;
|
|
13
14
|
}
|
|
14
15
|
/** Ellipsis marker used to collapse ranges in pagination output. */
|
|
15
|
-
|
|
16
|
+
declare const ELLIPSIS = "\u2022\u2022\u2022";
|
|
16
17
|
/**
|
|
17
18
|
* Compute a pagination structure for result sets.
|
|
18
19
|
*
|
|
@@ -33,4 +34,11 @@ export declare const ELLIPSIS = "\u2022\u2022\u2022";
|
|
|
33
34
|
* });
|
|
34
35
|
* ```
|
|
35
36
|
*/
|
|
36
|
-
|
|
37
|
+
declare function usePagination({
|
|
38
|
+
currentPage,
|
|
39
|
+
resultsPerPage,
|
|
40
|
+
siblingPagesCount,
|
|
41
|
+
totalResults
|
|
42
|
+
}: UsePaginationProps): (number | string)[];
|
|
43
|
+
//#endregion
|
|
44
|
+
export { ELLIPSIS, UsePaginationProps, usePagination };
|
|
@@ -1,56 +1,107 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
|
+
//#region src/hooks/use-pagination.ts
|
|
4
|
+
/** Ellipsis marker used to collapse ranges in pagination output. */
|
|
3
5
|
const ELLIPSIS = "•••";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Generate a numeric range from start to end inclusive.
|
|
8
|
+
*
|
|
9
|
+
* @param start - Starting number (inclusive).
|
|
10
|
+
* @param end - Ending number (inclusive).
|
|
11
|
+
* @returns Array of numbers from start to end.
|
|
12
|
+
*/
|
|
13
|
+
const createRange = (start, end) => {
|
|
14
|
+
const length = end - start + 1;
|
|
15
|
+
return Array.from({ length }, (_, index) => start + index);
|
|
9
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Compute a pagination structure for result sets.
|
|
19
|
+
*
|
|
20
|
+
* Returns a mixed array of page numbers and the `ELLIPSIS` marker representing
|
|
21
|
+
* collapsed ranges. The shape adapts to the total pages and the requested
|
|
22
|
+
* sibling window around the current page.
|
|
23
|
+
*
|
|
24
|
+
* @param props - Pagination options. See {@link UsePaginationProps}.
|
|
25
|
+
* @returns Array of page numbers and `ELLIPSIS` representing the pagination model.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* const paginationRange = usePagination({
|
|
30
|
+
* currentPage: 3,
|
|
31
|
+
* resultsPerPage: 10,
|
|
32
|
+
* siblingPagesCount: 1,
|
|
33
|
+
* totalResults: 100
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
10
37
|
function usePagination({ currentPage, resultsPerPage, siblingPagesCount = 1, totalResults }) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
return useMemo(() => {
|
|
39
|
+
const totalPages = Math.ceil(totalResults / Math.floor(resultsPerPage));
|
|
40
|
+
if (totalPages <= 0) return [];
|
|
41
|
+
/**
|
|
42
|
+
* Case 1: If the number of pages is less than or equal to the visible page
|
|
43
|
+
* numbers, return an array of all page numbers.
|
|
44
|
+
*/
|
|
45
|
+
if (siblingPagesCount + 5 >= totalPages) return createRange(1, totalPages);
|
|
46
|
+
/**
|
|
47
|
+
* Left sibling boundary (min 1).
|
|
48
|
+
*/
|
|
49
|
+
const leftSiblingIndex = Math.max(currentPage - siblingPagesCount, 1);
|
|
50
|
+
/**
|
|
51
|
+
* Right sibling boundary (max totalPages).
|
|
52
|
+
*/
|
|
53
|
+
const rightSiblingIndex = Math.min(currentPage + siblingPagesCount, totalPages);
|
|
54
|
+
/**
|
|
55
|
+
* Whether a left-side ellipsis is needed.
|
|
56
|
+
*/
|
|
57
|
+
const shouldShowLeftEllipsis = leftSiblingIndex > 2;
|
|
58
|
+
/**
|
|
59
|
+
* Whether a right-side ellipsis is needed.
|
|
60
|
+
*/
|
|
61
|
+
const shouldShowRightEllipsis = rightSiblingIndex < totalPages - 2;
|
|
62
|
+
/** First page number (always 1). */
|
|
63
|
+
const firstPage = 1;
|
|
64
|
+
/** Last page number (equals totalPages). */
|
|
65
|
+
const lastPage = totalPages;
|
|
66
|
+
/**
|
|
67
|
+
* Case 2: No left ellipsis, but right ellipsis is necessary.
|
|
68
|
+
* This occurs when the current page is close to the start of the
|
|
69
|
+
* pagination range.
|
|
70
|
+
*/
|
|
71
|
+
if (!shouldShowLeftEllipsis && shouldShowRightEllipsis) return [
|
|
72
|
+
...createRange(1, 3 + 2 * siblingPagesCount),
|
|
73
|
+
ELLIPSIS,
|
|
74
|
+
lastPage
|
|
75
|
+
];
|
|
76
|
+
/**
|
|
77
|
+
* Case 3: No right ellipsis, but left ellipsis is necessary.
|
|
78
|
+
* This occurs when the current page is close to the end of the pagination
|
|
79
|
+
* range.
|
|
80
|
+
*/
|
|
81
|
+
if (shouldShowLeftEllipsis && !shouldShowRightEllipsis) return [
|
|
82
|
+
firstPage,
|
|
83
|
+
ELLIPSIS,
|
|
84
|
+
...createRange(totalPages - (3 + 2 * siblingPagesCount) + 1, totalPages)
|
|
85
|
+
];
|
|
86
|
+
/**
|
|
87
|
+
* Case 4: Both left and right ellipsis are necessary.
|
|
88
|
+
* This occurs when the current page is far enough from both the start and
|
|
89
|
+
* end of the pagination range.
|
|
90
|
+
*/
|
|
91
|
+
if (shouldShowLeftEllipsis && shouldShowRightEllipsis) return [
|
|
92
|
+
firstPage,
|
|
93
|
+
ELLIPSIS,
|
|
94
|
+
...createRange(leftSiblingIndex, rightSiblingIndex),
|
|
95
|
+
ELLIPSIS,
|
|
96
|
+
lastPage
|
|
97
|
+
];
|
|
98
|
+
return [];
|
|
99
|
+
}, [
|
|
100
|
+
totalResults,
|
|
101
|
+
resultsPerPage,
|
|
102
|
+
siblingPagesCount,
|
|
103
|
+
currentPage
|
|
104
|
+
]);
|
|
55
105
|
}
|
|
106
|
+
//#endregion
|
|
56
107
|
export { ELLIPSIS, usePagination };
|