mirror of
https://github.com/aljazceru/lightning-address.git
synced 2025-12-17 05:14:22 +01:00
Initial commit from Create Next App
This commit is contained in:
4
.babelrc
Normal file
4
.babelrc
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"presets": ["next/babel"],
|
||||||
|
"plugins": ["styled-components"]
|
||||||
|
}
|
||||||
34
.gitignore
vendored
Normal file
34
.gitignore
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# next.js
|
||||||
|
/.next/
|
||||||
|
/out/
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
|
||||||
|
# debug
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
# vercel
|
||||||
|
.vercel
|
||||||
84
README.md
Normal file
84
README.md
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
# Example app with styled-components
|
||||||
|
|
||||||
|
This example features how you use a different styling solution than [styled-jsx](https://github.com/vercel/styled-jsx) that also supports universal styles. That means we can serve the required styles for the first render within the HTML and then load the rest in the client. In this case we are using [styled-components](https://github.com/styled-components/styled-components).
|
||||||
|
|
||||||
|
For this purpose we are extending the `<Document />` and injecting the server side rendered styles into the `<head>`, and also adding the `babel-plugin-styled-components` (which is required for server side rendering). Additionally we set up a global [theme](https://www.styled-components.com/docs/advanced#theming) for styled-components using NextJS custom [`<App>`](https://nextjs.org/docs/advanced-features/custom-app) component.
|
||||||
|
|
||||||
|
## Preview
|
||||||
|
|
||||||
|
Preview the example live on [StackBlitz](http://stackblitz.com/):
|
||||||
|
|
||||||
|
[](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-styled-components)
|
||||||
|
|
||||||
|
## Deploy your own
|
||||||
|
|
||||||
|
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):
|
||||||
|
|
||||||
|
[](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-styled-components&project-name=with-styled-components&repository-name=with-styled-components)
|
||||||
|
|
||||||
|
## How to use
|
||||||
|
|
||||||
|
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx create-next-app --example with-styled-components with-styled-components-app
|
||||||
|
# or
|
||||||
|
yarn create next-app --example with-styled-components with-styled-components-app
|
||||||
|
```
|
||||||
|
|
||||||
|
Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
|
||||||
|
|
||||||
|
### Try it on CodeSandbox
|
||||||
|
|
||||||
|
[Open this example on CodeSandbox](https://codesandbox.io/s/github/vercel/next.js/tree/canary/examples/with-styled-components)
|
||||||
|
|
||||||
|
### Notes
|
||||||
|
|
||||||
|
When wrapping a [Link](https://nextjs.org/docs/api-reference/next/link) from `next/link` within a styled-component, the [as](https://styled-components.com/docs/api#as-polymorphic-prop) prop provided by `styled` will collide with the Link's `as` prop and cause styled-components to throw an `Invalid tag` error. To avoid this, you can either use the recommended [forwardedAs](https://styled-components.com/docs/api#forwardedas-prop) prop from styled-components or use a different named prop to pass to a `styled` Link.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Click to expand workaround example</summary>
|
||||||
|
<br />
|
||||||
|
|
||||||
|
**components/StyledLink.js**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import Link from 'next/link'
|
||||||
|
import styled from 'styled-components'
|
||||||
|
|
||||||
|
const StyledLink = ({ as, children, className, href }) => (
|
||||||
|
<Link href={href} as={as} passHref>
|
||||||
|
<a className={className}>{children}</a>
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default styled(StyledLink)`
|
||||||
|
color: #0075e0;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: all 0.2s ease-in-out;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: #40a9ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
color: #40a9ff;
|
||||||
|
outline: none;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
`
|
||||||
|
```
|
||||||
|
|
||||||
|
**pages/index.js**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import StyledLink from '../components/StyledLink'
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<StyledLink href="/post/[pid]" forwardedAs="/post/abc">
|
||||||
|
First post
|
||||||
|
</StyledLink>
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
19
package.json
Normal file
19
package.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"dev": "next",
|
||||||
|
"build": "next build",
|
||||||
|
"start": "next start"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"next": "latest",
|
||||||
|
"react": "^17.0.2",
|
||||||
|
"react-dom": "^17.0.2",
|
||||||
|
"react-is": "^17.0.2",
|
||||||
|
"styled-components": "^5.2.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"babel-plugin-styled-components": "^1.12.0"
|
||||||
|
},
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
26
pages/_app.js
Normal file
26
pages/_app.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { createGlobalStyle, ThemeProvider } from 'styled-components'
|
||||||
|
|
||||||
|
const GlobalStyle = createGlobalStyle`
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const theme = {
|
||||||
|
colors: {
|
||||||
|
primary: '#0070f3',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function App({ Component, pageProps }) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<GlobalStyle />
|
||||||
|
<ThemeProvider theme={theme}>
|
||||||
|
<Component {...pageProps} />
|
||||||
|
</ThemeProvider>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
30
pages/_document.js
Normal file
30
pages/_document.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import Document from 'next/document'
|
||||||
|
import { ServerStyleSheet } from 'styled-components'
|
||||||
|
|
||||||
|
export default class MyDocument extends Document {
|
||||||
|
static async getInitialProps(ctx) {
|
||||||
|
const sheet = new ServerStyleSheet()
|
||||||
|
const originalRenderPage = ctx.renderPage
|
||||||
|
|
||||||
|
try {
|
||||||
|
ctx.renderPage = () =>
|
||||||
|
originalRenderPage({
|
||||||
|
enhanceApp: (App) => (props) =>
|
||||||
|
sheet.collectStyles(<App {...props} />),
|
||||||
|
})
|
||||||
|
|
||||||
|
const initialProps = await Document.getInitialProps(ctx)
|
||||||
|
return {
|
||||||
|
...initialProps,
|
||||||
|
styles: (
|
||||||
|
<>
|
||||||
|
{initialProps.styles}
|
||||||
|
{sheet.getStyleElement()}
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
sheet.seal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
10
pages/index.js
Normal file
10
pages/index.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import styled from 'styled-components'
|
||||||
|
|
||||||
|
const Title = styled.h1`
|
||||||
|
font-size: 50px;
|
||||||
|
color: ${({ theme }) => theme.colors.primary};
|
||||||
|
`
|
||||||
|
|
||||||
|
export default function Home() {
|
||||||
|
return <Title>My page</Title>
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user