1
1
<script lang =" ts" >
2
+ import { Tabs , TabItem } from ' flowbite-svelte' ;
2
3
import TableProp from ' ./TableProp.svelte' ;
3
4
import TableDefaultRow from ' ./TableDefaultRow.svelte' ;
4
-
5
+ import { GridSolid , AdjustmentsVerticalSolid , ClipboardSolid } from ' flowbite-svelte-icons ' ;
5
6
import { onMount } from ' svelte' ;
7
+ import { getFilteredFileNames } from ' ./helpers' ;
6
8
7
-
8
- export let components;
9
- let compoData = [];
9
+ type TCompoData = {
10
+ data: {
11
+ default: {
12
+ name: string ;
13
+ props: string [][];
14
+ events: string [][];
15
+ slots: string [][];
16
+ };
17
+ };
18
+ };
19
+
20
+ export let dirName: string = ' ' ;
21
+ export let components: string ;
10
22
11
- // Split the components into an array
12
- const componentArray = components .split (' , ' );
23
+ let compoData: TCompoData [] = [];
24
+ // default is find fileName using dirName
25
+ const fileNames = getFilteredFileNames (dirName );
13
26
27
+ // if components are given (e.g. checkbox, etc in forms, typography, utils)
28
+ // use the components string
29
+ let componentArray = components ? components .split (' , ' ) : [];
30
+
31
+ if (components ) {
32
+ // Split the components into an array
33
+ const componentArray = components .split (' , ' );
34
+ }
35
+
36
+ let importPromises: Promise <any >[] = [];
37
+
14
38
async function processComponents() {
15
- const importPromises = componentArray .map (async (component ) => {
16
- const module = await import (` ../component-data/${component }.json ` );
17
- return { data: module };
18
- });
39
+ if (componentArray .length > 0 ) {
40
+ importPromises = componentArray .map (async (component ) => {
41
+ const module = await import (` ../component-data/${component }.json ` );
42
+ return { data: module };
43
+ });
44
+ } else {
45
+ importPromises = fileNames .map (async (component ) => {
46
+ const module = await import (` ../component-data/${component }.json ` );
47
+ return { data: module };
48
+ });
49
+ }
19
50
20
51
try {
21
52
compoData = await Promise .all (importPromises );
25
56
}
26
57
}
27
58
59
+
28
60
onMount (() => {
29
61
processComponents ()
30
62
.catch (error => {
31
63
console .error (' Error outside of processComponents:' , error );
32
64
});
33
65
});
34
-
35
66
</script >
36
67
37
68
{#if compoData }
38
- <h2 >Component data</h2 >
39
- {#each compoData as compo }
40
-
41
- <h3 >{compo .data .default .name }</h3 >
42
-
43
- {#if compo .data .default .props .length > 0 }
44
- <h4 >Props</h4 >
45
- <ul class =" w-full" >
46
- <TableProp >
47
- <TableDefaultRow items ={compo .data .default .props } rowState =' hover' />
48
- </TableProp >
49
- </ul >
50
- {/if }
69
+ <div id =" compoData" >
70
+ {#each compoData as compo }
71
+ <h4 class ="text-lg" >{compo .data .default .name }</h4 >
72
+ <Tabs style =" underline" class =" list-none" >
73
+ {#if compo .data .default .props .length > 0 }
74
+ <TabItem open >
75
+ <div slot =" title" class =" flex items-center gap-2" >
76
+ <ClipboardSolid size =" sm" />
77
+ Props
78
+ </div >
79
+ <ul class =" w-full" >
80
+ <TableProp >
81
+ <TableDefaultRow items ={compo .data .default .props } rowState =' hover' />
82
+ </TableProp >
83
+ </ul >
84
+ </TabItem >
85
+ {/if }
51
86
52
- <div class =" grid grid-cols-1 md:grid-cols-2 gap-2" >
53
-
54
- {#if compo .data .default .events .length > 0 }
55
- <div >
56
- <h4 class =" mt-8 mb-4 text-lg font-bold text-gray-900 dark:text-white" >Events</h4 >
57
- <ul >
58
- <TableProp category =" slots" >
59
- <TableDefaultRow items ={compo .data .default .events } rowState =' hover' />
60
- </TableProp >
61
- </ul >
62
- </div >
63
- {/if }
64
-
65
- {#if compo .data .default .slots .length > 0 }
66
- <div >
67
- <h4 class =" mt-8 mb-4 text-lg font-bold text-gray-900 dark:text-white" >Slots</h4 >
68
- <ul class =" w-full" >
69
- <TableProp category =" slots" >
70
- <TableDefaultRow items ={compo .data .default .slots } rowState =' hover' />
71
- </TableProp >
72
- </ul >
73
- </div >
74
- {/if }
87
+ {#if compo .data .default .events .length > 0 }
88
+ <TabItem >
89
+ <div slot =" title" class =" flex items-center gap-2" >
90
+ <AdjustmentsVerticalSolid size =" sm" />
91
+ Events
92
+ </div >
93
+ <ul class =" w-full list-none" >
94
+ <TableProp category =" slots" >
95
+ <TableDefaultRow items ={compo .data .default .events } rowState =' hover' />
96
+ </TableProp >
97
+ </ul >
98
+ </TabItem >
99
+ {/if }
75
100
101
+ {#if compo .data .default .slots .length > 0 }
102
+ <TabItem >
103
+ <div slot =" title" class =" flex items-center gap-2" >
104
+ <GridSolid size =" sm" />
105
+ Slots
106
+ </div >
107
+ <ul class =" w-full list-none" >
108
+ <TableProp category =" slots" >
109
+ <TableDefaultRow items ={compo .data .default .slots } rowState =' hover' />
110
+ </TableProp >
111
+ </ul >
112
+ </TabItem >
113
+ {/if }
114
+ </Tabs >
115
+ {/each }
76
116
</div >
77
- {/each }
78
117
{/if }
0 commit comments