5
5
import * as React from 'react' ;
6
6
7
7
// -----------------------------------------------------------------------------
8
- // Types
8
+ // ModuleGrid Component
9
9
// -----------------------------------------------------------------------------
10
10
11
11
export type ModuleGridCol = 'auto' | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 ;
12
12
13
- export interface ModuleGridProps {
13
+ export interface ModuleGridProps
14
+ extends React . HTMLAttributes <
15
+ | HTMLDivElement
16
+ | HTMLSpanElement
17
+ | HTMLUListElement
18
+ | HTMLOListElement
19
+ | HTMLLIElement
20
+ > {
21
+ component ?:
22
+ | 'div'
23
+ | 'span'
24
+ | 'ul'
25
+ | 'ol'
26
+ | 'li'
27
+ | 'header'
28
+ | 'footer'
29
+ | 'aside'
30
+ | 'section'
31
+ | 'main' ;
14
32
cols ?: ModuleGridCol ;
15
33
xxsCols ?: ModuleGridCol ;
16
34
xsCols ?: ModuleGridCol ;
@@ -23,10 +41,6 @@ export interface ModuleGridProps {
23
41
hdCols ?: ModuleGridCol ;
24
42
}
25
43
26
- // -----------------------------------------------------------------------------
27
- // ModuleGrid Component
28
- // -----------------------------------------------------------------------------
29
-
30
44
const colClassName = ( col ?: ModuleGridCol , mq : string = '' ) : string | boolean => {
31
45
return typeof col === 'number' || col === 'auto'
32
46
? `_${ mq } module-grid--${ col } `
@@ -37,16 +51,41 @@ export const ModuleGrid: React.FC<ModuleGridProps> = ({
37
51
cols,
38
52
xxsCols,
39
53
xsCols,
40
- children
54
+ smCols,
55
+ mdCols,
56
+ dfCols,
57
+ lgCols,
58
+ xlCols,
59
+ xxlCols,
60
+ hdCols,
61
+ className,
62
+ component = 'div' ,
63
+ children,
64
+ ...htmlProps
41
65
} ) => {
42
- const classes = [
43
- '_module-grid' ,
44
- colClassName ( cols ) ,
45
- colClassName ( xxsCols , 'xxs:' ) ,
46
- colClassName ( xsCols , 'xs:' )
47
- ] ;
48
-
49
- return < div className = { classes . filter ( Boolean ) . join ( ' ' ) } > { children } </ div > ;
66
+ return React . createElement (
67
+ component ,
68
+ {
69
+ ...htmlProps ,
70
+ classNames : [
71
+ '_module-grid' ,
72
+ colClassName ( cols ) ,
73
+ colClassName ( xxsCols , 'xxs:' ) ,
74
+ colClassName ( xsCols , 'xs:' ) ,
75
+ colClassName ( smCols , 'sm:' ) ,
76
+ colClassName ( mdCols , 'md:' ) ,
77
+ colClassName ( dfCols , 'df:' ) ,
78
+ colClassName ( lgCols , 'lg:' ) ,
79
+ colClassName ( xlCols , 'xl:' ) ,
80
+ colClassName ( xxlCols , 'xxl:' ) ,
81
+ colClassName ( hdCols , 'hd:' ) ,
82
+ className
83
+ ]
84
+ . filter ( Boolean )
85
+ . join ( ' ' )
86
+ } ,
87
+ children
88
+ ) ;
50
89
} ;
51
90
52
91
// -----------------------------------------------------------------------------
@@ -55,7 +94,24 @@ export const ModuleGrid: React.FC<ModuleGridProps> = ({
55
94
56
95
export type ModuleCellSpan = 'auto' | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 ;
57
96
58
- export type ModuleCellProps = {
97
+ export interface ModuleCellProps
98
+ extends React . HTMLAttributes <
99
+ | HTMLDivElement
100
+ | HTMLSpanElement
101
+ | HTMLUListElement
102
+ | HTMLOListElement
103
+ | HTMLLIElement
104
+ > {
105
+ component ?:
106
+ | 'div'
107
+ | 'span'
108
+ | 'ul'
109
+ | 'ol'
110
+ | 'li'
111
+ | 'header'
112
+ | 'footer'
113
+ | 'aside'
114
+ | 'section' ;
59
115
span ?: ModuleCellSpan ;
60
116
xxsSpan ?: ModuleCellSpan ;
61
117
xsSpan ?: ModuleCellSpan ;
@@ -66,15 +122,51 @@ export type ModuleCellProps = {
66
122
xlSpan ?: ModuleCellSpan ;
67
123
xxlSpan ?: ModuleCellSpan ;
68
124
hdSpan ?: ModuleCellSpan ;
69
- } ;
125
+ }
70
126
71
127
const spanClassName = ( span ?: ModuleCellSpan , mq : string = '' ) : string | boolean => {
72
128
return typeof span === 'number' || span === 'auto'
73
129
? `_${ mq } module-cell--${ span } `
74
130
: false ;
75
131
} ;
76
132
77
- export const ModuleCell : React . FC < ModuleCellProps > = ( { span, children } ) => {
78
- const classes = [ '_module-cell' , spanClassName ( span ) ] ;
79
- return < div className = { classes . join ( ' ' ) } > { children } </ div > ;
133
+ export const ModuleCell : React . FC < ModuleCellProps > = ( {
134
+ span,
135
+ xxsSpan,
136
+ xsSpan,
137
+ smSpan,
138
+ mdSpan,
139
+ dfSpan,
140
+ lgSpan,
141
+ xlSpan,
142
+ xxlSpan,
143
+ hdSpan,
144
+ className,
145
+ component = 'div' ,
146
+ children,
147
+ ...htmlProps
148
+ } ) => {
149
+ return React . createElement (
150
+ component ,
151
+ {
152
+ ...htmlProps ,
153
+ classNames : [
154
+ '_module-cell' ,
155
+ spanClassName ( span ) ,
156
+ spanClassName ( xxsSpan , 'xxs:' ) ,
157
+ spanClassName ( xsSpan , 'xs:' ) ,
158
+ spanClassName ( smSpan , 'sm:' ) ,
159
+ spanClassName ( mdSpan , 'md:' ) ,
160
+ spanClassName ( dfSpan , 'df:' ) ,
161
+ spanClassName ( lgSpan , 'lg:' ) ,
162
+ spanClassName ( xlSpan , 'xl:' ) ,
163
+ spanClassName ( xxlSpan , 'xxl:' ) ,
164
+ spanClassName ( hdSpan , 'hd:' ) ,
165
+ className
166
+ ]
167
+ . filter ( Boolean )
168
+ . join ( ' ' )
169
+ } ,
170
+ children
171
+ ) ;
80
172
} ;
0 commit comments