import { useBoolean } from "usehooks-ts";
import styled, { css } from "styled-components";
type ParagraphProps = {
active?: boolean,
};
const Paragraph =
styled.p <
ParagraphProps >
`
color: ${(props) => (props.active ? "#F00" : "#888")};
${(props) =>
props.active &&
css`
font-weight: bold;
`}
`;
export default function Greeting() {
const { value: active, toggle } = useBoolean(false);
return (
<div>
<Paragraph>Inactive</Paragraph>
<Paragraph active>Active</Paragraph>
<Paragraph active={active}>
Hello, world{" "}
<button type="button" onClick={toggle}>
Toggle
</button>
</Paragraph>
</div>
);
}
๊ธฐ๋ณธ ์์ฑ์ ์ถ๊ฐํ ์ ์์. ๋ถํ์ํ๊ฒ ๋ฐ๋ณต๋๋ ์์ฑ์ ์ฒ๋ฆฌํ ๋ ์ ์ฉํ๋ฐ, ๋ฒํผ ๋ฑ์ ๋ง๋ค ๋ ์ ๊ทน ํ์ฉํจ.
import styled from "styled-components";
const Button = styled.button.attrs({
type: "button",
})`
border: 1px solid #888;
background: transparent;
cursor: pointer;
`;
export default Button;