;
+
+// Use Grafana Dark theme by default
+export const ThemeContext = React.createContext(getTheme(GrafanaThemeType.Dark));
+
+export const withTheme = (Component: React.ComponentType
) => {
+ const WithTheme: React.FunctionComponent> = props => {
+ // @ts-ignore
+ return {theme => };
+ };
+
+ WithTheme.displayName = `WithTheme(${Component.displayName})`;
+
+ return WithTheme;
+};
diff --git a/packages/grafana-ui/src/themes/dark.js b/packages/grafana-ui/src/themes/dark.js
index c80a4593f53..3031018bd56 100644
--- a/packages/grafana-ui/src/themes/dark.js
+++ b/packages/grafana-ui/src/themes/dark.js
@@ -4,7 +4,7 @@ const defaultTheme = require('./default');
const tinycolor = require('tinycolor2');
const basicColors = {
- black: '#00ff00',
+ black: '#000000',
white: '#ffffff',
dark1: '#141414',
dark2: '#1f1f20',
@@ -33,6 +33,7 @@ const basicColors = {
const darkTheme = {
...defaultTheme,
+ type: 'dark',
name: 'Grafana Dark',
colors: {
...basicColors,
diff --git a/packages/grafana-ui/src/themes/index.d.ts b/packages/grafana-ui/src/themes/index.d.ts
new file mode 100644
index 00000000000..304c478b46e
--- /dev/null
+++ b/packages/grafana-ui/src/themes/index.d.ts
@@ -0,0 +1,4 @@
+import { GrafanaTheme } from "../types";
+
+export function getTheme(themeName?: string): GrafanaTheme
+export function mockTheme(themeMock: Partial): () => void
diff --git a/packages/grafana-ui/src/theme.js b/packages/grafana-ui/src/themes/index.js
similarity index 70%
rename from packages/grafana-ui/src/theme.js
rename to packages/grafana-ui/src/themes/index.js
index 3d0695e2490..c88cf137574 100644
--- a/packages/grafana-ui/src/theme.js
+++ b/packages/grafana-ui/src/themes/index.js
@@ -1,5 +1,5 @@
-const darkTheme = require('./themes/dark');
-const lightTheme = require('./themes/light');
+const darkTheme = require('./dark');
+const lightTheme = require('./light');
const getTheme = name => (name === 'light' ? lightTheme : darkTheme);
@@ -11,5 +11,5 @@ const mockTheme = mock => {
module.exports = {
getTheme,
- mockTheme,
+ mockTheme
};
diff --git a/packages/grafana-ui/src/themes/light.js b/packages/grafana-ui/src/themes/light.js
index 84d1e656baa..de5c79e8319 100644
--- a/packages/grafana-ui/src/themes/light.js
+++ b/packages/grafana-ui/src/themes/light.js
@@ -33,6 +33,7 @@ const basicColors = {
const lightTheme/*: GrafanaThemeType*/ = {
...defaultTheme,
+ type: 'light',
name: 'Grafana Light',
colors: {
...basicColors,
diff --git a/packages/grafana-ui/src/types/index.ts b/packages/grafana-ui/src/types/index.ts
index e23b5e63af8..81bdf741f30 100644
--- a/packages/grafana-ui/src/types/index.ts
+++ b/packages/grafana-ui/src/types/index.ts
@@ -1,14 +1,7 @@
+
export * from './data';
export * from './time';
export * from './panel';
export * from './plugin';
export * from './datasource';
-
-export enum GrafanaTheme {
- Light = 'light',
- Dark = 'dark',
-}
-
-export interface Themeable {
- theme?: GrafanaTheme;
-}
+export * from './theme';
diff --git a/packages/grafana-ui/src/theme.d.ts b/packages/grafana-ui/src/types/theme.ts
similarity index 92%
rename from packages/grafana-ui/src/theme.d.ts
rename to packages/grafana-ui/src/types/theme.ts
index 015bcd16136..0fc81fa24e1 100644
--- a/packages/grafana-ui/src/theme.d.ts
+++ b/packages/grafana-ui/src/types/theme.ts
@@ -1,4 +1,10 @@
-export interface GrafanaThemeType {
+export enum GrafanaThemeType {
+ Light = 'light',
+ Dark = 'dark',
+}
+
+export interface GrafanaTheme {
+ type: GrafanaThemeType;
name: string;
// TODO: not sure if should be a part of theme
brakpoints: {
@@ -112,5 +118,7 @@ export interface GrafanaThemeType {
headingColor: string;
};
}
-export function getTheme(): GrafanaThemeType
-export function mockTheme(themeMock: Partial): () => void
+
+export interface Themeable {
+ theme: GrafanaTheme;
+}
diff --git a/packages/grafana-ui/src/utils/storybook/withTheme.tsx b/packages/grafana-ui/src/utils/storybook/withTheme.tsx
new file mode 100644
index 00000000000..b1a9bca013a
--- /dev/null
+++ b/packages/grafana-ui/src/utils/storybook/withTheme.tsx
@@ -0,0 +1,40 @@
+import React from 'react';
+import { RenderFunction } from '@storybook/react';
+import { ThemeContext } from '../../themes/ThemeContext';
+import { select } from '@storybook/addon-knobs';
+import { getTheme } from '../../themes';
+import { GrafanaThemeType } from '../../types';
+
+const ThemableStory: React.FunctionComponent<{}> = ({ children }) => {
+ const themeKnob = select(
+ 'Theme',
+ {
+ Default: GrafanaThemeType.Dark,
+ Light: GrafanaThemeType.Light,
+ Dark: GrafanaThemeType.Dark,
+ },
+ GrafanaThemeType.Dark
+ );
+
+ return (
+
+ {children}
+
+
+ );
+};
+
+export const renderComponentWithTheme = (component: React.ComponentType, props: any) => {
+ return (
+
+ {theme => {
+ return React.createElement(component, {
+ ...props,
+ theme,
+ });
+ }}
+
+ );
+};
+
+export const withTheme = (story: RenderFunction) => {story()};
diff --git a/scripts/webpack/getThemeVariable.js b/scripts/webpack/getThemeVariable.js
index c0b6bc4ed79..0db0a9842a8 100644
--- a/scripts/webpack/getThemeVariable.js
+++ b/scripts/webpack/getThemeVariable.js
@@ -1,8 +1,8 @@
const sass = require('node-sass');
const sassUtils = require('node-sass-utils')(sass);
-const { getTheme } = require('../../packages/grafana-ui/src/theme');
const { get } = require('lodash');
const tinycolor = require('tinycolor2');
+const { getTheme } = require('@grafana/ui/src/themes');
const units = ['rem', 'em', 'vh', 'vw', 'vmin', 'vmax', 'ex', '%', 'px', 'cm', 'mm', 'in', 'pt', 'pc', 'ch'];
const matchDimension = value => value.match(/[a-zA-Z]+|[0-9]+/g);
@@ -13,12 +13,11 @@ const isHex = value => {
};
const isDimension = value => {
- if( typeof value !== "string") {
+ if (typeof value !== 'string') {
return false;
}
-
const [val, unit] = matchDimension(value);
- return units.indexOf(unit) > -1
+ return units.indexOf(unit) > -1;
};
/**
@@ -40,11 +39,9 @@ function getThemeVariable(variablePath, themeName) {
}
if (isDimension(variable)) {
- const [value, unit] = matchDimension(variable)
-
- const tmp = new sassUtils.SassDimension(parseInt(value,10), unit);
- // debugger
- return sassUtils.castToSass(tmp)
+ const [value, unit] = matchDimension(variable);
+ const dimension = new sassUtils.SassDimension(parseInt(value, 10), unit);
+ return sassUtils.castToSass(dimension);
}
return sassUtils.castToSass(variable);
From 6b1390b972c8e6d5494ed6a3b400ddc89d8fbca9 Mon Sep 17 00:00:00 2001
From: Dominik Prokop
Date: Tue, 5 Feb 2019 17:04:48 +0100
Subject: [PATCH 062/144] Update types and themes usage in components
---
.../components/ColorPicker/ColorPicker.tsx | 12 ++--
.../ColorPicker/ColorPickerPopover.test.tsx | 11 ++--
.../ColorPicker/ColorPickerPopover.tsx | 28 ++++------
.../ColorPicker/NamedColorsGroup.tsx | 9 +--
.../ColorPicker/NamedColorsPalette.test.tsx | 9 +--
.../ColorPicker/SeriesColorPickerPopover.tsx | 5 +-
.../ColorPicker/SpectrumPalette.tsx | 4 +-
.../ColorPicker/SpectrumPalettePointer.tsx | 4 +-
.../src/components/Gauge/Gauge.test.tsx | 2 +
.../grafana-ui/src/components/Gauge/Gauge.tsx | 23 ++++----
.../ThresholdsEditor/ThresholdsEditor.tsx | 55 +++++++++++--------
packages/grafana-ui/src/components/index.ts | 4 +-
.../src/utils/namedColorsPalette.test.ts | 16 +++---
.../src/utils/namedColorsPalette.ts | 14 ++---
public/app/core/angular_wrappers.ts | 4 +-
public/app/core/utils/ConfigProvider.tsx | 19 ++++---
public/app/core/utils/react2angular.ts | 4 +-
public/app/plugins/panel/gauge/GaugePanel.tsx | 7 +--
.../plugins/panel/gauge/GaugePanelOptions.tsx | 28 ++++------
.../panel/graph/Legend/LegendSeriesItem.tsx | 31 ++++-------
.../app/plugins/panel/graph/data_processor.ts | 4 +-
public/app/plugins/panel/graph/graph.ts | 7 ++-
public/app/plugins/panel/graph/module.ts | 4 +-
.../panel/graph/time_region_manager.ts | 8 +--
.../app/plugins/panel/heatmap/color_legend.ts | 4 +-
public/app/plugins/panel/heatmap/rendering.ts | 4 +-
public/app/plugins/panel/singlestat/module.ts | 8 +--
public/app/plugins/panel/table/module.ts | 4 +-
public/app/plugins/panel/table/renderer.ts | 4 +-
public/app/routes/ReactContainer.tsx | 3 +-
30 files changed, 171 insertions(+), 168 deletions(-)
diff --git a/packages/grafana-ui/src/components/ColorPicker/ColorPicker.tsx b/packages/grafana-ui/src/components/ColorPicker/ColorPicker.tsx
index b6cf176a24b..67201727a34 100644
--- a/packages/grafana-ui/src/components/ColorPicker/ColorPicker.tsx
+++ b/packages/grafana-ui/src/components/ColorPicker/ColorPicker.tsx
@@ -2,11 +2,11 @@ import React, { Component, createRef } from 'react';
import PopperController from '../Tooltip/PopperController';
import Popper, { RenderPopperArrowFn } from '../Tooltip/Popper';
import { ColorPickerPopover } from './ColorPickerPopover';
-import { Themeable, GrafanaTheme } from '../../types';
+import { GrafanaThemeType, Themeable } from '../../types';
import { getColorFromHexRgbOrName } from '../../utils/namedColorsPalette';
import { SeriesColorPickerPopover } from './SeriesColorPickerPopover';
import propDeprecationWarning from '../../utils/propDeprecationWarning';
-
+import { withTheme } from '../../themes/ThemeContext';
type ColorPickerChangeHandler = (color: string) => void;
export interface ColorPickerProps extends Themeable {
@@ -57,7 +57,7 @@ export const colorPickerFactory = (
);
};
@@ -95,7 +95,7 @@ export const colorPickerFactory = (