From 1cb701c304c1f8c8bb121e84806fb63502bae9db Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Tue, 4 Jun 2024 09:34:38 +0100 Subject: [PATCH] Chore: Move `Switch` SCSS to emotion/angular (#88553) move switch scss to emotion/angular --- .betterer.results | 5 - .../components/Forms/Legacy/Switch/Switch.tsx | 87 ++++++++++- public/sass/_angular.scss | 130 ++++++++++++++++ public/sass/_grafana.scss | 1 - public/sass/components/_switch.scss | 139 ------------------ 5 files changed, 211 insertions(+), 151 deletions(-) delete mode 100644 public/sass/components/_switch.scss diff --git a/.betterer.results b/.betterer.results index 669d6e84e79..e86565d5cf4 100644 --- a/.betterer.results +++ b/.betterer.results @@ -7732,11 +7732,6 @@ exports[`no gf-form usage`] = { [0, 0, 0, "gf-form usage has been deprecated. Use a component from @grafana/ui or custom CSS instead.", "5381"] ], "packages/grafana-ui/src/components/Forms/Legacy/Switch/Switch.tsx:5381": [ - [0, 0, 0, "gf-form usage has been deprecated. Use a component from @grafana/ui or custom CSS instead.", "5381"], - [0, 0, 0, "gf-form usage has been deprecated. Use a component from @grafana/ui or custom CSS instead.", "5381"], - [0, 0, 0, "gf-form usage has been deprecated. Use a component from @grafana/ui or custom CSS instead.", "5381"], - [0, 0, 0, "gf-form usage has been deprecated. Use a component from @grafana/ui or custom CSS instead.", "5381"], - [0, 0, 0, "gf-form usage has been deprecated. Use a component from @grafana/ui or custom CSS instead.", "5381"], [0, 0, 0, "gf-form usage has been deprecated. Use a component from @grafana/ui or custom CSS instead.", "5381"], [0, 0, 0, "gf-form usage has been deprecated. Use a component from @grafana/ui or custom CSS instead.", "5381"], [0, 0, 0, "gf-form usage has been deprecated. Use a component from @grafana/ui or custom CSS instead.", "5381"] diff --git a/packages/grafana-ui/src/components/Forms/Legacy/Switch/Switch.tsx b/packages/grafana-ui/src/components/Forms/Legacy/Switch/Switch.tsx index e5d21915180..c3476f1a560 100644 --- a/packages/grafana-ui/src/components/Forms/Legacy/Switch/Switch.tsx +++ b/packages/grafana-ui/src/components/Forms/Legacy/Switch/Switch.tsx @@ -1,11 +1,16 @@ +import { css, cx } from '@emotion/css'; import { Placement } from '@popperjs/core'; import { uniqueId } from 'lodash'; import React, { PureComponent } from 'react'; +import { GrafanaTheme2 } from '@grafana/data'; + +import { withTheme2 } from '../../../../themes'; +import { Themeable2 } from '../../../../types'; import { Icon } from '../../../Icon/Icon'; import { Tooltip } from '../../../Tooltip/Tooltip'; -export interface Props { +export interface Props extends Themeable2 { label: string; checked: boolean; disabled?: boolean; @@ -23,7 +28,7 @@ export interface State { } /** @deprecated Please use the `Switch` component, {@link https://developers.grafana.com/ui/latest/index.html?path=/story/forms-switch--controlled as seen in Storybook} */ -export class Switch extends PureComponent { +class UnthemedSwitch extends PureComponent { state = { id: uniqueId(), }; @@ -42,17 +47,21 @@ export class Switch extends PureComponent { disabled, transparent, className, + theme, tooltip, tooltipPlacement, } = this.props; + const styles = getStyles(theme); const labelId = this.state.id; const labelClassName = `gf-form-label ${labelClass} ${transparent ? 'gf-form-label--transparent' : ''} pointer`; - const switchClassName = `gf-form-switch ${switchClass} ${transparent ? 'gf-form-switch--transparent' : ''}`; + const switchClassName = cx(styles.switch, switchClass, { + [styles.switchTransparent]: transparent, + }); return ( -
-