React-js의 버튼 구성 요소(올인원)
8206 단어 javascriptcssreactwebdev
Reactjs에서 하나의 버튼 구성 요소 만들기
버튼.jsx
import React from "react";
import "./Button.scss";
const Button = (props) => {
return (
<div className={`${props.className}`}>
<button
title={props.title}
type={props.type}
id={props.id}
className={`${props.btnClassName} ${props.icon ? 'iconButton' : false}
${props.size} ${props.variant} ${(props.startIcon || props.endIcon) ? 'iconWithLabel' : false}`}
name={props.name}
tabIndex={props.tabIndex}
onClick={props.onClick}
disabled={props.disabled}>
{props.startIcon && <span style={{ marginRight: "0.5rem", display: "flex" }}> {props.startIcon}</span>}
<span style={{ display: "flex" }}>{props.label ? props.label : props.Icon}</span>
{props.endIcon && <span style={{ marginLeft: "0.5rem", display: "flex" }}>{props.endIcon}</span>}
</button>
</div>
)
}
export default Button;
다른 파일 만들기 Button.scss
button{
outline: none;
border-radius: 3px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
&:focus{
outline: none;
}
&.contained{
border: 1px solid #100F0F;
background-color: #100F0F;
color:#fff;
&:hover{
background-color: #2C3333;
border:1px solid #2C3333;
}
&:focus{
box-shadow: 0 0 0 3px rgba(0,0,0,0.2);
}
}
&.outlined{
border: 1px solid #100F0F;
background-color: transparent;
color:#100F0F;
&:focus{
box-shadow: 0 0 0 3px rgba(0,0,0,0.2);
}
}
&.link{
border:none;
outline:none;
background-color: transparent;
&:focus{
border: none;
outline: none;
}
}
&.small{
min-height: 2rem;
font-size: 0.8rem;
min-width: 5rem;
padding: 0 1.5rem;
}
&.medium{
min-height: 2.4rem;
font-size: 0.9rem;
min-width: 7rem;
padding: 0 1.5rem;
}
&.large{
min-height: 3rem;
font-size: 1rem;
min-width: 8rem;
padding: 0 2rem;
}
&.iconButton{
&.small{
min-width: 2rem;
min-height: 2rem;
padding:0;
}
&.medium{
min-width: 2.5rem;
min-height: 2.5rem;
padding:0;
}
&.large{
min-width: 3rem;
min-height: 3rem;
padding:0;
}
}
}
마지막으로 다른 소품으로 버튼 구성 요소를 호출합니다.
<h2 style={{ margin: "10px" }}>Button Size</h2>
<div style={{ margin: "10px" }}>
<Button label="Send" variant="contained" size="small" />
</div>
<div style={{ margin: "10px" }}>
<Button label="Send" variant="contained" size="medium" />
</div>
<div style={{ margin: "10px" }}>
<Button label="Send" variant="contained" size="large" />
</div>
<h2 style={{ margin: "10px" }}>Button Variant</h2>
<div style={{ margin: "10px" }}>
<Button label="Send" variant="contained" size="small" />
</div>
<div style={{ margin: "10px" }}>
<Button label="Send" variant="outlined" size="small" />
</div>
<div style={{ margin: "10px" }}>
<Button label="Send" variant="link" size="small" />
</div>
<h2 style={{ margin: "10px" }}>Only Icon Button Size</h2>
<div style={{ margin: "10px" }}>
<Button variant="contained" size="small" icon Icon={<SendIcon height="15px" width="15px" />} />
</div>
<div style={{ margin: "10px" }}>
<Button variant="contained" size="medium" icon Icon={<SendIcon height="20px" width="20px" />} />
</div>
<div style={{ margin: "10px" }}>
<Button variant="contained" size="large" icon Icon={<SendIcon height="25px" width="25px" />} />
</div>
<h2 style={{ margin: "10px" }}>Only Icon Button Variant</h2>
<div style={{ margin: "10px" }}>
<Button variant="contained" size="medium" icon Icon={<SendIcon height="15px" width="15px" />} />
</div>
<div style={{ margin: "10px" }}>
<Button variant="outlined" size="medium" icon Icon={<SendIcon height="20px" width="20px" />} />
</div>
<div style={{ margin: "10px" }}>
<Button variant="link" size="medium" icon Icon={<SendIcon height="25px" width="25px" />} />
</div>
<h2 style={{ margin: "10px" }}>Label With EndIcon Button</h2>
<div style={{ margin: "10px" }}>
<Button variant="contained" size="small" label="Send" endIcon={<SendIcon height="15px" width="15px" />} />
</div>
<div style={{ margin: "10px" }}>
<Button variant="outlined" size="medium" label="Send" endIcon={<SendIcon height="20px" width="20px" />} />
</div>
<div style={{ margin: "10px" }}>
<Button variant="outlined" size="large" label="Send" endIcon={<SendIcon height="25px" width="25px" />} />
</div>
<h2 style={{ margin: "10px" }}>Label With StartIcon Button</h2>
<div style={{ margin: "10px" }}>
<Button variant="contained" size="small" label="Send" startIcon={<SendIcon height="15px" width="15px" />} />
</div>
<div style={{ margin: "10px" }}>
<Button variant="outlined" size="medium" label="Send" startIcon={<SendIcon height="20px" width="20px" />} />
</div>
<div style={{ margin: "10px" }}>
<Button variant="outlined" size="large" label="Send" startIcon={<SendIcon height="25px" width="25px" />} />
</div>
그게 다야. 네가 좋아하길 바래
좋아요, 댓글 및 팔로우
감사합니다 :)
Reference
이 문제에 관하여(React-js의 버튼 구성 요소(올인원)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/uidesign09/button-component-in-react-js-all-in-one-2odd텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)