props์ attrs
Props
import styled, { css } from "styled-components";
import { useBoolean } from "usehooks-ts";
type ButtonProps = {
active: boolean,
};
// ์ด๋ ๊ฒ ํด๋ ๋๊ณ
function background(props: ButtonProps) {
return props.active ? "#00F" : "#FFF";
}
// ๋ด๋ถ์ ์จ๋ ๋๋ค.(์ด๋ฏธ ํ์
์ด ์ง์ ๋์ด ์์ผ๋ฏ๋ก ๋ํด์ค ํ์์์)
const Button =
styled.button <
ButtonProps >
`
background: #FFF;
color: #000;
border: 1px solid ${(props) => (props.active ? "#F00" : "#888")};
${(props) =>
props.active &&
css`
background: #f00;
color: #fff;
`}
`;
export default function Switch() {
const { value: active, toggle } = useBoolean(false);
return (
<Button type="button" onClick={toggle} active={active}>
On/Off
</Button>
);
}๊ณต์ ๋ฌธ์ ์์
attrs
๊ณต์ ์ฌ์ดํธ ์์
Last updated