diff --git a/index.js b/index.js index 03f8397..e9124f2 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ import terminalLink from 'terminal-link'; const Link = props => { return ( - terminalLink(children, props.url)}> + terminalLink(children, props.url, {fallback: props.fallback})}> {props.children} ); @@ -16,11 +16,13 @@ Link.propTypes = { PropTypes.arrayOf(PropTypes.node), PropTypes.node ]).isRequired, - url: PropTypes.string + url: PropTypes.string, + fallback: PropTypes.bool }; Link.defaultProps = { - url: '' + url: '', + fallback: true }; module.exports = Link; diff --git a/package.json b/package.json index 8256007..2fccaa1 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ ], "dependencies": { "prop-types": "^15.7.2", - "terminal-link": "^1.2.0" + "terminal-link": "^2.1.1" }, "devDependencies": { "@babel/cli": "^7.2.3", diff --git a/readme.md b/readme.md index fd4c8ec..b3c20bb 100644 --- a/readme.md +++ b/readme.md @@ -43,6 +43,12 @@ Type: `string` The URL to link to. +#### fallback + +Type: `boolean`\ +Default: `true` + +Determines whether the URL should be printed in parens after the text for unsupported terminals: `My website (https://sindresorhus.com)`. ## Related diff --git a/test.js b/test.js index 0c0a418..5873b45 100644 --- a/test.js +++ b/test.js @@ -37,3 +37,29 @@ test('render fallback', t => { console.log(lastFrame()); t.snapshot(lastFrame()); }); + +test('exclude fallback if disabled', t => { + process.env.FORCE_HYPERLINK = 0; + const Link = require('.'); + + const {lastFrame} = render( + + My Website + + ); + console.log(lastFrame()); + t.snapshot(lastFrame()); +}); + +test('include fallback if explicitly enabled', t => { + process.env.FORCE_HYPERLINK = 0; + const Link = require('.'); + + const {lastFrame} = render( + + My Website + + ); + console.log(lastFrame()); + t.snapshot(lastFrame()); +}); diff --git a/test.js.md b/test.js.md index b04778a..91d2879 100644 --- a/test.js.md +++ b/test.js.md @@ -4,6 +4,12 @@ The actual snapshot is saved in `test.js.snap`. Generated by [AVA](https://ava.li). +## exclude fallback if disabled + +> Snapshot 1 + + 'My Website' + ## render > Snapshot 1 @@ -14,4 +20,10 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - 'My Website (https://sindresorhus.com)' + 'My Website (​https://sindresorhus.com​)' + +## include fallback if explicitly enabled + +> Snapshot 1 + + 'My Website (​https://sindresorhus.com​)' diff --git a/test.js.snap b/test.js.snap index 35dd436..7dc4752 100644 Binary files a/test.js.snap and b/test.js.snap differ