Skip to content

Commit

Permalink
update to new stitches version and api
Browse files Browse the repository at this point in the history
  • Loading branch information
christianalfoni committed Jul 6, 2020
1 parent 55bfafc commit 1ddaf06
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 87 deletions.
8 changes: 3 additions & 5 deletions examples/with-stitches-styled/css/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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',
Expand All @@ -12,6 +12,4 @@ const config = createConfig({
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>
))}
</>
),
}
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
24 changes: 2 additions & 22 deletions examples/with-stitches/css/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
import { createConfig } from '@stitches/css'
import { createCss } from '@stitches/css'
import * as React from 'react'

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>
))}
</>
),
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>
)
}

0 comments on commit 1ddaf06

Please sign in to comment.