@trackunit/react-components 1.22.17 → 1.22.18

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/index.cjs.js CHANGED
@@ -333,7 +333,7 @@ const Tag = ({ className, "data-testid": dataTestId, children, size = "medium",
333
333
  * A component used to display the package name and version in the Storybook docs.
334
334
  */
335
335
  const PackageNameStoryComponent = ({ packageJSON }) => {
336
- return (jsxRuntime.jsxs("div", { className: "flex gap-2", children: [jsxRuntime.jsx(Tag, { color: "neutral", children: packageJSON?.name }), jsxRuntime.jsxs(Tag, { color: "neutral", children: ["v", packageJSON?.version] })] }));
336
+ return (jsxRuntime.jsxs("div", { className: "flex gap-2", children: [jsxRuntime.jsx(Tag, { color: "neutral", children: packageJSON?.name }), packageJSON?.version ? jsxRuntime.jsxs(Tag, { color: "neutral", children: ["v", packageJSON.version] }) : null] }));
337
337
  };
338
338
 
339
339
  const docs = {
@@ -1352,11 +1352,16 @@ const getViewportBreakpointState = () => {
1352
1352
  }), { ...defaultBreakpointState });
1353
1353
  };
1354
1354
  /**
1355
- * A custom React hook that provides real-time information about the current viewport size.
1356
- * ! Consider using `useContainerBreakpoints` instead, and only use this when you need to actually react to the viewport size, not the container size.
1355
+ * Returns real-time boolean flags for each design-token breakpoint based on viewport width.
1357
1356
  *
1358
- * This hook listens to changes in the viewport size and returns an object with boolean values
1359
- * indicating which breakpoints are currently active.
1357
+ * **When to use:**
1358
+ * - Use `useViewportBreakpoints` when you need to respond to the **full viewport width**
1359
+ * — for example, toggling a mobile navigation drawer or switching a global layout shell.
1360
+ * - **Prefer `useContainerBreakpoints`** for component-level responsiveness, as it
1361
+ * responds to the parent container's width and works correctly when a component appears
1362
+ * in different layout contexts (sidebar, main content, widget).
1363
+ * - Pass `{ skip: true }` when you only need the initial value and don't want ongoing
1364
+ * `matchMedia` listeners.
1360
1365
  *
1361
1366
  * @param {object} [options] - Configuration options
1362
1367
  * @param {boolean} [options.skip] - Whether to skip observing for viewport changes (default: false)
@@ -4327,14 +4332,43 @@ const Highlight = ({ className, "data-testid": dataTestId, children, size = "sma
4327
4332
  Highlight.displayName = "Highlight";
4328
4333
 
4329
4334
  /**
4330
- * The useDebounce hook works like useState, but adds a delay where previous values will be ignored.
4335
+ * Returns a debounced copy of `value`: it updates only after `delay` ms without further
4336
+ * changes. Pass whatever changes on each keystroke, tick, or prop update; this hook only
4337
+ * delays the value you read back — it does not own the source of truth or expose a setter.
4338
+ *
4339
+ * ### When to use
4340
+ * Use `useDebounce` to delay expensive operations triggered by rapidly changing values —
4341
+ * search inputs, filter fields, resize observers, or any value that changes faster than
4342
+ * you want to react to it.
4343
+ *
4344
+ * ### When not to use
4345
+ * - When you need to debounce a callback rather than a value — wrap the callback in a
4346
+ * `setTimeout` / `useMemo` pattern instead.
4347
+ * - For throttling (fixed-interval updates) — debounce waits for inactivity, throttle
4348
+ * fires at intervals.
4331
4349
  *
4332
4350
  * @template TValue
4333
- * @param {TValue} value The value to set
4351
+ * @param {TValue} value The value to debounce (the fast-changing source)
4334
4352
  * @param {UseDebounceOptions<TValue>} options The debounce options
4335
4353
  * @param {(debouncedValue: TValue) => void} options.onBounce Callback when the value is debounced
4336
4354
  * @param {number} options.delay The debounce time
4337
- * @returns {TValue} The latest value received
4355
+ * @returns {TValue} The debounced value (lags behind `value` until the quiet period elapses)
4356
+ * @example
4357
+ * ```tsx
4358
+ * // Debounce a search input before firing a query
4359
+ * const [search, setSearch] = useState("");
4360
+ * const debouncedSearch = useDebounce(search, { delay: 300 });
4361
+ *
4362
+ * const { data } = useQuery(SearchDocument, {
4363
+ * variables: { query: debouncedSearch },
4364
+ * });
4365
+ *
4366
+ * // With an onBounce callback (e.g. for analytics)
4367
+ * const debouncedValue = useDebounce(inputValue, {
4368
+ * delay: 500,
4369
+ * onBounce: value => logEvent("SearchPerformed", { query: value }),
4370
+ * });
4371
+ * ```
4338
4372
  */
