|
911 | 911 | return pageNode |
912 | 912 | } |
913 | 913 |
|
914 | | - function createThemeNode ({ name } = {}) { |
| 914 | + const THEME_PRESETS = { |
| 915 | + version: 1, |
| 916 | + presets: { |
| 917 | + light: { |
| 918 | + colors: { surface: '#fcfcfd', primary: '#0d74ce', bgPage: '#f9f9fb', groupBg: '#ffffff', groupOutline: '#d9d9e0' }, |
| 919 | + sizes: { density: 'default', pagePadding: '12px', groupGap: '12px', groupBorderRadius: '4px', widgetGap: '12px' } |
| 920 | + }, |
| 921 | + dark: { |
| 922 | + colors: { surface: '#18191b', primary: '#0d74ce', bgPage: '#111113', groupBg: '#212225', groupOutline: '#363a3f' }, |
| 923 | + sizes: { density: 'default', pagePadding: '12px', groupGap: '12px', groupBorderRadius: '4px', widgetGap: '12px' } |
| 924 | + }, |
| 925 | + dracula: { |
| 926 | + colors: { surface: '#21222c', primary: '#bd93f9', bgPage: '#282a36', groupBg: '#343746', groupOutline: '#44475a' }, |
| 927 | + sizes: { density: 'default', pagePadding: '12px', groupGap: '12px', groupBorderRadius: '4px', widgetGap: '12px' } |
| 928 | + }, |
| 929 | + nord: { |
| 930 | + colors: { surface: '#3b4252', primary: '#88c0d0', bgPage: '#2e3440', groupBg: '#3b4252', groupOutline: '#4c566a' }, |
| 931 | + sizes: { density: 'default', pagePadding: '12px', groupGap: '12px', groupBorderRadius: '4px', widgetGap: '12px' } |
| 932 | + }, |
| 933 | + sepia: { |
| 934 | + colors: { surface: '#f2e5bc', primary: '#af3a03', bgPage: '#ebdbb2', groupBg: '#fbf1c7', groupOutline: '#d5c4a1' }, |
| 935 | + sizes: { density: 'default', pagePadding: '12px', groupGap: '12px', groupBorderRadius: '4px', widgetGap: '12px' } |
| 936 | + } |
| 937 | + } |
| 938 | + } |
| 939 | + window.NRDB_THEME_PRESETS = THEME_PRESETS |
| 940 | + |
| 941 | + let themePreset = Object.keys(THEME_PRESETS.presets)[0] |
| 942 | + |
| 943 | + function createThemeNode ({ name, preset = 'light' } = {}) { |
915 | 944 | if (RED._db2debug) { console.log('dashboard 2: ui_base.html: createThemeNode', name) } |
916 | 945 | const theme = RED.nodes.getType('ui-theme') |
917 | 946 | let themeName = name |
|
932 | 961 | ...mapDefaults(theme.defaults), |
933 | 962 | name: themeName || c_('themes.defaultTheme') |
934 | 963 | } |
| 964 | + const presetDef = THEME_PRESETS.presets[preset] |
| 965 | + if (presetDef) { |
| 966 | + themeNode.colors = { ...presetDef.colors } |
| 967 | + themeNode.sizes = { ...presetDef.sizes } |
| 968 | + } |
935 | 969 | return themeNode |
936 | 970 | } |
937 | 971 |
|
|
1945 | 1979 | // button group |
1946 | 1980 | const buttonGroup = $('<div>', { class: 'nrdb2-sb-list-button-group' }).appendTo(themeHeader) |
1947 | 1981 |
|
1948 | | - // add theme button |
| 1982 | + const presetKeys = Object.keys(THEME_PRESETS.presets) |
| 1983 | + const presetLabel = (k) => c_('themes.presets.' + k) |
| 1984 | + const themePresetButton = $('<a href="#" class="editor-button editor-button-small nr-db-sb-list-header-button"></a>').appendTo(buttonGroup) |
| 1985 | + function renderThemePresetButton () { |
| 1986 | + themePresetButton.text(presetLabel(themePreset) + ' ') |
| 1987 | + $('<i class="fa fa-caret-down"></i>').appendTo(themePresetButton) |
| 1988 | + } |
| 1989 | + renderThemePresetButton() |
| 1990 | + const themePresetTooltip = RED.popover.tooltip(themePresetButton, c_('themes.presetHint')) |
| 1991 | + themePresetButton.click(function (evt) { |
| 1992 | + evt.preventDefault() |
| 1993 | + themePresetTooltip.close(true) |
| 1994 | + RED.popover.menu({ |
| 1995 | + options: presetKeys.map((key) => ({ |
| 1996 | + label: presetLabel(key), |
| 1997 | + onselect: function () { themePreset = key; renderThemePresetButton() } |
| 1998 | + })) |
| 1999 | + }).show({ target: themePresetButton }) |
| 2000 | + }) |
1949 | 2001 | $('<a href="#" class="editor-button editor-button-small nr-db-sb-list-header-button"><i class="fa fa-plus"></i> ' + c_('themes.theme') + '</a>') |
1950 | 2002 | .click(function (evt) { |
1951 | | - themesOL.editableList('addItem') |
1952 | 2003 | evt.preventDefault() |
| 2004 | + const theme = createThemeNode({ preset: themePreset }) |
| 2005 | + addNode(theme) |
| 2006 | + themesOL.editableList('addItem', theme) |
| 2007 | + RED.editor.editConfig('', theme.type, theme.id) |
1953 | 2008 | }) |
1954 | 2009 | .appendTo(buttonGroup) |
1955 | 2010 |
|
|
0 commit comments