Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for disabling the fallback #5

Merged
merged 5 commits into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import terminalLink from 'terminal-link';

const Link = props => {
return (
<Text unstable__transformChildren={children => terminalLink(children, props.url)}>
<Text unstable__transformChildren={children => terminalLink(children, props.url, {fallback: props.fallback})}>
{props.children}
</Text>
);
Expand All @@ -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
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved
};

module.exports = Link;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 26 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<Link url="https://sindresorhus.com" fallback={false}>
My Website
</Link>
);
console.log(lastFrame());
t.snapshot(lastFrame());
});

test('include fallback if explicitly enabled', t => {
process.env.FORCE_HYPERLINK = 0;
const Link = require('.');

const {lastFrame} = render(
<Link fallback url="https://sindresorhus.com">
My Website
</Link>
);
console.log(lastFrame());
t.snapshot(lastFrame());
});
14 changes: 13 additions & 1 deletion test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,4 +20,10 @@ Generated by [AVA](https://ava.li).

> Snapshot 1

'My Website (https://sindresorhus.com)'
'My Website (​https://sindresorhus.com​)'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adds zero-width spaces, after bumping to terminal-link@2.0.0


## include fallback if explicitly enabled

> Snapshot 1

'My Website (​https://sindresorhus.com​)'
Binary file modified test.js.snap
Binary file not shown.