@@ -2,18 +2,51 @@ import dataLarge from '@sb/mockData/Friends500.json';
22import type { Meta , StoryObj } from '@storybook/react' ;
33import TableGrowingMode from '@ui5/webcomponents/dist/types/TableGrowingMode.js' ;
44import TableSelectionMode from '@ui5/webcomponents/dist/types/TableSelectionMode.js' ;
5- import type { TableVirtualizerPropTypes } from '@ui5/webcomponents-react' ;
5+ import editIcon from '@ui5/webcomponents-icons/dist/edit.js' ;
6+ import saveIcon from '@ui5/webcomponents-icons/dist/save.js' ;
7+ import type { TablePropTypes , TableVirtualizerPropTypes } from '@ui5/webcomponents-react' ;
68import { SegmentedButton , SegmentedButtonItem } from '@ui5/webcomponents-react' ;
79import { useEffect , useState } from 'react' ;
810import { TableCell } from '../TableCell/index.js' ;
911import { TableGrowing } from '../TableGrowing/index.js' ;
1012import { TableHeaderCell } from '../TableHeaderCell/index.js' ;
1113import { TableHeaderRow } from '../TableHeaderRow/index.js' ;
1214import { TableRow } from '../TableRow/index.js' ;
15+ import { TableRowAction } from '../TableRowAction/index.js' ;
16+ import { TableRowActionNavigation } from '../TableRowActionNavigation/index.js' ;
1317import { TableSelection } from '../TableSelection/index.js' ;
1418import { TableVirtualizer } from '../TableVirtualizer/index.js' ;
1519import { Table } from './index.js' ;
1620
21+ const popInColumns = (
22+ < TableHeaderRow sticky >
23+ < TableHeaderCell width = { '200px' } minWidth = { '200px' } >
24+ < span > Product</ span >
25+ </ TableHeaderCell >
26+ < TableHeaderCell minWidth = { '200px' } >
27+ < span > Supplier</ span >
28+ </ TableHeaderCell >
29+ < TableHeaderCell minWidth = { '200px' } >
30+ < span > Dimensions</ span >
31+ </ TableHeaderCell >
32+ < TableHeaderCell minWidth = { '100px' } maxWidth = "200px" >
33+ < span > Weight</ span >
34+ </ TableHeaderCell >
35+ < TableHeaderCell minWidth = "200px" >
36+ < span > Price</ span >
37+ </ TableHeaderCell >
38+ </ TableHeaderRow >
39+ ) ;
40+
41+ const columns = (
42+ < TableHeaderRow sticky >
43+ < TableHeaderCell > Name</ TableHeaderCell >
44+ < TableHeaderCell > Age</ TableHeaderCell >
45+ < TableHeaderCell > Friend Name</ TableHeaderCell >
46+ < TableHeaderCell > Friend Age</ TableHeaderCell >
47+ </ TableHeaderRow >
48+ ) ;
49+
1750const meta = {
1851 title : 'Data Display / Table' ,
1952 component : Table ,
@@ -23,25 +56,7 @@ const meta = {
2356 children : { control : { disable : true } }
2457 } ,
2558 args : {
26- headerRow : (
27- < TableHeaderRow sticky >
28- < TableHeaderCell width = { '200px' } minWidth = { '200px' } >
29- < span > Product</ span >
30- </ TableHeaderCell >
31- < TableHeaderCell minWidth = { '200px' } >
32- < span > Supplier</ span >
33- </ TableHeaderCell >
34- < TableHeaderCell minWidth = { '200px' } >
35- < span > Dimensions</ span >
36- </ TableHeaderCell >
37- < TableHeaderCell minWidth = { '100px' } maxWidth = "200px" >
38- < span > Weight</ span >
39- </ TableHeaderCell >
40- < TableHeaderCell minWidth = "200px" >
41- < span > Price</ span >
42- </ TableHeaderCell >
43- </ TableHeaderRow >
44- )
59+ headerRow : popInColumns
4560 } ,
4661 tags : [ 'package:@ui5/webcomponents' ]
4762} satisfies Meta < typeof Table > ;
@@ -189,7 +204,7 @@ export const WithSelection: Story = {
189204const dataLargeWithPosition = dataLarge . map ( ( item , index ) => ( { ...item , position : index } ) ) ;
190205
191206export const VirtualizedTableRows : Story = {
192- args : { className : 'tableHeightContentDensity' } ,
207+ args : { className : 'tableHeightContentDensity' , headerRow : columns } ,
193208 render ( args ) {
194209 const [ data , setData ] = useState ( dataLargeWithPosition . slice ( 0 , 9 ) ) ;
195210 const [ isCozy , setIsCozy ] = useState ( true ) ;
@@ -224,14 +239,6 @@ export const VirtualizedTableRows: Story = {
224239 return (
225240 < Table
226241 { ...args }
227- headerRow = {
228- < TableHeaderRow sticky >
229- < TableHeaderCell > Name</ TableHeaderCell >
230- < TableHeaderCell > Age</ TableHeaderCell >
231- < TableHeaderCell > Friend Name</ TableHeaderCell >
232- < TableHeaderCell > Friend Age</ TableHeaderCell >
233- </ TableHeaderRow >
234- }
235242 features = { < TableVirtualizer rowCount = { 500 } rowHeight = { isCozy ? 44 : 32 } onRangeChange = { handleRangeChange } /> }
236243 >
237244 { data . map ( ( row ) => (
@@ -254,3 +261,107 @@ export const VirtualizedTableRows: Story = {
254261 ) ;
255262 }
256263} ;
264+
265+ export const withRowActions : Story = {
266+ args : { headerRow : columns , rowActionCount : 3 } ,
267+ render ( args ) {
268+ return (
269+ < Table { ...args } >
270+ { dataLarge . slice ( 0 , 10 ) . map ( ( row , index ) => (
271+ < TableRow
272+ key = { `${ row . name } -${ row . age } ` }
273+ actions = {
274+ < >
275+ < TableRowAction icon = { editIcon } > Edit</ TableRowAction >
276+ < TableRowAction icon = { saveIcon } disabled >
277+ Save
278+ </ TableRowAction >
279+ < TableRowActionNavigation interactive = { ! ! ( index % 2 ) } />
280+ </ >
281+ }
282+ >
283+ < TableCell >
284+ < span > { row . name } </ span >
285+ </ TableCell >
286+ < TableCell >
287+ < span > { row . age } </ span >
288+ </ TableCell >
289+ < TableCell >
290+ < span > { row . friend . name } </ span >
291+ </ TableCell >
292+ < TableCell >
293+ < span > { row . friend . age } </ span >
294+ </ TableCell >
295+ </ TableRow >
296+ ) ) }
297+ </ Table >
298+ ) ;
299+ }
300+ } ;
301+
302+ export const dragAndDropRows : Story = {
303+ args : { headerRow : columns } ,
304+ render ( args ) {
305+ const [ rows , setRows ] = useState ( dataLargeWithPosition . slice ( 0 , 10 ) ) ;
306+
307+ const handleMove : TablePropTypes [ 'onMove' ] = ( e ) => {
308+ const { source, destination } = e . detail ;
309+ // enabling this causes the Storybook to freeze due to the number of logs
310+ // args.onMove(e);
311+
312+ setRows ( ( prevRows ) => {
313+ const sourceIndex = prevRows . findIndex ( ( row ) => `${ row . position } ` === source . element . dataset . id ) ;
314+ const destinationIndex = prevRows . findIndex ( ( row ) => `${ row . position } ` === destination . element . dataset . id ) ;
315+
316+ if ( sourceIndex === - 1 || destinationIndex === - 1 ) {
317+ return prevRows ;
318+ }
319+
320+ const updatedRows = [ ...prevRows ] ;
321+ const [ movedRow ] = updatedRows . splice ( sourceIndex , 1 ) ;
322+
323+ if ( destination . placement === 'Before' ) {
324+ updatedRows . splice ( destinationIndex , 0 , movedRow ) ;
325+ } else if ( destination . placement === 'After' ) {
326+ updatedRows . splice ( destinationIndex + 1 , 0 , movedRow ) ;
327+ }
328+
329+ return updatedRows ;
330+ } ) ;
331+ } ;
332+
333+ const handleMoveOver : TablePropTypes [ 'onMoveOver' ] = ( e ) => {
334+ const { source, destination } = e . detail ;
335+ // args.onMoveOver(e);
336+
337+ if (
338+ source . element . hasAttribute ( 'ui5-table-row' ) &&
339+ destination . element . hasAttribute ( 'ui5-table-row' ) &&
340+ destination . placement !== 'On'
341+ ) {
342+ e . preventDefault ( ) ;
343+ }
344+ } ;
345+
346+ return (
347+ < Table { ...args } onMove = { handleMove } onMoveOver = { handleMoveOver } >
348+ { rows . map ( ( row ) => (
349+ < TableRow key = { row . position } movable data-id = { row . position } >
350+ < TableCell >
351+ < span > { row . name } </ span >
352+ </ TableCell >
353+ < TableCell >
354+ < span > { row . age } </ span >
355+ </ TableCell >
356+ < TableCell >
357+ < span > { row . friend . name } </ span >
358+ </ TableCell >
359+ < TableCell >
360+ < span > { row . friend . age } </ span >
361+ </ TableCell >
362+ </ TableRow >
363+ ) ) }
364+ </ Table >
365+ ) ;
366+ }
367+ } ;
0 commit comments