@registrucentras/rc-ses-react-components 2.0.0-rc.2 → 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/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 +2599 -2311
- 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/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/library/index.ts +6 -0
- package/src/library/types.ts +26 -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,17 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { default as RcSesCardShell } from '../../../components/common/CardShell';
|
|
3
|
+
declare const meta: Meta<typeof RcSesCardShell>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof RcSesCardShell>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const SubcardVariant: Story;
|
|
8
|
+
export declare const BrandTheme: Story;
|
|
9
|
+
export declare const SunkenTheme: Story;
|
|
10
|
+
export declare const HeaderComplete: Story;
|
|
11
|
+
export declare const WithoutHeader: Story;
|
|
12
|
+
export declare const FooterSingleLink: Story;
|
|
13
|
+
export declare const WithoutFooter: Story;
|
|
14
|
+
export declare const ContentOnly: Story;
|
|
15
|
+
export declare const FullHeight: Story;
|
|
16
|
+
export declare const MobileViewport: Story;
|
|
17
|
+
export declare const TabletViewport: Story;
|
|
@@ -37,9 +37,116 @@ export declare const CalendarOpen: {
|
|
|
37
37
|
};
|
|
38
38
|
parameters: {
|
|
39
39
|
docs: {
|
|
40
|
+
story: {
|
|
41
|
+
inline: boolean;
|
|
42
|
+
iframeHeight: number;
|
|
43
|
+
};
|
|
40
44
|
description: {
|
|
41
45
|
story: string;
|
|
42
46
|
};
|
|
43
47
|
};
|
|
44
48
|
};
|
|
45
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Days past the 20th are out of range: they must read as greyed out, not merely
|
|
52
|
+
* be unclickable. Disabled weekends stay red.
|
|
53
|
+
*/
|
|
54
|
+
export declare const CalendarWithDisabledDates: {
|
|
55
|
+
render: (args: any) => import("react").JSX.Element;
|
|
56
|
+
parameters: {
|
|
57
|
+
docs: {
|
|
58
|
+
story: {
|
|
59
|
+
inline: boolean;
|
|
60
|
+
iframeHeight: number;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
args: {
|
|
65
|
+
clearable: boolean;
|
|
66
|
+
label: string;
|
|
67
|
+
open: boolean;
|
|
68
|
+
rules: {
|
|
69
|
+
required: boolean;
|
|
70
|
+
};
|
|
71
|
+
datepickerProps: {
|
|
72
|
+
maxDate: Date;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* A scattered rule rather than a range, so disabled days sit between selectable
|
|
78
|
+
* ones.
|
|
79
|
+
*/
|
|
80
|
+
export declare const CalendarWithDisabledRule: {
|
|
81
|
+
render: (args: any) => import("react").JSX.Element;
|
|
82
|
+
parameters: {
|
|
83
|
+
docs: {
|
|
84
|
+
story: {
|
|
85
|
+
inline: boolean;
|
|
86
|
+
iframeHeight: number;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
args: {
|
|
91
|
+
clearable: boolean;
|
|
92
|
+
label: string;
|
|
93
|
+
open: boolean;
|
|
94
|
+
rules: {
|
|
95
|
+
required: boolean;
|
|
96
|
+
};
|
|
97
|
+
datepickerProps: {
|
|
98
|
+
shouldDisableDate: (date: Date) => boolean;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Covers the `Mui-selected` day styling.
|
|
104
|
+
*/
|
|
105
|
+
export declare const CalendarWithValue: {
|
|
106
|
+
render: (args: any) => import("react").JSX.Element;
|
|
107
|
+
parameters: {
|
|
108
|
+
docs: {
|
|
109
|
+
story: {
|
|
110
|
+
inline: boolean;
|
|
111
|
+
iframeHeight: number;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
args: {
|
|
116
|
+
clearable: boolean;
|
|
117
|
+
label: string;
|
|
118
|
+
open: boolean;
|
|
119
|
+
rules: {
|
|
120
|
+
required: boolean;
|
|
121
|
+
};
|
|
122
|
+
value: string;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* The whole field disabled - a different state from a disabled day.
|
|
127
|
+
*/
|
|
128
|
+
export declare const Disabled: {
|
|
129
|
+
render: (args: any) => import("react").JSX.Element;
|
|
130
|
+
args: {
|
|
131
|
+
clearable: boolean;
|
|
132
|
+
disabled: boolean;
|
|
133
|
+
label: string;
|
|
134
|
+
rules: {
|
|
135
|
+
required: boolean;
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* The error state: input border and helper text.
|
|
141
|
+
*/
|
|
142
|
+
export declare const WithError: {
|
|
143
|
+
render: (args: any) => import("react").JSX.Element;
|
|
144
|
+
args: {
|
|
145
|
+
clearable: boolean;
|
|
146
|
+
error: string;
|
|
147
|
+
label: string;
|
|
148
|
+
rules: {
|
|
149
|
+
required: boolean;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Card surface tokens - Figma `Cards/card/*` and `Cards/subcard/*`.
|
|
3
|
+
*
|
|
4
|
+
* The boxed surface lives here rather than in the component that draws it, so
|
|
5
|
+
* anything needing a boxed row reads the same values instead of copying them.
|
|
6
|
+
* `MuiCard` keeps its own radius until `RcSesCard` is deprecated.
|
|
7
|
+
*/
|
|
8
|
+
declare const borderWidth = "1px";
|
|
9
|
+
declare const card: {
|
|
10
|
+
borderRadius: string;
|
|
11
|
+
gap: {
|
|
12
|
+
xs: string;
|
|
13
|
+
md: string;
|
|
14
|
+
};
|
|
15
|
+
padding: {
|
|
16
|
+
xs: string;
|
|
17
|
+
md: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
declare const subcard: {
|
|
21
|
+
borderRadius: string;
|
|
22
|
+
gap: {
|
|
23
|
+
xs: string;
|
|
24
|
+
md: string;
|
|
25
|
+
};
|
|
26
|
+
padding: {
|
|
27
|
+
xs: string;
|
|
28
|
+
md: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Card header values. Two of them are departures from the type scale: the title
|
|
33
|
+
* is `h6` at weight 600 rather than 500, and the description is `body2` on a
|
|
34
|
+
* 1.25rem line. The three gaps follow the surrounding components - the row gap
|
|
35
|
+
* matches the card gap and the actions gap matches the footer - rather than a
|
|
36
|
+
* measured token. All six are pending confirmation against the DS.
|
|
37
|
+
*/
|
|
38
|
+
declare const header: {
|
|
39
|
+
actionsGap: string;
|
|
40
|
+
badgeGap: string;
|
|
41
|
+
descriptionLineHeight: string;
|
|
42
|
+
gap: string;
|
|
43
|
+
rowGap: string;
|
|
44
|
+
titleFontWeight: number;
|
|
45
|
+
};
|
|
46
|
+
declare const footer: {
|
|
47
|
+
gap: string;
|
|
48
|
+
};
|
|
49
|
+
declare const themes: {
|
|
50
|
+
brand: {
|
|
51
|
+
backgroundColor: string;
|
|
52
|
+
borderColor: string;
|
|
53
|
+
};
|
|
54
|
+
default: {
|
|
55
|
+
backgroundColor: string;
|
|
56
|
+
borderColor: string;
|
|
57
|
+
};
|
|
58
|
+
sunken: {
|
|
59
|
+
backgroundColor: string;
|
|
60
|
+
borderColor: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
export { borderWidth, card, footer, header, subcard, themes };
|
|
64
|
+
declare const _default: {
|
|
65
|
+
borderWidth: string;
|
|
66
|
+
card: {
|
|
67
|
+
borderRadius: string;
|
|
68
|
+
gap: {
|
|
69
|
+
xs: string;
|
|
70
|
+
md: string;
|
|
71
|
+
};
|
|
72
|
+
padding: {
|
|
73
|
+
xs: string;
|
|
74
|
+
md: string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
footer: {
|
|
78
|
+
gap: string;
|
|
79
|
+
};
|
|
80
|
+
header: {
|
|
81
|
+
actionsGap: string;
|
|
82
|
+
badgeGap: string;
|
|
83
|
+
descriptionLineHeight: string;
|
|
84
|
+
gap: string;
|
|
85
|
+
rowGap: string;
|
|
86
|
+
titleFontWeight: number;
|
|
87
|
+
};
|
|
88
|
+
subcard: {
|
|
89
|
+
borderRadius: string;
|
|
90
|
+
gap: {
|
|
91
|
+
xs: string;
|
|
92
|
+
md: string;
|
|
93
|
+
};
|
|
94
|
+
padding: {
|
|
95
|
+
xs: string;
|
|
96
|
+
md: string;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
themes: {
|
|
100
|
+
brand: {
|
|
101
|
+
backgroundColor: string;
|
|
102
|
+
borderColor: string;
|
|
103
|
+
};
|
|
104
|
+
default: {
|
|
105
|
+
backgroundColor: string;
|
|
106
|
+
borderColor: string;
|
|
107
|
+
};
|
|
108
|
+
sunken: {
|
|
109
|
+
backgroundColor: string;
|
|
110
|
+
borderColor: string;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
export default _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PickerComponents } from '@mui/x-date-pickers/themeAugmentation';
|
|
2
|
+
/**
|
|
3
|
+
* x-date-pickers 9 gives the picker its own field components, which none of the
|
|
4
|
+
* `MuiInputBase` / `MuiOutlinedInput` slots reach. This mirrors them onto the
|
|
5
|
+
* picker slots - keep the two in step.
|
|
6
|
+
*/
|
|
7
|
+
declare const MuiPickersOutlinedInput: PickerComponents['MuiPickersOutlinedInput'];
|
|
8
|
+
export default MuiPickersOutlinedInput;
|
package/package.json
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
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 RcSesCardFooter from '.'
|
|
10
|
+
|
|
11
|
+
const renderCardFooter = (ui: ReactElement) =>
|
|
12
|
+
render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
|
|
13
|
+
|
|
14
|
+
describe('RcSesCardFooter', () => {
|
|
15
|
+
test('renders its children', () => {
|
|
16
|
+
renderCardFooter(
|
|
17
|
+
<RcSesCardFooter>
|
|
18
|
+
<button type='button'>Atšaukti</button>
|
|
19
|
+
<button type='button'>Tęsti</button>
|
|
20
|
+
</RcSesCardFooter>,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
expect(screen.getByRole('button', { name: 'Atšaukti' })).toBeInTheDocument()
|
|
24
|
+
expect(screen.getByRole('button', { name: 'Tęsti' })).toBeInTheDocument()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('defaults to pushing the first and last child apart', () => {
|
|
28
|
+
renderCardFooter(
|
|
29
|
+
<RcSesCardFooter testIds={{ root: 'footer' }}>
|
|
30
|
+
<button type='button'>Tęsti</button>
|
|
31
|
+
</RcSesCardFooter>,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
expect(screen.getByTestId('footer')).toHaveStyle({
|
|
35
|
+
justifyContent: 'space-between',
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test.each([
|
|
40
|
+
['start', 'flex-start'],
|
|
41
|
+
['between', 'space-between'],
|
|
42
|
+
['end', 'flex-end'],
|
|
43
|
+
] as const)('align="%s" maps to justify-content %s', (align, expected) => {
|
|
44
|
+
renderCardFooter(
|
|
45
|
+
<RcSesCardFooter align={align} testIds={{ root: 'footer' }}>
|
|
46
|
+
<button type='button'>Tęsti</button>
|
|
47
|
+
</RcSesCardFooter>,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
expect(screen.getByTestId('footer')).toHaveStyle({ justifyContent: expected })
|
|
51
|
+
})
|
|
52
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Stack } from '@mui/material'
|
|
2
|
+
|
|
3
|
+
import cards from '@/theme/cards'
|
|
4
|
+
|
|
5
|
+
import { CardFooterAlign, RcSesCardFooterProps } from './types'
|
|
6
|
+
|
|
7
|
+
const justifyContent: Record<CardFooterAlign, string> = {
|
|
8
|
+
between: 'space-between',
|
|
9
|
+
end: 'flex-end',
|
|
10
|
+
start: 'flex-start',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function RcSesCardFooter({
|
|
14
|
+
children,
|
|
15
|
+
align = 'between',
|
|
16
|
+
stretchOnMobile = true,
|
|
17
|
+
className,
|
|
18
|
+
testIds,
|
|
19
|
+
}: RcSesCardFooterProps) {
|
|
20
|
+
return (
|
|
21
|
+
<Stack
|
|
22
|
+
className={className}
|
|
23
|
+
data-testid={testIds?.root}
|
|
24
|
+
direction={{ xs: 'column', sm: 'row' }}
|
|
25
|
+
spacing={cards.footer.gap}
|
|
26
|
+
sx={{
|
|
27
|
+
alignItems: 'center',
|
|
28
|
+
justifyContent: justifyContent[align],
|
|
29
|
+
width: '100%',
|
|
30
|
+
...(stretchOnMobile ? { '& > *': { width: { xs: '100%', sm: 'auto' } } } : {}),
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
{children}
|
|
34
|
+
</Stack>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default RcSesCardFooter
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
export type CardFooterAlign = 'start' | 'between' | 'end'
|
|
4
|
+
|
|
5
|
+
export type RcSesCardFooterTestIds = {
|
|
6
|
+
root?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type RcSesCardFooterProps = {
|
|
10
|
+
children?: ReactNode
|
|
11
|
+
/**
|
|
12
|
+
* Horizontal distribution of the row. `between` pushes the first and last
|
|
13
|
+
* child apart, which is the cancel/continue pattern; `end` is the single
|
|
14
|
+
* primary action; `start` is a lone link such as "Žiūrėti visas".
|
|
15
|
+
*/
|
|
16
|
+
align?: CardFooterAlign
|
|
17
|
+
/**
|
|
18
|
+
* Whether direct children stretch to the full width once the row stacks.
|
|
19
|
+
* Right for buttons, wrong for a text link, which is why it is a prop.
|
|
20
|
+
*/
|
|
21
|
+
stretchOnMobile?: boolean
|
|
22
|
+
className?: string
|
|
23
|
+
testIds?: RcSesCardFooterTestIds
|
|
24
|
+
}
|
|
@@ -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
|