From 46edf5cb740bc6614fddff525f70e76e2ee14d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Wed, 27 Dec 2023 08:13:33 +0400 Subject: [PATCH] fix(types): support svg tags Closes #27 --- src/index.test.tsx | 8 ++++++++ src/index.tsx | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/index.test.tsx b/src/index.test.tsx index e589d18..d971b4e 100644 --- a/src/index.test.tsx +++ b/src/index.test.tsx @@ -234,4 +234,12 @@ describe("twc", () => { >`py-2`; render(); }); + + test("allows svg", () => { + const Svg = twc.svg`text-xl`; + render(); + const svg = screen.getByTestId("svg"); + expect(svg).toBeDefined(); + expect(svg.tagName).toBe("SVG"); + }); }); diff --git a/src/index.tsx b/src/index.tsx index 291e4b5..8ee8921 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -40,6 +40,11 @@ type Template< ResultProps >; +type ElementTagName = Exclude< + keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap, + "set" +>; + type FirstLevelTemplate< TComponent extends React.ElementType, TCompose extends AbstractCompose, @@ -57,7 +62,7 @@ type FirstLevelTemplate< type Twc = (( component: T, ) => FirstLevelTemplate) & { - [Key in keyof HTMLElementTagNameMap]: FirstLevelTemplate< + [Key in ElementTagName]: FirstLevelTemplate< Key, TCompose, { asChild?: boolean }