Skip to content

Commit 9ea05f6

Browse files
bug: #277 support svg types
1 parent 768461d commit 9ea05f6

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

src/jsx.d.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ type ElementAttributes<E extends HTMLElement> = {
77
[A in keyof E]?: E[A] extends (...args: any) => any ? any : IsCSSStyleDeclaration<E[A]>;
88
} & {
99
class?: string;
10+
children?: any;
11+
};
12+
13+
// creates a utility type for SVG attributes, allowing string values for SVG-specific attributes
14+
type SVGElementAttributes<E extends SVGElement> = {
15+
[A in keyof E]?: string | undefined;
16+
} & {
17+
class?: string;
18+
fill?: string;
19+
stroke?: string;
20+
d?: string;
21+
viewBox?: string;
22+
xmlns?: string;
23+
preserveAspectRatio?: string;
24+
[key: string]: any;
1025
};
1126

1227
type PopoverState = 'auto' | 'manual' | 'hint';
@@ -25,9 +40,15 @@ type PopoverAttributes = {
2540
// map each HTML tag to its attributes
2641
type IntrinsicElementsFromDom = {
2742
[E in keyof HTMLElementTagNameMap]: ElementAttributes<HTMLElementTagNameMap[E]> &
28-
(E extends 'button' | 'input' ? PopoverAttributes : {});
43+
(E extends 'button' | 'input' ? PopoverAttributes : {}) &
44+
(E extends 'button' ? { tabindex?: number | string } : {});
45+
};
46+
47+
// map each SVG tag to its attributes
48+
type IntrinsicElementsFromSVG = {
49+
[E in keyof SVGElementTagNameMap]: SVGElementAttributes<SVGElementTagNameMap[E]>;
2950
};
3051

3152
declare namespace JSX {
32-
interface IntrinsicElements extends IntrinsicElementsFromDom {}
53+
interface IntrinsicElements extends IntrinsicElementsFromDom, IntrinsicElementsFromSVG {}
3354
}

test/cases/tsx/src/counter.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,24 @@ export default class Counter extends HTMLElement {
5555
</span>
5656
{/* @ts-expect-error - onclick should be a function, but we coerce to an assignment */}
5757
<button onclick={(this.count += 1)}> + (inline state update)</button>
58-
<button onclick={this.increment}> + (function reference)</button>
58+
{/* test for https://github.com/ProjectEvergreen/wcc/issues/277 */}
59+
<button onclick={this.increment} tabindex={-1}> + (function reference)</button>
60+
{/* test for https://github.com/ProjectEvergreen/wcc/issues/277 */}
61+
<svg
62+
class="svg-inline--fa fa-share-alt fa-w-14"
63+
aria-hidden="true"
64+
data-prefix="fas"
65+
data-icon="share-alt"
66+
role="img"
67+
xmlns="http://www.w3.org/2000/svg"
68+
viewBox="0 0 448 512"
69+
data-fa-i2svg=""
70+
>
71+
<path
72+
fill="currentColor"
73+
d="M352 320c-22.608 0-43.387 7.819-59.79 20.895l-102.486-64.054a96.551 96.551 0 0 0 0-41.683l102.486-64.054C308.613 184.181 329.392 192 352 192c53.019 0 96-42.981 96-96S405.019 0 352 0s-96 42.981-96 96c0 7.158.79 14.13 2.276 20.841L155.79 180.895C139.387 167.819 118.608 160 96 160c-53.019 0-96 42.981-96 96s42.981 96 96 96c22.608 0 43.387-7.819 59.79-20.895l102.486 64.054A96.301 96.301 0 0 0 256 416c0 53.019 42.981 96 96 96s96-42.981 96-96-42.981-96-96-96z"
74+
></path>
75+
</svg>
5976
</div>
6077
);
6178
}

0 commit comments

Comments
 (0)