uikit-react-public 0.40.1 → 0.40.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.
@@ -1,9 +1,10 @@
1
1
  import { memo, HTMLAttributes } from 'react';
2
2
  import { css, cx } from '@emotion/css';
3
- import { useTheme } from '../..';
3
+ import { themes, useTheme } from '../../theme';
4
4
  import UclLogo from '../UclLogo/UclLogo';
5
5
  import HeaderMenu from './HeaderMenu';
6
6
  import Link from '../Link';
7
+ import HeaderNew from '../HeaderNew';
7
8
 
8
9
  export const NAME = 'ucl-uikit-header';
9
10
  export const HEADER_DESKTOP_HEIGHT_PX = 72;
@@ -12,17 +13,19 @@ export const DEFAULT_Z_INDEX = 3;
12
13
 
13
14
  export interface HeaderProps extends HTMLAttributes<HTMLElement> {
14
15
  title?: string;
16
+ /** @deprecated Only used by the default-theme legacy Header. */
15
17
  fixed?: boolean;
16
18
  titleAs?: React.ElementType<React.HTMLAttributes<HTMLElement>>;
17
19
  titleClassName?: string;
18
20
  titleProps?: Record<string, unknown>;
19
21
  homeLinkHref?: string;
20
22
  homeLinkProps?: Record<string, unknown>;
23
+ /** @deprecated Use `homeLinkProps={{ 'aria-label': '...' }}` instead. */
21
24
  homeLinkAriaLabel?: string;
22
25
  testId?: string;
23
26
  }
24
27
 
