-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy patherror-summary.tsx
More file actions
47 lines (44 loc) · 1.41 KB
/
error-summary.tsx
File metadata and controls
47 lines (44 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import type { DSErrorSummaryElement } from '@digdir/designsystemet-web';
import { Slot } from '@radix-ui/react-slot';
import cl from 'clsx/lite';
import type { HTMLAttributes, ReactNode } from 'react';
import { forwardRef } from 'react';
import type { DefaultProps } from '../../types';
export type ErrorSummaryProps = {
/**
* @deprecated This is not supported anymore, as the element needs to be `ds-error-summary`
*/
asChild?: ReactNode;
} & Omit<HTMLAttributes<DSErrorSummaryElement> & DefaultProps, 'data-color'>;
/**
* ErrorSummary component, used to display a list of errors.
*
* @example
* <ErrorSummary>
* <ErrorSummary.Heading>Heading</ErrorSummary.Heading>
* <ErrorSummary.List>
* <ErrorSummary.Item>
* <ErrorSummary.Link href='#'>Error 1</ErrorSummary.Link>
* </ErrorSummary.Item>
* <ErrorSummary.Item>
* <ErrorSummary.Link href='#'>Error 2</ErrorSummary.Link>
* </ErrorSummary.Item>
* </ErrorSummary.List>
* </ErrorSummary>
*/
export const ErrorSummary = forwardRef<
DSErrorSummaryElement,
ErrorSummaryProps
>(function ErrorSummary({ asChild, className, ...rest }, ref) {
const Component = asChild ? Slot : 'ds-error-summary';
return (
<Component
{...(asChild
? { className: cl('ds-error-summary', className) }
: { class: cl('ds-error-summary', className) })}
ref={ref}
suppressHydrationWarning
{...rest}
/>
);
});