Compare commits

..
Author SHA1 Message Date
github-actions[bot] 0673ab670f Lerna versionbump [ci skip]
- @navikt/ds-icons@0.6.0
 - @navikt/ds-react@0.12.0
 - @navikt/ds-react-internal@0.7.0
2021-11-01 11:54:29 +00:00
KenandKenAJoh 68d5e81076 [FEATURE] Automatisk PR for ikoner (#1314)
Co-authored-by: KenAJoh <KenAJoh@users.noreply.github.com>
2021-11-01 12:39:54 +01:00
Ken b775a84493 oppdatert automatisk PR tekst 2021-11-01 10:53:02 +01:00
Ken 27f491d452 bedre feilmeldinger 2021-11-01 10:21:36 +01:00
Ken 129d159570 fikset update build script 2021-11-01 10:10:38 +01:00
github-actions[bot] b5d1eb0105 Lerna versionbump [ci skip]
- @navikt/ds-icons@0.5.10
 - @navikt/ds-react@0.11.10
 - @navikt/ds-react-internal@0.6.11
2021-10-29 13:19:58 +00:00
Ken 0f03d9c538 [FIX] Fjernet tabindex fra ikoner (#1313) 2021-10-29 15:01:07 +02:00
Ken 29f1567601 Lerna versionbump [ci skip]
- @navikt/ds-icons@0.5.9
 - @navikt/ds-react@0.11.9
 - @navikt/ds-react-internal@0.6.10
2021-10-29 14:30:16 +02:00
Ken 2bd4fd52ff fjernet test-sjekk i icon-update workflow 2021-10-28 16:46:31 +02:00
Ken 9af1c3b5d2 [FIX] Automatisk PR for ikon-oppdateringer (#1312) 2021-10-28 16:32:24 +02:00
github-actions[bot] b1eebe5228 Lerna versionbump [ci skip]
- @navikt/ds-icons@0.5.8
 - @navikt/ds-react@0.11.8
 - @navikt/ds-react-internal@0.6.9
2021-10-26 13:41:08 +00:00
Andreas Nordahl 804a24f631 [fix] Icons uu (#1310)
* add role=img to icon svgs

* use svgr config file

* add svgr template to default titleId to uuid-v4

* clean icon cjs and esm

* set tabIndex to -1 for ie11 compat

* update icons props to reflect icon updates
2021-10-26 15:20:40 +02:00
Ken 6918e1695b Hotjar for verktøykassen (#1311) 2021-10-26 14:47:33 +02:00
github-actions[bot] cffc4b6539 Lerna versionbump [ci skip]
- @navikt/ds-react-internal@0.6.8
2021-10-26 12:14:28 +00:00
Ken b575e39000 [FIX] Kjøre onClick og onClose i header/dropdow (#1309) 2021-10-26 13:54:04 +02:00
Ken ced2b9b46b @storybook/addon-a11y for storybook (#1308) 2021-10-26 13:53:58 +02:00
github-actions[bot] f19ea3d0fe Lerna versionbump [ci skip]
- @navikt/ds-react@0.11.7
 - @navikt/ds-react-internal@0.6.7
2021-10-26 09:08:48 +00:00
Andreas Nordahl 260ee43f09 [fix] input className only on field container (#1307) 2021-10-26 10:54:34 +02:00
github-actions[bot] a1bdcd4df5 Lerna versionbump [ci skip]
- @navikt/ds-icons@0.5.7
 - @navikt/ds-react@0.11.6
 - @navikt/ds-react-internal@0.6.6
2021-10-25 15:54:41 +00:00
Ken 5669efc0dd [FIX] Gjør ikoner default focusable={false} (#1304) 2021-10-25 17:36:52 +02:00
Karl O 00a02fa8ae [FIX] bruk camelCase isteden for kebab-case i react svg (#1306) 2021-10-25 17:36:41 +02:00
github-actions[bot] 93f1d199cd Lerna versionbump [ci skip]
- @navikt/ds-react@0.11.5
 - @navikt/ds-react-internal@0.6.5
2021-10-25 08:07:17 +00:00
Ken a69db74d79 [FIX] Fjernet alt-tag fra alert-ikon, trenger bare aria-label (#1302) 2021-10-25 09:49:56 +02:00
Ken 717b70a011 Litt dokumentasjon om forwardedAs (#1303) 2021-10-25 09:49:49 +02:00
github-actions[bot] ed937f68c5 Lerna versionbump [ci skip]
- @navikt/ds-react@0.11.4
 - @navikt/ds-react-internal@0.6.4
2021-10-21 08:11:19 +00:00
Ken 47c4f9aa26 [FIX] Bugfix loader-id (#1301) 2021-10-21 09:52:47 +02:00
github-actions[bot] b166e5e5df Lerna versionbump [ci skip]
- @navikt/ds-react@0.11.3
 - @navikt/ds-react-internal@0.6.3
2021-10-20 14:49:50 +00:00
KenandAndreas Nordahl e150b4f264 [FIX] State-handling og warnings i Checkbox (#1295)
Co-authored-by: Andreas Nordahl <andnorda@gmail.com>
2021-10-20 16:34:53 +02:00
github-actions[bot] be9660948c Lerna versionbump [ci skip]
- @navikt/ds-react@0.11.2
 - @navikt/ds-react-internal@0.6.2
2021-10-20 14:06:48 +00:00
Andreas Nordahl 26023c888b [fix] remove aria-controls (#1300) 2021-10-20 15:50:19 +02:00
github-actions[bot] 79b85169d1 Lerna versionbump [ci skip]
- @navikt/ds-react@0.11.1
 - @navikt/ds-react-internal@0.6.1
2021-10-20 12:40:42 +00:00
Andreas Nordahl 4e5d410f9f [fix] remove aria-live from popover (#1299) 2021-10-20 14:22:20 +02:00
126 changed files with 1137 additions and 1446 deletions

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
name: Update Icons
on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Required to retrieve git history
- uses: actions/setup-node@v1
with:
node-version: 14
- name: Node-modules cache
uses: actions/cache@v2
id: node-cache
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- name: install
if: steps.node-cache.outputs.cache-hit != 'true'
run: yarn install
- name: postinstall
if: steps.node-cache.outputs.cache-hit == 'true'
run: yarn postinstall
- name: add Figma token to .env
run: echo "FIGMA_TOKEN=${{ secrets.FIGMA_IKONER_API }}" >> @navikt/core/icons/.env
- name: Update Icons
run: yarn update:icons
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GIT_REPO }}
commit-message: "Oppdatert ikoner fra figma"
committer: GitHub <noreply@github.com>
branch: figma-icons-sync
delete-branch: true
title: "[FIX] Automatisk PR for ikoner"
labels: |
Icons
automated pr
+1
View File
@@ -11,6 +11,7 @@ module.exports = {
],
addons: [
"@storybook/addon-docs",
"@storybook/addon-a11y",
{
name: "@storybook/addon-storysource",
options: {
@@ -20,3 +20,16 @@ import "@navikt/ds-css"
Dette vil også legge css-variabler på :root. For å få dette til å fungere med IE11, kan denne pakken tas i bruk: https://jhildenbiddle.github.io/css-vars-ponyfill/#/
Note: Disse komponentene kan ikke garanteres at fungerer som forventet i IE11 da vi har valgt og ikke unngå styling-valg basert på IE11 støtte eller ikke.
## Bruke styled-components eller emotion
Flere av våre komponenter er implementert med OverridableComponent. Dette vil si at komponenten tar i mot en prop, `as` som lar deg endre hvilken tag som blir satt.
Bruk for dette er eks hvis du ønsker `Heading` stilen, men ikke en heading-tag. Da kan man lett skrive `<Heading as="div">` og man vil få en `div`-tag istedenfor.
Flere css-in-js bibliotek har også denne funksjonaliteten bygd inne, noe som kan komplisere ting når alle bruker samme navn `as` for dette.
### Løsninger
[Styled-components](https://styled-components.com/docs/api#forwardedas-prop)
> TLDR: Bruk `forwardedAs` istendenfor `as` på komponentene, SD fikser resten.
+16
View File
@@ -0,0 +1,16 @@
const template = require("./template");
module.exports = {
typescript: true,
ref: true,
icon: true,
titleProp: true,
svgProps: {
focusable: false,
role: "img",
},
replaceAttrValues: {
"#262626": "currentColor",
},
template,
};
+12 -2
View File
@@ -1,6 +1,6 @@
# @navikt/ds-icons
Denne pakken leverer [NAVs ikoner](https://design.nav.no/resources/icons) i en pakke med React-komponenter og SVGer.
Leverer [NAVs ikoner](https://design.nav.no/resources/icons) i React og SVG.
## Installering
@@ -12,7 +12,17 @@ yarn add @navikt/ds-icons
npm install @navikt/ds-icons
```
## Bruk
```jsx
/* ESM (anbefalt for tree-shaking)*/
import { Down } from "@navikt/ds-icons";
/* CJS */
import { Down } from "@navikt/cjs/ds-icons";
<Down aria-label="Åpne meny" />;
```
## Dokumentasjon
- [Ikonsøk](https://design.nav.no/resources/icons)
- [Installering](https://design.nav.no/resources/icons/install)
-49
View File
@@ -1,49 +0,0 @@
// https://levelup.gitconnected.com/learn-svg-to-react-using-figma-api-be0a5f9c0ca
// used for reference/implementation
import Axios from "axios";
const { create, get } = Axios;
// Requires user to add a personalized figma token in .env
const headers = {
"X-FIGMA-TOKEN": process.env.FIGMA_TOKEN,
};
/**
* Api connection for icon components
* https://www.figma.com/file/UmEVH3pZ71uJPsSz9ilP3Y/NAV-ikoner-2.1-Figma-i-test?node-id=0%3A1
*/
const instanceFiles = create({
baseURL: `https://api.figma.com/v1/files/${process.env.FILE_KEY}/components`,
headers,
});
/**
* api endpoint for images
*/
const instanceImages = create({
baseURL: `https://api.figma.com/v1/images/${process.env.FILE_KEY}`,
headers,
});
/**
* get Figma node components children
*/
export const getNodeChildren = async () => {
const { data } = await instanceFiles.get();
return data.meta.components;
};
/**
* get svg image resource urls
*/
export const getSvgImageUrls = async (nodeIds) => {
const {
data: { images },
} = await instanceImages.get(`/?ids=${nodeIds}&format=svg`);
return Object.values(images);
};
/**
* Gets raw svg data from url
*/
export const getIconContent = async (url) => get(url);
-105
View File
@@ -1,105 +0,0 @@
import { getNodeChildren, getSvgImageUrls, getIconContent } from "./api";
import { existsSync, unlinkSync, writeFileSync, mkdirSync } from "fs";
import { resolve } from "path";
import pLimit from "p-limit";
import rimraf from "rimraf";
import startCase from "lodash.startcase";
const generateMetadata = (iconNodesArr) => {
return iconNodesArr
.map(({ name, description, created_at, updated_at, containing_frame }) => {
return {
name: startCase(name).replace(/\s/g, ""),
description,
created_at,
updated_at,
//strip emojis
pageName: containing_frame.pageName.replace(
/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g,
""
),
visible: true,
};
})
.sort((a, b) => a.name.localeCompare(b.name));
};
const main = async () => {
const iconFolder = "./svg";
const metadataFileName = "./figma-api/metadata.json";
const misses = [];
// Limiting to ~20 concurrent downloads seems to lead to fewer erros
const limit = pLimit(20);
const iconNodesArr = await getNodeChildren().catch((e) => {
throw e;
});
if (existsSync(metadataFileName)) {
unlinkSync(metadataFileName);
}
writeFileSync(
metadataFileName,
JSON.stringify(generateMetadata(iconNodesArr), null, 4),
{
encoding: "utf8",
}
);
const iconUrls = await getSvgImageUrls(
iconNodesArr.map((node) => node.node_id).join(",")
);
if (existsSync(iconFolder)) {
rimraf.sync(iconFolder);
}
mkdirSync(iconFolder);
console.log("Total icons: " + iconNodesArr.length);
await Promise.all(
iconUrls.map((url, x) =>
limit(() =>
getIconContent(url)
.then(({ data }) => {
writeFileSync(
resolve(
iconFolder,
`${startCase(iconNodesArr[x].name).replace(/\s/g, "")}.svg`
),
data,
{
encoding: "utf8",
}
);
})
.catch((e) => {
misses.push({
name: iconNodesArr[x].name,
error: e.message,
});
})
)
)
);
if (misses.length > 0) {
writeFileSync(
resolve("./", `misses.txt`),
JSON.stringify(misses, null, 4),
{
encoding: "utf8",
}
);
console.log(`\nCould not download ${misses.length} icons\n`);
} else {
console.log("\nDownloaded all icons from Figma successfully!\n");
}
};
try {
main();
} catch (e) {
console.error(e);
}
+48
View File
@@ -0,0 +1,48 @@
import Axios from "axios";
const { create, get } = Axios;
const FILE_KEY = "UmEVH3pZ71uJPsSz9ilP3Y";
const FigmaAxion = (token?: string) =>
create({
headers: {
"X-FIGMA-TOKEN": token,
},
});
/**
* Published Figma-components
* https://www.figma.com/file/UmEVH3pZ71uJPsSz9ilP3Y/%F0%9F%92%A0NAV-ikoner-2.5-Figma
*/
export const getPublishedIcons = async () => {
const { data } = await FigmaAxion(process.env.FIGMA_TOKEN)
.get(`https://api.figma.com/v1/files/${FILE_KEY}/components`)
.catch((e) => {
console.log("Failed getPublishedIcons ");
throw e;
});
return data?.meta?.components;
};
/**
* Downloadable link to each icon in SVG-format
*/
export const getIconsDownloadableUrl = async (nodeIds: string) => {
const {
data: { images },
} = await FigmaAxion(process.env.FIGMA_TOKEN)
.get(
`https://api.figma.com/v1/images/${FILE_KEY}/?ids=${nodeIds}&format=svg`
)
.catch((e) => {
console.log("Failed getIconsDownloadableUrl ");
throw e;
});
return Object.values(images) as string[];
};
/**
* Download icon @url
*/
export const getIconContent = async (url: string) => get(url);
+85
View File
@@ -0,0 +1,85 @@
import {
getPublishedIcons,
getIconsDownloadableUrl,
getIconContent,
} from "./api";
import { existsSync, writeFileSync, mkdirSync } from "fs";
import { resolve } from "path";
import pLimit from "p-limit";
import rimraf from "rimraf";
import startCase from "lodash.startcase";
import { writeMeta } from "./write-meta";
import dotenv from "dotenv";
dotenv.config();
export type ComponentT = {
key: string;
file_key: string;
node_id: string;
thumbnail_url: string;
name: string;
description: string;
updated_at: string;
created_at: string;
user: any;
containing_frame: any;
};
const main = async () => {
if (!process.env.FIGMA_TOKEN) {
throw new Error("FIGMA_TOKEN not set in .env");
}
const iconFolder = "./svg";
// Limiting to ~20 concurrent downloads seems to lead to less errors
const limit = pLimit(20);
const publishedIconNodes: ComponentT[] = await getPublishedIcons();
writeMeta(publishedIconNodes);
/* Get all urls in one fetch rather than 300+ */
const iconUrls: string[] = await getIconsDownloadableUrl(
publishedIconNodes.map((node) => node.node_id).join(",")
);
if (existsSync(iconFolder)) {
rimraf.sync(iconFolder);
}
mkdirSync(iconFolder);
console.log("Total icons: " + publishedIconNodes.length);
await Promise.all(
iconUrls.map((url, x) =>
limit(() =>
getIconContent(url)
.then(({ data }) => {
writeFileSync(
resolve(
iconFolder,
`${startCase(publishedIconNodes[x].name).replace(
/\s/g,
""
)}.svg`
),
data,
{
encoding: "utf8",
}
);
})
.catch((e) => {
throw e;
})
)
)
);
console.log("\nDownloaded all icons from Figma!\n");
};
try {
main();
} catch (e) {
throw e;
}
+35
View File
@@ -0,0 +1,35 @@
import { existsSync, unlinkSync, writeFileSync } from "fs";
import startCase from "lodash.startcase";
import { ComponentT } from ".";
const generateMetadata = (publishedIconNodes: ComponentT[]) => {
return publishedIconNodes
.map(({ name, description, created_at, containing_frame }) => {
return {
name: startCase(name).replace(/\s/g, ""),
description,
created_at,
// strip emojis
pageName: containing_frame.pageName.replace(
/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g,
""
),
};
})
.sort((a, b) => a.name.localeCompare(b.name));
};
export const writeMeta = (publishedIconNodes: ComponentT[]) => {
const metadataFileName = "./meta.json";
if (existsSync(metadataFileName)) {
unlinkSync(metadataFileName);
}
writeFileSync(
metadataFileName,
JSON.stringify(generateMetadata(publishedIconNodes)),
{
encoding: "utf8",
}
);
};
File diff suppressed because it is too large. Load diff
+15 -8
View File
@@ -1,6 +1,6 @@
{
"name": "@navikt/ds-icons",
"version": "0.5.6",
"version": "0.6.0",
"private": false,
"description": "NAVs egne ikoner i SVG og React format",
"repository": {
@@ -22,22 +22,28 @@
"/cjs",
"/esm",
"/src",
"/svg"
"/svg",
"/meta.json"
],
"scripts": {
"create-package-json-pointers-to-esm": "node ../../../utilities/scripts/createPackageJsonsWithESMPointers.js",
"dl-icons": "FILE_KEY=UmEVH3pZ71uJPsSz9ilP3Y node --experimental-modules --es-module-specifier-resolution=node -r dotenv/config figma-api/index.mjs dotenv_config_path=figma-api/.env",
"create-icons": "svgr --silent --typescript --ref --icon --title-prop --replace-attr-values \"#262626=currentColor\" -d src svg",
"convert-icons": "node figma-api/pngConverter.mjs",
"clean": "rimraf src png NAV-ikonpakke-png.zip NAV-ikonpakke-svg.zip",
"zip-icons": "node figma-api/zipIcons.mjs",
"build": "yarn clean && yarn create-icons && tsc && tsc -p tsconfig.esm.json && yarn create-package-json-pointers-to-esm && yarn run convert-icons && yarn zip-icons"
"create-icons": "svgr --out-dir src svg",
"convert-icons": "node scripts/pngConverter.mjs",
"clean": "rimraf src cjs esm png NAV-ikonpakke-png.zip NAV-ikonpakke-svg.zip",
"zip-icons": "node scripts/zipIcons.mjs",
"build": "yarn clean && yarn create-icons && tsc && tsc -p tsconfig.esm.json && yarn create-package-json-pointers-to-esm && yarn run convert-icons && yarn zip-icons",
"update": "ts-node figma/index.ts dotenv/config"
},
"dependencies": {
"uuid": "^8.3.2"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0"
},
"devDependencies": {
"@svgr/cli": "^5.5.0",
"@types/lodash.startcase": "^4.4.6",
"@types/uuid": "^8.3.1",
"copyfiles": "^2.4.1",
"dotenv": "^10.0.0",
"lodash.kebabcase": "^4.1.1",
@@ -45,6 +51,7 @@
"react": "^16.8.0 || ^17.0.0",
"rimraf": "3.0.2",
"sharp": "0.29.1",
"ts-node": "^10.4.0",
"zip-dir": "^2.0.0"
}
}
+1 -3
View File
@@ -16,9 +16,7 @@ yarn add @navikt/ds-icons
Import { Expand } from `@navikt/ds-icons`;
<Expand
aria-label="Åpne meny"
role="img"
focusable="false"
title="Åpne meny"
/>
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+44
View File
@@ -0,0 +1,44 @@
function defaultTemplate(
{ template },
opts,
{ imports, interfaces, componentName, props, jsx, exports }
) {
const plugins = ["jsx"];
if (opts.typescript) {
plugins.push("typescript");
}
imports.push({
type: "ImportDeclaration",
specifiers: [
{
type: "ImportSpecifier",
imported: {
type: "Identifier",
name: "v4",
},
},
],
source: {
type: "StringLiteral",
value: "uuid",
},
});
props[0].properties.find((prop) => prop.key.name === "titleId").value = {
type: "Identifier",
name: "_titleId",
};
const typeScriptTpl = template.smart({ plugins });
return typeScriptTpl.ast`
${imports}
${interfaces}
function ${componentName}(${props}) {
const titleId = _titleId ?? (title ? v4() : undefined);
return ${jsx};
}
${exports}`;
}
module.exports = defaultTemplate;
+2 -1
View File
@@ -3,5 +3,6 @@
"compilerOptions": {
"outDir": "./cjs",
"module": "commonjs"
}
},
"exclude": ["./figma", "./scripts", "**/stories"]
}
Loaded 100 of 126 files, more files were not shown because too many files have changed in this diff. Show more