uikit-react-public 0.41.0 → 0.42.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.
@@ -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,2 @@
1
+ export { default } from './Callout';
2
+ export type { CalloutProps } from './Callout';
@@ -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
 
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.41.0",
5
+ "version": "0.42.0",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",