Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
EmotionでReactをstylingすればモテるかもしれない
Search
Matsuo Obu
May 29, 2019
Technology
0
620
EmotionでReactをstylingすればモテるかもしれない
Emotion使うとモテるかもしれないという話。React LT会 @Informetis (2019-05-29) で発表。
Matsuo Obu
May 29, 2019
Tweet
Share
More Decks by Matsuo Obu
See All by Matsuo Obu
Reactの歴史
mqtsuo02
0
1k
文学作品「檸檬」をReactで読む
mqtsuo02
1
500
僕が求めていたのはNext.jsだったんだ
mqtsuo02
0
690
Repro Tech Hands-on : Nuxt.js
mqtsuo02
1
910
ピピピのPWA
mqtsuo02
0
730
GraphQLについての5分間
mqtsuo02
0
810
Create React App 読解特急
mqtsuo02
0
100
JekyllとBootstrapを使って静的なブログを作ってみたよ
mqtsuo02
0
88
Other Decks in Technology
See All in Technology
学生・新卒・ジュニアから目指すSRE
hiroyaonoe
2
760
外部キー制約の知っておいて欲しいこと - RDBMSを正しく使うために必要なこと / FOREIGN KEY Night
soudai
PRO
12
5.6k
コスト削減から「セキュリティと利便性」を担うプラットフォームへ
sansantech
PRO
3
1.6k
顧客との商談議事録をみんなで読んで顧客解像度を上げよう
shibayu36
0
320
日本の85%が使う公共SaaSは、どう育ったのか
taketakekaho
1
240
We Built for Predictability; The Workloads Didn’t Care
stahnma
0
150
Amazon Bedrock Knowledge Basesチャンキング解説!
aoinoguchi
0
160
AIが実装する時代、人間は仕様と検証を設計する
gotalab555
1
380
~Everything as Codeを諦めない~ 後からCDK
mu7889yoon
3
500
22nd ACRi Webinar - NTT Kawahara-san's slide
nao_sumikawa
0
100
Webhook best practices for rock solid and resilient deployments
glaforge
2
310
pool.ntp.orgに ⾃宅サーバーで 参加してみたら...
tanyorg
0
800
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
87
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.8k
KATA
mclloyd
PRO
34
15k
GitHub's CSS Performance
jonrohan
1032
470k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.9k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
1
1.3k
The Curse of the Amulet
leimatthew05
1
8.7k
How to Think Like a Performance Engineer
csswizardry
28
2.5k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
110
Transcript
@mqtsuo02 2019-05-29 React LT会 EmotionでReactをstylingすれば モテるかもしれない
自己紹介 - フリーランスのWebエンジニア - 直近2年間はずっとReactメイン - ReactのSPA3本、ReactNative1本やった - 最近はNext.jsとGAEが好き
Reactでstylingといえば....
いろいろあるけど...
None
ですが...
こんなやつもいます...
自己紹介 - CSS in JS のライブラリ - 高性能:パフォーマンスがいい - 多機能:色々な方法でstylingできる
- 大人気:★ 8,000 over - とてもエモーショナルなロゴですね emotion-js / emotion
多機能な点において styled-componentsに完全勝利
Emotionのstyling いろいろ - css prop (Object styles) - css prop
(String styles) - Styled Components (String styles) - Styled Components (Object styles)
css prop (Object styles) const textStyle = { color: "red"
}; const Page = () => ( <div css={textStyle}>Emotion でモテモテ</div> ); Inline stylesと同じ要領のstyling cssプロパティに指定する
@emotion/coreのcss関数を使うと CSSと同じように書ける css prop (String styles) import { css }
from "@emotion/core" ; const textStyle = css` color: blue; `; const Page = () => ( <div css={textStyle}>Emotion でモテモテ</div> );
styleの共通化はこんな感じに書ける const baseStyleSt = css` color: black; `; const textStyleSt
= css` ${baseStyleSt}; font-size: .8rem; color: blue; `; const baseStyleOb = { color: "black", }; const textStyleOb = { ...baseStyleOb, fontSize: ".8rem", color: "blue", }; String Styles Object Styles
Styled Components (String styles) styled-componentsと同じ要領で書ける import styled from "@emotion/styled" ;
const MoteText = styled.div` color: yellow; `; const Page = () => ( <MoteText>Emotionでモテモテ</MoteText> );
Styled Components (Object styles) import styled from "@emotion/styled" ; const
MoteText = styled.div({ color: "green", }); const Page = () => ( <MoteText>Emotionでモテモテ</MoteText> ); styled-componentsと同じ要領で書ける
$ npm install --save @emotion/core 導入方法 (css props) /** @jsx
jsx */ import { jsx, css } from "@emotion/core" ; @emotion/core パッケージをインストール 各ページファイルでプラグマを書いて Reactの代わりに jsx モジュールをimportする
$ npm install --save @emotion/styled 導入方法 (Styled Components) import React
from "react"; import styled from "@emotion/styled" ; @emotion/styled パッケージをインストール styledだけを使う場合は、プラグマは必要なし styled-components と同じ使用感
Emotionは他にもいろいろな機能がある - Globalコンポーネントでglobalのstylingができる - ネストされてるelementに対してもstylingできる - propsの値から動的なstylingもできる - 姉妹パッケージのfacepaintでメディアクエリをいい感じに書ける -
TypeScriptの型定義がパッケージに入っているのでtsxへの導入も楽
Emotionはこんな人にオススメかもしれない - stylingをとことんカスタムしたい人 - Inline Stylesっぽい感じでclassによるstylingがしたい人 - 環境整備だけして、styling方法は後で考えたい人 - とりあえずナウいパッケージ使いたい人
そうゆうことだ
ReactやってるならEmotionもさわった方がいい プラグマはうざいけど、多機能なのはいい 個人的にはこのロゴ(絵文字)好き Reactのお仕事おまちしてます! このLTで伝えたかったこと
E N D