File size: 1,080 Bytes
7e3630c fcdf1d0 7e3630c fcdf1d0 7e3630c fcdf1d0 7e3630c | 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 43 44 45 | import { Box, type DOMElement, Newline, Text } from "src/ink";
import React, { forwardRef } from "react";
export interface ImageBoxProps {
width: number | string;
height: number | string; // 字符高度(占位)
alt?: string;
error?: boolean;
loaded?: boolean;
children?: React.ReactNode;
}
const ImageBox = forwardRef<DOMElement, ImageBoxProps>(function ImageBox(
{ width, height, alt, error, loaded, children },
ref,
) {
return (
<Box ref={ref} flexDirection="column" width={width} height={height}>
{loaded && children ? (
children
) : (
<Box
flexDirection="column"
alignItems="center"
justifyContent="center"
overflow="hidden"
>
{alt ? (
<Text color="gray">{alt}</Text>
) : error ? (
<Text color="red">
X<Newline />
Load failed
</Text>
) : (
<Text color="gray">Loading...</Text>
)}
</Box>
)}
</Box>
);
});
export default ImageBox;
|