@registrucentras/rc-ses-react-components 2.0.0-rc.1 → 2.0.0-rc.3
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/components/common/CardShell/CardFooter/index.d.ts +3 -0
- package/dist/components/common/CardShell/CardFooter/types.d.ts +21 -0
- package/dist/components/common/CardShell/CardHeader/index.d.ts +3 -0
- package/dist/components/common/CardShell/CardHeader/types.d.ts +33 -0
- package/dist/components/common/CardShell/index.d.ts +5 -0
- package/dist/components/common/CardShell/types.d.ts +24 -0
- package/dist/components/form/inputs/Select/index.d.ts +1 -0
- package/dist/library/index.d.ts +4 -1
- package/dist/library/types.d.ts +4 -1
- package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
- package/dist/registrucentras-rc-ses-react-components.js +2634 -2319
- package/dist/stories/components/display/AdvancedList.stories.d.ts +1 -0
- package/dist/stories/components/display/CardShell.stories.d.ts +17 -0
- package/dist/stories/components/inputs/DatePicker.stories.d.ts +107 -0
- package/dist/theme/cards.d.ts +114 -0
- package/dist/theme/light/MuiPickersOutlinedInput.d.ts +8 -0
- package/package.json +1 -1
- package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.tsx +6 -2
- package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.tsx +11 -4
- package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +12 -4
- package/src/components/common/Card/index.tsx +2 -2
- package/src/components/common/CardShell/CardFooter/index.test.tsx +52 -0
- package/src/components/common/CardShell/CardFooter/index.tsx +38 -0
- package/src/components/common/CardShell/CardFooter/types.ts +24 -0
- package/src/components/common/CardShell/CardHeader/index.test.tsx +207 -0
- package/src/components/common/CardShell/CardHeader/index.tsx +104 -0
- package/src/components/common/CardShell/CardHeader/types.ts +36 -0
- package/src/components/common/CardShell/index.test.tsx +137 -0
- package/src/components/common/CardShell/index.tsx +75 -0
- package/src/components/common/CardShell/types.ts +28 -0
- package/src/components/form/inputs/Datepicker/index.test.tsx +117 -0
- package/src/components/form/inputs/FileDropzone.tsx +1 -0
- package/src/components/form/inputs/FileUpload.tsx +1 -0
- package/src/components/form/inputs/NumberStepper.tsx +1 -0
- package/src/components/form/inputs/PhoneInputFormControl/index.tsx +1 -1
- package/src/components/form/inputs/RadioButtonGroup.test.tsx +71 -0
- package/src/components/form/inputs/RadioButtonGroup.tsx +1 -0
- package/src/components/form/inputs/Select/index.test.tsx +57 -0
- package/src/components/form/inputs/Select/index.tsx +2 -0
- package/src/components/layout/Footer/index.test.tsx +13 -0
- package/src/components/layout/Footer/index.tsx +5 -2
- package/src/library/index.ts +6 -0
- package/src/library/types.ts +26 -0
- package/src/stories/components/display/AdvancedList.stories.tsx +131 -0
- package/src/stories/components/display/CardShell.stories.tsx +261 -0
- package/src/stories/components/inputs/DatePicker.stories.tsx +105 -9
- package/src/theme/cards.ts +60 -0
- package/src/theme/light/MuiPickersLayout.ts +10 -1
- package/src/theme/light/MuiPickersOutlinedInput.ts +88 -0
- package/src/theme/light/index.tsx +2 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { ThemeProvider } from '@mui/material/styles'
|
|
2
|
+
import '@testing-library/jest-dom'
|
|
3
|
+
import { render, screen } from '@testing-library/react'
|
|
4
|
+
import { type ReactElement } from 'react'
|
|
5
|
+
import { describe, expect, test } from 'vitest'
|
|
6
|
+
|
|
7
|
+
import theme from '@/theme/light'
|
|
8
|
+
|
|
9
|
+
import RcSesCardHeader from '.'
|
|
10
|
+
|
|
11
|
+
const renderCardHeader = (ui: ReactElement) =>
|
|
12
|
+
render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
|
|
13
|
+
|
|
14
|
+
describe('RcSesCardHeader', () => {
|
|
15
|
+
test('renders title and description', () => {
|
|
16
|
+
renderCardHeader(
|
|
17
|
+
<RcSesCardHeader title='Test Title' description='Test description' />,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
expect(
|
|
21
|
+
screen.getByRole('heading', { level: 3, name: 'Test Title' }),
|
|
22
|
+
).toBeInTheDocument()
|
|
23
|
+
expect(screen.getByText('Test description')).toBeInTheDocument()
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('uses default heading level 3 when not provided', () => {
|
|
27
|
+
renderCardHeader(<RcSesCardHeader title='Test Title' />)
|
|
28
|
+
|
|
29
|
+
expect(screen.getByRole('heading', { level: 3 })).toBeInTheDocument()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('respects custom headingLevel prop', () => {
|
|
33
|
+
renderCardHeader(<RcSesCardHeader title='Test Title' headingLevel={2} />)
|
|
34
|
+
|
|
35
|
+
expect(
|
|
36
|
+
screen.getByRole('heading', { level: 2, name: 'Test Title' }),
|
|
37
|
+
).toBeInTheDocument()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('omits description when not provided', () => {
|
|
41
|
+
renderCardHeader(
|
|
42
|
+
<RcSesCardHeader title='Test Title' testIds={{ description: 'description' }} />,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
expect(screen.queryByTestId('description')).not.toBeInTheDocument()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('applies testIds correctly', () => {
|
|
49
|
+
renderCardHeader(
|
|
50
|
+
<RcSesCardHeader
|
|
51
|
+
description='Test description'
|
|
52
|
+
testIds={{
|
|
53
|
+
root: 'header-root',
|
|
54
|
+
heading: 'header-heading',
|
|
55
|
+
description: 'header-desc',
|
|
56
|
+
}}
|
|
57
|
+
title='Test Title'
|
|
58
|
+
/>,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
expect(screen.getByTestId('header-root')).toBeInTheDocument()
|
|
62
|
+
expect(screen.getByTestId('header-heading')).toBeInTheDocument()
|
|
63
|
+
expect(screen.getByTestId('header-desc')).toBeInTheDocument()
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('handles ReactNode as title', () => {
|
|
67
|
+
renderCardHeader(
|
|
68
|
+
<RcSesCardHeader
|
|
69
|
+
title={
|
|
70
|
+
<span>
|
|
71
|
+
Complex <strong>Title</strong>
|
|
72
|
+
</span>
|
|
73
|
+
}
|
|
74
|
+
/>,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
expect(screen.getByRole('heading', { level: 3 })).toBeInTheDocument()
|
|
78
|
+
expect(screen.getByText('Complex')).toBeInTheDocument()
|
|
79
|
+
expect(screen.getByText('Title')).toBeInTheDocument()
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('handles ReactNode as description', () => {
|
|
83
|
+
renderCardHeader(
|
|
84
|
+
<RcSesCardHeader
|
|
85
|
+
description={
|
|
86
|
+
<span>
|
|
87
|
+
Description with <em>emphasis</em>
|
|
88
|
+
</span>
|
|
89
|
+
}
|
|
90
|
+
title='Test Title'
|
|
91
|
+
/>,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
expect(screen.getByText('Description with')).toBeInTheDocument()
|
|
95
|
+
expect(screen.getByText('emphasis')).toBeInTheDocument()
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('heading levels 2 through 6 render correctly', () => {
|
|
99
|
+
const levels = [2, 3, 4, 5, 6] as const
|
|
100
|
+
|
|
101
|
+
levels.forEach((level) => {
|
|
102
|
+
const { unmount } = renderCardHeader(
|
|
103
|
+
<RcSesCardHeader headingLevel={level} title={`Level ${level} Title`} />,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
expect(
|
|
107
|
+
screen.getByRole('heading', { level, name: `Level ${level} Title` }),
|
|
108
|
+
).toBeInTheDocument()
|
|
109
|
+
unmount()
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('title and description keep the design type ramp', () => {
|
|
114
|
+
renderCardHeader(
|
|
115
|
+
<RcSesCardHeader
|
|
116
|
+
description='Test description'
|
|
117
|
+
testIds={{ description: 'description' }}
|
|
118
|
+
title='Test Title'
|
|
119
|
+
/>,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
expect(screen.getByText('Test Title')).toHaveStyle({
|
|
123
|
+
fontSize: '1.125rem',
|
|
124
|
+
fontWeight: '600',
|
|
125
|
+
lineHeight: '1.5rem',
|
|
126
|
+
})
|
|
127
|
+
expect(screen.getByTestId('description')).toHaveStyle({
|
|
128
|
+
fontSize: '0.875rem',
|
|
129
|
+
lineHeight: '1.25rem',
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
test('count renders a badge inside the heading accessible name', () => {
|
|
134
|
+
renderCardHeader(<RcSesCardHeader count={4} title='Pasirinktos teisės' />)
|
|
135
|
+
|
|
136
|
+
expect(
|
|
137
|
+
screen.getByRole('heading', { level: 3, name: 'Pasirinktos teisės 4' }),
|
|
138
|
+
).toBeInTheDocument()
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('count of zero still renders the badge', () => {
|
|
142
|
+
renderCardHeader(
|
|
143
|
+
<RcSesCardHeader
|
|
144
|
+
count={0}
|
|
145
|
+
testIds={{ badge: 'badge' }}
|
|
146
|
+
title='Pasirinktos teisės'
|
|
147
|
+
/>,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
expect(screen.getByTestId('badge')).toHaveTextContent('0')
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
test('omits the badge when count is not provided', () => {
|
|
154
|
+
renderCardHeader(<RcSesCardHeader testIds={{ badge: 'badge' }} title='Test Title' />)
|
|
155
|
+
|
|
156
|
+
expect(screen.queryByTestId('badge')).not.toBeInTheDocument()
|
|
157
|
+
expect(
|
|
158
|
+
screen.getByRole('heading', { level: 3, name: 'Test Title' }),
|
|
159
|
+
).toBeInTheDocument()
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
test('icon is decorative and stays out of the accessible name', () => {
|
|
163
|
+
renderCardHeader(
|
|
164
|
+
<RcSesCardHeader
|
|
165
|
+
icon={<span>dekoracija</span>}
|
|
166
|
+
testIds={{ icon: 'icon' }}
|
|
167
|
+
title='Test Title'
|
|
168
|
+
/>,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
expect(screen.getByTestId('icon')).toHaveAttribute('aria-hidden', 'true')
|
|
172
|
+
expect(
|
|
173
|
+
screen.getByRole('heading', { level: 3, name: 'Test Title' }),
|
|
174
|
+
).toBeInTheDocument()
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test('renders up to two actions at the end of the row', () => {
|
|
178
|
+
renderCardHeader(
|
|
179
|
+
<RcSesCardHeader
|
|
180
|
+
actions={
|
|
181
|
+
<>
|
|
182
|
+
<button type='button'>Atšaukti</button>
|
|
183
|
+
<button type='button'>Tęsti</button>
|
|
184
|
+
</>
|
|
185
|
+
}
|
|
186
|
+
testIds={{ actions: 'actions' }}
|
|
187
|
+
title='Test Title'
|
|
188
|
+
/>,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
const actions = screen.getByTestId('actions')
|
|
192
|
+
expect(actions).toContainElement(screen.getByRole('button', { name: 'Atšaukti' }))
|
|
193
|
+
expect(actions).toContainElement(screen.getByRole('button', { name: 'Tęsti' }))
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
test('omits the icon and actions slots when not provided', () => {
|
|
197
|
+
renderCardHeader(
|
|
198
|
+
<RcSesCardHeader
|
|
199
|
+
testIds={{ actions: 'actions', icon: 'icon' }}
|
|
200
|
+
title='Test Title'
|
|
201
|
+
/>,
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
expect(screen.queryByTestId('icon')).not.toBeInTheDocument()
|
|
205
|
+
expect(screen.queryByTestId('actions')).not.toBeInTheDocument()
|
|
206
|
+
})
|
|
207
|
+
})
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Box, Stack, Typography } from '@mui/material'
|
|
2
|
+
|
|
3
|
+
import RcSesBadge from '@/components/common/Badge'
|
|
4
|
+
import cards from '@/theme/cards'
|
|
5
|
+
import palette from '@/theme/palette'
|
|
6
|
+
|
|
7
|
+
import { RcSesCardHeaderProps } from './types'
|
|
8
|
+
|
|
9
|
+
function RcSesCardHeader({
|
|
10
|
+
title,
|
|
11
|
+
headingLevel = 3,
|
|
12
|
+
icon,
|
|
13
|
+
count,
|
|
14
|
+
description,
|
|
15
|
+
actions,
|
|
16
|
+
className,
|
|
17
|
+
testIds,
|
|
18
|
+
}: RcSesCardHeaderProps) {
|
|
19
|
+
const HeadingTag = `h${headingLevel}` as 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
|
|
20
|
+
const hasCount = count !== undefined && count !== null
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<Stack
|
|
24
|
+
className={className}
|
|
25
|
+
data-testid={testIds?.root}
|
|
26
|
+
direction='row'
|
|
27
|
+
spacing={cards.header.rowGap}
|
|
28
|
+
sx={{ alignItems: 'flex-start', width: '100%' }}
|
|
29
|
+
>
|
|
30
|
+
{icon ? (
|
|
31
|
+
<Box
|
|
32
|
+
aria-hidden
|
|
33
|
+
data-testid={testIds?.icon}
|
|
34
|
+
sx={{ display: 'flex', flexShrink: 0 }}
|
|
35
|
+
>
|
|
36
|
+
{icon}
|
|
37
|
+
</Box>
|
|
38
|
+
) : null}
|
|
39
|
+
|
|
40
|
+
<Stack spacing={cards.header.gap} sx={{ flex: 1, minWidth: 0 }}>
|
|
41
|
+
<HeadingTag data-testid={testIds?.heading} style={{ margin: 0 }}>
|
|
42
|
+
<Typography
|
|
43
|
+
component='span'
|
|
44
|
+
variant='h6'
|
|
45
|
+
sx={{
|
|
46
|
+
color: palette.grey[900],
|
|
47
|
+
// inline only when the badge has to sit on the heading's last line
|
|
48
|
+
display: hasCount ? 'inline' : 'block',
|
|
49
|
+
fontWeight: cards.header.titleFontWeight,
|
|
50
|
+
overflowWrap: 'anywhere',
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
{title}
|
|
54
|
+
</Typography>
|
|
55
|
+
|
|
56
|
+
{hasCount ? (
|
|
57
|
+
<Box
|
|
58
|
+
component='span'
|
|
59
|
+
data-testid={testIds?.badge}
|
|
60
|
+
sx={{
|
|
61
|
+
display: 'inline-flex',
|
|
62
|
+
ml: cards.header.badgeGap,
|
|
63
|
+
verticalAlign: 'middle',
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
<RcSesBadge
|
|
67
|
+
label={String(count)}
|
|
68
|
+
showIcon={false}
|
|
69
|
+
size='small'
|
|
70
|
+
variant='neutral'
|
|
71
|
+
/>
|
|
72
|
+
</Box>
|
|
73
|
+
) : null}
|
|
74
|
+
</HeadingTag>
|
|
75
|
+
|
|
76
|
+
{description !== undefined && description !== null ? (
|
|
77
|
+
<Typography
|
|
78
|
+
data-testid={testIds?.description}
|
|
79
|
+
variant='body2'
|
|
80
|
+
sx={{
|
|
81
|
+
color: palette.grey[700],
|
|
82
|
+
lineHeight: cards.header.descriptionLineHeight,
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
{description}
|
|
86
|
+
</Typography>
|
|
87
|
+
) : null}
|
|
88
|
+
</Stack>
|
|
89
|
+
|
|
90
|
+
{actions ? (
|
|
91
|
+
<Stack
|
|
92
|
+
data-testid={testIds?.actions}
|
|
93
|
+
direction='row'
|
|
94
|
+
spacing={cards.header.actionsGap}
|
|
95
|
+
sx={{ alignItems: 'center', flexShrink: 0 }}
|
|
96
|
+
>
|
|
97
|
+
{actions}
|
|
98
|
+
</Stack>
|
|
99
|
+
) : null}
|
|
100
|
+
</Stack>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export default RcSesCardHeader
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
export type CardHeadingLevel = 2 | 3 | 4 | 5 | 6
|
|
4
|
+
|
|
5
|
+
export type RcSesCardHeaderTestIds = {
|
|
6
|
+
root?: string
|
|
7
|
+
icon?: string
|
|
8
|
+
heading?: string
|
|
9
|
+
badge?: string
|
|
10
|
+
description?: string
|
|
11
|
+
actions?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type RcSesCardHeaderProps = {
|
|
15
|
+
title: ReactNode
|
|
16
|
+
headingLevel?: CardHeadingLevel
|
|
17
|
+
/**
|
|
18
|
+
* Decorative leading visual, `Icon-tile` once SAV-6476 lands. Rendered
|
|
19
|
+
* `aria-hidden`, so it never contributes to the heading's accessible name.
|
|
20
|
+
*/
|
|
21
|
+
icon?: ReactNode
|
|
22
|
+
/**
|
|
23
|
+
* Count rendered as a Neutral/Small `Badge` inside the heading, so it is
|
|
24
|
+
* announced together with the title. Intended for short section headings.
|
|
25
|
+
*/
|
|
26
|
+
count?: number
|
|
27
|
+
description?: ReactNode
|
|
28
|
+
/**
|
|
29
|
+
* Up to two CTAs, rendered at the end of the header row. A trailing
|
|
30
|
+
* affordance such as the Category-tile chevron is not a CTA and will need its
|
|
31
|
+
* own slot.
|
|
32
|
+
*/
|
|
33
|
+
actions?: ReactNode
|
|
34
|
+
className?: string
|
|
35
|
+
testIds?: RcSesCardHeaderTestIds
|
|
36
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Box, Typography } from '@mui/material'
|
|
2
|
+
import { ThemeProvider } from '@mui/material/styles'
|
|
3
|
+
import '@testing-library/jest-dom'
|
|
4
|
+
import { render, screen } from '@testing-library/react'
|
|
5
|
+
import { type ReactElement } from 'react'
|
|
6
|
+
import { describe, expect, test } from 'vitest'
|
|
7
|
+
|
|
8
|
+
import RcSesButton from '@/components/common/Button'
|
|
9
|
+
import theme from '@/theme/light'
|
|
10
|
+
|
|
11
|
+
import RcSesCardShell from '.'
|
|
12
|
+
|
|
13
|
+
const renderCard = (ui: ReactElement) =>
|
|
14
|
+
render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
|
|
15
|
+
|
|
16
|
+
describe('RcSesCardShell', () => {
|
|
17
|
+
test('renders header, content and footer slots when provided', () => {
|
|
18
|
+
renderCard(
|
|
19
|
+
<RcSesCardShell
|
|
20
|
+
header={
|
|
21
|
+
<Box>
|
|
22
|
+
<Typography variant='h5' component='h3' sx={{ mb: 2.5 }}>
|
|
23
|
+
Kortelės antraštė
|
|
24
|
+
</Typography>
|
|
25
|
+
<Typography variant='body2' color='text.secondary'>
|
|
26
|
+
Paaiškinimas apie šios kortelės turinį
|
|
27
|
+
</Typography>
|
|
28
|
+
</Box>
|
|
29
|
+
}
|
|
30
|
+
footer={
|
|
31
|
+
<>
|
|
32
|
+
<RcSesButton color='grey' variant='outlined'>
|
|
33
|
+
Atšaukti
|
|
34
|
+
</RcSesButton>
|
|
35
|
+
<RcSesButton>Tęsti</RcSesButton>
|
|
36
|
+
</>
|
|
37
|
+
}
|
|
38
|
+
>
|
|
39
|
+
<div>Turinys</div>
|
|
40
|
+
</RcSesCardShell>,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
expect(
|
|
44
|
+
screen.getByRole('heading', { level: 3, name: 'Kortelės antraštė' }),
|
|
45
|
+
).toBeInTheDocument()
|
|
46
|
+
expect(screen.getByText('Paaiškinimas apie šios kortelės turinį')).toBeInTheDocument()
|
|
47
|
+
expect(screen.getByText('Turinys')).toBeInTheDocument()
|
|
48
|
+
expect(screen.getByRole('button', { name: 'Tęsti' })).toBeInTheDocument()
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('header slot is OFF when not provided (free-form slot content)', () => {
|
|
52
|
+
renderCard(
|
|
53
|
+
<RcSesCardShell testIds={{ header: 'card-header' }}>
|
|
54
|
+
<div>Laisvos formos turinys</div>
|
|
55
|
+
</RcSesCardShell>,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
expect(screen.queryByTestId('card-header')).not.toBeInTheDocument()
|
|
59
|
+
expect(screen.queryByRole('heading')).not.toBeInTheDocument()
|
|
60
|
+
expect(screen.getByText('Laisvos formos turinys')).toBeInTheDocument()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('omits content slot when no children provided', () => {
|
|
64
|
+
renderCard(
|
|
65
|
+
<RcSesCardShell header={<h3>Antraštė</h3>} testIds={{ content: 'card-content' }} />,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
expect(screen.queryByTestId('card-content')).not.toBeInTheDocument()
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test('omits footer when not provided', () => {
|
|
72
|
+
renderCard(
|
|
73
|
+
<RcSesCardShell
|
|
74
|
+
testIds={{ footer: 'card-footer', root: 'card-root' }}
|
|
75
|
+
variant='subcard'
|
|
76
|
+
>
|
|
77
|
+
<div>Turinys</div>
|
|
78
|
+
</RcSesCardShell>,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
expect(screen.getByTestId('card-root')).toBeInTheDocument()
|
|
82
|
+
expect(screen.queryByTestId('card-footer')).not.toBeInTheDocument()
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('fullHeight stretches the card and grows the content slot', () => {
|
|
86
|
+
renderCard(
|
|
87
|
+
<RcSesCardShell fullHeight testIds={{ content: 'card-content', root: 'card-root' }}>
|
|
88
|
+
<div>Turinys</div>
|
|
89
|
+
</RcSesCardShell>,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
expect(screen.getByTestId('card-root')).toHaveStyle({ height: '100%' })
|
|
93
|
+
expect(screen.getByTestId('card-content')).toHaveStyle({ flexGrow: '1' })
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('variant="card" applies larger border-radius', () => {
|
|
97
|
+
renderCard(
|
|
98
|
+
<RcSesCardShell variant='card' testIds={{ root: 'card-root' }}>
|
|
99
|
+
<div>Turinys</div>
|
|
100
|
+
</RcSesCardShell>,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
const card = screen.getByTestId('card-root')
|
|
104
|
+
expect(card).toHaveStyle({ borderRadius: '0.75rem' })
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('variant="subcard" applies smaller border-radius', () => {
|
|
108
|
+
renderCard(
|
|
109
|
+
<RcSesCardShell variant='subcard' testIds={{ root: 'card-root' }}>
|
|
110
|
+
<div>Turinys</div>
|
|
111
|
+
</RcSesCardShell>,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
const card = screen.getByTestId('card-root')
|
|
115
|
+
expect(card).toHaveStyle({ borderRadius: '0.5rem' })
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
test.each([
|
|
119
|
+
['default', '#ffffff', '#c5cad1'],
|
|
120
|
+
['brand', '#f3fbfe', '#b9e9fa'],
|
|
121
|
+
['sunken', '#f0f2f5', '#dce0e5'],
|
|
122
|
+
] as const)(
|
|
123
|
+
'theme=%s paints its own background and border',
|
|
124
|
+
(name, background, border) => {
|
|
125
|
+
renderCard(
|
|
126
|
+
<RcSesCardShell theme={name} testIds={{ root: 'card-root' }}>
|
|
127
|
+
<div>Turinys</div>
|
|
128
|
+
</RcSesCardShell>,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
expect(screen.getByTestId('card-root')).toHaveStyle({
|
|
132
|
+
backgroundColor: background,
|
|
133
|
+
borderColor: border,
|
|
134
|
+
})
|
|
135
|
+
},
|
|
136
|
+
)
|
|
137
|
+
})
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Box, BoxProps } from '@mui/material'
|
|
2
|
+
import { ReactNode } from 'react'
|
|
3
|
+
|
|
4
|
+
import cards from '@/theme/cards'
|
|
5
|
+
|
|
6
|
+
import { RcSesCardShellProps } from './types'
|
|
7
|
+
|
|
8
|
+
// A conditional slot renders as false rather than as nothing, so false is absent
|
|
9
|
+
const hasSlot = (node: ReactNode) => node !== undefined && node !== null && node !== false
|
|
10
|
+
|
|
11
|
+
type ShellProps = RcSesCardShellProps &
|
|
12
|
+
Omit<BoxProps, keyof RcSesCardShellProps | 'children'>
|
|
13
|
+
|
|
14
|
+
function RcSesCardShell({
|
|
15
|
+
variant = 'card',
|
|
16
|
+
theme = 'default',
|
|
17
|
+
fullHeight = false,
|
|
18
|
+
header,
|
|
19
|
+
children,
|
|
20
|
+
footer,
|
|
21
|
+
className,
|
|
22
|
+
testIds,
|
|
23
|
+
sx,
|
|
24
|
+
...boxProps
|
|
25
|
+
}: ShellProps) {
|
|
26
|
+
return (
|
|
27
|
+
<Box
|
|
28
|
+
{...boxProps}
|
|
29
|
+
className={className}
|
|
30
|
+
data-testid={testIds?.root}
|
|
31
|
+
sx={[
|
|
32
|
+
{
|
|
33
|
+
display: 'flex',
|
|
34
|
+
flexDirection: 'column',
|
|
35
|
+
height: fullHeight ? '100%' : 'auto',
|
|
36
|
+
minWidth: 0,
|
|
37
|
+
// enables stretched-link pattern in interactive compositions
|
|
38
|
+
position: 'relative',
|
|
39
|
+
backgroundColor: cards.themes[theme].backgroundColor,
|
|
40
|
+
border: `${cards.borderWidth} solid ${cards.themes[theme].borderColor}`,
|
|
41
|
+
borderRadius: cards[variant].borderRadius,
|
|
42
|
+
gap: cards[variant].gap,
|
|
43
|
+
p: cards[variant].padding,
|
|
44
|
+
},
|
|
45
|
+
...(Array.isArray(sx) ? sx : [sx]),
|
|
46
|
+
]}
|
|
47
|
+
>
|
|
48
|
+
{hasSlot(header) ? (
|
|
49
|
+
<Box data-testid={testIds?.header} sx={{ minWidth: 0, width: '100%' }}>
|
|
50
|
+
{header}
|
|
51
|
+
</Box>
|
|
52
|
+
) : null}
|
|
53
|
+
|
|
54
|
+
{hasSlot(children) ? (
|
|
55
|
+
<Box
|
|
56
|
+
data-testid={testIds?.content}
|
|
57
|
+
sx={{ flexGrow: fullHeight ? 1 : 0, minWidth: 0, width: '100%' }}
|
|
58
|
+
>
|
|
59
|
+
{children}
|
|
60
|
+
</Box>
|
|
61
|
+
) : null}
|
|
62
|
+
|
|
63
|
+
{hasSlot(footer) ? (
|
|
64
|
+
<Box
|
|
65
|
+
data-testid={testIds?.footer}
|
|
66
|
+
sx={{ minWidth: 0, mt: fullHeight ? 'auto' : 0, width: '100%' }}
|
|
67
|
+
>
|
|
68
|
+
{footer}
|
|
69
|
+
</Box>
|
|
70
|
+
) : null}
|
|
71
|
+
</Box>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default RcSesCardShell
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
export type CardShellVariant = 'card' | 'subcard'
|
|
4
|
+
|
|
5
|
+
export type CardShellTheme = 'default' | 'brand' | 'sunken'
|
|
6
|
+
|
|
7
|
+
export type RcSesCardShellTestIds = {
|
|
8
|
+
root?: string
|
|
9
|
+
header?: string
|
|
10
|
+
content?: string
|
|
11
|
+
footer?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type RcSesCardShellProps = {
|
|
15
|
+
variant?: CardShellVariant
|
|
16
|
+
theme?: CardShellTheme
|
|
17
|
+
fullHeight?: boolean
|
|
18
|
+
/** Header row, normally `RcSesCardHeader`. The shell only provides the slot. */
|
|
19
|
+
header?: ReactNode
|
|
20
|
+
children?: ReactNode
|
|
21
|
+
/**
|
|
22
|
+
* Footer row, normally `RcSesCardFooter`. The shell only provides the slot, so
|
|
23
|
+
* direction and alignment belong to the footer block rather than here.
|
|
24
|
+
*/
|
|
25
|
+
footer?: ReactNode
|
|
26
|
+
className?: string
|
|
27
|
+
testIds?: RcSesCardShellTestIds
|
|
28
|
+
}
|