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 ( - - - {children} - - - ); -}); 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 ( + + + + ); +}; diff --git a/hyperglass/ui/components/Footer/FooterContent.js b/hyperglass/ui/components/Footer/FooterContent.js deleted file mode 100644 index c460995..0000000 --- a/hyperglass/ui/components/Footer/FooterContent.js +++ /dev/null @@ -1,27 +0,0 @@ -import * as React from 'react'; -import { forwardRef } from 'react'; -import { Box, Collapse } from '@chakra-ui/core'; -import { Markdown } from 'app/components/Markdown'; - -export const FooterContent = forwardRef( - ({ isOpen = false, content, side = 'left', title, ...props }, ref) => { - return ( - - - - - - ); - }, -); diff --git a/hyperglass/ui/components/Footer/FooterContent.tsx b/hyperglass/ui/components/Footer/FooterContent.tsx new file mode 100644 index 0000000..8d46587 --- /dev/null +++ b/hyperglass/ui/components/Footer/FooterContent.tsx @@ -0,0 +1,27 @@ +import * as React from 'react'; +import { forwardRef } from 'react'; +import { Box, Collapse } from '@chakra-ui/core'; +import { Markdown } from '~/components'; + +import type { IFooterContent } from './types'; + +export const FooterContent = (props: IFooterContent) => { + const { isOpen = false, content, side = 'left', children: _, ...rest } = props; + return ( + + + + + + ); +}; diff --git a/hyperglass/ui/components/Footer/index.mjs b/hyperglass/ui/components/Footer/index.ts similarity index 100% rename from hyperglass/ui/components/Footer/index.mjs rename to hyperglass/ui/components/Footer/index.ts diff --git a/hyperglass/ui/components/Footer/types.ts b/hyperglass/ui/components/Footer/types.ts new file mode 100644 index 0000000..91fa158 --- /dev/null +++ b/hyperglass/ui/components/Footer/types.ts @@ -0,0 +1,17 @@ +import type { FlexProps, ButtonProps, CollapseProps } from '@chakra-ui/core'; + +type TFooterSide = 'left' | 'right'; + +export interface IFooterButton extends ButtonProps { + side: TFooterSide; + href?: string; +} + +export interface IFooterContent extends Omit { + isOpen: boolean; + content: string; + side: TFooterSide; + children?: undefined; +} + +export type TFooterItems = 'help' | 'credit' | 'terms'; diff --git a/hyperglass/ui/components/Markdown/MDComponents.js b/hyperglass/ui/components/Markdown/MDComponents.js deleted file mode 100644 index 183d008..0000000 --- a/hyperglass/ui/components/Markdown/MDComponents.js +++ /dev/null @@ -1,60 +0,0 @@ -import * as React from 'react'; -import { - Checkbox as ChakraCheckbox, - Divider as ChakraDivider, - Code as ChakraCode, - Heading as ChakraHeading, - Link as ChakraLink, - List as ChakraList, - ListItem as ChakraListItem, - Text as ChakraText, -} from '@chakra-ui/core'; - -import { TableCell, TableHeader, Table as ChakraTable } from './MDTable'; - -import { CodeBlock as CustomCodeBlock } from 'app/components'; - -export const Checkbox = ({ checked, children }) => ( - {children} -); - -export const List = ({ ordered, children }) => ( - {children} -); - -export const ListItem = ({ checked, children }) => - checked ? ( - {children} - ) : ( - {children} - ); - -export const Heading = ({ level, children }) => { - const levelMap = { - 1: { as: 'h1', size: 'lg', fontWeight: 'bold' }, - 2: { as: 'h2', size: 'lg', fontWeight: 'normal' }, - 3: { as: 'h3', size: 'lg', fontWeight: 'bold' }, - 4: { as: 'h4', size: 'md', fontWeight: 'normal' }, - 5: { as: 'h5', size: 'md', fontWeight: 'bold' }, - 6: { as: 'h6', size: 'sm', fontWeight: 'bold' }, - }; - return {children}; -}; - -export const Link = ({ children, ...props }) => ( - - {children} - -); - -export const CodeBlock = ({ value }) => {value}; - -export const TableData = ({ isHeader, children, ...props }) => { - const Component = isHeader ? TableHeader : TableCell; - return {children}; -}; - -export const Paragraph = props => ; -export const InlineCode = props => ; -export const Divider = props => ; -export const Table = props => ; diff --git a/hyperglass/ui/components/Markdown/MDComponents.tsx b/hyperglass/ui/components/Markdown/MDComponents.tsx new file mode 100644 index 0000000..ae97cb3 --- /dev/null +++ b/hyperglass/ui/components/Markdown/MDComponents.tsx @@ -0,0 +1,63 @@ +import * as React from 'react'; +import { + Checkbox as ChakraCheckbox, + Divider as ChakraDivider, + Code as ChakraCode, + Heading as ChakraHeading, + Link as ChakraLink, + ListItem as ChakraListItem, + Text as ChakraText, + UnorderedList, + OrderedList, +} from '@chakra-ui/core'; + +import { TableCell, TableHeader, Table as ChakraTable } from './MDTable'; + +import { CodeBlock as CustomCodeBlock } from '~/components'; + +import type { BoxProps, TextProps, CodeProps, DividerProps, LinkProps } from '@chakra-ui/core'; +import type { ICheckbox, IList, IHeading, ICodeBlock, ITableData } from './types'; + +export const Checkbox = (props: ICheckbox) => { + const { checked, ...rest } = props; + return ; +}; + +export const List = (props: IList) => { + const { ordered, ...rest } = props; + const Component = ordered ? OrderedList : UnorderedList; + return ; +}; + +export const ListItem = (props: ICheckbox) => { + const { checked, ...rest } = props; + return checked ? : ; +}; + +export const Heading = (props: IHeading) => { + const { level, ...rest } = props; + const levelMap = { + 1: { as: 'h1', size: 'lg', fontWeight: 'bold' }, + 2: { as: 'h2', size: 'lg', fontWeight: 'normal' }, + 3: { as: 'h3', size: 'lg', fontWeight: 'bold' }, + 4: { as: 'h4', size: 'md', fontWeight: 'normal' }, + 5: { as: 'h5', size: 'md', fontWeight: 'bold' }, + 6: { as: 'h6', size: 'sm', fontWeight: 'bold' }, + }; + return ; +}; + +export const Link = (props: LinkProps) => ; + +export const CodeBlock = (props: ICodeBlock) => {props.value}; + +export const TableData = (props: ITableData) => { + const { isHeader, ...rest } = props; + const Component = isHeader ? TableHeader : TableCell; + return ; +}; + +export const Paragraph = (props: TextProps) => ; +export const InlineCode = (props: CodeProps) => ; +export const Divider = (props: DividerProps) => ; +export const Table = (props: BoxProps) => ; diff --git a/hyperglass/ui/components/Markdown/MDTable.js b/hyperglass/ui/components/Markdown/MDTable.js deleted file mode 100644 index 84749a0..0000000 --- a/hyperglass/ui/components/Markdown/MDTable.js +++ /dev/null @@ -1,24 +0,0 @@ -import * as React from 'react'; -import { Box, useColorMode } from '@chakra-ui/core'; - -export const Table = props => ; - -const bg = { light: 'blackAlpha.50', dark: 'whiteAlpha.50' }; - -export const TableHeader = props => { - const { colorMode } = useColorMode(); - - return ; -}; - -export const TableCell = ({ isHeader = false, ...props }) => ( - -); diff --git a/hyperglass/ui/components/Markdown/MDTable.tsx b/hyperglass/ui/components/Markdown/MDTable.tsx new file mode 100644 index 0000000..ad025b8 --- /dev/null +++ b/hyperglass/ui/components/Markdown/MDTable.tsx @@ -0,0 +1,29 @@ +import * as React from 'react'; +import { Box } from '@chakra-ui/core'; +import { useColorValue } from '~/context'; +import type { BoxProps } from '@chakra-ui/core'; +import type { ITableData } from './types'; + +export const Table = (props: BoxProps) => ( + +); + +export const TableHeader = (props: BoxProps) => { + const bg = useColorValue('blackAlpha.50', 'whiteAlpha.50'); + return ; +}; + +export const TableCell = (props: ITableData) => { + const { isHeader = false, ...rest } = props; + return ( + + ); +}; diff --git a/hyperglass/ui/components/Markdown/Markdown.js b/hyperglass/ui/components/Markdown/Markdown.tsx similarity index 72% rename from hyperglass/ui/components/Markdown/Markdown.js rename to hyperglass/ui/components/Markdown/Markdown.tsx index 63c49a9..a4f413f 100644 --- a/hyperglass/ui/components/Markdown/Markdown.js +++ b/hyperglass/ui/components/Markdown/Markdown.tsx @@ -1,5 +1,4 @@ import * as React from 'react'; -import { forwardRef } from 'react'; import ReactMarkdown from 'react-markdown'; import { List, @@ -14,6 +13,8 @@ import { Table, } from './MDComponents'; +import type { IMarkdown } from './types'; + const mdComponents = { paragraph: Paragraph, link: Link, @@ -27,6 +28,6 @@ const mdComponents = { tableCell: TableData, }; -export const Markdown = forwardRef(({ content }, ref) => ( - -)); +export const Markdown = (props: IMarkdown) => ( + +); diff --git a/hyperglass/ui/components/Markdown/index.mjs b/hyperglass/ui/components/Markdown/index.ts similarity index 100% rename from hyperglass/ui/components/Markdown/index.mjs rename to hyperglass/ui/components/Markdown/index.ts diff --git a/hyperglass/ui/components/Markdown/types.ts b/hyperglass/ui/components/Markdown/types.ts new file mode 100644 index 0000000..ebec2ff --- /dev/null +++ b/hyperglass/ui/components/Markdown/types.ts @@ -0,0 +1,24 @@ +import type { ReactNode } from 'react'; +import type { BoxProps, CheckboxProps, HeadingProps } from '@chakra-ui/core'; +export interface IMarkdown { + content: string; +} +export interface ICheckbox extends CheckboxProps { + checked: boolean; +} + +export interface IList { + ordered: boolean; + children?: ReactNode; +} +export interface IHeading extends HeadingProps { + level: 1 | 2 | 3 | 4 | 5 | 6; +} + +export interface ICodeBlock { + value: ReactNode; +} + +export interface ITableData extends BoxProps { + isHeader: boolean; +} diff --git a/hyperglass/ui/components/index.mjs b/hyperglass/ui/components/index.ts similarity index 96% rename from hyperglass/ui/components/index.mjs rename to hyperglass/ui/components/index.ts index e8d3498..3715e3e 100644 --- a/hyperglass/ui/components/index.mjs +++ b/hyperglass/ui/components/index.ts @@ -33,3 +33,4 @@ export * from './SubmitButton'; export * from './Table'; export * from './TextOutput'; export * from './Title'; +export * from './withAnimation'; diff --git a/hyperglass/ui/components/withAnimation.ts b/hyperglass/ui/components/withAnimation.ts new file mode 100644 index 0000000..49af599 --- /dev/null +++ b/hyperglass/ui/components/withAnimation.ts @@ -0,0 +1,5 @@ +import { motion } from 'framer-motion'; + +export function withAnimation(Component: React.FunctionComponent) { + return motion.custom>(Component); +} diff --git a/hyperglass/ui/globals.d.ts b/hyperglass/ui/globals.d.ts index 4265de5..ea2c0b8 100644 --- a/hyperglass/ui/globals.d.ts +++ b/hyperglass/ui/globals.d.ts @@ -1 +1,8 @@ -type Dict = { [k: string]: T }; +import type { MotionProps } from 'framer-motion'; + +type Dict = Record; + +type ReactRef = MutableRefObject; + +type Animated = Omit & + Omit & { transition?: MotionProps['transition'] }; diff --git a/hyperglass/ui/package.json b/hyperglass/ui/package.json index 39d5b11..0cbece2 100644 --- a/hyperglass/ui/package.json +++ b/hyperglass/ui/package.json @@ -42,6 +42,7 @@ "devDependencies": { "@types/node": "^14.11.10", "@types/react-select": "^3.0.22", + "@types/string-format": "^2.0.0", "@typescript-eslint/eslint-plugin": "^2.24.0", "@typescript-eslint/parser": "^2.24.0", "@upstatement/eslint-config": "^0.4.3", diff --git a/hyperglass/ui/yarn.lock b/hyperglass/ui/yarn.lock index cf34859..b53e254 100644 --- a/hyperglass/ui/yarn.lock +++ b/hyperglass/ui/yarn.lock @@ -1966,6 +1966,11 @@ "@types/prop-types" "*" csstype "^3.0.2" +"@types/string-format@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@types/string-format/-/string-format-2.0.0.tgz#c1588f507be7b8ef5eb5074a41e48e4538f3f6d5" + integrity sha512-mMwtmgN0ureESnJ3SuMM4W9lsi4CgOxs43YxNo14SDHgzJ+OPYO3yM7nOTJTh8x5YICseBdtrySUbvxnpb+NYQ== + "@types/tinycolor2@1.4.2": version "1.4.2" resolved "https://registry.yarnpkg.com/@types/tinycolor2/-/tinycolor2-1.4.2.tgz#721ca5c5d1a2988b4a886e35c2ffc5735b6afbdf"
(Component: React.FunctionComponent) { + return motion.custom>(Component); +} diff --git a/hyperglass/ui/globals.d.ts b/hyperglass/ui/globals.d.ts index 4265de5..ea2c0b8 100644 --- a/hyperglass/ui/globals.d.ts +++ b/hyperglass/ui/globals.d.ts @@ -1 +1,8 @@ -type Dict = { [k: string]: T }; +import type { MotionProps } from 'framer-motion'; + +type Dict = Record; + +type ReactRef = MutableRefObject; + +type Animated = Omit & + Omit & { transition?: MotionProps['transition'] }; diff --git a/hyperglass/ui/package.json b/hyperglass/ui/package.json index 39d5b11..0cbece2 100644 --- a/hyperglass/ui/package.json +++ b/hyperglass/ui/package.json @@ -42,6 +42,7 @@ "devDependencies": { "@types/node": "^14.11.10", "@types/react-select": "^3.0.22", + "@types/string-format": "^2.0.0", "@typescript-eslint/eslint-plugin": "^2.24.0", "@typescript-eslint/parser": "^2.24.0", "@upstatement/eslint-config": "^0.4.3", diff --git a/hyperglass/ui/yarn.lock b/hyperglass/ui/yarn.lock index cf34859..b53e254 100644 --- a/hyperglass/ui/yarn.lock +++ b/hyperglass/ui/yarn.lock @@ -1966,6 +1966,11 @@ "@types/prop-types" "*" csstype "^3.0.2" +"@types/string-format@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@types/string-format/-/string-format-2.0.0.tgz#c1588f507be7b8ef5eb5074a41e48e4538f3f6d5" + integrity sha512-mMwtmgN0ureESnJ3SuMM4W9lsi4CgOxs43YxNo14SDHgzJ+OPYO3yM7nOTJTh8x5YICseBdtrySUbvxnpb+NYQ== + "@types/tinycolor2@1.4.2": version "1.4.2" resolved "https://registry.yarnpkg.com/@types/tinycolor2/-/tinycolor2-1.4.2.tgz#721ca5c5d1a2988b4a886e35c2ffc5735b6afbdf"