|
|
|
@ -3,7 +3,7 @@ import { css, cx } from '@emotion/css'; |
|
|
|
|
import uniqueId from 'lodash/uniqueId'; |
|
|
|
|
import { GrafanaTheme, deprecationWarning } from '@grafana/data'; |
|
|
|
|
import { stylesFactory, useTheme } from '../../themes'; |
|
|
|
|
import { focusCss } from '../../themes/mixins'; |
|
|
|
|
import { focusCss, getMouseFocusStyles } from '../../themes/mixins'; |
|
|
|
|
|
|
|
|
|
export interface Props extends Omit<HTMLProps<HTMLInputElement>, 'value'> { |
|
|
|
|
value?: boolean; |
|
|
|
@ -69,15 +69,15 @@ const getSwitchStyles = stylesFactory((theme: GrafanaTheme, transparent?: boolea |
|
|
|
|
position: absolute; |
|
|
|
|
|
|
|
|
|
&:disabled + label { |
|
|
|
|
background: ${theme.colors.formSwitchBgDisabled}; |
|
|
|
|
background: ${theme.v2.palette.action.disabledBackground}; |
|
|
|
|
cursor: not-allowed; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
&:checked + label { |
|
|
|
|
background: ${theme.colors.formSwitchBgActive}; |
|
|
|
|
background: ${theme.v2.palette.primary.main}; |
|
|
|
|
|
|
|
|
|
&:hover { |
|
|
|
|
background: ${theme.colors.formSwitchBgActiveHover}; |
|
|
|
|
background: ${theme.v2.palette.primary.shade}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
&::after { |
|
|
|
@ -85,8 +85,13 @@ const getSwitchStyles = stylesFactory((theme: GrafanaTheme, transparent?: boolea |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
&:focus + label { |
|
|
|
|
${focusCss(theme)}; |
|
|
|
|
&:focus + label, |
|
|
|
|
&:focus-visible + label { |
|
|
|
|
${focusCss(theme)} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
&:focus:not(:focus-visible) + label { |
|
|
|
|
${getMouseFocusStyles(theme.v2)} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -96,11 +101,11 @@ const getSwitchStyles = stylesFactory((theme: GrafanaTheme, transparent?: boolea |
|
|
|
|
cursor: pointer; |
|
|
|
|
border: none; |
|
|
|
|
border-radius: 50px; |
|
|
|
|
background: ${theme.colors.formSwitchBg}; |
|
|
|
|
background: ${theme.v2.palette.secondary.main}; |
|
|
|
|
transition: all 0.3s ease; |
|
|
|
|
|
|
|
|
|
&:hover { |
|
|
|
|
background: ${theme.colors.formSwitchBgHover}; |
|
|
|
|
background: ${theme.v2.palette.secondary.shade}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
&::after { |
|
|
|
@ -110,7 +115,7 @@ const getSwitchStyles = stylesFactory((theme: GrafanaTheme, transparent?: boolea |
|
|
|
|
width: 12px; |
|
|
|
|
height: 12px; |
|
|
|
|
border-radius: 6px; |
|
|
|
|
background: ${theme.colors.formSwitchDot}; |
|
|
|
|
background: ${theme.v2.palette.text.primary}; |
|
|
|
|
top: 50%; |
|
|
|
|
transform: translate3d(2px, -50%, 0); |
|
|
|
|
transition: transform 0.2s cubic-bezier(0.19, 1, 0.22, 1); |
|
|
|
@ -118,13 +123,13 @@ const getSwitchStyles = stylesFactory((theme: GrafanaTheme, transparent?: boolea |
|
|
|
|
} |
|
|
|
|
`,
|
|
|
|
|
inlineContainer: css` |
|
|
|
|
padding: 0 ${theme.spacing.sm}; |
|
|
|
|
height: ${theme.spacing.formInputHeight}px; |
|
|
|
|
padding: ${theme.v2.spacing(0, 1)}; |
|
|
|
|
height: ${theme.v2.spacing(theme.v2.components.height.md)}; |
|
|
|
|
display: flex; |
|
|
|
|
align-items: center; |
|
|
|
|
background: ${transparent ? 'transparent' : theme.colors.formInputBg}; |
|
|
|
|
border: 1px solid ${transparent ? 'transparent' : theme.colors.formInputBorder}; |
|
|
|
|
border-radius: ${theme.border.radius.md}; |
|
|
|
|
background: ${transparent ? 'transparent' : theme.v2.components.form.background}; |
|
|
|
|
border: 1px solid ${transparent ? 'transparent' : theme.v2.components.form.border}; |
|
|
|
|
border-radius: ${theme.v2.shape.borderRadius()}; |
|
|
|
|
`,
|
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|