Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 10 additions & 43 deletions src/components/ConnectNavigationHeader.js
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand Down Expand Up @@ -65,40 +56,16 @@ export const ConnectNavigationHeader = (props) => {
}

return (
<Box data-test="navigation-header" sx={sx.container}>
<AppBar elevation={0} position="static" sx={sx.appBar}>
<Toolbar disableGutters={true} sx={sx.toolbar}>
{shouldShowGlobalBackButton || showMobileBackButton ? (
<IconButton
aria-label={__('Go Back')}
data-test="back-button"
name="connect-navigation-back-button"
onClick={backButtonNavigationHandler}
ref={goBackButtonContainerRef}
sx={sx.button}
>
<Icon name="arrow_back_ios_new" size={24} />
</IconButton>
) : null}
</Toolbar>
</AppBar>
</Box>
<GoBackButton
handleGoBack={backButtonNavigationHandler}
ref={goBackButtonContainerRef}
shouldShowBackButton={shouldShowGlobalBackButton || showMobileBackButton}
toolbarSx={{ left: '50%', transform: 'translateX(-50%)' }}
/>
)
}

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 },
})
59 changes: 33 additions & 26 deletions src/components/GoBackButton.tsx
Original file line number Diff line number Diff line change
@@ -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<Theme>
}

export const GoBackButton = forwardRef<HTMLButtonElement, GoBackButtonProps>((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 (
<IconButton
aria-label={__('Go Back')}
data-test="back-button"
onClick={handleGoBack}
ref={ref ?? defaultRef}
style={styles}
>
<ChevronLeft
color={tokens.TextColor.Default}
height={tokens.Spacing.Large}
width={tokens.Spacing.Large}
/>
</IconButton>
<Box data-test="navigation-header" sx={defaultStyles.container}>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go back button is used in multiple places. Are we intending for this App bar to show up everywhere that GoBackButton is rendered?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency and maintainability I would say yes. There is no visual difference that the AppBar adds if you look at the screenshots I shared. To me having a single Back button defined and used across the entire experience makes the most sense. @platypus801 what do you think?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GoBackButton is used in 4 places including DayOfMonth picker. I'm doubtful that you want the appbar for the day of month picker

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how it looks on my branch:

Screenshot 2026-07-30 at 13 21 05

vs on master:

Screenshot 2026-07-30 at 13 22 04

You can't really tell the difference.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just a slight space at the top.

<AppBar elevation={0} position="static" sx={defaultStyles.appBar}>
<Toolbar sx={{ ...defaultStyles.toolbar, ...toolbarSx }}>
{shouldShowBackButton ? (
<IconButton
aria-label={__('Go Back')}
data-test="back-button"
name="connect-navigation-back-button"
onClick={handleGoBack}
ref={ref ?? defaultRef}
sx={defaultStyles.button}
>
<Icon name="arrow_back_ios_new" size={24} />
</IconButton>
) : null}
</Toolbar>
</AppBar>
</Box>
)
})

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' },

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using css modules for styling.

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'
13 changes: 8 additions & 5 deletions src/components/__tests__/GoBackButton-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<GoBackButton handleGoBack={handleGoBack} />)
render(<GoBackButton {...defaultProps} />)
const button = screen.getByRole('button', { name: /back/i })
expect(button).toBeInTheDocument()
})

it('navigates back when clicked', () => {
render(<GoBackButton handleGoBack={handleGoBack} />)
render(<GoBackButton {...defaultProps} />)
const button = screen.getByRole('button', { name: /back/i })

fireEvent.click(button)
expect(handleGoBack).toHaveBeenCalled()
expect(defaultProps.handleGoBack).toHaveBeenCalled()
})

it('is accessible', () => {
render(<GoBackButton handleGoBack={handleGoBack} />)
render(<GoBackButton {...defaultProps} />)
const button = screen.getByRole('button', { name: /back/i })
expect(button).toHaveAttribute('aria-label', 'Go Back')
})
Expand Down
1 change: 0 additions & 1 deletion typings/kyper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading