Skip to content

Commit

Permalink
introduce styled-components
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur791004 committed Aug 15, 2019
1 parent 2e24f4f commit d46fc5a
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 7 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const config = {
'import/prefer-default-export': 0,
'no-else-return': 0,
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }],
'react/jsx-props-no-spreading': 0,
'react/jsx-wrap-multilines': [
'error',
{
Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ module.exports = {
},
},
],
['styled-components', { ssr: true }],
],
};
30 changes: 30 additions & 0 deletions components/GlobalStyle/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createGlobalStyle } from 'styled-components';

const GlobalStyle = createGlobalStyle`
html,
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
overflow: hidden;
}
body {
font-family: 'Helvetica', 'Arial', 'PingFang TC', 'Heiti TC', 'Microsoft Jhenghei', sans-serif;
font-size: 14px;
}
a {
text-decoration: none;
}
#__next {
position: relative;
height: 100%;
overflow-x: hidden;
overflow-y: auto;
}
`;

export default GlobalStyle;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
"dependencies": {
"next": "9.0.3",
"react": "16.9.0",
"react-dom": "16.9.0"
"react-dom": "16.9.0",
"styled-components": "~4.3.2"
},
"devDependencies": {
"babel-eslint": "~10.0.2",
"babel-plugin-module-resolver": "~3.2.0",
"babel-plugin-styled-components": "~1.10.6",
"eslint": "~6.1.0",
"eslint-config-airbnb": "~18.0.1",
"eslint-config-prettier": "~6.0.0",
Expand Down
16 changes: 16 additions & 0 deletions pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import App from 'next/app';
import GlobalStyle from '@/components/GlobalStyle';

export default class MyApp extends App {
render() {
const { Component, pageProps } = this.props;

return (
<>
<GlobalStyle />
<Component {...pageProps} />
</>
);
}
}
34 changes: 34 additions & 0 deletions pages/_document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import Document from 'next/document';
import { ServerStyleSheet, StyleSheetManager } from 'styled-components';

export default class MyDocument extends Document {
static async getInitialProps(context) {
const sheet = new ServerStyleSheet();
const { renderPage } = context;
const { styles, ...initialProps } = await Document.getInitialProps(context);
const styleElement = sheet.getStyleElement();

// eslint-disable-next-line no-param-reassign
context.renderPage = () =>
renderPage({
enhanceApp: App => props => (
<StyleSheetManager sheet={sheet.instance}>
<App {...props} />
</StyleSheetManager>
),
});

sheet.seal();

return {
...initialProps,
styles: (
<>
{styles}
{styleElement}
</>
),
};
}
}
87 changes: 81 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,20 @@
lodash "^4.17.13"
to-fast-properties "^2.0.0"

"@emotion/is-prop-valid@^0.8.1":
version "0.8.2"
resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-0.8.2.tgz#b9692080da79041683021fcc32f96b40c54c59dc"
dependencies:
"@emotion/memoize" "0.7.2"

"@emotion/memoize@0.7.2":
version "0.7.2"
resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.7.2.tgz#7f4c71b7654068dfcccad29553520f984cc66b30"

"@emotion/unitless@^0.7.0":
version "0.7.4"
resolved "https://registry.yarnpkg.com/@emotion/unitless/-/unitless-0.7.4.tgz#a87b4b04e5ae14a88d48ebef15015f6b7d1f5677"

"@nodelib/fs.scandir@2.1.1":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.1.tgz#7fa8fed654939e1a39753d286b48b4836d00e0eb"
Expand Down Expand Up @@ -1169,7 +1183,16 @@ babel-plugin-react-require@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/babel-plugin-react-require/-/babel-plugin-react-require-3.0.0.tgz#2e4e7b4496b93a654a1c80042276de4e4eeb20e3"

babel-plugin-syntax-jsx@6.18.0:
"babel-plugin-styled-components@>= 1", babel-plugin-styled-components@~1.10.6:
version "1.10.6"
resolved "https://registry.yarnpkg.com/babel-plugin-styled-components/-/babel-plugin-styled-components-1.10.6.tgz#f8782953751115faf09a9f92431436912c34006b"
dependencies:
"@babel/helper-annotate-as-pure" "^7.0.0"
"@babel/helper-module-imports" "^7.0.0"
babel-plugin-syntax-jsx "^6.18.0"
lodash "^4.17.11"

babel-plugin-syntax-jsx@6.18.0, babel-plugin-syntax-jsx@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"

Expand Down Expand Up @@ -1408,6 +1431,10 @@ callsites@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73"

camelize@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/camelize/-/camelize-1.0.0.tgz#164a5483e630fa4321e5af07020e531831b2609b"

caniuse-lite@^1.0.30000984:
version "1.0.30000989"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000989.tgz#b9193e293ccf7e4426c5245134b8f2a56c0ac4b9"
Expand Down Expand Up @@ -1708,6 +1735,18 @@ crypto-browserify@^3.11.0:
randombytes "^2.0.0"
randomfill "^1.0.3"

css-color-keywords@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/css-color-keywords/-/css-color-keywords-1.0.0.tgz#fea2616dc676b2962686b3af8dbdbe180b244e05"

css-to-react-native@^2.2.2:
version "2.3.1"
resolved "https://registry.yarnpkg.com/css-to-react-native/-/css-to-react-native-2.3.1.tgz#cf0f61e0514846e2d4dc188b0886e29d8bef64a2"
dependencies:
camelize "^1.0.0"
css-color-keywords "^1.0.0"
postcss-value-parser "^3.3.0"

css@2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/css/-/css-2.2.4.tgz#c646755c73971f2bba6a601e2cf2fd71b1298929"
Expand Down Expand Up @@ -2989,6 +3028,10 @@ is-symbol@^1.0.2:
dependencies:
has-symbols "^1.0.0"

is-what@^3.2.4:
version "3.3.1"
resolved "https://registry.yarnpkg.com/is-what/-/is-what-3.3.1.tgz#79502181f40226e2d8c09226999db90ef7c1bcbe"

is-windows@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d"
Expand Down Expand Up @@ -3285,13 +3328,23 @@ md5.js@^1.3.4:
inherits "^2.0.1"
safe-buffer "^5.1.2"

memoize-one@^5.0.0:
version "5.0.5"
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-5.0.5.tgz#8cd3809555723a07684afafcd6f756072ac75d7e"

memory-fs@^0.4.0, memory-fs@^0.4.1, memory-fs@~0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/memory-fs/-/memory-fs-0.4.1.tgz#3a9a20b8462523e447cfbc7e8bb80ed667bfc552"
dependencies:
errno "^0.1.3"
readable-stream "^2.0.1"

merge-anything@^2.2.4:
version "2.4.0"
resolved "https://registry.yarnpkg.com/merge-anything/-/merge-anything-2.4.0.tgz#86959caf02bb8969d1ae5e1b652862bc5fe54e44"
dependencies:
is-what "^3.2.4"

merge-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
Expand Down Expand Up @@ -4042,6 +4095,10 @@ posix-character-classes@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"

postcss-value-parser@^3.3.0:
version "3.3.1"
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-3.3.1.tgz#9ff822547e2893213cf1c30efa51ac5fd1ba8281"

prelude-ls@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
Expand Down Expand Up @@ -4084,7 +4141,7 @@ prop-types-exact@1.2.0:
object.assign "^4.1.0"
reflect.ownkeys "^0.2.0"

prop-types@15.7.2, prop-types@^15.6.2, prop-types@^15.7.2:
prop-types@15.7.2, prop-types@^15.5.4, prop-types@^15.6.2, prop-types@^15.7.2:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
dependencies:
Expand Down Expand Up @@ -4201,7 +4258,7 @@ react-is@16.8.6:
version "16.8.6"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"

react-is@^16.8.1:
react-is@^16.6.0, react-is@^16.8.1:
version "16.9.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.9.0.tgz#21ca9561399aad0ff1a7701c01683e8ca981edcb"

Expand Down Expand Up @@ -4801,6 +4858,24 @@ strip-json-comments@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"

styled-components@~4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/styled-components/-/styled-components-4.3.2.tgz#4ca81918c812d3006f60ac5fdec7d6b64a9509cc"
dependencies:
"@babel/helper-module-imports" "^7.0.0"
"@babel/traverse" "^7.0.0"
"@emotion/is-prop-valid" "^0.8.1"
"@emotion/unitless" "^0.7.0"
babel-plugin-styled-components ">= 1"
css-to-react-native "^2.2.2"
memoize-one "^5.0.0"
merge-anything "^2.2.4"
prop-types "^15.5.4"
react-is "^16.6.0"
stylis "^3.5.0"
stylis-rule-sheet "^0.0.10"
supports-color "^5.5.0"

styled-jsx@3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/styled-jsx/-/styled-jsx-3.2.1.tgz#452051fe50df5e9c7c7f3dd20fa46c3060ac65b0"
Expand All @@ -4814,19 +4889,19 @@ styled-jsx@3.2.1:
stylis "3.5.4"
stylis-rule-sheet "0.0.10"

stylis-rule-sheet@0.0.10:
stylis-rule-sheet@0.0.10, stylis-rule-sheet@^0.0.10:
version "0.0.10"
resolved "https://registry.yarnpkg.com/stylis-rule-sheet/-/stylis-rule-sheet-0.0.10.tgz#44e64a2b076643f4b52e5ff71efc04d8c3c4a430"

stylis@3.5.4:
stylis@3.5.4, stylis@^3.5.0:
version "3.5.4"
resolved "https://registry.yarnpkg.com/stylis/-/stylis-3.5.4.tgz#f665f25f5e299cf3d64654ab949a57c768b73fbe"

supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"

supports-color@^5.3.0:
supports-color@^5.3.0, supports-color@^5.5.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
dependencies:
Expand Down

0 comments on commit d46fc5a

Please sign in to comment.