Skip to content

Commit 678aea9

Browse files
committed
modernise demo site
1 parent d01e04c commit 678aea9

File tree

8 files changed

+3081
-3433
lines changed

8 files changed

+3081
-3433
lines changed

demo/.babelrc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"presets": [
3-
"next/babel"
4-
],
5-
"plugins": [
6-
["babel-plugin-styled-components", {
7-
"displayName": true,
8-
"ssr": true,
9-
"uglifyPure": false
10-
}],
11-
"babel-plugin-polished"
12-
]
2+
"presets": [
3+
"next/babel"
4+
],
5+
"plugins": [
6+
["styled-components", {
7+
"displayName": true,
8+
"ssr": true,
9+
"uglifyPure": false
10+
}],
11+
"polished"
12+
]
1313
}

demo/components/GlobalStyle.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { createGlobalStyle } from 'styled-components';
2+
import { background } from '../utils/colors';
3+
4+
const resetStyles = `
5+
*,::after,::before{background-repeat:no-repeat;box-sizing:inherit}::after,::before{text-decoration:inherit;vertical-align:inherit}html{box-sizing:border-box;cursor:default;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}article,aside,footer,header,nav,section{display:block}body{margin:0}h1{font-size:2em;margin:.67em 0}figcaption,figure,main{display:block}figure{margin:1em 40px}hr{box-sizing:content-box;height:0;overflow:visible}nav ol,nav ul{list-style:none}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent;-webkit-text-decoration-skip:objects}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:inherit}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}dfn{font-style:italic}mark{background-color:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}::-moz-selection{background-color:#b3d4fc;color:#000;text-shadow:none}::selection{background-color:#b3d4fc;color:#000;text-shadow:none}audio,canvas,iframe,img,svg,video{vertical-align:middle}audio,video{display:inline-block}audio:not([controls]){display:none;height:0}img{border-style:none}svg{fill:currentColor}svg:not(:root){overflow:hidden}table{border-collapse:collapse}button,input,optgroup,select,textarea{margin:0}button,input,select,textarea{background-color:transparent;color:inherit;font-size:inherit;line-height:inherit}button,input{overflow:visible}button,select{text-transform:none}[type=reset],[type=submit],button,html [type=button]{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{display:inline-block;vertical-align:baseline}textarea{overflow:auto;resize:vertical}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-cancel-button,[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details,menu{display:block}summary{display:list-item}canvas{display:inline-block}template{display:none}[tabindex],a,area,button,input,label,select,summary,textarea{-ms-touch-action:manipulation;touch-action:manipulation}[hidden]{display:none}[aria-busy=true]{cursor:progress}[aria-controls]{cursor:pointer}[aria-hidden=false][hidden]:not(:focus){clip:rect(0,0,0,0);display:inherit;position:absolute}[aria-disabled]{cursor:default}
6+
`;
7+
8+
const mainStyles = `
9+
@font-face {
10+
font-family: 'Source Code Pro';
11+
font-style: normal;
12+
font-weight: 400;
13+
src: local('Source Code Pro'), local('SourceCodePro-Regular'), url(https://fonts.gstatic.com/s/sourcecodepro/v6/mrl8jkM18OlOQN8JLgasD5bPFduIYtoLzwST68uhz_Y.woff2) format('woff2');
14+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
15+
}
16+
17+
@font-face {
18+
font-family: 'Montserrat';
19+
font-style: normal;
20+
font-weight: 400;
21+
src: local('Montserrat Regular'), local('Montserrat-Regular'), url(https://fonts.gstatic.com/s/montserrat/v10/zhcz-_WihjSQC0oHJ9TCYAzyDMXhdD8sAj6OAJTFsBI.woff2) format('woff2');
22+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
23+
}
24+
25+
@font-face {
26+
font-family: 'Montserrat';
27+
font-style: normal;
28+
font-weight: 500;
29+
src: local('Montserrat Medium'), local('Montserrat-Medium'), url(https://fonts.gstatic.com/s/montserrat/v10/BYPM-GE291ZjIXBWrtCweteM9fzAXBk846EtUMhet0E.woff2) format('woff2');
30+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
31+
}
32+
33+
html, body {
34+
font-size: 16px;
35+
line-height: 1.3;
36+
font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
37+
font-weight: normal;
38+
font-style: normal;
39+
padding: 0;
40+
margin: 0;
41+
background: ${background};
42+
color: #f8f8f2;
43+
}
44+
45+
.root {
46+
position: relative;
47+
overflow: auto;
48+
min-height: 100vh;
49+
z-index: 0;
50+
}
51+
52+
@media (max-width: 1200px) {
53+
html, body {
54+
font-size: 14px;
55+
}
56+
}
57+
`;
58+
59+
const GlobalStyle = createGlobalStyle`
60+
${resetStyles}
61+
${mainStyles}
62+
`;
63+
64+
export default GlobalStyle;

