Skip to content

Commit 75573b6

Browse files
George KaragkiaourisVadim Demedes
authored andcommitted
Rename <Text> to <Color> and add <Bold> and <Underline> (#69)
1 parent 11c4e94 commit 75573b6

5 files changed

Lines changed: 43 additions & 7 deletions

File tree

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ const renderToString = require('./lib/render-to-string');
88
const diff = require('./lib/diff');
99
const h = require('./lib/h');
1010
const Indent = require('./lib/components/indent');
11-
const Text = require('./lib/components/text');
11+
const Color = require('./lib/components/color');
12+
const Bold = require('./lib/components/bold');
13+
const Underline = require('./lib/components/underline');
1214

1315
exports.StringComponent = StringComponent;
1416
exports.Component = Component;
1517
exports.h = h;
1618
exports.Indent = Indent;
17-
exports.Text = Text;
19+
exports.Color = Color;
20+
exports.Underline = Underline;
21+
exports.Bold = Bold;
1822

1923
const noop = () => {};
2024

lib/components/bold.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const chalk = require('chalk');
4+
const StringComponent = require('../string-component');
5+
6+
class Bold extends StringComponent {
7+
renderString(children) {
8+
return chalk.bold(children);
9+
}
10+
}
11+
12+
module.exports = Bold;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const methods = [
1919
'bgKeyword'
2020
];
2121

22-
class Text extends StringComponent {
22+
class Color extends StringComponent {
2323
renderString(children) {
2424
Object.keys(this.props).forEach(method => {
2525
if (this.props[method]) {
@@ -35,4 +35,4 @@ class Text extends StringComponent {
3535
}
3636
}
3737

38-
module.exports = Text;
38+
module.exports = Color;

lib/components/underline.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const chalk = require('chalk');
4+
const StringComponent = require('../string-component');
5+
6+
class Underline extends StringComponent {
7+
renderString(children) {
8+
return chalk.underline(children);
9+
}
10+
}
11+
12+
module.exports = Underline;

test/components.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {spy, stub} from 'sinon';
33
import ansiStyles from 'ansi-styles';
44
import chalk from 'chalk';
55
import test from 'ava';
6-
import {h, build, Indent, Text, Component} from '..';
6+
import {h, build, Indent, Color, Underline, Bold, Component} from '..';
77
import renderToString from '../lib/render-to-string';
88
import {rerender} from '../lib/render-queue';
99

@@ -656,10 +656,18 @@ test('render styled text', t => {
656656
[style]: true
657657
};
658658

659-
t.is(renderToString(build(<Text {...props}>Test</Text>)), chalk[style]('Test'));
659+
t.is(renderToString(build(<Color {...props}>Test</Color>)), chalk[style]('Test'));
660660
}
661661

662-
t.is(renderToString(build(<Text rgb={[40, 42, 54]}>Test</Text>)), chalk.rgb(40, 42, 54)('Test'));
662+
t.is(renderToString(build(<Color rgb={[40, 42, 54]}>Test</Color>)), chalk.rgb(40, 42, 54)('Test'));
663+
});
664+
665+
test('render bold text', t => {
666+
t.is(renderToString(build(<Bold>Test</Bold>)), chalk.bold('Test'));
667+
});
668+
669+
test('render underlined text', t => {
670+
t.is(renderToString(build(<Underline>Test</Underline>)), chalk.underline('Test'));
663671
});
664672

665673
test('indent text', t => {

0 commit comments

Comments
 (0)