1+ import { ReactNode } from 'react' ;
2+
13import { BaseProps , ContainerStyleProps } from '../../../tasty' ;
24import { Flow } from '../../layout/Flow' ;
35import { CubeGridProps , Grid } from '../../layout/Grid' ;
46import { Space } from '../../layout/Space' ;
57import { CubePlaceholderProps , Placeholder } from '../Placeholder/Placeholder' ;
68
79const LAYOUT_MAP = {
8- page ( { lines, children, isStatic = false , ...props } : CubeSkeletonProps ) {
10+ page ( {
11+ lines,
12+ children,
13+ isStatic = false ,
14+ rootProps,
15+ } : CubeSkeletonLayoutProps ) {
916 return (
10- < Flow gap = "4x" { ...props } >
17+ < Flow gap = "4x" { ...rootProps } >
1118 < Space placeContent = "space-between" >
1219 < Placeholder isStatic = { isStatic } width = "100px 25% 300px" />
1320 < Placeholder isStatic = { isStatic } width = "50px 10% 150px" />
@@ -21,25 +28,30 @@ const LAYOUT_MAP = {
2128 </ Flow >
2229 ) ;
2330 } ,
24- content ( { children, lines, isStatic = false , ...props } : CubeSkeletonProps ) {
31+ content ( {
32+ children,
33+ lines,
34+ isStatic = false ,
35+ rootProps,
36+ } : CubeSkeletonLayoutProps ) {
2537 return (
26- < Flow gap = "2x" { ...props } >
38+ < Flow gap = "2x" { ...rootProps } >
2739 { children ||
2840 Array ( lines || 5 )
2941 . fill ( 0 )
3042 . map ( ( item , i ) => < Placeholder key = { i } isStatic = { isStatic } /> ) }
3143 </ Flow >
3244 ) ;
3345 } ,
34- topbar ( { isStatic = false , ... props } : CubeSkeletonProps ) {
46+ topbar ( { isStatic = false , rootProps } : CubeSkeletonLayoutProps ) {
3547 return (
3648 < Space
3749 gap = "4x"
3850 placeContent = "space-between"
3951 height = "6x"
4052 padding = "1x"
4153 border = "bottom"
42- { ...props }
54+ { ...rootProps }
4355 >
4456 < Space >
4557 < Placeholder circle isStatic = { isStatic } size = "4x" />
@@ -53,9 +65,9 @@ const LAYOUT_MAP = {
5365 </ Space >
5466 ) ;
5567 } ,
56- menu ( { lines, isStatic = false , ... props } : CubeSkeletonProps ) {
68+ menu ( { lines, isStatic = false , rootProps } : CubeSkeletonLayoutProps ) {
5769 return (
58- < Flow gap = "3.25x" { ... props } padding = "3x 1x" >
70+ < Flow gap = "3.25x" padding = "3x 1x" { ... rootProps } >
5971 { Array ( lines || 5 )
6072 . fill ( 0 )
6173 . map ( ( item , i ) => (
@@ -64,9 +76,9 @@ const LAYOUT_MAP = {
6476 </ Flow >
6577 ) ;
6678 } ,
67- stats ( { cards, isStatic = false , ... props } : CubeSkeletonProps ) {
79+ stats ( { cards, isStatic = false , rootProps } : CubeSkeletonLayoutProps ) {
6880 return (
69- < Space gap = "4x" { ...props } >
81+ < Space gap = "4x" { ...rootProps } >
7082 { Array ( cards || 3 )
7183 . fill ( 0 )
7284 . map ( ( item , i ) => (
@@ -87,10 +99,10 @@ const LAYOUT_MAP = {
8799 children,
88100 lines,
89101 isStatic = false ,
90- ... props
91- } : CubeSkeletonProps ) {
102+ rootProps ,
103+ } : CubeSkeletonLayoutProps ) {
92104 return (
93- < Flow gap = "4x" { ...props } >
105+ < Flow gap = "4x" { ...rootProps } >
94106 < Space >
95107 { Array ( tabs || 3 )
96108 . fill ( 0 )
@@ -107,16 +119,21 @@ const LAYOUT_MAP = {
107119 </ Flow >
108120 ) ;
109121 } ,
110- table ( { rows, columns, isStatic = false , ...props } : CubeSkeletonProps ) {
122+ table ( {
123+ rows,
124+ columns,
125+ isStatic = false ,
126+ rootProps,
127+ } : CubeSkeletonLayoutProps ) {
111128 columns = columns || 5 ;
112129 rows = rows || 5 ;
113130
114131 return (
115132 < Grid
116133 columns = { `repeat(${ columns } , 1fr)` }
117134 gap = "3x"
118- { ...props }
119135 padding = "1x 0"
136+ { ...rootProps }
120137 >
121138 { Array ( rows )
122139 . fill ( 0 )
@@ -136,7 +153,7 @@ const LAYOUT_MAP = {
136153 </ Grid >
137154 ) ;
138155 } ,
139- chart ( { columns, isStatic = false , ... props } : CubeSkeletonProps ) {
156+ chart ( { columns, isStatic = false , rootProps } : CubeSkeletonLayoutProps ) {
140157 columns = columns || 12 ;
141158
142159 const heightMap = [ 1 , 4 , 2 , 5 , 8 , 9 , 5 , 3 , 4 , 2 , 6 , 7 , 2 ] ;
@@ -148,7 +165,7 @@ const LAYOUT_MAP = {
148165 padding = "1x 0"
149166 placeItems = "end stretch"
150167 height = "40x"
151- { ...props }
168+ { ...rootProps }
152169 >
153170 { Array ( columns )
154171 . fill ( 0 )
@@ -168,15 +185,22 @@ const LAYOUT_MAP = {
168185} as const ;
169186
170187export interface CubeSkeletonProps
171- extends CubeGridProps ,
172- CubePlaceholderProps ,
173- BaseProps ,
174- ContainerStyleProps {
188+ extends CubeSkeletonRootProps ,
189+ Omit < CubeSkeletonLayoutProps , 'rootProps' > {
175190 /** The type of the layout */
176191 layout ?: keyof typeof LAYOUT_MAP ;
177- /** The number of columns for table layout */
192+ }
193+
194+ export interface CubeSkeletonRootProps
195+ extends Omit < CubeGridProps , 'columns' | 'rows' > ,
196+ CubePlaceholderProps ,
197+ BaseProps ,
198+ ContainerStyleProps { }
199+
200+ export interface CubeSkeletonLayoutProps {
201+ /** The number of columns for the table layout */
178202 columns ?: number ;
179- /** The number of rows for table layout */
203+ /** The number of rows for the table layout */
180204 rows ?: number ;
181205 /** The number of placeholder lines */
182206 lines ?: number ;
@@ -186,14 +210,33 @@ export interface CubeSkeletonProps
186210 cards ?: number ;
187211 /** The static mode */
188212 isStatic ?: boolean ;
213+ rootProps ?: CubeSkeletonRootProps ;
214+ children ?: ReactNode ;
189215}
190216
191- export function Skeleton ( { layout, isStatic, ...props } : CubeSkeletonProps ) {
217+ export function Skeleton ( {
218+ layout,
219+ isStatic,
220+ columns,
221+ rows,
222+ lines,
223+ tabs,
224+ cards,
225+ ...props
226+ } : CubeSkeletonProps ) {
192227 layout = layout || 'page' ;
193228
194229 return LAYOUT_MAP [ layout ] ? (
195- LAYOUT_MAP [ layout ] ( { isStatic, ...props , qa : 'Skeleton' } )
230+ LAYOUT_MAP [ layout ] ( {
231+ isStatic,
232+ columns,
233+ rows,
234+ lines,
235+ tabs,
236+ cards,
237+ rootProps : { qa : 'Skeleton' , ...props } ,
238+ } )
196239 ) : (
197- < Placeholder { ...props } />
240+ < Placeholder qa = "Skeleton" isStatic = { isStatic } { ...props } />
198241 ) ;
199242}
0 commit comments