-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create Right Sidebar * Create responsive layout for sidebars * Remove width test from Sidebar.test.tsx This test doesn't fit well with RTL unit testing, this test case will be covered later by integration tests. * Rename RightSidebar to ContentSidebar * Add ScreenReaderOnly test * Center SkipNavigation link
- Loading branch information
1 parent
9498e08
commit ace6bce
Showing
11 changed files
with
185 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Button from '@mui/joy/Button' | ||
import { ChevronRight16Filled } from '@fluentui/react-icons' | ||
import { ScreenReaderOnly } from '@/ui/ScreenReaderOnly/ScreenReaderOnly' | ||
import { SxProps } from '@mui/joy/styles/types' | ||
|
||
type CollapseButtonProps = { | ||
onClick: () => void | ||
sx: SxProps | ||
} | ||
|
||
export const CollapseButton = ({ onClick, sx }: CollapseButtonProps) => { | ||
return ( | ||
<Button | ||
size="sm" | ||
onClick={onClick} | ||
sx={{ | ||
borderRadius: '50%', | ||
bgcolor: 'white', | ||
width: 32, | ||
height: 32, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
display: 'flex', | ||
position: 'absolute', | ||
padding: 0, | ||
zIndex: 1, | ||
boxShadow: '0px 6px 6px #00000029', | ||
...sx | ||
}} | ||
> | ||
<ChevronRight16Filled primaryFill="black" /> | ||
<ScreenReaderOnly>Expand/collapse menu</ScreenReaderOnly> | ||
</Button> | ||
) | ||
} |
26 changes: 26 additions & 0 deletions
26
frontend/src/ui/CollapseButton/__tests__/CollapseButton.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { render, screen, fireEvent } from '@/test-utils/test-utils' | ||
import { CollapseButton } from '../CollapseButton' | ||
|
||
describe('CollapseButton', () => { | ||
it('should have an invisible screen-reader text for the collapse button', () => { | ||
render(<CollapseButton sx={{}} onClick={() => {}} />) | ||
|
||
const collapseButton = screen.getByRole('button') | ||
|
||
expect(collapseButton).toHaveTextContent('Expand/collapse menu') | ||
}) | ||
|
||
it('receives an sx to extend component style', () => { | ||
render(<CollapseButton sx={{ top: '60px' }} onClick={() => {}} />) | ||
const collapseButton = screen.getByRole('button') | ||
expect(collapseButton).toHaveStyle({ top: '60px' }) | ||
}) | ||
|
||
it('calls onClick prop when clicked', () => { | ||
const onClick = jest.fn() | ||
render(<CollapseButton sx={{}} onClick={onClick} />) | ||
const collapseButton = screen.getByRole('button') | ||
fireEvent.click(collapseButton) | ||
expect(onClick).toHaveBeenCalled() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use client' | ||
|
||
import { useState } from 'react' | ||
import Box from '@mui/joy/Box' | ||
import { CollapseButton } from '../CollapseButton/CollapseButton' | ||
|
||
type ContentSidebarProps = { | ||
children: React.ReactNode | ||
} | ||
|
||
export const ContentSidebar = ({ children }: ContentSidebarProps) => { | ||
const [expanded, setExpanded] = useState(false) | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
height: { xs: expanded ? '60px' : '320px', sm: '100vh' }, | ||
width: { xs: '100vw', sm: expanded ? '60px' : '320px' }, | ||
transition: { xs: 'height 0.6s', sm: 'width 0.6s' }, | ||
position: 'relative', | ||
bgcolor: 'white', | ||
border: '1px solid #D2D2D4' | ||
}} | ||
> | ||
<CollapseButton | ||
sx={{ | ||
left: { xs: '0px', sm: '-16px' }, | ||
right: { xs: '0px', sm: 'unset' }, | ||
top: { xs: '-16px', sm: '61px' }, | ||
margin: '0 auto', | ||
transform: { xs: 'rotateZ(90deg)', sm: 'rotateZ(180deg)' }, | ||
...(expanded && { | ||
transform: { xs: 'rotateZ(-90deg)', sm: 'rotateZ(0deg)' } | ||
}) | ||
}} | ||
onClick={() => setExpanded((prevState) => !prevState)} | ||
/> | ||
{children} | ||
</Box> | ||
) | ||
} |
10 changes: 10 additions & 0 deletions
10
frontend/src/ui/ScreenReaderOnly/__tests__/ScreenReaderOnly.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { render, screen } from '@/test-utils/test-utils' | ||
import { ScreenReaderOnly } from '../ScreenReaderOnly' | ||
|
||
describe('ScreenReaderOnly', () => { | ||
it('renders the component with children', () => { | ||
render(<ScreenReaderOnly>Test text</ScreenReaderOnly>) | ||
|
||
expect(screen.getByText('Test text')).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters