47
loading...
This website collects cookies to deliver better user experience
npx create-next-app my-project
# or
yarn create next-app my-project
create-next-app
using the --ts
, --typescript
flag as shown below:npx create-next-app@latest --ts
# or
yarn create next-app --typescript
next-env.d.ts
will be created in the root of your project. This file ensures Next.js types are picked up by the TypeScript compiler. You cannot remove it or edit it as it can change at any time.npm i @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^4
# or
yarn add @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^4
ChakraProvider
component, which then wraps your website with a context containing properties such as the Chakra theme, color mode functionality, CSS reset, global styles, and more../pages/_app.js
:import { ChakraProvider } from '@chakra-ui/react';
const MyApp = ({ Component, pageProps }) => {
return (
<ChakraProvider>
<Component {...pageProps} />
</ChakraProvider>
);
}
export default MyApp;
ChakraProvider
component in ./pages/_app.tsx
and replace by the following code:import type { AppProps } from 'next/app';
import { ChakraProvider } from '@chakra-ui/react';
const MyApp = ({ Component, pageProps }: AppProps) => {
return (
<ChakraProvider>
<Component {...pageProps} />
</ChakraProvider>
);
}
export default MyApp;
./pages/index.jsx
or ./pages/index.tsx
, add the following code:import { Heading } from '@chakra-ui/react';
const Home = () => {
return (
<Heading>Welcome to Chakra + Next.js</Heading>
);
}
export default Home;
./components/Hero.js
or ./components/Hero.tsx
file. And inside try out the following example code:import { Container, Stack, Flex, Box, Heading, Text, Image, useColorModeValue } from "@chakra-ui/react";
import Blob from './Blob';
const Hero = () => {
return (
<Container maxW={'7xl'}>
<Stack
align={'center'}
spacing={ { base: 8, md: 10 } }
py={ { base: 20, md: 28 } }
direction={ { base: 'column', md: 'row' } }>
<Stack flex={1} spacing={ { base: 5, md: 10 } }>
<Heading
lineHeight={1.1}
fontWeight={600}
fontSize={ { base: '3xl', sm: '4xl', lg: '6xl' } }>
<Text
as={'span'}
position={'relative'}
_after={ {
content: "''",
width: 'full',
height: '20%',
position: 'absolute',
bottom: 1,
left: 0,
bg: 'cyan.400',
zIndex: -1,
} }>
Example Application
</Text>
<br />
<Text as={'span'} color={'cyan.400'}>
Next.js + Chakra UI
</Text>
</Heading>
</Stack>
<Flex
flex={1}
justify={'center'}
align={'center'}
position={'relative'}
w={'full'}>
<Blob
w={'150%'}
h={'150%'}
position={'absolute'}
top={'-20%'}
left={0}
zIndex={-1}
color={useColorModeValue('cyan.50', 'cyan.400')}
/>
<Box
position={'relative'}
height={'300px'}
rounded={'2xl'}
boxShadow={'2xl'}
width={'full'}
overflow={'hidden'}>
<Image
alt={'Hero Image'}
fit={'cover'}
align={'center'}
w={'100%'}
h={'100%'}
src={
'https://cdn.pixabay.com/photo/2016/04/15/04/02/water-1330252_960_720.jpg'
}
/>
</Box>
</Flex>
</Stack>
</Container>
);
}
export default Hero;
./components/Blob.jsx
(find the TypeScript below) file with the following code:import { Icon, IconProps } from "@chakra-ui/react";
const Blob = (props: IconProps) => {
return (
<Icon
width={'100%'}
viewBox="0 0 578 440"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M239.184 439.443c-55.13-5.419-110.241-21.365-151.074-58.767C42.307 338.722-7.478 282.729.938 221.217c8.433-61.644 78.896-91.048 126.871-130.712 34.337-28.388 70.198-51.348 112.004-66.78C282.34 8.024 325.382-3.369 370.518.904c54.019 5.115 112.774 10.886 150.881 49.482 39.916 40.427 49.421 100.753 53.385 157.402 4.13 59.015 11.255 128.44-30.444 170.44-41.383 41.683-111.6 19.106-169.213 30.663-46.68 9.364-88.56 35.21-135.943 30.551z"
fill="currentColor"
/>
</Icon>
);
};
export default Blob;
./components/Blob.tsx
file:import { Icon } from "@chakra-ui/react";
const Blob = (props) => {
return (
<Icon
width={'100%'}
viewBox="0 0 578 440"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M239.184 439.443c-55.13-5.419-110.241-21.365-151.074-58.767C42.307 338.722-7.478 282.729.938 221.217c8.433-61.644 78.896-91.048 126.871-130.712 34.337-28.388 70.198-51.348 112.004-66.78C282.34 8.024 325.382-3.369 370.518.904c54.019 5.115 112.774 10.886 150.881 49.482 39.916 40.427 49.421 100.753 53.385 157.402 4.13 59.015 11.255 128.44-30.444 170.44-41.383 41.683-111.6 19.106-169.213 30.663-46.68 9.364-88.56 35.21-135.943 30.551z"
fill="currentColor"
/>
</Icon>
);
};
export default Blob;
Hero.tsx
into your ./pages/index.js
or ./pages/index.tsx
file like so:import Hero from '../components/Hero';
const Home = () => {
return (
<Hero />
);
}
export default Home;