@patternfly/react-core
Version:
This library provides a set of common React components for use with the PatternFly reference implementation.
76 lines • 2.9 kB
TypeScript
import { FunctionComponent, ReactNode } from 'react';
/** Configuration for animations throughout PatternFly components */
export interface AnimationsConfig {
/** Whether animations are enabled globally */
hasAnimations?: boolean;
}
/** Props for the AnimationsProvider component */
export interface AnimationsProviderProps {
/** Animation configuration settings */
config: AnimationsConfig;
/** Child components that will have access to the animations context */
children: ReactNode;
}
/**
* AnimationsProvider is an application-level provider that provides uniform
* animation configuration for all PatternFly React components via the React context API.
*
* **Usage**: Place this provider at the root of your application to enable global
* animation control without requiring manual prop drilling throughout your component tree.
*
* **Benefits**:
* - Centralized animation control for the entire application
* - Respects user accessibility preferences (reduced motion)
* - Components can still override the global setting when needed
* - Works with all PatternFly components that support animations
*
* @example
* ```tsx
* // App.tsx - Place at your application root
* import { AnimationsProvider } from '@patternfly/react-core';
*
* const App = () => (
* <AnimationsProvider config={{ hasAnimations: true }}>
* <MyApplication />
* </AnimationsProvider>
* );
* ```
*/
export declare const AnimationsProvider: FunctionComponent<AnimationsProviderProps>;
/**
* Hook to access the animations configuration from the nearest AnimationsProvider.
*
* This hook allows components to check if animations are enabled and override
* their local hasAnimations prop accordingly.
*
* @returns The animations configuration object
*
* @example
* ```tsx
* const MyComponent = ({ hasAnimations: hasAnimationsProp, ...props }) => {
* const { hasAnimations: contextHasAnimations } = useAnimationsConfig();
* const hasAnimations = hasAnimationsProp ?? contextHasAnimations;
*
* return <div className={hasAnimations ? 'with-animations' : ''} {...props} />;
* };
* ```
*/
export declare const useAnimationsConfig: () => AnimationsConfig;
/**
* Utility hook that combines local hasAnimations prop with context configuration.
* The local prop takes precedence when explicitly set, otherwise falls back to context.
*
* @param hasAnimationsProp - The hasAnimations prop passed directly to the component
* @returns The resolved hasAnimations value
*
* @example
* ```tsx
* const MyComponent = ({ hasAnimations: hasAnimationsProp, ...props }) => {
* const hasAnimations = useHasAnimations(hasAnimationsProp);
*
* return <div className={hasAnimations ? 'animated' : 'static'} {...props} />;
* };
* ```
*/
export declare const useHasAnimations: (hasAnimationsProp?: boolean) => boolean;
//# sourceMappingURL=AnimationsProvider.d.ts.map