Skip to content

Commit

Permalink
fix(types): support svg tags
Browse files Browse the repository at this point in the history
Closes #27
  • Loading branch information
gregberge committed Dec 27, 2023
1 parent 0d8ce78 commit 46edf5c
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 46edf5c

Please sign in to comment.