baseui
Version:
A React Component library implementing the Base design language
64 lines (63 loc) • 2.65 kB
TypeScript
import * as React from 'react';
export type ConfigurationOverrideFunction = (a: any) => any | undefined | null;
export type ConfigurationOverrideObject = {
[k: string]: any;
};
export type ConfigurationOverride = ConfigurationOverrideObject | ConfigurationOverrideFunction;
export type StyleOverride = ConfigurationOverride;
export type OverrideObject = {
component?: React.ComponentType<any> | null;
props?: ConfigurationOverride | null;
style?: ConfigurationOverride | null;
};
export type Override<T = any> = OverrideObject | (React.ComponentType<any> & {
component?: undefined;
props?: undefined;
style?: undefined;
});
export type Overrides<T = any> = {
[x: string]: Override;
};
/**
* Given an override argument, returns the component implementation override if it exists
*/
export declare function getOverride(_override: any): any;
/**
* Given an override argument, returns the override props that should be passed
* to the component when rendering it.
*/
export declare function getOverrideProps<T>(_override?: Override | null): T;
/**
* Coerces an override argument into an override object
* (sometimes it is just an override component)
*/
export declare function toObjectOverride<T>(_override?: Override): OverrideObject;
/**
* Get a convenient override array that will always have [component, props]
*/
export declare function getOverrides<T = {
[k: string]: any;
}>(_override: any, defaultComponent: React.ComponentType<any>): [React.ComponentType<any>, T];
/**
* Merges two overrides objects – this is useful if you want to inject your own
* overrides into a child component, but also accept further overrides from
* from upstream. See `mergeOverride` below.
*/
export declare function mergeOverrides(target?: Overrides, source?: Overrides): Overrides;
/**
* Merges two override objects using the following behavior:
* - Component implementation from the source (parent) replaces target
* - Props and styles are both deep merged
*/
export declare function mergeOverride(target: OverrideObject, source: OverrideObject): OverrideObject;
/**
* Since style or props overrides can be an object *or* a function, we need to handle
* the case that one of them is a function. We do this by returning a new
* function that deep merges the result of each style override
*/
export declare function mergeConfigurationOverrides(target: ConfigurationOverride, source: ConfigurationOverride): ConfigurationOverride;
export declare function useOverrides(defaults: {
[x: string]: React.ComponentType<any>;
}, overrides?: Overrides): {
[x: string]: [React.ComponentType<any>, {}];
};