Skip to content

Commit

Permalink
fix(svelte): add onClick props types
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Apr 27, 2022
1 parent b2f2244 commit b237927
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion scripts/build-svelte-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
const fs = require('fs-extra');
const path = require('path');

const addOnClick = [
'Badge',
'Button',
'Chip',
'Fab',
'Link',
'ListItem',
'NavbarBackLink',
'ListButton',
'NavbarBackLink',
'SegmentedButton',
];

const addOnClickProp = (componentName) => {
if (addOnClick.includes(componentName))
return `\n onClick?: (e: any) => void;\n`;
return '';
};

const createComponentTypes = (componentName, propsContent) => {
const slots = ['default'];
const removeProps = ['defaultChecked', 'defaultValue'];
Expand All @@ -20,7 +39,12 @@ const createComponentTypes = (componentName, propsContent) => {
'inputMode',
];
propsContent = propsContent
.replace('interface Props {', `export interface Props {\n class?: string;`)
.replace(
'interface Props {',
`export interface Props {\n class?: string;${addOnClickProp(
componentName
)}`
)
.replace(/ClassName/g, 'Class')
.replace(/Children/g, '')
.split('\n')
Expand Down

0 comments on commit b237927

Please sign in to comment.