From da1e39cfd67364da16fe5d2213fa27f3a600d8df Mon Sep 17 00:00:00 2001 From: checktheroads Date: Mon, 19 Oct 2020 08:17:10 -0700 Subject: [PATCH] continue typescript & chakra-ui 1.0 migrations --- .../Footer/{Footer.js => Footer.tsx} | 49 +++++++-------- .../ui/components/Footer/FooterButton.js | 26 -------- .../ui/components/Footer/FooterButton.tsx | 32 ++++++++++ .../ui/components/Footer/FooterContent.js | 27 -------- .../ui/components/Footer/FooterContent.tsx | 27 ++++++++ .../components/Footer/{index.mjs => index.ts} | 0 hyperglass/ui/components/Footer/types.ts | 17 +++++ .../ui/components/Markdown/MDComponents.js | 60 ------------------ .../ui/components/Markdown/MDComponents.tsx | 63 +++++++++++++++++++ hyperglass/ui/components/Markdown/MDTable.js | 24 ------- hyperglass/ui/components/Markdown/MDTable.tsx | 29 +++++++++ .../Markdown/{Markdown.js => Markdown.tsx} | 9 +-- .../Markdown/{index.mjs => index.ts} | 0 hyperglass/ui/components/Markdown/types.ts | 24 +++++++ .../ui/components/{index.mjs => index.ts} | 1 + hyperglass/ui/components/withAnimation.ts | 5 ++ hyperglass/ui/globals.d.ts | 9 ++- hyperglass/ui/package.json | 1 + hyperglass/ui/yarn.lock | 5 ++ 19 files changed, 240 insertions(+), 168 deletions(-) rename hyperglass/ui/components/Footer/{Footer.js => Footer.tsx} (73%) delete mode 100644 hyperglass/ui/components/Footer/FooterButton.js create mode 100644 hyperglass/ui/components/Footer/FooterButton.tsx delete mode 100644 hyperglass/ui/components/Footer/FooterContent.js create mode 100644 hyperglass/ui/components/Footer/FooterContent.tsx rename hyperglass/ui/components/Footer/{index.mjs => index.ts} (100%) create mode 100644 hyperglass/ui/components/Footer/types.ts delete mode 100644 hyperglass/ui/components/Markdown/MDComponents.js create mode 100644 hyperglass/ui/components/Markdown/MDComponents.tsx delete mode 100644 hyperglass/ui/components/Markdown/MDTable.js create mode 100644 hyperglass/ui/components/Markdown/MDTable.tsx rename hyperglass/ui/components/Markdown/{Markdown.js => Markdown.tsx} (72%) rename hyperglass/ui/components/Markdown/{index.mjs => index.ts} (100%) create mode 100644 hyperglass/ui/components/Markdown/types.ts rename hyperglass/ui/components/{index.mjs => index.ts} (96%) create mode 100644 hyperglass/ui/components/withAnimation.ts 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 ( + +