@base-ui-components/react
Version:
Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
76 lines • 3.27 kB
TypeScript
import * as React from 'react';
export type HTMLProps<T = any> = React.HTMLAttributes<T> & {
ref?: React.Ref<T> | undefined;
};
export interface FloatingUIOpenChangeDetails {
open: boolean;
reason: string;
nativeEvent: Event;
nested: boolean;
triggerElement?: Element | undefined;
}
export type BaseUIEvent<E extends React.SyntheticEvent<Element, Event>> = E & {
preventBaseUIHandler: () => void;
readonly baseUIHandlerPrevented?: boolean;
};
type WithPreventBaseUIHandler<T> = T extends ((event: infer E) => any) ? E extends React.SyntheticEvent<Element, Event> ? (event: BaseUIEvent<E>) => ReturnType<T> : T : T extends undefined ? undefined : T;
/**
* Adds a `preventBaseUIHandler` method to all event handlers.
*/
export type WithBaseUIEvent<T> = { [K in keyof T]: WithPreventBaseUIHandler<T[K]> };
/**
* Shape of the render prop: a function that takes props to be spread on the element and component's state and returns a React element.
*
* @template Props Props to be spread on the rendered element.
* @template State Component's internal state.
*/
export type ComponentRenderFn<Props, State> = (props: Props, state: State) => React.ReactElement<unknown>;
/**
* Props shared by all Base UI components.
* Contains `className` (string or callback taking the component's state as an argument) and `render` (function to customize rendering).
*/
export type BaseUIComponentProps<ElementType extends React.ElementType, State, RenderFunctionProps = HTMLProps> = Omit<WithBaseUIEvent<React.ComponentPropsWithoutRef<ElementType>>, 'className' | 'color' | 'defaultValue' | 'defaultChecked'> & {
/**
* CSS class applied to the element, or a function that
* returns a class based on the component’s state.
*/
className?: string | ((state: State) => string | undefined);
/**
* Allows you to replace the component’s HTML element
* with a different tag, or compose it with another component.
*
* Accepts a `ReactElement` or a function that returns the element to render.
*/
render?: ComponentRenderFn<RenderFunctionProps, State> | React.ReactElement<Record<string, unknown>>;
/**
* Style applied to the element, or a function that
* returns a style object based on the component’s state.
*/
style?: React.CSSProperties | ((state: State) => React.CSSProperties | undefined);
};
export interface NativeButtonProps {
/**
* Whether the component renders a native `<button>` element when replacing it
* via the `render` prop.
* Set to `false` if the rendered element is not a button (e.g. `<div>`).
* @default true
*/
nativeButton?: boolean;
}
export interface NonNativeButtonProps {
/**
* Whether the component renders a native `<button>` element when replacing it
* via the `render` prop.
* Set to `true` if the rendered element is a native button.
* @default false
*/
nativeButton?: boolean;
}
/**
* Simplifies the display of a type (without modifying it).
* Taken from https://effectivetypescript.com/2022/02/25/gentips-4-display/
*/
export type Simplify<T> = T extends Function ? T : { [K in keyof T]: T[K] };
export type RequiredExcept<T, K extends keyof T> = Required<Omit<T, K>> & Pick<T, K>;
export type Orientation = 'horizontal' | 'vertical';
export {};