Skip to content

Commit

Permalink
Merge pull request #28 from gregberge/support-svg
Browse files Browse the repository at this point in the history
fix(types): support svg tags
  • Loading branch information
gregberge authored Dec 27, 2023
2 parents 0d8ce78 + 46edf5c commit 4705653
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,12 @@ describe("twc", () => {
>`py-2`;
render(<Accordion type="single" collapsible></Accordion>);
});

test("allows svg", () => {
const Svg = twc.svg`text-xl`;
render(<Svg data-testid="svg" />);
const svg = screen.getByTestId("svg");
expect(svg).toBeDefined();
expect(svg.tagName).toBe("SVG");
});
});
7 changes: 6 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ type Template<
ResultProps<TComponent, TProps, TExtraProps, TCompose>
>;

type ElementTagName = Exclude<
keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap,
"set"
>;

type FirstLevelTemplate<
TComponent extends React.ElementType,
TCompose extends AbstractCompose,
Expand All @@ -57,7 +62,7 @@ type FirstLevelTemplate<
type Twc<TCompose extends AbstractCompose> = (<T extends React.ElementType>(
component: T,
) => FirstLevelTemplate<T, TCompose, undefined>) & {
[Key in keyof HTMLElementTagNameMap]: FirstLevelTemplate<
[Key in ElementTagName]: FirstLevelTemplate<
Key,
TCompose,
{ asChild?: boolean }
Expand Down

0 comments on commit 4705653

Please sign in to comment.