Output Shimmer

Shimmer คือ view ที่ใช้แสดงผลเมื่อรอการโหลดข้อมูล

Source Code

ReactJs Styled Component
Copy
import styled from "styled-components";
export default function OutputShimmer({
  width = "100%",
  height = "100px",
  backgroundColor = "#333",
  borderRadius = "8px",
  className,
  style,
  margin,
}) {
  return (
    <Styled
      style={style}
      className={className}
      $width={width}
      $height={height}
      $backgroundColor={backgroundColor}
      $borderRadius={borderRadius}
      $margin={margin}
    >
      <div className="shimmer"></div>
    </Styled>
  );
}

const Styled = styled.div`
  width: ${({ $width }) => $width};
  height: ${({ $height }) => $height};
  margin: ${({ $margin }) => $margin};
  border-radius: ${({ $borderRadius }) => $borderRadius};
  overflow: hidden;
  background-color: ${({ $backgroundColor }) => $backgroundColor };
  .shimmer {
    width: 100%;
    height: 100%;
    background: rgba(100, 100, 100, 0.02);

    background-image: linear-gradient(
      to right,
      rgba(100, 100, 100, 0.02) 0%,
      rgba(100, 100, 100, 0.2) 20%,
      rgba(100, 100, 100, 0.02) 40%,
      rgba(100, 100, 100, 0.02) 100%
    );
    background-repeat: no-repeat;
    background-size: ${({ $width }) => $width} ${({ $height }) => $height};
    display: inline-block;
    position: relative;
    animation-duration: 1s;
    animation-fill-mode: forwards;
    animation-iteration-count: infinite;
    animation-name: anim;
    animation-timing-function: linear;

    @keyframes anim {
      0% {
        background-position: -${({ $width }) => $width} 0;
      }

      100% {
        background-position: ${({ $width }) => $width} 0;
      }
    }
  }
`;

Usage

ReactJs Styled Component
Copy
import OutputShimmer from "../../example/OutputShimmer";

export default function TestView() {
  return (
    <div className="test-view">
      <Shimmer width="200px" height="20px" margin={"0 0 20px 0"} />
      <Shimmer width="200px" height="20px" margin={"0 0 20px 0"} />
      <Shimmer width="200px" height="20px" />
    </div>
  );
}

Properties

Property

Description

Type

Default

className

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

string

style

inline style ของ view

CSSProperties

borderRadius

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

string

"8px"

backgroundColor

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

string

"#333"

width

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

string

"100%"

height

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

string

"100px"

margin

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

string

Requirements

styled-components

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