vmui: set light theme for app mode (#3748)

* fix: set light theme for app mode

* fix: check inputTenantID flag

* fix: rename inputTenantID to useTenantID
This commit is contained in:
Yury Molodov 2023-02-04 04:31:37 +01:00 committed by GitHub
parent 98dc968920
commit e4c04b6dbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 9 deletions

View file

@ -60,7 +60,7 @@ VMUI can be used to paste into other applications
| Name | Default | Description | | Name | Default | Description |
|:------------------------|:-----------:|--------------------------------------------------------------------------------------:| |:------------------------|:-----------:|--------------------------------------------------------------------------------------:|
| serverURL | domain name | Can't be changed from the UI | | serverURL | domain name | Can't be changed from the UI |
| inputTenantID | - | If the flag is present, the "Tenant ID" field is displayed | | useTenantID | - | If the flag is present, the "Tenant ID" select is displayed |
| headerStyles.background | `#FFFFFF` | Header background color | | headerStyles.background | `#FFFFFF` | Header background color |
| headerStyles.color | `#3F51B5` | Header font color | | headerStyles.color | `#3F51B5` | Header font color |
| palette.primary | `#3F51B5` | used to represent primary interface elements for a user | | palette.primary | `#3F51B5` | used to represent primary interface elements for a user |
@ -74,7 +74,7 @@ VMUI can be used to paste into other applications
```json ```json
{ {
"serverURL": "http://localhost:8428", "serverURL": "http://localhost:8428",
"inputTenantID": "true", "useTenantID": true,
"headerStyles": { "headerStyles": {
"background": "#FFFFFF", "background": "#FFFFFF",
"color": "#538DE8" "color": "#538DE8"
@ -93,7 +93,7 @@ VMUI can be used to paste into other applications
#### HTML example: #### HTML example:
```html ```html
<div id="root" data-params='{"serverURL":"http://localhost:8428","inputTenantID":"true","headerStyles":{"background":"#FFFFFF","color":"#538DE8"},"palette":{"primary":"#538DE8","secondary":"#F76F8E","error":"#FD151B","warning":"#FFB30F","success":"#7BE622","info":"#0F5BFF"}}'></div> <div id="root" data-params='{"serverURL":"http://localhost:8428","useTenantID":true,"headerStyles":{"background":"#FFFFFF","color":"#538DE8"},"palette":{"primary":"#538DE8","secondary":"#F76F8E","error":"#FD151B","warning":"#FFB30F","success":"#7BE622","info":"#0F5BFF"}}'></div>
``` ```

View file

@ -100,9 +100,11 @@ const GlobalSettings: FC<{showTitle?: boolean}> = ({ showTitle }) => {
onChange={setTimezone} onChange={setTimezone}
/> />
</div> </div>
<div className="vm-server-configurator__input"> {!appModeEnable && (
<ThemeControl/> <div className="vm-server-configurator__input">
</div> <ThemeControl/>
</div>
)}
<div className="vm-server-configurator__footer"> <div className="vm-server-configurator__footer">
<Button <Button
variant="outlined" variant="outlined"

View file

@ -2,8 +2,10 @@ import { useAppState } from "../../../../../state/common/StateContext";
import { useEffect, useMemo, useState } from "preact/compat"; import { useEffect, useMemo, useState } from "preact/compat";
import { ErrorTypes } from "../../../../../types"; import { ErrorTypes } from "../../../../../types";
import { getAccountIds } from "../../../../../api/accountId"; import { getAccountIds } from "../../../../../api/accountId";
import { getAppModeParams } from "../../../../../utils/app-mode";
export const useFetchAccountIds = () => { export const useFetchAccountIds = () => {
const { useTenantID } = getAppModeParams();
const { serverUrl } = useAppState(); const { serverUrl } = useAppState();
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
@ -13,6 +15,7 @@ export const useFetchAccountIds = () => {
const fetchUrl = useMemo(() => getAccountIds(serverUrl), [serverUrl]); const fetchUrl = useMemo(() => getAccountIds(serverUrl), [serverUrl]);
useEffect(() => { useEffect(() => {
if (!useTenantID) return;
const fetchData = async () => { const fetchData = async () => {
setIsLoading(true); setIsLoading(true);
try { try {

View file

@ -102,6 +102,7 @@ const NavSubItem: FC<NavItemProps> = ({
activeMenu={activeMenu} activeMenu={activeMenu}
value={sm.value} value={sm.value}
label={sm.label || ""} label={sm.label || ""}
color={color}
/> />
))} ))}
</div> </div>

View file

@ -1,7 +1,7 @@
import { FC, useEffect, useState } from "preact/compat"; import { FC, useEffect, useState } from "preact/compat";
import { getContrastColor } from "../../../utils/color"; import { getContrastColor } from "../../../utils/color";
import { getCssVariable, isSystemDark, setCssVariable } from "../../../utils/theme"; import { getCssVariable, isSystemDark, setCssVariable } from "../../../utils/theme";
import { AppParams, getAppModeParams } from "../../../utils/app-mode"; import { AppParams, getAppModeEnable, getAppModeParams } from "../../../utils/app-mode";
import { getFromStorage } from "../../../utils/storage"; import { getFromStorage } from "../../../utils/storage";
import { darkPalette, lightPalette } from "../../../constants/palette"; import { darkPalette, lightPalette } from "../../../constants/palette";
import { Theme } from "../../../types"; import { Theme } from "../../../types";
@ -23,6 +23,7 @@ const colorVariables = [
export const ThemeProvider: FC<ThemeProviderProps> = ({ onLoaded }) => { export const ThemeProvider: FC<ThemeProviderProps> = ({ onLoaded }) => {
const appModeEnable = getAppModeEnable();
const { palette: paletteAppMode = {} } = getAppModeParams(); const { palette: paletteAppMode = {} } = getAppModeParams();
const { theme } = useAppState(); const { theme } = useAppState();
const isDarkTheme = useSystemTheme(); const isDarkTheme = useSystemTheme();
@ -71,6 +72,8 @@ export const ThemeProvider: FC<ThemeProviderProps> = ({ onLoaded }) => {
setCssVariable(variable, value); setCssVariable(variable, value);
}); });
setContrastText(); setContrastText();
if (appModeEnable) setAppModePalette();
}; };
const updatePalette = () => { const updatePalette = () => {
@ -86,13 +89,18 @@ export const ThemeProvider: FC<ThemeProviderProps> = ({ onLoaded }) => {
}; };
useEffect(() => { useEffect(() => {
setAppModePalette();
setScrollbarSize(); setScrollbarSize();
setTheme(); setTheme();
}, [palette]); }, [palette]);
useEffect(updatePalette, [theme, isDarkTheme]); useEffect(updatePalette, [theme, isDarkTheme]);
useEffect(() => {
if (appModeEnable) {
dispatch({ type: "SET_THEME", payload: Theme.light });
}
}, []);
return null; return null;
}; };

View file

@ -1,6 +1,6 @@
export interface AppParams { export interface AppParams {
serverURL?: string serverURL?: string
inputTenantID?: boolean useTenantID?: boolean
headerStyles?: { headerStyles?: {
background?: string background?: string
color?: string color?: string