From a939ae7e7a9bb9b2be22456235697468add15d84 Mon Sep 17 00:00:00 2001 From: Jonas Braathen <jonas.braathen@usit.uio.no> Date: Tue, 14 Sep 2021 11:38:17 +0200 Subject: [PATCH] Add airbnb-typescript and prettier to .eslintrc, format files with prettier --- frontend/.eslintrc.json | 15 ++- frontend/package-lock.json | 140 +++++++++++------------ frontend/package.json | 4 +- frontend/src/App.tsx | 22 +++- frontend/src/components/button/index.tsx | 1 + frontend/src/components/link/index.tsx | 134 +++++++++++----------- 6 files changed, 163 insertions(+), 153 deletions(-) diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json index cc6f1cb0..ef74cbdb 100644 --- a/frontend/.eslintrc.json +++ b/frontend/.eslintrc.json @@ -6,19 +6,22 @@ }, "extends": [ "plugin:react/recommended", - "airbnb" + "airbnb", + "airbnb-typescript", + "prettier" ], "parser": "@typescript-eslint/parser", "parserOptions": { + "project": "./tsconfig.json", "ecmaFeatures": { "jsx": true }, "ecmaVersion": 12, "sourceType": "module" }, - "plugins": [ - "react", - "@typescript-eslint" - ], - "rules": {} + "plugins": ["react", "@typescript-eslint"], + "rules": { + "semi": "off", + "@typescript-eslint/semi": ["error", "never"] + } } diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 28f9dcfb..308d7855 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -28,8 +28,8 @@ "web-vitals": "^1.1.2" }, "devDependencies": { - "@typescript-eslint/eslint-plugin": "^4.31.0", - "@typescript-eslint/parser": "^4.31.0", + "@typescript-eslint/eslint-plugin": "^4.31.1", + "@typescript-eslint/parser": "^4.31.1", "eslint": "^7.32.0", "eslint-config-airbnb": "^18.2.1", "eslint-config-airbnb-typescript": "^14.0.0", @@ -3605,12 +3605,12 @@ "integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==" }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "4.31.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.31.0.tgz", - "integrity": "sha512-iPKZTZNavAlOhfF4gymiSuUkgLne/nh5Oz2/mdiUmuZVD42m9PapnCnzjxuDsnpnbH3wT5s2D8bw6S39TC6GNw==", + "version": "4.31.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.31.1.tgz", + "integrity": "sha512-UDqhWmd5i0TvPLmbK5xY3UZB0zEGseF+DHPghZ37Sb83Qd3p8ujhvAtkU4OF46Ka5Pm5kWvFIx0cCTBFKo0alA==", "dependencies": { - "@typescript-eslint/experimental-utils": "4.31.0", - "@typescript-eslint/scope-manager": "4.31.0", + "@typescript-eslint/experimental-utils": "4.31.1", + "@typescript-eslint/scope-manager": "4.31.1", "debug": "^4.3.1", "functional-red-black-tree": "^1.0.1", "regexpp": "^3.1.0", @@ -3649,14 +3649,14 @@ } }, "node_modules/@typescript-eslint/experimental-utils": { - "version": "4.31.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.31.0.tgz", - "integrity": "sha512-Hld+EQiKLMppgKKkdUsLeVIeEOrwKc2G983NmznY/r5/ZtZCDvIOXnXtwqJIgYz/ymsy7n7RGvMyrzf1WaSQrw==", + "version": "4.31.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.31.1.tgz", + "integrity": "sha512-NtoPsqmcSsWty0mcL5nTZXMf7Ei0Xr2MT8jWjXMVgRK0/1qeQ2jZzLFUh4QtyJ4+/lPUyMw5cSfeeME+Zrtp9Q==", "dependencies": { "@types/json-schema": "^7.0.7", - "@typescript-eslint/scope-manager": "4.31.0", - "@typescript-eslint/types": "4.31.0", - "@typescript-eslint/typescript-estree": "4.31.0", + "@typescript-eslint/scope-manager": "4.31.1", + "@typescript-eslint/types": "4.31.1", + "@typescript-eslint/typescript-estree": "4.31.1", "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0" }, @@ -3672,13 +3672,13 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "4.31.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.31.0.tgz", - "integrity": "sha512-oWbzvPh5amMuTmKaf1wp0ySxPt2ZXHnFQBN2Szu1O//7LmOvgaKTCIDNLK2NvzpmVd5A2M/1j/rujBqO37hj3w==", + "version": "4.31.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.31.1.tgz", + "integrity": "sha512-dnVZDB6FhpIby6yVbHkwTKkn2ypjVIfAR9nh+kYsA/ZL0JlTsd22BiDjouotisY3Irmd3OW1qlk9EI5R8GrvRQ==", "dependencies": { - "@typescript-eslint/scope-manager": "4.31.0", - "@typescript-eslint/types": "4.31.0", - "@typescript-eslint/typescript-estree": "4.31.0", + "@typescript-eslint/scope-manager": "4.31.1", + "@typescript-eslint/types": "4.31.1", + "@typescript-eslint/typescript-estree": "4.31.1", "debug": "^4.3.1" }, "engines": { @@ -3698,12 +3698,12 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "4.31.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.31.0.tgz", - "integrity": "sha512-LJ+xtl34W76JMRLjbaQorhR0hfRAlp3Lscdiz9NeI/8i+q0hdBZ7BsiYieLoYWqy+AnRigaD3hUwPFugSzdocg==", + "version": "4.31.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.31.1.tgz", + "integrity": "sha512-N1Uhn6SqNtU2XpFSkD4oA+F0PfKdWHyr4bTX0xTj8NRx1314gBDRL1LUuZd5+L3oP+wo6hCbZpaa1in6SwMcVQ==", "dependencies": { - "@typescript-eslint/types": "4.31.0", - "@typescript-eslint/visitor-keys": "4.31.0" + "@typescript-eslint/types": "4.31.1", + "@typescript-eslint/visitor-keys": "4.31.1" }, "engines": { "node": "^8.10.0 || ^10.13.0 || >=11.10.1" @@ -3714,9 +3714,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "4.31.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.31.0.tgz", - "integrity": "sha512-9XR5q9mk7DCXgXLS7REIVs+BaAswfdHhx91XqlJklmqWpTALGjygWVIb/UnLh4NWhfwhR5wNe1yTyCInxVhLqQ==", + "version": "4.31.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.31.1.tgz", + "integrity": "sha512-kixltt51ZJGKENNW88IY5MYqTBA8FR0Md8QdGbJD2pKZ+D5IvxjTYDNtJPDxFBiXmka2aJsITdB1BtO1fsgmsQ==", "engines": { "node": "^8.10.0 || ^10.13.0 || >=11.10.1" }, @@ -3726,12 +3726,12 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "4.31.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.31.0.tgz", - "integrity": "sha512-QHl2014t3ptg+xpmOSSPn5hm4mY8D4s97ftzyk9BZ8RxYQ3j73XcwuijnJ9cMa6DO4aLXeo8XS3z1omT9LA/Eg==", + "version": "4.31.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.31.1.tgz", + "integrity": "sha512-EGHkbsUvjFrvRnusk6yFGqrqMBTue5E5ROnS5puj3laGQPasVUgwhrxfcgkdHNFECHAewpvELE1Gjv0XO3mdWg==", "dependencies": { - "@typescript-eslint/types": "4.31.0", - "@typescript-eslint/visitor-keys": "4.31.0", + "@typescript-eslint/types": "4.31.1", + "@typescript-eslint/visitor-keys": "4.31.1", "debug": "^4.3.1", "globby": "^11.0.3", "is-glob": "^4.0.1", @@ -3766,11 +3766,11 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "4.31.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.31.0.tgz", - "integrity": "sha512-HUcRp2a9I+P21+O21yu3ezv3GEPGjyGiXoEUQwZXjR8UxRApGeLyWH4ZIIUSalE28aG4YsV6GjtaAVB3QKOu0w==", + "version": "4.31.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.31.1.tgz", + "integrity": "sha512-PCncP8hEqKw6SOJY+3St4LVtoZpPPn+Zlpm7KW5xnviMhdqcsBty4Lsg4J/VECpJjw1CkROaZhH4B8M1OfnXTQ==", "dependencies": { - "@typescript-eslint/types": "4.31.0", + "@typescript-eslint/types": "4.31.1", "eslint-visitor-keys": "^2.0.0" }, "engines": { @@ -24347,12 +24347,12 @@ "integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==" }, "@typescript-eslint/eslint-plugin": { - "version": "4.31.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.31.0.tgz", - "integrity": "sha512-iPKZTZNavAlOhfF4gymiSuUkgLne/nh5Oz2/mdiUmuZVD42m9PapnCnzjxuDsnpnbH3wT5s2D8bw6S39TC6GNw==", + "version": "4.31.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.31.1.tgz", + "integrity": "sha512-UDqhWmd5i0TvPLmbK5xY3UZB0zEGseF+DHPghZ37Sb83Qd3p8ujhvAtkU4OF46Ka5Pm5kWvFIx0cCTBFKo0alA==", "requires": { - "@typescript-eslint/experimental-utils": "4.31.0", - "@typescript-eslint/scope-manager": "4.31.0", + "@typescript-eslint/experimental-utils": "4.31.1", + "@typescript-eslint/scope-manager": "4.31.1", "debug": "^4.3.1", "functional-red-black-tree": "^1.0.1", "regexpp": "^3.1.0", @@ -24371,50 +24371,50 @@ } }, "@typescript-eslint/experimental-utils": { - "version": "4.31.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.31.0.tgz", - "integrity": "sha512-Hld+EQiKLMppgKKkdUsLeVIeEOrwKc2G983NmznY/r5/ZtZCDvIOXnXtwqJIgYz/ymsy7n7RGvMyrzf1WaSQrw==", + "version": "4.31.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.31.1.tgz", + "integrity": "sha512-NtoPsqmcSsWty0mcL5nTZXMf7Ei0Xr2MT8jWjXMVgRK0/1qeQ2jZzLFUh4QtyJ4+/lPUyMw5cSfeeME+Zrtp9Q==", "requires": { "@types/json-schema": "^7.0.7", - "@typescript-eslint/scope-manager": "4.31.0", - "@typescript-eslint/types": "4.31.0", - "@typescript-eslint/typescript-estree": "4.31.0", + "@typescript-eslint/scope-manager": "4.31.1", + "@typescript-eslint/types": "4.31.1", + "@typescript-eslint/typescript-estree": "4.31.1", "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0" } }, "@typescript-eslint/parser": { - "version": "4.31.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.31.0.tgz", - "integrity": "sha512-oWbzvPh5amMuTmKaf1wp0ySxPt2ZXHnFQBN2Szu1O//7LmOvgaKTCIDNLK2NvzpmVd5A2M/1j/rujBqO37hj3w==", + "version": "4.31.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.31.1.tgz", + "integrity": "sha512-dnVZDB6FhpIby6yVbHkwTKkn2ypjVIfAR9nh+kYsA/ZL0JlTsd22BiDjouotisY3Irmd3OW1qlk9EI5R8GrvRQ==", "requires": { - "@typescript-eslint/scope-manager": "4.31.0", - "@typescript-eslint/types": "4.31.0", - "@typescript-eslint/typescript-estree": "4.31.0", + "@typescript-eslint/scope-manager": "4.31.1", + "@typescript-eslint/types": "4.31.1", + "@typescript-eslint/typescript-estree": "4.31.1", "debug": "^4.3.1" } }, "@typescript-eslint/scope-manager": { - "version": "4.31.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.31.0.tgz", - "integrity": "sha512-LJ+xtl34W76JMRLjbaQorhR0hfRAlp3Lscdiz9NeI/8i+q0hdBZ7BsiYieLoYWqy+AnRigaD3hUwPFugSzdocg==", + "version": "4.31.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.31.1.tgz", + "integrity": "sha512-N1Uhn6SqNtU2XpFSkD4oA+F0PfKdWHyr4bTX0xTj8NRx1314gBDRL1LUuZd5+L3oP+wo6hCbZpaa1in6SwMcVQ==", "requires": { - "@typescript-eslint/types": "4.31.0", - "@typescript-eslint/visitor-keys": "4.31.0" + "@typescript-eslint/types": "4.31.1", + "@typescript-eslint/visitor-keys": "4.31.1" } }, "@typescript-eslint/types": { - "version": "4.31.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.31.0.tgz", - "integrity": "sha512-9XR5q9mk7DCXgXLS7REIVs+BaAswfdHhx91XqlJklmqWpTALGjygWVIb/UnLh4NWhfwhR5wNe1yTyCInxVhLqQ==" + "version": "4.31.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.31.1.tgz", + "integrity": "sha512-kixltt51ZJGKENNW88IY5MYqTBA8FR0Md8QdGbJD2pKZ+D5IvxjTYDNtJPDxFBiXmka2aJsITdB1BtO1fsgmsQ==" }, "@typescript-eslint/typescript-estree": { - "version": "4.31.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.31.0.tgz", - "integrity": "sha512-QHl2014t3ptg+xpmOSSPn5hm4mY8D4s97ftzyk9BZ8RxYQ3j73XcwuijnJ9cMa6DO4aLXeo8XS3z1omT9LA/Eg==", + "version": "4.31.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.31.1.tgz", + "integrity": "sha512-EGHkbsUvjFrvRnusk6yFGqrqMBTue5E5ROnS5puj3laGQPasVUgwhrxfcgkdHNFECHAewpvELE1Gjv0XO3mdWg==", "requires": { - "@typescript-eslint/types": "4.31.0", - "@typescript-eslint/visitor-keys": "4.31.0", + "@typescript-eslint/types": "4.31.1", + "@typescript-eslint/visitor-keys": "4.31.1", "debug": "^4.3.1", "globby": "^11.0.3", "is-glob": "^4.0.1", @@ -24433,11 +24433,11 @@ } }, "@typescript-eslint/visitor-keys": { - "version": "4.31.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.31.0.tgz", - "integrity": "sha512-HUcRp2a9I+P21+O21yu3ezv3GEPGjyGiXoEUQwZXjR8UxRApGeLyWH4ZIIUSalE28aG4YsV6GjtaAVB3QKOu0w==", + "version": "4.31.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.31.1.tgz", + "integrity": "sha512-PCncP8hEqKw6SOJY+3St4LVtoZpPPn+Zlpm7KW5xnviMhdqcsBty4Lsg4J/VECpJjw1CkROaZhH4B8M1OfnXTQ==", "requires": { - "@typescript-eslint/types": "4.31.0", + "@typescript-eslint/types": "4.31.1", "eslint-visitor-keys": "^2.0.0" } }, diff --git a/frontend/package.json b/frontend/package.json index b43b1751..a6916883 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -54,8 +54,8 @@ ] }, "devDependencies": { - "@typescript-eslint/eslint-plugin": "^4.31.0", - "@typescript-eslint/parser": "^4.31.0", + "@typescript-eslint/eslint-plugin": "^4.31.1", + "@typescript-eslint/parser": "^4.31.1", "eslint": "^7.32.0", "eslint-config-airbnb": "^18.2.1", "eslint-config-airbnb-typescript": "^14.0.0", diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 28d1b701..a04ec01d 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -65,11 +65,23 @@ const App = () => { API reachable? {apiHealth} </p> - - <Link to='test@example.org' mail={true}>Mail link</Link> - <Link to='test4' external={false} underline={true} noExternalIcon={true}>Internal link</Link> - <Link to='test6' external={true} underline={false} noUnderline={true}>External link</Link> - <Link to='test5' external={false} noUnderline={true}>Another internal link</Link> + <Link to="test@example.org" mail={true}> + Mail link + </Link> + <Link + to="test4" + external={false} + underline={true} + noExternalIcon={true} + > + Internal link + </Link> + <Link to="test6" external={true} underline={false} noUnderline={true}> + External link + </Link> + <Link to="test5" external={false} noUnderline={true}> + Another internal link + </Link> </header> </div> ) diff --git a/frontend/src/components/button/index.tsx b/frontend/src/components/button/index.tsx index a585ca36..047e3b64 100644 --- a/frontend/src/components/button/index.tsx +++ b/frontend/src/components/button/index.tsx @@ -19,3 +19,4 @@ export const Button = styled.a<ButtonProps>` } background: ${(props) => props.theme.colors.main}; ` +export default Button diff --git a/frontend/src/components/link/index.tsx b/frontend/src/components/link/index.tsx index f3b06431..b745f826 100644 --- a/frontend/src/components/link/index.tsx +++ b/frontend/src/components/link/index.tsx @@ -1,56 +1,56 @@ -import styled, {css, DefaultTheme} from 'styled-components/macro' - +import React from 'react' +import styled, { css, DefaultTheme } from 'styled-components/macro' interface IStyledLink { - theme: DefaultTheme - external?: boolean - underline?: boolean - marginRight?: boolean - inheritColor?: boolean - noUnderline?: boolean + theme: DefaultTheme + external?: boolean + underline?: boolean + marginRight?: boolean + inheritColor?: boolean + noUnderline?: boolean } - interface ILink { - to: string - external?: boolean - children?: React.ReactNode - marginRight?: boolean - noExternalIcon?: boolean - mail?: boolean - inheritColor?: boolean - underline?: boolean - noUnderline?: boolean + to: string + external?: boolean + children?: React.ReactNode + marginRight?: boolean + noExternalIcon?: boolean + mail?: boolean + inheritColor?: boolean + underline?: boolean + noUnderline?: boolean } const externalLinkIcon = ( - <svg width="15.3" height="12.6" viewBox="0 0 17 14"> - <g fill="#0F748D" fillRule="evenodd"> - <path - d="M13.044 8.157h-.607a.3.3 0 0 0-.218.082.276.276 0 0 0-.085.208v2.907c0 .4-.148.742-.445 1.027a1.493 1.493 0 0 1-1.072.427H2.73c-.417 0-.774-.143-1.071-.427a1.371 1.371 0 0 1-.446-1.027V3.796c0-.4.149-.742.446-1.026a1.493 1.493 0 0 1 1.071-.427h6.674a.302.302 0 0 0 .218-.082.277.277 0 0 0 .085-.209v-.581a.277.277 0 0 0-.085-.21.302.302 0 0 0-.218-.08H2.73c-.752 0-1.395.255-1.93.767-.533.511-.8 1.128-.8 1.848v7.558c0 .721.267 1.337.801 1.849a2.689 2.689 0 0 0 1.93.768h7.886c.752 0 1.395-.256 1.93-.768.534-.512.8-1.128.8-1.849V8.448a.276.276 0 0 0-.085-.21.302.302 0 0 0-.218-.081z"/> - <path - d="M16.807.19a.596.596 0 0 0-.426-.173h-4.854a.596.596 0 0 0-.426.173.548.548 0 0 0-.18.409c0 .157.06.294.18.409l1.668 1.598-6.18 5.923a.281.281 0 0 0-.095.21c0 .078.031.148.094.208L7.67 9.983a.306.306 0 0 0 .436 0l6.18-5.923 1.67 1.599c.12.115.262.172.426.172a.596.596 0 0 0 .426-.172.547.547 0 0 0 .18-.409V.599a.548.548 0 0 0-.18-.409z"/> - </g> - </svg> -); + <svg width="15.3" height="12.6" viewBox="0 0 17 14"> + <g fill="#0F748D" fillRule="evenodd"> + <path d="M13.044 8.157h-.607a.3.3 0 0 0-.218.082.276.276 0 0 0-.085.208v2.907c0 .4-.148.742-.445 1.027a1.493 1.493 0 0 1-1.072.427H2.73c-.417 0-.774-.143-1.071-.427a1.371 1.371 0 0 1-.446-1.027V3.796c0-.4.149-.742.446-1.026a1.493 1.493 0 0 1 1.071-.427h6.674a.302.302 0 0 0 .218-.082.277.277 0 0 0 .085-.209v-.581a.277.277 0 0 0-.085-.21.302.302 0 0 0-.218-.08H2.73c-.752 0-1.395.255-1.93.767-.533.511-.8 1.128-.8 1.848v7.558c0 .721.267 1.337.801 1.849a2.689 2.689 0 0 0 1.93.768h7.886c.752 0 1.395-.256 1.93-.768.534-.512.8-1.128.8-1.849V8.448a.276.276 0 0 0-.085-.21.302.302 0 0 0-.218-.081z" /> + <path d="M16.807.19a.596.596 0 0 0-.426-.173h-4.854a.596.596 0 0 0-.426.173.548.548 0 0 0-.18.409c0 .157.06.294.18.409l1.668 1.598-6.18 5.923a.281.281 0 0 0-.095.21c0 .078.031.148.094.208L7.67 9.983a.306.306 0 0 0 .436 0l6.18-5.923 1.67 1.599c.12.115.262.172.426.172a.596.596 0 0 0 .426-.172.547.547 0 0 0 .18-.409V.599a.548.548 0 0 0-.18-.409z" /> + </g> + </svg> +) const ExternalIcon = styled.span` margin-left: 1.2rem; position: relative; top: 1px; - zIndex: -1; + zindex: -1; ` const baseInputStyles = css<IStyledLink>` display: inline-flex; align-items: center; - color: ${props => props.external ? props.theme.linkExternalColor : props.theme.linkInternalColor}; + color: ${(props) => + props.external + ? props.theme.linkExternalColor + : props.theme.linkInternalColor}; - ${props => props.marginRight ? "margin-right: 3rem;" : ""} - ${props => props.inheritColor ? "color: inherit;" : ""} - ${props => props.underline ? "text-decoration: underline;" : ""} - ${props => props.noUnderline ? ":hover { text-decoration: none };" : ""} + ${(props) => (props.marginRight ? 'margin-right: 3rem;' : '')} + ${(props) => (props.inheritColor ? 'color: inherit;' : '')} + ${(props) => (props.underline ? 'text-decoration: underline;' : '')} + ${(props) => (props.noUnderline ? ':hover { text-decoration: none };' : '')} ` const StyledLink = styled.a<IStyledLink>` @@ -62,47 +62,41 @@ const StyledLink = styled.a<IStyledLink>` // ` function Link(props: ILink) { - const {children, external, to, noExternalIcon, mail} = props - - if (mail) { - return ( - <StyledLink href={`mailto:${to}`} {...props}> - {children} - </StyledLink> - ); - } - - if (external) { - const urlRegex = /^((http|https):\/\/)/; - const href = urlRegex.test(to) ? to : `//${to}`; + const { children, external, to, noExternalIcon, mail } = props - return ( - <StyledLink - href={href} - target="_blank" - rel="noopener noreferrer" - {...props} - > - {children} - {!noExternalIcon && ( - <ExternalIcon>{externalLinkIcon}</ExternalIcon> - )} - </StyledLink> - ); - } + if (mail) { + return ( + <StyledLink href={`mailto:${to}`} {...props}> + {children} + </StyledLink> + ) + } - // TODO Use StyledRouterLink for internal links when routes are set up - // return ( - // <StyledRouterLink {...props}> - // {children} - // </StyledRouterLink> - // ) + if (external) { + const urlRegex = /^((http|https):\/\/)/ + const href = urlRegex.test(to) ? to : `//${to}` return ( - <StyledLink {...props}> - {children} - </StyledLink> + <StyledLink + href={href} + target="_blank" + rel="noopener noreferrer" + {...props} + > + {children} + {!noExternalIcon && <ExternalIcon>{externalLinkIcon}</ExternalIcon>} + </StyledLink> ) + } + + // TODO Use StyledRouterLink for internal links when routes are set up + // return ( + // <StyledRouterLink {...props}> + // {children} + // </StyledRouterLink> + // ) + + return <StyledLink {...props}>{children}</StyledLink> } -export default Link \ No newline at end of file +export default Link -- GitLab