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 @@ ...@@ -7,18 +7,21 @@
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"@chakra-ui/core": "^1.0.0-rc.8", "@chakra-ui/icons": "^1.0.0",
"@chakra-ui/icons": "^1.0.0-rc.8", "@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", "framer-motion": "^2.9.4",
"next": "latest", "next": "latest",
"react": "^16.13.1", "react": "^17.0.1",
"react-dom": "^16.13.1" "react-dom": "^17.0.1"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^14.6.0", "@types/node": "^14.6.0",
"@types/react": "^16.9.46", "@types/react": "^16.9.46",
"@types/react-dom": "^16.9.8", "@types/react-dom": "^16.9.8",
"typescript": "4.0.2" "typescript": "4.0.5"
}, },
"license": "MIT" "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 { Container } from './Container'
......
import { Flex, useColorMode, FlexProps } from '@chakra-ui/core' import { Flex, useColorMode, FlexProps } from '@chakra-ui/react'
export const Container = (props: FlexProps) => { export const Container = (props: FlexProps) => {
const { colorMode } = useColorMode() const { colorMode } = useColorMode()
......
import { useColorMode, Switch } from '@chakra-ui/core' import { useColorMode, Switch } from '@chakra-ui/react'
export const DarkModeSwitch = () => { export const DarkModeSwitch = () => {
const { colorMode, toggleColorMode } = useColorMode() const { colorMode, toggleColorMode } = useColorMode()
......
import { Flex, FlexProps } from '@chakra-ui/core' import { Flex, FlexProps } from '@chakra-ui/react'
export const Footer = (props: FlexProps) => ( export const Footer = (props: FlexProps) => (
<Flex as="footer" py="8rem" {...props} /> <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 }) => ( export const Hero = ({ title }: { title: string }) => (
<Flex justifyContent="center" alignItems="center" height="100vh"> <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) => ( export const Main = (props: StackProps) => (
<Stack <Stack
......
import { ChakraProvider } from '@chakra-ui/core' import { ChakraProvider } from '@chakra-ui/react'
import theme from '../theme' import theme from '../theme'
import { AppProps } from 'next/app' 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 { ...@@ -5,7 +5,7 @@ import {
List, List,
ListIcon, ListIcon,
ListItem, ListItem,
} from '@chakra-ui/core' } from '@chakra-ui/react'
import { CheckCircleIcon, LinkIcon } from '@chakra-ui/icons' import { CheckCircleIcon, LinkIcon } from '@chakra-ui/icons'
import { Hero } from '../components/Hero' 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 = { const theme = extendTheme({
...chakraTheme,
colors: { colors: {
...chakraTheme.colors,
black: '#16161D', black: '#16161D',
}, },
fonts, fonts,
breakpoints, breakpoints,
} })
export default theme export default theme
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
"@chakra-ui/react": "^1.0.0", "@chakra-ui/react": "^1.0.0",
"@emotion/react": "^11.0.0", "@emotion/react": "^11.0.0",
"@emotion/styled": "^11.0.0", "@emotion/styled": "^11.0.0",
"emotion-theming": "^11.0.0",
"framer-motion": "^2.9.4", "framer-motion": "^2.9.4",
"next": "latest", "next": "latest",
"react": "^17.0.1", "react": "^17.0.1",
......
import { ThemeProvider, CSSReset, ColorModeProvider } from '@chakra-ui/react' import { ChakraProvider, ColorModeProvider } from '@chakra-ui/react'
import theme from '../theme' import theme from '../theme'
function MyApp({ Component, pageProps }) { function MyApp({ Component, pageProps }) {
return ( return (
<ThemeProvider theme={theme}> <ChakraProvider resetCSS theme={theme}>
<ColorModeProvider <ColorModeProvider
options={{ options={{
useSystemColorMode: true, useSystemColorMode: true,
}} }}
> >
<CSSReset />
<Component {...pageProps} /> <Component {...pageProps} />
</ColorModeProvider> </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 { ...@@ -2,12 +2,11 @@ import {
Link as ChakraLink, Link as ChakraLink,
Text, Text,
Code, Code,
Icon,
List, List,
ListIcon, ListIcon,
ListItem, ListItem,
} from '@chakra-ui/react' } from '@chakra-ui/react'
import { ExternalLinkIcon } from '@chakra-ui/icons' import { CheckCircleIcon, LinkIcon } from '@chakra-ui/icons'
import { Hero } from '../components/Hero' import { Hero } from '../components/Hero'
import { Container } from '../components/Container' import { Container } from '../components/Container'
import { Main } from '../components/Main' import { Main } from '../components/Main'
...@@ -16,7 +15,7 @@ import { CTA } from '../components/CTA' ...@@ -16,7 +15,7 @@ import { CTA } from '../components/CTA'
import { Footer } from '../components/Footer' import { Footer } from '../components/Footer'
const Index = () => ( const Index = () => (
<Container> <Container height="100vh">
<Hero /> <Hero />
<Main> <Main>
<Text> <Text>
...@@ -25,20 +24,20 @@ const Index = () => ( ...@@ -25,20 +24,20 @@ const Index = () => (
<List spacing={3} my={0}> <List spacing={3} my={0}>
<ListItem> <ListItem>
<ListIcon icon="check-circle" color="green.500" /> <ListIcon as={CheckCircleIcon} color="green.500" />
<ChakraLink <ChakraLink
isExternal isExternal
href="https://chakra-ui.com" href="https://chakra-ui.com"
flexGrow={1} flexGrow={1}
mr={2} mr={2}
> >
Chakra UI <Icon as={ExternalLinkIcon} mx="2px" /> Chakra UI <LinkIcon />
</ChakraLink> </ChakraLink>
</ListItem> </ListItem>
<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}> <ChakraLink isExternal href="https://nextjs.org" flexGrow={1} mr={2}>
Next.js <Icon as={ExternalLinkIcon} mx="2px" /> Next.js <LinkIcon />
</ChakraLink> </ChakraLink>
</ListItem> </ListItem>
</List> </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 = { const theme = extendTheme({
...chakraTheme,
colors: { colors: {
...chakraTheme.colors,
black: '#16161D', black: '#16161D',
}, },
fonts, fonts,
breakpoints, breakpoints,
icons: { icons: {
...chakraTheme.icons,
logo: { logo: {
path: ( path: (
<svg <svg
...@@ -33,6 +36,6 @@ const theme = { ...@@ -33,6 +36,6 @@ const theme = {
viewBox: '0 0 3000 3163', viewBox: '0 0 3000 3163',
}, },
}, },
} })
export default theme 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