Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 48 additions & 30 deletions src/components/GridContainer/GridContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { styled } from "styled-components";
import { HTMLAttributes } from "react";
import {
ComponentProps,
ComponentPropsWithRef,
ElementType,
forwardRef,
ReactNode,
} from "react";

export type FlowOptions = "row" | "column" | "row-dense" | "column-dense";
type GapOptions = "none" | "xxs" | "xs" | "sm" | "md" | "lg" | "xl" | "xxl" | "unset";
Expand All @@ -15,7 +21,8 @@ type ContentOptions =
| "left"
| "right";

export interface GridContainerProps extends HTMLAttributes<HTMLDivElement> {
export interface GridContainerProps<T extends ElementType = "div"> {
component?: T;
alignItems?: ItemsOptions;
alignContent?: ContentOptions;
children?: React.ReactNode;
Expand All @@ -42,35 +49,44 @@ export interface GridContainerProps extends HTMLAttributes<HTMLDivElement> {
overflow?: string;
}

const GridContainer = ({
alignItems = "stretch",
alignContent = "stretch",
children,
columnGap,
gap,
gridAutoColumns,
gridAutoFlow,
gridAutoRows,
gridTemplateAreas,
gridTemplateColumns,
gridTemplateRows,
gridTemplate,
inline = false,
isResponsive = true,
justifyContent = "stretch",
justifyItems = "stretch",
rowGap,
height,
maxHeight,
minHeight,
fillWidth = true,
maxWidth,
minWidth,
overflow,
...props
}: GridContainerProps) => {
type GridContainerPolymorphicComponent = <T extends ElementType = "div">(
props: Omit<ComponentProps<T>, keyof T> & GridContainerProps<T>
) => ReactNode;

const _GridContainer = <T extends ElementType = "div">(
{
alignItems = "stretch",
alignContent = "stretch",
children,
columnGap,
gap,
gridAutoColumns,
gridAutoFlow,
gridAutoRows,
gridTemplateAreas,
gridTemplateColumns,
gridTemplateRows,
gridTemplate,
inline = false,
isResponsive = true,
justifyContent = "stretch",
justifyItems = "stretch",
rowGap,
height,
maxHeight,
minHeight,
fillWidth = true,
maxWidth,
minWidth,
overflow,
component,
...props
}: Omit<ComponentProps<T>, keyof T> & GridContainerProps<T>,
ref: ComponentPropsWithRef<T>["ref"]
) => {
return (
<Wrapper
as={component ?? "div"}
$alignItems={alignItems}
$alignContent={alignContent}
$columnGap={columnGap}
Expand All @@ -95,6 +111,7 @@ const GridContainer = ({
$minWidth={minWidth}
$overflow={overflow}
data-testid="grid-container"
ref={ref}
{...props}
>
{children}
Expand Down Expand Up @@ -171,4 +188,5 @@ const Wrapper = styled.div<{
}
`;

export { GridContainer };
export const GridContainer: GridContainerPolymorphicComponent =
forwardRef(_GridContainer);