4339
4373
  const useDebounce = (value, { onBounce, delay = 500 } = {}) => {
4340
4374
  const [debouncedValue, setDebouncedValue] = react.useState(value);
@@ -10881,6 +10915,25 @@ const useWebStorage = (storage, { key, defaultState, schema, migration, onValida
10881
10915
  * @param options.onValidationFailed - Optional error callback.
10882
10916
  * @param options.onValidationSuccessful - Optional success callback.
10883
10917
  * @returns {Array} A tuple of [state, setState, reset].
10918
+ * @example
10919
+ * ```tsx
10920
+ * import { z } from "zod";
10921
+ * import { useLocalStorage } from "@trackunit/react-components";
10922
+ *
10923
+ * const preferencesSchema = z.object({
10924
+ * theme: z.enum(["light", "dark"]),
10925
+ * lastVisited: z.date(),
10926
+ * });
10927
+ *
10928
+ * const [preferences, setPreferences, reset] = useLocalStorage({
10929
+ * key: "user-preferences",
10930
+ * defaultState: { theme: "light", lastVisited: new Date() },
10931
+ * schema: preferencesSchema,
10932
+ * });
10933
+ *
10934
+ * setPreferences(prev => ({ ...prev, theme: "dark" }));
10935
+ * reset(); // clear the stored value and fall back to defaultState
10936
+ * ```
10884
10937
  */
10885
10938
  const useLocalStorage = (options) => useWebStorage(globalThis.localStorage, options);
10886
10939
 
package/index.esm.js CHANGED
@@ -331,7 +331,7 @@ const Tag = ({ className, "data-testid": dataTestId, children, size = "medium",
331
331
  * A component used to display the package name and version in the Storybook docs.
332
332
  */
333
333
  const PackageNameStoryComponent = ({ packageJSON }) => {
334
- return (jsxs("div", { className: "flex gap-2", children: [jsx(Tag, { color: "neutral", children: packageJSON?.name }), jsxs(Tag, { color: "neutral", children: ["v", packageJSON?.version] })] }));
334
+ return (jsxs("div", { className: "flex gap-2", children: [jsx(Tag, { color: "neutral", children: packageJSON?.name }), packageJSON?.version ? jsxs(Tag, { color: "neutral", children: ["v", packageJSON.version] }) : null] }));
335
335
  };
336
336
 
337
337
  const docs = {
@@ -1350,11 +1350,16 @@ const getViewportBreakpointState = () => {
1350
1350
  }), { ...defaultBreakpointState });
1351
1351
  };
1352
1352
  /**
1353
- * A custom React hook that provides real-time information about the current viewport size.
1354
- * ! Consider using `useContainerBreakpoints` instead, and only use this when you need to actually react to the viewport size, not the container size.
1353
+ * Returns real-time boolean flags for each design-token breakpoint based on viewport width.
1355
1354
  *
1356
- * This hook listens to changes in the viewport size and returns an object with boolean values
1357
- * indicating which breakpoints are currently active.
1355
+ * **When to use:**
1356
+ * - Use `useViewportBreakpoints` when you need to respond to the **full viewport width**
1357
+ * — for example, toggling a mobile navigation drawer or switching a global layout shell.
1358
+ * - **Prefer `useContainerBreakpoints`** for component-level responsiveness, as it
1359
+ * responds to the parent container's width and works correctly when a component appears
1360
+ * in different layout contexts (sidebar, main content, widget).
1361
+ * - Pass `{ skip: true }` when you only need the initial value and don't want ongoing
1362
+ * `matchMedia` listeners.
1358
1363
  *
1359
1364
  * @param {object} [options] - Configuration options
1360
1365
  * @param {boolean} [options.skip] - Whether to skip observing for viewport changes (default: false)
@@ -4325,14 +4330,43 @@ const Highlight = ({ className, "data-testid": dataTestId, children, size = "sma
4325
4330
  Highlight.displayName = "Highlight";
4326
4331
 
4327
4332
  /**
4328
- * The useDebounce hook works like useState, but adds a delay where previous values will be ignored.
4333
+ * Returns a debounced copy of `value`: it updates only after `delay` ms without further
4334
+ * changes. Pass whatever changes on each keystroke, tick, or prop update; this hook only
4335
+ * delays the value you read back — it does not own the source of truth or expose a setter.
4336
+ *
4337
+ * ### When to use
4338
+ * Use `useDebounce` to delay expensive operations triggered by rapidly changing values —
4339
+ * search inputs, filter fields, resize observers, or any value that changes faster than
4340
+ * you want to react to it.
4341
+ *
4342
+ * ### When not to use
4343
+ * - When you need to debounce a callback rather than a value — wrap the callback in a
4344
+ * `setTimeout` / `useMemo` pattern instead.
4345
+ * - For throttling (fixed-interval updates) — debounce waits for inactivity, throttle
4346
+ * fires at intervals.
4329
4347
  *
4330
4348
  * @template TValue
4331
- * @param {TValue} value The value to set
4349
+ * @param {TValue} value The value to debounce (the fast-changing source)
4332
4350
  * @param {UseDebounceOptions<TValue>} options The debounce options
4333
4351
  * @param {(debouncedValue: TValue) => void} options.onBounce Callback when the value is debounced
4334
4352
  * @param {number} options.delay The debounce time
4335
- * @returns {TValue} The latest value received
4353
+ * @returns {TValue} The debounced value (lags behind `value` until the quiet period elapses)
4354
+ * @example
4355
+ * ```tsx
4356
+ * // Debounce a search input before firing a query
4357
+ * const [search, setSearch] = useState("");
4358
+ * const debouncedSearch = useDebounce(search, { delay: 300 });
4359
+ *
4360
+ * const { data } = useQuery(SearchDocument, {
4361
+ * variables: { query: debouncedSearch },
4362
+ * });
4363
+ *
4364
+ * // With an onBounce callback (e.g. for analytics)
4365
+ * const debouncedValue = useDebounce(inputValue, {
4366
+ * delay: 500,
4367
+ * onBounce: value => logEvent("SearchPerformed", { query: value }),
4368
+ * });
4369
+ * ```
4336
4370
  */
4337
4371
  const useDebounce = (value, { onBounce, delay = 500 } = {}) => {
4338
4372
  const [debouncedValue, setDebouncedValue] = useState(value);
@@ -10879,6 +10913,25 @@ const useWebStorage = (storage, { key, defaultState, schema, migration, onValida
10879
10913
  * @param options.onValidationFailed - Optional error callback.
10880
10914
  * @param options.onValidationSuccessful - Optional success callback.
10881
10915
  * @returns {Array} A tuple of [state, setState, reset].
10916
+ * @example
10917
+ * ```tsx
10918
+ * import { z } from "zod";
10919
+ * import { useLocalStorage } from "@trackunit/react-components";
10920
+ *
10921
+ * const preferencesSchema = z.object({
10922
+ * theme: z.enum(["light", "dark"]),
10923
+ * lastVisited: z.date(),
10924
+ * });
10925
+ *
10926
+ * const [preferences, setPreferences, reset] = useLocalStorage({
10927
+ * key: "user-preferences",
10928
+ * defaultState: { theme: "light", lastVisited: new Date() },
10929
+ * schema: preferencesSchema,
10930
+ * });
10931
+ *
10932
+ * setPreferences(prev => ({ ...prev, theme: "dark" }));
10933
+ * reset(); // clear the stored value and fall back to defaultState
10934
+ * ```
10882
10935
  */
10883
10936
  const useLocalStorage = (options) => useWebStorage(globalThis.localStorage, options);
10884
10937
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "1.22.17",
3
+ "version": "1.22.18",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -13,10 +13,10 @@
13
13
  "@floating-ui/react": "^0.26.25",
14
14
  "string-ts": "^2.0.0",
15
15
  "tailwind-merge": "^2.0.0",
16
- "@trackunit/ui-design-tokens": "1.11.108",
17
- "@trackunit/css-class-variance-utilities": "1.11.111",
18
- "@trackunit/shared-utils": "1.13.111",
19
- "@trackunit/ui-icons": "1.11.107",
16
+ "@trackunit/ui-design-tokens": "1.11.109",
17
+ "@trackunit/css-class-variance-utilities": "1.11.112",
18
+ "@trackunit/shared-utils": "1.13.112",
19
+ "@trackunit/ui-icons": "1.11.108",
20
20
  "es-toolkit": "^1.39.10",
21
21
  "@tanstack/react-virtual": "3.13.12",
22
22
  "dequal": "^2.0.3",
@@ -12,5 +12,24 @@ import type { WebStorageCallbacks, WebStorageOptions } from "./types";
12
12
  * @param options.onValidationFailed - Optional error callback.
13
13
  * @param options.onValidationSuccessful - Optional success callback.
14
14
  * @returns {Array} A tuple of [state, setState, reset].
15
+ * @example
16
+ * ```tsx
17
+ * import { z } from "zod";
18
+ * import { useLocalStorage } from "@trackunit/react-components";
19
+ *
20
+ * const preferencesSchema = z.object({
21
+ * theme: z.enum(["light", "dark"]),
22
+ * lastVisited: z.date(),
23
+ * });
24
+ *
25
+ * const [preferences, setPreferences, reset] = useLocalStorage({
26
+ * key: "user-preferences",
27
+ * defaultState: { theme: "light", lastVisited: new Date() },
28
+ * schema: preferencesSchema,
29
+ * });
30
+ *
31
+ * setPreferences(prev => ({ ...prev, theme: "dark" }));
32
+ * reset(); // clear the stored value and fall back to defaultState
33
+ * ```
15
34
  */
16
35
  export declare const useLocalStorage: <TState>(options: WebStorageOptions<TState> & WebStorageCallbacks<TState>) => readonly [TState, Dispatch<SetStateAction<TState>>, () => void];
@@ -3,14 +3,43 @@ type UseDebounceOptions<TValue> = {
3
3
  delay?: number;
4
4
  };
5
5
  /**
6
- * The useDebounce hook works like useState, but adds a delay where previous values will be ignored.
6
+ * Returns a debounced copy of `value`: it updates only after `delay` ms without further
7
+ * changes. Pass whatever changes on each keystroke, tick, or prop update; this hook only
8
+ * delays the value you read back — it does not own the source of truth or expose a setter.
9
+ *
10
+ * ### When to use
11
+ * Use `useDebounce` to delay expensive operations triggered by rapidly changing values —
12
+ * search inputs, filter fields, resize observers, or any value that changes faster than
13
+ * you want to react to it.
14
+ *
15
+ * ### When not to use
16
+ * - When you need to debounce a callback rather than a value — wrap the callback in a
17
+ * `setTimeout` / `useMemo` pattern instead.
18
+ * - For throttling (fixed-interval updates) — debounce waits for inactivity, throttle
19
+ * fires at intervals.
7
20
  *
8
21
  * @template TValue
9
- * @param {TValue} value The value to set
22
+ * @param {TValue} value The value to debounce (the fast-changing source)
10
23
  * @param {UseDebounceOptions<TValue>} options The debounce options
11
24
  * @param {(debouncedValue: TValue) => void} options.onBounce Callback when the value is debounced
12
25
  * @param {number} options.delay The debounce time
13
- * @returns {TValue} The latest value received
26
+ * @returns {TValue} The debounced value (lags behind `value` until the quiet period elapses)
27
+ * @example
28
+ * ```tsx
29
+ * // Debounce a search input before firing a query
30
+ * const [search, setSearch] = useState("");
31
+ * const debouncedSearch = useDebounce(search, { delay: 300 });
32
+ *
33
+ * const { data } = useQuery(SearchDocument, {
34
+ * variables: { query: debouncedSearch },
35
+ * });
36
+ *
37
+ * // With an onBounce callback (e.g. for analytics)
38
+ * const debouncedValue = useDebounce(inputValue, {
39
+ * delay: 500,
40
+ * onBounce: value => logEvent("SearchPerformed", { query: value }),
41
+ * });
42
+ * ```
14
43
  */
15
44
  export declare const useDebounce: <TValue>(value: TValue, { onBounce, delay }?: UseDebounceOptions<TValue>) => TValue;
16
45
  export {};
@@ -3,11 +3,16 @@ type UseViewportBreakpointsOptions = {
3
3
  skip?: boolean;
4
4
  };
5
5
  /**
6
- * A custom React hook that provides real-time information about the current viewport size.
7
- * ! Consider using `useContainerBreakpoints` instead, and only use this when you need to actually react to the viewport size, not the container size.
6
+ * Returns real-time boolean flags for each design-token breakpoint based on viewport width.
8
7
  *
9
- * This hook listens to changes in the viewport size and returns an object with boolean values
10
- * indicating which breakpoints are currently active.
8
+ * **When to use:**
9
+ * - Use `useViewportBreakpoints` when you need to respond to the **full viewport width**
10
+ * — for example, toggling a mobile navigation drawer or switching a global layout shell.
11
+ * - **Prefer `useContainerBreakpoints`** for component-level responsiveness, as it
12
+ * responds to the parent container's width and works correctly when a component appears
13
+ * in different layout contexts (sidebar, main content, widget).
14
+ * - Pass `{ skip: true }` when you only need the initial value and don't want ongoing
15
+ * `matchMedia` listeners.
11
16
  *
12
17
  * @param {object} [options] - Configuration options
13
18
  * @param {boolean} [options.skip] - Whether to skip observing for viewport changes (default: false)