-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
1,479 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"@navikt/ds-css": minor | ||
"@navikt/ds-react": minor | ||
"@navikt/ds-react-internal": minor | ||
--- | ||
|
||
:sparkles: Ny komponent `<CopyButton />`! | ||
|
||
- Erstatter `<CopyToClipboard />` fra `@navikt/ds-react-internal` | ||
- CopyToClipboard er markert som deprecated. Den vil fortsatt fungere, men noen lintere vil kunne ende opp med å klage på den. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
@navikt/aksel/src/codemod/transforms/v3.0.0/copybutton/copybutton.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import chalk from "chalk"; | ||
import moveAndRenameImport from "../../../utils/moveAndRenameImport"; | ||
import removePropsFromComponent from "../../../utils/removeProps"; | ||
|
||
/** | ||
* @param {import('jscodeshift').FileInfo} file | ||
* @param {import('jscodeshift').API} api | ||
*/ | ||
export default function transformer(file, api, options, ...rest) { | ||
const j = api.jscodeshift; | ||
|
||
let root: any; | ||
try { | ||
root = j(file.source); | ||
} catch { | ||
return file.source; | ||
} | ||
|
||
const toName = "CopyButton"; | ||
const localName = moveAndRenameImport(j, root, { | ||
fromImport: "@navikt/ds-react-internal", | ||
toImport: "@navikt/ds-react", | ||
fromName: "CopyToClipboard", | ||
toName, | ||
}); | ||
|
||
if (localName === null) { | ||
return root.toSource(options.printOptions); | ||
} | ||
|
||
/* Finds and replaces import from CopyToClipboard -> CopyButton */ | ||
|
||
if (root.findJSXElements(localName)) { | ||
removePropsFromComponent(j, root, localName, [ | ||
"popoverText", | ||
"popoverPlacement", | ||
"iconPosition", | ||
"variant", | ||
]); | ||
|
||
const component = root.findJSXElements(localName); | ||
|
||
component.forEach((node) => { | ||
const children = node.node.children; | ||
let flagged = false; | ||
if ( | ||
children.length > 0 && | ||
!node.node.openingElement.attributes.some( | ||
(attr) => attr.name.name === "text" | ||
) | ||
) { | ||
if (children.length === 1 && children[0].type === "JSXText") { | ||
node.node.openingElement.attributes.push( | ||
j.jsxAttribute( | ||
j.jsxIdentifier("text"), | ||
j.literal(children[0].value.trim()) | ||
) | ||
); | ||
} else { | ||
flagged = true; | ||
console.log( | ||
chalk.yellow( | ||
`\n\nWarning: Detected advanced children-type!\nCodemod can't convert into "text" prop so you will need to update this manually.` | ||
) | ||
); | ||
} | ||
} | ||
|
||
if (!flagged) { | ||
node.node.children = []; | ||
node.node.openingElement.selfClosing = true; | ||
node.node.closingElement = null; | ||
} | ||
}); | ||
|
||
const compRoot = root.find(j.JSXElement, { | ||
openingElement: { name: { name: localName } }, | ||
}); | ||
|
||
compRoot.forEach((x) => { | ||
x.node.openingElement.name.name = "CopyButton"; | ||
if (x.node.children.length > 0) { | ||
x.node.closingElement.name.name = "CopyButton"; | ||
} | ||
}); | ||
} | ||
|
||
return root.toSource(options.printOptions); | ||
} |
6 changes: 6 additions & 0 deletions
6
@navikt/aksel/src/codemod/transforms/v3.0.0/copybutton/tests/alias.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { CopyToClipboard as DsCpyButton } from "@navikt/ds-react-internal"; | ||
|
||
/* eslint-disable react/jsx-no-undef */ | ||
export const Page = () => { | ||
return <DsCpyButton></DsCpyButton>; | ||
}; |
6 changes: 6 additions & 0 deletions
6
@navikt/aksel/src/codemod/transforms/v3.0.0/copybutton/tests/alias.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { CopyButton } from "@navikt/ds-react"; | ||
|
||
/* eslint-disable react/jsx-no-undef */ | ||
export const Page = () => { | ||
return <CopyButton />; | ||
}; |
16 changes: 16 additions & 0 deletions
16
@navikt/aksel/src/codemod/transforms/v3.0.0/copybutton/tests/children.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { CopyToClipboard } from "@navikt/ds-react-internal"; | ||
|
||
/* eslint-disable react/jsx-no-undef */ | ||
export const Page = () => { | ||
return ( | ||
<CopyToClipboard | ||
popoverText="popoverText" | ||
copyText="Text to copy" | ||
iconPosition="left" | ||
size="medium" | ||
popoverPlacement="bottom-end" | ||
> | ||
{text} | ||
</CopyToClipboard> | ||
); | ||
}; |
10 changes: 10 additions & 0 deletions
10
@navikt/aksel/src/codemod/transforms/v3.0.0/copybutton/tests/children.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { CopyButton } from "@navikt/ds-react"; | ||
|
||
/* eslint-disable react/jsx-no-undef */ | ||
export const Page = () => { | ||
return ( | ||
<CopyButton copyText="Text to copy" size="medium" text="text"> | ||
{text} | ||
</CopyButton> | ||
); | ||
}; |
6 changes: 6 additions & 0 deletions
6
@navikt/aksel/src/codemod/transforms/v3.0.0/copybutton/tests/cleanup.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { CopyToClipboard } from "@navikt/ds-react-internal"; | ||
|
||
/* eslint-disable react/jsx-no-undef */ | ||
export const Page = () => { | ||
return <CopyToClipboard></CopyToClipboard>; | ||
}; |
6 changes: 6 additions & 0 deletions
6
@navikt/aksel/src/codemod/transforms/v3.0.0/copybutton/tests/cleanup.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { CopyButton } from "@navikt/ds-react"; | ||
|
||
/* eslint-disable react/jsx-no-undef */ | ||
export const Page = () => { | ||
return <CopyButton />; | ||
}; |
16 changes: 16 additions & 0 deletions
16
@navikt/aksel/src/codemod/transforms/v3.0.0/copybutton/tests/complete.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { CopyToClipboard } from "@navikt/ds-react-internal"; | ||
|
||
/* eslint-disable react/jsx-no-undef */ | ||
export const Page = () => { | ||
return ( | ||
<CopyToClipboard | ||
popoverText="popoverText" | ||
copyText="Text to copy" | ||
iconPosition="left" | ||
size="medium" | ||
popoverPlacement="bottom-end" | ||
> | ||
text | ||
</CopyToClipboard> | ||
); | ||
}; |
6 changes: 6 additions & 0 deletions
6
@navikt/aksel/src/codemod/transforms/v3.0.0/copybutton/tests/complete.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { CopyButton } from "@navikt/ds-react"; | ||
|
||
/* eslint-disable react/jsx-no-undef */ | ||
export const Page = () => { | ||
return <CopyButton copyText="Text to copy" size="medium" text="text" />; | ||
}; |
12 changes: 12 additions & 0 deletions
12
@navikt/aksel/src/codemod/transforms/v3.0.0/copybutton/tests/copybutton.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { check } from "../../../../utils/check"; | ||
|
||
const migration = "copybutton"; | ||
const fixtures = ["complete", "idempotent", "alias", "cleanup", "import"]; | ||
|
||
for (const fixture of fixtures) { | ||
check(__dirname, { | ||
fixture, | ||
migration, | ||
extension: "js", | ||
}); | ||
} |
6 changes: 6 additions & 0 deletions
6
@navikt/aksel/src/codemod/transforms/v3.0.0/copybutton/tests/idempotent.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { CopyButton } from "@navikt/ds-react"; | ||
|
||
/* eslint-disable react/jsx-no-undef */ | ||
export const Page = () => { | ||
return <CopyButton copyText="Text to copy" size="medium" text={props.text} />; | ||
}; |
6 changes: 6 additions & 0 deletions
6
@navikt/aksel/src/codemod/transforms/v3.0.0/copybutton/tests/idempotent.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { CopyButton } from "@navikt/ds-react"; | ||
|
||
/* eslint-disable react/jsx-no-undef */ | ||
export const Page = () => { | ||
return <CopyButton copyText="Text to copy" size="medium" text={props.text} />; | ||
}; |
7 changes: 7 additions & 0 deletions
7
@navikt/aksel/src/codemod/transforms/v3.0.0/copybutton/tests/import.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { CopyToClipboard, Dropdown } from "@navikt/ds-react-internal"; | ||
import { Button } from "@navikt/ds-react"; | ||
|
||
/* eslint-disable react/jsx-no-undef */ | ||
export const Page = () => { | ||
return <CopyToClipboard></CopyToClipboard>; | ||
}; |
7 changes: 7 additions & 0 deletions
7
@navikt/aksel/src/codemod/transforms/v3.0.0/copybutton/tests/import.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Dropdown } from "@navikt/ds-react-internal"; | ||
import { Button, CopyButton } from "@navikt/ds-react"; | ||
|
||
/* eslint-disable react/jsx-no-undef */ | ||
export const Page = () => { | ||
return <CopyButton />; | ||
}; |
Oops, something went wrong.