UNPKG

6.72 kBTypeScriptView Raw
1import React, { ForwardedRef, HTMLAttributes, MutableRefObject, EffectCallback, RefObject, Dispatch } from "react";
2import { AriaLabelingProps, DOMProps, FocusableElement, Orientation } from "@react-types/shared";
3export const useLayoutEffect: typeof React.useLayoutEffect;
4/**
5 * If a default is not provided, generate an id.
6 * @param defaultId - Default component id.
7 */
8export function useId(defaultId?: string): string;
9/**
10 * Merges two ids.
11 * Different ids will trigger a side-effect and re-render components hooked up with `useId`.
12 */
13export function mergeIds(idA: string, idB: string): string;
14/**
15 * Used to generate an id, and after render, check if that id is rendered so we know
16 * if we can use it in places such as labelledby.
17 * @param depArray - When to recalculate if the id is in the DOM.
18 */
19export function useSlotId(depArray?: ReadonlyArray<any>): string;
20/**
21 * Calls all functions in the order they were chained with the same arguments.
22 */
23export function chain(...callbacks: any[]): (...args: any[]) => void;
24interface Props {
25 [key: string]: any;
26}
27type TupleTypes<T> = {
28 [P in keyof T]: T[P];
29} extends {
30 [key: number]: infer V;
31} ? V : never;
32type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
33/**
34 * Merges multiple props objects together. Event handlers are chained,
35 * classNames are combined, and ids are deduplicated - different ids
36 * will trigger a side-effect and re-render components hooked up with `useId`.
37 * For all other props, the last prop object overrides all previous ones.
38 * @param args - Multiple sets of props to merge together.
39 */
40export function mergeProps<T extends Props[]>(...args: T): UnionToIntersection<TupleTypes<T>>;
41/**
42 * Merges multiple refs into one. Works with either callback or object refs.
43 */
44export function mergeRefs<T>(...refs: ForwardedRef<T>[]): ForwardedRef<T>;
45interface Options {
46 /**
47 * If labelling associated aria properties should be included in the filter.
48 */
49 labelable?: boolean;
50 /**
51 * A Set of other property names that should be included in the filter.
52 */
53 propNames?: Set<string>;
54}
55/**
56 * Filters out all props that aren't valid DOM props or defined via override prop obj.
57 * @param props - The component props to be filtered.
58 * @param opts - Props to override.
59 */
60export function filterDOMProps(props: DOMProps & AriaLabelingProps, opts?: Options): DOMProps & AriaLabelingProps;
61export function focusWithoutScrolling(element: FocusableElement): void;
62export function getOffset(element: any, reverse: any, orientation?: string): any;
63export function runAfterTransition(fn: () => void): void;
64interface UseDrag1DProps {
65 containerRef: MutableRefObject<HTMLElement>;
66 reverse?: boolean;
67 orientation?: Orientation;
68 onHover?: (hovered: boolean) => void;
69 onDrag?: (dragging: boolean) => void;
70 onPositionChange?: (position: number) => void;
71 onIncrement?: () => void;
72 onDecrement?: () => void;
73 onIncrementToMax?: () => void;
74 onDecrementToMin?: () => void;
75 onCollapseToggle?: () => void;
76}
77export function useDrag1D(props: UseDrag1DProps): HTMLAttributes<HTMLElement>;
78interface GlobalListeners {
79 addGlobalListener<K extends keyof DocumentEventMap>(el: EventTarget, type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
80 addGlobalListener(el: EventTarget, type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
81 removeGlobalListener<K extends keyof DocumentEventMap>(el: EventTarget, type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
82 removeGlobalListener(el: EventTarget, type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
83 removeAllGlobalListeners(): void;
84}
85export function useGlobalListeners(): GlobalListeners;
86/**
87 * Merges aria-label and aria-labelledby into aria-labelledby when both exist.
88 * @param props - Aria label props.
89 * @param defaultLabel - Default value for aria-label when not present.
90 */
91export function useLabels(props: DOMProps & AriaLabelingProps, defaultLabel?: string): DOMProps & AriaLabelingProps;
92/**
93 * Offers an object ref for a given callback ref or an object ref. Especially
94 * helfpul when passing forwarded refs (created using `React.forwardRef`) to
95 * React Aria Hooks.
96 *
97 * @param forwardedRef The original ref intended to be used.
98 * @returns An object ref that updates the given ref.
99 * @see https://reactjs.org/docs/forwarding-refs.html
100 */
101export function useObjectRef<T>(forwardedRef?: ((instance: T | null) => void) | MutableRefObject<T | null> | null): MutableRefObject<T>;
102export function useUpdateEffect(effect: EffectCallback, dependencies: any[]): void;
103type useResizeObserverOptionsType<T> = {
104 ref: RefObject<T | undefined> | undefined;
105 onResize: () => void;
106};
107export function useResizeObserver<T extends Element>(options: useResizeObserverOptionsType<T>): void;
108interface ContextValue<T> {
109 ref?: MutableRefObject<T>;
110}
111export function useSyncRef<T>(context: ContextValue<T>, ref: RefObject<T>): void;
112export function getScrollParent(node: Element): Element;
113interface ViewportSize {
114 width: number;
115 height: number;
116}
117export function useViewportSize(): ViewportSize;
118export function useDescription(description: string): AriaLabelingProps;
119export function isMac(): boolean;
120export function isIPhone(): boolean;
121export function isIPad(): boolean;
122export function isIOS(): boolean;
123export function isAppleDevice(): boolean;
124export function isWebKit(): boolean;
125export function isChrome(): any;
126export function isAndroid(): any;
127export function useEvent<K extends keyof GlobalEventHandlersEventMap>(ref: RefObject<EventTarget>, event: K, handler: (this: Document, ev: GlobalEventHandlersEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
128type SetValueAction<S> = (prev: S) => Generator<any, void, unknown>;
129export function useValueEffect<S>(defaultValue: S | (() => S)): [S, Dispatch<SetValueAction<S>>];
130/**
131 * Scrolls `scrollView` so that `element` is visible.
132 * Similar to `element.scrollIntoView({block: 'nearest'})` (not supported in Edge),
133 * but doesn't affect parents above `scrollView`.
134 */
135export function scrollIntoView(scrollView: HTMLElement, element: HTMLElement): void;
136export function isVirtualClick(event: MouseEvent | PointerEvent): boolean;
137export function isVirtualPointerEvent(event: PointerEvent): boolean;
138export { clamp, snapValueToStep } from '@react-stately/utils';
139
140//# sourceMappingURL=types.d.ts.map