| ... | @@ -42,9 +42,13 @@ function alertChildSlot(child: React.ReactElement): string | undefined { | ... | @@ -42,9 +42,13 @@ function alertChildSlot(child: React.ReactElement): string | undefined { |
| 42 | function Alert({ | 42 | function Alert({ |
| 43 | className, | 43 | className, |
| 44 | variant, | 44 | variant, |
| | 45 | controlAlignment = "center", |
| 45 | children, | 46 | children, |
| 46 | ...props | 47 | ...props |
| 47 | }: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) { | 48 | }: React.ComponentProps<"div"> & |
| | 49 | VariantProps<typeof alertVariants> & { |
| | 50 | controlAlignment?: "center" | "first-line"; |
| | 51 | }) { |
| 48 | const icon: React.ReactNode[] = []; | 52 | const icon: React.ReactNode[] = []; |
| 49 | const content: React.ReactNode[] = []; | 53 | const content: React.ReactNode[] = []; |
| 50 | const action: React.ReactNode[] = []; | 54 | const action: React.ReactNode[] = []; |
| ... | @@ -71,9 +75,24 @@ function Alert({ | ... | @@ -71,9 +75,24 @@ function Alert({ |
| 71 | role="alert" | 75 | role="alert" |
| 72 | {...props} | 76 | {...props} |
| 73 | > | 77 | > |
| 74 | <div className="flex items-center gap-2"> | 78 | <div |
| | 79 | className={cn( |
| | 80 | "flex gap-2", |
| | 81 | controlAlignment === "first-line" ? "items-start" : "items-center", |
| | 82 | controlAlignment === "first-line" && |
| | 83 | action.length > 0 && |
| | 84 | "min-h-7 pt-1 sm:min-h-6 sm:pt-0.5", |
| | 85 | )} |
| | 86 | > |
| 75 | {icon.length > 0 && ( | 87 | {icon.length > 0 && ( |
| 76 | <div className="flex size-4 shrink-0 items-center justify-center [&>svg]:size-full"> | 88 | <div |
| | 89 | className={cn( |
| | 90 | "flex shrink-0 items-center justify-center", |
| | 91 | controlAlignment === "first-line" |
| | 92 | ? "h-lh w-4 [&>svg]:size-4" |
| | 93 | : "size-4 [&>svg]:size-full", |
| | 94 | )} |
| | 95 | > |
| 77 | {icon} | 96 | {icon} |
| 78 | </div> | 97 | </div> |
| 79 | )} | 98 | )} |
| ... | @@ -81,7 +100,14 @@ function Alert({ | ... | @@ -81,7 +100,14 @@ function Alert({ |
| 81 | <div className="flex min-w-0 flex-1 flex-col gap-0.5">{content}</div> | 100 | <div className="flex min-w-0 flex-1 flex-col gap-0.5">{content}</div> |
| 82 | )} | 101 | )} |
| 83 | {action.length > 0 && ( | 102 | {action.length > 0 && ( |
| 84 | <div className="flex shrink-0 items-center self-center">{action}</div> | 103 | <div |
| | 104 | className={cn( |
| | 105 | "flex shrink-0 items-center", |
| | 106 | controlAlignment === "first-line" ? "h-lh self-start" : "self-center", |
| | 107 | )} |
| | 108 | > |
| | 109 | {action} |
| | 110 | </div> |
| 85 | )} | 111 | )} |
| 86 | </div> | 112 | </div> |
| 87 | </div> | 113 | </div> |