Commit bf4c11d0 by Alex Khomenko Committed by GitHub

Grafana ui/time of day picker ui improvements (#21950)

* Grafana-UI: Add caret to the picker

* Grafana-UI: Customise popup's font-size and border-color

* Grafana-UI: Replace highlight background with border color

* Grafana-UI: Use stylesFactory vs inline classes

* Grafana-UI: Import stylesFactory from themes vs index
parent dd37d003
import React, { FC } from 'react'; import React, { FC } from 'react';
import RcTimePicker from 'rc-time-picker'; import RcTimePicker from 'rc-time-picker';
import { dateTime, DateTime, dateTimeAsMoment } from '@grafana/data'; import { css } from 'emotion';
import { dateTime, DateTime, dateTimeAsMoment, GrafanaTheme } from '@grafana/data';
import { useTheme, Icon } from '../../index';
import { stylesFactory } from '../../themes';
interface Props { interface Props {
onChange: (value: DateTime) => void; onChange: (value: DateTime) => void;
...@@ -9,10 +12,42 @@ interface Props { ...@@ -9,10 +12,42 @@ interface Props {
minuteStep?: number; minuteStep?: number;
} }
const getStyles = stylesFactory((theme: GrafanaTheme) => {
return {
caretWrapper: css`
position: absolute;
right: 8px;
top: 50%;
transform: translateY(-50%);
display: inline-block;
text-align: right;
z-index: 1071;
`,
picker: css`
.rc-time-picker-panel-select {
border-color: ${theme.colors.dark6};
font-size: 14px;
li {
outline-width: 2px;
&.rc-time-picker-panel-select-option-selected {
background-color: inherit;
border: 1px solid ${theme.colors.orange};
border-radius: ${theme.border.radius.sm};
}
}
}
`,
};
});
export const TimeOfDayPicker: FC<Props> = ({ minuteStep = 1, showHour = true, onChange, value }) => { export const TimeOfDayPicker: FC<Props> = ({ minuteStep = 1, showHour = true, onChange, value }) => {
const theme = useTheme();
const styles = getStyles(theme);
return ( return (
<div> <div>
<RcTimePicker <RcTimePicker
popupClassName={styles.picker}
defaultValue={dateTimeAsMoment()} defaultValue={dateTimeAsMoment()}
onChange={(value: any) => onChange(dateTime(value))} onChange={(value: any) => onChange(dateTime(value))}
allowEmpty={false} allowEmpty={false}
...@@ -20,7 +55,20 @@ export const TimeOfDayPicker: FC<Props> = ({ minuteStep = 1, showHour = true, on ...@@ -20,7 +55,20 @@ export const TimeOfDayPicker: FC<Props> = ({ minuteStep = 1, showHour = true, on
value={dateTimeAsMoment(value)} value={dateTimeAsMoment(value)}
showHour={showHour} showHour={showHour}
minuteStep={minuteStep} minuteStep={minuteStep}
inputIcon={<Caret wrapperStyle={styles.caretWrapper} />}
/> />
</div> </div>
); );
}; };
interface CaretProps {
wrapperStyle?: string;
}
const Caret: FC<CaretProps> = ({ wrapperStyle = '' }) => {
return (
<div className={wrapperStyle}>
<Icon name="caret-down" />
</div>
);
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment