@registrucentras/rc-ses-react-components 2.0.0-rc.2 → 2.0.0-rc.4

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.
Files changed (81) hide show
  1. package/dist/assets/icons/ArrowRightIcon.d.ts +1 -1
  2. package/dist/components/common/CardShell/CardFooter/index.d.ts +3 -0
  3. package/dist/components/common/CardShell/CardFooter/types.d.ts +21 -0
  4. package/dist/components/common/CardShell/index.d.ts +5 -0
  5. package/dist/components/common/CardShell/types.d.ts +26 -0
  6. package/dist/components/common/IconWithSquareBackground/index.d.ts +12 -0
  7. package/dist/components/common/ServiceLinks/ServiceLinkItem/index.d.ts +15 -0
  8. package/dist/components/common/ServiceLinks/index.d.ts +3 -0
  9. package/dist/components/common/ServiceLinks/types.d.ts +34 -0
  10. package/dist/components/common/SideNav/SideNav.types.d.ts +20 -0
  11. package/dist/components/common/SideNav/SideNavLayout.d.ts +4 -0
  12. package/dist/components/common/SideNav/components/SideNavPill.d.ts +9 -0
  13. package/dist/components/common/SideNav/components/SideNavPillList.d.ts +9 -0
  14. package/dist/components/common/SideNav/components/SideNavRow.d.ts +9 -0
  15. package/dist/components/common/SideNav/hooks/useSideNavScrollSpy.d.ts +12 -0
  16. package/dist/components/common/SideNav/index.d.ts +4 -0
  17. package/dist/components/common/TitleBlock/index.d.ts +3 -0
  18. package/dist/components/common/TitleBlock/types.d.ts +73 -0
  19. package/dist/components/utils/normalizeSx.d.ts +4 -0
  20. package/dist/library/index.d.ts +10 -1
  21. package/dist/library/types.d.ts +8 -1
  22. package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
  23. package/dist/registrucentras-rc-ses-react-components.js +3535 -2563
  24. package/dist/stories/components/display/CardShell.stories.d.ts +17 -0
  25. package/dist/stories/components/display/SelectableCardList.stories.d.ts +1 -0
  26. package/dist/stories/components/display/ServiceLinks.stories.d.ts +28 -0
  27. package/dist/stories/components/display/TitleBlock.stories.d.ts +20 -0
  28. package/dist/stories/components/form/FormControlWrapper.stories.d.ts +1 -0
  29. package/dist/stories/components/icons/IconWithSquareBackground.stories.d.ts +7 -0
  30. package/dist/stories/components/inputs/DatePicker.stories.d.ts +107 -0
  31. package/dist/stories/components/navigation/SideNav.stories.d.ts +7 -0
  32. package/dist/theme/cards.d.ts +114 -0
  33. package/dist/theme/light/MuiPickersOutlinedInput.d.ts +8 -0
  34. package/package.json +1 -1
  35. package/src/assets/icons/ArrowRightIcon.tsx +2 -1
  36. package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +8 -6
  37. package/src/components/common/Card/index.tsx +1 -23
  38. package/src/components/common/CardShell/CardFooter/index.test.tsx +52 -0
  39. package/src/components/common/CardShell/CardFooter/index.tsx +38 -0
  40. package/src/components/common/CardShell/CardFooter/types.ts +24 -0
  41. package/src/components/common/CardShell/index.test.tsx +137 -0
  42. package/src/components/common/CardShell/index.tsx +78 -0
  43. package/src/components/common/CardShell/types.ts +30 -0
  44. package/src/components/common/IconWithSquareBackground/index.test.tsx +55 -0
  45. package/src/components/common/IconWithSquareBackground/index.tsx +83 -0
  46. package/src/components/common/ServiceLinks/ServiceLinkItem/index.tsx +177 -0
  47. package/src/components/common/ServiceLinks/index.test.tsx +166 -0
  48. package/src/components/common/ServiceLinks/index.tsx +66 -0
  49. package/src/components/common/ServiceLinks/types.ts +37 -0
  50. package/src/components/common/SideNav/SideNav.types.ts +24 -0
  51. package/src/components/common/SideNav/SideNavLayout.test.tsx +113 -0
  52. package/src/components/common/SideNav/SideNavLayout.tsx +67 -0
  53. package/src/components/common/SideNav/components/SideNavPill.tsx +62 -0
  54. package/src/components/common/SideNav/components/SideNavPillList.tsx +190 -0
  55. package/src/components/common/SideNav/components/SideNavRow.tsx +72 -0
  56. package/src/components/common/SideNav/hooks/useSideNavScrollSpy.test.ts +457 -0
  57. package/src/components/common/SideNav/hooks/useSideNavScrollSpy.ts +154 -0
  58. package/src/components/common/SideNav/index.test.tsx +99 -0
  59. package/src/components/common/SideNav/index.tsx +83 -0
  60. package/src/components/common/TitleBlock/index.test.tsx +366 -0
  61. package/src/components/common/TitleBlock/index.tsx +144 -0
  62. package/src/components/common/TitleBlock/types.ts +82 -0
  63. package/src/components/form/inputs/Datepicker/index.test.tsx +117 -0
  64. package/src/components/utils/normalizeSx.ts +24 -0
  65. package/src/i18n/namespaces/common/en.json +4 -0
  66. package/src/i18n/namespaces/common/lt.json +4 -0
  67. package/src/library/index.ts +12 -0
  68. package/src/library/types.ts +38 -0
  69. package/src/stories/components/display/CardShell.stories.tsx +263 -0
  70. package/src/stories/components/display/SelectableCardList.stories.tsx +33 -1
  71. package/src/stories/components/display/ServiceLinks.stories.tsx +154 -0
  72. package/src/stories/components/display/TitleBlock.stories.tsx +506 -0
  73. package/src/stories/components/form/FormControlWrapper.stories.tsx +23 -0
  74. package/src/stories/components/icons/IconWithSquareBackground.stories.tsx +60 -0
  75. package/src/stories/components/inputs/DatePicker.stories.tsx +105 -9
  76. package/src/stories/components/navigation/SideNav.stories.tsx +110 -0
  77. package/src/theme/cards.ts +60 -0
  78. package/src/theme/light/MuiButton.tsx +6 -0
  79. package/src/theme/light/MuiPickersLayout.ts +10 -1
  80. package/src/theme/light/MuiPickersOutlinedInput.ts +88 -0
  81. package/src/theme/light/index.tsx +2 -0
@@ -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