mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 23:55:47 -06:00
Use TS instead of JS to store theme variables@next
This commit is contained in:
parent
71576a634e
commit
7e03913d0d
@ -1,5 +1,6 @@
|
||||
const defaultTheme = require('./default');
|
||||
const tinycolor = require('tinycolor2');
|
||||
import tinycolor from 'tinycolor2';
|
||||
import defaultTheme from './default';
|
||||
import { GrafanaTheme, GrafanaThemeType } from '../types/theme';
|
||||
|
||||
const basicColors = {
|
||||
black: '#000000',
|
||||
@ -29,9 +30,9 @@ const basicColors = {
|
||||
orange: '#eb7b18',
|
||||
};
|
||||
|
||||
const darkTheme = {
|
||||
const darkTheme: GrafanaTheme = {
|
||||
...defaultTheme,
|
||||
type: 'dark',
|
||||
type: GrafanaThemeType.Dark,
|
||||
name: 'Grafana Dark',
|
||||
colors: {
|
||||
...basicColors,
|
||||
@ -65,4 +66,4 @@ const darkTheme = {
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = darkTheme;
|
||||
export default darkTheme;
|
@ -59,4 +59,4 @@ const theme = {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = theme;
|
||||
export default theme;
|
4
packages/grafana-ui/src/themes/index.d.ts
vendored
4
packages/grafana-ui/src/themes/index.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
import { GrafanaTheme } from "../types";
|
||||
|
||||
export function getTheme(themeName?: string): GrafanaTheme
|
||||
export function mockTheme(themeMock: (name: string) => object): () => void
|
@ -1,16 +0,0 @@
|
||||
const darkTheme = require('./dark');
|
||||
const lightTheme = require('./light');
|
||||
|
||||
let mockedTheme;
|
||||
|
||||
let getTheme = name => (mockedTheme && mockedTheme(name)) || (name === 'light' ? lightTheme : darkTheme);
|
||||
|
||||
const mockTheme = mock => {
|
||||
mockedTheme = mock;
|
||||
return () => (mockedTheme = null);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getTheme,
|
||||
mockTheme,
|
||||
};
|
14
packages/grafana-ui/src/themes/index.ts
Normal file
14
packages/grafana-ui/src/themes/index.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import darkTheme from './dark';
|
||||
import lightTheme from './light';
|
||||
import { GrafanaTheme } from '../types/theme';
|
||||
|
||||
let themeMock: ((name?: string) => GrafanaTheme) | null;
|
||||
|
||||
export let getTheme = (name?: string) => (themeMock && themeMock(name)) || (name === 'light' ? lightTheme : darkTheme);
|
||||
|
||||
export const mockTheme = (mock: (name: string) => GrafanaTheme) => {
|
||||
themeMock = mock;
|
||||
return () => {
|
||||
themeMock = null;
|
||||
};
|
||||
};
|
@ -1,7 +1,6 @@
|
||||
// import { GrafanaThemeType } from "../theme";
|
||||
|
||||
const defaultTheme = require('./default');
|
||||
const tinycolor = require('tinycolor2');
|
||||
import tinycolor from 'tinycolor2';
|
||||
import defaultTheme from './default';
|
||||
import { GrafanaTheme, GrafanaThemeType } from '../types/theme';
|
||||
|
||||
const basicColors = {
|
||||
black: '#000000',
|
||||
@ -31,11 +30,11 @@ const basicColors = {
|
||||
orange: '#ff7941',
|
||||
};
|
||||
|
||||
const lightTheme/*: GrafanaThemeType*/ = {
|
||||
const lightTheme: GrafanaTheme = {
|
||||
...defaultTheme,
|
||||
type: 'light',
|
||||
type: GrafanaThemeType.Light,
|
||||
name: 'Grafana Light',
|
||||
colors: {
|
||||
colors: {
|
||||
...basicColors,
|
||||
variable: basicColors.blue,
|
||||
inputBlack: '#09090b',
|
||||
@ -65,7 +64,7 @@ const lightTheme/*: GrafanaThemeType*/ = {
|
||||
dropdown: basicColors.white,
|
||||
scrollbar: basicColors.gray5,
|
||||
scrollbar2: basicColors.gray5,
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = lightTheme;
|
||||
export default lightTheme;
|
@ -17,6 +17,7 @@ const darkThemeMock = {
|
||||
};
|
||||
|
||||
describe('Theme variable variant selector', () => {
|
||||
// @ts-ignore
|
||||
const restoreTheme = mockTheme(name => (name === GrafanaThemeType.Light ? lightThemeMock : darkThemeMock));
|
||||
|
||||
afterAll(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user