refactor and restructure ui theme hooks

This commit is contained in:
thatmattlove 2021-12-19 23:30:09 -07:00
parent fe8cd9f356
commit 2dd03ad81d
50 changed files with 138 additions and 158 deletions

View file

@ -3,18 +3,22 @@ import {
Modal, Modal,
HStack, HStack,
Button, Button,
useTheme,
ModalBody, ModalBody,
ModalHeader, ModalHeader,
ModalOverlay, ModalOverlay,
ModalContent, ModalContent,
useColorMode,
useDisclosure, useDisclosure,
ModalCloseButton, ModalCloseButton,
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { useConfig, useColorValue, useBreakpointValue } from '~/context'; import { useConfig } from '~/context';
import { CodeBlock, DynamicIcon } from '~/elements'; import { CodeBlock, DynamicIcon } from '~/elements';
import { useHyperglassConfig } from '~/hooks'; import {
useTheme,
useColorMode,
useColorValue,
useBreakpointValue,
useHyperglassConfig,
} from '~/hooks';
import type { UseDisclosureReturn } from '@chakra-ui/react'; import type { UseDisclosureReturn } from '@chakra-ui/react';

View file

@ -9,8 +9,8 @@ import {
useDisclosure, useDisclosure,
ModalCloseButton, ModalCloseButton,
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { useColorValue } from '~/context';
import { DynamicIcon, Markdown } from '~/elements'; import { DynamicIcon, Markdown } from '~/elements';
import { useColorValue } from '~/hooks';
import type { ModalContentProps } from '@chakra-ui/react'; import type { ModalContentProps } from '@chakra-ui/react';

View file

@ -1,8 +1,8 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import { Button, Menu, MenuButton, MenuList } from '@chakra-ui/react'; import { Button, Menu, MenuButton, MenuList } from '@chakra-ui/react';
import { useColorValue, useBreakpointValue, useConfig } from '~/context'; import { useConfig } from '~/context';
import { Markdown } from '~/elements'; import { Markdown } from '~/elements';
import { useOpposingColor, useStrf } from '~/hooks'; import { useColorValue, useBreakpointValue, useOpposingColor, useStrf } from '~/hooks';
import type { MenuListProps } from '@chakra-ui/react'; import type { MenuListProps } from '@chakra-ui/react';
import type { Config } from '~/types'; import type { Config } from '~/types';

View file

@ -1,9 +1,8 @@
import { forwardRef } from 'react'; import { forwardRef } from 'react';
import { Button, Tooltip } from '@chakra-ui/react'; import { Button, Tooltip } from '@chakra-ui/react';
import { Switch, Case } from 'react-if'; import { Switch, Case } from 'react-if';
import { useColorMode, useColorValue, useBreakpointValue } from '~/context';
import { DynamicIcon } from '~/elements'; import { DynamicIcon } from '~/elements';
import { useOpposingColor } from '~/hooks'; import { useOpposingColor, useColorMode, useColorValue, useBreakpointValue } from '~/hooks';
import type { ButtonProps } from '@chakra-ui/react'; import type { ButtonProps } from '@chakra-ui/react';

View file

@ -1,9 +1,9 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import { Flex, HStack, useToken } from '@chakra-ui/react'; import { Flex, HStack, useToken } from '@chakra-ui/react';
import { If, Then } from 'react-if'; import { If, Then } from 'react-if';
import { useConfig, useMobile, useColorValue, useBreakpointValue } from '~/context'; import { useConfig } from '~/context';
import { DynamicIcon } from '~/elements'; import { DynamicIcon } from '~/elements';
import { useStrf } from '~/hooks'; import { useStrf, useMobile, useColorValue, useBreakpointValue } from '~/hooks';
import { FooterButton } from './button'; import { FooterButton } from './button';
import { ColorModeToggle } from './color-mode'; import { ColorModeToggle } from './color-mode';
import { FooterLink } from './link'; import { FooterLink } from './link';

View file

@ -1,4 +1,5 @@
import { Button, Link, useBreakpointValue } from '@chakra-ui/react'; import { Button, Link } from '@chakra-ui/react';
import { useBreakpointValue } from '~/hooks';
import type { ButtonProps, LinkProps } from '@chakra-ui/react'; import type { ButtonProps, LinkProps } from '@chakra-ui/react';

View file

@ -2,8 +2,7 @@ import { useMemo } from 'react';
import { Flex, FormControl, FormLabel, FormErrorMessage } from '@chakra-ui/react'; import { Flex, FormControl, FormLabel, FormErrorMessage } from '@chakra-ui/react';
import { useFormContext } from 'react-hook-form'; import { useFormContext } from 'react-hook-form';
import { If, Then } from 'react-if'; import { If, Then } from 'react-if';
import { useColorValue } from '~/context'; import { useBooleanValue, useColorValue } from '~/hooks';
import { useBooleanValue } from '~/hooks';
import type { FormControlProps } from '@chakra-ui/react'; import type { FormControlProps } from '@chakra-ui/react';
import type { FieldError } from 'react-hook-form'; import type { FieldError } from 'react-hook-form';

View file

@ -11,8 +11,8 @@ import {
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { If, Then } from 'react-if'; import { If, Then } from 'react-if';
import { Markdown } from '~/elements'; import { Markdown } from '~/elements';
import { useConfig, useColorValue } from '~/context'; import { useConfig } from '~/context';
import { useGreeting, useOpposingColor } from '~/hooks'; import { useGreeting, useColorValue, useOpposingColor } from '~/hooks';
import type { ModalContentProps } from '@chakra-ui/react'; import type { ModalContentProps } from '@chakra-ui/react';

View file

@ -1,7 +1,6 @@
import { Flex, ScaleFade } from '@chakra-ui/react'; import { Flex, ScaleFade } from '@chakra-ui/react';
import { useBreakpointValue } from '~/context';
import { motionChakra } from '~/elements'; import { motionChakra } from '~/elements';
import { useBooleanValue, useFormInteractive } from '~/hooks'; import { useBooleanValue, useFormInteractive, useBreakpointValue } from '~/hooks';
import { Title } from './title'; import { Title } from './title';
const Wrapper = motionChakra('header', { const Wrapper = motionChakra('header', {

View file

@ -1,6 +1,7 @@
import { useCallback, useMemo, useState } from 'react'; import { useCallback, useMemo, useState } from 'react';
import { Image, Skeleton } from '@chakra-ui/react'; import { Image, Skeleton } from '@chakra-ui/react';
import { useColorValue, useConfig } from '~/context'; import { useConfig } from '~/context';
import { useColorValue } from '~/hooks';
import type { ImageProps } from '@chakra-ui/react'; import type { ImageProps } from '@chakra-ui/react';

View file

@ -1,6 +1,7 @@
import { Heading } from '@chakra-ui/react'; import { Heading } from '@chakra-ui/react';
import { useConfig, useBreakpointValue } from '~/context'; import { useConfig } from '~/context';
import { useTitleSize } from './useTitleSize'; import { useBreakpointValue } from '~/hooks';
import { useTitleSize } from './use-title-size';
export const SubtitleOnly = (): JSX.Element => { export const SubtitleOnly = (): JSX.Element => {
const { web } = useConfig(); const { web } = useConfig();

View file

@ -1,7 +1,7 @@
import { Heading } from '@chakra-ui/react'; import { Heading } from '@chakra-ui/react';
import { useConfig } from '~/context'; import { useConfig } from '~/context';
import { useBooleanValue, useFormInteractive } from '~/hooks'; import { useBooleanValue, useFormInteractive } from '~/hooks';
import { useTitleSize } from './useTitleSize'; import { useTitleSize } from './use-title-size';
export const TitleOnly = (): JSX.Element => { export const TitleOnly = (): JSX.Element => {
const { web } = useConfig(); const { web } = useConfig();

View file

@ -2,8 +2,8 @@ import { Flex, Button, VStack } from '@chakra-ui/react';
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import { isSafari } from 'react-device-detect'; import { isSafari } from 'react-device-detect';
import { Switch, Case } from 'react-if'; import { Switch, Case } from 'react-if';
import { useConfig, useMobile } from '~/context'; import { useConfig } from '~/context';
import { useFormState, useFormInteractive } from '~/hooks'; import { useFormState, useFormInteractive, useMobile } from '~/hooks';
import { Logo } from './logo'; import { Logo } from './logo';
import { SubtitleOnly } from './subtitle-only'; import { SubtitleOnly } from './subtitle-only';
import { TitleOnly } from './title-only'; import { TitleOnly } from './title-only';

View file

@ -1,6 +1,6 @@
import { useMemo, useState } from 'react'; import { useMemo, useState } from 'react';
import { useToken } from '@chakra-ui/react'; import { useToken } from '@chakra-ui/react';
import { useMobile } from '~/context'; import { useMobile } from '~/hooks';
// Mobile: // Mobile:
// xs: 32 // xs: 32

View file

@ -1,8 +1,7 @@
import { useMemo, useState } from 'react'; import { useMemo, useState } from 'react';
import { Flex, Box, Avatar, chakra } from '@chakra-ui/react'; import { Flex, Avatar, chakra } from '@chakra-ui/react';
import { motion } from 'framer-motion'; import { motionChakra } from '~/elements';
import { useColorValue } from '~/context'; import { useColorValue, useOpposingColor } from '~/hooks';
import { useOpposingColor } from '~/hooks';
import type { SingleOption } from '~/types'; import type { SingleOption } from '~/types';
import type { LocationOption } from './query-location'; import type { LocationOption } from './query-location';
@ -14,7 +13,21 @@ interface LocationCardProps {
hasError: boolean; hasError: boolean;
} }
const MotionBox = motion(Box); const LocationCardWrapper = motionChakra('div', {
baseStyle: {
py: 4,
px: 6,
w: '100%',
minW: 'xs',
maxW: 'sm',
mx: 'auto',
shadow: 'sm',
rounded: 'lg',
cursor: 'pointer',
borderWidth: '1px',
borderStyle: 'solid',
},
});
export const LocationCard = (props: LocationCardProps): JSX.Element => { export const LocationCard = (props: LocationCardProps): JSX.Element => {
const { option, onChange, defaultChecked, hasError } = props; const { option, onChange, defaultChecked, hasError } = props;
@ -51,20 +64,9 @@ export const LocationCard = (props: LocationCardProps): JSX.Element => {
[hasError, isChecked, checkedBorder, errorBorder], [hasError, isChecked, checkedBorder, errorBorder],
); );
return ( return (
<MotionBox <LocationCardWrapper
py={4}
px={6}
bg={bg} bg={bg}
w="100%"
minW="xs"
maxW="sm"
mx="auto"
shadow="sm"
key={label} key={label}
rounded="lg"
cursor="pointer"
borderWidth="1px"
borderStyle="solid"
whileHover={{ scale: 1.05 }} whileHover={{ scale: 1.05 }}
borderColor={borderColor} borderColor={borderColor}
onClick={(e: React.MouseEvent) => { onClick={(e: React.MouseEvent) => {
@ -101,6 +103,6 @@ export const LocationCard = (props: LocationCardProps): JSX.Element => {
{option.data.description as string} {option.data.description as string}
</chakra.p> </chakra.p>
)} )}
</MotionBox> </LocationCardWrapper>
); );
}; };

View file

@ -1,7 +1,7 @@
import { useEffect, useMemo, useState } from 'react'; import { useEffect, useMemo, useState } from 'react';
import Head from 'next/head'; import Head from 'next/head';
import { useTheme } from '@chakra-ui/react';
import { useConfig } from '~/context'; import { useConfig } from '~/context';
import { useTheme } from '~/hooks';
import { googleFontUrl } from '~/util'; import { googleFontUrl } from '~/util';
export const Meta = (): JSX.Element => { export const Meta = (): JSX.Element => {

View file

@ -4,9 +4,9 @@ import dayjs from 'dayjs';
import relativeTimePlugin from 'dayjs/plugin/relativeTime'; import relativeTimePlugin from 'dayjs/plugin/relativeTime';
import utcPlugin from 'dayjs/plugin/utc'; import utcPlugin from 'dayjs/plugin/utc';
import { If, Then, Else } from 'react-if'; import { If, Then, Else } from 'react-if';
import { useConfig, useColorValue } from '~/context'; import { useConfig } from '~/context';
import { DynamicIcon } from '~/elements'; import { DynamicIcon } from '~/elements';
import { useOpposingColor } from '~/hooks'; import { useOpposingColor, useColorValue } from '~/hooks';
import type { TextProps } from '@chakra-ui/react'; import type { TextProps } from '@chakra-ui/react';

View file

@ -1,5 +1,6 @@
import { Box } from '@chakra-ui/react'; import { Box } from '@chakra-ui/react';
import { useColorValue, useConfig } from '~/context'; import { useConfig } from '~/context';
import { useColorValue } from '~/hooks';
import { Highlighted } from './highlighted'; import { Highlighted } from './highlighted';
import type { BoxProps } from '@chakra-ui/react'; import type { BoxProps } from '@chakra-ui/react';

View file

@ -1,7 +1,7 @@
import { Box, Flex, SkeletonText, Badge, VStack } from '@chakra-ui/react'; import { Box, Flex, SkeletonText, Badge, VStack } from '@chakra-ui/react';
import ReactFlow, { Background, ReactFlowProvider, Handle, Position } from 'react-flow-renderer'; import ReactFlow, { Background, ReactFlowProvider, Handle, Position } from 'react-flow-renderer';
import { useConfig, useColorValue, useColorToken } from '~/context'; import { useConfig } from '~/context';
import { useASNDetail } from '~/hooks'; import { useASNDetail, useColorValue, useColorToken } from '~/hooks';
import { Controls } from './controls'; import { Controls } from './controls';
import { useElements } from './useElements'; import { useElements } from './useElements';

View file

@ -8,8 +8,7 @@ import {
useDisclosure, useDisclosure,
ModalCloseButton, ModalCloseButton,
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { useColorValue, useBreakpointValue } from '~/context'; import { useFormState, useColorValue, useBreakpointValue } from '~/hooks';
import { useFormState } from '~/hooks';
import { PathButton } from './path-button'; import { PathButton } from './path-button';
import { Chart } from './chart'; import { Chart } from './chart';

View file

@ -6,7 +6,7 @@ import {
PopoverContent, PopoverContent,
PopoverCloseButton, PopoverCloseButton,
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { useColorValue } from '~/context'; import { useColorValue } from '~/hooks';
import type { PromptProps } from './types'; import type { PromptProps } from './types';

View file

@ -1,4 +1,4 @@
import { useMobile } from '~/context'; import { useMobile } from '~/hooks';
import { DesktopPrompt } from './desktop'; import { DesktopPrompt } from './desktop';
import { MobilePrompt } from './mobile'; import { MobilePrompt } from './mobile';

View file

@ -1,5 +1,5 @@
import { Modal, ModalBody, ModalOverlay, ModalContent, ModalCloseButton } from '@chakra-ui/react'; import { Modal, ModalBody, ModalOverlay, ModalContent, ModalCloseButton } from '@chakra-ui/react';
import { useColorValue } from '~/context'; import { useColorValue } from '~/hooks';
import type { PromptProps } from './types'; import type { PromptProps } from './types';

View file

@ -4,8 +4,7 @@ import { components } from 'react-select';
import { If, Then, Else } from 'react-if'; import { If, Then, Else } from 'react-if';
import { Select } from '~/components'; import { Select } from '~/components';
import { isSingleValue } from '~/components/select'; import { isSingleValue } from '~/components/select';
import { useColorValue } from '~/context'; import { useColorValue, useDirective, useFormState } from '~/hooks';
import { useDirective, useFormState } from '~/hooks';
import { isSelectDirective } from '~/types'; import { isSelectDirective } from '~/types';
import { UserIP } from './user-ip'; import { UserIP } from './user-ip';

View file

@ -1,8 +1,7 @@
import { Flex, IconButton } from '@chakra-ui/react'; import { Flex, IconButton } from '@chakra-ui/react';
import { AnimatePresence } from 'framer-motion'; import { AnimatePresence } from 'framer-motion';
import { useColorValue } from '~/context';
import { AnimatedDiv, DynamicIcon } from '~/elements'; import { AnimatedDiv, DynamicIcon } from '~/elements';
import { useOpposingColor, useFormState } from '~/hooks'; import { useColorValue, useOpposingColor, useFormState } from '~/hooks';
import type { FlexProps } from '@chakra-ui/react'; import type { FlexProps } from '@chakra-ui/react';

View file

@ -1,8 +1,8 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import { Button, Stack, Text, VStack } from '@chakra-ui/react'; import { Button, Stack, Text, VStack } from '@chakra-ui/react';
import { useConfig, useColorValue } from '~/context'; import { useConfig } from '~/context';
import { DynamicIcon } from '~/elements'; import { DynamicIcon } from '~/elements';
import { useStrf, useDNSQuery, useFormState } from '~/hooks'; import { useStrf, useColorValue, useDNSQuery, useFormState } from '~/hooks';
import type { DnsOverHttps } from '~/types'; import type { DnsOverHttps } from '~/types';

View file

@ -1,8 +1,8 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import { AccordionIcon, Box, Spinner, HStack, Text, Tooltip } from '@chakra-ui/react'; import { AccordionIcon, Box, Spinner, HStack, Text, Tooltip } from '@chakra-ui/react';
import { useConfig, useColorValue } from '~/context'; import { useConfig } from '~/context';
import { DynamicIcon } from '~/elements'; import { DynamicIcon } from '~/elements';
import { useOpposingColor, useStrf } from '~/hooks'; import { useColorValue, useOpposingColor, useStrf } from '~/hooks';
import type { ErrorLevels } from '~/types'; import type { ErrorLevels } from '~/types';

View file

@ -17,9 +17,17 @@ import startCase from 'lodash/startCase';
import isEqual from 'react-fast-compare'; import isEqual from 'react-fast-compare';
import { If, Then, Else } from 'react-if'; import { If, Then, Else } from 'react-if';
import { BGPTable, Path, TextOutput } from '~/components'; import { BGPTable, Path, TextOutput } from '~/components';
import { useColorValue, useConfig, useMobile } from '~/context'; import { useConfig } from '~/context';
import { Countdown, DynamicIcon } from '~/elements'; import { Countdown, DynamicIcon } from '~/elements';
import { useStrf, useLGQuery, useTableToString, useFormState, useDevice } from '~/hooks'; import {
useStrf,
useDevice,
useMobile,
useLGQuery,
useFormState,
useColorValue,
useTableToString,
} from '~/hooks';
import { isStructuredOutput, isStringOutput } from '~/types'; import { isStructuredOutput, isStringOutput } from '~/types';
import { isStackError, isFetchError, isLGError, isLGOutputOrError } from './guards'; import { isStackError, isFetchError, isLGError, isLGOutputOrError } from './guards';
import { RequeryButton } from './requery-button'; import { RequeryButton } from './requery-button';

View file

@ -1,9 +1,9 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import { Box, Stack, useToken } from '@chakra-ui/react'; import { Box, Stack, useToken } from '@chakra-ui/react';
import { motion, AnimatePresence } from 'framer-motion'; import { motion, AnimatePresence } from 'framer-motion';
import { useConfig, useBreakpointValue } from '~/context'; import { useConfig } from '~/context';
import { Label } from '~/elements'; import { Label } from '~/elements';
import { useFormState } from '~/hooks'; import { useFormState, useBreakpointValue } from '~/hooks';
import type { Transition } from 'framer-motion'; import type { Transition } from 'framer-motion';

View file

@ -1,7 +1,7 @@
import { createContext, forwardRef, useContext } from 'react'; import { createContext, forwardRef, useContext } from 'react';
import ReactSelect from 'react-select'; import ReactSelect from 'react-select';
import { useDisclosure } from '@chakra-ui/react'; import { useDisclosure } from '@chakra-ui/react';
import { useColorMode } from '~/context'; import { useColorMode } from '~/hooks';
import { Option } from './option'; import { Option } from './option';
import { import {
useRSTheme, useRSTheme,

View file

@ -3,8 +3,13 @@ import { useCallback } from 'react';
import { useToken } from '@chakra-ui/react'; import { useToken } from '@chakra-ui/react';
import { mergeWith } from '@chakra-ui/utils'; import { mergeWith } from '@chakra-ui/utils';
import { merge } from 'merge-anything'; import { merge } from 'merge-anything';
import { useOpposingColor, useOpposingColorCallback } from '~/hooks'; import {
import { useColorValue, useColorToken, useMobile } from '~/context'; useMobile,
useColorValue,
useColorToken,
useOpposingColor,
useOpposingColorCallback,
} from '~/hooks';
import { useSelectContext } from './select'; import { useSelectContext } from './select';
import * as ReactSelect from 'react-select'; import * as ReactSelect from 'react-select';

View file

@ -16,9 +16,8 @@ import {
import { useFormContext } from 'react-hook-form'; import { useFormContext } from 'react-hook-form';
import { If, Then, Else } from 'react-if'; import { If, Then, Else } from 'react-if';
import { ResolvedTarget } from '~/components'; import { ResolvedTarget } from '~/components';
import { useMobile, useColorValue } from '~/context';
import { DynamicIcon } from '~/elements'; import { DynamicIcon } from '~/elements';
import { useFormState } from '~/hooks'; import { useFormState, useMobile, useColorValue } from '~/hooks';
import type { IconButtonProps } from '@chakra-ui/react'; import type { IconButtonProps } from '@chakra-ui/react';

View file

@ -1,5 +1,5 @@
import { chakra } from '@chakra-ui/react'; import { chakra } from '@chakra-ui/react';
import { useColorValue } from '~/context'; import { useColorValue } from '~/hooks';
import type { BoxProps } from '@chakra-ui/react'; import type { BoxProps } from '@chakra-ui/react';

View file

@ -1,5 +1,5 @@
import { chakra } from '@chakra-ui/react'; import { chakra } from '@chakra-ui/react';
import { useColorValue } from '~/context'; import { useColorValue } from '~/hooks';
import type { BoxProps } from '@chakra-ui/react'; import type { BoxProps } from '@chakra-ui/react';

View file

@ -3,8 +3,8 @@
import { Flex, Text } from '@chakra-ui/react'; import { Flex, Text } from '@chakra-ui/react';
import { usePagination, useSortBy, useTable } from 'react-table'; import { usePagination, useSortBy, useTable } from 'react-table';
import { If, Then, Else } from 'react-if'; import { If, Then, Else } from 'react-if';
import { useMobile } from '~/context';
import { CardBody, CardFooter, CardHeader, DynamicIcon } from '~/elements'; import { CardBody, CardFooter, CardHeader, DynamicIcon } from '~/elements';
import { useMobile } from '~/hooks';
import { TableMain } from './table'; import { TableMain } from './table';
import { TableCell } from './cell'; import { TableCell } from './cell';
import { TableHead } from './head'; import { TableHead } from './head';

View file

@ -1,9 +1,7 @@
import { chakra } from '@chakra-ui/react'; import { chakra } from '@chakra-ui/react';
import { useColorValue } from '~/context'; import { useColorValue, useOpposingColor } from '~/hooks';
import { useOpposingColor } from '~/hooks';
import type { BoxProps } from '@chakra-ui/react'; import type { BoxProps } from '@chakra-ui/react';
import type { Theme } from '~/types'; import type { Theme } from '~/types';
interface TableRowProps extends BoxProps { interface TableRowProps extends BoxProps {

View file

@ -1,5 +1,5 @@
import { chakra } from '@chakra-ui/react'; import { chakra } from '@chakra-ui/react';
import { useColorValue } from '~/context'; import { useColorValue } from '~/hooks';
import type { BoxProps } from '@chakra-ui/react'; import type { BoxProps } from '@chakra-ui/react';

View file

@ -1,9 +1,9 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import { Button, Stack, Text, VStack, useDisclosure } from '@chakra-ui/react'; import { Button, Stack, Text, VStack, useDisclosure } from '@chakra-ui/react';
import { Prompt } from '~/components'; import { Prompt } from '~/components';
import { useConfig, useColorValue } from '~/context'; import { useConfig } from '~/context';
import { DynamicIcon } from '~/elements'; import { DynamicIcon } from '~/elements';
import { useStrf, useWtf } from '~/hooks'; import { useStrf, useWtf, useColorValue } from '~/hooks';
interface UserIPProps { interface UserIPProps {
setTarget(target: string): void; setTarget(target: string): void;

View file

@ -1,62 +0,0 @@
import { createContext, useContext, useMemo } from 'react';
import {
useToken,
ChakraProvider,
useColorModeValue,
useBreakpointValue,
useTheme as useChakraTheme,
} from '@chakra-ui/react';
import { QueryClient, QueryClientProvider } from 'react-query';
import { makeTheme, defaultTheme } from '~/util';
import type { Config, Theme } from '~/types';
import type { THyperglassProvider } from './types';
export const HyperglassContext = createContext<Config>({} as Config);
const queryClient = new QueryClient();
export const HyperglassProvider = (props: THyperglassProvider): JSX.Element => {
const { config, children } = props;
const value = useMemo(() => config, [config]);
const userTheme = value && makeTheme(value.web.theme, value.web.theme.defaultColorMode);
const theme = value ? userTheme : defaultTheme;
return (
<ChakraProvider theme={theme}>
<HyperglassContext.Provider value={value}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</HyperglassContext.Provider>
</ChakraProvider>
);
};
/**
* Get the current configuration.
*/
export const useConfig = (): Config => useContext(HyperglassContext);
/**
* Get the current theme object.
*/
export const useTheme = (): Theme.Full => useChakraTheme();
/**
* Determine if device is mobile or desktop based on Chakra UI theme breakpoints.
*/
export const useMobile = (): boolean =>
useBreakpointValue<boolean>({ base: true, md: true, lg: false, xl: false }) ?? true;
/**
* Convenience function to combine Chakra UI's useToken & useColorModeValue.
*/
export const useColorToken = <L extends string, D extends string>(
token: keyof Theme.Full,
light: L,
dark: D,
): L | D => useColorModeValue(useToken(token, light), useToken(token, dark));
export {
useColorMode,
useBreakpointValue,
useColorModeValue as useColorValue,
} from '@chakra-ui/react';

View file

@ -0,0 +1,34 @@
import { createContext, useContext, useMemo } from 'react';
import { ChakraProvider } from '@chakra-ui/react';
import { QueryClient, QueryClientProvider } from 'react-query';
import { makeTheme, defaultTheme } from '~/util';
import type { Config } from '~/types';
interface HyperglassProviderProps {
config: Config;
children: React.ReactNode;
}
export const HyperglassContext = createContext<Config>({} as Config);
const queryClient = new QueryClient();
export const HyperglassProvider = (props: HyperglassProviderProps): JSX.Element => {
const { config, children } = props;
const value = useMemo(() => config, [config]);
const userTheme = value && makeTheme(value.web.theme, value.web.theme.defaultColorMode);
const theme = value ? userTheme : defaultTheme;
return (
<ChakraProvider theme={theme}>
<HyperglassContext.Provider value={value}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</HyperglassContext.Provider>
</ChakraProvider>
);
};
/**
* Get the current configuration.
*/
export const useConfig = (): Config => useContext(HyperglassContext);

View file

@ -1 +1 @@
export * from './HyperglassProvider'; export * from './hyperglass-provider';

View file

@ -1,6 +0,0 @@
import type { Config } from '~/types';
export interface THyperglassProvider {
config: Config;
children: React.ReactNode;
}

View file

@ -1,5 +1,5 @@
import { Flex } from '@chakra-ui/react'; import { Flex } from '@chakra-ui/react';
import { useColorValue } from '~/context'; import { useColorValue } from '~/hooks';
import type { FlexProps } from '@chakra-ui/react'; import type { FlexProps } from '@chakra-ui/react';

View file

@ -1,5 +1,5 @@
import { Flex, Text } from '@chakra-ui/react'; import { Flex, Text } from '@chakra-ui/react';
import { useColorValue } from '~/context'; import { useColorValue } from '~/hooks';
import type { FlexProps } from '@chakra-ui/react'; import type { FlexProps } from '@chakra-ui/react';

View file

@ -1,5 +1,5 @@
import { Box } from '@chakra-ui/react'; import { Box } from '@chakra-ui/react';
import { useColorValue } from '~/context'; import { useColorValue } from '~/hooks';
import type { BoxProps } from '@chakra-ui/react'; import type { BoxProps } from '@chakra-ui/react';

View file

@ -1,7 +1,7 @@
import { chakra, Text } from '@chakra-ui/react'; import { chakra, Text } from '@chakra-ui/react';
import ReactCountdown, { zeroPad } from 'react-countdown'; import ReactCountdown, { zeroPad } from 'react-countdown';
import { If, Then, Else } from 'react-if'; import { If, Then, Else } from 'react-if';
import { useColorValue } from '~/context'; import { useColorValue } from '~/hooks';
import type { CountdownRenderProps } from 'react-countdown'; import type { CountdownRenderProps } from 'react-countdown';

View file

@ -1,7 +1,6 @@
import { forwardRef } from 'react'; import { forwardRef } from 'react';
import { Flex } from '@chakra-ui/react'; import { Flex } from '@chakra-ui/react';
import { useColorValue } from '~/context'; import { useColorValue, useOpposingColor } from '~/hooks';
import { useOpposingColor } from '~/hooks';
import type { FlexProps } from '@chakra-ui/react'; import type { FlexProps } from '@chakra-ui/react';

View file

@ -19,7 +19,7 @@ import {
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { If, Then, Else } from 'react-if'; import { If, Then, Else } from 'react-if';
import { CodeBlock as CustomCodeBlock } from '~/elements'; import { CodeBlock as CustomCodeBlock } from '~/elements';
import { useColorValue } from '~/context'; import { useColorValue } from '~/hooks';
import type { import type {
BoxProps, BoxProps,

View file

@ -1,6 +1,6 @@
import { useMemo, useCallback } from 'react'; import { useMemo, useCallback } from 'react';
import { getColor, isLight } from '@chakra-ui/theme-tools'; import { getColor, isLight } from '@chakra-ui/theme-tools';
import { useTheme } from '~/context'; import { useTheme } from './theme-hooks';
interface OpposingColorOptions { interface OpposingColorOptions {
light?: string; light?: string;

View file

@ -12,7 +12,8 @@ export namespace Theme {
export type FontWeights = Partial<ChakraTheme['fontWeights']>; export type FontWeights = Partial<ChakraTheme['fontWeights']>;
export interface Full extends Omit<ChakraTheme, 'colors'> { export interface Full extends Omit<ChakraTheme, 'colors' | 'fonts'> {
colors: Colors; colors: Colors;
fonts: Fonts;
} }
} }