diff --git a/hyperglass/ui/components/ChakraSelect.js b/hyperglass/ui/components/ChakraSelect.js deleted file mode 100644 index c7e013c..0000000 --- a/hyperglass/ui/components/ChakraSelect.js +++ /dev/null @@ -1,190 +0,0 @@ -import * as React from 'react'; -import { Text, useColorMode, useTheme } from '@chakra-ui/core'; -import Select from 'react-select'; -import { opposingColor } from 'app/util'; - -export const ChakraSelect = React.forwardRef( - ({ placeholder = 'Select...', isFullWidth, size, children, ...props }, ref) => { - const theme = useTheme(); - const { colorMode } = useColorMode(); - const sizeMap = { - lg: { height: theme.space[12] }, - md: { height: theme.space[10] }, - sm: { height: theme.space[8] }, - }; - const colorSetPrimaryBg = { - dark: theme.colors.primary[300], - light: theme.colors.primary[500], - }; - const colorSetPrimaryColor = opposingColor(theme, colorSetPrimaryBg[colorMode]); - const bg = { - dark: theme.colors.whiteAlpha[100], - light: theme.colors.white, - }; - const color = { - dark: theme.colors.whiteAlpha[800], - light: theme.colors.black, - }; - const borderFocused = theme.colors.secondary[500]; - const borderDisabled = theme.colors.whiteAlpha[100]; - const border = { - dark: theme.colors.whiteAlpha[50], - light: theme.colors.gray[100], - }; - const borderRadius = theme.space[1]; - const hoverColor = { - dark: theme.colors.whiteAlpha[200], - light: theme.colors.gray[300], - }; - const { height } = sizeMap[size]; - const optionBgActive = { - dark: theme.colors.primary[400], - light: theme.colors.primary[600], - }; - const optionBgColor = opposingColor(theme, optionBgActive[colorMode]); - const optionSelectedBg = { - dark: theme.colors.whiteAlpha[400], - light: theme.colors.blackAlpha[400], - }; - const optionSelectedColor = opposingColor(theme, optionSelectedBg[colorMode]); - const selectedDisabled = theme.colors.whiteAlpha[400]; - const placeholderColor = { - dark: theme.colors.whiteAlpha[700], - light: theme.colors.gray[600], - }; - const menuBg = { - dark: theme.colors.blackFaded[800], - light: theme.colors.whiteFaded[50], - }; - const menuColor = { - dark: theme.colors.white, - light: theme.colors.blackAlpha[800], - }; - const scrollbar = { - dark: theme.colors.whiteAlpha[300], - light: theme.colors.blackAlpha[300], - }; - const scrollbarHover = { - dark: theme.colors.whiteAlpha[400], - light: theme.colors.blackAlpha[400], - }; - const scrollbarBg = { - dark: theme.colors.whiteAlpha[50], - light: theme.colors.blackAlpha[50], - }; - return ( - - ); - }, -); diff --git a/hyperglass/ui/components/HelpModal.js b/hyperglass/ui/components/HelpModal.js deleted file mode 100644 index 9cc6fcf..0000000 --- a/hyperglass/ui/components/HelpModal.js +++ /dev/null @@ -1,66 +0,0 @@ -import * as React from 'react'; -import { - IconButton, - Modal, - ModalOverlay, - ModalContent, - ModalHeader, - ModalBody, - ModalCloseButton, - useDisclosure, - useColorMode, - useTheme, -} from '@chakra-ui/core'; -import { motion, AnimatePresence } from 'framer-motion'; -import { Markdown } from 'app/components'; - -const AnimatedIcon = motion.custom(IconButton); - -export const HelpModal = ({ item, name }) => { - const { isOpen, onOpen, onClose } = useDisclosure(); - const { colors } = useTheme(); - const { colorMode } = useColorMode(); - const bg = { light: 'whiteFaded.50', dark: 'blackFaded.800' }; - const color = { light: 'black', dark: 'white' }; - const iconColor = { - light: colors.primary[500], - dark: colors.primary[300], - }; - return ( - <> - - - - - - - {item.params.title} - - - - - - - - ); -}; diff --git a/hyperglass/ui/components/LookingGlass.js b/hyperglass/ui/components/LookingGlass.js deleted file mode 100644 index 7168fe4..0000000 --- a/hyperglass/ui/components/LookingGlass.js +++ /dev/null @@ -1,46 +0,0 @@ -import * as React from 'react'; -import { motion, AnimatePresence } from 'framer-motion'; -import { Layout, HyperglassForm, Results } from 'app/components'; -import { useHyperglassState } from 'app/context'; - -const AnimatedForm = motion.custom(HyperglassForm); - -export const LookingGlass = () => { - const { - isSubmitting, - setSubmitting, - formData, - setFormData, - greetingAck, - setGreetingAck, - } = useHyperglassState(); - - return ( - - {isSubmitting && formData && ( - - )} - - {!isSubmitting && ( - - )} - - - ); -}; diff --git a/hyperglass/ui/components/QueryLocation.js b/hyperglass/ui/components/QueryLocation.js deleted file mode 100644 index 00fffaf..0000000 --- a/hyperglass/ui/components/QueryLocation.js +++ /dev/null @@ -1,41 +0,0 @@ -import * as React from 'react'; -import { ChakraSelect } from 'app/components'; - -const buildLocations = networks => { - const locations = []; - networks.map(net => { - const netLocations = []; - net.locations.map(loc => { - netLocations.push({ - label: loc.display_name, - value: loc.name, - group: net.display_name, - }); - }); - locations.push({ label: net.display_name, options: netLocations }); - }); - return locations; -}; - -export const QueryLocation = ({ locations, onChange, label }) => { - const options = buildLocations(locations); - const handleChange = e => { - const selected = []; - e && - e.map(sel => { - selected.push(sel.value); - }); - onChange({ field: 'query_location', value: selected }); - }; - return ( - - ); -}; diff --git a/hyperglass/ui/components/Title.js b/hyperglass/ui/components/Title.js deleted file mode 100644 index a1f29a0..0000000 --- a/hyperglass/ui/components/Title.js +++ /dev/null @@ -1,115 +0,0 @@ -/** @jsx jsx */ -import { jsx } from '@emotion/core'; -import { forwardRef } from 'react'; -import { Button, Heading, Image, Stack, useColorMode } from '@chakra-ui/core'; -import { useConfig, useMedia } from 'app/context'; - -const titleSize = { true: ['2xl', '2xl', '5xl', '5xl'], false: '2xl' }; -const titleMargin = { true: 2, false: 0 }; -const textAlignment = { false: ['right', 'center'], true: ['left', 'center'] }; -const logoName = { light: 'dark', dark: 'light' }; -const justifyMap = { - true: ['flex-end', 'center', 'center', 'center'], - false: ['flex-start', 'center', 'center', 'center'], -}; - -const logoFallback = { - light: 'https://res.cloudinary.com/hyperglass/image/upload/v1593916013/logo-dark.svg', - dark: 'https://res.cloudinary.com/hyperglass/image/upload/v1593916013/logo-light.svg', -}; - -const TitleOnly = ({ text, showSubtitle }) => ( - - {text} - -); - -const SubtitleOnly = ({ text, mediaSize, ...props }) => ( - - {text} - -); - -const TextOnly = ({ text, mediaSize, showSubtitle, ...props }) => ( - - - {showSubtitle && } - -); - -const Logo = ({ text, logo }) => { - const { colorMode } = useColorMode(); - const { width, dark_format, light_format } = logo; - const logoExt = { light: dark_format, dark: light_format }; - return ( - {text.title} - ); -}; - -const LogoSubtitle = ({ text, logo, mediaSize }) => ( - <> - - - -); - -const All = ({ text, logo, mediaSize, showSubtitle }) => ( - <> - - - -); - -const modeMap = { - text_only: TextOnly, - logo_only: Logo, - logo_subtitle: LogoSubtitle, - all: All, -}; - -export const Title = forwardRef(({ onClick, isSubmitting, ...props }, ref) => { - const { web } = useConfig(); - const { mediaSize } = useMedia(); - const titleMode = web.text.title_mode; - const MatchedMode = modeMap[titleMode]; - return ( - - ); -}); diff --git a/hyperglass/ui/components/form/queryLocation.tsx b/hyperglass/ui/components/form/queryLocation.tsx new file mode 100644 index 0000000..86287c3 --- /dev/null +++ b/hyperglass/ui/components/form/queryLocation.tsx @@ -0,0 +1,46 @@ +import { useMemo } from 'react'; +import { Select } from '~/components'; + +import type { TNetwork } from '~/types'; +import type { TQueryLocation, OnChangeArgs } from './types'; + +function isOnChangeArgsArray(e: OnChangeArgs | OnChangeArgs[]): e is OnChangeArgs[] { + return Array.isArray(e); +} + +function buildOptions(networks: TNetwork[]) { + return networks.map(net => { + const label = net.display_name; + const options = net.locations.map(loc => ({ + label: loc.display_name, + value: loc.name, + group: net.display_name, + })); + return { label, options }; + }); +} + +export const QueryLocation = (props: TQueryLocation) => { + const { locations, onChange, label } = props; + + const options = useMemo(() => buildOptions(locations), [locations.length]); + + function handleChange(e: OnChangeArgs | OnChangeArgs[]): void { + if (isOnChangeArgsArray(e)) { + const value = e.map(sel => sel.value as string); + onChange({ label: 'query_location', value }); + } + } + + return ( +