-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Autoplay pages in fullscreen (#35981)
* feat: add autoplay redux boilerplate WIP auto-play settings * feat: add page cycle settings * feat: add cycle toggle hotkey * chore: add tooltip text to settings icon * settings layout * fix: handle invalid input for custom interval * chore: address nit
- Loading branch information
Showing
15 changed files
with
384 additions
and
106 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
2 changes: 1 addition & 1 deletion
2
...ck/plugins/canvas/public/components/workpad_header/control_settings/control_settings.scss
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,3 @@ | ||
.canvasControlSettings__popover { | ||
width: 300px; | ||
width: 600px; | ||
} |
90 changes: 90 additions & 0 deletions
90
x-pack/plugins/canvas/public/components/workpad_header/control_settings/custom_interval.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,90 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiFormRow, EuiButton, EuiFieldText } from '@elastic/eui'; | ||
|
||
const getRefreshInterval = (val = '') => { | ||
// if it's a number, there is no interval, return undefined | ||
if (!isNaN(Number(val))) { | ||
return; | ||
} | ||
|
||
// if it's a string, try to parse out the shorthand duration value | ||
const match = String(val).match(/^([0-9]{1,})([hmsd])$/); | ||
|
||
// if it's invalid, there is no interval, return undefined | ||
if (!match) { | ||
return; | ||
} | ||
|
||
switch (match[2]) { | ||
case 's': | ||
return match[1] * 1000; | ||
case 'm': | ||
return match[1] * 1000 * 60; | ||
case 'h': | ||
return match[1] * 1000 * 60 * 60; | ||
case 'd': | ||
return match[1] * 1000 * 60 * 60 * 24; | ||
} | ||
}; | ||
|
||
export const CustomInterval = ({ gutterSize, buttonSize, onSubmit, defaultValue }) => { | ||
const [customInterval, setCustomInterval] = useState(defaultValue); | ||
const refreshInterval = getRefreshInterval(customInterval); | ||
const isInvalid = Boolean(customInterval.length && !refreshInterval); | ||
|
||
const handleChange = ev => setCustomInterval(ev.target.value); | ||
|
||
return ( | ||
<form | ||
onSubmit={ev => { | ||
ev.preventDefault(); | ||
onSubmit(refreshInterval); | ||
}} | ||
> | ||
<EuiFlexGroup gutterSize={gutterSize}> | ||
<EuiFlexItem> | ||
<EuiFormRow | ||
label="Set a custom interval" | ||
helpText="Use shorthand notation, like 30s, 10m, or 1h" | ||
compressed | ||
> | ||
<EuiFieldText isInvalid={isInvalid} value={customInterval} onChange={handleChange} /> | ||
</EuiFormRow> | ||
</EuiFlexItem> | ||
|
||
<EuiFlexItem grow={false}> | ||
<EuiFormRow label=" "> | ||
<EuiButton | ||
disabled={isInvalid} | ||
size={buttonSize} | ||
type="submit" | ||
style={{ minWidth: 'auto' }} | ||
> | ||
Set | ||
</EuiButton> | ||
</EuiFormRow> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</form> | ||
); | ||
}; | ||
|
||
CustomInterval.propTypes = { | ||
buttonSize: PropTypes.string, | ||
gutterSize: PropTypes.string, | ||
defaultValue: PropTypes.string, | ||
onSubmit: PropTypes.func.isRequired, | ||
}; | ||
|
||
CustomInterval.defaultProps = { | ||
buttonSize: 's', | ||
gutterSize: 's', | ||
defaultValue: '', | ||
}; |
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.