2019-09-17 04:25:12 -05:00
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { css } from 'emotion';
|
|
|
|
import memoizeOne from 'memoize-one';
|
|
|
|
import tinycolor from 'tinycolor2';
|
2019-09-20 06:00:11 -05:00
|
|
|
import { CSSTransition } from 'react-transition-group';
|
2019-10-10 15:16:04 -05:00
|
|
|
import { ResponsiveButton } from './ResponsiveButton';
|
2019-09-17 04:25:12 -05:00
|
|
|
|
2019-10-07 16:30:07 -05:00
|
|
|
import { GrafanaTheme, useTheme, Tooltip } from '@grafana/ui';
|
2019-09-17 04:25:12 -05:00
|
|
|
|
|
|
|
const getStyles = memoizeOne((theme: GrafanaTheme) => {
|
2019-09-25 11:09:08 -05:00
|
|
|
const orangeLighter = tinycolor(theme.colors.orangeDark)
|
2019-09-20 06:00:11 -05:00
|
|
|
.lighten(10)
|
|
|
|
.toString();
|
2019-09-25 11:09:08 -05:00
|
|
|
const pulseTextColor = tinycolor(theme.colors.orangeDark)
|
2019-09-20 06:00:11 -05:00
|
|
|
.desaturate(90)
|
|
|
|
.toString();
|
2019-09-17 04:25:12 -05:00
|
|
|
|
|
|
|
return {
|
|
|
|
noRightBorderStyle: css`
|
|
|
|
label: noRightBorderStyle;
|
|
|
|
border-right: 0;
|
|
|
|
`,
|
2019-09-20 06:00:11 -05:00
|
|
|
liveButton: css`
|
|
|
|
label: liveButton;
|
|
|
|
transition: background-color 1s, border-color 1s, color 1s;
|
|
|
|
margin: 0;
|
|
|
|
`,
|
2019-09-17 04:25:12 -05:00
|
|
|
isLive: css`
|
|
|
|
label: isLive;
|
2019-09-25 11:09:08 -05:00
|
|
|
border-color: ${theme.colors.orangeDark};
|
|
|
|
color: ${theme.colors.orangeDark};
|
2019-09-17 04:25:12 -05:00
|
|
|
background: transparent;
|
|
|
|
&:focus {
|
2019-09-25 11:09:08 -05:00
|
|
|
border-color: ${theme.colors.orangeDark};
|
|
|
|
color: ${theme.colors.orangeDark};
|
2019-09-17 04:25:12 -05:00
|
|
|
}
|
|
|
|
&:active,
|
|
|
|
&:hover {
|
|
|
|
border-color: ${orangeLighter};
|
|
|
|
color: ${orangeLighter};
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
isPaused: css`
|
|
|
|
label: isPaused;
|
2019-09-25 11:09:08 -05:00
|
|
|
border-color: ${theme.colors.orangeDark};
|
2019-09-17 04:25:12 -05:00
|
|
|
background: transparent;
|
2019-09-20 06:00:11 -05:00
|
|
|
animation: pulse 3s ease-out 0s infinite normal forwards;
|
2019-09-17 04:25:12 -05:00
|
|
|
&:focus {
|
2019-09-25 11:09:08 -05:00
|
|
|
border-color: ${theme.colors.orangeDark};
|
2019-09-17 04:25:12 -05:00
|
|
|
}
|
|
|
|
&:active,
|
|
|
|
&:hover {
|
|
|
|
border-color: ${orangeLighter};
|
|
|
|
}
|
|
|
|
@keyframes pulse {
|
|
|
|
0% {
|
2019-09-20 06:00:11 -05:00
|
|
|
color: ${pulseTextColor};
|
2019-09-17 04:25:12 -05:00
|
|
|
}
|
|
|
|
50% {
|
2019-09-25 11:09:08 -05:00
|
|
|
color: ${theme.colors.orangeDark};
|
2019-09-17 04:25:12 -05:00
|
|
|
}
|
|
|
|
100% {
|
2019-09-20 06:00:11 -05:00
|
|
|
color: ${pulseTextColor};
|
2019-09-17 04:25:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
2019-09-20 06:00:11 -05:00
|
|
|
stopButtonEnter: css`
|
|
|
|
label: stopButtonEnter;
|
|
|
|
width: 0;
|
|
|
|
opacity: 0;
|
|
|
|
overflow: hidden;
|
|
|
|
`,
|
|
|
|
stopButtonEnterActive: css`
|
|
|
|
label: stopButtonEnterActive;
|
|
|
|
opacity: 1;
|
|
|
|
width: 32px;
|
|
|
|
transition: opacity 500ms ease-in 50ms, width 500ms ease-in 50ms;
|
|
|
|
`,
|
|
|
|
stopButtonExit: css`
|
|
|
|
label: stopButtonExit;
|
|
|
|
width: 32px;
|
|
|
|
opacity: 1;
|
|
|
|
overflow: hidden;
|
|
|
|
`,
|
|
|
|
stopButtonExitActive: css`
|
|
|
|
label: stopButtonExitActive;
|
|
|
|
opacity: 0;
|
|
|
|
width: 0;
|
|
|
|
transition: opacity 500ms ease-in 50ms, width 500ms ease-in 50ms;
|
|
|
|
`,
|
2019-09-17 04:25:12 -05:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2019-10-07 16:32:50 -05:00
|
|
|
const defaultLiveTooltip = () => {
|
|
|
|
return <>Live</>;
|
2019-10-07 16:30:07 -05:00
|
|
|
};
|
|
|
|
|
2019-09-17 04:25:12 -05:00
|
|
|
type LiveTailButtonProps = {
|
2019-10-10 15:16:04 -05:00
|
|
|
splitted: boolean;
|
2019-09-17 04:25:12 -05:00
|
|
|
start: () => void;
|
|
|
|
stop: () => void;
|
|
|
|
pause: () => void;
|
|
|
|
resume: () => void;
|
|
|
|
isLive: boolean;
|
|
|
|
isPaused: boolean;
|
|
|
|
};
|
|
|
|
export function LiveTailButton(props: LiveTailButtonProps) {
|
2019-10-10 15:16:04 -05:00
|
|
|
const { start, pause, resume, isLive, isPaused, stop, splitted } = props;
|
2019-09-17 04:25:12 -05:00
|
|
|
const theme = useTheme();
|
|
|
|
const styles = getStyles(theme);
|
|
|
|
|
|
|
|
const onClickMain = isLive ? (isPaused ? resume : pause) : start;
|
|
|
|
|
|
|
|
return (
|
2019-09-20 06:00:11 -05:00
|
|
|
<>
|
2019-10-07 16:32:50 -05:00
|
|
|
<Tooltip content={defaultLiveTooltip} placement="bottom">
|
2019-10-10 15:16:04 -05:00
|
|
|
<ResponsiveButton
|
|
|
|
splitted={splitted}
|
|
|
|
buttonClassName={classNames('btn navbar-button', styles.liveButton, {
|
2019-10-07 16:30:07 -05:00
|
|
|
[`btn--radius-right-0 ${styles.noRightBorderStyle}`]: isLive,
|
|
|
|
[styles.isLive]: isLive && !isPaused,
|
|
|
|
[styles.isPaused]: isLive && isPaused,
|
|
|
|
})}
|
2019-10-10 15:16:04 -05:00
|
|
|
iconClassName={classNames('fa', isPaused || !isLive ? 'fa-play' : 'fa-pause')}
|
2019-10-07 16:30:07 -05:00
|
|
|
onClick={onClickMain}
|
2019-10-10 15:16:04 -05:00
|
|
|
title={'\xa0Live'}
|
|
|
|
/>
|
2019-10-07 16:30:07 -05:00
|
|
|
</Tooltip>
|
2019-09-20 06:00:11 -05:00
|
|
|
<CSSTransition
|
|
|
|
mountOnEnter={true}
|
|
|
|
unmountOnExit={true}
|
|
|
|
timeout={500}
|
|
|
|
in={isLive}
|
|
|
|
classNames={{
|
|
|
|
enter: styles.stopButtonEnter,
|
|
|
|
enterActive: styles.stopButtonEnterActive,
|
|
|
|
exit: styles.stopButtonExit,
|
|
|
|
exitActive: styles.stopButtonExitActive,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<button className={`btn navbar-button navbar-button--attached ${styles.isLive}`} onClick={stop}>
|
|
|
|
<i className={'fa fa-stop'} />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</CSSTransition>
|
|
|
|
</>
|
2019-09-17 04:25:12 -05:00
|
|
|
);
|
|
|
|
}
|