|
1 | | -import React from "react"; |
2 | | -import { classNames } from "../../util/class-names"; |
3 | | -import { ErrorIcon, InfoSignIcon, TickCircleIcon, WarningSignIcon } from "../../icons"; |
| 1 | +import type { ElementType, ComponentPropsWithoutRef } from 'react' |
| 2 | +import { ReactNode } from 'react' |
| 3 | +import { classNames } from '../../util/class-names' |
| 4 | +import { |
| 5 | + ErrorIcon, |
| 6 | + InfoSignIcon, |
| 7 | + TickCircleIcon, |
| 8 | + WarningSignIcon, |
| 9 | +} from '../../icons' |
4 | 10 |
|
5 | | -export type AlertIntent = "success" | "info" | "warning" | "danger"; |
| 11 | +export type AlertIntent = 'success' | 'info' | 'warning' | 'danger' |
6 | 12 |
|
7 | 13 | const alertVariants: Record<AlertIntent, string> = { |
8 | | - info: "border-primary-400 bg-primary-50 text-primary-600", |
9 | | - danger: "border-danger-400 bg-danger-50 text-danger-500", |
10 | | - warning: "border-warning-500 bg-warning-50 text-warning-600", |
11 | | - success: "border-success-400 bg-success-50 text-success-500", |
12 | | -}; |
| 14 | + info: 'border-primary-400 bg-primary-50 text-primary-600', |
| 15 | + danger: 'border-danger-400 bg-danger-50 text-danger-500', |
| 16 | + warning: 'border-warning-500 bg-warning-50 text-warning-600', |
| 17 | + success: 'border-success-400 bg-success-50 text-success-500', |
| 18 | +} |
13 | 19 |
|
14 | 20 | const iconVariants: Record<AlertIntent, string> = { |
15 | | - info: "fill-primary-500", |
16 | | - danger: "fill-danger-400", |
17 | | - success: "fill-success-400", |
18 | | - warning: "fill-warning-500", |
19 | | -}; |
| 21 | + info: 'fill-primary-500', |
| 22 | + danger: 'fill-danger-400', |
| 23 | + success: 'fill-success-400', |
| 24 | + warning: 'fill-warning-500', |
| 25 | +} |
20 | 26 |
|
21 | | -const iconNames: Record<AlertIntent, React.ElementType> = { |
22 | | - info: InfoSignIcon, |
23 | | - success: TickCircleIcon, |
24 | | - warning: WarningSignIcon, |
25 | | - danger: ErrorIcon, |
26 | | -}; |
| 27 | +const iconNames: Record<AlertIntent, ElementType> = { |
| 28 | + info: InfoSignIcon, |
| 29 | + success: TickCircleIcon, |
| 30 | + warning: WarningSignIcon, |
| 31 | + danger: ErrorIcon, |
| 32 | +} |
27 | 33 |
|
28 | | -export interface AlertProps extends React.ComponentPropsWithoutRef<"div"> { |
29 | | - title: string; |
30 | | - intent: AlertIntent; |
31 | | - children?: React.ReactNode; |
| 34 | +export interface AlertProps extends ComponentPropsWithoutRef<'div'> { |
| 35 | + title: string |
| 36 | + intent: AlertIntent |
| 37 | + children?: ReactNode |
32 | 38 | } |
33 | 39 |
|
34 | | -export const Alert = ({ title, children, intent, className, ...props }: AlertProps) => { |
35 | | - const Icon = iconNames[intent]; |
| 40 | +export const Alert = ({ |
| 41 | + title, |
| 42 | + children, |
| 43 | + intent, |
| 44 | + className, |
| 45 | + ...props |
| 46 | +}: AlertProps) => { |
| 47 | + const Icon = iconNames[intent] |
36 | 48 |
|
37 | | - return ( |
38 | | - <div |
39 | | - role="alert" |
40 | | - className={classNames( |
41 | | - "flex flex-row gap-4 rounded-lg border px-4 py-3 text-neutral-800", |
42 | | - alertVariants[intent], |
43 | | - className |
44 | | - )} |
45 | | - {...props} |
46 | | - > |
47 | | - <Icon className={classNames("h-4 w-4 shrink-0", iconVariants[intent])} /> |
48 | | - <div className="grow"> |
49 | | - <div className="text-sm font-medium">{title}</div> |
50 | | - {children && <div className="pt-1 text-sm text-neutral-800">{children}</div>} |
51 | | - </div> |
52 | | - </div> |
53 | | - ); |
54 | | -}; |
| 49 | + return ( |
| 50 | + <div |
| 51 | + role='alert' |
| 52 | + className={classNames( |
| 53 | + 'flex flex-row gap-4 rounded-lg border px-4 py-3 text-neutral-800', |
| 54 | + alertVariants[intent], |
| 55 | + className, |
| 56 | + )} |
| 57 | + {...props} |
| 58 | + > |
| 59 | + <Icon className={classNames('h-4 w-4 shrink-0', iconVariants[intent])} /> |
| 60 | + <div className='grow'> |
| 61 | + <div className='text-sm font-medium'>{title}</div> |
| 62 | + {children && ( |
| 63 | + <div className='pt-1 text-sm text-neutral-800'>{children}</div> |
| 64 | + )} |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + ) |
| 68 | +} |
0 commit comments