Set "as" prop in component styles #2363
-
Is there any way to set the
Is there a specific way built into ChakraUI to achieve this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Afraid not, it's currently hardcoded as |
Beta Was this translation helpful? Give feedback.
-
In case this helps, we implemented our own custom We can use our
Source// Heading.tsx
import React from "react";
import { Heading as ChakraHeading, HeadingProps as ChakraHeadingProps } from "@chakra-ui/core";
export interface HeadingProps extends ChakraHeadingProps {
type: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
}
const Heading = ({ type, children, ...props }: HeadingProps) => {
return (
<ChakraHeading as={type} textStyle={type} {...props}>
{children}
</ChakraHeading>
);
};
export default Heading; // theme.js
import { theme } from "@chakra-ui/core";
import { merge } from "@chakra-ui/utils";
const customTheme = merge(theme, {
textStyles: {
h1: {
fontSize: ["35px", "55px"],
fontWeight: 700,
color: "gray.500",
},
h2: {
fontSize: ["30px", "30px"],
fontWeight: 700,
color: "gray.500",
},
h3: {
fontSize: ["21px", "21px"],
fontWeight: 700,
color: "gray.500",
},
h4: {
fontSize: ["16px", "16px"],
fontWeight: 700,
color: "gray.500",
},
h5: {
fontSize: ["14px", "14px"],
fontWeight: 700,
color: "gray.500",
},
h6: {
fontSize: ["12px", "12px"],
fontWeight: 700,
color: "gray.500",
},
},
});
export default customTheme; |
Beta Was this translation helpful? Give feedback.
In case this helps, we implemented our own custom
Heading
based on chakra's.We can use our
Heading
component like so:<Heading type="h1">This is a H1</Heading>
Source