UNPKG

1.97 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const react_1 = __importDefault(require("react"));
7const chalk_1 = __importDefault(require("chalk"));
8const colorize_1 = __importDefault(require("../colorize"));
9/**
10 * This component can display text, and change its style to make it colorful, bold, underline, italic or strikethrough.
11 */
12const Text = ({ color, backgroundColor, dimColor, bold, italic, underline, strikethrough, inverse, wrap, children }) => {
13 if (children === undefined || children === null) {
14 return null;
15 }
16 const transform = (children) => {
17 if (dimColor) {
18 children = chalk_1.default.dim(children);
19 }
20 if (color) {
21 children = colorize_1.default(children, color, 'foreground');
22 }
23 if (backgroundColor) {
24 children = colorize_1.default(children, backgroundColor, 'background');
25 }
26 if (bold) {
27 children = chalk_1.default.bold(children);
28 }
29 if (italic) {
30 children = chalk_1.default.italic(children);
31 }
32 if (underline) {
33 children = chalk_1.default.underline(children);
34 }
35 if (strikethrough) {
36 children = chalk_1.default.strikethrough(children);
37 }
38 if (inverse) {
39 children = chalk_1.default.inverse(children);
40 }
41 return children;
42 };
43 return (react_1.default.createElement("ink-text", { style: { flexGrow: 0, flexShrink: 1, flexDirection: 'row', textWrap: wrap }, internal_transform: transform }, children));
44};
45Text.displayName = 'Text';
46Text.defaultProps = {
47 dimColor: false,
48 bold: false,
49 italic: false,
50 underline: false,
51 strikethrough: false,
52 wrap: 'wrap'
53};
54exports.default = Text;
55//# sourceMappingURL=Text.js.map
\No newline at end of file