ã¯ããã«
Qiitaæ ªåŒäŒç€Ÿ Advent Calendar 2022ã®9æ¥ç®ã¯ã
Qiita æ ªåŒäŒç€Ÿ ãããã¯ãéçºG ãã¶ã€ã³TMã®åºå£ïŒ@degudegu2510ïŒãæ
åœããŸãïŒ
æ®æ®µã®æ¥åã¯ãQiita, Qiita Team, Qiita Jobsã®ãã¶ã€ããŒãšããŠãæ å ±èšèšãäœéšèšèš(UX)ãUIãã¶ã€ã³ãããã³ããšã³ããŸã§æºãã£ãŠããŸãã
ãã®èšäºã§ã¯ãQiitaã§äœ¿ã£ãŠããCSS in JS ã®ð©âð€Emotionã«ã€ããŠ
ð©âð€Emotionã®ç¹åŸŽãQiitaã§ð©âð€Emotionã䜿ã£ãŠããçç±ãªã©ããŸãšããŸããã
CSS in JSã¯ãäœããããã ãããšèããŠãã人ãð©âð€Emotionãå°å ¥ããããšæ€èšããŠãã人ãªã©ã®åèã«ãªãã°å¹žãã§ãã
ð©âð€Emotion
ð©âð€Emotionãšã¯ïŒ
ð
styled-componentsã»ðglamorous ãšãã£ãCSS-in-JSã©ã€ãã©ãªã«ã€ã³ã¹ãã€ã¢ãããæ¯èŒçåŸçºã®ã©ã€ãã©ãªã§ãããã®ãããéåžžã«å€æ©èœã§ãããä»ã©ã€ãã©ãªã®æ©èœã®å€ããæŽã«æŽç·Žãããäžã§åããŠããã®ãç¹åŸŽã§ãã
ãŸããReactãVueãšãã£ããã¬ãŒã ã¯ãŒã¯ã«äŸåããããšãªããCSS in JSãå©çšããããšãã§ããããæ±çšæ§ãé«ããð styled-components ãããããã©ãŒãã³ã¹ãé«ãã®ãç¹åŸŽã«ãªããŸãã
äž»ãªæ©èœã®çŽ¹ä»
â CSS Props ãš Styled Components
ð©âð€Emotionãæ¯èŒçåŸçºã®ã©ã€ãã©ãªã§ãããããä»ã®CSS in JSããã€ã³ã¹ãã€ã¢ãããå€ãã®æžãæ¹ãã§ããŸãã
CSS Propsã§ã¯ãcss={paragraph}
ã®ããã«ãclassåãããŠããããã«ã§ããDOMæ§é ãšã¹ã¿ã€ã«ãåããŠèšè¿°ã§ããã®ãç¹åŸŽã§ãã
ãŸãããªããžã§ã¯ãèšæ³ãšã¿ã°ä»ããã³ãã¬ãŒããªãã©ã«èšæ³ã®2ã€ã®æžãæ¹ãã§ããŸãã
ãªããžã§ã¯ãèšæ³ã¯ãå³å¯ãªåå®çŸ©ããããããäºæž¬å€æããããã§ãããCSSã®ããããã£ããã£ã¡ã«ã±ãŒã¹ã«ãªããŸãã
ã¿ã°ä»ããã³ãã¬ãŒããªãã©ã«èšæ³ã¯ãcssã®ããããã£ããã®ãŸãŸèšèŒã§ããŸãããã¹ããªã³ã°ã®ãããšã©ãŒæ€ç¥ãã¥ããã§ãã â»ãã©ã°ã€ã³ãå ¥ããã°ãªããšããªã
Styled Componentsã§ã¯ãstyled.pâŠ
ãã®ããã«DOMèŠçŽ ã®å®£èšã¯ãã¹ã¿ã€ã«ãšäžç·ã«èšèŒããã®ãç¹åŸŽã§ãã
ãŸããStyled Componentsã§ããªããžã§ã¯ãèšæ³ãšã¿ã°ä»ããã³ãã¬ãŒããªãã©ã«èšæ³ã®2ã€ã®æžãæ¹ãã§ããŸãã
ãªããžã§ã¯ãèšæ³ã¯ãå³å¯ãªåå®çŸ©ããããããäºæž¬å€æããããã§ãããCSSã®ããããã£ããã£ã¡ã«ã±ãŒã¹ã«ãªããŸãã
ã¿ã°ä»ããã³ãã¬ãŒããªãã©ã«èšæ³ã¯ãcssã®ããããã£ããã®ãŸãŸèšèŒã§ããŸãããã¹ããªã³ã°ã®ãããšã©ãŒæ€ç¥ãã¥ããã§ãã â»ãã©ã°ã€ã³ãå ¥ããã°ãªããšããªã
â¡ @emotion/css
ð©âð€Emotionã¯ãReactãvue.jsããªã©ã®Javascriptã®ã©ã€ãã©ãªãŒã«å·Šå³ãããªãããã«ããããã®ããã±ãŒãžãçšæãããŠããŸãã
ããã@emotion/css
ã«ãªããŸãã
ãã ãReactã§æé©ã«äœ¿ãããå ŽåããStyled Componentsã䜿ãããå Žåã¯ã以äžã®ããã«å¥ã®ããã±ãŒãžãçšæãããŠããŸãã
-
@emotion/react
- Reactçšã®Emotionããã±ãŒãž
-
@emotion/styled
- Styled Componentsçšã®Emotionããã±ãŒãž
-
@emotion/css
- ãã¬ãŒã ã¯ãŒã¯ã«ãšãããããEmotionã䜿çšããããã®ããã±ãŒãž
ð©âð€Emotionã䜿ã£ãŠããçç±
ã»ãã³ãã£ãã¯ãªããŒã¯ã¢ãããå®çŸãããã£ãã
ð©âð€Emotionã䜿ã£ãŠããçç±ã®1ã€ç®ã¯ãEmotionã¯æ¥œã«ã»ãã³ãã£ãã¯ãªããŒã¯ã¢ãããå®çŸã§ããããšã§ãã
ð styled-componentsã䜿ã£ãŠããäžã§èª²é¡ã«ãªã£ãã®ã¯ãã»ãã³ãã£ãã¯ãªããŒã¯ã¢ããã®å®çŸãããã«ããããšã§ããSEOãã¢ã¯ã»ã·ããªãã£ãåäžãããããã«ããã»ãã³ãã£ãã¯ãªããŒã¯ã¢ããã¯å¿ èŠã§ãã
ããã§ãð
styled-components
ãšð©âð€Emotion
ã®éããèŠãŠãããŸãããã
ð
styled-components
ã¯ãèŠçŽ ã®å®£èšãã¹ã¿ã€ã«åŽã«æãããŠããŸãã
ãã®ãã <Paragraph>
ã®ã¿ã°ãèŠãããã«ã¯ã<Paragraph>
ã§åç
§ããŠããè¡ãŸã§è¡ãå¿
èŠããããŸãã
<Paragraph>
ãšãã£ãã¿ã°ãé£æ³ããããååãã€ããŠããã°ããã®ã§ããããããªããšã¯ããªããããªæãã®ã³ãŒããçãŸããŸãã
<a>
ãªã®ã« <SampleButton>
ã䜿ããããã<list>
ãªã®ã«ã<div>
ã䜿ãããããªã©ãåœåèŠåãªã©ã§çžã£ãŠãé£ããéšåããããã»ãã³ãã£ãã¯ã®ããŒã¯ã¢ãããé£ããã§ãã
ããã«æ¯ã¹ãŠEmotionã¯ãããŒã¯ã¢ãããšã¹ã¿ã€ã«ãåããŠèšè¿°ã§ãããšããç¹ãã
CSS in JSã«Emotionãéžãã§ããïŒã€ç®ã®çç±ã§ãã
Emotoinãžã®ç§»è¡ããããããã£ãã
Qiitaã¯ä»å¹Žã§11幎ç®ã®ãããã¯ãã«ãªããå€ãã®ã³ã³ããŒãã³ããäœãããŠããŸãã
ãããã®ã³ã³ããŒãã³ããã¡ãäžæã«å€æŽããã ãã§ãäžèŠåŽã§ãã
ãã®ãããã©ã€ãã©ãªãŒã®å€æŽãããããããšãEmotionãéžãã§ããçç±ã®ïŒã€ã§ãã
å ·äœçã«ã¯ã以äžã®ããã«Emotionãå€æŽããŠãããŸããã
ð
styled-components
â ð©âð€@emotion/styled
â ð©âð€@emotion/css
ãŸãã¯ãð
styled-components
ãã ð©âð€@emotion/styled
ã«å€æŽããŸãã
ã¹ã¿ã€ãªã³ã°ã®éšåã«é¢ããŠã¯ã以äžã®ããã«åºæ¬çã«å€ãããŸããã
ãã®ãããð
styled-components
ãã ð©âð€Emotion
ãžã®å€æã¯ãããŸã§å€§å€ã§ã¯ãããŸããã§ããã
ð©âð€@emotion/styled
ã«å€ããããä»ã®PJãé²ããªãããé 次@emotion/css
ã«ãªãã¡ã¯ã¿ãªã³ã°ããŠãããŸãã
ãã®ããã«ãã¹ã ãŒãºã« ð©âð€Emotion
ãžã®ç§»è¡ããããšãã§ããç¹ã
CSS in JSã«Emotionãéžãã§ããïŒã€ç®ã®çç±ã§ãã
4. ãŸãšã
ãã®èšäºã§ã¯ãQiitaã§äœ¿ã£ãŠããCSS in JS ã®Emotionã«ã€ããŠ
Emotionã®ç¹åŸŽãQiitaã§Emotionã䜿ã£ãŠããçç±ãªã©ããŸãšããŸããã
Emotionã¯ãð
styled-components ãããããã©ãŒãã³ã¹ãé«ããã»ãã³ãã£ãã¯ãªããŒã¯ã¢ãããå®çŸã§ãã
移è¡ããã®ãã¹ã ãŒãºã§ãã
ãã ãè¿å¹Žå°é ããŠããŠãããŒãã©ã³ã¿ã€ã ã®CSS in JSã®æ¹ããããã©ãŒãã³ã¹ããããããã®ã§ã
ãŒãã©ã³ã¿ã€ã ã®CSS in JSã«ç§»è¡ããã®ãè¿ããããããŸããã
ãŒãã©ã³ã¿ã€ã ã®CSS in JSã«ç§»è¡ããéã¯ããŸãèšäºã«ãŸãšããããšæããŸãã®ã§ã楜ãã¿ããŠãã ããã
æåŸãŸã§èªãã§ãã ãã£ãŠããããšãããããŸãïŒ
æ®æ®µã¯ãã¶ã€ã³ãããã³ããšã³ããäžå¿ã«Qiitaã«èšäºãæçš¿ããŠããã®ã§ããã²Qiitaã®ãã©ããŒãšX(Twitter)ã®ãã©ããŒããé¡ãããŸãã