@jamsrui/hooks 0.0.17 → 0.0.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.
@@ -0,0 +1,13 @@
1
+ export { useControlled } from './use-controlled.mjs';
2
+ export { useControlledState } from './use-controlled-state.mjs';
3
+ export { useIsDisabled } from './use-disabled.mjs';
4
+ export { useDisclosure } from './use-disclosure.mjs';
5
+ export { useFocus } from './use-focus.mjs';
6
+ export { useFocusVisible } from './use-focus-visible.mjs';
7
+ export { useHover } from './use-hover.mjs';
8
+ export { useMergeRefs } from './use-merge-refs.mjs';
9
+ export { useIsMobile } from './use-mobile.mjs';
10
+ export { usePress } from './use-press.mjs';
11
+ export { useRenderElement } from './use-render-element.mjs';
12
+ import 'react';
13
+ import '@jamsrui/utils';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a
3
+ * prop or avoid re-executing effects when passed as a dependency
4
+ */
5
+ declare function useCallbackRef<T extends (...args: any[]) => any>(callback: T | undefined): T;
6
+
7
+ export { useCallbackRef };
@@ -0,0 +1,9 @@
1
+ import * as react from 'react';
2
+
3
+ declare function useControlledState<T>({ defaultProp, onChange, prop, }: {
4
+ defaultProp?: T;
5
+ prop?: T;
6
+ onChange?: (state: T) => void;
7
+ }): readonly [T, react.Dispatch<react.SetStateAction<T>>];
8
+
9
+ export { useControlledState };
@@ -0,0 +1,21 @@
1
+ interface UseControlledProps<T = unknown> {
2
+ /**
3
+ * Holds the component value when it's controlled.
4
+ */
5
+ controlled: T | undefined;
6
+ /**
7
+ * The default value when uncontrolled.
8
+ */
9
+ default: T | undefined;
10
+ /**
11
+ * The component name displayed in warnings.
12
+ */
13
+ name: string;
14
+ /**
15
+ * The name of the state variable displayed in warnings.
16
+ */
17
+ state?: string;
18
+ }
19
+ declare function useControlled<T = unknown>({ controlled, default: defaultProp, name, state, }: UseControlledProps<T>): [T, (newValue: T | ((prevValue: T) => T)) => void];
20
+
21
+ export { type UseControlledProps, useControlled };
@@ -0,0 +1,12 @@
1
+ import * as react from 'react';
2
+
3
+ type UseIsDisableProps = {
4
+ isDisabled: boolean;
5
+ isFormControl: boolean;
6
+ };
7
+ declare const useIsDisabled: <T extends HTMLElement>(props: UseIsDisableProps) => {
8
+ ref: react.RefObject<T | null>;
9
+ isDisabled: boolean;
10
+ };
11
+
12
+ export { useIsDisabled };
@@ -0,0 +1,11 @@
1
+ import * as react from 'react';
2
+
3
+ declare const useDisclosure: (defaultOpen?: boolean) => {
4
+ onToggle: () => void;
5
+ isOpen: boolean;
6
+ setIsOpen: react.Dispatch<react.SetStateAction<boolean>>;
7
+ onOpen: () => void;
8
+ onClose: () => void;
9
+ };
10
+
11
+ export { useDisclosure };
@@ -0,0 +1,11 @@
1
+ import * as react from 'react';
2
+
3
+ type UseFocusVisibleOptions = {
4
+ isDisabled?: boolean;
5
+ };
6
+ declare const useFocusVisible: <T extends HTMLElement>(options?: UseFocusVisibleOptions) => {
7
+ ref: react.RefObject<T | null>;
8
+ isFocusVisible: boolean;
9
+ };
10
+
11
+ export { type UseFocusVisibleOptions, useFocusVisible };
@@ -0,0 +1,13 @@
1
+ import * as react from 'react';
2
+
3
+ declare const useFocus: <T extends HTMLElement>(props: useFocus.Props) => {
4
+ ref: react.RefObject<T | null>;
5
+ isFocused: boolean;
6
+ };
7
+ declare namespace useFocus {
8
+ interface Props {
9
+ isDisabled?: boolean;
10
+ }
11
+ }
12
+
13
+ export { useFocus };
@@ -0,0 +1,13 @@
1
+ import * as react from 'react';
2
+
3
+ type UseHoverOptions = {
4
+ enterDelay?: number;
5
+ exitDelay?: number;
6
+ isDisabled?: boolean;
7
+ };
8
+ declare const useHover: <T extends HTMLElement>(options?: UseHoverOptions) => {
9
+ ref: react.RefObject<T | null>;
10
+ isHovered: boolean;
11
+ };
12
+
13
+ export { type UseHoverOptions, useHover };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Merges an array of refs into a single memoized callback ref or `null`.
3
+ */
4
+ declare function useMergeRefs<Instance>(refs: Array<React.Ref<Instance> | undefined>): null | React.RefCallback<Instance>;
5
+
6
+ export { useMergeRefs };
@@ -0,0 +1,3 @@
1
+ declare function useIsMobile(): boolean;
2
+
3
+ export { useIsMobile };
@@ -0,0 +1,16 @@
1
+ import * as react from 'react';
2
+
3
+ declare function usePress(props?: {
4
+ isDisabled?: boolean;
5
+ }): {
6
+ isPressed: boolean;
7
+ ref: react.RefObject<HTMLElement | null>;
8
+ isPressing: boolean;
9
+ };
10
+ declare namespace usePress {
11
+ interface UsePressProps {
12
+ isDisabled?: boolean;
13
+ }
14
+ }
15
+
16
+ export { usePress };
@@ -0,0 +1,15 @@
1
+ import react__default from 'react';
2
+ import { UIProps } from '@jamsrui/utils';
3
+
4
+ declare const useRenderElement: <TagName extends keyof react__default.JSX.IntrinsicElements>(element: TagName, params: useRenderElement.Parameters<TagName>) => react__default.ReactElement;
5
+ declare namespace useRenderElement {
6
+ interface Parameters<TagName extends keyof react__default.JSX.IntrinsicElements> {
7
+ props: UIProps<TagName> | UIProps<TagName>[];
8
+ }
9
+ interface ComponentProps {
10
+ className?: string;
11
+ render?: react__default.ReactElement;
12
+ }
13
+ }
14
+
15
+ export { useRenderElement };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@jamsrui/hooks",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "peerDependencies": {
5
5
  "react": ">=19"
6
6
  },
7
7
  "dependencies": {
8
- "@jamsrui/utils": "^0.0.17"
8
+ "@jamsrui/utils": "^0.0.18"
9
9
  },
10
10
  "exports": {
11
11
  ".": {