1
- import { createRef , Fragment , RefObject , useEffect , useRef } from 'react'
1
+ import { createElement , createRef , Fragment , ReactElement , RefObject , useEffect , useRef } from 'react'
2
2
// eslint-disable-next-line import/no-extraneous-dependencies
3
3
import { followCursor } from 'tippy.js'
4
4
@@ -19,12 +19,15 @@ import { getActionButtonPosition, getRowGridTemplateColumn, rowTypeHasInputField
19
19
import { DynamicDataTableRowType , DynamicDataTableRowProps , DynamicDataTableRowDataType } from './types'
20
20
21
21
const conditionalWrap =
22
- (
23
- renderer : ( props : { customState ?: Record < string , any > ; children : JSX . Element } ) => JSX . Element ,
24
- customState : Record < string , any > ,
25
- ) =>
26
- ( children : JSX . Element ) =>
27
- renderer ( { children, customState } )
22
+ < K extends string > ( renderer : ( row : DynamicDataTableRowType < K > ) => ReactElement , row : DynamicDataTableRowType < K > ) =>
23
+ ( children : JSX . Element ) => {
24
+ if ( renderer ) {
25
+ const { props, type } = renderer ( row )
26
+ return createElement ( type , props , children )
27
+ }
28
+
29
+ return null
30
+ }
28
31
29
32
export const DynamicDataTableRow = < K extends string > ( {
30
33
rows = [ ] ,
@@ -40,6 +43,7 @@ export const DynamicDataTableRow = <K extends string>({
40
43
onRowDelete,
41
44
leadingCellIcon,
42
45
trailingCellIcon,
46
+ buttonCellWrapComponent,
43
47
} : DynamicDataTableRowProps < K > ) => {
44
48
// CONSTANTS
45
49
const isFirstRowEmpty = headers . every ( ( { key } ) => ! rows [ 0 ] ?. data [ key ] . value )
@@ -151,18 +155,16 @@ export const DynamicDataTableRow = <K extends string>({
151
155
return (
152
156
< div className = "w-100 h-100 flex top" >
153
157
< ConditionalWrap
154
- condition = { row . data [ key ] . wrap }
155
- wrap = { conditionalWrap ( row . data [ key ] . wrapRenderer , row . customState ) }
158
+ condition = { ! ! buttonCellWrapComponent }
159
+ wrap = { conditionalWrap ( buttonCellWrapComponent , row ) }
156
160
>
157
- < div >
158
- < button
159
- type = "button"
160
- className = { `dc__transparent w-100 p-8 flex left dc__gap-8 dc__hover-n50 cn-9 fs-13 lh-20 ${ row . data [ key ] . disabled ? 'dc__disabled' : '' } ` }
161
- >
162
- { row . data [ key ] . props ?. icon || null }
163
- { row . data [ key ] . props . text }
164
- </ button >
165
- </ div >
161
+ < button
162
+ type = "button"
163
+ className = { `dc__transparent w-100 p-8 flex left dc__gap-8 dc__hover-n50 cn-9 fs-13 lh-20 ${ row . data [ key ] . disabled ? 'dc__disabled' : '' } ` }
164
+ >
165
+ { row . data [ key ] . props ?. icon || null }
166
+ { row . data [ key ] . props . text }
167
+ </ button >
166
168
</ ConditionalWrap >
167
169
</ div >
168
170
)
0 commit comments