From b4485f12abca0145fb453cdce9026ce176bc74e4 Mon Sep 17 00:00:00 2001 From: Ajetunmobi Isaac Date: Thu, 5 Dec 2024 02:26:11 +0100 Subject: [PATCH] added documentation for prop --- README.md | 7 +++++++ src/responsive-grid/index.tsx | 26 +++++++++++++++----------- src/responsive-grid/types.ts | 4 ++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 12f3685..1449e0c 100644 --- a/README.md +++ b/README.md @@ -383,6 +383,13 @@ A lower value results in more frequent updates, offering smoother visual updates false Defines the base unit height for items within the grid. This value serves as a foundational measure to determine the actual height of each grid item. The item's final height is calculated by multiplying this base unit height (itemUnitHeight) by the item's heightRatio, allowing for proportional scaling of items based on their content or design requirements. While widthRatio affects the item's width in relation to the column width, itemUnitHeight and heightRatio together define the item's vertical dimension, enabling dynamic grid layouts that adapt seamlessly to varying content sizes. + + direction + string + ltr + false + Determines the direction for arranging grid items in the layout: left-to-right (ltr) or right-to-left (rtl). + virtualization Boolean diff --git a/src/responsive-grid/index.tsx b/src/responsive-grid/index.tsx index 6069a5b..d0b1607 100644 --- a/src/responsive-grid/index.tsx +++ b/src/responsive-grid/index.tsx @@ -28,7 +28,6 @@ export const ResponsiveGrid: React.FC = ({ FooterComponent = null, direction = 'ltr', }) => { - const start = direction === 'ltr' ? 'left' : 'right'; const [visibleItems, setVisibleItems] = useState([]); const [containerSize, setContainerSize] = useState({ width: 0, height: 0 }); @@ -122,6 +121,20 @@ export const ResponsiveGrid: React.FC = ({ onEndReachedCalled.current = false; }, [gridItems, containerSize, virtualization]); + const getItemPositionStyle = (item: TileItem) => { + const baseStyle = { + position: 'absolute' as const, + top: item.top, + width: item.width, + height: item.height, + }; + + return { + ...baseStyle, + ...(direction === 'rtl' ? { right: item.left } : { left: item.left }), + }; + }; + return ( = ({ {renderedItems.map((item, index) => ( {renderItem({ item, index })} diff --git a/src/responsive-grid/types.ts b/src/responsive-grid/types.ts index a3578bb..9e91806 100644 --- a/src/responsive-grid/types.ts +++ b/src/responsive-grid/types.ts @@ -69,6 +69,10 @@ export interface ResponsiveGridProps { | null | undefined; + /** + * Determines the direction for arranging grid items in the layout: left-to-right (ltr) or right-to-left (rtl). + * @default ltr + */ direction?: 'rtl' | 'ltr'; }