@registrucentras/rc-ses-react-components 2.4.0 → 2.5.1
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/phosphorIcons.d.ts +4 -0
- package/dist/components/common/Badge/index.d.ts +1 -0
- package/dist/components/overlays/Drawer/Drawer.types.d.ts +30 -0
- package/dist/components/overlays/Drawer/index.d.ts +9 -0
- package/dist/library/index.d.ts +2 -1
- package/dist/library/types.d.ts +2 -0
- package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
- package/dist/registrucentras-rc-ses-react-components.js +2054 -1866
- package/package.json +5 -5
- package/src/assets/icons/phosphorIcons.ts +2 -0
- package/src/components/common/AdvancedList/components/AdvancedListItemShell/index.test.tsx +23 -0
- package/src/components/common/AdvancedList/components/AdvancedListItemShell/index.tsx +6 -0
- package/src/components/common/Badge/index.test.tsx +16 -0
- package/src/components/common/Badge/index.tsx +34 -10
- package/src/components/form/inputs/Select/index.tsx +3 -1
- package/src/components/overlays/Drawer/Drawer.types.ts +32 -0
- package/src/components/overlays/Drawer/index.test.tsx +174 -0
- package/src/components/overlays/Drawer/index.tsx +192 -0
- package/src/i18n/namespaces/common/en.json +3 -0
- package/src/i18n/namespaces/common/lt.json +3 -0
- package/src/library/index.ts +2 -0
- package/src/library/types.ts +2 -0
- package/src/stories/atoms/Badge.stories.tsx +40 -0
- package/src/stories/atoms/Icons.stories.tsx +133 -226
- package/src/stories/foundations/ThemedMuiComponents.stories.tsx +31 -0
- package/src/stories/organisms/AdvancedListItemShell.stories.tsx +93 -3
- package/src/stories/organisms/Drawer.stories.tsx +90 -0
- package/src/theme/light/MuiAutocomplete.ts +5 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@registrucentras/rc-ses-react-components",
|
|
3
3
|
"author": "VĮ REGISTRŲ CENTRAS",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.5.1",
|
|
5
5
|
"description": "RC SES React komponentų biblioteka",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"private": false,
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@emotion/react": "^11.13.3",
|
|
52
52
|
"@emotion/styled": "^11.13.0",
|
|
53
|
-
"@mui/material": "^9.
|
|
54
|
-
"@mui/system": "^9.
|
|
53
|
+
"@mui/material": "^9.3.1",
|
|
54
|
+
"@mui/system": "^9.3.0",
|
|
55
55
|
"@mui/x-date-pickers": "^9.10.1",
|
|
56
56
|
"date-fns": "^3.6.0 || ^4.0.0",
|
|
57
57
|
"date-fns-tz": "^3.2.0",
|
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
"@eslint/js": "^9.39.5",
|
|
78
78
|
"@fontsource/public-sans": "^5.3.0",
|
|
79
79
|
"@microsoft/api-extractor": "^7.58.12",
|
|
80
|
-
"@mui/material": "9.
|
|
81
|
-
"@mui/system": "9.
|
|
80
|
+
"@mui/material": "9.3.1",
|
|
81
|
+
"@mui/system": "9.3.0",
|
|
82
82
|
"@mui/x-date-pickers": "9.10.1",
|
|
83
83
|
"@playwright/test": "^1.62.0",
|
|
84
84
|
"@rollup/plugin-commonjs": "^26.0.3",
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
CheckCircleIcon as CheckCircle,
|
|
18
18
|
CheckSquareIcon as CheckSquare,
|
|
19
19
|
CircleIcon as Circle,
|
|
20
|
+
ClockIcon as Clock,
|
|
20
21
|
CopyIcon as Copy,
|
|
21
22
|
EnvelopeSimpleIcon as EnvelopeSimple,
|
|
22
23
|
InfoIcon as Info,
|
|
@@ -104,6 +105,7 @@ export const CircleFilledIcon = /* @__PURE__ */ createIcon(Circle, {
|
|
|
104
105
|
weight: 'fill',
|
|
105
106
|
name: 'CircleFilledIcon',
|
|
106
107
|
})
|
|
108
|
+
export const ClockIcon = /* @__PURE__ */ createIcon(Clock)
|
|
107
109
|
export const CloseIcon = /* @__PURE__ */ createIcon(X, { name: 'CloseIcon' })
|
|
108
110
|
export const CollapseChevronsIcon = /* @__PURE__ */ createIcon(ArrowsInLineVertical, {
|
|
109
111
|
size: 16,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fireEvent, render, screen } from '@testing-library/react'
|
|
2
|
+
import { createPortal } from 'react-dom'
|
|
2
3
|
import { describe, expect, it, vi } from 'vitest'
|
|
3
4
|
|
|
4
5
|
import AdvancedListItemShell from '.'
|
|
@@ -202,6 +203,28 @@ describe('AdvancedListItemShell', () => {
|
|
|
202
203
|
expect(onClick).not.toHaveBeenCalled()
|
|
203
204
|
})
|
|
204
205
|
|
|
206
|
+
it('does not call onClick when clicked on portalled content from slot (dropdown option)', () => {
|
|
207
|
+
const onClick = vi.fn()
|
|
208
|
+
render(
|
|
209
|
+
<AdvancedListItemShell
|
|
210
|
+
content={<span>Content</span>}
|
|
211
|
+
isExpanded
|
|
212
|
+
onClick={onClick}
|
|
213
|
+
expanded={createPortal(
|
|
214
|
+
<ul role='listbox'>
|
|
215
|
+
<li role='option' aria-selected={false}>
|
|
216
|
+
Pasas
|
|
217
|
+
</li>
|
|
218
|
+
</ul>,
|
|
219
|
+
document.body,
|
|
220
|
+
)}
|
|
221
|
+
/>,
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
fireEvent.click(screen.getByRole('option', { name: 'Pasas' }))
|
|
225
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
226
|
+
})
|
|
227
|
+
|
|
205
228
|
it('does not expose role="button" on the root, even when clickable', () => {
|
|
206
229
|
render(
|
|
207
230
|
<AdvancedListItemShell
|
|
@@ -99,6 +99,12 @@ const AdvancedListItemShell = ({
|
|
|
99
99
|
|
|
100
100
|
const target = event.target as HTMLElement
|
|
101
101
|
|
|
102
|
+
// Skip clicks on portalled content (dropdown poppers, dialogs) rendered from a slot,
|
|
103
|
+
// React bubbles them up
|
|
104
|
+
if (!rootRef.current?.contains(target)) {
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
|
|
102
108
|
// Skip clicks on interactive elements that have their own handlers. The root itself
|
|
103
109
|
// is role="button" in expandable rows, so it is excluded.
|
|
104
110
|
const control = target.closest('button, a, input, select, textarea, [role="button"]')
|
|
@@ -3,6 +3,7 @@ import { fireEvent, render, screen } from '@testing-library/react'
|
|
|
3
3
|
import { ReactElement } from 'react'
|
|
4
4
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
5
|
|
|
6
|
+
import { CheckIcon } from '@/assets/icons/phosphorIcons'
|
|
6
7
|
import i18n from '@/i18n/i18n'
|
|
7
8
|
import theme from '@/theme/light'
|
|
8
9
|
|
|
@@ -63,6 +64,21 @@ describe('RcSesBadge', () => {
|
|
|
63
64
|
expect(container.querySelector('svg')).not.toBeInTheDocument()
|
|
64
65
|
})
|
|
65
66
|
|
|
67
|
+
it('renders custom icon over default icon', () => {
|
|
68
|
+
const { container } = renderBadge(
|
|
69
|
+
<RcSesBadge
|
|
70
|
+
label='Label'
|
|
71
|
+
variant='neutral'
|
|
72
|
+
size='regular'
|
|
73
|
+
showIcon
|
|
74
|
+
icon={<CheckIcon data-testid='custom-icon' />}
|
|
75
|
+
/>,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
expect(screen.getByTestId('custom-icon')).toBeInTheDocument()
|
|
79
|
+
expect(container.querySelectorAll('svg').length).toBe(1)
|
|
80
|
+
})
|
|
81
|
+
|
|
66
82
|
it('does not render a close button by default', () => {
|
|
67
83
|
renderBadge(<RcSesBadge label='Label' variant='neutral' size='regular' />)
|
|
68
84
|
|
|
@@ -9,6 +9,7 @@ export interface RcSesBadgeProps {
|
|
|
9
9
|
variant: 'neutral' | 'success' | 'warning' | 'error' | 'info' | 'brand'
|
|
10
10
|
size: 'small' | 'regular'
|
|
11
11
|
showIcon?: boolean
|
|
12
|
+
icon?: React.ReactNode
|
|
12
13
|
showClose?: boolean
|
|
13
14
|
onClose?: () => void
|
|
14
15
|
}
|
|
@@ -82,7 +83,15 @@ const sizeStyles: Record<RcSesBadgeProps['size'], SizeStyle> = {
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
function RcSesBadge(props: RcSesBadgeProps) {
|
|
85
|
-
const {
|
|
86
|
+
const {
|
|
87
|
+
label,
|
|
88
|
+
variant,
|
|
89
|
+
size,
|
|
90
|
+
showIcon = true,
|
|
91
|
+
icon,
|
|
92
|
+
showClose = false,
|
|
93
|
+
onClose,
|
|
94
|
+
} = props
|
|
86
95
|
const { t } = useTranslation('input', { keyPrefix: 'components.RcSesBadge' })
|
|
87
96
|
|
|
88
97
|
const variantStyle = variantStyles[variant]
|
|
@@ -104,15 +113,30 @@ function RcSesBadge(props: RcSesBadgeProps) {
|
|
|
104
113
|
|
|
105
114
|
return (
|
|
106
115
|
<Box sx={baseStyle}>
|
|
107
|
-
{showIcon &&
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
{showIcon &&
|
|
117
|
+
(icon ? (
|
|
118
|
+
<Box
|
|
119
|
+
aria-hidden
|
|
120
|
+
sx={{
|
|
121
|
+
display: 'flex',
|
|
122
|
+
alignItems: 'center',
|
|
123
|
+
justifyContent: 'center',
|
|
124
|
+
width: 14,
|
|
125
|
+
height: 14,
|
|
126
|
+
flexShrink: 0,
|
|
127
|
+
}}
|
|
128
|
+
>
|
|
129
|
+
{icon}
|
|
130
|
+
</Box>
|
|
131
|
+
) : (
|
|
132
|
+
<CircleFilledIcon
|
|
133
|
+
size={14}
|
|
134
|
+
fillColor={variantStyle.iconColor}
|
|
135
|
+
aria-hidden
|
|
136
|
+
focusable={false}
|
|
137
|
+
style={{ flexShrink: 0 }}
|
|
138
|
+
/>
|
|
139
|
+
))}
|
|
116
140
|
<Box
|
|
117
141
|
component='span'
|
|
118
142
|
title={label}
|
|
@@ -596,6 +596,7 @@ function RcSesSelect<TFieldValues extends FieldValues = FieldValues>(
|
|
|
596
596
|
handleSelectAll()
|
|
597
597
|
}}
|
|
598
598
|
sx={{
|
|
599
|
+
alignItems: 'center !important',
|
|
599
600
|
display: 'flex',
|
|
600
601
|
flexDirection: 'row !important',
|
|
601
602
|
gap: '.75rem',
|
|
@@ -628,7 +629,7 @@ function RcSesSelect<TFieldValues extends FieldValues = FieldValues>(
|
|
|
628
629
|
toggleGroupValue(groupValue)
|
|
629
630
|
}}
|
|
630
631
|
sx={{
|
|
631
|
-
alignItems: 'center',
|
|
632
|
+
alignItems: 'center !important',
|
|
632
633
|
backgroundColor: isGroupSelected
|
|
633
634
|
? palette.primary['50']
|
|
634
635
|
: 'transparent',
|
|
@@ -678,6 +679,7 @@ function RcSesSelect<TFieldValues extends FieldValues = FieldValues>(
|
|
|
678
679
|
{...rest}
|
|
679
680
|
className={[className, indentClassName].filter(Boolean).join(' ')}
|
|
680
681
|
sx={{
|
|
682
|
+
alignItems: 'center !important',
|
|
681
683
|
display: 'flex',
|
|
682
684
|
gap: multiple ? '.75rem' : '.5rem',
|
|
683
685
|
flexDirection: 'row !important',
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface RcSesDrawerTestIds {
|
|
4
|
+
root?: string
|
|
5
|
+
header?: string
|
|
6
|
+
closeButton?: string
|
|
7
|
+
body?: string
|
|
8
|
+
footer?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface RcSesDrawerProps {
|
|
12
|
+
/** Whether the drawer is open */
|
|
13
|
+
isOpen: boolean
|
|
14
|
+
/** Callback fired when the drawer should close */
|
|
15
|
+
onClose: () => void
|
|
16
|
+
/** Drawer title displayed in header */
|
|
17
|
+
title: ReactNode
|
|
18
|
+
/** Main content of the drawer (scrollable body) */
|
|
19
|
+
children: ReactNode
|
|
20
|
+
/** Label for the secondary (left) action button */
|
|
21
|
+
secondaryActionLabel?: string
|
|
22
|
+
/** Callback fired when secondary action button is clicked */
|
|
23
|
+
onSecondaryAction?: () => void
|
|
24
|
+
/** Label for the primary (right) action button */
|
|
25
|
+
primaryActionLabel?: string
|
|
26
|
+
/** Callback fired when primary action button is clicked */
|
|
27
|
+
onPrimaryAction?: () => void
|
|
28
|
+
/** Test IDs for testing */
|
|
29
|
+
testIds?: RcSesDrawerTestIds
|
|
30
|
+
/** Optional CSS class name */
|
|
31
|
+
className?: string
|
|
32
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from '@testing-library/react'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import RcSesDrawer from '.'
|
|
5
|
+
|
|
6
|
+
describe('RcSesDrawer', () => {
|
|
7
|
+
it('renders when isOpen is true', () => {
|
|
8
|
+
render(
|
|
9
|
+
<RcSesDrawer isOpen title='Test Drawer' onClose={vi.fn()}>
|
|
10
|
+
Test content
|
|
11
|
+
</RcSesDrawer>,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
expect(screen.getByText('Test Drawer')).toBeInTheDocument()
|
|
15
|
+
expect(screen.getByText('Test content')).toBeInTheDocument()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('does not display when isOpen is false', () => {
|
|
19
|
+
render(
|
|
20
|
+
<RcSesDrawer isOpen={false} title='Test Drawer' onClose={vi.fn()}>
|
|
21
|
+
Test content
|
|
22
|
+
</RcSesDrawer>,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('calls onClose when close button is clicked', () => {
|
|
29
|
+
const onClose = vi.fn()
|
|
30
|
+
render(
|
|
31
|
+
<RcSesDrawer
|
|
32
|
+
isOpen
|
|
33
|
+
title='Test Drawer'
|
|
34
|
+
onClose={onClose}
|
|
35
|
+
testIds={{ closeButton: 'test-close-btn' }}
|
|
36
|
+
>
|
|
37
|
+
Test content
|
|
38
|
+
</RcSesDrawer>,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const closeButton = screen.getByTestId('test-close-btn')
|
|
42
|
+
fireEvent.click(closeButton)
|
|
43
|
+
|
|
44
|
+
expect(onClose).toHaveBeenCalledTimes(1)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('calls onClose when backdrop is clicked', () => {
|
|
48
|
+
const onClose = vi.fn()
|
|
49
|
+
render(
|
|
50
|
+
<RcSesDrawer isOpen title='Test Drawer' onClose={onClose}>
|
|
51
|
+
Test content
|
|
52
|
+
</RcSesDrawer>,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
const backdrop = document.querySelector('.MuiBackdrop-root') as Element
|
|
56
|
+
fireEvent.click(backdrop)
|
|
57
|
+
expect(onClose).toHaveBeenCalledTimes(1)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('calls onClose when Escape key is pressed', () => {
|
|
61
|
+
const onClose = vi.fn()
|
|
62
|
+
render(
|
|
63
|
+
<RcSesDrawer isOpen title='Test Drawer' onClose={onClose}>
|
|
64
|
+
Test content
|
|
65
|
+
</RcSesDrawer>,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const dialog = screen.getByRole('dialog')
|
|
69
|
+
fireEvent.keyDown(dialog, { key: 'Escape' })
|
|
70
|
+
expect(onClose).toHaveBeenCalledTimes(1)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('renders footer when action labels are provided', () => {
|
|
74
|
+
render(
|
|
75
|
+
<RcSesDrawer
|
|
76
|
+
isOpen
|
|
77
|
+
title='Test Drawer'
|
|
78
|
+
onClose={vi.fn()}
|
|
79
|
+
secondaryActionLabel='Cancel'
|
|
80
|
+
primaryActionLabel='Apply'
|
|
81
|
+
>
|
|
82
|
+
Test content
|
|
83
|
+
</RcSesDrawer>,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
expect(screen.getByText('Cancel')).toBeInTheDocument()
|
|
87
|
+
expect(screen.getByText('Apply')).toBeInTheDocument()
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('does not render footer when no action labels are provided', () => {
|
|
91
|
+
render(
|
|
92
|
+
<RcSesDrawer isOpen title='Test Drawer' onClose={vi.fn()}>
|
|
93
|
+
Test content
|
|
94
|
+
</RcSesDrawer>,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
expect(
|
|
98
|
+
screen.queryByRole('button', { name: /cancel|apply/i }),
|
|
99
|
+
).not.toBeInTheDocument()
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('calls onPrimaryAction when primary button is clicked', () => {
|
|
103
|
+
const onPrimaryAction = vi.fn()
|
|
104
|
+
render(
|
|
105
|
+
<RcSesDrawer
|
|
106
|
+
isOpen
|
|
107
|
+
title='Test Drawer'
|
|
108
|
+
onClose={vi.fn()}
|
|
109
|
+
primaryActionLabel='Apply'
|
|
110
|
+
onPrimaryAction={onPrimaryAction}
|
|
111
|
+
>
|
|
112
|
+
Test content
|
|
113
|
+
</RcSesDrawer>,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
fireEvent.click(screen.getByText('Apply'))
|
|
117
|
+
|
|
118
|
+
expect(onPrimaryAction).toHaveBeenCalledTimes(1)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('calls onSecondaryAction when secondary button is clicked', () => {
|
|
122
|
+
const onSecondaryAction = vi.fn()
|
|
123
|
+
render(
|
|
124
|
+
<RcSesDrawer
|
|
125
|
+
isOpen
|
|
126
|
+
title='Test Drawer'
|
|
127
|
+
onClose={vi.fn()}
|
|
128
|
+
secondaryActionLabel='Cancel'
|
|
129
|
+
onSecondaryAction={onSecondaryAction}
|
|
130
|
+
>
|
|
131
|
+
Test content
|
|
132
|
+
</RcSesDrawer>,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
fireEvent.click(screen.getByText('Cancel'))
|
|
136
|
+
|
|
137
|
+
expect(onSecondaryAction).toHaveBeenCalledTimes(1)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('has proper ARIA attributes', () => {
|
|
141
|
+
render(
|
|
142
|
+
<RcSesDrawer isOpen title='Test Drawer' onClose={vi.fn()}>
|
|
143
|
+
Test content
|
|
144
|
+
</RcSesDrawer>,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
const dialog = screen.getByRole('dialog')
|
|
148
|
+
expect(dialog).toHaveAttribute('aria-modal', 'true')
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('renders with testIds', () => {
|
|
152
|
+
render(
|
|
153
|
+
<RcSesDrawer
|
|
154
|
+
isOpen
|
|
155
|
+
title='Test Drawer'
|
|
156
|
+
onClose={vi.fn()}
|
|
157
|
+
testIds={{
|
|
158
|
+
root: 'test-drawer-root',
|
|
159
|
+
header: 'test-drawer-header',
|
|
160
|
+
body: 'test-drawer-body',
|
|
161
|
+
footer: 'test-drawer-footer',
|
|
162
|
+
closeButton: 'test-drawer-close',
|
|
163
|
+
}}
|
|
164
|
+
>
|
|
165
|
+
Test content
|
|
166
|
+
</RcSesDrawer>,
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
expect(screen.getByTestId('test-drawer-root')).toBeInTheDocument()
|
|
170
|
+
expect(screen.getByTestId('test-drawer-header')).toBeInTheDocument()
|
|
171
|
+
expect(screen.getByTestId('test-drawer-body')).toBeInTheDocument()
|
|
172
|
+
expect(screen.getByTestId('test-drawer-close')).toBeInTheDocument()
|
|
173
|
+
})
|
|
174
|
+
})
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Box,
|
|
3
|
+
Fade,
|
|
4
|
+
Dialog as MuiDialog,
|
|
5
|
+
Slide,
|
|
6
|
+
SlideProps,
|
|
7
|
+
Typography,
|
|
8
|
+
} from '@mui/material'
|
|
9
|
+
import { forwardRef, useId } from 'react'
|
|
10
|
+
import { useTranslation } from 'react-i18next'
|
|
11
|
+
|
|
12
|
+
import { CloseIcon } from '@/assets/icons/phosphorIcons'
|
|
13
|
+
import usePrefersReducedMotion from '@/components/common/AdvancedList/components/AdvancedListItem/hooks/usePrefersReducedMotion'
|
|
14
|
+
import RcSesButton from '@/components/common/Button'
|
|
15
|
+
|
|
16
|
+
import { RcSesDrawerProps, RcSesDrawerTestIds } from './Drawer.types'
|
|
17
|
+
|
|
18
|
+
const DRAWER_WIDTH = 440
|
|
19
|
+
const ANIMATION_DURATION = 250
|
|
20
|
+
const BACKDROP_OPACITY = 0.5
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* SlideLeftTransition - Wrapper for Slide component with direction='left'
|
|
24
|
+
* Allows type-safe usage without 'as any' cast
|
|
25
|
+
*/
|
|
26
|
+
const SlideLeftTransition = forwardRef<HTMLDivElement, SlideProps>((props, ref) => (
|
|
27
|
+
<Slide ref={ref} direction='left' {...props} />
|
|
28
|
+
))
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* RcSesDrawer component - a slide-over panel that slides in from the right.
|
|
32
|
+
* Built on MUI Dialog for proper focus management, scroll locking, and DOM handling.
|
|
33
|
+
* Composition: Header (title + close button), scrollable body, and optional footer.
|
|
34
|
+
*/
|
|
35
|
+
const RcSesDrawer = ({
|
|
36
|
+
isOpen,
|
|
37
|
+
onClose,
|
|
38
|
+
title,
|
|
39
|
+
children,
|
|
40
|
+
secondaryActionLabel,
|
|
41
|
+
onSecondaryAction,
|
|
42
|
+
primaryActionLabel,
|
|
43
|
+
onPrimaryAction,
|
|
44
|
+
testIds,
|
|
45
|
+
className,
|
|
46
|
+
}: RcSesDrawerProps) => {
|
|
47
|
+
const prefersReducedMotion = usePrefersReducedMotion()
|
|
48
|
+
const { t } = useTranslation('common', { keyPrefix: 'components.Drawer' })
|
|
49
|
+
const headerId = useId()
|
|
50
|
+
|
|
51
|
+
const handleClose = () => {
|
|
52
|
+
onClose()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<MuiDialog
|
|
57
|
+
open={isOpen}
|
|
58
|
+
onClose={handleClose}
|
|
59
|
+
aria-labelledby={headerId}
|
|
60
|
+
maxWidth={false}
|
|
61
|
+
transitionDuration={prefersReducedMotion ? 0 : ANIMATION_DURATION}
|
|
62
|
+
sx={{
|
|
63
|
+
'& .MuiDialog-container': {
|
|
64
|
+
height: '100vh',
|
|
65
|
+
minHeight: '100vh',
|
|
66
|
+
},
|
|
67
|
+
}}
|
|
68
|
+
slots={{
|
|
69
|
+
transition: prefersReducedMotion ? Fade : SlideLeftTransition,
|
|
70
|
+
}}
|
|
71
|
+
slotProps={{
|
|
72
|
+
transition: {
|
|
73
|
+
appear: true,
|
|
74
|
+
},
|
|
75
|
+
backdrop: {
|
|
76
|
+
sx: {
|
|
77
|
+
backgroundColor: `rgba(0, 0, 0, ${BACKDROP_OPACITY})`,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
container: {
|
|
81
|
+
sx: {
|
|
82
|
+
display: 'flex',
|
|
83
|
+
justifyContent: 'flex-end',
|
|
84
|
+
alignItems: 'stretch',
|
|
85
|
+
width: '100%',
|
|
86
|
+
margin: 0,
|
|
87
|
+
padding: 0,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
paper: {
|
|
91
|
+
sx: {
|
|
92
|
+
margin: 0,
|
|
93
|
+
padding: 0,
|
|
94
|
+
width: DRAWER_WIDTH,
|
|
95
|
+
maxWidth: DRAWER_WIDTH,
|
|
96
|
+
flex: '1 1 auto',
|
|
97
|
+
minHeight: '100vh',
|
|
98
|
+
borderRadius: 0,
|
|
99
|
+
boxShadow: '-4px 0 24px rgba(0, 0, 0, 0.18)',
|
|
100
|
+
backgroundColor: (theme) => theme.palette.common.white,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
}}
|
|
104
|
+
>
|
|
105
|
+
<Box
|
|
106
|
+
data-testid={testIds?.root}
|
|
107
|
+
className={className}
|
|
108
|
+
sx={{
|
|
109
|
+
display: 'flex',
|
|
110
|
+
flexDirection: 'column',
|
|
111
|
+
height: '100%',
|
|
112
|
+
width: '100%',
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
<Box
|
|
116
|
+
data-testid={testIds?.header}
|
|
117
|
+
sx={{
|
|
118
|
+
display: 'flex',
|
|
119
|
+
alignItems: 'center',
|
|
120
|
+
justifyContent: 'space-between',
|
|
121
|
+
padding: '1.25rem 1rem 1rem 1.5rem',
|
|
122
|
+
borderBottom: (theme) => `1px solid ${theme.palette.grey[200]}`,
|
|
123
|
+
flexShrink: 0,
|
|
124
|
+
gap: '1rem',
|
|
125
|
+
}}
|
|
126
|
+
>
|
|
127
|
+
<Typography
|
|
128
|
+
id={headerId}
|
|
129
|
+
component='h2'
|
|
130
|
+
sx={{
|
|
131
|
+
fontSize: '14px',
|
|
132
|
+
fontStyle: 'normal',
|
|
133
|
+
fontWeight: 600,
|
|
134
|
+
lineHeight: '20px',
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
{title}
|
|
138
|
+
</Typography>
|
|
139
|
+
<RcSesButton
|
|
140
|
+
variant='link'
|
|
141
|
+
onClick={handleClose}
|
|
142
|
+
data-testid={testIds?.closeButton}
|
|
143
|
+
sx={{ flexShrink: 0, width: '2.75rem', height: '2.75rem' }}
|
|
144
|
+
aria-label={t('closeDrawer')}
|
|
145
|
+
>
|
|
146
|
+
<CloseIcon size={24} />
|
|
147
|
+
</RcSesButton>
|
|
148
|
+
</Box>
|
|
149
|
+
|
|
150
|
+
<Box
|
|
151
|
+
data-testid={testIds?.body}
|
|
152
|
+
sx={{
|
|
153
|
+
flex: 1,
|
|
154
|
+
overflowY: 'auto',
|
|
155
|
+
padding: '1rem 1.5rem',
|
|
156
|
+
backgroundColor: (theme) => theme.palette.grey[50],
|
|
157
|
+
}}
|
|
158
|
+
>
|
|
159
|
+
{children}
|
|
160
|
+
</Box>
|
|
161
|
+
|
|
162
|
+
{(secondaryActionLabel || primaryActionLabel) && (
|
|
163
|
+
<Box
|
|
164
|
+
data-testid={testIds?.footer}
|
|
165
|
+
sx={{
|
|
166
|
+
padding: '1rem 1.5rem',
|
|
167
|
+
borderTop: (theme) => `1px solid ${theme.palette.grey[200]}`,
|
|
168
|
+
flexShrink: 0,
|
|
169
|
+
display: 'flex',
|
|
170
|
+
alignItems: 'center',
|
|
171
|
+
justifyContent: secondaryActionLabel ? 'space-between' : 'flex-end',
|
|
172
|
+
}}
|
|
173
|
+
>
|
|
174
|
+
{secondaryActionLabel && (
|
|
175
|
+
<RcSesButton variant='link' onClick={onSecondaryAction}>
|
|
176
|
+
{secondaryActionLabel}
|
|
177
|
+
</RcSesButton>
|
|
178
|
+
)}
|
|
179
|
+
{primaryActionLabel && (
|
|
180
|
+
<RcSesButton variant='contained' onClick={onPrimaryAction}>
|
|
181
|
+
{primaryActionLabel}
|
|
182
|
+
</RcSesButton>
|
|
183
|
+
)}
|
|
184
|
+
</Box>
|
|
185
|
+
)}
|
|
186
|
+
</Box>
|
|
187
|
+
</MuiDialog>
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export default RcSesDrawer
|
|
192
|
+
export type { RcSesDrawerProps, RcSesDrawerTestIds }
|
package/src/library/index.ts
CHANGED
|
@@ -65,6 +65,7 @@ import RcSesLoader from '@/components/loaders/Loader'
|
|
|
65
65
|
import RcSesLoadingSpinner from '@/components/loaders/LoadingSpinner'
|
|
66
66
|
import RcSesBottomSheet from '@/components/overlays/BottomSheet'
|
|
67
67
|
import RcSesDialog from '@/components/overlays/Dialog'
|
|
68
|
+
import RcSesDrawer from '@/components/overlays/Drawer'
|
|
68
69
|
import RcSesModal from '@/components/overlays/Modal'
|
|
69
70
|
import RcSesTheme from '@/theme/light'
|
|
70
71
|
import RcSesPalette from '@/theme/palette'
|
|
@@ -102,6 +103,7 @@ export {
|
|
|
102
103
|
RcSesStepCard,
|
|
103
104
|
RcSesSwitch,
|
|
104
105
|
RcSesBottomSheet,
|
|
106
|
+
RcSesDrawer,
|
|
105
107
|
}
|
|
106
108
|
export { RcSesSegmentedControl }
|
|
107
109
|
export { RcSesSideNavLayout }
|
package/src/library/types.ts
CHANGED
|
@@ -59,6 +59,7 @@ import {
|
|
|
59
59
|
} from '@/components/loaders/LoadingSpinner'
|
|
60
60
|
import { RcSesBottomSheetProps } from '@/components/overlays/BottomSheet'
|
|
61
61
|
import { DialogSize, RcSesDialogProps } from '@/components/overlays/Dialog'
|
|
62
|
+
import { RcSesDrawerProps, RcSesDrawerTestIds } from '@/components/overlays/Drawer'
|
|
62
63
|
import { ModalVariant, RcSesModalProps } from '@/components/overlays/Modal'
|
|
63
64
|
import { ButtonProps } from '@/types/buttons/ButtonProps'
|
|
64
65
|
|
|
@@ -112,3 +113,4 @@ export type {
|
|
|
112
113
|
export type { RcSesDialogProps, DialogSize }
|
|
113
114
|
export type { RcSesModalProps, ModalVariant }
|
|
114
115
|
export type { RcSesBottomSheetProps }
|
|
116
|
+
export type { RcSesDrawerProps, RcSesDrawerTestIds }
|