demo/components/Header.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const SubTitle = styled.h2`
1919
}
2020
`;
2121

22-
const StyledProjectBadge = styled(ProjectBadge)`
23-
height: 230px;
22+
const BadgeContainer = styled.div`
23+
width: 230px;
2424
`;
2525

2626
const Title = styled.h1`
@@ -82,11 +82,13 @@ const Container = styled.div`
8282
const Header = () => (
8383
<Container>
8484
<TitleRow>
85-
<StyledProjectBadge
86-
color="#f677e1"
87-
abbreviation="Rl"
88-
description="React Live"
89-
/>
85+
<BadgeContainer>
86+
<ProjectBadge
87+
color="#f677e1"
88+
abbreviation="Rl"
89+
description="React Live"
90+
/>
91+
</BadgeContainer>
9092

9193
<div>
9294
<Title>React Live</Title>

demo/next.config.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,8 @@ const path = require('path');
22

33
module.exports = {
44
webpack: config => {
5-
if (process.env.CONTEXT) {
6-
return config;
7-
}
8-
9-
config.resolve.alias = {
10-
'react-live': path.resolve('../'),
11-
react: path.resolve('../node_modules/react'),
12-
'react-dom': path.resolve('../node_modules/react-dom')
13-
};
5+
config.resolve.alias['react-live'] = path.resolve('../');
146

157
return config;
16-
},
17-
exportPathMap: () => ({
18-
'/': { page: '/' }
19-
})
8+
}
209
};

demo/package.json

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
{
22
"name": "react-live-demo",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"private": true,
55
"license": "MIT",
66
"scripts": {
77
"prebuild": "cd .. && yarn && yarn build",
88
"prebuild:npm": "cd .. && npm i && npm run build",
9-
"dev": "next",
9+
"dev": "next dev",
1010
"build": "next build",
11-
"start": "NODE_ENV=production next start"
11+
"start": "next start"
1212
},
1313
"dependencies": {
14-
"babel-plugin-polished": "^1.0.3",
15-
"babel-plugin-styled-components": "^1.5.0",
16-
"express": "^4.15.2",
17-
"formidable-oss-badges": "^0.2.1",
18-
"lru-cache": "^4.0.2",
19-
"module-alias": "^2.0.0",
20-
"next": "^5.0.0",
21-
"polished": "^1.0.2",
22-
"react": "^16.9.0",
23-
"react-dom": "^16.9.0",
24-
"react-is": "^16.9.0",
25-
"react-live": "^2.1.2",
26-
"styled-components": "^5.0.0-beta.8",
27-
"stylis": "^3.5.4"
14+
"formidable-oss-badges": "^0.3.5",
15+
"next": "9.5.3",
16+
"polished": "^3.6.7",
17+
"react": "16.13.1",
18+
"react-dom": "16.13.1",
19+
"react-live": "^2.2.2",
20+
"styled-components": "^5.2.0"
21+
},
22+
"devDependencies": {
23+
"babel-plugin-polished": "^1.1.0",
24+
"babel-plugin-styled-components": "^1.11.1"
2825
}
2926
}

demo/pages/_app.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import Head from 'next/head';
3+
import GlobalStyle from '../components/GlobalStyle';
4+
5+
export default function App({ Component, pageProps }) {
6+
return (
7+
<>
8+
<Head>
9+
<meta name="viewport" content="width=device-width, initial-scale=1" />
10+
<title>React Live Demo</title>
11+
<meta httpEquiv="X-UA-Compatible" content="IE=edge,chrome=1" />
12+
</Head>
13+
<GlobalStyle />
14+
<Component {...pageProps} />
15+
</>
16+
);
17+
}

demo/pages/_document.js

Lines changed: 26 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,44 @@
1-
import Document, { Head, Main, NextScript } from 'next/document';
1+
import Document, { Html, Head, Main, NextScript } from 'next/document';
22
import { ServerStyleSheet } from 'styled-components';
3-
import { background } from '../utils/colors';
4-
5-
const resetStyles = `
6-
*,::after,::before{background-repeat:no-repeat;box-sizing:inherit}::after,::before{text-decoration:inherit;vertical-align:inherit}html{box-sizing:border-box;cursor:default;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}article,aside,footer,header,nav,section{display:block}body{margin:0}h1{font-size:2em;margin:.67em 0}figcaption,figure,main{display:block}figure{margin:1em 40px}hr{box-sizing:content-box;height:0;overflow:visible}nav ol,nav ul{list-style:none}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent;-webkit-text-decoration-skip:objects}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:inherit}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}dfn{font-style:italic}mark{background-color:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}::-moz-selection{background-color:#b3d4fc;color:#000;text-shadow:none}::selection{background-color:#b3d4fc;color:#000;text-shadow:none}audio,canvas,iframe,img,svg,video{vertical-align:middle}audio,video{display:inline-block}audio:not([controls]){display:none;height:0}img{border-style:none}svg{fill:currentColor}svg:not(:root){overflow:hidden}table{border-collapse:collapse}button,input,optgroup,select,textarea{margin:0}button,input,select,textarea{background-color:transparent;color:inherit;font-size:inherit;line-height:inherit}button,input{overflow:visible}button,select{text-transform:none}[type=reset],[type=submit],button,html [type=button]{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{display:inline-block;vertical-align:baseline}textarea{overflow:auto;resize:vertical}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-cancel-button,[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details,menu{display:block}summary{display:list-item}canvas{display:inline-block}template{display:none}[tabindex],a,area,button,input,label,select,summary,textarea{-ms-touch-action:manipulation;touch-action:manipulation}[hidden]{display:none}[aria-busy=true]{cursor:progress}[aria-controls]{cursor:pointer}[aria-hidden=false][hidden]:not(:focus){clip:rect(0,0,0,0);display:inherit;position:absolute}[aria-disabled]{cursor:default}
7-
`;
8-
9-
const mainStyles = `
10-
@font-face {
11-
font-family: 'Source Code Pro';
12-
font-style: normal;
13-
font-weight: 400;
14-
src: local('Source Code Pro'), local('SourceCodePro-Regular'), url(https://fonts.gstatic.com/s/sourcecodepro/v6/mrl8jkM18OlOQN8JLgasD5bPFduIYtoLzwST68uhz_Y.woff2) format('woff2');
15-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
16-
}
17-
18-
@font-face {
19-
font-family: 'Montserrat';
20-
font-style: normal;
21-
font-weight: 400;
22-
src: local('Montserrat Regular'), local('Montserrat-Regular'), url(https://fonts.gstatic.com/s/montserrat/v10/zhcz-_WihjSQC0oHJ9TCYAzyDMXhdD8sAj6OAJTFsBI.woff2) format('woff2');
23-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
24-
}
25-
26-
@font-face {
27-
font-family: 'Montserrat';
28-
font-style: normal;
29-
font-weight: 500;
30-
src: local('Montserrat Medium'), local('Montserrat-Medium'), url(https://fonts.gstatic.com/s/montserrat/v10/BYPM-GE291ZjIXBWrtCweteM9fzAXBk846EtUMhet0E.woff2) format('woff2');
31-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
32-
}
33-
34-
html, body {
35-
font-size: 16px;
36-
line-height: 1.3;
37-
font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
38-
font-weight: normal;
39-
font-style: normal;
40-
padding: 0;
41-
margin: 0;
42-
background: ${background};
43-
color: #f8f8f2;
44-
}
45-
46-
.root {
47-
position: relative;
48-
overflow: auto;
49-
min-height: 100vh;
50-
z-index: 0;
51-
}
52-
53-
@media (max-width: 1200px) {
54-
html, body {
55-
font-size: 14px;
56-
}
57-
}
58-
`;
59-
60-
const globalStyles = resetStyles + '\n' + mainStyles + '\n';
613

624
export default class MyDocument extends Document {
63-
static getInitialProps({ renderPage }) {
5+
static async getInitialProps(ctx) {
646
const sheet = new ServerStyleSheet();
65-
66-
const page = renderPage(Component => props =>
67-
sheet.collectStyles(<Component {...props} />)
68-
);
69-
70-
const styleElements = sheet.getStyleElement();
71-
return { ...page, styleElements };
7+
const originalRenderPage = ctx.renderPage;
8+
9+
try {
10+
ctx.renderPage = () =>
11+
originalRenderPage({
12+
enhanceApp: App => props => sheet.collectStyles(<App {...props} />)
13+
});
14+
15+
const initialProps = await Document.getInitialProps(ctx);
16+
return {
17+
...initialProps,
18+
styles: (
19+
<>
20+
{initialProps.styles}
21+
{sheet.getStyleElement()}
22+
</>
23+
)
24+
};
25+
} finally {
26+
sheet.seal();
27+
}
7228
}
7329

7430
render() {
75-
const { styleElements } = this.props;
76-
7731
return (
78-
<html>
79-
<Head>
80-
<meta name="viewport" content="width=device-width, initial-scale=1" />
81-
82-
<title>React Live Demo</title>
83-
84-
<meta httpEquiv="X-UA-Compatible" content="IE=edge,chrome=1" />
85-
86-
<style dangerouslySetInnerHTML={{ __html: globalStyles }} />
87-
{styleElements}
88-
</Head>
89-
32+
<Html>
33+
<Head />
9034
<body>
9135
<div className="root">
9236
<Main />
9337
</div>
9438

9539
<NextScript />
9640
</body>
97-
</html>
41+
</Html>
9842
);
9943
}
10044
}

0 commit comments

Comments
 (0)