uikit-react-public 0.26.3 → 0.27.2
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/BaseCheckbox/BaseCheckbox.d.ts +26 -0
- package/dist/components/BaseCheckbox/BaseCheckbox.stories.d.ts +29 -0
- package/dist/components/BaseCheckbox/__tests__/BaseCheckbox.test.d.ts +1 -0
- package/dist/components/BaseCheckbox/index.d.ts +2 -0
- package/dist/components/MenuNew/MenuAccordion/MenuAccordionItem.d.ts +2 -3
- package/dist/components/MenuNew/MenuBaseItem.d.ts +2 -1
- package/dist/components/MenuNew/index.d.ts +1 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/index.js +2871 -2776
- package/lib/components/BaseCheckbox/BaseCheckbox.stories.tsx +82 -0
- package/lib/components/BaseCheckbox/BaseCheckbox.tsx +168 -0
- package/lib/components/BaseCheckbox/__tests__/BaseCheckbox.test.tsx +98 -0
- package/lib/components/BaseCheckbox/index.ts +2 -0
- package/lib/components/Checkbox/Checkbox.tsx +49 -53
- package/lib/components/Checkbox/__tests__/__snapshots__/Checkbox.test.tsx.snap +66 -43
- package/lib/components/MenuNew/MenuAccordion/MenuAccordion.tsx +2 -1
- package/lib/components/MenuNew/MenuAccordion/MenuAccordionItem.tsx +7 -6
- package/lib/components/MenuNew/MenuBaseItem.tsx +17 -0
- package/lib/components/MenuNew/MenuItemText.tsx +6 -0
- package/lib/components/MenuNew/__tests__/Menu.test.tsx +100 -0
- package/lib/components/MenuNew/index.ts +1 -0
- package/lib/components/Table/subcomponents/Cell/__tests__/__snapshots__/Cell.test.tsx.snap +7 -2
- package/lib/components/Table/subcomponents/HeadCell/__tests__/__snapshots__/HeadCell.test.tsx.snap +7 -2
- package/lib/components/index.ts +3 -0
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ export interface MenuBaseItemProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
8
8
|
endAdornment?: ReactNode;
|
|
9
9
|
hoverMode?: 'background' | 'underline';
|
|
10
10
|
asChild?: boolean;
|
|
11
|
+
active?: boolean;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
const MenuBaseItem = ({
|
|
@@ -22,6 +23,7 @@ const MenuBaseItem = ({
|
|
|
22
23
|
tabIndex,
|
|
23
24
|
hoverMode = 'background',
|
|
24
25
|
asChild = false,
|
|
26
|
+
active = false,
|
|
25
27
|
...props
|
|
26
28
|
}: MenuBaseItemProps) => {
|
|
27
29
|
const [theme] = useTheme();
|
|
@@ -53,6 +55,7 @@ const MenuBaseItem = ({
|
|
|
53
55
|
display: flex;
|
|
54
56
|
align-items: center;
|
|
55
57
|
gap: ${theme.margin.m16};
|
|
58
|
+
position: relative;
|
|
56
59
|
cursor: pointer;
|
|
57
60
|
outline: none;
|
|
58
61
|
|
|
@@ -65,6 +68,19 @@ const MenuBaseItem = ({
|
|
|
65
68
|
}
|
|
66
69
|
`;
|
|
67
70
|
|
|
71
|
+
const activeStyle = css`
|
|
72
|
+
&::before {
|
|
73
|
+
content: '';
|
|
74
|
+
position: absolute;
|
|
75
|
+
left: 0;
|
|
76
|
+
top: calc(50% - 12px);
|
|
77
|
+
width: 6px;
|
|
78
|
+
height: 24px;
|
|
79
|
+
background-color: ${theme.colour.fill.brand};
|
|
80
|
+
pointer-events: none;
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
|
|
68
84
|
const backgroundOnHoverStyle = css`
|
|
69
85
|
&:hover {
|
|
70
86
|
background-color: ${theme.colour.fill.brandSubtleHover};
|
|
@@ -79,6 +95,7 @@ const MenuBaseItem = ({
|
|
|
79
95
|
|
|
80
96
|
const style = cx(
|
|
81
97
|
baseStyle,
|
|
98
|
+
active && activeStyle,
|
|
82
99
|
hoverMode === 'underline' && underlineStyleOnHoverStyle,
|
|
83
100
|
hoverMode === 'background' && backgroundOnHoverStyle,
|
|
84
101
|
className
|
|
@@ -129,6 +129,7 @@ describe('Menu', () => {
|
|
|
129
129
|
.getByText('Library')
|
|
130
130
|
.closest('.ucl-uikit-menu__accordion-item');
|
|
131
131
|
const accordionContentInner = accordionItem?.parentElement;
|
|
132
|
+
const accordionContent = accordionContentInner?.parentElement;
|
|
132
133
|
|
|
133
134
|
expect(accordionItem).toHaveStyle({
|
|
134
135
|
marginTop: '0px',
|
|
@@ -137,6 +138,10 @@ describe('Menu', () => {
|
|
|
137
138
|
marginBottom: '0px',
|
|
138
139
|
width: 'calc(100% - 12px)',
|
|
139
140
|
});
|
|
141
|
+
expect(accordionContent).toHaveStyle({
|
|
142
|
+
marginLeft: '-6px',
|
|
143
|
+
width: 'calc(100% + 12px)',
|
|
144
|
+
});
|
|
140
145
|
expect(accordionContentInner).toHaveStyle({
|
|
141
146
|
paddingTop: '6px',
|
|
142
147
|
paddingBottom: '6px',
|
|
@@ -244,6 +249,42 @@ describe('Menu', () => {
|
|
|
244
249
|
);
|
|
245
250
|
});
|
|
246
251
|
|
|
252
|
+
test.each([
|
|
253
|
+
{
|
|
254
|
+
name: 'primary',
|
|
255
|
+
menu: (
|
|
256
|
+
<Menu.PrimaryItem asChild>
|
|
257
|
+
<a href='/home'>Home</a>
|
|
258
|
+
</Menu.PrimaryItem>
|
|
259
|
+
),
|
|
260
|
+
linkName: 'Home',
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
name: 'accordion',
|
|
264
|
+
menu: (
|
|
265
|
+
<Menu.Accordion.Item asChild>
|
|
266
|
+
<a href='/library'>Library</a>
|
|
267
|
+
</Menu.Accordion.Item>
|
|
268
|
+
),
|
|
269
|
+
linkName: 'Library',
|
|
270
|
+
},
|
|
271
|
+
])('$name asChild link covers the full item', ({ menu, linkName }) => {
|
|
272
|
+
wrap(<Menu>{menu}</Menu>);
|
|
273
|
+
|
|
274
|
+
const link = screen.getByRole('link', { name: linkName });
|
|
275
|
+
const generatedClass = Array.from(link.classList).find((className) =>
|
|
276
|
+
className.startsWith('css-')
|
|
277
|
+
);
|
|
278
|
+
const cssRules = Array.from(document.styleSheets)
|
|
279
|
+
.flatMap((styleSheet) => Array.from(styleSheet.cssRules))
|
|
280
|
+
.map((rule) => rule.cssText)
|
|
281
|
+
.join(' ');
|
|
282
|
+
|
|
283
|
+
expect(cssRules).toContain(`.${generatedClass}::after`);
|
|
284
|
+
expect(cssRules).toContain('position: absolute');
|
|
285
|
+
expect(cssRules).toContain('inset: 0');
|
|
286
|
+
});
|
|
287
|
+
|
|
247
288
|
test('primary item enforces icon on the left', () => {
|
|
248
289
|
const { getByText } = wrap(
|
|
249
290
|
<Menu>
|
|
@@ -257,6 +298,65 @@ describe('Menu', () => {
|
|
|
257
298
|
expect(item?.firstChild).toHaveAttribute('data-testid', 'left-icon');
|
|
258
299
|
});
|
|
259
300
|
|
|
301
|
+
test('active items render a non-disruptive marker', () => {
|
|
302
|
+
wrap(
|
|
303
|
+
<Menu>
|
|
304
|
+
<Menu.PrimaryItem active>Home</Menu.PrimaryItem>
|
|
305
|
+
</Menu>
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
const item = screen
|
|
309
|
+
.getByText('Home')
|
|
310
|
+
.closest('.ucl-uikit-menu__primary-item');
|
|
311
|
+
const generatedClass = Array.from(item?.classList ?? []).find((className) =>
|
|
312
|
+
className.startsWith('css-')
|
|
313
|
+
);
|
|
314
|
+
const cssRules = Array.from(document.styleSheets)
|
|
315
|
+
.flatMap((styleSheet) => Array.from(styleSheet.cssRules))
|
|
316
|
+
.map((rule) => rule.cssText)
|
|
317
|
+
.join(' ');
|
|
318
|
+
|
|
319
|
+
expect(item).not.toHaveAttribute('active');
|
|
320
|
+
expect(item).toHaveStyle({ position: 'relative' });
|
|
321
|
+
expect(cssRules).toContain(`.${generatedClass}::before`);
|
|
322
|
+
expect(cssRules).toContain('width: 6px');
|
|
323
|
+
expect(cssRules).toContain('height: 24px');
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
test.each([
|
|
327
|
+
{
|
|
328
|
+
name: 'accordion',
|
|
329
|
+
menu: (
|
|
330
|
+
<Menu.Accordion
|
|
331
|
+
active
|
|
332
|
+
label='Systems'
|
|
333
|
+
/>
|
|
334
|
+
),
|
|
335
|
+
text: 'Systems',
|
|
336
|
+
selector: '.ucl-uikit-menu__accordion',
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
name: 'accordion item',
|
|
340
|
+
menu: <Menu.Accordion.Item active>Library</Menu.Accordion.Item>,
|
|
341
|
+
text: 'Library',
|
|
342
|
+
selector: '.ucl-uikit-menu__accordion-item',
|
|
343
|
+
},
|
|
344
|
+
])('$name supports active state', ({ menu, text, selector }) => {
|
|
345
|
+
wrap(<Menu>{menu}</Menu>);
|
|
346
|
+
|
|
347
|
+
const item = screen.getByText(text).closest(selector);
|
|
348
|
+
const generatedClass = Array.from(item?.classList ?? []).find((className) =>
|
|
349
|
+
className.startsWith('css-')
|
|
350
|
+
);
|
|
351
|
+
const cssRules = Array.from(document.styleSheets)
|
|
352
|
+
.flatMap((styleSheet) => Array.from(styleSheet.cssRules))
|
|
353
|
+
.map((rule) => rule.cssText)
|
|
354
|
+
.join(' ');
|
|
355
|
+
|
|
356
|
+
expect(item).not.toHaveAttribute('active');
|
|
357
|
+
expect(cssRules).toContain(`.${generatedClass}::before`);
|
|
358
|
+
});
|
|
359
|
+
|
|
260
360
|
test('primary items use background hover instead of underline hover', () => {
|
|
261
361
|
wrap(
|
|
262
362
|
<Menu>
|
|
@@ -44,13 +44,18 @@ exports[`Cell > Snapshot: variants 1`] = `
|
|
|
44
44
|
data-testid="ucl-uikit-table__cell-content"
|
|
45
45
|
>
|
|
46
46
|
<span
|
|
47
|
-
class="ucl-uikit-checkbox css-
|
|
47
|
+
class="ucl-uikit-base-checkbox ucl-uikit-checkbox css-tfrbiv"
|
|
48
|
+
data-testid="ucl-uikit-checkbox__root"
|
|
48
49
|
>
|
|
49
50
|
<input
|
|
50
|
-
class="css-
|
|
51
|
+
class="css-1bjd9qx"
|
|
51
52
|
data-testid="ucl-uikit-checkbox"
|
|
52
53
|
type="checkbox"
|
|
53
54
|
/>
|
|
55
|
+
<span
|
|
56
|
+
aria-hidden="true"
|
|
57
|
+
class="css-1quq9cp"
|
|
58
|
+
/>
|
|
54
59
|
</span>
|
|
55
60
|
</div>
|
|
56
61
|
</td>
|
package/lib/components/Table/subcomponents/HeadCell/__tests__/__snapshots__/HeadCell.test.tsx.snap
CHANGED
|
@@ -14,14 +14,19 @@ exports[`HeadCell > Snapshot: checkbox variant 1`] = `
|
|
|
14
14
|
data-testid="ucl-uikit-table__head-cell-content"
|
|
15
15
|
>
|
|
16
16
|
<span
|
|
17
|
-
class="ucl-uikit-checkbox css-
|
|
17
|
+
class="ucl-uikit-base-checkbox ucl-uikit-checkbox css-tfrbiv"
|
|
18
|
+
data-testid="ucl-uikit-checkbox__root"
|
|
18
19
|
>
|
|
19
20
|
<input
|
|
20
21
|
aria-label="Select all rows"
|
|
21
|
-
class="css-
|
|
22
|
+
class="css-1bjd9qx"
|
|
22
23
|
data-testid="ucl-uikit-checkbox"
|
|
23
24
|
type="checkbox"
|
|
24
25
|
/>
|
|
26
|
+
<span
|
|
27
|
+
aria-hidden="true"
|
|
28
|
+
class="css-1quq9cp"
|
|
29
|
+
/>
|
|
25
30
|
</span>
|
|
26
31
|
</div>
|
|
27
32
|
</th>
|
package/lib/components/index.ts
CHANGED
|
@@ -34,6 +34,9 @@ export type { AvatarProps } from './Avatar';
|
|
|
34
34
|
export { default as Badge } from './Badge';
|
|
35
35
|
export type { BadgeProps } from './Badge';
|
|
36
36
|
|
|
37
|
+
export { default as BaseCheckbox } from './BaseCheckbox';
|
|
38
|
+
export type { BaseCheckboxProps, BaseCheckboxState } from './BaseCheckbox';
|
|
39
|
+
|
|
37
40
|
export { default as Spinner } from './Spinner';
|
|
38
41
|
export type { SpinnerProps } from './Spinner';
|
|
39
42
|
|