Nue Camp
This is the card body. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur nec odio vel dui euismod fermentum. Curabitur nec odio vel dui euismod fermentum.
import { Avatar, Button, Card } from "@chakra-ui/react"
const Demo = () => {
return (
<Card.Root width="320px">
<Card.Body gap="2">
<Avatar.Root size="lg" shape="rounded">
<Avatar.Image src="https://picsum.photos/200/300" />
<Avatar.Fallback name="Nue Camp" />
</Avatar.Root>
<Card.Title mt="2">Nue Camp</Card.Title>
<Card.Description>
This is the card body. Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Curabitur nec odio vel dui euismod fermentum.
Curabitur nec odio vel dui euismod fermentum.
</Card.Description>
</Card.Body>
<Card.Footer justifyContent="flex-end">
<Button variant="outline">View</Button>
<Button>Join</Button>
</Card.Footer>
</Card.Root>
)
}
用法
¥Usage
import { Card } from "@chakra-ui/react"
<Card.Root>
<Card.Header />
<Card.Body />
<Card.Footer />
</Card.Root>
示例
¥Examples
变量
¥Variants
使用 variant
属性更改卡片的视觉样式。
¥Use the variant
prop to change the visual style of the Card.
Nue Camp
This is the card body. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nue Camp
This is the card body. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nue Camp
This is the card body. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
import { Avatar, Button, Card, For, Stack } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack gap="4" direction="row" wrap="wrap">
<For each={["subtle", "outline", "elevated"]}>
{(variant) => (
<Card.Root width="320px" variant={variant} key={variant}>
<Card.Body gap="2">
<Avatar.Root size="lg" shape="rounded">
<Avatar.Image src="https://picsum.photos/200/300" />
<Avatar.Fallback name="Nue Camp" />
</Avatar.Root>
<Card.Title mb="2">Nue Camp</Card.Title>
<Card.Description>
This is the card body. Lorem ipsum dolor sit amet, consectetur
adipiscing elit.
</Card.Description>
</Card.Body>
<Card.Footer justifyContent="flex-end">
<Button variant="outline">View</Button>
<Button>Join</Button>
</Card.Footer>
</Card.Root>
)}
</For>
</Stack>
)
}
在表单
¥Within Form
在表单中使用 Card 组件将相关字段分组。
¥Use the Card component within a form to group related fields together.
Sign up
Fill in the form below to create an account
import { Button, Card, Field, Input, Stack } from "@chakra-ui/react"
export const CardWithForm = () => (
<Card.Root maxW="sm">
<Card.Header>
<Card.Title>Sign up</Card.Title>
<Card.Description>
Fill in the form below to create an account
</Card.Description>
</Card.Header>
<Card.Body>
<Stack gap="4" w="full">
<Field.Root>
<Field.Label>First Name</Field.Label>
<Input />
</Field.Root>
<Field.Root>
<Field.Label>Last Name</Field.Label>
<Input />
</Field.Root>
</Stack>
</Card.Body>
<Card.Footer justifyContent="flex-end">
<Button variant="outline">Cancel</Button>
<Button variant="solid">Sign in</Button>
</Card.Footer>
</Card.Root>
)
尺寸
¥Sizes
使用 size
属性更改卡片的大小。
¥Use the size
prop to change the size of the Card.
Card - sm
Card - md
Card - lg
import { Card, Heading, Stack } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack>
<Card.Root size="sm">
<Card.Header>
<Heading size="md"> Card - sm</Heading>
</Card.Header>
<Card.Body color="fg.muted">
This is the card body. Lorem ipsum dolor sit amet, consectetur
adipiscing elit.
</Card.Body>
</Card.Root>
<Card.Root size="md">
<Card.Header>
<Heading size="md"> Card - md</Heading>
</Card.Header>
<Card.Body color="fg.muted">
This is the card body. Lorem ipsum dolor sit amet, consectetur
adipiscing elit.
</Card.Body>
</Card.Root>
<Card.Root size="lg">
<Card.Header>
<Heading size="md"> Card - lg</Heading>
</Card.Header>
<Card.Body color="fg.muted">
This is the card body. Lorem ipsum dolor sit amet, consectetur
adipiscing elit.
</Card.Body>
</Card.Root>
</Stack>
)
}
包含图片
¥With Image
使用 Card 组件显示图片。
¥Use the Card component to display an image.
Living room Sofa
This sofa is perfect for modern tropical spaces, baroque inspired spaces.
$450
import { Button, Card, Image, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Card.Root maxW="sm" overflow="hidden">
<Image
src="https://images.unsplash.com/photo-1555041469-a586c61ea9bc?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1770&q=80"
alt="Green double couch with wooden legs"
/>
<Card.Body gap="2">
<Card.Title>Living room Sofa</Card.Title>
<Card.Description>
This sofa is perfect for modern tropical spaces, baroque inspired
spaces.
</Card.Description>
<Text textStyle="2xl" fontWeight="medium" letterSpacing="tight" mt="2">
$450
</Text>
</Card.Body>
<Card.Footer gap="2">
<Button variant="solid">Buy now</Button>
<Button variant="ghost">Add to cart</Button>
</Card.Footer>
</Card.Root>
)
}
水平
¥Horizontal
使用 Card 组件水平显示内容。
¥Use the Card component to display content horizontally.
The perfect latte
Caffè latte is a coffee beverage of Italian origin made with espresso and steamed milk.
import { Badge, Box, Button, Card, HStack, Image } from "@chakra-ui/react"
export const CardHorizontal = () => (
<Card.Root flexDirection="row" overflow="hidden" maxW="xl">
<Image
objectFit="cover"
maxW="200px"
src="https://images.unsplash.com/photo-1667489022797-ab608913feeb?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw5fHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=800&q=60"
alt="Caffe Latte"
/>
<Box>
<Card.Body>
<Card.Title mb="2">The perfect latte</Card.Title>
<Card.Description>
Caffè latte is a coffee beverage of Italian origin made with espresso
and steamed milk.
</Card.Description>
<HStack mt="4">
<Badge>Hot</Badge>
<Badge>Caffeine</Badge>
</HStack>
</Card.Body>
<Card.Footer>
<Button>Buy Latte</Button>
</Card.Footer>
</Box>
</Card.Root>
)
包含头像
¥With Avatar
使用 Card 组件显示头像。
¥Use the Card component to display an avatar.
Nate Foss
@natefoss
Nate Foss has requested to join your team. You can approve or decline their request.
import {
Avatar,
Button,
Card,
HStack,
Stack,
Strong,
Text,
} from "@chakra-ui/react"
import { LuCheck, LuX } from "react-icons/lu"
const Demo = () => {
return (
<Card.Root width="320px">
<Card.Body>
<HStack mb="6" gap="3">
<Avatar.Root>
<Avatar.Image src="https://images.unsplash.com/photo-1511806754518-53bada35f930" />
<Avatar.Fallback name="Nate Foss" />
</Avatar.Root>
<Stack gap="0">
<Text fontWeight="semibold" textStyle="sm">
Nate Foss
</Text>
<Text color="fg.muted" textStyle="sm">
@natefoss
</Text>
</Stack>
</HStack>
<Card.Description>
<Strong color="fg">Nate Foss </Strong>
has requested to join your team. You can approve or decline their
request.
</Card.Description>
</Card.Body>
<Card.Footer>
<Button variant="subtle" colorPalette="red" flex="1">
<LuX />
Decline
</Button>
<Button variant="subtle" colorPalette="blue" flex="1">
<LuCheck />
Approve
</Button>
</Card.Footer>
</Card.Root>
)
}
属性
¥Props
根元素
¥Root
Prop | Default | Type |
---|---|---|
colorPalette | 'gray' | 'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' The color palette of the component |
size | 'md' | 'sm' | 'md' | 'lg' The size of the component |
variant | 'outline' | 'elevated' | 'outline' | 'subtle' The variant of the component |
as | React.ElementType The underlying element to render. | |
asChild | boolean Use the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. | |
unstyled | boolean Whether to remove the component's style. |