UNPKG

@enact/ui

Version:

A collection of simplified unstyled cross-platform UI components for Enact

83 lines (74 loc) 2.74 kB
// Type definitions for ui/Repeater import { ForwardRefProps as ui_ForwardRef_ForwardRefProps } from "@enact/ui/ForwardRef"; import * as React from "react"; type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N; export interface RepeaterBaseProps { /** * Component type to repeat. * * This can be a React component or a string describing a DOM node (e.g. `'div'` ). */ childComponent: string | React.ComponentType; /** * An array of data to be mapped onto the `childComponent` . * * This supports two data types. If an array of strings is provided, the strings will be used in the generated `childComponent` as the readable text. If an array of objects is provided, each object will be spread onto the generated `childComponent` with no interpretation. You'll be responsible for setting properties like `disabled` , `className` , and setting the text content using the `children` key. * * NOTE : When an array of objects is provided, make sure a unique `key` is assigned to each data. See for more information. */ children: string[] | { key: number | string; [propName: string]: any }[]; /** * The property on each `childComponent` that receives the data in `children` . */ childProp?: string; /** * Component type to wrap around all the repeated elements. * * This can be a string describing a DOM node or React component (e.g. `'div'` or `Layout` ). */ component?: string | React.ComponentType; /** * Called with a reference to the root component. * * When using , the `ref` prop is forwarded to this component as `componentRef` . */ componentRef?: object | Function; /** * The property on each `childComponent` that receives the index of the item in the `Repeater` . */ indexProp?: string; /** * An object containing properties to be passed to each child. */ itemProps?: object; } /** * A stateless component that stamps out copies of `childComponent` , without applied. */ export class RepeaterBase extends React.Component< Merge<React.HTMLProps<HTMLElement>, RepeaterBaseProps> > {} export interface RepeaterDecoratorProps extends ui_ForwardRef_ForwardRefProps {} export function RepeaterDecorator<P>( Component: React.ComponentType<P> | string, ): React.ComponentType<P & RepeaterDecoratorProps>; export interface RepeaterProps extends Omit< Merge<RepeaterBaseProps, RepeaterDecoratorProps>, "componentRef" > {} /** * A stateless component that stamps out copies of `childComponent` . */ export class Repeater extends React.Component< Merge<React.HTMLProps<HTMLElement>, RepeaterProps> > {} export default Repeater;