List Grid

Grid List Layout คือ view ที่ใช้เรียง children views ในลักษณะแถวและคอลัม

Source Code

ReactJs Styled Components
Copy
import styled from "styled-components";

export default function ListGrid({
  children,
  style,
  className,
  itemWidth = "150px",
  gapX = "20px",
  gapY = "20px",
  backgroundColor,
  padding,
  margin,
  width,
  height,
  borderRadius,
  borderColor,
  borderWidth,
  align = "start",
}) {
  return (
    <Styled
      className={className}
      style={style}
      itemWidth={itemWidth}
      gapX={gapX}
      gapY={gapY}
      padding={padding}
      margin={margin}
      width={width}
      height={height}
      borderColor={borderColor}
      borderWidth={borderWidth}
      borderRadius={borderRadius}
      backgroundColor={backgroundColor}
      align={align}
    >
      {children}
    </Styled>
  );
}

const Styled = styled.div`
  display: grid;
  grid-gap: ${({ gapY }) => gapY} ${({ gapX }) => gapX};
  grid-template-columns: repeat(
    auto-fit,
    minmax(${({ itemWidth }) => itemWidth}, 1fr)
  );
  color: ${({ fontColor }) => fontColor};
  background-color: ${({ backgroundColor }) => backgroundColor};
  width: ${({ width }) => width};
  height: ${({ height }) => height};
  padding: ${({ padding }) => padding};
  margin: ${({ margin }) => margin};
  border-width: ${({ borderWidth }) => (borderWidth ? borderWidth : 0)};
  border-color: ${({ borderColor }) => borderColor};
  border-style: ${({ borderWidth }) => (borderWidth ? "solid" : null)};
  border-radius: ${({ borderRadius }) => borderRadius};
  align-content: ${({ align }) => align};
`;

Usage

No Title
Copy
import Box from "../../example/Box";
import ListGrid from "../../example/ListGrid";

export default function TestView() {
  return (
    <div className="test-view">
      <ListGrid itemWidth="30px">
        <Box padding={"30px"} backgroundColor={"var(--primary)"} />
        <Box padding={"30px"} backgroundColor={"var(--primary)"} />
        <Box padding={"30px"} backgroundColor={"var(--primary)"} />
        <Box padding={"30px"} backgroundColor={"var(--primary)"} />
        <Box padding={"30px"} backgroundColor={"var(--primary)"} />
        <Box padding={"30px"} backgroundColor={"var(--primary)"} />
        <Box padding={"30px"} backgroundColor={"var(--primary)"} />
        <Box padding={"30px"} backgroundColor={"var(--primary)"} />
        <Box padding={"30px"} backgroundColor={"var(--primary)"} />
      </ListGrid>
    </div>
  );
}

Properties

Property

Description

Type

Default

children

children views

ReactElement

style

inline style ของ view

CSSProperties

className

ใช้กำหนดลักษณะเฉพาะของ view

string

itemWidth

ความกว้างของ item

string

"150px"

gapX

ระยะหว่างระหว่าง item ในแนวนอน

string

"20px"

gapY

ระยะหว่างระหว่าง item ในแนวตั้ง

string

"20px"

backgroundColor

สีพื้นหลังของ view

string

padding

พื้นที่ว่างระหว่างเส้นขอบทั้ง 4 ด้านของ view และ เนื้อหาของ view

string

margin

พื้นที่ว่างระหว่างขอบนอกสุดทั้ง 4 ด้านของ view และ view อื่น

string

width

ความกว้างเนื้อหาของ view

string

height

ความสูงเนื้อหาของ view

string

borderRadius

ความโค้งมนของ view

string

borderColor

สีเส้นขอบนอกสุดของ view

string

borderWidth

ความหนาเส้นขอบนอกสุดของ view

string

align

ลักษณะการเรียงตัวของ children views

string

"start"

Requirements

styled-components

ยักซ่า (Yakxar)
สร้างสรรค์และแบ่งปันสื่อดิจิทัลง่ายๆ ที่นี่
© 2025 ยักซ่า (Yakxar)