@@ -3,6 +3,26 @@ import { utilityTypes } from './utilityTypes.js'
3
3
4
4
import fs from 'fs'
5
5
6
+ const getTypeName = ( component , framework ) => {
7
+ const componentsWithoutFrameworkSpecificTypes = [
8
+ 'Accordion' ,
9
+ 'Avatar' ,
10
+ 'BottomNavigation' ,
11
+ 'Breadcrumb' ,
12
+ 'Icon' ,
13
+ 'Rating' ,
14
+ 'Skeleton' ,
15
+ 'Spinner' ,
16
+ 'Stepper' ,
17
+ 'Table' ,
18
+ 'Progress'
19
+ ]
20
+
21
+ return componentsWithoutFrameworkSpecificTypes . includes ( component )
22
+ ? `${ component } Props`
23
+ : `${ framework } ${ component } Props`
24
+ }
25
+
6
26
const format = template => template . trim ( ) . replace ( new RegExp ( '^[ \\t]{12}' , 'gm' ) , '' )
7
27
8
28
const buildTypes = type => {
@@ -31,44 +51,21 @@ const buildTypes = type => {
31
51
}
32
52
33
53
if ( type === 'svelte' ) {
34
- const getTypeName = component => {
35
- const componentsWithSvelteSpecificTypes = [
36
- 'Badge' ,
37
- 'Button' ,
38
- 'Carousel' ,
39
- 'Checkbox' ,
40
- 'DataTable' ,
41
- 'Input' ,
42
- 'List' ,
43
- 'Masonry' ,
44
- 'Pagination' ,
45
- 'Radio' ,
46
- 'Select' ,
47
- 'Slider' ,
48
- 'Switch' ,
49
- 'Textarea'
50
- ]
51
-
52
- return componentsWithSvelteSpecificTypes . includes ( component )
53
- ? `Svelte${ component } Props`
54
- : `${ component } Props`
55
- }
56
-
57
54
return format ( `
58
- import type { SvelteComponent } from 'svelte'
55
+ import type { Component } from 'svelte'
59
56
${ components . map ( component => {
60
- return `import type { ${ getTypeName ( component ) } as W${ getTypeName ( component ) } } from './components/${ component } /${ component . toLowerCase ( ) } '`
57
+ return `import type { ${ getTypeName ( component , 'Svelte' ) } as W${ getTypeName ( component , 'Svelte' ) } } from './components/${ component } /${ component . toLowerCase ( ) } '`
61
58
} ) . join ( '\n' ) }
62
59
63
60
${ getAdditionalTypeImports ( ) }
64
61
65
62
declare module 'webcoreui/${ type } ' {
66
63
${ components . map ( component => {
67
- return `export class ${ component } extends SvelteComponent <W${ getTypeName ( component ) } > {} `
64
+ return `export const ${ component } : Component <W${ getTypeName ( component , 'Svelte' ) } >`
68
65
} ) . join ( '\n\t' ) }
69
66
70
67
${ components . map ( component => {
71
- return `export type ${ component } Props = W${ getTypeName ( component ) } `
68
+ return `export type ${ component } Props = W${ getTypeName ( component , 'Svelte' ) } `
72
69
} ) . join ( '\n\t' ) }
73
70
74
71
${ getAdditionalTypeExports ( ) }
@@ -77,40 +74,21 @@ const buildTypes = type => {
77
74
}
78
75
79
76
if ( type === 'react' ) {
80
- const getTypeName = component => {
81
- const componentsWithoutReactSpecificTypes = [
82
- 'Accordion' ,
83
- 'Avatar' ,
84
- 'Breadcrumb' ,
85
- 'Icon' ,
86
- 'Rating' ,
87
- 'Skeleton' ,
88
- 'Spinner' ,
89
- 'Stepper' ,
90
- 'Table' ,
91
- 'Progress'
92
- ]
93
-
94
- return componentsWithoutReactSpecificTypes . includes ( component )
95
- ? `${ component } Props`
96
- : `React${ component } Props`
97
- }
98
-
99
77
return format ( `
100
78
import { FC } from 'react'
101
79
${ components . map ( component => {
102
- return `import type { ${ getTypeName ( component ) } as W${ getTypeName ( component ) } } from './components/${ component } /${ component . toLowerCase ( ) } '`
80
+ return `import type { ${ getTypeName ( component , 'React' ) } as W${ getTypeName ( component , 'React' ) } } from './components/${ component } /${ component . toLowerCase ( ) } '`
103
81
} ) . join ( '\n' ) }
104
82
105
83
${ getAdditionalTypeImports ( ) }
106
84
107
85
declare module 'webcoreui/${ type } ' {
108
86
${ components . map ( component => {
109
- return `export const ${ component } : FC<W${ getTypeName ( component ) } >`
87
+ return `export const ${ component } : FC<W${ getTypeName ( component , 'React' ) } >`
110
88
} ) . join ( '\n\t' ) }
111
89
112
90
${ components . map ( component => {
113
- return `export type ${ component } Props = W${ getTypeName ( component ) } `
91
+ return `export type ${ component } Props = W${ getTypeName ( component , 'React' ) } `
114
92
} ) . join ( '\n\t' ) }
115
93
116
94
${ getAdditionalTypeExports ( ) }
0 commit comments