Created
May 27, 2021 20:24
-
-
Save smhutch/8fa1daa6587c7d1f99c51ca657a54a9d to your computer and use it in GitHub Desktop.
Restricting the `as` prop with Stitches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type * as Polymorphic from "@radix-ui/react-polymorphic"; | |
import type { ComponentProps } from "react"; | |
import React, { forwardRef } from "react"; | |
import { styled } from "../../theme"; | |
const DEFAULT_TAG = "p"; | |
const StyledText = styled(DEFAULT_TAG, { | |
// your styles | |
}); | |
export interface TextProps extends ComponentProps<typeof StyledText> { | |
as?: "h1" | "h2" | "h3" | "h4" | "h5" | "p" | "li" | "pre" | "span" | "label"; | |
} | |
type PolymorphicText = Polymorphic.ForwardRefComponent< | |
typeof DEFAULT_TAG, | |
TextProps | |
>; | |
export const Text = forwardRef((props, ref) => ( | |
<StyledText ref={ref} {...props} /> | |
)) as PolymorphicText; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment