Progress Bar

Progress Bar คือ view ที่ใช้แสดงความคืบหน้าของ process

Source Code

ReactJs Styled Component
Copy
import styled from "styled-components";
export default function ProgressBar({
  width = "200px",
  height = "20px",
  backgroundColor = "#efefef",
  progressColor = "#2F7FCA",
  borderRadius = "10px",
  borderColor = "#ccc",
  borderWidth = "1px",
  className,
  style,
  value = 0,
}) {
  return (
    <Styled
      width={width}
      height={height}
      backgroundColor={backgroundColor}
      style={style}
      borderWidth={borderWidth}
      className={className}
      progressColor={progressColor}
      borderRadius={borderRadius}
      borderColor={borderColor}
    >
      <div className="progress" style={{ width: value + "%" }}></div>
    </Styled>
  );
}
const Styled = styled.div`
  position: relative;
  display: inline-block;
  width: ${({ width }) => width};
  height: ${({ height }) => height};
  border-radius: ${({ borderRadius }) => borderRadius};
  background-color: ${({ backgroundColor }) => backgroundColor};
  overflow: hidden;
  border: ${({ borderWidth }) => borderWidth} solid
    ${({ borderColor }) => borderColor};
  .progress {
    background-color: ${({ progressColor }) => progressColor};
    height: 100%;
  }
`;

Usage

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

export default function TestView() {
  return (
    <div className="test-view">
      <ProgressBar value={50}/>
    </div>
  );
}

Properties

Property

Description

Type

Default

className

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

string

style

inline style ของ view

CSSProperties

value

ค่าความคืบหน้าของ progress

number

0

borderWidth

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

string

"1px"

borderColor

สีเส้นขอบของ view

string

"#ccc"

borderRadius

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

string

"10px"

progressColor

สีของแท่ง progress

string

"#2F7FCA"

backgroundColor

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

string

"#efefef"

height

ความสูงของ view

string

"20px"

width

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

string

"200px"

Requirements

styled-component

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