회원가입 폼에서 주로 볼 수 있는 필수입력사항 * 별표시를 렌더링하고 싶을 땐 가상요소(pseudo-Element)를 이용할 수 있다.
&::after {
content: '*';
color: '#ff0000';
}
styled-components를 이용한다면 믹스인을 만들어서 사용하면 편하다.
import { css } from 'styled-components';
export const RequiredStar = (position: 'before' | 'after') => css`
${position === 'before'
? css`
&::before {
content: '*';
color: ${({ theme }) => theme.color.red};
}
`
: css`
&::after {
content: '*';
color: ${({ theme }) => theme.color.red};
}
`}
`;
before
, after
를 정할 수 있게 추상화했다.
'프론트엔드' 카테고리의 다른 글
StorageEvent와 CustomEvent로 useLocalStorage 훅 만들기 (1) | 2023.11.29 |
---|---|
[번들 사이즈 최적화] 웹팩으로 생성한 번들 파일을 분석해보자(BundleAnalyzerPlugin) (0) | 2023.09.11 |
KDC 한국십진분류표 (0) | 2023.06.21 |
styled-components를 이용할 때 기존 태그의 attributes를 override하는법 (0) | 2023.06.20 |
컴포넌트를 만들 때 기존 태그의 props를 상속받는 법 (0) | 2023.06.17 |