import { CSSProperties, RefObject } from 'react' import { SpringConfig, SpringBaseProps, TransitionKeyProps, State, } from './renderprops-universal' export { SpringConfig, SpringBaseProps, TransitionKeyProps, State } export { config, interpolate } from './renderprops-universal' // hooks are currently web-only export { animated } from './renderprops' /** List from `function getForwardProps` in `src/shared/helpers` */ type ExcludedProps = | 'to' | 'from' | 'config' | 'onStart' | 'onRest' | 'onFrame' | 'children' | 'reset' | 'reverse' | 'force' | 'immediate' | 'delay' | 'attach' | 'destroyed' | 'interpolateTo' | 'ref' | 'lazy' // The config options for an interoplation. It maps out from in "in" type // to an "out" type. export type InterpolationConfig = { range: T[] output: U[] } // The InterpolationChain is either a function that takes a config object // and returns the next chainable type or it is a function that takes in params // and maps out to another InterpolationChain. export interface InterpolationChain { (config: InterpolationConfig): OpaqueInterpolation (interpolator: (params: T) => U): OpaqueInterpolation } // The opaque interpolation masks as its original type but provides to helpers // for chaining the interpolate method and getting its raw value. export type OpaqueInterpolation = { interpolate: InterpolationChain getValue: () => T } & T // Map all keys to our OpaqueInterpolation type which can either be interpreted // as its initial value by "animated.{tag}" or chained with interpolations. export type AnimatedValue = { [P in keyof T]: OpaqueInterpolation } // Make ForwardedProps chainable with interpolate / make it an animated value. export type ForwardedProps = Pick> // NOTE: because of the Partial, this makes a weak type, which can have excess props type InferFrom = T extends { to: infer TTo } ? Partial : Partial> // This is similar to "Omit & B", // but with a delayed evaluation that still allows A to be inferrable type Merge = { [K in keyof A]: K extends keyof B ? B[K] : A[K] } & B export type SetUpdateFn = (ds: Partial>) => void export interface SetUpdateCallbackFn { (ds: Partial>): void; (i: number): Partial>; } // The hooks do emulate React's 'ref' by accepting { ref?: React.RefObject } and // updating it. However, there are no types for Controller, and I assume it is intentionally so. // This is a partial interface for Controller that has only the properties needed for useChain to work. export interface ReactSpringHook { start(): void stop(): void } export function useChain(refs: ReadonlyArray>): void // this looks like it can just be a single overload, but we don't want to allow // timeFrame to be specifiable when timeSteps is explicitly "undefined" export function useChain( refs: ReadonlyArray>, timeSteps: number[], timeFrame?: number ): void export interface HooksBaseProps extends Pick> { /** * Will skip rendering the component if true and write to the dom directly. * @default true * @deprecated */ native?: never // there is an undocumented onKeyframesHalt which passes the controller instance, // so it also cannot be typed unless Controller types are written ref?: React.RefObject } export interface UseSpringBaseProps extends HooksBaseProps { config?: SpringBaseProps['config'] } export type UseSpringProps = Merge< DS & UseSpringBaseProps, { from?: InferFrom /** * Callback when the animation comes to a still-stand */ onRest?(ds: InferFrom): void } > type OverwriteKeys = { [K in keyof A]: K extends keyof B ? B[K] : A[K] }; // there's a third value in the tuple but it's not public API (?) export function useSpring( values: UseSpringProps> ): AnimatedValue>> export function useSpring( getProps: () => UseSpringProps> ): [AnimatedValue>>, SetUpdateFn>] // there's a third value in the tuple but it's not public API (?) export function useSprings( count: number, items: ReadonlyArray, ): ForwardedProps[] // safe to modify (result of .map) export function useSprings( count: number, getProps: (i: number) => UseSpringProps ): [AnimatedValue>[], SetUpdateCallbackFn] // there's a third value in the tuple but it's not public API (?) export function useTrail( count: number, getProps: () => UseSpringProps ): [ForwardedProps[], SetUpdateFn] export function useTrail( count: number, values: UseSpringProps ): ForwardedProps[] // safe to modify (result of .map) export function useTrail( count: number, getProps: () => UseSpringProps ): [AnimatedValue>[], SetUpdateFn] export function useTrail( count: number, values: UseSpringProps ): AnimatedValue>[] // safe to modify (result of .map) export interface UseTransitionProps extends HooksBaseProps { /** * Spring config, or for individual items: fn(item => config) * @default config.default */ config?: SpringConfig | ((item: TItem) => SpringConfig) /** * When true enforces that an item can only occur once instead of allowing two or more items with the same key to co-exist in a stack * @default false */ unique?: boolean /** * Trailing delay in ms */ trail?: number from?: InferFrom | ((item: TItem) => InferFrom) /** * Values that apply to new elements, or: item => values * @default {} */ enter?: InferFrom | InferFrom[] | ((item: TItem) => InferFrom) /** * Values that apply to leaving elements, or: item => values * @default {} */ leave?: InferFrom | InferFrom[] | ((item: TItem) => InferFrom) /** * Values that apply to elements that are neither entering nor leaving (you can use this to update present elements), or: item => values */ update?: InferFrom | InferFrom[] | ((item: TItem) => InferFrom) /** * Initial (first time) base values, optional (can be null) */ initial?: InferFrom | ((item: TItem) => InferFrom) | null /** * Called when objects have disappeared for good */ onDestroyed?: (isDestroyed: boolean) => void } export interface UseTransitionResult { item: TItem key: string state: State props: AnimatedValue> } export function useTransition( items: ReadonlyArray | TItem | null | undefined, keys: | ((item: TItem) => TransitionKeyProps) | ReadonlyArray | TransitionKeyProps | null, values: Merge> ): UseTransitionResult>[] // result array is safe to modify export function useTransition( items: ReadonlyArray | TItem | null | undefined, keys: | ((item: TItem) => TransitionKeyProps) | ReadonlyArray | TransitionKeyProps | null, values: Merge> ): UseTransitionResult>>[] // result array is safe to modify