25
- const Header = ({
28
+ const LegacyHeader = ({
26
29
  title,
27
30
  fixed = false,
28
31
  titleAs = 'div',
@@ -159,15 +162,77 @@ const Header = ({
159
162
  );
160
163
  };
161
164
 
165
+ const Header = ({
166
+ title,
167
+ titleAs = 'div',
168
+ titleClassName,
169
+ titleProps,
170
+ homeLinkHref,
171
+ homeLinkProps,
172
+ homeLinkAriaLabel,
173
+ testId = NAME,
174
+ className,
175
+ children,
176
+ fixed,
177
+ ...props
178
+ }: HeaderProps) => {
179
+ const [theme] = useTheme();
180
+
181
+ if (theme === themes.default) {
182
+ return (
183
+ <LegacyHeader
184
+ title={title}
185
+ fixed={fixed}
186
+ titleAs={titleAs}
187
+ titleClassName={titleClassName}
188
+ titleProps={titleProps}
189
+ homeLinkHref={homeLinkHref}
190
+ homeLinkProps={homeLinkProps}
191
+ homeLinkAriaLabel={homeLinkAriaLabel}
192
+ testId={testId}
193
+ className={className}
194
+ {...props}
195
+ >
196
+ {children}
197
+ </LegacyHeader>
198
+ );
199
+ }
200
+
201
+ const resolvedHomeLinkProps =
202
+ homeLinkAriaLabel && !homeLinkProps?.['aria-label']
203
+ ? { ...homeLinkProps, 'aria-label': homeLinkAriaLabel }
204
+ : homeLinkProps;
205
+
206
+ return (
207
+ <HeaderNew
208
+ title={title ?? ''}
209
+ titleAs={titleAs}
210
+ titleClassName={titleClassName}
211
+ titleProps={titleProps}
212
+ homeLinkHref={homeLinkHref}
213
+ homeLinkProps={resolvedHomeLinkProps}
214
+ testId={testId}
215
+ className={className}
216
+ {...props}
217
+ >
218
+ {children}
219
+ </HeaderNew>
220
+ );
221
+ };
222
+
162
223
  const MemoAppHeader = memo(Header);
163
224
 
164
225
  export interface IHeaderSubComponents {
165
226
  Menu: typeof HeaderMenu;
227
+ MenuContainer: (typeof HeaderNew)['MenuContainer'];
228
+ Item: (typeof HeaderNew)['Item'];
166
229
  }
167
230
 
168
231
  const HeaderWithSubComponents = MemoAppHeader as typeof MemoAppHeader &
169
232
  IHeaderSubComponents;
170
233
 
171
234
  HeaderWithSubComponents.Menu = HeaderMenu;
235
+ HeaderWithSubComponents.MenuContainer = HeaderNew.MenuContainer;
236
+ HeaderWithSubComponents.Item = HeaderNew.Item;
172
237
 
173
238
  export default HeaderWithSubComponents;
@@ -39,4 +39,54 @@ describe('Header', () => {
39
39
  expect(link).toBeInTheDocument();
40
40
  expect(link.getAttribute('href')).toBe('/');
41
41
  });
42
+
43
+ test('uses the legacy header for the default theme', () => {
44
+ const renderResult = render(
45
+ <ThemeContextProvider>
46
+ <Header title='LIDS'>
47
+ <Header.Menu testId='legacy-header-menu'>Menu</Header.Menu>
48
+ </Header>
49
+ </ThemeContextProvider>
50
+ );
51
+
52
+ expect(screen.getByTestId('legacy-header-menu')).toBeInTheDocument();
53
+ expect(
54
+ renderResult.container.querySelector('.ucl-uikit-header__border')
55
+ ).not.toBeInTheDocument();
56
+ });
57
+
58
+ test('uses the new header for light and dark themes', () => {
59
+ const renderResult = render(
60
+ <ThemeContextProvider theme='light'>
61
+ <Header title='LIDS'>
62
+ <Header.MenuContainer>
63
+ <Header.Item testId='new-header-item'>Item</Header.Item>
64
+ </Header.MenuContainer>
65
+ </Header>
66
+ </ThemeContextProvider>
67
+ );
68
+
69
+ expect(screen.getByTestId('new-header-item')).toHaveClass(
70
+ 'ucl-uikit-header__item'
71
+ );
72
+ expect(
73
+ renderResult.container.querySelector('.ucl-uikit-header__border')
74
+ ).toBeInTheDocument();
75
+ });
76
+
77
+ test('maps the deprecated homeLinkAriaLabel prop to the new header link props', () => {
78
+ render(
79
+ <ThemeContextProvider theme='dark'>
80
+ <Header
81
+ title='LIDS'
82
+ homeLinkHref='/'
83
+ homeLinkAriaLabel='Go home'
84
+ />
85
+ </ThemeContextProvider>
86
+ );
87
+
88
+ const link = screen.getByLabelText('Go home');
89
+ expect(link).toBeInTheDocument();
90
+ expect(link.getAttribute('href')).toBe('/');
91
+ });
42
92
  });
@@ -1,6 +1,6 @@
1
1
  import { memo, HTMLAttributes } from 'react';
2
2
  import { css, cx } from '@emotion/css';
3
- import { useTheme } from '../..';
3
+ import { useTheme } from '../../theme';
4
4
  import HeaderMenuContainer from './HeaderMenuContainer';
5
5
  import HeaderItem from './HeaderItem';
6
6
  import HeaderTitle from './HeaderTitle';
@@ -1,5 +1,5 @@
1
1
  import { css, cx } from '@emotion/css';
2
- import { useTheme } from '../..';
2
+ import { useTheme } from '../../theme';
3
3
  import { HTMLAttributes } from 'react';
4
4
 
5
5
  export const NAME = 'ucl-uikit-header__border';
@@ -1,6 +1,6 @@
1
1
  import { HTMLAttributes } from 'react';
2
2
  import { css, cx } from '@emotion/css';
3
- import { useTheme } from '../..';
3
+ import { useTheme } from '../../theme';
4
4
 
5
5
  export const NAME = 'ucl-uikit-header__item';
6
6
 
@@ -1,5 +1,7 @@
1
1
  import { css, cx } from '@emotion/css';
2
- import { UclLogoNew, UclLogoProps, useTheme } from '../..';
2
+ import { useTheme } from '../../theme';
3
+ import UclLogoNew from '../UclLogoNew/UclLogo';
4
+ import type { UclLogoProps } from '../UclLogoNew/UclLogo';
3
5
 
4
6
  export const NAME = 'ucl-uikit-header__logo';
5
7
 
@@ -1,5 +1,5 @@
1
1
  import { css, cx } from '@emotion/css';
2
- import { useTheme } from '../..';
2
+ import { useTheme } from '../../theme';
3
3
  import { HTMLAttributes } from 'react';
4
4
 
5
5
  export const NAME = 'ucl-uikit-header__title';
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.40.1",
5
+ "version": "0.40.2",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",