Skip to content

Commit

Permalink
Merge pull request #7 from kylermintah/master
Browse files Browse the repository at this point in the history
Adding hyperlink support
  • Loading branch information
reezpatel authored Apr 13, 2021
2 parents 9d4c84a + 1c61b58 commit 7067030
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/Components/JSONView/JBlock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const JBlock = ({ children, collapsible, onArrowClick, active, copyData }) => {
const events = React.useContext(EventContext);

const handleSectionClick = (e: MouseEvent) => {
e.preventDefault();
// e.preventDefault();
e.stopPropagation();

setSelected(!selected);
Expand Down
18 changes: 15 additions & 3 deletions app/Components/JSONView/JString/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@ const JString = ({ label, value, isLast }) => {
)}
{value === null ? (
<span className="null">null</span>
) : (
<span className="string">"{value}"</span>
)}
) : isValidHttpUrl(value) ? (
<span className="hyperlink">"<a href={String(value)} target='_blank'>{value}</a>"</span>
) : <span className="string">"{value}"</span>}
{!isLast && ','}
</section>
);
};

function isValidHttpUrl(string) {
let url;

try {
url = new URL(string);
} catch (_) {
return false;
}

return url.protocol === "http:" || url.protocol === "https:";
}

export { JString };
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@types/chrome": "^0.0.96",
"jsonpath": "^1.0.2",
"jsonpath-plus": "^3.0.0",
"parcel-bundler": "^1.12.4",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-icons": "^3.9.0",
Expand All @@ -24,6 +23,7 @@
"typescript": "^3.7.5"
},
"devDependencies": {
"parcel-bundler": "^1.12.3",
"sass": "^1.25.0"
}
}
9 changes: 9 additions & 0 deletions styles/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
--accent-color: #00cc7d;
--accent-color-light: #00cc7e69;
--string-color: #d69d85;
--hyperlink-color: #43beee;
--number-color: #b5cea8;
--boolean-color: #4ec9b0;
--label-color: #569cd6;
Expand Down Expand Up @@ -79,6 +80,14 @@ body {
color: var(--string-color);
}

.hyperlink {
color: var(--hyperlink-color);
}

.hyperlink a{
color: var(--hyperlink-color);
}

.boolean {
color: var(--boolean-color);
}
Expand Down

0 comments on commit 7067030

Please sign in to comment.