1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

fix logo file & width parameter handling

This commit is contained in:
checktheroads
2020-03-25 11:23:45 -07:00
parent d0451fd7af
commit 33dc790137
6 changed files with 28 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
"""Validate branding configuration variables."""
# Standard Library
from typing import Optional
from typing import Optional, Union
# Third Party
from pydantic import (
@@ -92,8 +92,8 @@ class Logo(HyperglassLevel3):
light: StrictStr = "images/hyperglass-light.png"
dark: StrictStr = "images/hyperglass-dark.png"
width: StrictInt = 384
height: Optional[StrictInt]
width: Optional[Union[StrictInt, constr(regex=r"^([1-9][0-9]?|100)\%$")]] = "80%"
height: Optional[Union[StrictInt, constr(regex=r"^([1-9][0-9]?|100)\%$")]]
favicons: StrictStr = "ui/images/favicons/"
@validator("favicons")
@@ -133,7 +133,9 @@ class Terms(HyperglassLevel3):
class Text(HyperglassLevel3):
"""Validation model for params.branding.text."""
title_mode: constr(regex=("logo_only|text_only|logo_title|all")) = "logo_only"
title_mode: constr(
regex=("logo_only|text_only|logo_title|logo_subtitle|all")
) = "logo_only"
title: StrictStr = "hyperglass"
subtitle: StrictStr = "AS{primary_asn}"
query_location: StrictStr = "Location"
@@ -143,6 +145,13 @@ class Text(HyperglassLevel3):
fqdn_tooltip: StrictStr = "Use {protocol}" # Formatted by Javascript
cache: StrictStr = "Results will be cached for {timeout} {period}."
@validator("title_mode")
def validate_title_mode(cls, value):
"""Set legacy logo_title to logo_subtitle."""
if value == "logo_title":
value = "logo_subtitle"
return value
class ThemeColors(HyperglassLevel4):
"""Validation model for theme colors."""

View File

@@ -4,7 +4,7 @@ import sys
from datetime import datetime
__name__ = "hyperglass"
__version__ = "1.0.0-beta.12"
__version__ = "1.0.0-beta.13"
__author__ = "Matt Love"
__copyright__ = f"Copyright {datetime.now().year} Matthew Love"
__license__ = "BSD 3-Clause Clear License"

View File

@@ -46,10 +46,10 @@ const Logo = ({ text, logo }) => {
const { colorMode } = useColorMode();
const logoColor = { light: logo.dark, dark: logo.light };
const logoPath = logoColor[colorMode];
return <Image src={logoPath} alt={text.title} />;
return <Image src={logoPath} alt={text.title} width={logo.width ?? "auto"} />;
};
const LogoTitle = ({ text, logo, showSubtitle }) => (
const LogoSubtitle = ({ text, logo, showSubtitle }) => (
<>
<Logo text={text} logo={logo} />
<AnimatePresence>
@@ -67,11 +67,11 @@ const All = ({ text, logo, mediaSize, showSubtitle }) => (
</>
);
const modeMap = { text_only: TextOnly, logo_only: Logo, logo_title: LogoTitle, all: All };
const modeMap = { text_only: TextOnly, logo_only: Logo, logo_subtitle: LogoSubtitle, all: All };
const widthMap = {
text_only: "100%",
logo_only: ["90%", "90%", "25%", "25%"],
logo_title: ["90%", "90%", "25%", "25%"],
logo_subtitle: ["90%", "90%", "25%", "25%"],
all: ["90%", "90%", "25%", "25%"]
};