-
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.
Revamp EuiSuperDatePicker docs (#2641)
- Loading branch information
1 parent
fbe66d5
commit 0cd2dae
Showing
6 changed files
with
427 additions
and
160 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
131 changes: 131 additions & 0 deletions
131
src-docs/src/views/super_date_picker/super_date_picker.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,131 @@ | ||
import React, { Component, Fragment } from 'react'; | ||
|
||
import { | ||
EuiSuperDatePicker, | ||
EuiSpacer, | ||
EuiFormControlLayoutDelimited, | ||
EuiFormLabel, | ||
EuiPanel, | ||
EuiText, | ||
} from '../../../../src/components'; | ||
|
||
export default class extends Component { | ||
state = { | ||
recentlyUsedRanges: [], | ||
isLoading: false, | ||
start: 'now-30m', | ||
end: 'now', | ||
}; | ||
|
||
onTimeChange = ({ start, end }) => { | ||
this.setState(prevState => { | ||
const recentlyUsedRanges = prevState.recentlyUsedRanges.filter( | ||
recentlyUsedRange => { | ||
const isDuplicate = | ||
recentlyUsedRange.start === start && recentlyUsedRange.end === end; | ||
return !isDuplicate; | ||
} | ||
); | ||
recentlyUsedRanges.unshift({ start, end }); | ||
return { | ||
start, | ||
end, | ||
recentlyUsedRanges: | ||
recentlyUsedRanges.length > 10 | ||
? recentlyUsedRanges.slice(0, 9) | ||
: recentlyUsedRanges, | ||
isLoading: true, | ||
}; | ||
}, this.startLoading); | ||
}; | ||
|
||
onRefresh = ({ start, end, refreshInterval }) => { | ||
return new Promise(resolve => { | ||
setTimeout(resolve, 100); | ||
}).then(() => { | ||
console.log(start, end, refreshInterval); | ||
}); | ||
}; | ||
|
||
onStartInputChange = e => { | ||
this.setState({ | ||
start: e.target.value, | ||
}); | ||
}; | ||
|
||
onEndInputChange = e => { | ||
this.setState({ | ||
end: e.target.value, | ||
}); | ||
}; | ||
|
||
startLoading = () => { | ||
setTimeout(this.stopLoading, 1000); | ||
}; | ||
|
||
stopLoading = () => { | ||
this.setState({ isLoading: false }); | ||
}; | ||
|
||
onRefreshChange = ({ isPaused, refreshInterval }) => { | ||
this.setState({ | ||
isPaused, | ||
refreshInterval, | ||
}); | ||
}; | ||
|
||
renderTimeRange = () => { | ||
return ( | ||
<Fragment> | ||
<EuiPanel paddingSize="m"> | ||
<EuiText size="s"> | ||
EuiSuperDatePicker should be resilient to invalid date values. You | ||
can try to break it with unexpected values here. | ||
</EuiText> | ||
<EuiSpacer /> | ||
<EuiFormControlLayoutDelimited | ||
prepend={<EuiFormLabel>Dates</EuiFormLabel>} | ||
startControl={ | ||
<input | ||
onChange={this.onStartInputChange} | ||
type="text" | ||
value={this.state.start} | ||
placeholder="start" | ||
className="euiFieldText" | ||
/> | ||
} | ||
endControl={ | ||
<input | ||
onChange={this.onEndInputChange} | ||
type="text" | ||
placeholder="end" | ||
value={this.state.end} | ||
className="euiFieldText" | ||
/> | ||
} | ||
/> | ||
</EuiPanel> | ||
</Fragment> | ||
); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<Fragment> | ||
<EuiSuperDatePicker | ||
isLoading={this.state.isLoading} | ||
start={this.state.start} | ||
end={this.state.end} | ||
onTimeChange={this.onTimeChange} | ||
onRefresh={this.onRefresh} | ||
isPaused={this.state.isPaused} | ||
refreshInterval={this.state.refreshInterval} | ||
onRefreshChange={this.onRefreshChange} | ||
recentlyUsedRanges={this.state.recentlyUsedRanges} | ||
/> | ||
<EuiSpacer /> | ||
{this.renderTimeRange()} | ||
</Fragment> | ||
); | ||
} | ||
} |
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
Oops, something went wrong.