Unverified Commit f637c8a2 authored by Tobias Lundgren's avatar Tobias Lundgren Committed by GitHub

Update Chakra UI examples to v1 (#19282)

- Upgrade TypeScript example to Chakra UI v1
- Upgrade to React 17
- Patch some missing parts and fix broken icons in non TypeScript example
- Add example how to persist color mode when you refresh the page: https://chakra-ui.com/docs/features/color-mode#add-colormodescript

Source: https://chakra-ui.com/docs/migration
parent 53a4458b
......@@ -7,18 +7,21 @@
"start": "next start"
},
"dependencies": {
"@chakra-ui/core": "^1.0.0-rc.8",
"@chakra-ui/icons": "^1.0.0-rc.8",
"@chakra-ui/icons": "^1.0.0",
"@chakra-ui/react": "^1.0.0",
"@chakra-ui/theme-tools": "1.0.0",
"@emotion/react": "11.1.1",
"@emotion/styled": "11.0.0",
"framer-motion": "^2.9.4",
"next": "latest",
"react": "^16.13.1",
"react-dom": "^16.13.1"
"react": "^17.0.1",
"react-dom": "^17.0.1"
},
"devDependencies": {
"@types/node": "^14.6.0",
"@types/react": "^16.9.46",
"@types/react-dom": "^16.9.8",
"typescript": "4.0.2"
"typescript": "4.0.5"
},
"license": "MIT"
}
import { Link as ChakraLink, Button } from '@chakra-ui/core'
import { Link as ChakraLink, Button } from '@chakra-ui/react'
import { Container } from './Container'
......
import { Flex, useColorMode, FlexProps } from '@chakra-ui/core'
import { Flex, useColorMode, FlexProps } from '@chakra-ui/react'
export const Container = (props: FlexProps) => {
const { colorMode } = useColorMode()
......
import { useColorMode, Switch } from '@chakra-ui/core'
import { useColorMode, Switch } from '@chakra-ui/react'
export const DarkModeSwitch = () => {
const { colorMode, toggleColorMode } = useColorMode()
......
import { Flex, FlexProps } from '@chakra-ui/core'
import { Flex, FlexProps } from '@chakra-ui/react'
export const Footer = (props: FlexProps) => (
<Flex as="footer" py="8rem" {...props} />
......
import { Flex, Heading } from '@chakra-ui/core'
import { Flex, Heading } from '@chakra-ui/react'
export const Hero = ({ title }: { title: string }) => (
<Flex justifyContent="center" alignItems="center" height="100vh">
......
import { Stack, StackProps } from '@chakra-ui/core'
import { Stack, StackProps } from '@chakra-ui/react'
export const Main = (props: StackProps) => (
<Stack
......
import { ChakraProvider } from '@chakra-ui/core'
import { ChakraProvider } from '@chakra-ui/react'
import theme from '../theme'
import { AppProps } from 'next/app'
......
import NextDocument, { Html, Head, Main, NextScript } from 'next/document'
import { ColorModeScript } from '@chakra-ui/react'
export default class Document extends NextDocument {
render() {
return (
<Html>
<Head />
<body>
{/* Make Color mode to persists when you refresh the page. */}
<ColorModeScript />
<Main />
<NextScript />
</body>
</Html>
)
}
}
......@@ -5,7 +5,7 @@ import {
List,
ListIcon,
ListItem,
} from '@chakra-ui/core'
} from '@chakra-ui/react'
import { CheckCircleIcon, LinkIcon } from '@chakra-ui/icons'
import { Hero } from '../components/Hero'
......
import { theme as chakraTheme } from '@chakra-ui/core'
import { extendTheme } from '@chakra-ui/react'
import { createBreakpoints } from '@chakra-ui/theme-tools'
const fonts = { ...chakraTheme.fonts, mono: `'Menlo', monospace` }
const fonts = { mono: `'Menlo', monospace` }
const breakpoints = ['40em', '52em', '64em']
const breakpoints = createBreakpoints({
sm: '40em',
md: '52em',
lg: '64em',
xl: '80em',
})
const theme = {
...chakraTheme,
const theme = extendTheme({
colors: {
...chakraTheme.colors,
black: '#16161D',
},
fonts,
breakpoints,
}
})
export default theme
......@@ -11,7 +11,6 @@
"@chakra-ui/react": "^1.0.0",
"@emotion/react": "^11.0.0",
"@emotion/styled": "^11.0.0",
"emotion-theming": "^11.0.0",
"framer-motion": "^2.9.4",
"next": "latest",
"react": "^17.0.1",
......
import { ThemeProvider, CSSReset, ColorModeProvider } from '@chakra-ui/react'
import { ChakraProvider, ColorModeProvider } from '@chakra-ui/react'
import theme from '../theme'
function MyApp({ Component, pageProps }) {
return (
<ThemeProvider theme={theme}>
<ChakraProvider resetCSS theme={theme}>
<ColorModeProvider
options={{
useSystemColorMode: true,
}}
>
<CSSReset />
<Component {...pageProps} />
</ColorModeProvider>
</ThemeProvider>
</ChakraProvider>
)
}
......
import NextDocument, { Html, Head, Main, NextScript } from 'next/document'
import { ColorModeScript } from '@chakra-ui/react'
export default class Document extends NextDocument {
render() {
return (
<Html>
<Head />
<body>
{/* Make Color mode to persists when you refresh the page. */}
<ColorModeScript />
<Main />
<NextScript />
</body>
</Html>
)
}
}
......@@ -2,12 +2,11 @@ import {
Link as ChakraLink,
Text,
Code,
Icon,
List,
ListIcon,
ListItem,
} from '@chakra-ui/react'
import { ExternalLinkIcon } from '@chakra-ui/icons'
import { CheckCircleIcon, LinkIcon } from '@chakra-ui/icons'
import { Hero } from '../components/Hero'
import { Container } from '../components/Container'
import { Main } from '../components/Main'
......@@ -16,7 +15,7 @@ import { CTA } from '../components/CTA'
import { Footer } from '../components/Footer'
const Index = () => (
<Container>
<Container height="100vh">
<Hero />
<Main>
<Text>
......@@ -25,20 +24,20 @@ const Index = () => (
<List spacing={3} my={0}>
<ListItem>
<ListIcon icon="check-circle" color="green.500" />
<ListIcon as={CheckCircleIcon} color="green.500" />
<ChakraLink
isExternal
href="https://chakra-ui.com"
flexGrow={1}
mr={2}
>
Chakra UI <Icon as={ExternalLinkIcon} mx="2px" />
Chakra UI <LinkIcon />
</ChakraLink>
</ListItem>
<ListItem>
<ListIcon icon="check-circle" color="green.500" />
<ListIcon as={CheckCircleIcon} color="green.500" />
<ChakraLink isExternal href="https://nextjs.org" flexGrow={1} mr={2}>
Next.js <Icon as={ExternalLinkIcon} mx="2px" />
Next.js <LinkIcon />
</ChakraLink>
</ListItem>
</List>
......
import { theme as chakraTheme } from '@chakra-ui/react'
import { extendTheme } from '@chakra-ui/react'
import { createBreakpoints } from '@chakra-ui/theme-tools'
const fonts = { ...chakraTheme.fonts, mono: `'Menlo', monospace` }
const fonts = { mono: `'Menlo', monospace` }
const breakpoints = ['40em', '52em', '64em']
const breakpoints = createBreakpoints({
sm: '40em',
md: '52em',
lg: '64em',
xl: '80em',
})
const theme = {
...chakraTheme,
const theme = extendTheme({
colors: {
...chakraTheme.colors,
black: '#16161D',
},
fonts,
breakpoints,
icons: {
...chakraTheme.icons,
logo: {
path: (
<svg
......@@ -33,6 +36,6 @@ const theme = {
viewBox: '0 0 3000 3163',
},
},
}
})
export default theme
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