Commit 99362592 authored by Tomáš Hapl's avatar Tomáš Hapl Committed by Tim Neutkens

example with orbit-components (#6793)

parent 9504a389
{
"presets": ["next/babel"],
"plugins": [["styled-components", { "ssr": true }], "@kiwicom/babel-plugin-orbit-components"]
}
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-orbit-components)
# Example app with styled-components
## How to use
### Using `create-next-app`
Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example:
```bash
npx create-next-app --example with-orbit-components with-orbit-components-app
# or
yarn create next-app --example with-orbit-components with-orbit-components-app
```
### Download manually
Download the example:
```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-orbit-components
cd with-orbit-components
```
Install it and run:
```bash
npm install
npm run dev
# or
yarn
yarn dev
```
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
```bash
now
```
## The idea behind the example
[Orbit-components](https://orbit.kiwi) is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.
For this purpose we are extending `<App />` of injected `<ThemeProvider/>`, and also adding `@kiwicom/babel-plugin-orbit-components`
This fork comes from [styled-components-example](https://github.com/zeit/next.js/tree/canary/examples/with-styled-components)
{
"name": "with-styled-components",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@kiwicom/orbit-components": "latest",
"next": "latest",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"styled-components": "^4.0.0"
},
"devDependencies": {
"@kiwicom/babel-plugin-orbit-components": "latest",
"babel-plugin-styled-components": "^1.8.0"
},
"license": "ISC"
}
import * as React from 'react'
import App, { Container } from 'next/app'
import { getTokens } from '@kiwicom/orbit-components'
import { ThemeProvider, createGlobalStyle } from 'styled-components'
const GlobalStyle = createGlobalStyle`
body {
width: 100vw;
height: 100vh;
margin: 0 auto;
background-color: ${({ theme }) => theme.orbit.paletteCloudLight};
}
`
const tokens = getTokens()
export default class MyApp extends App {
render () {
const { Component, pageProps } = this.props
return (
<Container>
<ThemeProvider theme={{ orbit: tokens }}>
<>
<GlobalStyle />
<Component {...pageProps} />
</>
</ThemeProvider>
</Container>
)
}
}
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()
}
}
}
import React from 'react'
import { Alert, Illustration } from '@kiwicom/orbit-components'
export default () => {
return (
<React.Fragment>
<Alert type='success' spaceAfter='large'>It Works!</Alert>
<Illustration name='Success' />
</React.Fragment>
)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment