uikit-react-public 0.25.3 → 0.25.5

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.
Files changed (29) hide show
  1. package/dist/components/Badge/Badge.d.ts +3 -1
  2. package/dist/components/Dropdown/Dropdown.context.d.ts +2 -0
  3. package/dist/components/Dropdown/DropdownContent.d.ts +1 -1
  4. package/dist/components/DropdownMenu/DropdownMenu.d.ts +7 -2
  5. package/dist/components/MenuNew/Menu.d.ts +3 -1
  6. package/dist/components/MenuNew/MenuHead.d.ts +9 -0
  7. package/dist/components/MenuNew/index.d.ts +1 -1
  8. package/dist/index.js +3975 -3771
  9. package/lib/components/Badge/Badge.stories.tsx +2 -0
  10. package/lib/components/Badge/Badge.tsx +12 -0
  11. package/lib/components/Badge/__tests__/Badge.test.tsx +19 -0
  12. package/lib/components/Badge/__tests__/__snapshots__/Badge.test.tsx.snap +42 -0
  13. package/lib/components/Dropdown/Dropdown.context.tsx +9 -1
  14. package/lib/components/Dropdown/Dropdown.tsx +10 -2
  15. package/lib/components/Dropdown/DropdownContent.tsx +178 -18
  16. package/lib/components/Dropdown/DropdownTrigger.tsx +3 -2
  17. package/lib/components/Dropdown/__tests__/Dropdown.test.tsx +1 -1
  18. package/lib/components/DropdownMenu/DropdownMenu.tsx +41 -3
  19. package/lib/components/DropdownMenu/__tests__/DropdownMenu.test.tsx +49 -0
  20. package/lib/components/MenuNew/Menu.tsx +8 -2
  21. package/lib/components/MenuNew/MenuAccordion/MenuAccordion.tsx +1 -0
  22. package/lib/components/MenuNew/MenuHead.tsx +76 -0
  23. package/lib/components/MenuNew/MenuHeading.tsx +1 -0
  24. package/lib/components/MenuNew/PrimaryMenuItem.tsx +1 -0
  25. package/lib/components/MenuNew/SecondaryMenuItem.tsx +5 -1
  26. package/lib/components/MenuNew/__tests__/Menu.test.tsx +25 -0
  27. package/lib/components/MenuNew/index.ts +1 -0
  28. package/lib/hooks/useMediaQuery.ts +2 -0
  29. package/package.json +1 -1
@@ -0,0 +1,76 @@
1
+ import { HTMLAttributes } from 'react';
2
+ import { css, cx } from '@emotion/css';
3
+ import { useTheme } from '../../theme';
4
+ import { UclLogoNew } from '../UclLogoNew';
5
+ import IconButton from '../IconButton';
6
+ import Icon from '../Icon';
7
+ import { useDropdownContextOptional } from '../Dropdown/Dropdown.context';
8
+
9
+ export const NAME = 'ucl-uikit-menu__head';
10
+
11
+ export interface MenuHeadProps extends HTMLAttributes<HTMLDivElement> {
12
+ testId?: string;
13
+ onClose?: () => void;
14
+ closeButtonAriaLabel?: string;
15
+ }
16
+
17
+ const MenuHead = ({
18
+ testId = NAME,
19
+ onClose,
20
+ closeButtonAriaLabel = 'Close menu',
21
+ className,
22
+ ...props
23
+ }: MenuHeadProps) => {
24
+ const [theme] = useTheme();
25
+ const dropdownContext = useDropdownContextOptional();
26
+
27
+ const baseStyle = css`
28
+ box-sizing: border-box;
29
+ margin: 0 0 48px;
30
+ padding: 0 ${theme.padding.p8};
31
+ display: flex;
32
+ align-items: center;
33
+ justify-content: space-between;
34
+
35
+ @media screen and (min-width: ${theme.breakpoints.tablet}px) {
36
+ display: none;
37
+ padding: 0 ${theme.padding.p16};
38
+ }
39
+ `;
40
+
41
+ const style = cx(NAME, baseStyle, className);
42
+
43
+ const closeButtonStyle = css`
44
+ width: 32px;
45
+ height: 32px;
46
+ display: inline-flex;
47
+ align-items: center;
48
+ justify-content: center;
49
+ `;
50
+
51
+ return (
52
+ <div
53
+ className={style}
54
+ data-testid={testId}
55
+ {...props}
56
+ >
57
+ <UclLogoNew
58
+ testId={`${testId}__logo`}
59
+ height={30}
60
+ />
61
+ <IconButton
62
+ testId={`${testId}__close-button`}
63
+ aria-label={closeButtonAriaLabel}
64
+ onClick={() => {
65
+ onClose?.();
66
+ dropdownContext?.setIsOpen(false);
67
+ }}
68
+ className={closeButtonStyle}
69
+ >
70
+ <Icon.X size={32} />
71
+ </IconButton>
72
+ </div>
73
+ );
74
+ };
75
+
76
+ export default MenuHead;
@@ -20,6 +20,7 @@ const MenuHeading = ({
20
20
  const baseStyle = css`
21
21
  box-sizing: border-box;
22
22
  margin: ${theme.margin.m32} 0 ${theme.margin.m16};
23
+ padding: 0 ${theme.padding.p16};
23
24
  text-transform: uppercase;
24
25
 
25
26
  @media screen and (min-width: ${theme.breakpoints.tablet}px) {
@@ -26,6 +26,7 @@ const PrimaryMenuItem = ({
26
26
 
27
27
  const baseStyle = css`
28
28
  color: ${theme.colour.text.default};
29
+ padding: 0 ${theme.padding.p16};
29
30
 
30
31
  @media screen and (min-width: ${theme.breakpoints.tablet}px) {
31
32
  padding: 0 ${theme.padding.p16};
@@ -25,8 +25,12 @@ const SecondaryMenuItem = ({
25
25
  const [theme] = useTheme();
26
26
 
27
27
  const baseStyle = css`
28
- padding-inline: ${theme.margin.m16};
28
+ padding: 0 ${theme.padding.p16};
29
29
  color: ${theme.colour.text.secondary};
30
+
31
+ @media screen and (min-width: ${theme.breakpoints.tablet}px) {
32
+ padding: 0 ${theme.padding.p16};
33
+ }
30
34
  `;
31
35
 
32
36
  const style = cx(NAME, baseStyle, className);
@@ -26,6 +26,31 @@ describe('Menu', () => {
26
26
  expect(heading).not.toHaveAttribute('role', 'button');
27
27
  });
28
28
 
29
+ test('renders head item', () => {
30
+ const onClose = vi.fn();
31
+
32
+ wrap(
33
+ <Menu>
34
+ <Menu.Head onClose={onClose} />
35
+ </Menu>
36
+ );
37
+
38
+ const head = screen.getByTestId('ucl-uikit-menu__head');
39
+ const logo = screen.getByTestId('ucl-uikit-menu__head__logo');
40
+ const closeButton = screen.getByTestId(
41
+ 'ucl-uikit-menu__head__close-button'
42
+ );
43
+
44
+ expect(head).toBeInTheDocument();
45
+ expect(logo).toBeInTheDocument();
46
+ expect(closeButton).toBeInTheDocument();
47
+ expect(head).toHaveClass('ucl-uikit-menu__head');
48
+ expect(head).not.toHaveAttribute('role', 'button');
49
+
50
+ fireEvent.click(closeButton);
51
+ expect(onClose).toHaveBeenCalledTimes(1);
52
+ });
53
+
29
54
  test('renders semantic section wrapper', () => {
30
55
  wrap(
31
56
  <Menu>
@@ -2,6 +2,7 @@ export { default } from './Menu';
2
2
  export type {
3
3
  MenuProps,
4
4
  MenuDividerProps,
5
+ MenuHeadProps,
5
6
  MenuHeadingProps,
6
7
  MenuSectionProps,
7
8
  MenuAccordionProps,
@@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
2
2
 
3
3
  const getInitialMatch = (query: string): boolean => {
4
4
  if (typeof window === 'undefined') return false;
5
+ if (typeof window.matchMedia !== 'function') return false;
5
6
  return window.matchMedia(query).matches;
6
7
  };
7
8
 
@@ -12,6 +13,7 @@ const useMediaQuery = (query: string): boolean => {
12
13
 
13
14
  useEffect(() => {
14
15
  if (typeof window === 'undefined') return;
16
+ if (typeof window.matchMedia !== 'function') return;
15
17
 
16
18
  const mediaQueryList = window.matchMedia(query);
17
19
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "uikit-react-public",
3
3
  "private": false,
4
4
  "license": "UNLICENSED",
5
- "version": "0.25.3",
5
+ "version": "0.25.5",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",