@trackunit/react-components 0.1.119 → 0.1.124

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.1.119",
3
+ "version": "0.1.124",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -12,7 +12,7 @@
12
12
  "@trackunit/css-core": "0.0.88",
13
13
  "@trackunit/tailwind-styled-components": "0.0.58",
14
14
  "@trackunit/ui-design-tokens": "0.0.72",
15
- "@trackunit/ui-icons": "0.0.68",
15
+ "@trackunit/ui-icons": "0.0.69",
16
16
  "date-fns": "2.29.3",
17
17
  "lodash": "4.17.21",
18
18
  "react": "18.2.0",
@@ -20,7 +20,8 @@
20
20
  "react-helmet-async": "1.3.0",
21
21
  "react-router-dom": "6.11.2",
22
22
  "react-use": "17.4.0",
23
- "react-useportal": "1.0.17"
23
+ "react-useportal": "1.0.17",
24
+ "zod": "3.14.1"
24
25
  },
25
26
  "module": "./index.js",
26
27
  "main": "./index.cjs",
@@ -10,14 +10,6 @@ export interface MenuItemProps extends CommonProps {
10
10
  * If you use this prop, the label prop will be ignored.
11
11
  */
12
12
  children?: React.ReactNode;
13
- /**
14
- * Additional tailwind classes to be applied to the component.
15
- */
16
- className?: string;
17
- /**
18
- * Test id to be used for the component.
19
- */
20
- dataTestId?: string;
21
13
  /**
22
14
  * An React element to render before the label.
23
15
  * This is typically used to render an icon.
@@ -0,0 +1,12 @@
1
+ export declare const cvaMenuItem: (props?: ({
2
+ selected?: boolean | null | undefined;
3
+ disabled?: boolean | null | undefined;
4
+ focused?: boolean | null | undefined;
5
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
6
+ export declare const cvaMenuItemLabel: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
7
+ export declare const cvaMenuItemSuffix: (props?: ({
8
+ selected?: boolean | null | undefined;
9
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
10
+ export declare const cvaMenuItemPrefix: (props?: ({
11
+ selected?: boolean | null | undefined;
12
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
@@ -1,17 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { MenuItemProps } from "../MenuItem/MenuItem";
3
+ import { CommonProps } from "../../../common";
3
4
  export interface MenuListItemProps extends MenuItemProps {
4
5
  showDivider?: boolean;
5
6
  }
6
- export interface MenuListProps {
7
- /**
8
- * Additional tailwind classes to be applied to the component.
9
- */
10
- className?: string;
11
- /**
12
- * Test id to be used for the component.
13
- */
14
- dataTestId?: string;
7
+ export interface MenuListProps extends CommonProps {
15
8
  /**
16
9
  * List of menu items to be rendered.
17
10
  */
@@ -0,0 +1,4 @@
1
+ export declare const cvaMenuList: (props?: ({
2
+ stickyHeader?: boolean | null | undefined;
3
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
4
+ export declare const cvaMenuListDivider: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
@@ -0,0 +1 @@
1
+ export declare const cvaMoreMenu: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
@@ -0,0 +1,5 @@
1
+ export declare const cvaModalContainer: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
2
+ export declare const cvaModalCard: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
3
+ export declare const cvaModalBackdrop: (props?: ({
4
+ show?: boolean | null | undefined;
5
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
@@ -0,0 +1,9 @@
1
+ export declare const cvaText: (props?: ({
2
+ align?: "left" | "right" | "center" | null | undefined;
3
+ italic?: boolean | null | undefined;
4
+ uppercase?: boolean | null | undefined;
5
+ underline?: boolean | null | undefined;
6
+ weight?: "normal" | "bold" | "thick" | null | undefined;
7
+ size?: "small" | "medium" | "large" | null | undefined;
8
+ color?: "default" | "subtleInverted" | "subtle" | "inverted" | null | undefined;
9
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
@@ -1,9 +1,9 @@
1
+ export * from "./localStorage/useLocalStorage";
2
+ export * from "./localStorage/useLocalStorageReducer";
1
3
  export * from "./useClickOutside";
2
4
  export * from "./useDebounce";
3
5
  export * from "./useDevicePixelRatio";
4
6
  export * from "./useHover";
5
7
  export * from "./useIsFirstRender";
6
- export * from "./useLocalStorage";
7
- export * from "./useLocalStorageReducer";
8
8
  export * from "./useResize";
9
9
  export * from "./useTimeout";
@@ -0,0 +1,9 @@
1
+ import { LocalStorageParams } from "./types";
2
+ /**
3
+ * Initializes the state from local storage, parsing and validating it if a Zod schema is provided.
4
+ *
5
+ * @template State - The type of the state stored in local storage.
6
+ * @param {Omit<LocalStorageParams<State>, "state">} params - The parameters for initializing the local storage state.
7
+ * @returns {State} - The initialized state.
8
+ */
9
+ export declare const initLocalStorageState: <State>({ key, defaultState, schema, }: Omit<LocalStorageParams<State>, "state">) => State;
@@ -0,0 +1,27 @@
1
+ import { ZodType } from "zod";
2
+ export interface LocalStorageParams<State> {
3
+ /**
4
+ * The key used to store the value in local storage.
5
+ */
6
+ key: string;
7
+ /**
8
+ * The default state value.
9
+ */
10
+ defaultState: State;
11
+ /**
12
+ * Optional schema for validating the state.
13
+ */
14
+ schema?: ZodType<State>;
15
+ }
16
+ export interface LocalStorageCallbacks {
17
+ /**
18
+ * Optional callback function called when validation fails.
19
+ *
20
+ * @param error - The validation error object.
21
+ */
22
+ onValidationFailed?: (error: unknown) => void;
23
+ /**
24
+ * Optional callback function called when validation succeeds.
25
+ */
26
+ onValidationSuccessful?: () => void;
27
+ }
@@ -0,0 +1,10 @@
1
+ import { Dispatch, SetStateAction } from "react";
2
+ import { LocalStorageCallbacks, LocalStorageParams } from "./types";
3
+ /**
4
+ * Works like a normal useState, but saves to local storage and has optional schema validation.
5
+ *
6
+ * @template State - The type of the value stored in local storage.
7
+ * @param {Omit<LocalStorageParams<State>, "state"> & LocalStorageCallbacks} options - The options for useLocalStorage.
8
+ * @returns {[State, Dispatch<SetStateAction<State>>, () => void]} - A tuple containing the current value, a function to update the value, and a function to remove the value from local storage.
9
+ */
10
+ export declare const useLocalStorage: <State>({ key, defaultState, schema, onValidationFailed, onValidationSuccessful, }: Omit<LocalStorageParams<State>, "state"> & LocalStorageCallbacks) => [State, Dispatch<SetStateAction<State>>, () => void];
@@ -0,0 +1,11 @@
1
+ import { LocalStorageCallbacks, LocalStorageParams } from "./types";
2
+ /**
3
+ * Custom hook for synchronizing a state variable with local storage,
4
+ * with optional schema validation and callbacks.
5
+ *
6
+ * @template State - The type of the state variable.
7
+ * @param {LocalStorageParams<State> & LocalStorageCallbacks & { state: State }} params - The parameters for the useLocalStorageEffect hook.
8
+ */
9
+ export declare const useLocalStorageEffect: <State>({ key, state, defaultState, schema, onValidationFailed, onValidationSuccessful, }: LocalStorageParams<State> & LocalStorageCallbacks & {
10
+ state: State;
11
+ }) => void;
@@ -0,0 +1,13 @@
1
+ import { Dispatch } from "react";
2
+ import { LocalStorageCallbacks, LocalStorageParams } from "./types";
3
+ /**
4
+ * Works like a normal useReducer, but saves to local storage and has optional schema validation.
5
+ *
6
+ * @template State - The type of the state.
7
+ * @template Action - The type of the action.
8
+ * @param {LocalStorageParams<State> & LocalStorageCallbacks} params - The parameters for the useLocalStorageReducer function.
9
+ * @returns {[State, Dispatch<Action>]} - A tuple containing the state and the dispatch function.
10
+ */
11
+ export declare const useLocalStorageReducer: <State, Action>({ key, defaultState, reducer, schema, onValidationFailed, onValidationSuccessful, }: {
12
+ reducer: (state: State, action: Action) => State;
13
+ } & LocalStorageParams<State> & LocalStorageCallbacks) => [State, Dispatch<Action>];
@@ -0,0 +1,13 @@
1
+ import { LocalStorageCallbacks, LocalStorageParams } from "./types";
2
+ type ValidateStateOptions<State> = Required<Pick<LocalStorageParams<State>, "schema">> & {
3
+ state: State;
4
+ } & LocalStorageCallbacks;
5
+ /**
6
+ * Validates the state object using a Zod schema.
7
+ *
8
+ * @template State - The type of the state.
9
+ * @param {ValidateStateOptions<State>} params - The parameters for the validateState function.
10
+ * @returns {boolean} - `true` if the state is valid according to the schema, `false` otherwise.
11
+ */
12
+ export declare const validateState: <State>({ state, schema, onValidationFailed, onValidationSuccessful, }: ValidateStateOptions<State>) => boolean;
13
+ export {};
package/src/index.d.ts CHANGED
@@ -3,5 +3,6 @@ export * from "./components";
3
3
  export * from "./components/buttons/shared/Button.variants";
4
4
  export * from "./components/Clickable/Clickable.variants";
5
5
  export * from "./components/Indicator/Indicator.variants";
6
+ export * from "./components/Menu/MenuItem/MenuItem.variants";
6
7
  export * from "./hooks";
7
8
  export * from "./layout";
@@ -1,9 +0,0 @@
1
- import { Dispatch, SetStateAction } from "react";
2
- /**
3
- * The useLocalStorage hook works like useState, but saves to localstorage.
4
- *
5
- * @param {string} key - The key the values is saved under.
6
- * @param {string | null | undefined} initialValue - The initial value for the state/local storage item
7
- * @returns {string | null | undefined} value
8
- */
9
- export declare const useLocalStorage: <TValue = string | null | undefined>(key: string, initialValue?: TValue | undefined) => [TValue | null, Dispatch<SetStateAction<TValue | null>>, () => void];
@@ -1,7 +0,0 @@
1
- import { Dispatch } from "react";
2
- /**
3
- * Wraps a normal useReducer with local storage functionality
4
- *
5
- * @param {string} key - The key the state is saved with in local storage.
6
- */
7
- export declare const useLocalStorageReducer: <State, Action>(key: string, reducer: (state: State, action: Action) => State, initialState: State) => [State, Dispatch<Action>];