-
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.
* 🎨 script for svg-parsing * 🐛 Fikset buffer av readFileScript * 🧪 Parse-svg test * 📝 changeset * 🔥 forenklet svg i tester * 🔥 Fjernet svg-parser fra yarn.lock * 🐛 Tryggere svg-parsing * 🎨 Kjører nå ikke main-script i tester * Update @navikt/aksel-icons/config/parse-svg.js Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com> --------- Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>
- Loading branch information
1 parent
2aa3cd5
commit d426a94
Showing
4 changed files
with
84 additions
and
4 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,5 @@ | ||
--- | ||
"@navikt/aksel-icons": minor | ||
--- | ||
|
||
Ikoner: SVG export setter nå `height="1em"`, `width="1em"` og `fill="currentColor"`. |
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,34 @@ | ||
import { parseIcon } from "../config/parse-svg"; | ||
|
||
describe(`SVG should be correctly parsed`, () => { | ||
const simpleSvg = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path fill-rule="evenodd" clip-rule="evenodd" d="18.1559 9.81056 17.4392Z" fill="#23262A"/> | ||
</svg> | ||
`; | ||
|
||
const simpleSvgResult = `<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path fill-rule="evenodd" clip-rule="evenodd" d="18.1559 9.81056 17.4392Z" fill="currentColor"/> | ||
</svg> | ||
`; | ||
|
||
const advancedSvg = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path fill-rule="evenodd" clip-rule="evenodd" d="18.1559 9.81056 17.4392Z" fill="#23262A"/> | ||
<path fill-rule="evenodd" clip-rule="evenodd" d="18.1559 9.81056 17.4392Z" fill="#23262A"/> | ||
<path fill-rule="evenodd" clip-rule="evenodd" d="18.1559 9.81056 17.4392Z" fill="#23262A"/> | ||
<path fill-rule="evenodd" clip-rule="evenodd" d="18.1559 9.81056 17.4392Z" fill="#23262A"/> | ||
</svg> | ||
`; | ||
|
||
const advancedSvgResult = `<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path fill-rule="evenodd" clip-rule="evenodd" d="18.1559 9.81056 17.4392Z" fill="currentColor"/> | ||
<path fill-rule="evenodd" clip-rule="evenodd" d="18.1559 9.81056 17.4392Z" fill="currentColor"/> | ||
<path fill-rule="evenodd" clip-rule="evenodd" d="18.1559 9.81056 17.4392Z" fill="currentColor"/> | ||
<path fill-rule="evenodd" clip-rule="evenodd" d="18.1559 9.81056 17.4392Z" fill="currentColor"/> | ||
</svg> | ||
`; | ||
|
||
it("a", () => { | ||
expect(parseIcon(simpleSvg)).toEqual(simpleSvgResult); | ||
expect(parseIcon(advancedSvg)).toEqual(advancedSvgResult); | ||
}); | ||
}); |
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,42 @@ | ||
const fastglob = require("fast-glob"); | ||
const path = require("path"); | ||
const { | ||
existsSync, | ||
readFileSync, | ||
mkdirSync, | ||
rmSync, | ||
writeFileSync, | ||
} = require("fs"); | ||
|
||
function main() { | ||
const basePath = path.resolve(__dirname, "../icons"); | ||
const iconFolder = path.resolve(__dirname, "../dist/svg"); | ||
|
||
const svgList = fastglob.sync("*.svg", { cwd: basePath }); | ||
|
||
if (existsSync(iconFolder)) { | ||
rmSync(iconFolder, { recursive: true, force: true }); | ||
} | ||
mkdirSync(iconFolder); | ||
|
||
svgList.forEach((svg) => { | ||
const icon = readFileSync(`${basePath}/${svg}`).toString(); | ||
writeFileSync(`${iconFolder}/${svg}`, parseIcon(icon)); | ||
}); | ||
} | ||
|
||
/** | ||
* | ||
* @param {string} SVG-string | ||
* @returns {string} Parsed SVG-string | ||
*/ | ||
function parseIcon(svgString) { | ||
let icon = svgString; | ||
icon = icon.replace(`width="24"`, `width="1em"`); | ||
icon = icon.replace(`height="24"`, `height="1em"`); | ||
icon = icon.replaceAll(`#23262A`, `currentColor`); | ||
|
||
return icon; | ||
} | ||
|
||
module.exports = { parseIcon, main }; |
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