Chakra Card 组件是垂直映射而不是水平映射
Chakra Card component is mapping vertically rather than horizontally
我正在尝试渲染一张卡片并将每张卡片映射为一行三张(如果此数字响应性地更改则更好)。
我不确定哪些代码行覆盖了 SimpleGrid
,并尝试使用 Grid
和 Flex
。我也没有CSS
我附上了我正在渲染的代码。
return (
<>
{data.map((item: ICard, index: number) => (
<SimpleGrid columns={3} minChildWidth="30%" py={6} ml={10} key={index}>
<Box
maxW={"445px"}
w={"full"}
boxShadow={"2xl"}
rounded={"md"}
p={6}
overflow={"hidden"}
>
<Box
h={"310px"}
bg={"gray.100"}
mt={-6}
mx={-6}
mb={6}
pos={"relative"}
>
<div
style={{
height: 310,
width: 445,
backgroundImage: `url(${
item.edmIsShownBy ?? item.edmPreview
})`,
backgroundSize: "cover",
backgroundPosition: "middle",
}}
></div>
</Box>
<Stack>
<Text
color={"green.500"}
textTransform={"uppercase"}
fontWeight={800}
fontSize={"sm"}
letterSpacing={1.1}
>
{item.dcCreator ?? searchTerm ?? "Unknown Artist"} {item.year}
</Text>
<Heading fontSize={"2xl"} fontFamily={"body"}>
{item.title}
</Heading>
<Text color={"gray.500"} noOfLines={4}>
{item.dcDescription ?? item.dcDescriptionLangAware}
</Text>
</Stack>
<Stack mt={6} direction={"row"} spacing={4} align={"center"}>
<Avatar
src={item.edmPreview ?? item.edmIsShownBy}
alt={"Author"}
/>
<Stack direction={"column"} spacing={0} fontSize={"sm"}>
<Text fontWeight={600}>
{item.dataProvider}, {item.country}
</Text>
<Text color={"gray.500"} noOfLines={3} mx={1}>
Find {item.title ?? "this artwork"} at{" "}
<a href="url">{item.source ?? item.edmIsShownAt}</a>
</Text>
</Stack>
</Stack>
</Box>
</SimpleGrid>
))}
</>
);
您需要从 data.map
中取出 SimpleGrid
。否则,您将为每条记录呈现一个 SimpleGrid:
这是我的一个快速测试运行(强制数据有东西)==>
import * as React from "react";
import {
Box,
SimpleGrid,
Stack,
Heading,
Text,
Avatar
} from "@chakra-ui/react";
export default function Example() {
const data: any = [
{ id: 1, title: "title1" },
{ id: 2, title: "title2" },
{ id: 3, title: "title3" }
];
return (
<>
<SimpleGrid columns={3} minChildWidth="30%" py={6} ml={10}>
{data.map((item: any, index: number) => {
return (
<Box
maxW={"445px"}
w={"full"}
boxShadow={"2xl"}
rounded={"md"}
p={6}
overflow={"hidden"}
>
<Box
h={"310px"}
bg={"gray.100"}
mt={-6}
mx={-6}
mb={6}
pos={"relative"}
>
<div
style={{
height: 310,
width: 445,
backgroundImage: "",
backgroundSize: "cover",
backgroundPosition: "middle"
}}
></div>
</Box>
<Stack>
<Text
color={"green.500"}
textTransform={"uppercase"}
fontWeight={800}
fontSize={"sm"}
letterSpacing={1.1}
>
{"Unknown Artist"} 2008
</Text>
<Heading fontSize={"2xl"} fontFamily={"body"}>
{item.title}
</Heading>
<Text color={"gray.500"} noOfLines={4}>
{item.dcDescription ?? item.dcDescriptionLangAware}
</Text>
</Stack>
<Stack mt={6} direction={"row"} spacing={4} align={"center"}>
<Avatar
src={item.edmPreview ?? item.edmIsShownBy}
alt={"Author"}
/>
<Stack direction={"column"} spacing={0} fontSize={"sm"}>
<Text fontWeight={600}>
{item.dataProvider}, {item.country}
</Text>
<Text color={"gray.500"} noOfLines={3} mx={1}>
Find {item.title ?? "this artwork"} at{" "}
<a href="url">{item.source ?? item.edmIsShownAt}</a>
</Text>
</Stack>
</Stack>
</Box>
);
})}
</SimpleGrid>
</>
);
}
我正在尝试渲染一张卡片并将每张卡片映射为一行三张(如果此数字响应性地更改则更好)。
我不确定哪些代码行覆盖了 SimpleGrid
,并尝试使用 Grid
和 Flex
。我也没有CSS
我附上了我正在渲染的代码。
return (
<>
{data.map((item: ICard, index: number) => (
<SimpleGrid columns={3} minChildWidth="30%" py={6} ml={10} key={index}>
<Box
maxW={"445px"}
w={"full"}
boxShadow={"2xl"}
rounded={"md"}
p={6}
overflow={"hidden"}
>
<Box
h={"310px"}
bg={"gray.100"}
mt={-6}
mx={-6}
mb={6}
pos={"relative"}
>
<div
style={{
height: 310,
width: 445,
backgroundImage: `url(${
item.edmIsShownBy ?? item.edmPreview
})`,
backgroundSize: "cover",
backgroundPosition: "middle",
}}
></div>
</Box>
<Stack>
<Text
color={"green.500"}
textTransform={"uppercase"}
fontWeight={800}
fontSize={"sm"}
letterSpacing={1.1}
>
{item.dcCreator ?? searchTerm ?? "Unknown Artist"} {item.year}
</Text>
<Heading fontSize={"2xl"} fontFamily={"body"}>
{item.title}
</Heading>
<Text color={"gray.500"} noOfLines={4}>
{item.dcDescription ?? item.dcDescriptionLangAware}
</Text>
</Stack>
<Stack mt={6} direction={"row"} spacing={4} align={"center"}>
<Avatar
src={item.edmPreview ?? item.edmIsShownBy}
alt={"Author"}
/>
<Stack direction={"column"} spacing={0} fontSize={"sm"}>
<Text fontWeight={600}>
{item.dataProvider}, {item.country}
</Text>
<Text color={"gray.500"} noOfLines={3} mx={1}>
Find {item.title ?? "this artwork"} at{" "}
<a href="url">{item.source ?? item.edmIsShownAt}</a>
</Text>
</Stack>
</Stack>
</Box>
</SimpleGrid>
))}
</>
);
您需要从 data.map
中取出 SimpleGrid
。否则,您将为每条记录呈现一个 SimpleGrid:
这是我的一个快速测试运行(强制数据有东西)==>
import * as React from "react";
import {
Box,
SimpleGrid,
Stack,
Heading,
Text,
Avatar
} from "@chakra-ui/react";
export default function Example() {
const data: any = [
{ id: 1, title: "title1" },
{ id: 2, title: "title2" },
{ id: 3, title: "title3" }
];
return (
<>
<SimpleGrid columns={3} minChildWidth="30%" py={6} ml={10}>
{data.map((item: any, index: number) => {
return (
<Box
maxW={"445px"}
w={"full"}
boxShadow={"2xl"}
rounded={"md"}
p={6}
overflow={"hidden"}
>
<Box
h={"310px"}
bg={"gray.100"}
mt={-6}
mx={-6}
mb={6}
pos={"relative"}
>
<div
style={{
height: 310,
width: 445,
backgroundImage: "",
backgroundSize: "cover",
backgroundPosition: "middle"
}}
></div>
</Box>
<Stack>
<Text
color={"green.500"}
textTransform={"uppercase"}
fontWeight={800}
fontSize={"sm"}
letterSpacing={1.1}
>
{"Unknown Artist"} 2008
</Text>
<Heading fontSize={"2xl"} fontFamily={"body"}>
{item.title}
</Heading>
<Text color={"gray.500"} noOfLines={4}>
{item.dcDescription ?? item.dcDescriptionLangAware}
</Text>
</Stack>
<Stack mt={6} direction={"row"} spacing={4} align={"center"}>
<Avatar
src={item.edmPreview ?? item.edmIsShownBy}
alt={"Author"}
/>
<Stack direction={"column"} spacing={0} fontSize={"sm"}>
<Text fontWeight={600}>
{item.dataProvider}, {item.country}
</Text>
<Text color={"gray.500"} noOfLines={3} mx={1}>
Find {item.title ?? "this artwork"} at{" "}
<a href="url">{item.source ?? item.edmIsShownAt}</a>
</Text>
</Stack>
</Stack>
</Box>
);
})}
</SimpleGrid>
</>
);
}