uikit-react-public 0.40.3 → 0.41.0
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/BreadcrumbsNew/BaseBreadcrumbsItem.d.ts +1 -2
- package/dist/components/BreadcrumbsNew/BreadcrumbsLink.d.ts +3 -1
- package/dist/components/ProgressBar/ProgressBar.d.ts +24 -0
- package/dist/components/ProgressBar/ProgressBar.stories.d.ts +77 -0
- package/dist/components/ProgressBar/__tests__/ProgressBar.test.d.ts +1 -0
- package/dist/components/ProgressBar/index.d.ts +2 -0
- package/dist/components/Table/Table.context.d.ts +2 -0
- package/dist/components/Table/Table.d.ts +1 -1
- package/dist/components/Table/Table.stories.d.ts +1 -1
- package/dist/components/Table/Table.types.d.ts +2 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/index.js +5717 -5554
- package/lib/components/BreadcrumbsNew/BaseBreadcrumbsItem.tsx +0 -9
- package/lib/components/BreadcrumbsNew/BreadcrumbsLink.tsx +23 -6
- package/lib/components/BreadcrumbsNew/__tests__/Breadcrumbs.test.tsx +3 -0
- package/lib/components/ProgressBar/ProgressBar.stories.tsx +131 -0
- package/lib/components/ProgressBar/ProgressBar.tsx +220 -0
- package/lib/components/ProgressBar/__tests__/ProgressBar.test.tsx +120 -0
- package/lib/components/ProgressBar/index.ts +6 -0
- package/lib/components/Table/Table.context.ts +10 -1
- package/lib/components/Table/Table.tsx +8 -3
- package/lib/components/Table/Table.types.ts +2 -0
- package/lib/components/Table/__tests__/Table.test.tsx +90 -0
- package/lib/components/Table/subcomponents/Body.tsx +7 -1
- package/lib/components/Table/subcomponents/Cell/Cell.tsx +22 -18
- package/lib/components/Table/subcomponents/Cell/CellContent.tsx +11 -5
- package/lib/components/Table/subcomponents/Head.tsx +7 -1
- package/lib/components/Table/subcomponents/Row.tsx +10 -6
- package/lib/components/index.ts +7 -0
- package/package.json +1 -1
|
@@ -8,7 +8,6 @@ export const NAME = 'ucl-uikit-breadcrumbs__item';
|
|
|
8
8
|
|
|
9
9
|
export interface BaseBreadcrumbsItemProps extends LiHTMLAttributes<HTMLLIElement> {
|
|
10
10
|
separator?: boolean;
|
|
11
|
-
back?: boolean;
|
|
12
11
|
size?: BreadcrumbsSize;
|
|
13
12
|
testId?: string;
|
|
14
13
|
children?: ReactNode;
|
|
@@ -16,7 +15,6 @@ export interface BaseBreadcrumbsItemProps extends LiHTMLAttributes<HTMLLIElement
|
|
|
16
15
|
|
|
17
16
|
const BaseBreadcrumbsItem = ({
|
|
18
17
|
separator = false,
|
|
19
|
-
back = false,
|
|
20
18
|
size = 'medium',
|
|
21
19
|
testId = NAME,
|
|
22
20
|
className,
|
|
@@ -47,13 +45,6 @@ const BaseBreadcrumbsItem = ({
|
|
|
47
45
|
data-testid={testId}
|
|
48
46
|
{...props}
|
|
49
47
|
>
|
|
50
|
-
{back && (
|
|
51
|
-
<Icon.ArrowLeft
|
|
52
|
-
aria-hidden
|
|
53
|
-
className={iconStyle}
|
|
54
|
-
size={size === 'small' ? 16 : 20}
|
|
55
|
-
/>
|
|
56
|
-
)}
|
|
57
48
|
{children}
|
|
58
49
|
{separator && (
|
|
59
50
|
<Icon.ChevronRight
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Children, isValidElement, ReactNode } from 'react';
|
|
2
2
|
import { css, cx } from '@emotion/css';
|
|
3
|
+
import Icon from '../Icon';
|
|
3
4
|
import StandaloneLink, { StandaloneLinkProps } from '../StandaloneLink';
|
|
4
5
|
import { useTheme } from '../../theme';
|
|
5
6
|
import BaseBreadcrumbsItem, {
|
|
@@ -10,8 +11,10 @@ export const NAME = 'ucl-uikit-breadcrumbs__link';
|
|
|
10
11
|
|
|
11
12
|
type BreadcrumbsLinkOwnProps = Pick<
|
|
12
13
|
BaseBreadcrumbsItemProps,
|
|
13
|
-
'separator' | '
|
|
14
|
-
|
|
14
|
+
'separator' | 'size'
|
|
15
|
+
> & {
|
|
16
|
+
back?: boolean;
|
|
17
|
+
};
|
|
15
18
|
|
|
16
19
|
export type BreadcrumbsLinkProps = BreadcrumbsLinkOwnProps &
|
|
17
20
|
Omit<StandaloneLinkProps, 'size' | 'variant'>;
|
|
@@ -45,9 +48,15 @@ const BreadcrumbsLink = ({
|
|
|
45
48
|
: theme.typography.body.mdSemibold.fontWeight;
|
|
46
49
|
|
|
47
50
|
const linkStyle = css`
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
${
|
|
52
|
+
back
|
|
53
|
+
? ''
|
|
54
|
+
: `
|
|
55
|
+
flex-direction: column;
|
|
56
|
+
align-items: flex-start;
|
|
57
|
+
gap: 0;
|
|
58
|
+
`
|
|
59
|
+
}
|
|
51
60
|
|
|
52
61
|
&::after {
|
|
53
62
|
content: attr(data-breadcrumb-label);
|
|
@@ -62,11 +71,19 @@ const BreadcrumbsLink = ({
|
|
|
62
71
|
return (
|
|
63
72
|
<BaseBreadcrumbsItem
|
|
64
73
|
separator={separator}
|
|
65
|
-
back={back}
|
|
66
74
|
size={size}
|
|
67
75
|
>
|
|
68
76
|
<StandaloneLink
|
|
69
77
|
className={cx(NAME, linkStyle, className)}
|
|
78
|
+
icon={
|
|
79
|
+
back ? (
|
|
80
|
+
<Icon.ArrowLeft
|
|
81
|
+
aria-hidden
|
|
82
|
+
width={size === 'small' ? 16 : 20}
|
|
83
|
+
height={size === 'small' ? 16 : 20}
|
|
84
|
+
/>
|
|
85
|
+
) : undefined
|
|
86
|
+
}
|
|
70
87
|
variant='secondary'
|
|
71
88
|
noVisited
|
|
72
89
|
size={size === 'small' ? 'small' : 'default'}
|
|
@@ -30,6 +30,9 @@ describe('BreadcrumbsNew', () => {
|
|
|
30
30
|
expect(
|
|
31
31
|
within(lists[1]).getByRole('link', { hidden: true })
|
|
32
32
|
).toHaveAttribute('href', '/parent');
|
|
33
|
+
expect(
|
|
34
|
+
within(lists[1]).getByRole('link', { hidden: true }).querySelector('svg')
|
|
35
|
+
).toBeTruthy();
|
|
33
36
|
const parentLink = within(lists[0]).getByRole('link', {
|
|
34
37
|
name: 'Parent',
|
|
35
38
|
hidden: true,
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { css } from '@emotion/css';
|
|
3
|
+
import ProgressBar, {
|
|
4
|
+
type ProgressBarSize,
|
|
5
|
+
type ProgressBarVariant,
|
|
6
|
+
} from './ProgressBar';
|
|
7
|
+
|
|
8
|
+
const VARIANTS: ProgressBarVariant[] = [
|
|
9
|
+
'info',
|
|
10
|
+
'success',
|
|
11
|
+
'critical',
|
|
12
|
+
'warning',
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
const SIZES: ProgressBarSize[] = ['small', 'large'];
|
|
16
|
+
|
|
17
|
+
const meta = {
|
|
18
|
+
title: 'Components/ProgressBar',
|
|
19
|
+
component: ProgressBar,
|
|
20
|
+
parameters: {
|
|
21
|
+
layout: 'centered',
|
|
22
|
+
},
|
|
23
|
+
argTypes: {
|
|
24
|
+
value: { control: { type: 'number', min: 0, max: 100 } },
|
|
25
|
+
max: { control: { type: 'number', min: 1 } },
|
|
26
|
+
variant: {
|
|
27
|
+
options: VARIANTS,
|
|
28
|
+
control: { type: 'radio' },
|
|
29
|
+
},
|
|
30
|
+
size: {
|
|
31
|
+
options: SIZES,
|
|
32
|
+
control: { type: 'radio' },
|
|
33
|
+
},
|
|
34
|
+
title: { control: { type: 'text' } },
|
|
35
|
+
label: { control: { type: 'text' } },
|
|
36
|
+
valueLabel: { control: { type: 'text' } },
|
|
37
|
+
testId: { control: { type: 'text' } },
|
|
38
|
+
className: { control: false },
|
|
39
|
+
},
|
|
40
|
+
args: {
|
|
41
|
+
value: 50,
|
|
42
|
+
max: 100,
|
|
43
|
+
variant: 'info',
|
|
44
|
+
size: 'small',
|
|
45
|
+
title: 'Uploading file',
|
|
46
|
+
valueLabel: '50%',
|
|
47
|
+
label: 'Uploading... 50%',
|
|
48
|
+
'aria-label': 'Uploading file',
|
|
49
|
+
},
|
|
50
|
+
tags: ['autodocs'],
|
|
51
|
+
} satisfies Meta<typeof ProgressBar>;
|
|
52
|
+
|
|
53
|
+
export default meta;
|
|
54
|
+
type Story = StoryObj<typeof meta>;
|
|
55
|
+
|
|
56
|
+
export const Default: Story = {};
|
|
57
|
+
|
|
58
|
+
export const Large: Story = {
|
|
59
|
+
args: {
|
|
60
|
+
size: 'large',
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const Indeterminate: Story = {
|
|
65
|
+
args: {
|
|
66
|
+
value: undefined,
|
|
67
|
+
valueLabel: undefined,
|
|
68
|
+
label: 'Loading...',
|
|
69
|
+
'aria-label': 'Loading',
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const stackStyle = css`
|
|
74
|
+
display: flex;
|
|
75
|
+
flex-direction: column;
|
|
76
|
+
gap: 20px;
|
|
77
|
+
width: 360px;
|
|
78
|
+
`;
|
|
79
|
+
|
|
80
|
+
const rowStyle = css`
|
|
81
|
+
display: flex;
|
|
82
|
+
flex-direction: column;
|
|
83
|
+
gap: 8px;
|
|
84
|
+
`;
|
|
85
|
+
|
|
86
|
+
const labelStyle = css`
|
|
87
|
+
font-family: sans-serif;
|
|
88
|
+
font-size: 12px;
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
export const Variants: Story = {
|
|
92
|
+
parameters: { layout: 'padded' },
|
|
93
|
+
render: () => (
|
|
94
|
+
<div className={stackStyle}>
|
|
95
|
+
{VARIANTS.map((variant) => (
|
|
96
|
+
<div
|
|
97
|
+
key={variant}
|
|
98
|
+
className={rowStyle}
|
|
99
|
+
>
|
|
100
|
+
<span className={labelStyle}>{variant}</span>
|
|
101
|
+
<ProgressBar
|
|
102
|
+
value={50}
|
|
103
|
+
variant={variant}
|
|
104
|
+
aria-label={`${variant} progress`}
|
|
105
|
+
/>
|
|
106
|
+
</div>
|
|
107
|
+
))}
|
|
108
|
+
</div>
|
|
109
|
+
),
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const Sizes: Story = {
|
|
113
|
+
parameters: { layout: 'padded' },
|
|
114
|
+
render: () => (
|
|
115
|
+
<div className={stackStyle}>
|
|
116
|
+
{SIZES.map((size) => (
|
|
117
|
+
<div
|
|
118
|
+
key={size}
|
|
119
|
+
className={rowStyle}
|
|
120
|
+
>
|
|
121
|
+
<span className={labelStyle}>{size}</span>
|
|
122
|
+
<ProgressBar
|
|
123
|
+
value={70}
|
|
124
|
+
size={size}
|
|
125
|
+
aria-label={`${size} progress`}
|
|
126
|
+
/>
|
|
127
|
+
</div>
|
|
128
|
+
))}
|
|
129
|
+
</div>
|
|
130
|
+
),
|
|
131
|
+
};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { HTMLAttributes, ReactNode, Ref, memo, useId } from 'react';
|
|
2
|
+
import { css, cx } from '@emotion/css';
|
|
3
|
+
import useTheme from '../../theme/useTheme';
|
|
4
|
+
import type { ThemeType } from '../../theme';
|
|
5
|
+
import marginsStyle, { MarginProps } from '../common/marginsStyle';
|
|
6
|
+
import Text from '../Text';
|
|
7
|
+
|
|
8
|
+
export const NAME = 'ucl-uikit-progress-bar';
|
|
9
|
+
|
|
10
|
+
export type ProgressBarVariant = 'info' | 'success' | 'critical' | 'warning';
|
|
11
|
+
|
|
12
|
+
export type ProgressBarSize = 'small' | 'large';
|
|
13
|
+
|
|
14
|
+
export interface ProgressBarBaseProps extends Omit<
|
|
15
|
+
HTMLAttributes<HTMLDivElement>,
|
|
16
|
+
| 'children'
|
|
17
|
+
| 'title'
|
|
18
|
+
| 'aria-label'
|
|
19
|
+
| 'aria-labelledby'
|
|
20
|
+
| 'aria-describedby'
|
|
21
|
+
| 'role'
|
|
22
|
+
> {
|
|
23
|
+
value?: number | null;
|
|
24
|
+
max?: number;
|
|
25
|
+
variant?: ProgressBarVariant;
|
|
26
|
+
size?: ProgressBarSize;
|
|
27
|
+
title?: ReactNode;
|
|
28
|
+
label?: ReactNode;
|
|
29
|
+
valueLabel?: ReactNode;
|
|
30
|
+
testId?: string;
|
|
31
|
+
ref?: Ref<HTMLDivElement>;
|
|
32
|
+
'aria-label'?: string;
|
|
33
|
+
'aria-labelledby'?: string;
|
|
34
|
+
'aria-describedby'?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type ProgressBarProps = ProgressBarBaseProps & MarginProps;
|
|
38
|
+
|
|
39
|
+
export const getProgressBarVariantColour = (
|
|
40
|
+
theme: ThemeType,
|
|
41
|
+
variant: ProgressBarVariant
|
|
42
|
+
) =>
|
|
43
|
+
({
|
|
44
|
+
info: theme.colour.fill.brand,
|
|
45
|
+
success: theme.colour.fill.success,
|
|
46
|
+
critical: theme.colour.fill.critical,
|
|
47
|
+
warning: theme.colour.fill.warning,
|
|
48
|
+
})[variant];
|
|
49
|
+
|
|
50
|
+
const clamp = (value: number, min: number, max: number) =>
|
|
51
|
+
Math.min(Math.max(value, min), max);
|
|
52
|
+
|
|
53
|
+
const ProgressBar = ({
|
|
54
|
+
value,
|
|
55
|
+
max = 100,
|
|
56
|
+
variant = 'info',
|
|
57
|
+
size = 'small',
|
|
58
|
+
title,
|
|
59
|
+
label,
|
|
60
|
+
valueLabel,
|
|
61
|
+
testId = NAME,
|
|
62
|
+
className,
|
|
63
|
+
ref,
|
|
64
|
+
'aria-label': ariaLabel,
|
|
65
|
+
'aria-labelledby': ariaLabelledBy,
|
|
66
|
+
'aria-describedby': ariaDescribedBy,
|
|
67
|
+
...props
|
|
68
|
+
}: ProgressBarProps) => {
|
|
69
|
+
const [theme] = useTheme();
|
|
70
|
+
const generatedId = useId();
|
|
71
|
+
|
|
72
|
+
const isIndeterminate = value === undefined || value === null;
|
|
73
|
+
const normalizedMax = max > 0 ? max : 100;
|
|
74
|
+
const normalizedValue = isIndeterminate
|
|
75
|
+
? undefined
|
|
76
|
+
: clamp(value, 0, normalizedMax);
|
|
77
|
+
const percentage =
|
|
78
|
+
normalizedValue === undefined ? 0 : (normalizedValue / normalizedMax) * 100;
|
|
79
|
+
const barHeight = size === 'large' ? 8 : 4;
|
|
80
|
+
const fillColour = getProgressBarVariantColour(theme, variant);
|
|
81
|
+
const titleId = `${generatedId}-title`;
|
|
82
|
+
const labelId = `${generatedId}-label`;
|
|
83
|
+
const progressBarLabelledBy =
|
|
84
|
+
ariaLabelledBy ??
|
|
85
|
+
(ariaLabel ? undefined : label ? labelId : title ? titleId : undefined);
|
|
86
|
+
|
|
87
|
+
const rootStyle = css`
|
|
88
|
+
display: flex;
|
|
89
|
+
flex-direction: column;
|
|
90
|
+
gap: ${theme.padding.p8};
|
|
91
|
+
width: 100%;
|
|
92
|
+
`;
|
|
93
|
+
|
|
94
|
+
const labelRowStyle = css`
|
|
95
|
+
display: flex;
|
|
96
|
+
align-items: baseline;
|
|
97
|
+
justify-content: space-between;
|
|
98
|
+
gap: ${theme.padding.p16};
|
|
99
|
+
`;
|
|
100
|
+
|
|
101
|
+
const titleStyle = css`
|
|
102
|
+
color: ${theme.colour.text.default};
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
const valueLabelStyle = css`
|
|
106
|
+
color: ${theme.colour.text.secondary};
|
|
107
|
+
white-space: nowrap;
|
|
108
|
+
`;
|
|
109
|
+
|
|
110
|
+
const trackStyle = css`
|
|
111
|
+
position: relative;
|
|
112
|
+
width: 100%;
|
|
113
|
+
height: ${barHeight}px;
|
|
114
|
+
overflow: hidden;
|
|
115
|
+
background-color: ${theme.colour.fill.subtle};
|
|
116
|
+
border-radius: 100px;
|
|
117
|
+
`;
|
|
118
|
+
|
|
119
|
+
const fillStyle = cx(
|
|
120
|
+
css`
|
|
121
|
+
display: block;
|
|
122
|
+
height: 100%;
|
|
123
|
+
background-color: ${fillColour};
|
|
124
|
+
border-radius: 100px;
|
|
125
|
+
`,
|
|
126
|
+
isIndeterminate
|
|
127
|
+
? css`
|
|
128
|
+
position: absolute;
|
|
129
|
+
inset-block: 0;
|
|
130
|
+
inline-size: 40%;
|
|
131
|
+
animation: progress-bar-indeterminate 1.6s ease-in-out infinite;
|
|
132
|
+
|
|
133
|
+
@keyframes progress-bar-indeterminate {
|
|
134
|
+
0% {
|
|
135
|
+
transform: translateX(-100%);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
100% {
|
|
139
|
+
transform: translateX(250%);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@media (prefers-reduced-motion: reduce) {
|
|
144
|
+
animation: none;
|
|
145
|
+
transform: translateX(75%);
|
|
146
|
+
}
|
|
147
|
+
`
|
|
148
|
+
: css`
|
|
149
|
+
width: ${percentage}%;
|
|
150
|
+
transition: width 160ms ease-out;
|
|
151
|
+
|
|
152
|
+
@media (prefers-reduced-motion: reduce) {
|
|
153
|
+
transition: none;
|
|
154
|
+
}
|
|
155
|
+
`
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const labelStyle = css`
|
|
159
|
+
color: ${fillColour};
|
|
160
|
+
`;
|
|
161
|
+
|
|
162
|
+
const style = cx(NAME, rootStyle, marginsStyle(props, theme), className);
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
<div
|
|
166
|
+
className={style}
|
|
167
|
+
data-testid={testId}
|
|
168
|
+
ref={ref}
|
|
169
|
+
{...props}
|
|
170
|
+
>
|
|
171
|
+
{(title || valueLabel) && (
|
|
172
|
+
<div className={labelRowStyle}>
|
|
173
|
+
{title && (
|
|
174
|
+
<Text
|
|
175
|
+
id={titleId}
|
|
176
|
+
level='sm'
|
|
177
|
+
className={titleStyle}
|
|
178
|
+
>
|
|
179
|
+
{title}
|
|
180
|
+
</Text>
|
|
181
|
+
)}
|
|
182
|
+
{valueLabel && (
|
|
183
|
+
<Text
|
|
184
|
+
level='xs'
|
|
185
|
+
className={valueLabelStyle}
|
|
186
|
+
>
|
|
187
|
+
{valueLabel}
|
|
188
|
+
</Text>
|
|
189
|
+
)}
|
|
190
|
+
</div>
|
|
191
|
+
)}
|
|
192
|
+
<div
|
|
193
|
+
className={trackStyle}
|
|
194
|
+
role='progressbar'
|
|
195
|
+
aria-label={ariaLabel}
|
|
196
|
+
aria-labelledby={progressBarLabelledBy}
|
|
197
|
+
aria-describedby={ariaDescribedBy}
|
|
198
|
+
aria-valuemin={isIndeterminate ? undefined : 0}
|
|
199
|
+
aria-valuemax={isIndeterminate ? undefined : normalizedMax}
|
|
200
|
+
aria-valuenow={normalizedValue}
|
|
201
|
+
>
|
|
202
|
+
<span
|
|
203
|
+
className={fillStyle}
|
|
204
|
+
aria-hidden='true'
|
|
205
|
+
/>
|
|
206
|
+
</div>
|
|
207
|
+
{label && (
|
|
208
|
+
<Text
|
|
209
|
+
id={labelId}
|
|
210
|
+
level='xs'
|
|
211
|
+
className={labelStyle}
|
|
212
|
+
>
|
|
213
|
+
{label}
|
|
214
|
+
</Text>
|
|
215
|
+
)}
|
|
216
|
+
</div>
|
|
217
|
+
);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export default memo(ProgressBar);
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { ThemeContextProvider } from '../../../theme/useTheme';
|
|
4
|
+
import ProgressBar, { getProgressBarVariantColour } from '../ProgressBar';
|
|
5
|
+
import lightTheme from '../../../theme/light/lightTheme';
|
|
6
|
+
import darkTheme from '../../../theme/dark/darkTheme';
|
|
7
|
+
|
|
8
|
+
const wrap = (ui: React.ReactElement) =>
|
|
9
|
+
render(<ThemeContextProvider>{ui}</ThemeContextProvider>);
|
|
10
|
+
|
|
11
|
+
describe('ProgressBar', () => {
|
|
12
|
+
test('renders with default test id', () => {
|
|
13
|
+
const { getByTestId } = wrap(<ProgressBar value={50} />);
|
|
14
|
+
|
|
15
|
+
expect(getByTestId('ucl-uikit-progress-bar')).toBeInTheDocument();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('renders custom title, value label, and label', () => {
|
|
19
|
+
wrap(
|
|
20
|
+
<ProgressBar
|
|
21
|
+
value={50}
|
|
22
|
+
title='coverletter.pdf'
|
|
23
|
+
valueLabel='2.4 MB'
|
|
24
|
+
label='Uploading... 50%'
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expect(screen.getByText('coverletter.pdf')).toBeInTheDocument();
|
|
29
|
+
expect(screen.getByText('2.4 MB')).toBeInTheDocument();
|
|
30
|
+
expect(screen.getByText('Uploading... 50%')).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('sets determinate progressbar aria attributes', () => {
|
|
34
|
+
wrap(
|
|
35
|
+
<ProgressBar
|
|
36
|
+
value={25}
|
|
37
|
+
max={50}
|
|
38
|
+
aria-label='Upload progress'
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const progressbar = screen.getByRole('progressbar', {
|
|
43
|
+
name: 'Upload progress',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
expect(progressbar).toHaveAttribute('aria-valuemin', '0');
|
|
47
|
+
expect(progressbar).toHaveAttribute('aria-valuemax', '50');
|
|
48
|
+
expect(progressbar).toHaveAttribute('aria-valuenow', '25');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('omits value aria attributes for indeterminate progress', () => {
|
|
52
|
+
wrap(<ProgressBar aria-label='Loading' />);
|
|
53
|
+
|
|
54
|
+
const progressbar = screen.getByRole('progressbar', {
|
|
55
|
+
name: 'Loading',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(progressbar).not.toHaveAttribute('aria-valuemin');
|
|
59
|
+
expect(progressbar).not.toHaveAttribute('aria-valuemax');
|
|
60
|
+
expect(progressbar).not.toHaveAttribute('aria-valuenow');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('clamps aria-valuenow to the allowed range', () => {
|
|
64
|
+
wrap(
|
|
65
|
+
<ProgressBar
|
|
66
|
+
value={120}
|
|
67
|
+
max={100}
|
|
68
|
+
aria-label='Clamped progress'
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect(screen.getByRole('progressbar')).toHaveAttribute(
|
|
73
|
+
'aria-valuenow',
|
|
74
|
+
'100'
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('applies custom className', () => {
|
|
79
|
+
const { getByTestId } = wrap(
|
|
80
|
+
<ProgressBar
|
|
81
|
+
value={50}
|
|
82
|
+
className='custom-class'
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(getByTestId('ucl-uikit-progress-bar').classList).toContain(
|
|
87
|
+
'custom-class'
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('uses semantic variant colours in light theme', () => {
|
|
92
|
+
expect(getProgressBarVariantColour(lightTheme, 'info')).toBe(
|
|
93
|
+
lightTheme.colour.fill.brand
|
|
94
|
+
);
|
|
95
|
+
expect(getProgressBarVariantColour(lightTheme, 'success')).toBe(
|
|
96
|
+
lightTheme.colour.fill.success
|
|
97
|
+
);
|
|
98
|
+
expect(getProgressBarVariantColour(lightTheme, 'critical')).toBe(
|
|
99
|
+
lightTheme.colour.fill.critical
|
|
100
|
+
);
|
|
101
|
+
expect(getProgressBarVariantColour(lightTheme, 'warning')).toBe(
|
|
102
|
+
lightTheme.colour.fill.warning
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('uses semantic variant colours in dark theme', () => {
|
|
107
|
+
expect(getProgressBarVariantColour(darkTheme, 'info')).toBe(
|
|
108
|
+
darkTheme.colour.fill.brand
|
|
109
|
+
);
|
|
110
|
+
expect(getProgressBarVariantColour(darkTheme, 'success')).toBe(
|
|
111
|
+
darkTheme.colour.fill.success
|
|
112
|
+
);
|
|
113
|
+
expect(getProgressBarVariantColour(darkTheme, 'critical')).toBe(
|
|
114
|
+
darkTheme.colour.fill.critical
|
|
115
|
+
);
|
|
116
|
+
expect(getProgressBarVariantColour(darkTheme, 'warning')).toBe(
|
|
117
|
+
darkTheme.colour.fill.warning
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -3,10 +3,19 @@ import type { TableColumnMetadata } from './Table.types';
|
|
|
3
3
|
|
|
4
4
|
export type TableContextValue = {
|
|
5
5
|
columns: TableColumnMetadata[];
|
|
6
|
+
disableMobileView: boolean;
|
|
6
7
|
};
|
|
7
8
|
|
|
8
|
-
const TableContext = createContext<TableContextValue>({
|
|
9
|
+
const TableContext = createContext<TableContextValue>({
|
|
10
|
+
columns: [],
|
|
11
|
+
disableMobileView: false,
|
|
12
|
+
});
|
|
9
13
|
|
|
10
14
|
export const TableContextProvider = TableContext.Provider;
|
|
11
15
|
|
|
12
16
|
export const useTableContext = () => use(TableContext);
|
|
17
|
+
|
|
18
|
+
export const getMobileBreakpoint = (
|
|
19
|
+
tabletBreakpoint: number,
|
|
20
|
+
disableMobileView: boolean
|
|
21
|
+
) => (disableMobileView ? -1 : tabletBreakpoint - 1);
|
|
@@ -2,7 +2,7 @@ import { Children, isValidElement } from 'react';
|
|
|
2
2
|
import { css, cx } from '@emotion/css';
|
|
3
3
|
import { Head, HeadCell, Body, Row, Cell } from './subcomponents';
|
|
4
4
|
import { useTheme } from '../../theme';
|
|
5
|
-
import { TableContextProvider } from './Table.context';
|
|
5
|
+
import { TableContextProvider, getMobileBreakpoint } from './Table.context';
|
|
6
6
|
import type {
|
|
7
7
|
ColumnVariant,
|
|
8
8
|
NormalizedTableMobileRole,
|
|
@@ -78,10 +78,15 @@ const Table = ({
|
|
|
78
78
|
children,
|
|
79
79
|
ref,
|
|
80
80
|
ariaLabel,
|
|
81
|
+
disableMobileView = false,
|
|
81
82
|
...props
|
|
82
83
|
}: TableProps) => {
|
|
83
84
|
const [theme] = useTheme();
|
|
84
85
|
const columns = getColumnsFromChildren(children);
|
|
86
|
+
const mobileBreakpoint = getMobileBreakpoint(
|
|
87
|
+
theme.breakpoints.tablet,
|
|
88
|
+
disableMobileView
|
|
89
|
+
);
|
|
85
90
|
|
|
86
91
|
const baseStyle = css`
|
|
87
92
|
width: 100%;
|
|
@@ -92,7 +97,7 @@ const Table = ({
|
|
|
92
97
|
line-height: ${theme.typography.body.sm.lineHeight}%;
|
|
93
98
|
border-collapse: collapse;
|
|
94
99
|
|
|
95
|
-
@media screen and (max-width: ${
|
|
100
|
+
@media screen and (max-width: ${mobileBreakpoint}px) {
|
|
96
101
|
display: block;
|
|
97
102
|
border-collapse: separate;
|
|
98
103
|
}
|
|
@@ -101,7 +106,7 @@ const Table = ({
|
|
|
101
106
|
const style = cx(baseStyle, className, NAME);
|
|
102
107
|
|
|
103
108
|
return (
|
|
104
|
-
<TableContextProvider value={{ columns }}>
|
|
109
|
+
<TableContextProvider value={{ columns, disableMobileView }}>
|
|
105
110
|
<table
|
|
106
111
|
className={style}
|
|
107
112
|
data-testid={testId}
|
|
@@ -33,4 +33,6 @@ export interface TableProps extends React.HTMLAttributes<HTMLTableElement> {
|
|
|
33
33
|
className?: string;
|
|
34
34
|
ref?: React.Ref<HTMLTableElement>;
|
|
35
35
|
ariaLabel?: string;
|
|
36
|
+
/** Disable the responsive switch to a mobile card layout below the tablet breakpoint, keeping a real table at all widths. */
|
|
37
|
+
disableMobileView?: boolean;
|
|
36
38
|
}
|