Created
June 7, 2024 06:27
-
-
Save vladimir-ivanov/25aacf7fe502fef27cd5e3bf2ebe4402 to your computer and use it in GitHub Desktop.
Box.tsx
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
type Records<Keys extends keyof JSX.IntrinsicElements = keyof JSX.IntrinsicElements> = { | |
[P in Keys]: CSSProperties & JSX.IntrinsicElements[P] & { tag: P; }; | |
}[Keys]; | |
const Box: FC<Records> = ({tag, children, ...rest}): JSX.Element => { | |
const {styles, attributes} = splitProps(rest); | |
const Tag = tag as string; | |
return <Tag style={styles} {...attributes}>{children}</Tag> | |
} | |
const Test: FC = () => ( | |
<Box tag='button' type="submit" onSubmit={console.warn}/> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
couples tag with attributes to match e.g. and not