uikit-react-public 0.40.1 → 0.40.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.
Files changed (31) hide show
  1. package/dist/components/Footer/Footer.d.ts +10 -5
  2. package/dist/components/Footer/Footer.stories.d.ts +1 -1
  3. package/dist/components/Footer/FooterNavLink.d.ts +1 -1
  4. package/dist/components/Footer/SocialLink.d.ts +1 -1
  5. package/dist/components/FooterNew/FooterNavLink.d.ts +1 -1
  6. package/dist/components/FooterNew/SocialLink.d.ts +1 -1
  7. package/dist/components/Header/Header.d.ts +6 -1
  8. package/dist/components/Header/Header.stories.d.ts +1 -1
  9. package/dist/components/HeaderNew/HeaderLogo.d.ts +1 -1
  10. package/dist/index.js +5148 -5043
  11. package/lib/components/Footer/Footer.tsx +83 -6
  12. package/lib/components/Footer/FooterColumn.tsx +2 -3
  13. package/lib/components/Footer/FooterNavLink.tsx +3 -1
  14. package/lib/components/Footer/SocialLink.tsx +4 -1
  15. package/lib/components/Footer/__tests__/Footer.test.tsx +42 -9
  16. package/lib/components/FooterNew/BackToTop.tsx +1 -1
  17. package/lib/components/FooterNew/Footer.tsx +1 -1
  18. package/lib/components/FooterNew/FooterColumn.tsx +1 -1
  19. package/lib/components/FooterNew/FooterLinks.tsx +1 -1
  20. package/lib/components/FooterNew/FooterNavLink.tsx +3 -1
  21. package/lib/components/FooterNew/LegalAndCopyright.tsx +1 -1
  22. package/lib/components/FooterNew/LogoAddressAndSocial.tsx +2 -1
  23. package/lib/components/FooterNew/SocialLink.tsx +4 -1
  24. package/lib/components/Header/Header.tsx +67 -2
  25. package/lib/components/Header/__tests__/Header.test.tsx +50 -0
  26. package/lib/components/HeaderNew/Header.tsx +1 -1
  27. package/lib/components/HeaderNew/HeaderBorder.tsx +1 -1
  28. package/lib/components/HeaderNew/HeaderItem.tsx +1 -1
  29. package/lib/components/HeaderNew/HeaderLogo.tsx +3 -1
  30. package/lib/components/HeaderNew/HeaderTitle.tsx +1 -1
  31. package/package.json +1 -1
@@ -1,23 +1,31 @@
1
1
  import { memo, HTMLAttributes } from 'react';
2
2
  import { css, cx } from '@emotion/css';
3
- import { Divider, UclLogo, useTheme } from '../..';
3
+ import { themes, useTheme } from '../../theme';
4
+ import Divider from '../Divider';
5
+ import { UclLogo } from '../UclLogo';
4
6
  import FooterColumn from './FooterColumn';
7
+ import type { FooterColumnProps } from './FooterColumn';
5
8
  import SocialLink from './SocialLink';
6
9
  import FooterNavLink from './FooterNavLink';
10
+ import type { FooterNavLinkProps } from './FooterNavLink';
11
+ import FooterNew from '../FooterNew';
7
12
 
8
13
  export const NAME = 'ucl-uikit-footer';
9
14
 
10
15
  export interface FooterProps extends HTMLAttributes<HTMLElement> {
11
16
  testId?: string;
17
+ addressFormat?: 'compact' | 'full';
18
+ showSocialLinks?: boolean;
12
19
  disclaimer?: string;
13
20
  freedomOfInformation?: string;
14
21
  accessibility?: string;
15
22
  cookies?: string;
16
23
  privacy?: string;
17
24
  slaveryStatement?: string;
25
+ login?: string;
18
26
  }
19
27
 
