diff --git a/src/app/components/Button/index.tsx b/src/app/components/Button/index.tsx new file mode 100644 index 0000000000..89db149897 --- /dev/null +++ b/src/app/components/Button/index.tsx @@ -0,0 +1,55 @@ +import { cloneElement, useMemo } from 'react' +import styled, { DefaultTheme } from 'styled-components' +import { ThemeContext } from 'styled-components' +import { Button, ButtonExtendedProps } from 'grommet/es6/components/Button' +import { useContext } from 'react' +import { normalizeColor } from 'grommet/es6/utils' + +const StyledButton = styled(Button)` + font-size: 14px; + border-radius: 8px; + border-width: 1px; + border-style: solid; +` + +interface BrandButtonProps extends ButtonExtendedProps { + brandVariant?: 'blue' | 'gray' +} + +const getBrandVariantColors = (theme: DefaultTheme) => ({ + blue: { + backgroundColor: normalizeColor('brand-blue', theme), + color: normalizeColor('brand-white', theme), + }, + gray: { + backgroundColor: normalizeColor('brand-gray-medium', theme), + color: normalizeColor('brand-gray-extra-dark', theme), + }, +}) + +export function BrandButton(props: BrandButtonProps) { + const { brandVariant = 'blue', icon, ...rest } = props + const theme = useContext(ThemeContext) + const { backgroundColor, color } = getBrandVariantColors(theme)[brandVariant] + const styledIcon = useMemo(() => { + if (icon) { + return cloneElement(icon, { + size: '22px', + color, + }) + } + }, [color, icon]) + + return ( + + ) +} diff --git a/src/app/components/FatalErrorHandler/index.tsx b/src/app/components/FatalErrorHandler/index.tsx index 9d68945dcd..3315cae72f 100644 --- a/src/app/components/FatalErrorHandler/index.tsx +++ b/src/app/components/FatalErrorHandler/index.tsx @@ -10,7 +10,6 @@ import { ResponsiveContext } from 'grommet/es6/contexts/ResponsiveContext' import { ThemeContext } from 'styled-components' import { Anchor } from 'grommet/es6/components/Anchor' import { Box } from 'grommet/es6/components/Box' -import { Button } from 'grommet/es6/components/Button' import { Heading } from 'grommet/es6/components/Heading' import { TextArea } from 'grommet/es6/components/TextArea' import { Text } from 'grommet/es6/components/Text' @@ -25,6 +24,7 @@ import { normalizeColor } from 'grommet/es6/utils' import { ResponsiveLayer } from '../ResponsiveLayer' import logotype from '../../../../public/logo192.png' import { runtimeIs } from 'config' +import { BrandButton } from '../Button' const StyledTextArea = styled(TextArea)` // Opacity is a workaround for browsers anti-aliasing issue triggered by border-radius. @@ -35,14 +35,6 @@ const StyledTextArea = styled(TextArea)` font-size: 13px; color: ${({ theme }) => normalizeColor('text-custom', theme)}; ` - -const StyledButton = styled(Button)` - font-size: 14px; - border-radius: 8px; - border-width: 1px; - border-style: solid; -` - interface Props { children?: React.ReactNode } @@ -84,52 +76,35 @@ export function FatalErrorHandler({ children }: Props) { /> - } + icon={} label={t('fatalError.checkStatus', 'Check network status')} - style={{ - backgroundColor: normalizeColor('brand-blue', theme), - color: normalizeColor('brand-white', theme), - borderColor: normalizeColor('brand-blue', theme), - }} - size="large" /> - copyError()} - icon={} + icon={} label={ !copied ? t('fatalError.copy', 'Copy error to clipboard') : t('fatalError.copied', 'Error copied to clipboard') } - style={{ - backgroundColor: normalizeColor('brand-gray-medium', theme), - color: normalizeColor('brand-gray-extra-dark', theme), - borderColor: normalizeColor('brand-gray-medium', theme), - }} - size="large" /> {runtimeIs === 'extension' && ( - (window as any).chrome?.runtime?.reload()} - icon={} + icon={} label={t('fatalError.reloadExtension', 'Reload extension')} - style={{ - backgroundColor: normalizeColor('brand-blue', theme), - color: normalizeColor('brand-white', theme), - borderColor: normalizeColor('brand-blue', theme), - }} - size="large" /> )}