From 7aaf813751a186e1e5bed24cb03de2b6920a1072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 18 Jun 2021 09:09:47 +0200 Subject: [PATCH] ButtonGroup: Support nested buttons within button groups (#35884) * ButtonGroup: Support nested buttons within button groups * removed files * Fixes --- .../src/components/Button/ButtonGroup.tsx | 25 +++++------- .../components/Button/ToolbarButtonRow.tsx | 4 +- .../src/components/Dropdown/ButtonSelect.tsx | 6 +-- .../RefreshPicker/RefreshPicker.tsx | 40 +++++++++---------- .../RefreshPicker/_RefreshPicker.scss | 4 -- packages/grafana-ui/src/components/index.scss | 1 - .../DashNav/DashNavTimeControls.tsx | 17 ++------ 7 files changed, 37 insertions(+), 60 deletions(-) delete mode 100644 packages/grafana-ui/src/components/RefreshPicker/_RefreshPicker.scss diff --git a/packages/grafana-ui/src/components/Button/ButtonGroup.tsx b/packages/grafana-ui/src/components/Button/ButtonGroup.tsx index 62a1484912e..456bb7ab811 100644 --- a/packages/grafana-ui/src/components/Button/ButtonGroup.tsx +++ b/packages/grafana-ui/src/components/Button/ButtonGroup.tsx @@ -23,22 +23,17 @@ const getStyles = (theme: GrafanaTheme2) => ({ wrapper: css` display: flex; - > button { - border-radius: 0; + > .button-group:not(:first-child) > button, + > button:not(:first-child) { + border-top-left-radius: 0; + border-bottom-left-radius: 0; + } + + > .button-group:not(:last-child) > button, + > button:not(:last-child) { + border-top-right-radius: 0; + border-bottom-right-radius: 0; border-right-width: 0; - - &.toolbar-button { - margin-left: 0; - } - - &:last-of-type { - border-radius: 0 ${theme.shape.borderRadius()} ${theme.shape.borderRadius()} 0; - border-right-width: 1px; - } - - &:first-child { - border-radius: ${theme.shape.borderRadius()} 0 0 ${theme.shape.borderRadius()}; - } } `, }); diff --git a/packages/grafana-ui/src/components/Button/ToolbarButtonRow.tsx b/packages/grafana-ui/src/components/Button/ToolbarButtonRow.tsx index 359fb7f1192..eda19387c44 100644 --- a/packages/grafana-ui/src/components/Button/ToolbarButtonRow.tsx +++ b/packages/grafana-ui/src/components/Button/ToolbarButtonRow.tsx @@ -23,8 +23,8 @@ const getStyles = (theme: GrafanaTheme2) => ({ wrapper: css` display: flex; - .button-group, - .toolbar-button { + > .button-group, + > .toolbar-button { margin-left: ${theme.spacing(1)}; &:first-child { diff --git a/packages/grafana-ui/src/components/Dropdown/ButtonSelect.tsx b/packages/grafana-ui/src/components/Dropdown/ButtonSelect.tsx index dcf83f30318..e0d861d1f3c 100644 --- a/packages/grafana-ui/src/components/Dropdown/ButtonSelect.tsx +++ b/packages/grafana-ui/src/components/Dropdown/ButtonSelect.tsx @@ -1,7 +1,7 @@ import React, { useState, HTMLAttributes } from 'react'; import { PopoverContent } from '../Tooltip/Tooltip'; import { GrafanaTheme2, SelectableValue } from '@grafana/data'; -import { ToolbarButtonVariant, ToolbarButton } from '../Button'; +import { ToolbarButtonVariant, ToolbarButton, ButtonGroup } from '../Button'; import { ClickOutsideWrapper } from '../ClickOutsideWrapper/ClickOutsideWrapper'; import { css } from '@emotion/css'; import { useStyles2 } from '../../themes/ThemeContext'; @@ -43,7 +43,7 @@ export const ButtonSelect = React.memo((props: Props) => { }; return ( -
+ (props: Props) => {
)} - + ); }); diff --git a/packages/grafana-ui/src/components/RefreshPicker/RefreshPicker.tsx b/packages/grafana-ui/src/components/RefreshPicker/RefreshPicker.tsx index 228a814dd01..9e26505912f 100644 --- a/packages/grafana-ui/src/components/RefreshPicker/RefreshPicker.tsx +++ b/packages/grafana-ui/src/components/RefreshPicker/RefreshPicker.tsx @@ -65,28 +65,26 @@ export class RefreshPicker extends PureComponent { } return ( -
- - + + {text} + + {!noIntervalPicker && ( + - {text} - - {!noIntervalPicker && ( - - )} - -
+ aria-label={selectors.components.RefreshPicker.intervalButton} + /> + )} + ); } } diff --git a/packages/grafana-ui/src/components/RefreshPicker/_RefreshPicker.scss b/packages/grafana-ui/src/components/RefreshPicker/_RefreshPicker.scss deleted file mode 100644 index bda9cb20101..00000000000 --- a/packages/grafana-ui/src/components/RefreshPicker/_RefreshPicker.scss +++ /dev/null @@ -1,4 +0,0 @@ -.refresh-picker { - position: relative; - margin-left: 10px; -} diff --git a/packages/grafana-ui/src/components/index.scss b/packages/grafana-ui/src/components/index.scss index 9bb5adf1a36..97796ad1188 100644 --- a/packages/grafana-ui/src/components/index.scss +++ b/packages/grafana-ui/src/components/index.scss @@ -1,6 +1,5 @@ @import 'ButtonCascader/ButtonCascader'; @import 'Drawer/Drawer'; -@import 'RefreshPicker/RefreshPicker'; @import 'Forms/Legacy/Select/Select'; @import 'DateTimePickers/TimeOfDayPicker'; @import 'Tooltip/Tooltip'; diff --git a/public/app/features/dashboard/components/DashNav/DashNavTimeControls.tsx b/public/app/features/dashboard/components/DashNav/DashNavTimeControls.tsx index 1a06d0ee475..05dde88b1ae 100644 --- a/public/app/features/dashboard/components/DashNav/DashNavTimeControls.tsx +++ b/public/app/features/dashboard/components/DashNav/DashNavTimeControls.tsx @@ -1,13 +1,12 @@ // Libraries import React, { Component } from 'react'; import { dateMath, TimeRange, TimeZone } from '@grafana/data'; -import { css } from '@emotion/css'; // Types import { DashboardModel } from '../../state'; // Components -import { defaultIntervals, RefreshPicker, stylesFactory } from '@grafana/ui'; +import { defaultIntervals, RefreshPicker, ToolbarButtonRow } from '@grafana/ui'; import { TimePickerWithHistory } from 'app/core/components/TimePicker/TimePickerWithHistory'; // Utils & Services @@ -82,11 +81,10 @@ export class DashNavTimeControls extends Component { const timePickerValue = getTimeSrv().timeRange(); const timeZone = dashboard.getTimezone(); - const styles = getStyles(); const hideIntervalPicker = dashboard.panelInEdit?.isEditing; return ( -
+ { tooltip="Refresh dashboard" noIntervalPicker={hideIntervalPicker} /> -
+ ); } } - -const getStyles = stylesFactory(() => { - return { - container: css` - position: relative; - display: flex; - `, - }; -});