@registrucentras/rc-ses-react-components 2.0.0-rc.3 → 2.0.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/icons/ArrowRightIcon.d.ts +1 -1
- package/dist/assets/icons/WarningCircleIcon.d.ts +1 -1
- package/dist/components/common/Alert/index.d.ts +8 -2
- package/dist/components/common/CardShell/index.d.ts +1 -1
- package/dist/components/common/CardShell/types.d.ts +3 -1
- package/dist/components/common/IconWithSquareBackground/index.d.ts +12 -0
- package/dist/components/common/ServiceLinks/ServiceLinkItem/index.d.ts +15 -0
- package/dist/components/common/ServiceLinks/index.d.ts +3 -0
- package/dist/components/common/ServiceLinks/types.d.ts +34 -0
- package/dist/components/common/SideNav/SideNav.types.d.ts +20 -0
- package/dist/components/common/SideNav/SideNavLayout.d.ts +4 -0
- package/dist/components/common/SideNav/components/SideNavPill.d.ts +9 -0
- package/dist/components/common/SideNav/components/SideNavPillList.d.ts +9 -0
- package/dist/components/common/SideNav/components/SideNavRow.d.ts +9 -0
- package/dist/components/common/SideNav/hooks/useSideNavScrollSpy.d.ts +12 -0
- package/dist/components/common/SideNav/index.d.ts +4 -0
- package/dist/components/common/TitleBlock/index.d.ts +3 -0
- package/dist/components/common/TitleBlock/types.d.ts +73 -0
- package/dist/components/utils/normalizeSx.d.ts +4 -0
- package/dist/library/index.d.ts +8 -2
- package/dist/library/types.d.ts +6 -2
- package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
- package/dist/registrucentras-rc-ses-react-components.js +3489 -2703
- package/dist/stories/components/display/CardShell.stories.d.ts +1 -1
- package/dist/stories/components/display/SelectableCardList.stories.d.ts +1 -0
- package/dist/stories/components/display/ServiceLinks.stories.d.ts +28 -0
- package/dist/stories/components/display/TitleBlock.stories.d.ts +20 -0
- package/dist/stories/components/feedback/Alert.stories.d.ts +4 -0
- package/dist/stories/components/form/FormControlWrapper.stories.d.ts +1 -0
- package/dist/stories/components/icons/IconWithSquareBackground.stories.d.ts +7 -0
- package/dist/stories/components/navigation/SideNav.stories.d.ts +7 -0
- package/package.json +1 -1
- package/src/assets/icons/ArrowRightIcon.tsx +2 -1
- package/src/assets/icons/WarningCircleIcon.tsx +8 -2
- package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +8 -6
- package/src/components/common/Alert/index.test.tsx +157 -2
- package/src/components/common/Alert/index.tsx +144 -10
- package/src/components/common/Card/index.tsx +1 -23
- package/src/components/common/CardShell/index.tsx +4 -1
- package/src/components/common/CardShell/types.ts +3 -1
- package/src/components/common/IconWithSquareBackground/index.test.tsx +55 -0
- package/src/components/common/IconWithSquareBackground/index.tsx +83 -0
- package/src/components/common/ServiceLinks/ServiceLinkItem/index.tsx +177 -0
- package/src/components/common/ServiceLinks/index.test.tsx +166 -0
- package/src/components/common/ServiceLinks/index.tsx +66 -0
- package/src/components/common/ServiceLinks/types.ts +37 -0
- package/src/components/common/SideNav/SideNav.types.ts +24 -0
- package/src/components/common/SideNav/SideNavLayout.test.tsx +113 -0
- package/src/components/common/SideNav/SideNavLayout.tsx +67 -0
- package/src/components/common/SideNav/components/SideNavPill.tsx +62 -0
- package/src/components/common/SideNav/components/SideNavPillList.tsx +190 -0
- package/src/components/common/SideNav/components/SideNavRow.tsx +72 -0
- package/src/components/common/SideNav/hooks/useSideNavScrollSpy.test.ts +457 -0
- package/src/components/common/SideNav/hooks/useSideNavScrollSpy.ts +154 -0
- package/src/components/common/SideNav/index.test.tsx +99 -0
- package/src/components/common/SideNav/index.tsx +83 -0
- package/src/components/common/TitleBlock/index.test.tsx +366 -0
- package/src/components/common/TitleBlock/index.tsx +144 -0
- package/src/components/common/TitleBlock/types.ts +82 -0
- package/src/components/utils/normalizeSx.ts +24 -0
- package/src/i18n/namespaces/common/en.json +4 -0
- package/src/i18n/namespaces/common/lt.json +4 -0
- package/src/library/index.ts +8 -2
- package/src/library/types.ts +20 -8
- package/src/stories/components/display/CardShell.stories.tsx +14 -12
- package/src/stories/components/display/SelectableCardList.stories.tsx +33 -1
- package/src/stories/components/display/ServiceLinks.stories.tsx +154 -0
- package/src/stories/components/display/TitleBlock.stories.tsx +506 -0
- package/src/stories/components/feedback/Alert.stories.tsx +135 -4
- package/src/stories/components/form/FormControlWrapper.stories.tsx +23 -0
- package/src/stories/components/icons/IconWithSquareBackground.stories.tsx +60 -0
- package/src/stories/components/navigation/SideNav.stories.tsx +110 -0
- package/src/theme/cards.ts +1 -1
- package/src/theme/light/MuiAlert.tsx +28 -20
- package/src/theme/light/MuiButton.tsx +6 -0
- package/dist/components/common/CardShell/CardHeader/index.d.ts +0 -3
- package/dist/components/common/CardShell/CardHeader/types.d.ts +0 -33
- package/src/components/common/CardShell/CardHeader/index.test.tsx +0 -207
- package/src/components/common/CardShell/CardHeader/index.tsx +0 -104
- package/src/components/common/CardShell/CardHeader/types.ts +0 -36
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { ThemeProvider } from '@mui/material/styles'
|
|
2
|
+
import { act, render, screen } from '@testing-library/react'
|
|
3
|
+
import { ReactElement } from 'react'
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
|
|
6
|
+
import i18n from '@/i18n/i18n'
|
|
7
|
+
import theme from '@/theme/light'
|
|
8
|
+
|
|
9
|
+
import { RcSesSideNavItem } from './SideNav.types'
|
|
10
|
+
import RcSesSideNavLayout from './SideNavLayout'
|
|
11
|
+
|
|
12
|
+
function ResizeObserverMock() {
|
|
13
|
+
return { observe: () => {}, unobserve: () => {}, disconnect: () => {} }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
Element.prototype.scrollIntoView = vi.fn()
|
|
17
|
+
|
|
18
|
+
const items: RcSesSideNavItem[] = [
|
|
19
|
+
{ id: 'family', label: 'Aš ir mano šeima', count: 4 },
|
|
20
|
+
{ id: 'documents', label: 'Dokumentai apie gyventoją', count: 2 },
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
const renderLayout = (ui: ReactElement) =>
|
|
24
|
+
render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
|
|
25
|
+
|
|
26
|
+
describe('RcSesSideNavLayout', () => {
|
|
27
|
+
beforeEach(async () => {
|
|
28
|
+
vi.stubGlobal('ResizeObserver', ResizeObserverMock)
|
|
29
|
+
await i18n.changeLanguage('lt')
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
vi.unstubAllGlobals()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('renders the nav alongside its content children', () => {
|
|
37
|
+
renderLayout(
|
|
38
|
+
<RcSesSideNavLayout items={items} title='Temos'>
|
|
39
|
+
<div id='family'>Family content</div>
|
|
40
|
+
<div id='documents'>Documents content</div>
|
|
41
|
+
</RcSesSideNavLayout>,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
expect(screen.getByRole('navigation', { name: 'Temos' })).toBeInTheDocument()
|
|
45
|
+
expect(screen.getByText('Family content')).toBeInTheDocument()
|
|
46
|
+
expect(screen.getByText('Documents content')).toBeInTheDocument()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('forwards activeItemId/onItemClick through to the nav for controlled mode', () => {
|
|
50
|
+
const handleClick = vi.fn()
|
|
51
|
+
renderLayout(
|
|
52
|
+
<RcSesSideNavLayout items={items} activeItemId='family' onItemClick={handleClick}>
|
|
53
|
+
<div id='family' />
|
|
54
|
+
<div id='documents' />
|
|
55
|
+
</RcSesSideNavLayout>,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
screen.getAllByRole('button', { name: 'Dokumentai apie gyventoją, 2' })[0].click()
|
|
59
|
+
|
|
60
|
+
expect(handleClick).toHaveBeenCalledWith('documents')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('is interactive by default and scrolls to the clicked item when uncontrolled', () => {
|
|
64
|
+
const scrollToMock = vi.fn()
|
|
65
|
+
vi.stubGlobal('scrollTo', scrollToMock)
|
|
66
|
+
vi.stubGlobal(
|
|
67
|
+
'matchMedia',
|
|
68
|
+
vi.fn(() => ({ matches: false })),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
renderLayout(
|
|
72
|
+
<RcSesSideNavLayout items={items} title='Temos'>
|
|
73
|
+
<div id='family' />
|
|
74
|
+
<div id='documents' />
|
|
75
|
+
</RcSesSideNavLayout>,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
act(() => {
|
|
79
|
+
screen.getAllByRole('button', { name: 'Dokumentai apie gyventoją, 2' })[0].click()
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
expect(scrollToMock).toHaveBeenCalledWith(
|
|
83
|
+
expect.objectContaining({ behavior: 'smooth' }),
|
|
84
|
+
)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('does not throw when clicked with no matching section in the content', () => {
|
|
88
|
+
renderLayout(
|
|
89
|
+
<RcSesSideNavLayout items={items} title='Temos'>
|
|
90
|
+
<div />
|
|
91
|
+
</RcSesSideNavLayout>,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
expect(() =>
|
|
95
|
+
screen.getAllByRole('button', { name: 'Dokumentai apie gyventoją, 2' })[0].click(),
|
|
96
|
+
).not.toThrow()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('does not drop custom sx values passed as an array', () => {
|
|
100
|
+
const { container } = renderLayout(
|
|
101
|
+
<RcSesSideNavLayout
|
|
102
|
+
items={items}
|
|
103
|
+
title='Temos'
|
|
104
|
+
sx={[{ backgroundColor: 'rgb(1, 2, 3)' }]}
|
|
105
|
+
>
|
|
106
|
+
<div id='family' />
|
|
107
|
+
<div id='documents' />
|
|
108
|
+
</RcSesSideNavLayout>,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
expect(container.firstChild).toHaveStyle({ backgroundColor: 'rgb(1, 2, 3)' })
|
|
112
|
+
})
|
|
113
|
+
})
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Box } from '@mui/material'
|
|
2
|
+
import { useRef } from 'react'
|
|
3
|
+
|
|
4
|
+
import normalizeSx from '@/components/utils/normalizeSx'
|
|
5
|
+
|
|
6
|
+
import RcSesSideNav from '.'
|
|
7
|
+
import { RcSesSideNavLayoutProps } from './SideNav.types'
|
|
8
|
+
import useSideNavScrollSpy from './hooks/useSideNavScrollSpy'
|
|
9
|
+
|
|
10
|
+
function RcSesSideNavLayout({
|
|
11
|
+
children,
|
|
12
|
+
items,
|
|
13
|
+
activeItemId: controlledActiveItemId,
|
|
14
|
+
onItemClick,
|
|
15
|
+
title,
|
|
16
|
+
offset,
|
|
17
|
+
sidebarWidth = '17rem',
|
|
18
|
+
sx,
|
|
19
|
+
}: RcSesSideNavLayoutProps) {
|
|
20
|
+
const contentRef = useRef<HTMLDivElement>(null)
|
|
21
|
+
|
|
22
|
+
const isControlled = controlledActiveItemId !== undefined
|
|
23
|
+
const itemIds = items.map((item) => item.id)
|
|
24
|
+
const scrollSpy = useSideNavScrollSpy({
|
|
25
|
+
itemIds: isControlled ? [] : itemIds,
|
|
26
|
+
offset,
|
|
27
|
+
scope: contentRef,
|
|
28
|
+
})
|
|
29
|
+
const activeItemId = isControlled ? controlledActiveItemId : scrollSpy.activeItemId
|
|
30
|
+
|
|
31
|
+
const isInteractive = !isControlled || !!onItemClick
|
|
32
|
+
const handleItemClick = isInteractive
|
|
33
|
+
? (id: string) => {
|
|
34
|
+
if (!isControlled) scrollSpy.scrollToItem(id)
|
|
35
|
+
onItemClick?.(id)
|
|
36
|
+
}
|
|
37
|
+
: undefined
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Box
|
|
41
|
+
sx={[
|
|
42
|
+
{ display: 'flex', flexDirection: { xs: 'column', md: 'row' }, gap: '2rem' },
|
|
43
|
+
...normalizeSx(sx),
|
|
44
|
+
]}
|
|
45
|
+
>
|
|
46
|
+
<RcSesSideNav
|
|
47
|
+
items={items}
|
|
48
|
+
activeItemId={activeItemId}
|
|
49
|
+
onItemClick={handleItemClick}
|
|
50
|
+
title={title}
|
|
51
|
+
sx={{
|
|
52
|
+
position: 'sticky',
|
|
53
|
+
top: `${offset ?? 0}px`,
|
|
54
|
+
alignSelf: { xs: 'stretch', md: 'flex-start' },
|
|
55
|
+
width: { md: sidebarWidth },
|
|
56
|
+
flexShrink: 0,
|
|
57
|
+
}}
|
|
58
|
+
/>
|
|
59
|
+
<Box ref={contentRef} sx={{ flex: 1, minWidth: 0 }}>
|
|
60
|
+
{children}
|
|
61
|
+
</Box>
|
|
62
|
+
</Box>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default RcSesSideNavLayout
|
|
67
|
+
export type { RcSesSideNavLayoutProps } from './SideNav.types'
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Box, Typography } from '@mui/material'
|
|
2
|
+
|
|
3
|
+
import palette, { common } from '@/theme/palette'
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
label: string
|
|
7
|
+
count?: number
|
|
8
|
+
ariaLabel?: string
|
|
9
|
+
active: boolean
|
|
10
|
+
onClick?: () => void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function SideNavPill({ label, count, ariaLabel, active, onClick }: Props) {
|
|
14
|
+
return (
|
|
15
|
+
<Box
|
|
16
|
+
component={onClick ? 'button' : 'div'}
|
|
17
|
+
type={onClick ? 'button' : undefined}
|
|
18
|
+
onClick={onClick}
|
|
19
|
+
aria-current={active ? 'page' : undefined}
|
|
20
|
+
aria-label={ariaLabel}
|
|
21
|
+
sx={{
|
|
22
|
+
display: 'flex',
|
|
23
|
+
alignItems: 'center',
|
|
24
|
+
gap: '0.5rem',
|
|
25
|
+
flexShrink: 0,
|
|
26
|
+
whiteSpace: 'nowrap',
|
|
27
|
+
margin: 0,
|
|
28
|
+
borderRadius: '9999px',
|
|
29
|
+
border: `0.0625rem solid ${active ? palette.primary.main : palette.grey[200]}`,
|
|
30
|
+
backgroundColor: active ? palette.primary[50] : common.white,
|
|
31
|
+
padding: '0.5rem 1rem',
|
|
32
|
+
cursor: onClick ? 'pointer' : 'default',
|
|
33
|
+
WebkitTapHighlightColor: 'transparent',
|
|
34
|
+
'&:focus-visible': {
|
|
35
|
+
outline: `0.125rem solid ${palette.primary.main}`,
|
|
36
|
+
outlineOffset: '0.125rem',
|
|
37
|
+
},
|
|
38
|
+
}}
|
|
39
|
+
>
|
|
40
|
+
<Typography
|
|
41
|
+
component='span'
|
|
42
|
+
sx={{
|
|
43
|
+
fontSize: '0.875rem',
|
|
44
|
+
lineHeight: '1.25rem',
|
|
45
|
+
color: active ? palette.grey[900] : palette.grey[600],
|
|
46
|
+
}}
|
|
47
|
+
>
|
|
48
|
+
{label}
|
|
49
|
+
</Typography>
|
|
50
|
+
{count !== undefined && (
|
|
51
|
+
<Typography
|
|
52
|
+
component='span'
|
|
53
|
+
sx={{ fontSize: '0.8125rem', lineHeight: '1.125rem', color: palette.grey[500] }}
|
|
54
|
+
>
|
|
55
|
+
{count}
|
|
56
|
+
</Typography>
|
|
57
|
+
)}
|
|
58
|
+
</Box>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export default SideNavPill
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { Box } from '@mui/material'
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import palette, { common } from '@/theme/palette'
|
|
5
|
+
|
|
6
|
+
import { RcSesSideNavItem } from '../SideNav.types'
|
|
7
|
+
import SideNavPill from './SideNavPill'
|
|
8
|
+
|
|
9
|
+
const FADE_WIDTH = '2rem'
|
|
10
|
+
const SCROLL_EPSILON = 1
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
items: RcSesSideNavItem[]
|
|
14
|
+
activeItemId?: string
|
|
15
|
+
onItemClick?: (id: string) => void
|
|
16
|
+
getItemAriaLabel: (item: RcSesSideNavItem) => string | undefined
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type ScrollState = {
|
|
20
|
+
hasOverflow: boolean
|
|
21
|
+
showRightFade: boolean
|
|
22
|
+
thumbWidth: number
|
|
23
|
+
thumbOffset: number
|
|
24
|
+
// Gap to the viewport's right edge, so the fade can bleed over the page gutter.
|
|
25
|
+
edgeBleed: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const INITIAL_SCROLL_STATE: ScrollState = {
|
|
29
|
+
hasOverflow: false,
|
|
30
|
+
showRightFade: false,
|
|
31
|
+
thumbWidth: 100,
|
|
32
|
+
thumbOffset: 0,
|
|
33
|
+
edgeBleed: 0,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function SideNavPillList({ items, activeItemId, onItemClick, getItemAriaLabel }: Props) {
|
|
37
|
+
const scrollRef = useRef<HTMLDivElement>(null)
|
|
38
|
+
const [scrollState, setScrollState] = useState<ScrollState>(INITIAL_SCROLL_STATE)
|
|
39
|
+
|
|
40
|
+
const updateScrollState = useCallback(() => {
|
|
41
|
+
const el = scrollRef.current
|
|
42
|
+
if (!el) return
|
|
43
|
+
|
|
44
|
+
const hasOverflow = el.scrollWidth > el.clientWidth + SCROLL_EPSILON
|
|
45
|
+
const showRightFade =
|
|
46
|
+
hasOverflow && el.scrollLeft < el.scrollWidth - el.clientWidth - SCROLL_EPSILON
|
|
47
|
+
|
|
48
|
+
// Not innerWidth: that counts the vertical scrollbar.
|
|
49
|
+
const edgeBleed = Math.max(
|
|
50
|
+
0,
|
|
51
|
+
document.documentElement.clientWidth - el.getBoundingClientRect().right,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
const next: ScrollState = {
|
|
55
|
+
hasOverflow,
|
|
56
|
+
showRightFade,
|
|
57
|
+
thumbWidth: hasOverflow ? (el.clientWidth / el.scrollWidth) * 100 : 100,
|
|
58
|
+
thumbOffset: hasOverflow ? (el.scrollLeft / el.scrollWidth) * 100 : 0,
|
|
59
|
+
edgeBleed,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// onScroll fires far more often than these values actually change.
|
|
63
|
+
setScrollState((prev) =>
|
|
64
|
+
prev.hasOverflow === next.hasOverflow &&
|
|
65
|
+
prev.showRightFade === next.showRightFade &&
|
|
66
|
+
prev.thumbWidth === next.thumbWidth &&
|
|
67
|
+
prev.thumbOffset === next.thumbOffset &&
|
|
68
|
+
prev.edgeBleed === next.edgeBleed
|
|
69
|
+
? prev
|
|
70
|
+
: next,
|
|
71
|
+
)
|
|
72
|
+
}, [])
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
const el = scrollRef.current
|
|
76
|
+
updateScrollState()
|
|
77
|
+
if (!el) return undefined
|
|
78
|
+
|
|
79
|
+
const resizeObserver = new ResizeObserver(updateScrollState)
|
|
80
|
+
resizeObserver.observe(el)
|
|
81
|
+
// The pills too: a late web font changes scrollWidth, not the container's size.
|
|
82
|
+
Array.from(el.children).forEach((child) => resizeObserver.observe(child))
|
|
83
|
+
// A viewport resize inside a max-width container does not resize the list.
|
|
84
|
+
window.addEventListener('resize', updateScrollState)
|
|
85
|
+
|
|
86
|
+
return () => {
|
|
87
|
+
resizeObserver.disconnect()
|
|
88
|
+
window.removeEventListener('resize', updateScrollState)
|
|
89
|
+
}
|
|
90
|
+
}, [items, updateScrollState])
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (!activeItemId) return
|
|
94
|
+
const container = scrollRef.current
|
|
95
|
+
const target = container?.querySelector<HTMLElement>(
|
|
96
|
+
`[data-item-id="${activeItemId}"]`,
|
|
97
|
+
)
|
|
98
|
+
if (!container || !target) return
|
|
99
|
+
|
|
100
|
+
// Viewport rects on both, so they agree: offsetLeft would be relative to the
|
|
101
|
+
// positioned wrapper, not the scroll container.
|
|
102
|
+
const containerRect = container.getBoundingClientRect()
|
|
103
|
+
const targetRect = target.getBoundingClientRect()
|
|
104
|
+
const overflowLeft = containerRect.left - targetRect.left
|
|
105
|
+
const overflowRight = targetRect.right - containerRect.right
|
|
106
|
+
|
|
107
|
+
if (overflowLeft > 0) {
|
|
108
|
+
container.scrollLeft -= overflowLeft
|
|
109
|
+
} else if (overflowRight > 0) {
|
|
110
|
+
container.scrollLeft += overflowRight
|
|
111
|
+
}
|
|
112
|
+
}, [activeItemId])
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<Box>
|
|
116
|
+
<Box sx={{ position: 'relative' }}>
|
|
117
|
+
<Box
|
|
118
|
+
ref={scrollRef}
|
|
119
|
+
onScroll={updateScrollState}
|
|
120
|
+
sx={{
|
|
121
|
+
display: 'flex',
|
|
122
|
+
gap: '0.5rem',
|
|
123
|
+
overflowX: 'auto',
|
|
124
|
+
overflowY: 'hidden',
|
|
125
|
+
scrollbarWidth: 'none',
|
|
126
|
+
'&::-webkit-scrollbar': { display: 'none' },
|
|
127
|
+
padding: '0.5rem 0.75rem',
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
{items.map((item) => (
|
|
131
|
+
<Box key={item.id} data-item-id={item.id} sx={{ display: 'flex' }}>
|
|
132
|
+
<SideNavPill
|
|
133
|
+
label={item.label}
|
|
134
|
+
count={item.count}
|
|
135
|
+
ariaLabel={getItemAriaLabel(item)}
|
|
136
|
+
active={item.id === activeItemId}
|
|
137
|
+
onClick={onItemClick ? () => onItemClick(item.id) : undefined}
|
|
138
|
+
/>
|
|
139
|
+
</Box>
|
|
140
|
+
))}
|
|
141
|
+
</Box>
|
|
142
|
+
|
|
143
|
+
{scrollState.showRightFade && (
|
|
144
|
+
<Box
|
|
145
|
+
aria-hidden
|
|
146
|
+
sx={{
|
|
147
|
+
position: 'absolute',
|
|
148
|
+
top: 0,
|
|
149
|
+
bottom: 0,
|
|
150
|
+
right: `-${scrollState.edgeBleed}px`,
|
|
151
|
+
width: `calc(${FADE_WIDTH} + ${scrollState.edgeBleed}px)`,
|
|
152
|
+
// Stop at FADE_WIDTH, not 100%, so the bleed stays solid.
|
|
153
|
+
background: `linear-gradient(to right, ${common.white}00, ${common.white} ${FADE_WIDTH})`,
|
|
154
|
+
pointerEvents: 'none',
|
|
155
|
+
}}
|
|
156
|
+
/>
|
|
157
|
+
)}
|
|
158
|
+
</Box>
|
|
159
|
+
|
|
160
|
+
{scrollState.hasOverflow && (
|
|
161
|
+
<Box
|
|
162
|
+
aria-hidden
|
|
163
|
+
sx={{
|
|
164
|
+
position: 'relative',
|
|
165
|
+
height: '0.25rem',
|
|
166
|
+
marginX: '0.75rem',
|
|
167
|
+
marginTop: '0.25rem',
|
|
168
|
+
borderRadius: '9999px',
|
|
169
|
+
backgroundColor: palette.grey[200],
|
|
170
|
+
overflow: 'hidden',
|
|
171
|
+
}}
|
|
172
|
+
>
|
|
173
|
+
<Box
|
|
174
|
+
sx={{
|
|
175
|
+
position: 'absolute',
|
|
176
|
+
top: 0,
|
|
177
|
+
bottom: 0,
|
|
178
|
+
left: `${scrollState.thumbOffset}%`,
|
|
179
|
+
width: `${scrollState.thumbWidth}%`,
|
|
180
|
+
borderRadius: '9999px',
|
|
181
|
+
backgroundColor: palette.grey[400],
|
|
182
|
+
}}
|
|
183
|
+
/>
|
|
184
|
+
</Box>
|
|
185
|
+
)}
|
|
186
|
+
</Box>
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export default SideNavPillList
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Box, Typography } from '@mui/material'
|
|
2
|
+
|
|
3
|
+
import palette from '@/theme/palette'
|
|
4
|
+
|
|
5
|
+
const BORDER_WIDTH = '0.125rem'
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
label: string
|
|
9
|
+
count?: number
|
|
10
|
+
ariaLabel?: string
|
|
11
|
+
active: boolean
|
|
12
|
+
onClick?: () => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function SideNavRow({ label, count, ariaLabel, active, onClick }: Props) {
|
|
16
|
+
return (
|
|
17
|
+
<Box
|
|
18
|
+
component={onClick ? 'button' : 'div'}
|
|
19
|
+
type={onClick ? 'button' : undefined}
|
|
20
|
+
onClick={onClick}
|
|
21
|
+
aria-current={active ? 'page' : undefined}
|
|
22
|
+
aria-label={ariaLabel}
|
|
23
|
+
sx={{
|
|
24
|
+
display: 'flex',
|
|
25
|
+
alignItems: 'center',
|
|
26
|
+
gap: '0.5rem',
|
|
27
|
+
width: '100%',
|
|
28
|
+
boxSizing: 'border-box',
|
|
29
|
+
margin: 0,
|
|
30
|
+
border: 'none',
|
|
31
|
+
borderLeft: `${BORDER_WIDTH} solid ${active ? palette.primary.main : 'transparent'}`,
|
|
32
|
+
backgroundColor: active ? palette.primary[50] : 'transparent',
|
|
33
|
+
padding: '0.75rem 1rem',
|
|
34
|
+
textAlign: 'left',
|
|
35
|
+
cursor: onClick ? 'pointer' : 'default',
|
|
36
|
+
'&:hover': onClick && !active ? { backgroundColor: palette.grey[50] } : undefined,
|
|
37
|
+
'&:focus-visible': {
|
|
38
|
+
outline: `${BORDER_WIDTH} solid ${palette.primary.main}`,
|
|
39
|
+
outlineOffset: '-2px',
|
|
40
|
+
},
|
|
41
|
+
}}
|
|
42
|
+
>
|
|
43
|
+
<Typography
|
|
44
|
+
component='span'
|
|
45
|
+
sx={{
|
|
46
|
+
flex: '1 1 0%',
|
|
47
|
+
minWidth: 0,
|
|
48
|
+
fontSize: '0.9375rem',
|
|
49
|
+
lineHeight: '1.375rem',
|
|
50
|
+
color: active ? palette.grey[900] : palette.primary[700],
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
{label}
|
|
54
|
+
</Typography>
|
|
55
|
+
{count !== undefined && (
|
|
56
|
+
<Typography
|
|
57
|
+
component='span'
|
|
58
|
+
sx={{
|
|
59
|
+
flexShrink: 0,
|
|
60
|
+
fontSize: '0.8125rem',
|
|
61
|
+
lineHeight: '1.125rem',
|
|
62
|
+
color: palette.grey[500],
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
{count}
|
|
66
|
+
</Typography>
|
|
67
|
+
)}
|
|
68
|
+
</Box>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export default SideNavRow
|