diff --git a/plugins/examples/change-logo/src/index.tsx b/plugins/examples/change-logo/src/index.tsx index 28ba6544a3d..673c061838a 100644 --- a/plugins/examples/change-logo/src/index.tsx +++ b/plugins/examples/change-logo/src/index.tsx @@ -3,11 +3,20 @@ // import { registerAppLogo } from '@kinvolk/headlamp-plugin/lib'; // registerAppLogo(() =>

My Logo

); -import { AppLogoProps, registerAppLogo } from '@kinvolk/headlamp-plugin/lib'; +import { + AppLogoProps, + registerAppLogo, + registerPluginSettings, +} from '@kinvolk/headlamp-plugin/lib'; +import { ConfigStore } from '@kinvolk/headlamp-plugin/lib'; +import { PluginSettingsDetailProps } from '@kinvolk/headlamp-plugin/lib'; +import { NameValueTable } from '@kinvolk/headlamp-plugin/lib/CommonComponents'; import { SvgIcon } from '@mui/material'; +import Box from '@mui/material/Box'; +import TextField from '@mui/material/TextField'; +import { useEffect, useState } from 'react'; import LogoWithTextLight from './icon-large-light.svg'; import LogoLight from './icon-small-light.svg'; - /** * A simple logo using two different SVG files. * One for the small logo (used in mobile view), and a larger one used in desktop view. @@ -18,7 +27,12 @@ import LogoLight from './icon-small-light.svg'; function SimpleLogo(props: AppLogoProps) { const { logoType, className } = props; - return ( + const useConf = store.useConfig(); + const config = useConf(); + + return config?.url ? ( + logo + ) : ( { + const [value, setValue] = useState(defaultValue); + const [timer, setTimer] = useState(null); + + const handleChange = event => { + const newValue = event.target.value; + setValue(newValue); + + if (timer) { + clearTimeout(timer); + } + + const newTimer = setTimeout(() => onSave(newValue), delay); + setTimer(newTimer); + }; + + useEffect(() => { + return () => { + if (timer) { + clearTimeout(timer); + } + }; + }, [timer]); + + return ( + + ); +}; + +interface pluginConfig { + url: string; +} + +const store = new ConfigStore('change-logo'); + +const Settings: React.FC = () => { + const config = store.get(); + const [currentConfig, setCurrentConfig] = useState(config); + + function handleSave(value) { + const updatedConfig = { url: value }; + store.set(updatedConfig); + setCurrentConfig(store.get()); + } + + const settingsRows = [ + { + name: 'Logo URL', + value: ( + + ), + }, + ]; + + return ( + + + + ); +}; + +registerPluginSettings('change-logo', Settings, true);