I'm not sure what to enter for color or background. Property.color doesn't exist. There must be something that represents all these color options that can be normally seen. I've entered any right now to prevent error but that doesn't give me type hinting for colors.
我不确定要输入什么颜色或背景。Property.Color不存在。必须有一些东西来代表所有这些通常可以看到的颜色选项。我现在已经输入了任何内容,以防止出错,但这不会给我输入颜色提示。
import {
BackgroundProps,
Card,
CardBody,
ColorProps,
Colors,
HStack,
Icon,
ResponsiveValue,
Text,
} from "@chakra-ui/react";
import { HiFolder } from "react-icons/hi";
import { MdKeyboardArrowRight } from "react-icons/md";
import { ReactNode } from "react";
interface Props {
children: ReactNode;
color: ResponsiveValue<any>;
// backgroundColor: BackgroundProps;
}
function DashboardLinkSectionCard({ children, color }: Props) {
return (
<>
<Card
// maxW={"ms"}
maxH={"20"}
color={color}
// backgroundColor={backgroundColor}
>
<CardBody>
<HStack gap={2}>
<Icon as={HiFolder} boxSize={6} />
<Text>{children}</Text>
<Icon as={MdKeyboardArrowRight} boxSize={6} />
</HStack>
</CardBody>
</Card>
</>
);
}
export default DashboardLinkSectionCard;
This is the suggestions I would normally get.
这是我通常会得到的建议。
One possible solution is, I copy all the colors and make a custom type like this. Surely there must be a better way.
一种可能的解决方案是,我复制所有的颜色,并像这样定制一个类型。当然,一定有更好的办法。
更多回答
优秀答案推荐
It is possible to use the ChakraProps
interface to achieve what you want. It contains a color
attribute that enumerates all the values allowed by Chakra. This is also applicable to the backgroundColor
prop:
可以使用ChakraProps接口来实现您想要的功能。它包含一个颜色属性,该属性枚举了Chakra允许的所有值。这也适用于背景颜色道具:
import { ChakraProps } from '@chakra-ui/react';
interface Props {
children: ReactNode;
color: ChakraProps['color'];
backgroundColor: ChakraProps['backgroundColor'];
}
Actually, the ChakraProps
interface extends SystemProps
which itself extends ColorProps
and BackgroundProps
(that you already imported). So you could do this as an alternative option:
实际上,ChakraProps接口扩展了SystemProps,后者本身扩展了ColorProps和BackEarth Props(您已经导入了)。因此,您可以将此作为另一种选择:
import { BackgroundProps, ColorProps } from '@chakra-ui/react';
interface Props {
children: ReactNode;
color: ColorProps['color'];
backgroundColor: BackgroundProps['backgroundColor'];
}
更多回答
我是一名优秀的程序员,十分优秀!