diff --git a/packages/grafana-ui/src/components/TimePicker/TimeRangeInput.tsx b/packages/grafana-ui/src/components/TimePicker/TimeRangeInput.tsx index ea0f11be01a..a291852ab21 100644 --- a/packages/grafana-ui/src/components/TimePicker/TimeRangeInput.tsx +++ b/packages/grafana-ui/src/components/TimePicker/TimeRangeInput.tsx @@ -93,6 +93,7 @@ export const TimeRangeInput: FC = ({ onChangeTimeZone={onChangeTimeZone || noop} className={styles.content} hideTimeZone={hideTimeZone} + isReversed /> )} diff --git a/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimePickerCalendar.tsx b/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimePickerCalendar.tsx index 6138bb16445..76bf29ab2f9 100644 --- a/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimePickerCalendar.tsx +++ b/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimePickerCalendar.tsx @@ -9,15 +9,15 @@ import { Icon } from '../../Icon/Icon'; import { Portal } from '../../Portal/Portal'; import { ClickOutsideWrapper } from '../../ClickOutsideWrapper/ClickOutsideWrapper'; -const getStyles = stylesFactory((theme: GrafanaTheme) => { +const getStyles = stylesFactory((theme: GrafanaTheme, isReversed = false) => { const containerBorder = theme.isDark ? theme.palette.dark9 : theme.palette.gray5; return { container: css` top: -1px; position: absolute; - right: 544px; - box-shadow: 0px 0px 20px ${theme.colors.dropdownShadow}; + ${isReversed ? 'left' : 'right'}: 544px; + box-shadow: ${isReversed ? '10px' : '0px'} 0px 20px ${theme.colors.dropdownShadow}; background-color: ${theme.colors.bodyBg}; z-index: -1; border: 1px solid ${containerBorder}; @@ -28,7 +28,7 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => { background-color: ${theme.colors.bodyBg}; width: 19px; height: 100%; - content: ' '; + content: ${!isReversed ? ' ' : ''}; position: absolute; top: 0; right: -19px; @@ -193,13 +193,14 @@ interface Props { onChange: (from: DateTime, to: DateTime) => void; isFullscreen: boolean; timeZone?: TimeZone; + isReversed?: boolean; } const stopPropagation = (event: React.MouseEvent) => event.stopPropagation(); export const TimePickerCalendar = memo(props => { const theme = useTheme(); - const styles = getStyles(theme); + const styles = getStyles(theme, props.isReversed); const { isOpen, isFullscreen } = props; if (!isOpen) { diff --git a/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimePickerContent.tsx b/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimePickerContent.tsx index a533214dc33..3cad5e7de27 100644 --- a/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimePickerContent.tsx +++ b/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimePickerContent.tsx @@ -11,7 +11,7 @@ import { TimeRangeForm } from './TimeRangeForm'; import { TimeRangeList } from './TimeRangeList'; import { TimePickerFooter } from './TimePickerFooter'; -const getStyles = stylesFactory((theme: GrafanaTheme) => { +const getStyles = stylesFactory((theme: GrafanaTheme, isReversed) => { const containerBorder = theme.isDark ? theme.palette.dark9 : theme.palette.gray5; return { @@ -24,7 +24,7 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => { top: 116%; border-radius: 2px; border: 1px solid ${containerBorder}; - right: 0; + right: ${isReversed ? 'unset' : 0}; @media only screen and (max-width: ${theme.breakpoints.lg}) { width: 262px; @@ -37,9 +37,10 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => { leftSide: css` display: flex; flex-direction: column; - border-right: 1px solid ${theme.colors.border1}; + border-right: ${isReversed ? 'none' : `1px solid ${theme.colors.border1}`}; width: 60%; overflow: hidden; + order: ${isReversed ? 1 : 0}; @media only screen and (max-width: ${theme.breakpoints.lg}) { display: none; @@ -47,6 +48,7 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => { `, rightSide: css` width: 40% !important; + border-right: ${isReversed ? `1px solid ${theme.colors.border1}` : 'none'}; @media only screen and (max-width: ${theme.breakpoints.lg}) { width: 100% !important; @@ -131,6 +133,8 @@ interface Props { showHistory?: boolean; className?: string; hideTimeZone?: boolean; + /** Reverse the order of relative and absolute range pickers. Used to left align the picker in forms */ + isReversed?: boolean; } interface PropsWithScreenSize extends Props { @@ -144,7 +148,7 @@ interface FormProps extends Omit { export const TimePickerContentWithScreenSize: React.FC = props => { const theme = useTheme(); - const styles = getStyles(theme); + const styles = getStyles(theme, props.isReversed); const historyOptions = mapToHistoryOptions(props.history, props.timeZone); const { quickOptions = [], otherOptions = [], isFullscreen } = props; @@ -247,7 +251,13 @@ const FullScreenForm: React.FC = props => {
Absolute time range
- + {props.showHistory && (
diff --git a/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimeRangeForm.tsx b/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimeRangeForm.tsx index b53f2fca263..bf8d3a2f9cc 100644 --- a/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimeRangeForm.tsx +++ b/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimeRangeForm.tsx @@ -21,6 +21,7 @@ interface Props { onApply: (range: TimeRange) => void; timeZone?: TimeZone; roundup?: boolean; + isReversed?: boolean; } interface InputState { @@ -121,6 +122,7 @@ export const TimeRangeForm: React.FC = props => { onClose={() => setOpen(false)} onChange={onChange} timeZone={timeZone} + isReversed={props.isReversed} /> ); diff --git a/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/__snapshots__/TimePickerContent.test.tsx.snap b/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/__snapshots__/TimePickerContent.test.tsx.snap index df8ffb04c98..f1083f9824d 100644 --- a/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/__snapshots__/TimePickerContent.test.tsx.snap +++ b/packages/grafana-ui/src/components/TimePicker/TimeRangePicker/__snapshots__/TimePickerContent.test.tsx.snap @@ -8,7 +8,7 @@ exports[`TimePickerContent renders correctly in full screen 1`] = ` className="css-ooqtr4" >
@@ -109,7 +109,7 @@ exports[`TimePickerContent renders correctly in narrow screen 1`] = ` className="css-ooqtr4" >
@@ -206,7 +206,7 @@ exports[`TimePickerContent renders recent absolute ranges correctly 1`] = ` className="css-ooqtr4" >