-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathValidationMessage.tsx
42 lines (39 loc) · 1.08 KB
/
ValidationMessage.tsx
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
import { Slot } from '@radix-ui/react-slot';
import cl from 'clsx/lite';
import type { HTMLAttributes } from 'react';
import { forwardRef } from 'react';
export type ValidationMessageProps = {
/**
* Changes text sizing
* @default md
*/
size?: 'xs' | 'sm' | 'md' | 'lg';
/** Adds margin-bottom */
spacing?: boolean;
/** Toggle error color */
error?: boolean;
/**
* Change the default rendered element for the one passed as a child, merging their props and behavior.
* @default false
*/
asChild?: boolean;
} & HTMLAttributes<HTMLParagraphElement>;
/** Use `ValidationMessage` to display validation text */
export const ValidationMessage = forwardRef<
HTMLParagraphElement,
ValidationMessageProps
>(function ValidationMessage(
{ size = 'md', className, spacing, asChild, error = true, ...rest },
ref,
) {
const Component = asChild ? Slot : 'div';
return (
<Component
className={cl(`ds-validation-message--${size}`, className)}
data-error={error || undefined}
data-spacing={spacing || undefined}
ref={ref}
{...rest}
/>
);
});