uikit-react-public 0.41.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/Callout/Callout.d.ts +13 -0
- package/dist/components/Callout/Callout.stories.d.ts +48 -0
- package/dist/components/Callout/__tests__/Callout.test.d.ts +1 -0
- package/dist/components/Callout/index.d.ts +2 -0
- 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 +4 -0
- package/dist/index.js +4571 -4448
- package/lib/components/Callout/Callout.stories.tsx +56 -0
- package/lib/components/Callout/Callout.tsx +109 -0
- package/lib/components/Callout/__tests__/Callout.test.tsx +59 -0
- package/lib/components/Callout/index.ts +2 -0
- 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 +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { css } from '@emotion/css';
|
|
3
|
+
import Callout from './Callout';
|
|
4
|
+
import Icon from '../Icon';
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Components/Callout',
|
|
8
|
+
component: Callout,
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'centered',
|
|
11
|
+
},
|
|
12
|
+
argTypes: {
|
|
13
|
+
heading: { control: { type: 'text' } },
|
|
14
|
+
children: { control: { type: 'text' } },
|
|
15
|
+
showIcon: { control: { type: 'boolean' } },
|
|
16
|
+
icon: { control: false },
|
|
17
|
+
testId: { control: { type: 'text' } },
|
|
18
|
+
className: { control: false },
|
|
19
|
+
},
|
|
20
|
+
args: {
|
|
21
|
+
heading: 'Nobody at UCL will ever ask you for your password',
|
|
22
|
+
children:
|
|
23
|
+
"If you're unsure a request is genuine, contact OneDesk IT before entering anything.",
|
|
24
|
+
showIcon: true,
|
|
25
|
+
},
|
|
26
|
+
tags: ['autodocs'],
|
|
27
|
+
} satisfies Meta<typeof Callout>;
|
|
28
|
+
|
|
29
|
+
export default meta;
|
|
30
|
+
type Story = StoryObj<typeof meta>;
|
|
31
|
+
|
|
32
|
+
export const Default: Story = {};
|
|
33
|
+
|
|
34
|
+
export const WithoutIcon: Story = {
|
|
35
|
+
args: {
|
|
36
|
+
showIcon: false,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const CustomIcon: Story = {
|
|
41
|
+
args: {
|
|
42
|
+
icon: <Icon.Info size={24} />,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const ConstrainedWidth: Story = {
|
|
47
|
+
render: (args) => (
|
|
48
|
+
<div
|
|
49
|
+
className={css`
|
|
50
|
+
width: 420px;
|
|
51
|
+
`}
|
|
52
|
+
>
|
|
53
|
+
<Callout {...args} />
|
|
54
|
+
</div>
|
|
55
|
+
),
|
|
56
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { HTMLAttributes, ReactNode, Ref, memo } from 'react';
|
|
2
|
+
import { css, cx } from '@emotion/css';
|
|
3
|
+
import useTheme from '../../theme/useTheme';
|
|
4
|
+
import marginsStyle, { MarginProps } from '../common/marginsStyle';
|
|
5
|
+
import Heading from '../Heading';
|
|
6
|
+
import Icon from '../Icon';
|
|
7
|
+
import Paragraph from '../Paragraph';
|
|
8
|
+
|
|
9
|
+
export const NAME = 'ucl-uikit-callout';
|
|
10
|
+
|
|
11
|
+
export interface CalloutBaseProps extends HTMLAttributes<HTMLDivElement> {
|
|
12
|
+
heading?: ReactNode;
|
|
13
|
+
icon?: ReactNode;
|
|
14
|
+
showIcon?: boolean;
|
|
15
|
+
testId?: string;
|
|
16
|
+
ref?: Ref<HTMLDivElement>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type CalloutProps = CalloutBaseProps & MarginProps;
|
|
20
|
+
|
|
21
|
+
const Callout = ({
|
|
22
|
+
heading,
|
|
23
|
+
icon,
|
|
24
|
+
showIcon = true,
|
|
25
|
+
testId = NAME,
|
|
26
|
+
className,
|
|
27
|
+
children,
|
|
28
|
+
ref,
|
|
29
|
+
...props
|
|
30
|
+
}: CalloutProps) => {
|
|
31
|
+
const [theme] = useTheme();
|
|
32
|
+
|
|
33
|
+
const baseStyle = css`
|
|
34
|
+
box-sizing: border-box;
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
align-items: flex-start;
|
|
38
|
+
gap: 30px;
|
|
39
|
+
width: 100%;
|
|
40
|
+
padding: ${theme.padding.p24};
|
|
41
|
+
background-color: ${theme.colour.surface.brand};
|
|
42
|
+
border: 1px solid ${theme.colour.border.brand};
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
const rowStyle = css`
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: flex-start;
|
|
48
|
+
gap: ${theme.padding.p16};
|
|
49
|
+
width: 100%;
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
const iconStyle = css`
|
|
53
|
+
flex: 0 0 auto;
|
|
54
|
+
color: ${theme.colour.icon.brand};
|
|
55
|
+
`;
|
|
56
|
+
|
|
57
|
+
const contentStyle = css`
|
|
58
|
+
display: flex;
|
|
59
|
+
flex: 1 1 auto;
|
|
60
|
+
flex-direction: column;
|
|
61
|
+
justify-content: center;
|
|
62
|
+
align-items: flex-start;
|
|
63
|
+
gap: ${theme.padding.p8};
|
|
64
|
+
min-width: 0;
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
const style = cx(NAME, baseStyle, marginsStyle(props, theme), className);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div
|
|
71
|
+
className={style}
|
|
72
|
+
data-testid={testId}
|
|
73
|
+
ref={ref}
|
|
74
|
+
{...props}
|
|
75
|
+
>
|
|
76
|
+
<div className={rowStyle}>
|
|
77
|
+
{showIcon && (
|
|
78
|
+
<span
|
|
79
|
+
className={iconStyle}
|
|
80
|
+
aria-hidden='true'
|
|
81
|
+
>
|
|
82
|
+
{icon ?? <Icon.Info size={24} />}
|
|
83
|
+
</span>
|
|
84
|
+
)}
|
|
85
|
+
<div className={contentStyle}>
|
|
86
|
+
{heading && (
|
|
87
|
+
<Heading
|
|
88
|
+
level='xs'
|
|
89
|
+
as='h3'
|
|
90
|
+
noMargins
|
|
91
|
+
>
|
|
92
|
+
{heading}
|
|
93
|
+
</Heading>
|
|
94
|
+
)}
|
|
95
|
+
{children && (
|
|
96
|
+
<Paragraph
|
|
97
|
+
level='md'
|
|
98
|
+
noMargins
|
|
99
|
+
>
|
|
100
|
+
{children}
|
|
101
|
+
</Paragraph>
|
|
102
|
+
)}
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default memo(Callout);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { ThemeContextProvider } from '../../../theme/useTheme';
|
|
4
|
+
import Callout from '../Callout';
|
|
5
|
+
|
|
6
|
+
const wrap = (ui: React.ReactElement) =>
|
|
7
|
+
render(<ThemeContextProvider>{ui}</ThemeContextProvider>);
|
|
8
|
+
|
|
9
|
+
describe('Callout', () => {
|
|
10
|
+
test('renders with default test id', () => {
|
|
11
|
+
const { getByTestId } = wrap(<Callout />);
|
|
12
|
+
|
|
13
|
+
expect(getByTestId('ucl-uikit-callout')).toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('renders heading and children', () => {
|
|
17
|
+
wrap(
|
|
18
|
+
<Callout heading='Nobody at UCL will ever ask you for your password'>
|
|
19
|
+
If you're unsure a request is genuine, contact OneDesk IT before
|
|
20
|
+
entering anything.
|
|
21
|
+
</Callout>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
expect(
|
|
25
|
+
screen.getByRole('heading', {
|
|
26
|
+
name: 'Nobody at UCL will ever ask you for your password',
|
|
27
|
+
})
|
|
28
|
+
).toBeInTheDocument();
|
|
29
|
+
expect(
|
|
30
|
+
screen.getByText(
|
|
31
|
+
/If you're unsure a request is genuine, contact OneDesk IT/
|
|
32
|
+
)
|
|
33
|
+
).toBeInTheDocument();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('applies custom test id and className', () => {
|
|
37
|
+
const { getByTestId } = wrap(
|
|
38
|
+
<Callout
|
|
39
|
+
testId='custom-callout'
|
|
40
|
+
className='custom-class'
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(getByTestId('custom-callout')).toBeInTheDocument();
|
|
45
|
+
expect(getByTestId('custom-callout').classList).toContain('custom-class');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('renders an icon by default', () => {
|
|
49
|
+
const { container } = wrap(<Callout />);
|
|
50
|
+
|
|
51
|
+
expect(container.querySelector('svg')).toBeInTheDocument();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('can hide the icon', () => {
|
|
55
|
+
const { container } = wrap(<Callout showIcon={false} />);
|
|
56
|
+
|
|
57
|
+
expect(container.querySelector('svg')).not.toBeInTheDocument();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -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
|
@@ -13,6 +13,9 @@ export type { StandaloneLinkProps } from './StandaloneLink';
|
|
|
13
13
|
export { default as Button } from './Button';
|
|
14
14
|
export type { ButtonProps } from './Button';
|
|
15
15
|
|
|
16
|
+
export { default as Callout } from './Callout';
|
|
17
|
+
export type { CalloutProps } from './Callout';
|
|
18
|
+
|
|
16
19
|
export { default as Label } from './Label';
|
|
17
20
|
export type { LabelProps } from './Label';
|
|
18
21
|
|
|
@@ -210,6 +213,9 @@ export type { CookieNoticeProps } from './CookieNotice';
|
|
|
210
213
|
export { default as Search } from './Search';
|
|
211
214
|
export type { SearchProps } from './Search';
|
|
212
215
|
|
|
216
|
+
export { default as SkipToContent } from './SkipToContent';
|
|
217
|
+
export type { SkipToContentProps } from './SkipToContent';
|
|
218
|
+
|
|
213
219
|
export { default as Dropdown } from './Dropdown';
|
|
214
220
|
export type {
|
|
215
221
|
DropdownProps,
|