uikit-react-public 0.42.0 → 0.43.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/SkipToContent/SkipToContent.d.ts +8 -0
- package/dist/components/SkipToContent/SkipToContent.stories.d.ts +36 -0
- package/dist/components/SkipToContent/__tests__/SkipToContent.test.d.ts +1 -0
- package/dist/components/SkipToContent/index.d.ts +2 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/index.js +3328 -3281
- package/lib/components/SkipToContent/SkipToContent.stories.tsx +47 -0
- package/lib/components/SkipToContent/SkipToContent.tsx +68 -0
- package/lib/components/SkipToContent/__tests__/SkipToContent.test.tsx +38 -0
- package/lib/components/SkipToContent/index.ts +2 -0
- package/lib/components/index.ts +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { css } from '@emotion/css';
|
|
3
|
+
import SkipToContent from './SkipToContent';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Components/SkipToContent',
|
|
7
|
+
component: SkipToContent,
|
|
8
|
+
parameters: {
|
|
9
|
+
layout: 'fullscreen',
|
|
10
|
+
},
|
|
11
|
+
argTypes: {
|
|
12
|
+
href: { control: { type: 'text' } },
|
|
13
|
+
children: { control: { type: 'text' } },
|
|
14
|
+
testId: { control: { type: 'text' } },
|
|
15
|
+
className: { control: false },
|
|
16
|
+
},
|
|
17
|
+
args: {
|
|
18
|
+
href: '#main-content',
|
|
19
|
+
children: 'Skip to content',
|
|
20
|
+
},
|
|
21
|
+
tags: ['autodocs'],
|
|
22
|
+
} satisfies Meta<typeof SkipToContent>;
|
|
23
|
+
|
|
24
|
+
export default meta;
|
|
25
|
+
type Story = StoryObj<typeof meta>;
|
|
26
|
+
|
|
27
|
+
export const Default: Story = {
|
|
28
|
+
render: (args) => (
|
|
29
|
+
<>
|
|
30
|
+
<SkipToContent {...args} />
|
|
31
|
+
<div
|
|
32
|
+
className={css`
|
|
33
|
+
padding: 96px 24px 24px;
|
|
34
|
+
font-family: sans-serif;
|
|
35
|
+
`}
|
|
36
|
+
>
|
|
37
|
+
Press Tab to focus the skip link.
|
|
38
|
+
<main
|
|
39
|
+
id='main-content'
|
|
40
|
+
tabIndex={-1}
|
|
41
|
+
>
|
|
42
|
+
Main content target
|
|
43
|
+
</main>
|
|
44
|
+
</div>
|
|
45
|
+
</>
|
|
46
|
+
),
|
|
47
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AnchorHTMLAttributes, Ref, memo } from 'react';
|
|
2
|
+
import { css, cx } from '@emotion/css';
|
|
3
|
+
import useTheme from '../../theme/useTheme';
|
|
4
|
+
import Button from '../Button';
|
|
5
|
+
|
|
6
|
+
export const NAME = 'ucl-uikit-skip-to-content';
|
|
7
|
+
|
|
8
|
+
export interface SkipToContentProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
9
|
+
testId?: string;
|
|
10
|
+
ref?: Ref<HTMLAnchorElement>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const SkipToContent = ({
|
|
14
|
+
href = '#main-content',
|
|
15
|
+
testId = NAME,
|
|
16
|
+
className,
|
|
17
|
+
children = 'Skip to content',
|
|
18
|
+
ref,
|
|
19
|
+
...props
|
|
20
|
+
}: SkipToContentProps) => {
|
|
21
|
+
const [theme] = useTheme();
|
|
22
|
+
|
|
23
|
+
const wrapperStyle = css`
|
|
24
|
+
box-sizing: border-box;
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: column;
|
|
27
|
+
align-items: flex-start;
|
|
28
|
+
justify-content: center;
|
|
29
|
+
gap: ${theme.padding.p8};
|
|
30
|
+
width: 100%;
|
|
31
|
+
max-height: 0;
|
|
32
|
+
padding: 0 ${theme.padding.p16};
|
|
33
|
+
overflow: hidden;
|
|
34
|
+
background-color: ${theme.colour.fill.inverse};
|
|
35
|
+
|
|
36
|
+
&:focus-within {
|
|
37
|
+
max-height: 72px;
|
|
38
|
+
padding-top: ${theme.padding.p12};
|
|
39
|
+
padding-bottom: ${theme.padding.p12};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@media screen and (min-width: ${theme.breakpoints.tablet}px) {
|
|
43
|
+
padding-right: 60px;
|
|
44
|
+
padding-left: 60px;
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
const style = cx(NAME, className);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div className={wrapperStyle}>
|
|
52
|
+
<Button
|
|
53
|
+
as='a'
|
|
54
|
+
variant='secondary'
|
|
55
|
+
size='small'
|
|
56
|
+
href={href}
|
|
57
|
+
className={style}
|
|
58
|
+
testId={testId}
|
|
59
|
+
ref={ref}
|
|
60
|
+
{...props}
|
|
61
|
+
>
|
|
62
|
+
{children}
|
|
63
|
+
</Button>
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export default memo(SkipToContent);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { ThemeContextProvider } from '../../../theme/useTheme';
|
|
4
|
+
import SkipToContent from '../SkipToContent';
|
|
5
|
+
|
|
6
|
+
const wrap = (ui: React.ReactElement) =>
|
|
7
|
+
render(<ThemeContextProvider>{ui}</ThemeContextProvider>);
|
|
8
|
+
|
|
9
|
+
describe('SkipToContent', () => {
|
|
10
|
+
test('renders with default text and href', () => {
|
|
11
|
+
wrap(<SkipToContent />);
|
|
12
|
+
|
|
13
|
+
const link = screen.getByRole('link', { name: 'Skip to content' });
|
|
14
|
+
|
|
15
|
+
expect(link).toBeInTheDocument();
|
|
16
|
+
expect(link).toHaveAttribute('href', '#main-content');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('accepts custom text and href', () => {
|
|
20
|
+
wrap(<SkipToContent href='#content'>Skip to main content</SkipToContent>);
|
|
21
|
+
|
|
22
|
+
const link = screen.getByRole('link', { name: 'Skip to main content' });
|
|
23
|
+
|
|
24
|
+
expect(link).toHaveAttribute('href', '#content');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('applies custom test id and className', () => {
|
|
28
|
+
const { getByTestId } = wrap(
|
|
29
|
+
<SkipToContent
|
|
30
|
+
testId='custom-skip-link'
|
|
31
|
+
className='custom-class'
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(getByTestId('custom-skip-link')).toBeInTheDocument();
|
|
36
|
+
expect(getByTestId('custom-skip-link').classList).toContain('custom-class');
|
|
37
|
+
});
|
|
38
|
+
});
|
package/lib/components/index.ts
CHANGED
|
@@ -213,6 +213,9 @@ export type { CookieNoticeProps } from './CookieNotice';
|
|
|
213
213
|
export { default as Search } from './Search';
|
|
214
214
|
export type { SearchProps } from './Search';
|
|
215
215
|
|
|
216
|
+
export { default as SkipToContent } from './SkipToContent';
|
|
217
|
+
export type { SkipToContentProps } from './SkipToContent';
|
|
218
|
+
|
|
216
219
|
export { default as Dropdown } from './Dropdown';
|
|
217
220
|
export type {
|
|
218
221
|
DropdownProps,
|