20
- const Footer = ({
28
+ const LegacyFooter = ({
21
29
  testId = NAME,
22
30
  className,
23
31
  disclaimer = 'https://www.ucl.ac.uk/legal-services/disclaimer',
@@ -257,17 +265,86 @@ const Footer = ({
257
265
  );
258
266
  };
259
267
 
268
+ const Footer = ({
269
+ testId = NAME,
270
+ className,
271
+ addressFormat,
272
+ showSocialLinks,
273
+ disclaimer,
274
+ freedomOfInformation,
275
+ accessibility,
276
+ cookies,
277
+ privacy,
278
+ slaveryStatement,
279
+ login,
280
+ children,
281
+ ...props
282
+ }: FooterProps) => {
283
+ const [theme] = useTheme();
284
+
285
+ if (theme === themes.default) {
286
+ return (
287
+ <LegacyFooter
288
+ testId={testId}
289
+ className={className}
290
+ disclaimer={disclaimer}
291
+ freedomOfInformation={freedomOfInformation}
292
+ accessibility={accessibility}
293
+ cookies={cookies}
294
+ privacy={privacy}
295
+ slaveryStatement={slaveryStatement}
296
+ {...props}
297
+ >
298
+ {children}
299
+ </LegacyFooter>
300
+ );
301
+ }
302
+
303
+ return (
304
+ <FooterNew
305
+ testId={testId}
306
+ className={className}
307
+ addressFormat={addressFormat}
308
+ showSocialLinks={showSocialLinks}
309
+ disclaimer={disclaimer}
310
+ freedomOfInformation={freedomOfInformation}
311
+ accessibility={accessibility}
312
+ cookies={cookies}
313
+ privacy={privacy}
314
+ slaveryStatement={slaveryStatement}
315
+ login={login}
316
+ {...props}
317
+ >
318
+ {children}
319
+ </FooterNew>
320
+ );
321
+ };
322
+
323
+ const FooterColumnBridge = (props: FooterColumnProps) => {
324
+ const [theme] = useTheme();
325
+ const Column = theme === themes.default ? FooterColumn : FooterNew.Column;
326
+
327
+ return <Column {...props} />;
328
+ };
329
+
330
+ const FooterNavLinkBridge = (props: FooterNavLinkProps) => {
331
+ const [theme] = useTheme();
332
+ const NavLink = theme === themes.default ? FooterNavLink : FooterNew.NavLink;
333
+
334
+ return <NavLink {...props} />;
335
+ };
336
+
260
337
  const MemoFooter = memo(Footer);
261
338
 
262
339
  export interface IFooterSubComponents {
263
- Column: typeof FooterColumn;
264
- NavLink: typeof FooterNavLink;
340
+ Column: typeof FooterColumnBridge;
341
+ NavLink: typeof FooterNavLinkBridge;
265
342
  }
266
343
 
267
344
  const FooterWithSubComponents = MemoFooter as typeof MemoFooter &
268
345
  IFooterSubComponents;
269
346
 
270
- FooterWithSubComponents.Column = FooterColumn;
271
- FooterWithSubComponents.NavLink = FooterNavLink;
347
+ FooterWithSubComponents.Column = FooterColumnBridge;
348
+ FooterWithSubComponents.NavLink = FooterNavLinkBridge;
272
349
 
273
350
  export default FooterWithSubComponents;
@@ -1,11 +1,10 @@
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
 
5
5
  export const NAME = 'ucl-uikit-footer__column';
6
6
 
7
- export interface FooterColumnProps
8
- extends HTMLAttributes<HTMLDivElement> {
7
+ export interface FooterColumnProps extends HTMLAttributes<HTMLDivElement> {
9
8
  heading: string;
10
9
  testId?: string;
11
10
  }
@@ -1,6 +1,8 @@
1
1
  import { memo } from 'react';
2
2
  import { css, cx } from '@emotion/css';
3
- import { Link, LinkProps, useTheme } from '../..';
3
+ import { useTheme } from '../../theme';
4
+ import Link from '../Link';
5
+ import type { LinkProps } from '../Link';
4
6
 
5
7
  export const NAME = 'ucl-uikit-footer__nav-link';
6
8
 
@@ -1,6 +1,9 @@
1
1
  import { memo } from 'react';
2
2
  import { css, cx } from '@emotion/css';
3
- import { Icon, Link, LinkProps, useTheme } from '../..';
3
+ import { useTheme } from '../../theme';
4
+ import Icon from '../Icon';
5
+ import Link from '../Link';
6
+ import type { LinkProps } from '../Link';
4
7
 
5
8
  export const NAME = 'ucl-uikit-footer__social-link';
6
9
 
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from 'vitest';
2
- import { render } from '@testing-library/react';
2
+ import { render, screen } from '@testing-library/react';
3
3
  import Footer from '../Footer';
4
4
  import { ThemeContextProvider } from '../../../theme/useTheme';
5
5
 
@@ -12,9 +12,7 @@ describe('Footer', () => {
12
12
  <Footer />
13
13
  </ThemeContextProvider>
14
14
  );
15
- expect(
16
- renderResult.container.firstChild
17
- ).toMatchSnapshot();
15
+ expect(renderResult.container.firstChild).toMatchSnapshot();
18
16
  });
19
17
 
20
18
  test('snapshot: footer links provided', () => {
@@ -30,9 +28,7 @@ describe('Footer', () => {
30
28
  />
31
29
  </ThemeContextProvider>
32
30
  );
33
- expect(
34
- renderResult.container.firstChild
35
- ).toMatchSnapshot();
31
+ expect(renderResult.container.firstChild).toMatchSnapshot();
36
32
  });
37
33
 
38
34
  test('snapshot: nav links', () => {
@@ -50,8 +46,45 @@ describe('Footer', () => {
50
46
  </Footer>
51
47
  </ThemeContextProvider>
52
48
  );
49
+ expect(renderResult.container.firstChild).toMatchSnapshot();
50
+ });
51
+
52
+ test('uses the legacy footer for the default theme', () => {
53
+ render(
54
+ <ThemeContextProvider>
55
+ <Footer />
56
+ </ThemeContextProvider>
57
+ );
58
+
59
+ expect(
60
+ screen.queryByRole('button', { name: /back to top/i })
61
+ ).not.toBeInTheDocument();
62
+ });
63
+
64
+ test('uses the new footer for light and dark themes', () => {
65
+ render(
66
+ <ThemeContextProvider theme='light'>
67
+ <Footer
68
+ login='https://www.ucl.ac.uk/login'
69
+ showSocialLinks={false}
70
+ >
71
+ <Footer.Column heading='Category 1'>
72
+ <Footer.NavLink href='#'>Item 1</Footer.NavLink>
73
+ </Footer.Column>
74
+ </Footer>
75
+ </ThemeContextProvider>
76
+ );
77
+
53
78
  expect(
54
- renderResult.container.firstChild
55
- ).toMatchSnapshot();
79
+ screen.getByRole('button', { name: /back to top/i })
80
+ ).toBeInTheDocument();
81
+ expect(screen.getByRole('link', { name: 'Login' })).toHaveAttribute(
82
+ 'href',
83
+ 'https://www.ucl.ac.uk/login'
84
+ );
85
+ expect(screen.getByText('Category 1')).toBeInTheDocument();
86
+ expect(screen.getByRole('link', { name: 'Item 1' })).toHaveClass(
87
+ 'ucl-uikit-footer__nav-link'
88
+ );
56
89
  });
57
90
  });
@@ -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
  import Icon from '../Icon';
5
5
  import scrollToTop from '../../utils/scrollToTop';
6
6
 
@@ -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 FooterColumn from './FooterColumn';
5
5
  import FooterNavLink from './FooterNavLink';
6
6
  import LogoAddressAndSocial from './LogoAddressAndSocial';
@@ -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
 
5
5
  export const NAME = 'ucl-uikit-footer__column';
6
6
 
@@ -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-footer__links';
6
6
 
@@ -1,6 +1,8 @@
1
1
  import { memo } from 'react';
2
2
  import { css, cx } from '@emotion/css';
3
- import { Link, LinkProps, useTheme } from '../..';
3
+ import { useTheme } from '../../theme';
4
+ import Link from '../Link';
5
+ import type { LinkProps } from '../Link';
4
6
 
5
7
  export const NAME = 'ucl-uikit-footer__nav-link';
6
8
 
@@ -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-footer__legal-and-copyright';
6
6
 
@@ -1,6 +1,7 @@
1
1
  import { HTMLAttributes } from 'react';
2
2
  import { css, cx } from '@emotion/css';
3
- import { UclLogoNew, useTheme } from '../..';
3
+ import { useTheme } from '../../theme';
4
+ import UclLogoNew from '../UclLogoNew/UclLogo';
4
5
  import SocialLink from './SocialLink';
5
6
 
6
7
  export const NAME = 'ucl-uikit-footer__logo-address-social';
@@ -1,6 +1,9 @@
1
1
  import { memo } from 'react';
2
2
  import { css, cx } from '@emotion/css';
3
- import { Icon, Link, LinkProps, useTheme } from '../..';
3
+ import { useTheme } from '../../theme';
4
+ import Icon from '../Icon';
5
+ import Link from '../Link';
6
+ import type { LinkProps } from '../Link';
4
7
 
5
8
  export const NAME = 'ucl-uikit-footer__social-link';
6
9
 
@@ -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.3",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",