/** * WordPress dependencies */ import { useState, useMemo } from '@wordpress/element'; /** * Internal dependencies */ import DataViews from '../index'; import filterSortAndPaginate from '../../utils/filter-sort-and-paginate'; import type { View } from '../../types'; import { data, fields } from './fixtures'; import { LAYOUT_TABLE } from '../../constants'; /** * Poster/hero style layout that displays items as large image cards * with overlaid text content. */ function PosterGrid( { items }: { items: typeof data } ) { return (
{ items.map( ( item ) => (

{ item.name.title }

{ item.name.description }

{ item.categories.slice( 0, 2 ).map( ( cat ) => ( { cat } ) ) }
) ) }
); } /** * Demonstrates a custom poster/hero layout using free composition. * * This story shows how to: * - Use `` as a context provider with custom children * - Render a completely custom layout (poster grid) instead of `` * - Still leverage DataViews sub-components for search and pagination */ export const LayoutCustomComponent = ( { containerHeight, }: { containerHeight: string; } ) => { const [ view, setView ] = useState< View >( { type: LAYOUT_TABLE, search: '', page: 1, perPage: 6, filters: [], fields: [], } ); const { data: processedData, paginationInfo } = useMemo( () => { return filterSortAndPaginate( data, view, fields ); }, [ view ] ); return ( item.id.toString() } paginationInfo={ paginationInfo } data={ processedData } view={ view } fields={ fields } onChangeView={ setView } defaultLayouts={ { table: {} } } >
); }; export default LayoutCustomComponent;