Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update example: update to new stitches version and api #14876

Merged
merged 4 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions examples/with-stitches-styled/css/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { createConfig } from '@stitches/css'
import { createCss } from '@stitches/css'
import { createStyled } from '@stitches/styled'

const config = createConfig({
export const css = createCss({
tokens: {
colors: {
RED: 'tomato',
},
},
})
/*
With Typescript:
const { Provider, styled, useCss } = createStyled<typeof config>()
*/
const { Provider, styled, useCss } = createStyled()

export { config, Provider, styled, useCss }
export const styled = createStyled(css)
4 changes: 2 additions & 2 deletions examples/with-stitches-styled/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"start": "next start"
},
"dependencies": {
"@stitches/css": "2.0.6",
"@stitches/styled": "2.0.6",
"@stitches/css": "3.0.0",
"@stitches/styled": "3.0.0",
"next": "9.3.5",
"react": "16.13.1",
"react-dom": "16.13.1"
Expand Down
18 changes: 0 additions & 18 deletions examples/with-stitches-styled/pages/_app.js

This file was deleted.

19 changes: 11 additions & 8 deletions examples/with-stitches-styled/pages/_document.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import Document from 'next/document'
import { createCss } from '@stitches/css'
import { config } from '../css'
import { css } from '../css'

export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const css = createCss(config)
const originalRenderPage = ctx.renderPage

try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) => <App {...props} serverCss={css} />,
})
let extractedStyles
ctx.renderPage = () => {
const { styles, result } = css.getStyles(originalRenderPage)
extractedStyles = styles
return result
}

const initialProps = await Document.getInitialProps(ctx)

return {
...initialProps,
styles: (
<>
{initialProps.styles}
<style>{css.getStyles()}</style>
{extractedStyles.map((content) => (
<style>{content}</style>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a key here to prevent React from moaning? 😄

))}
</>
),
}
Expand Down
4 changes: 3 additions & 1 deletion examples/with-stitches-styled/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { styled } from '../css'

const Header = styled.h1((css) => css.color('RED'))
const Header = styled.h1({
color: 'RED',
})

export default function Home() {
return <Header>Hello world</Header>
Expand Down
25 changes: 2 additions & 23 deletions examples/with-stitches/css/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
import { createConfig } from '@stitches/css'
import * as React from 'react'
import { createCss } from '@stitches/css'

const config = createConfig({
export const css = createCss({
tokens: {
colors: {
RED: 'tomato',
},
},
})

/*
With Typescript:
const context = React.createContext<TCss<typeof config>>(null)
*/
const context = React.createContext(null)

/*
With Typescript:
const Provider = ({ css, children }: { css: TCss<typeof config>, children?: React.ReactNode }) => {
return <context.Provider value={css}>{children}</context.Provider>
}
*/
const Provider = ({ css, children }) => {
return <context.Provider value={css}>{children}</context.Provider>
}

const useCss = () => React.useContext(context)

export { config, Provider, useCss }
2 changes: 1 addition & 1 deletion examples/with-stitches/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start": "next start"
},
"dependencies": {
"@stitches/css": "2.0.6",
"@stitches/css": "3.0.0",
"next": "9.3.5",
"react": "16.13.1",
"react-dom": "16.13.1"
Expand Down
18 changes: 0 additions & 18 deletions examples/with-stitches/pages/_app.js

This file was deleted.

19 changes: 10 additions & 9 deletions examples/with-stitches/pages/_document.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { createCss } from '@stitches/css'
import Document from 'next/document'
import { config } from '../css'
import { css } from '../css'

export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const css = createCss(config)
const originalRenderPage = ctx.renderPage

try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) => <App {...props} serverCss={css} />,
})
let extractedStyles
ctx.renderPage = () => {
const { styles, result } = css.getStyles(originalRenderPage)
extractedStyles = styles
return result
}

const initialProps = await Document.getInitialProps(ctx)

return {
...initialProps,
styles: (
<>
{initialProps.styles}
{css.getStyles().map((css, index) => (
<style key={index}>{css}</style>
{extractedStyles.map((content) => (
<style>{content}</style>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a key here to prevent React from moaning? 😄

))}
</>
),
Expand Down
13 changes: 10 additions & 3 deletions examples/with-stitches/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { useCss } from '../css'
import { css } from '../css'

export default function Home() {
const css = useCss()
return <h1 className={css.color('RED')}>Hello world</h1>
return (
<h1
className={css({
color: 'RED',
})}
>
Hello world
</h1>
)
}