@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.
Files changed (149) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +34 -14
  3. package/dist/components/accordion.d.ts +29 -10
  4. package/dist/components/accordion.js +38 -37
  5. package/dist/components/alert-dialog.d.ts +60 -24
  6. package/dist/components/alert-dialog.js +69 -72
  7. package/dist/components/alert.d.ts +27 -15
  8. package/dist/components/alert.js +29 -31
  9. package/dist/components/aspect-ratio.d.ts +8 -4
  10. package/dist/components/aspect-ratio.js +7 -5
  11. package/dist/components/avatar.d.ts +17 -6
  12. package/dist/components/avatar.js +19 -17
  13. package/dist/components/badge.d.ts +21 -14
  14. package/dist/components/badge.js +19 -22
  15. package/dist/components/breadcrumb.d.ts +35 -12
  16. package/dist/components/breadcrumb.js +48 -54
  17. package/dist/components/button-group.d.ts +29 -14
  18. package/dist/components/button-group.js +27 -32
  19. package/dist/components/button.d.ts +35 -25
  20. package/dist/components/button.js +50 -48
  21. package/dist/components/calendar.d.ts +24 -9
  22. package/dist/components/calendar.js +92 -98
  23. package/dist/components/card.d.ts +34 -10
  24. package/dist/components/card.js +39 -37
  25. package/dist/components/carousel.d.ts +55 -24
  26. package/dist/components/carousel.js +113 -130
  27. package/dist/components/chart.d.ts +72 -36
  28. package/dist/components/chart.js +154 -166
  29. package/dist/components/checkbox-cards.d.ts +15 -8
  30. package/dist/components/checkbox-cards.js +22 -25
  31. package/dist/components/checkbox-group.d.ts +16 -8
  32. package/dist/components/checkbox-group.js +19 -19
  33. package/dist/components/checkbox.d.ts +9 -4
  34. package/dist/components/checkbox.js +14 -14
  35. package/dist/components/collapsible.d.ts +14 -6
  36. package/dist/components/collapsible.js +18 -16
  37. package/dist/components/command.d.ts +55 -23
  38. package/dist/components/command.js +70 -85
  39. package/dist/components/context-menu.d.ts +72 -22
  40. package/dist/components/context-menu.js +88 -109
  41. package/dist/components/dialog.d.ts +53 -22
  42. package/dist/components/dialog.js +71 -85
  43. package/dist/components/drawer.d.ts +60 -28
  44. package/dist/components/drawer.js +59 -67
  45. package/dist/components/dropdown-menu.d.ts +73 -22
  46. package/dist/components/dropdown-menu.js +95 -112
  47. package/dist/components/empty.d.ts +37 -15
  48. package/dist/components/empty.js +43 -45
  49. package/dist/components/field.d.ts +63 -25
  50. package/dist/components/field.js +88 -104
  51. package/dist/components/form.d.ts +37 -15
  52. package/dist/components/form.js +65 -70
  53. package/dist/components/hover-card.d.ts +21 -7
  54. package/dist/components/hover-card.js +24 -24
  55. package/dist/components/input-group.d.ts +53 -28
  56. package/dist/components/input-group.js +63 -77
  57. package/dist/components/input-number.d.ts +28 -7
  58. package/dist/components/input-number.js +55 -59
  59. package/dist/components/input-otp.d.ts +24 -10
  60. package/dist/components/input-otp.js +33 -37
  61. package/dist/components/input-password.d.ts +12 -5
  62. package/dist/components/input-password.js +31 -32
  63. package/dist/components/input-search.d.ts +18 -8
  64. package/dist/components/input-search.js +43 -41
  65. package/dist/components/input.d.ts +10 -4
  66. package/dist/components/input.js +9 -7
  67. package/dist/components/item.d.ts +69 -32
  68. package/dist/components/item.js +89 -92
  69. package/dist/components/kbd.d.ts +13 -5
  70. package/dist/components/kbd.js +13 -11
  71. package/dist/components/label.d.ts +9 -4
  72. package/dist/components/label.js +9 -7
  73. package/dist/components/menubar.d.ts +80 -23
  74. package/dist/components/menubar.js +97 -118
  75. package/dist/components/native-select.d.ts +16 -6
  76. package/dist/components/native-select.js +25 -26
  77. package/dist/components/navigation-menu.d.ts +36 -12
  78. package/dist/components/navigation-menu.js +60 -75
  79. package/dist/components/pagination.d.ts +35 -14
  80. package/dist/components/pagination.js +54 -69
  81. package/dist/components/popover.d.ts +24 -8
  82. package/dist/components/popover.js +28 -28
  83. package/dist/components/progress-circle.d.ts +106 -88
  84. package/dist/components/progress-circle.js +106 -138
  85. package/dist/components/progress.d.ts +10 -4
  86. package/dist/components/progress.js +14 -14
  87. package/dist/components/radio-cards.d.ts +10 -4
  88. package/dist/components/radio-cards.js +22 -23
  89. package/dist/components/radio-group.d.ts +13 -5
  90. package/dist/components/radio-group.js +18 -16
  91. package/dist/components/radio.d.ts +12 -5
  92. package/dist/components/radio.js +10 -8
  93. package/dist/components/resizable.d.ts +18 -7
  94. package/dist/components/resizable.js +22 -22
  95. package/dist/components/scroll-area.d.ts +33 -20
  96. package/dist/components/scroll-area.js +84 -88
  97. package/dist/components/select.d.ts +50 -16
  98. package/dist/components/select.js +77 -96
  99. package/dist/components/separator.d.ts +29 -19
  100. package/dist/components/separator.js +36 -34
  101. package/dist/components/sheet.d.ts +62 -29
  102. package/dist/components/sheet.js +79 -100
  103. package/dist/components/sidebar.d.ts +160 -66
  104. package/dist/components/sidebar.js +294 -336
  105. package/dist/components/skeleton.d.ts +9 -4
  106. package/dist/components/skeleton.js +8 -6
  107. package/dist/components/slider.d.ts +13 -4
  108. package/dist/components/slider.js +34 -40
  109. package/dist/components/sonner.d.ts +10 -7
  110. package/dist/components/sonner.js +16 -14
  111. package/dist/components/spinner.d.ts +12 -5
  112. package/dist/components/spinner.js +33 -35
  113. package/dist/components/switch.d.ts +9 -4
  114. package/dist/components/switch.js +13 -11
  115. package/dist/components/table.d.ts +37 -11
  116. package/dist/components/table.js +47 -45
  117. package/dist/components/tabs.d.ts +21 -7
  118. package/dist/components/tabs.js +24 -22
  119. package/dist/components/textarea.d.ts +9 -4
  120. package/dist/components/textarea.js +8 -6
  121. package/dist/components/toggle-group.d.ts +24 -9
  122. package/dist/components/toggle-group.js +41 -42
  123. package/dist/components/toggle.d.ts +25 -17
  124. package/dist/components/toggle.js +30 -28
  125. package/dist/components/tooltip.d.ts +24 -8
  126. package/dist/components/tooltip.js +29 -32
  127. package/dist/hooks/use-animated-value.d.ts +4 -1
  128. package/dist/hooks/use-animated-value.js +57 -36
  129. package/dist/hooks/use-copy-to-clipboard.d.ts +11 -5
  130. package/dist/hooks/use-copy-to-clipboard.js +39 -20
  131. package/dist/hooks/use-is-mobile.d.ts +4 -1
  132. package/dist/hooks/use-is-mobile.js +21 -1
  133. package/dist/hooks/use-media-query.d.ts +4 -1
  134. package/dist/hooks/use-media-query.js +45 -18
  135. package/dist/hooks/use-mutation-observer.d.ts +6 -2
  136. package/dist/hooks/use-mutation-observer.js +34 -16
  137. package/dist/hooks/use-pagination.d.ts +22 -14
  138. package/dist/hooks/use-pagination.js +100 -49
  139. package/dist/index.d.ts +69 -130
  140. package/dist/index.js +11 -11
  141. package/dist/primitives/checkbox-group.d.ts +105 -83
  142. package/dist/primitives/checkbox-group.js +111 -84
  143. package/dist/primitives/input-number.d.ts +51 -40
  144. package/dist/primitives/input-number.js +483 -350
  145. package/dist/primitives/input.d.ts +48 -42
  146. package/dist/primitives/input.js +65 -43
  147. package/dist/primitives/progress-circle.d.ts +79 -48
  148. package/dist/primitives/progress-circle.js +154 -105
  149. 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
- export declare function useMediaQuery(query: string): boolean;
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
- const [matches, setMatches] = useState(()=>{
5
- if ("u" > typeof window && "function" == typeof window.matchMedia) return window.matchMedia(query).matches;
6
- return false;
7
- });
8
- useEffect(()=>{
9
- if ("u" < typeof window) return;
10
- const mediaQueryList = window.matchMedia(query);
11
- const onChange = (event)=>{
12
- setMatches(event.matches);
13
- };
14
- mediaQueryList.addEventListener("change", onChange);
15
- return ()=>{
16
- mediaQueryList.removeEventListener("change", onChange);
17
- };
18
- }, [
19
- query
20
- ]);
21
- return matches;
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 type { RefObject } from "react";
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
- export declare function useMutationObserver(ref: RefObject<HTMLElement | null>, callback: MutationCallback, options?: MutationObserverInit): void;
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
- attributes: true,
5
- characterData: true,
6
- childList: true,
7
- subtree: true
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
- useEffect(()=>{
11
- if (!ref.current) return;
12
- const observer = new MutationObserver(callback);
13
- observer.observe(ref.current, options);
14
- return ()=>{
15
- observer.disconnect();
16
- };
17
- }, [
18
- ref,
19
- callback,
20
- options
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
- export interface UsePaginationProps {
2
- /** Current active page number. */
3
- currentPage: number;
4
- /** Number of results displayed per page. */
5
- resultsPerPage: number;
6
- /**
7
- * Number of sibling pages to show on each side of the current page.
8
- * Defaults to 1.
9
- */
10
- siblingPagesCount?: number;
11
- /** Total number of results across all pages. */
12
- totalResults: number;
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
- export declare const ELLIPSIS = "\u2022\u2022\u2022";
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
- export declare function usePagination({ currentPage, resultsPerPage, siblingPagesCount, totalResults, }: UsePaginationProps): (number | string)[];
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
- const createRange = (start, end)=>{
5
- const length = end - start + 1;
6
- return Array.from({
7
- length
8
- }, (_, index)=>start + index);
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
- return useMemo(()=>{
12
- const totalPages = Math.ceil(totalResults / Math.floor(resultsPerPage));
13
- if (totalPages <= 0) return [];
14
- const visiblePageNumbers = siblingPagesCount + 5;
15
- if (visiblePageNumbers >= totalPages) return createRange(1, totalPages);
16
- const leftSiblingIndex = Math.max(currentPage - siblingPagesCount, 1);
17
- const rightSiblingIndex = Math.min(currentPage + siblingPagesCount, totalPages);
18
- const shouldShowLeftEllipsis = leftSiblingIndex > 2;
19
- const shouldShowRightEllipsis = rightSiblingIndex < totalPages - 2;
20
- const firstPage = 1;
21
- const lastPage = totalPages;
22
- if (!shouldShowLeftEllipsis && shouldShowRightEllipsis) {
23
- const leftRange = createRange(1, 3 + 2 * siblingPagesCount);
24
- return [
25
- ...leftRange,
26
- ELLIPSIS,
27
- lastPage
28
- ];
29
- }
30
- if (shouldShowLeftEllipsis && !shouldShowRightEllipsis) {
31
- const rightRange = createRange(totalPages - (3 + 2 * siblingPagesCount) + 1, totalPages);
32
- return [
33
- firstPage,
34
- ELLIPSIS,
35
- ...rightRange
36
- ];
37
- }
38
- if (shouldShowLeftEllipsis && shouldShowRightEllipsis) {
39
- const middleRange = createRange(leftSiblingIndex, rightSiblingIndex);
40
- return [
41
- firstPage,
42
- ELLIPSIS,
43
- ...middleRange,
44
- ELLIPSIS,
45
- lastPage
46
- ];
47
- }
48
- return [];
49
- }, [
50
- totalResults,
51
- resultsPerPage,
52
- siblingPagesCount,
53
- currentPage
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 };