2025-04-18 17:44:24 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* @license
|
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2025-08-26 00:04:53 +02:00
|
|
|
|
import type React from 'react';
|
2025-04-15 21:41:08 -07:00
|
|
|
|
import { Text, Box } from 'ink';
|
2025-09-10 10:57:07 -07:00
|
|
|
|
import { theme } from '../../semantic-colors.js';
|
2025-08-18 13:26:34 +08:00
|
|
|
|
import { RenderInline } from '../../utils/InlineMarkdownRenderer.js';
|
2025-04-15 21:41:08 -07:00
|
|
|
|
|
|
|
|
|
|
interface InfoMessageProps {
|
2025-04-17 18:06:21 -04:00
|
|
|
|
text: string;
|
2026-03-03 01:22:29 -08:00
|
|
|
|
secondaryText?: string;
|
2025-11-07 15:17:23 -08:00
|
|
|
|
icon?: string;
|
|
|
|
|
|
color?: string;
|
2026-02-18 14:05:50 -08:00
|
|
|
|
marginBottom?: number;
|
2025-04-15 21:41:08 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-07 15:17:23 -08:00
|
|
|
|
export const InfoMessage: React.FC<InfoMessageProps> = ({
|
|
|
|
|
|
text,
|
2026-03-03 01:22:29 -08:00
|
|
|
|
secondaryText,
|
2025-11-07 15:17:23 -08:00
|
|
|
|
icon,
|
|
|
|
|
|
color,
|
2026-02-18 14:05:50 -08:00
|
|
|
|
marginBottom,
|
2025-11-07 15:17:23 -08:00
|
|
|
|
}) => {
|
|
|
|
|
|
color ??= theme.status.warning;
|
|
|
|
|
|
const prefix = icon ?? 'ℹ ';
|
2025-04-17 18:06:21 -04:00
|
|
|
|
const prefixWidth = prefix.length;
|
2025-04-15 21:41:08 -07:00
|
|
|
|
|
2025-04-17 18:06:21 -04:00
|
|
|
|
return (
|
2026-02-18 14:05:50 -08:00
|
|
|
|
<Box flexDirection="row" marginTop={1} marginBottom={marginBottom ?? 0}>
|
2025-04-17 18:06:21 -04:00
|
|
|
|
<Box width={prefixWidth}>
|
2025-11-07 15:17:23 -08:00
|
|
|
|
<Text color={color}>{prefix}</Text>
|
2025-04-17 18:06:21 -04:00
|
|
|
|
</Box>
|
2025-11-05 16:12:06 -05:00
|
|
|
|
<Box flexGrow={1} flexDirection="column">
|
|
|
|
|
|
{text.split('\n').map((line, index) => (
|
|
|
|
|
|
<Text wrap="wrap" key={index}>
|
2025-11-07 15:17:23 -08:00
|
|
|
|
<RenderInline text={line} defaultColor={color} />
|
2026-03-03 01:22:29 -08:00
|
|
|
|
{index === text.split('\n').length - 1 && secondaryText && (
|
|
|
|
|
|
<Text color={theme.text.secondary}> {secondaryText}</Text>
|
|
|
|
|
|
)}
|
2025-11-05 16:12:06 -05:00
|
|
|
|
</Text>
|
|
|
|
|
|
))}
|
2025-04-17 18:06:21 -04:00
|
|
|
|
</Box>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
);
|
2025-04-15 21:41:08 -07:00
|
|
|
|
};
|