From 68700e3d7de19ff3702d6f738fa6610e7de7cbc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 10 Feb 2025 14:12:23 +0100 Subject: [PATCH] TimeRangePicker: Options list padding (#100343) --- .../TimeRangePicker/TimeRangeList.tsx | 11 ++++---- .../TimeRangePicker/TimeRangeOption.tsx | 28 +++++++++++++------ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeList.tsx b/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeList.tsx index cfc070c51c7..1e63f4c1921 100644 --- a/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeList.tsx +++ b/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeList.tsx @@ -1,7 +1,7 @@ import { css } from '@emotion/css'; import { useRef, ReactNode } from 'react'; -import { TimeOption } from '@grafana/data'; +import { GrafanaTheme2, TimeOption } from '@grafana/data'; import { useStyles2 } from '../../../themes'; import { t } from '../../../utils/i18n'; @@ -55,6 +55,7 @@ const Options = ({ options, value, onChange, title }: Props) => { onKeyDown={handleKeys} ref={localRef} aria-roledescription={t('time-picker.time-range.aria-role', 'Time range selection')} + className={styles.list} > {options.map((option, index) => ( { /> ))} -
); }; @@ -91,9 +91,8 @@ const getStyles = () => ({ }), }); -const getOptionsStyles = () => ({ - grow: css({ - flexGrow: 1, - alignItems: 'flex-start', +const getOptionsStyles = (theme: GrafanaTheme2) => ({ + list: css({ + padding: theme.spacing(0.5), }), }); diff --git a/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeOption.tsx b/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeOption.tsx index a85a11f948a..37ee5248792 100644 --- a/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeOption.tsx +++ b/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeOption.tsx @@ -14,27 +14,39 @@ const getStyles = (theme: GrafanaTheme2) => { alignItems: 'center', flexDirection: 'row-reverse', justifyContent: 'space-between', - }), - selected: css({ - background: theme.colors.action.selected, - fontWeight: theme.typography.fontWeightMedium, + position: 'relative', }), radio: css({ opacity: 0, width: '0 !important', - '&:focus-visible + label': getFocusStyles(theme), }), label: css({ cursor: 'pointer', flex: 1, - padding: '7px 9px 7px 9px', + padding: theme.spacing(1), + borderRadius: theme.shape.radius.default, '&:hover': { background: theme.colors.action.hover, cursor: 'pointer', }, }), + labelSelected: css({ + background: theme.colors.action.selected, + + '&::before': { + backgroundImage: theme.colors.gradients.brandVertical, + borderRadius: theme.shape.radius.default, + content: '" "', + display: 'block', + height: '100%', + position: 'absolute', + width: theme.spacing(0.5), + left: 0, + top: 0, + }, + }), }; }; @@ -54,7 +66,7 @@ export const TimeRangeOption = memo(({ value, onSelect, selected = false, const id = uuidv4(); return ( -
  • +
  • (({ value, onSelect, selected = false, id={id} onChange={() => onSelect(value)} /> -