Skip to content

Set "as" prop in component styles #2363

Answered by chasinhues
neil-morgan asked this question in Q&A
Discussion options

You must be logged in to vote

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

// 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";

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@neil-morgan
Comment options

@ljosberinn
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by chasinhues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants