|
| 1 | +--- |
| 2 | +
|
| 3 | +interface Props { |
| 4 | + type: "warning" | "info" | "success" | "error"; |
| 5 | + title?: string; |
| 6 | + icon?: string; |
| 7 | +} |
| 8 | +
|
| 9 | +const { type="info", title, icon } = Astro.props; |
| 10 | +
|
| 11 | +// Define styles for different note types |
| 12 | +const styles = { |
| 13 | + warning: { |
| 14 | + bg: "bg-[rgb(255,252,204)]", |
| 15 | + text: "text-[rgb(153,101,21)]", |
| 16 | + border: "border-[rgb(255,204,0)]", |
| 17 | + defaultIcon: "fas fa-exclamation-triangle fa-2x", |
| 18 | + defaultTitle: "Warning" |
| 19 | + }, |
| 20 | + info: { |
| 21 | + bg: "bg-[rgb(229,246,253)]", |
| 22 | + text: "text-[rgb(27,95,133)]", |
| 23 | + border: "border-[rgb(83,177,234)]", |
| 24 | + defaultIcon: "fas fa-info-circle fa-2x", |
| 25 | + defaultTitle: "Info" |
| 26 | + }, |
| 27 | + success: { |
| 28 | + bg: "bg-[rgb(237,247,237)]", |
| 29 | + text: "text-[rgb(48,112,60)]", |
| 30 | + border: "border-[rgb(98,187,112)]", |
| 31 | + defaultIcon: "fas fa-check-circle fa-2x", |
| 32 | + defaultTitle: "Success" |
| 33 | + }, |
| 34 | + error: { |
| 35 | + bg: "bg-[rgb(253,237,237)]", |
| 36 | + text: "text-[rgb(156,38,38)]", |
| 37 | + border: "border-[rgb(244,99,99)]", |
| 38 | + defaultIcon: "fas fa-times-circle fa-2x", |
| 39 | + defaultTitle: "Error" |
| 40 | + } |
| 41 | +}; |
| 42 | +
|
| 43 | +const currentStyle = styles[type]; |
| 44 | +const noteIcon = icon || currentStyle.defaultIcon; |
| 45 | +const noteTitle = title || currentStyle.defaultTitle; |
| 46 | +--- |
| 47 | + |
| 48 | +<p class={`${currentStyle.bg} ${currentStyle.text} border-l-4 ${currentStyle.border} p-4 flex items-center space-x-2`}> |
| 49 | + { noteIcon && |
| 50 | + <i class={noteIcon}></i> |
| 51 | + } |
| 52 | + <span> |
| 53 | + {title && <strong>{noteTitle}:</strong>} |
| 54 | + <slot /> |
| 55 | + </span> |
| 56 | +</p> |
0 commit comments