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 |
|:------------------------|:-----------:|--------------------------------------------------------------------------------------:|
| 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.color | `#3F51B5` | Header font color |
| 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
{
"serverURL": "http://localhost:8428",
"inputTenantID": "true",
"useTenantID": true,
"headerStyles": {
"background": "#FFFFFF",
"color": "#538DE8"
@ -93,7 +93,7 @@ VMUI can be used to paste into other applications
#### HTML example:
```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}
/>
</div>
{!appModeEnable && (
<div className="vm-server-configurator__input">
<ThemeControl/>
</div>
)}
<div className="vm-server-configurator__footer">
<Button
variant="outlined"

View file

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

View file

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

View file

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

View file

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