Skip to content

Commit

Permalink
fix(svelte): Svelte Button and Link types (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyakamens authored Sep 18, 2024
1 parent 1acc653 commit db621ab
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions scripts/build-svelte-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
const fs = require('fs-extra');
const path = require('path');

const componentSvelteElementInheritance = {
Button: 'HTMLButtonAttributes',
Link: 'HTMLAnchorAttributes',
};

const componentNativeElementInheritance = {
Actions: 'HTMLDivElement',
ActionsButton: 'HTMLButtonElement',
Expand All @@ -18,13 +23,11 @@ const componentNativeElementInheritance = {
BreadcrumbsCollapsed: 'HTMLDivElement',
BreadcrumbsItem: 'HTMLDivElement',
BreadcrumbsSeparator: 'HTMLDivElement',
Button: 'HTMLButtonElement',
Card: 'HTMLDivElement',
Checkbox: 'HTMLLabelElement',
Chip: 'HTMLDivElement',
Fab: 'HTMLAnchorElement',
Icon: 'HTMLElement',
Link: 'HTMLAnchorElement',
List: 'HTMLDivElement',
ListButton: 'HTMLLIElement',
ListGroup: 'HTMLLIElement',
Expand Down Expand Up @@ -125,9 +128,15 @@ const createComponentTypes = (componentName, propsContent) => {
})
.join('\n');
const slotsContent = slots.map((slot) => `'${slot}': {};`).join('\n ');
const svelteElementType = componentSvelteElementInheritance[componentName];
const nativeElementType = componentNativeElementInheritance[componentName];
return `
import { SvelteComponent } from 'svelte';
import { HTMLAttributes } from 'svelte/elements';
${
svelteElementType
? `import type { ${svelteElementType} } from 'svelte/elements';`
: `import { HTMLAttributes } from 'svelte/elements';`
}
${propsContent}
Expand All @@ -137,9 +146,11 @@ interface ${componentName}Events extends Record<'',{}>{}
declare class ${componentName} extends SvelteComponent<
${componentName}Props${
componentNativeElementInheritance[componentName]
? ` & HTMLAttributes<${componentNativeElementInheritance[componentName]}>`
: ''
svelteElementType
? ` & ${svelteElementType}`
: nativeElementType
? ` & HTMLAttributes<${nativeElementType}>`
: ''
},
${componentName}Events,
{
Expand Down

0 comments on commit db621ab

Please sign in to comment.