-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply feedback and add alignment example
- Loading branch information
Showing
3 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
aries-site/src/examples/foundation/date-and-time/DateAlignmentExample.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react'; | ||
import { DataTable } from 'grommet'; | ||
|
||
// could be expanded to weeks, months, etc. | ||
const getDuration = (start, end) => { | ||
const difference = end.getTime() - start.getTime(); | ||
const hours = difference / (1000 * 60 * 60); | ||
const minutes = (hours % 1) * 60; | ||
const seconds = (minutes % 1) * 60; | ||
|
||
const formattedTime = { | ||
hours: Math.floor(hours), | ||
minutes: Math.floor(minutes), | ||
seconds: Math.floor(seconds), | ||
}; | ||
|
||
return `${formattedTime.hours ? `${formattedTime.hours} hr` : ''} ${ | ||
formattedTime.minutes ? `${formattedTime.minutes} min` : '' | ||
} ${formattedTime.seconds ? `${formattedTime.seconds} sec` : ''}`; | ||
}; | ||
|
||
export const DateAlignmentExample = () => { | ||
// in production, this should just be new Date(); | ||
const mockNow = new Date('2023-05-20T08:32:18.000Z'); | ||
return ( | ||
<DataTable | ||
columns={[ | ||
{ | ||
property: 'triggerTime', | ||
header: 'Trigger time', | ||
}, | ||
{ | ||
property: 'id', | ||
header: 'Duration', | ||
align: 'end', | ||
render: datum => getDuration(new Date(datum.triggerTime), mockNow), | ||
}, | ||
]} | ||
sort={{ property: 'triggerTime', direction: 'desc' }} | ||
data={[ | ||
{ | ||
id: 0, | ||
triggerTime: '2023-05-20T07:32:08.000Z', | ||
}, | ||
{ | ||
id: 1, | ||
triggerTime: '2023-05-20T07:45:15.000Z', | ||
}, | ||
{ | ||
id: 2, | ||
triggerTime: '2023-05-20T04:30:24.000Z', | ||
}, | ||
{ | ||
id: 3, | ||
triggerTime: '2023-05-20T07:49:30.000Z', | ||
}, | ||
{ | ||
id: 4, | ||
triggerTime: '2023-05-20T07:53:46.000Z', | ||
}, | ||
]} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters