diff --git a/src/components/ConnectNavigationHeader.js b/src/components/ConnectNavigationHeader.js index 6afe618fd0..bf058bd3bc 100644 --- a/src/components/ConnectNavigationHeader.js +++ b/src/components/ConnectNavigationHeader.js @@ -1,29 +1,20 @@ import React, { useContext, useState, useEffect, useRef } from 'react' import PropTypes from 'prop-types' import { useSelector } from 'react-redux' -import { useTokens } from '@kyper/tokenprovider' - -import AppBar from '@mui/material/AppBar' -import Box from '@mui/material/Box' -import Toolbar from '@mui/material/Toolbar' -import IconButton from '@mui/material/IconButton' -import { Icon } from '@mxenabled/mxui' - import { __ } from 'src/utilities/Intl' import { STEPS } from 'src/const/Connect' import { PostMessageContext } from 'src/ConnectWidget' +import { GoBackButton } from 'src/components/GoBackButton' export const ConnectNavigationHeader = (props) => { const goBackButtonContainerRef = useRef() const postMessageFunctions = useContext(PostMessageContext) - const tokens = useTokens() - const sx = getStyles(tokens) const step = useSelector( (state) => state.connect.location[state.connect.location.length - 1]?.step ?? STEPS.SEARCH, ) - const showMobileBackButton = useSelector( - (state) => state.config.show_back_button && state.connect.location.length === 1, - ) + const showMobileBackButton = + useSelector((state) => state.config.show_back_button && state.connect.location.length === 1) || + false const [shouldShowGlobalBackButton, setShouldShowGlobalBackButton] = useState(false) useEffect(() => { @@ -65,24 +56,12 @@ export const ConnectNavigationHeader = (props) => { } return ( - - - - {shouldShowGlobalBackButton || showMobileBackButton ? ( - - - - ) : null} - - - + ) } @@ -90,15 +69,3 @@ ConnectNavigationHeader.propTypes = { connectGoBack: PropTypes.func.isRequired, stepComponentRef: PropTypes.object, } - -const getStyles = (tokens) => ({ - container: { flexGrow: 1 }, - appBar: { backgroundColor: tokens.BackgroundColor.Container, display: 'flex' }, - toolbar: { - padding: `0 ${tokens.Spacing.Medium}px`, - maxWidth: '368px', - left: '50%', - transform: 'translateX(-50%)', - }, - button: { color: tokens.TextColor.Default }, -}) diff --git a/src/components/GoBackButton.tsx b/src/components/GoBackButton.tsx index 7ed18fa92d..c7c8444440 100644 --- a/src/components/GoBackButton.tsx +++ b/src/components/GoBackButton.tsx @@ -1,48 +1,55 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import React, { forwardRef, useRef } from 'react' -import PropTypes from 'prop-types' import { useTokens } from '@kyper/tokenprovider' -import { IconButton } from '@mui/material' -import { ChevronLeft } from '@kyper/icon/ChevronLeft' +import { AppBar, Box, IconButton, Toolbar, SxProps, Theme } from '@mui/material' +import { Icon } from '@mxenabled/mxui' import { __ } from 'src/utilities/Intl' interface GoBackButtonProps { handleGoBack: () => void + shouldShowBackButton?: boolean + toolbarSx?: SxProps } export const GoBackButton = forwardRef((props, ref) => { const defaultRef = useRef(null) - const { handleGoBack } = props + const { handleGoBack, shouldShowBackButton = true, toolbarSx = {} } = props const tokens = useTokens() - const styles = getStyles(tokens) + const defaultStyles = getStyles(tokens) return ( - - - + + + + {shouldShowBackButton ? ( + + + + ) : null} + + + ) }) const getStyles = (tokens: any) => ({ - height: '44px', - margin: `0px ${tokens.Spacing.XSmall}px ${tokens.Spacing.XSmall}px -${tokens.Spacing.Medium}px`, - padding: `0px 8px`, - width: '44px', + container: { flexGrow: 1 }, + appBar: { backgroundColor: tokens.BackgroundColor.Container, display: 'flex' }, + toolbar: { + padding: `0 ${tokens.Spacing.Medium}px`, + maxWidth: '368px', + left: 0, + transform: 'translateX(-5%)', + }, + button: { color: tokens.TextColor.Default }, }) -GoBackButton.propTypes = { - handleGoBack: PropTypes.func.isRequired, -} - GoBackButton.displayName = 'GoBackButton' diff --git a/src/components/__tests__/GoBackButton-test.tsx b/src/components/__tests__/GoBackButton-test.tsx index 7c30c69efd..fdbc9a2157 100644 --- a/src/components/__tests__/GoBackButton-test.tsx +++ b/src/components/__tests__/GoBackButton-test.tsx @@ -3,24 +3,27 @@ import { render, screen, fireEvent } from 'src/utilities/testingLibrary' import { GoBackButton } from '../GoBackButton' describe('GoBackButton', () => { - const handleGoBack = vi.fn() + const defaultProps = { + handleGoBack: vi.fn(), + shouldShowBackButton: true, + } it('renders the go back button', () => { - render() + render() const button = screen.getByRole('button', { name: /back/i }) expect(button).toBeInTheDocument() }) it('navigates back when clicked', () => { - render() + render() const button = screen.getByRole('button', { name: /back/i }) fireEvent.click(button) - expect(handleGoBack).toHaveBeenCalled() + expect(defaultProps.handleGoBack).toHaveBeenCalled() }) it('is accessible', () => { - render() + render() const button = screen.getByRole('button', { name: /back/i }) expect(button).toHaveAttribute('aria-label', 'Go Back') }) diff --git a/typings/kyper.d.ts b/typings/kyper.d.ts index e9b6e8122a..70d635e1d7 100644 --- a/typings/kyper.d.ts +++ b/typings/kyper.d.ts @@ -17,7 +17,6 @@ declare module '@kyper/icon/Image' declare module '@kyper/icon/Health' declare module '@kyper/icon/Grid' declare module '@kyper/progressindicators' -declare module '@kyper/icon/ChevronLeft' declare module '@kyper/icon/Lock' declare module '@kyper/utilityrow' declare module '@kyper/hooks'