Skip to content

Commit

Permalink
Switch out styled-components for emotion
Browse files Browse the repository at this point in the history
  • Loading branch information
12 committed Jun 12, 2020
1 parent 4149caa commit ae8ea90
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 92 deletions.
52 changes: 39 additions & 13 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"react-hot-loader/babel",
[
"@babel/plugin-transform-runtime",
{
"regenerator": true
}
]
]
"env": {
"production": {
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"emotion",
"react-hot-loader/babel",
[
"@babel/plugin-transform-runtime",
{
"regenerator": true
}
]
]
},
"development": {
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
[
"emotion",
{
"sourceMap": true
}
],
"react-hot-loader/babel",
[
"@babel/plugin-transform-runtime",
{
"regenerator": true
}
]
]
}
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
npm-debug.log
.vscode
.DS_Store
dist
dist
yarn-error.log
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="manifest" href="/manifest.json" />
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins">
<meta name="msapplication-TileColor" content="#da532c" />
<meta name="theme-color" content="#ffffff" />
<title>London Tube Status</title>
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@babel/preset-react": "^7.9.4",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.0.5",
"babel-plugin-emotion": "^10.0.33",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^6.0.2",
"eslint": "^7.0.0",
Expand All @@ -35,9 +36,10 @@
},
"dependencies": {
"@babel/runtime": "^7.10.2",
"@emotion/core": "^10.0.28",
"@emotion/styled": "^10.0.27",
"prop-types": "^15.7.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"styled-components": "^5.1.1"
"react-dom": "^16.13.1"
}
}
15 changes: 8 additions & 7 deletions src/Containers/App/index.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { Fragment, useState, useEffect } from 'react';
import React, { useState, useEffect } from 'react';
import { Global } from '@emotion/core';
import Line from '../../Components/Line';
import dataBroker from '../../Helpers/dataBroker';
import sortData from '../../Helpers/sortData';
import { GlobalStyled, WrapperStyled, GithubLinkStyled } from '../../Helpers/styles';
import { globalStyles, WrapperStyled, GithubLinkStyled } from '../../Helpers/styles';

const endpoint =
'https://api.tfl.gov.uk/line/mode/tube%2Cdlr%2Coverground%2Ctflrail%2Ctram%2Ccable-car/status';
Expand All @@ -24,19 +25,19 @@ const App = () => {
}, []);

return (
<Fragment>
<GlobalStyled />
<>
<Global styles={globalStyles} />
<WrapperStyled>
{lines.map(line => (
{lines && lines.map(line => (
<Line key={line.name} line={line} />
))}
</WrapperStyled>
</WrapperStyled> */}
{!!lines.length && (
<GithubLinkStyled href="https://github.com/12/tube-status">
Open source on Github!
</GithubLinkStyled>
)}
</Fragment>
</>
);
};

Expand Down
19 changes: 9 additions & 10 deletions src/Helpers/styles.js → src/Helpers/styles.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled, { createGlobalStyle } from 'styled-components';
import styled from '@emotion/styled';
import { css } from '@emotion/core';

const PAGE_COLOUR = '#273c75';
const WHITE = '#fefefe';
Expand All @@ -22,15 +23,7 @@ const LINE_COLOURS = {
tfl: '#0007ab'
};

const lineBackgroundColour = ({ name }) => {
const convertedName = name.split(' ')[0];

return LINE_COLOURS[convertedName.toLowerCase()] || WHITE;
};

export const GlobalStyled = createGlobalStyle`
@import url('https://fonts.googleapis.com/css?family=Poppins');
export const globalStyles = css`
body {
background: ${PAGE_COLOUR};
-webkit-font-smoothing: antialiased;
Expand All @@ -47,6 +40,12 @@ export const GlobalStyled = createGlobalStyle`
}
`;

const lineBackgroundColour = ({ name }) => {
const convertedName = name.split(' ')[0];

return LINE_COLOURS[convertedName.toLowerCase()] || WHITE;
};

export const WrapperStyled = styled.div`
margin: 0 auto;
width: 60%;
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = (env, argv) => {
new HtmlWebpackPlugin({
template: './index.html',
}),
new CopyPlugin({ patterns: [ { from: 'assets', to: 'dist' } ]})
new CopyPlugin({ patterns: [ { from: 'assets', to: '.' } ]})
],
resolve: {
extensions: ['.js', '.jsx'],
Expand Down
Loading

0 comments on commit ae8ea90

Please sign in to comment.