forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmixins.ts
85 lines (74 loc) · 2.85 KB
/
mixins.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { CSSObject } from '@emotion/css';
import tinycolor from 'tinycolor2';
import { GrafanaTheme, GrafanaTheme2 } from '@grafana/data';
export function cardChrome(theme: GrafanaTheme2): string {
return `
background: ${theme.colors.background.secondary};
&:hover {
background: ${hoverColor(theme.colors.background.secondary, theme)};
}
box-shadow: ${theme.components.panel.boxShadow};
border-radius: ${theme.shape.radius.default};
`;
}
export function hoverColor(color: string, theme: GrafanaTheme2): string {
return theme.isDark ? tinycolor(color).brighten(2).toString() : tinycolor(color).darken(2).toString();
}
export function listItem(theme: GrafanaTheme2): string {
return `
background: ${theme.colors.background.secondary};
&:hover {
background: ${hoverColor(theme.colors.background.secondary, theme)};
}
box-shadow: ${theme.components.panel.boxShadow};
border-radius: ${theme.shape.radius.default};
`;
}
export function listItemSelected(theme: GrafanaTheme2): string {
return `
background: ${hoverColor(theme.colors.background.secondary, theme)};
color: ${theme.colors.text.maxContrast};
`;
}
export function mediaUp(breakpoint: string) {
return `only screen and (min-width: ${breakpoint})`;
}
const isGrafanaTheme2 = (theme: GrafanaTheme | GrafanaTheme2): theme is GrafanaTheme2 => theme.hasOwnProperty('v1');
export const focusCss = (theme: GrafanaTheme | GrafanaTheme2) => {
const isTheme2 = isGrafanaTheme2(theme);
const firstColor = isTheme2 ? theme.colors.background.canvas : theme.colors.bodyBg;
const secondColor = isTheme2 ? theme.colors.primary.main : theme.colors.formFocusOutline;
return `
outline: 2px dotted transparent;
outline-offset: 2px;
box-shadow: 0 0 0 2px ${firstColor}, 0 0 0px 4px ${secondColor};
transition-property: outline, outline-offset, box-shadow;
transition-duration: 0.2s;
transition-timing-function: cubic-bezier(0.19, 1, 0.22, 1);`;
};
export function getMouseFocusStyles(theme: GrafanaTheme | GrafanaTheme2): CSSObject {
return {
outline: 'none',
boxShadow: `none`,
};
}
export function getFocusStyles(theme: GrafanaTheme2): CSSObject {
return {
outline: '2px dotted transparent',
outlineOffset: '2px',
boxShadow: `0 0 0 2px ${theme.colors.background.canvas}, 0 0 0px 4px ${theme.colors.primary.main}`,
transitionTimingFunction: `cubic-bezier(0.19, 1, 0.22, 1)`,
transitionDuration: '0.2s',
transitionProperty: 'outline, outline-offset, box-shadow',
};
}
// max-width is set up based on .grafana-tooltip class that's used in dashboard
export const getTooltipContainerStyles = (theme: GrafanaTheme2): CSSObject => ({
overflow: 'hidden',
background: theme.colors.background.secondary,
boxShadow: theme.shadows.z2,
maxWidth: '800px',
padding: theme.spacing(1),
borderRadius: theme.shape.radius.default,
zIndex: theme.zIndex.tooltip,
});