Skip to content

Commit 5c5a40f

Browse files
lgeigerrgbkrk
authored andcommitted
Add optional className prop (#25)
1 parent 2c58af9 commit 5c5a40f

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function inlineBundleToReact(bundle, key) {
7171
function Ansi(props) {
7272
return React.createElement(
7373
'code',
74-
{},
74+
{className: props.className},
7575
props.linkify
7676
? ansiToInlineStyle(props.children)
7777
.map(linkifyBundle)
@@ -82,6 +82,7 @@ function Ansi(props) {
8282

8383
Ansi.propTypes = {
8484
children: PropTypes.string,
85+
className: PropTypes.string
8586
};
8687

8788
module.exports = Ansi;

test/index-spec.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ describe('Ansi', () => {
2121
expect(el.html()).to.equal('<code><span>hello </span><span style="color:rgb(0, 187, 0);">world</span></code>');
2222
});
2323

24+
it('can have className', () => {
25+
const el = enzyme.shallow(React.createElement(Ansi, {className: 'my-class'}, `hello world`));
26+
expect(el).to.not.be.null;
27+
expect(el.text()).to.equal('hello world');
28+
expect(el.html()).to.equal('<code class="my-class"><span>hello world</span></code>');
29+
});
30+
2431
it('can nest', () => {
2532
const el = enzyme.shallow(React.createElement(Ansi, null, `hello ${GREEN_FG}wo${YELLOW_BG}rl${RESET}d`));
2633
expect(el).to.not.be.null;
@@ -33,20 +40,20 @@ describe('Ansi', () => {
3340
expect(el).to.not.be.null;
3441
expect(el.text()).to.equal('that sentence\nwill make you pause');
3542
});
36-
43+
3744
it('can linkify', () => {
3845
const el = enzyme.shallow(React.createElement(Ansi, {linkify: true}, 'this is a link: https://nteract.io/'));
3946
expect(el).to.not.be.null;
4047
expect(el.text()).to.equal('this is a link: https://nteract.io/');
4148
expect(el.html()).to.equal('<code><span>this is a link: <a href="https://nteract.io/" target="_blank">https://nteract.io/</a></span></code>');
4249
});
43-
50+
4451
it('can distinguish URL-ish text', () => {
4552
const el = enzyme.shallow(React.createElement(Ansi, {linkify: true}, '<transport.model.TransportInfo'));
4653
expect(el).to.not.be.null;
4754
expect(el.text()).to.equal('<transport.model.TransportInfo');
4855
});
49-
56+
5057
it('can distinguish URL-ish text', () => {
5158
const el = enzyme.shallow(React.createElement(Ansi, {linkify: true}, "<module 'something' from '/usr/local/lib/python2.7/dist-packages/something/__init__.pyc'>"));
5259
expect(el).to.not.be.null;

0 commit comments

Comments
 (0)