MCPcopy Create free account
hub / github.com/adobe/react-spectrum / Grid

Function Grid

packages/react-aria/stories/grid/example.tsx:24–66  ·  view source on GitHub ↗
(props: any)

Source from the content-addressed store, hash-verified

22import {useListState} from 'react-stately/useListState';
23
24export function Grid(props: any): JSX.Element {
25 let {gridFocusMode = 'row', cellFocusMode = 'child'} = props;
26 let state = useListState(props);
27 let gridState = useGridState({
28 ...props,
29 selectionMode: 'multiple',
30 collection: React.useMemo(
31 () =>
32 new GridCollection({
33 columnCount: 1,
34 items: [...state.collection].map(item => ({
35 type: 'item',
36 childNodes: [
37 {
38 ...item,
39 index: 0,
40 type: 'cell'
41 }
42 ]
43 }))
44 }),
45 [state.collection]
46 )
47 });
48
49 let ref = React.useRef(null);
50 let {gridProps} = useGrid(
51 {
52 'aria-label': 'Grid',
53 focusMode: gridFocusMode
54 },
55 gridState,
56 ref
57 );
58
59 return (
60 <div {...gridProps} ref={ref}>
61 {[...gridState.collection].map(item => (
62 <Row key={item.key} state={gridState} item={item} focusMode={cellFocusMode} />
63 ))}
64 </div>
65 );
66}
67
68function Row({state, item, focusMode}) {
69 let rowRef = React.useRef(null);

Callers

nothing calls this directly

Calls 3

useListStateFunction · 0.90
useGridStateFunction · 0.90
useGridFunction · 0.90

Tested by

no test coverage detected