diff --git a/hyperglass/ui/components/Footer/Footer.js b/hyperglass/ui/components/Footer/Footer.tsx similarity index 73% rename from hyperglass/ui/components/Footer/Footer.js rename to hyperglass/ui/components/Footer/Footer.tsx index 0d43f53..cda8d8c 100644 --- a/hyperglass/ui/components/Footer/Footer.js +++ b/hyperglass/ui/components/Footer/Footer.tsx @@ -1,26 +1,26 @@ import * as React from 'react'; import { useState } from 'react'; -import { Flex, useColorMode } from '@chakra-ui/core'; +import { Box, Flex } from '@chakra-ui/core'; import { FiCode } from '@meronex/icons/fi'; import { GoLinkExternal } from '@meronex/icons/go'; -import format from 'string-format'; -import { useConfig } from 'app/context'; +import stringFormat from 'string-format'; +import { useConfig, useColorValue } from '~/context'; import { FooterButton } from './FooterButton'; import { FooterContent } from './FooterContent'; -format.extend(String.prototype, {}); - -const footerBg = { light: 'blackAlpha.50', dark: 'whiteAlpha.100' }; -const footerColor = { light: 'black', dark: 'white' }; -const contentBorder = { light: 'blackAlpha.100', dark: 'whiteAlpha.200' }; +import type { TFooterItems } from './types'; export const Footer = () => { const config = useConfig(); - const { colorMode } = useColorMode(); const [helpVisible, showHelp] = useState(false); const [termsVisible, showTerms] = useState(false); const [creditVisible, showCredit] = useState(false); - const handleCollapse = i => { + + const footerBg = useColorValue('blackAlpha.50', 'whiteAlpha.100'); + const footerColor = useColorValue('black', 'white'); + const contentBorder = useColorValue('blackAlpha.100', 'whiteAlpha.200'); + + const handleCollapse = (i: TFooterItems) => { if (i === 'help') { showTerms(false); showCredit(false); @@ -35,18 +35,19 @@ export const Footer = () => { showTerms(!termsVisible); } }; + const extUrl = config.web.external_link.url.includes('{primary_asn}') - ? config.web.external_link.url.format({ primary_asn: config.primary_asn }) + ? stringFormat(config.web.external_link.url, { primary_asn: config.primary_asn }) : config.web.external_link.url || '/'; + return ( <> {config.web.help_menu.enable && ( )} @@ -54,9 +55,8 @@ export const Footer = () => { )} @@ -64,9 +64,8 @@ export const Footer = () => { )} @@ -78,8 +77,8 @@ export const Footer = () => { flexWrap="wrap" textAlign="center" alignItems="center" - bg={footerBg[colorMode]} - color={footerColor[colorMode]} + bg={footerBg} + color={footerColor} justifyContent="space-between"> {config.web.terms.enable && ( { )} {config.web.external_link.enable && ( } size="xs"> {config.web.external_link.title} diff --git a/hyperglass/ui/components/Footer/FooterButton.js b/hyperglass/ui/components/Footer/FooterButton.js deleted file mode 100644 index 68645ab..0000000 --- a/hyperglass/ui/components/Footer/FooterButton.js +++ /dev/null @@ -1,26 +0,0 @@ -import * as React from 'react'; -import { Button, Flex } from '@chakra-ui/core'; -import { motion } from 'framer-motion'; - -const AnimatedFlex = motion.custom(Flex); - -export const FooterButton = React.forwardRef(({ onClick, side, children, ...props }, ref) => { - return ( - - - - ); -}); diff --git a/hyperglass/ui/components/Footer/FooterButton.tsx b/hyperglass/ui/components/Footer/FooterButton.tsx new file mode 100644 index 0000000..eb3fd53 --- /dev/null +++ b/hyperglass/ui/components/Footer/FooterButton.tsx @@ -0,0 +1,32 @@ +import * as React from 'react'; +import { Button, Flex, FlexProps } from '@chakra-ui/core'; +import { withAnimation } from '~/components'; + +import type { IFooterButton } from './types'; + +const AnimatedFlex = withAnimation(Flex); + +export const FooterButton = (props: IFooterButton) => { + const { side, href, ...rest } = props; + + let buttonProps = Object(); + if (typeof href !== 'undefined') { + buttonProps = { href, as: 'a', target: '_blank', rel: 'noopener noreferrer' }; + } + + return ( + +