-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose prettyDuration and commonDurationRanges (#2132)
* Expose prettyDuration and commonDurationRanges * prettyDuration docs * changelog * changelog * Update src-docs/src/views/pretty_duration/pretty_duration.js Co-Authored-By: [email protected] <[email protected]> * Update src-docs/src/views/pretty_duration/pretty_duration_example.js Co-Authored-By: Caroline Horn <[email protected]> * Update src-docs/src/views/pretty_duration/pretty_duration.js Co-Authored-By: Caroline Horn <[email protected]> * Update src-docs/src/views/pretty_duration/pretty_duration.js Co-Authored-By: Caroline Horn <[email protected]> * docs tweaks * lint fix
- Loading branch information
1 parent
c350f7f
commit 647d946
Showing
10 changed files
with
196 additions
and
12 deletions.
There are no files selected for viewing
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
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,77 @@ | ||
import React, { Fragment } from 'react'; | ||
|
||
import { | ||
EuiSpacer, | ||
EuiCodeBlock, | ||
EuiText, | ||
prettyDuration, | ||
} from '../../../../src/components'; | ||
|
||
const examples = [ | ||
{ | ||
start: '2018-01-17T18:57:57.149Z', | ||
end: '2018-01-17T20:00:00.000Z', | ||
quickRanges: [], | ||
dateFormat: 'MMMM Do YYYY, HH:mm:ss.SSS', | ||
}, | ||
{ | ||
start: '2018-01-17T18:57:57.149Z', | ||
end: '2018-01-17T20:00:00.000Z', | ||
quickRanges: [], | ||
dateFormat: 'MMMM Do YYYY @ HH:mm:ss.SSS', | ||
}, | ||
{ | ||
start: '2018-01-17T18:57:57.149Z', | ||
end: 'now-2h', | ||
quickRanges: [], | ||
dateFormat: 'MMMM Do YYYY @ HH:mm:ss.SSS', | ||
}, | ||
{ | ||
start: 'now-17m', | ||
end: 'now', | ||
quickRanges: [], | ||
dateFormat: 'MMMM Do YYYY @ HH:mm:ss.SSS', | ||
}, | ||
{ | ||
start: 'now-17m', | ||
end: 'now-1m', | ||
quickRanges: [], | ||
dateFormat: 'MMMM Do YYYY @ HH:mm:ss.SSS', | ||
}, | ||
{ | ||
start: 'now-15m', | ||
end: 'now', | ||
quickRanges: [ | ||
{ | ||
start: 'now-15m', | ||
end: 'now', | ||
label: 'quick range 15 minutes custom display', | ||
}, | ||
], | ||
dateFormat: 'MMMM Do YYYY, HH:mm:ss.SSS', | ||
}, | ||
]; | ||
|
||
export default function prettyDurationExample() { | ||
return ( | ||
<Fragment> | ||
{examples.map(({ start, end, quickRanges, dateFormat }, idx) => ( | ||
<div key={idx}> | ||
<EuiCodeBlock paddingSize="s"> | ||
prettyDuration('{start}', '{end}',{' '} | ||
{JSON.stringify(quickRanges)}, ' | ||
{dateFormat}') | ||
</EuiCodeBlock> | ||
|
||
<EuiSpacer size="s" /> | ||
|
||
<EuiText> | ||
<p>{prettyDuration(start, end, quickRanges, dateFormat)}</p> | ||
</EuiText> | ||
|
||
<EuiSpacer size="xl" /> | ||
</div> | ||
))} | ||
</Fragment> | ||
); | ||
} |
71 changes: 71 additions & 0 deletions
71
src-docs/src/views/pretty_duration/pretty_duration_example.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,71 @@ | ||
import React, { Fragment } from 'react'; | ||
|
||
import { renderToHtml } from '../../services'; | ||
|
||
import { GuideSectionTypes } from '../../components'; | ||
|
||
import { | ||
EuiAccordion, | ||
EuiCode, | ||
EuiCodeBlock, | ||
EuiSpacer, | ||
commonDurationRanges, | ||
} from '../../../../src/components'; | ||
|
||
import PrettyDuration from './pretty_duration'; | ||
const prettyDurationSource = require('!!raw-loader!./pretty_duration'); | ||
const prettyDurationHtml = renderToHtml(PrettyDuration); | ||
|
||
export const PrettyDurationExample = { | ||
title: 'Pretty Duration', | ||
sections: [ | ||
{ | ||
source: [ | ||
{ | ||
type: GuideSectionTypes.JS, | ||
code: prettyDurationSource, | ||
}, | ||
{ | ||
type: GuideSectionTypes.HTML, | ||
code: prettyDurationHtml, | ||
}, | ||
], | ||
text: ( | ||
<Fragment> | ||
<p> | ||
Use <EuiCode>prettyDuration</EuiCode> to convert a start and end | ||
date string to a human-friendly format. | ||
</p> | ||
|
||
<p> | ||
Start and end values for the duration are passed as the first and | ||
second arguments, respectively. These can be timestamps ( | ||
<EuiCode>2018-01-17T18:57:57.149Z</EuiCode>) or relative times ( | ||
<EuiCode>now-15m</EuiCode>). | ||
</p> | ||
|
||
<p> | ||
An array of quick range values is passed as the third argument. | ||
These are used to pretty format custom ranges. EUI exports | ||
<EuiCode>commonDurationRanges</EuiCode> which can be passed here. | ||
</p> | ||
|
||
<EuiAccordion | ||
id="commonDurationRanges" | ||
buttonContent="Show commonDurationRanges definition"> | ||
<EuiCodeBlock> | ||
{JSON.stringify(commonDurationRanges, null, 2)} | ||
</EuiCodeBlock> | ||
</EuiAccordion> | ||
|
||
<EuiSpacer /> | ||
|
||
<p> | ||
The output date/time format is specified by the fourth argument. | ||
</p> | ||
</Fragment> | ||
), | ||
demo: <PrettyDuration />, | ||
}, | ||
], | ||
}; |
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export { EuiSuperDatePicker } from './super_date_picker'; | ||
|
||
export { EuiSuperUpdateButton } from './super_update_button'; | ||
|
||
export { prettyDuration, commonDurationRanges } from './pretty_duration'; |
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
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