@@ -12,6 +12,7 @@ import {
12
12
FormField ,
13
13
Header ,
14
14
Input ,
15
+ Link ,
15
16
Slider ,
16
17
SpaceBetween ,
17
18
StatusIndicator ,
@@ -192,37 +193,60 @@ function TableCellsDemo() {
192
193
193
194
const columnDefinitions : TableProps . ColumnDefinition < number > [ ] = columns . map ( index => {
194
195
const columnId = index . toString ( ) ;
195
- const cellContent = ( item : number ) =>
196
- editedValues [ `${ columnId } :${ item } ` ] ??
197
- `Body cell content ${ item } :${ index } ${ index === 1 ? ` (L=${ itemLevels [ item ] } )` : '' } ${ index === 8 ? ' with longer text' : '' } ` ;
196
+ const cellRenderer = ( ( ) => {
197
+ const getText = ( item : number ) =>
198
+ editedValues [ `${ columnId } :${ item } ` ] ??
199
+ `Body cell content ${ item } :${ index } ${ index === 1 ? ` (L=${ itemLevels [ item ] } )` : '' } ${ index === 8 ? ' with longer text' : '' } ` ;
200
+ switch ( index ) {
201
+ case 1 :
202
+ return { type : 'link' , getText, render : ( item : number ) => < Link > { getText ( item ) } </ Link > } ;
203
+ case 3 :
204
+ return {
205
+ type : 'status' ,
206
+ getText,
207
+ render : ( item : number ) => < StatusIndicator > { getText ( item ) } </ StatusIndicator > ,
208
+ } ;
209
+ case 4 :
210
+ return { type : 'right-align' , getText, render : ( ) => < Box textAlign = "right" > { index } </ Box > } ;
211
+ case 10 :
212
+ return {
213
+ type : 'actions' ,
214
+ getText,
215
+ render : ( ) => < Button variant = "icon" iconName = "ellipsis" ariaLabel = "Actions" /> ,
216
+ } ;
217
+ default :
218
+ return { type : 'text' , getText, render : getText } ;
219
+ }
220
+ } ) ( ) ;
198
221
return {
199
222
id : columnId ,
200
223
header : `Header cell content ${ index } ${ index === 8 ? ' with longer text' : '' } ` ,
201
224
sortingField : index === 2 ? 'field-1' : index === 3 ? 'field-2' : undefined ,
202
225
activeSorting : index === 3 ,
203
- cell : cellContent ,
226
+ cell : item => cellRenderer . render ( item ) ,
204
227
verticalAlign : settings . verticalAlign ,
205
- editConfig : settings . isEditable
206
- ? {
207
- ariaLabel : 'Edit dialog aria label' ,
208
- editIconAriaLabel : 'Edit icon label' ,
209
- errorIconAriaLabel : 'Edit error icon label' ,
210
- validation ( _item , value = '' ) {
211
- if ( value . trim ( ) && value . toLowerCase ( ) . includes ( 'content' ) ) {
212
- return 'Must not include "content"' ;
213
- }
214
- } ,
215
- editingCell ( item , { currentValue, setValue } : TableProps . CellContext < string > ) {
216
- return (
217
- < Input
218
- autoFocus = { true }
219
- value = { currentValue ?? cellContent ( item ) }
220
- onChange = { event => setValue ( event . detail . value ) }
221
- />
222
- ) ;
223
- } ,
224
- }
225
- : undefined ,
228
+ editConfig :
229
+ settings . isEditable && cellRenderer . type !== 'link' && cellRenderer . type !== 'actions'
230
+ ? {
231
+ ariaLabel : 'Edit dialog aria label' ,
232
+ editIconAriaLabel : 'Edit icon label' ,
233
+ errorIconAriaLabel : 'Edit error icon label' ,
234
+ validation ( _item , value = '' ) {
235
+ if ( value . trim ( ) && value . toLowerCase ( ) . includes ( 'content' ) ) {
236
+ return 'Must not include "content"' ;
237
+ }
238
+ } ,
239
+ editingCell ( item , { currentValue, setValue } : TableProps . CellContext < string > ) {
240
+ return (
241
+ < Input
242
+ autoFocus = { true }
243
+ value = { currentValue ?? cellRenderer . getText ( item ) }
244
+ onChange = { event => setValue ( event . detail . value ) }
245
+ />
246
+ ) ;
247
+ } ,
248
+ }
249
+ : undefined ,
226
250
} ;
227
251
} ) ;
228
252
0 commit comments