UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

29 lines (28 loc) 1.51 kB
import { jsx as _jsx } from "react/jsx-runtime"; import React from 'react'; export const ListRenderItemContext = React.createContext({}); /** * This hook is meant to be used inside the render function of `List` style components. It is used * by `ListBox`. This hook gives list-based components their static and dynamic APIs to handle list * items. This hook should only be used if you want to implement your own List. For example, * `Tabs.List` uses this hook, but `Menu.List` uses `ListBox` which uses this hook. * * ```tsx * const MyList = createContainer('ul')({ * modelHook: useListModel, * })((elemProps, Element, model) => { * return <Element {...elemProps}>{useListRenderItems(model, elemProps.children)}</Element>; * }); ``` */ export function useListRenderItems(model, children) { const items = typeof children === 'function' ? (model.state.isVirtualized ? (model.state.UNSTABLE_virtual.getVirtualItems().map(virtual => { const item = model.state.items[virtual.index]; const child = children(item.value, virtual.index); return (_jsx(ListRenderItemContext.Provider, { value: { item, virtual }, children: child }, item.id || item.index)); })) : (model.state.items.map(item => { const child = children(item.value, item.index); return (_jsx(ListRenderItemContext.Provider, { value: { item }, children: child }, item.id || item.index)); }))) : (_jsx(ListRenderItemContext.Provider, { value: {}, children: children })); return items; }