Skip to content

Commit

Permalink
feat: move DNB icons to subfolder (with v9 compatibility) (#2200)
Browse files Browse the repository at this point in the history
* Remove existing icons

* Move icons lock and meta files

* Remove left over PDF lock file

* Change consuming imports of portal

* Refactor convert script

* Update index files with new subfolder path

* Add icons files as tsx files in subfolder

* Deal with IconPrimary externalisation

* Generate index files

* Omit deleting files we want to keep

* Refactor related tests

* Look for converted files instead of SVG sources when creating index files

* Add docs/info about icons dev

* Automatically find subfolders

* Find outdated icons and warn

* Make total count of icons better understandable

* Convert script to TypeScript
  • Loading branch information
tujoworker committed May 31, 2023
1 parent 8136368 commit 942c271
Show file tree
Hide file tree
Showing 1,710 changed files with 19,237 additions and 22,196 deletions.
21 changes: 21 additions & 0 deletions packages/dnb-design-system-portal/above_the_line_medium.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import _extends from "@babel/runtime/helpers/esm/extends";

var _path;

import React from 'react';

const above_the_line_medium = props => React.createElement("svg", _extends({
xmlns: "http://www.w3.org/2000/svg",
width: 24,
height: 24,
fill: "none",
viewBox: "0 0 24 24"
}, props), _path || (_path = React.createElement("path", {
stroke: "#000",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeWidth: 1.5,
d: "M12 21V9m0 0-4 4m4-4s2.243 2.047 4 4M2 3.5h2m4 0h2m4 0h2m4 0h2"
})));

export default above_the_line_medium;
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ title: 'Icons Library'

Icons are getting added (more or less) automatically by extracting them from [Figma Icons Library](https://www.figma.com/file/2aNwT4Lbyt9hFmDv8k34yN/Eufemia---Icons?node-id=1%3A9).

## What is the icons flow?

1. Icons are fetched as SVG files from an API.
1. The information about the new icons are stored in two data files:
- `icons-svg.lock` contains API information, so we are able to compare it next time the API is called.
- `icons-meta.json` contains additional information such as the category it belongs to.
1. They are then optimized with SVGO and stored in `/assets/icons/`. Each size in a different SVG.
1. During build (`yarn build`) the SVG files get converted to JSX based React components and stored in `/src/icons`. Also several index files and fallbacks are automatically generated.

## How to sync new icons?

To fetch new icons from the [Figma Icons Library](https://www.figma.com/file/2aNwT4Lbyt9hFmDv8k34yN/Eufemia---Icons?node-id=1%3A9) file, you have to:

1. Re-branch `main`, and name it `icons/{your-branch-name}` (it needs to include icons in the name):

```bash
git checkout main && git pull origin main
git pull origin main
```

```bash
Expand All @@ -34,6 +43,11 @@ If you need to re-fetch one or several icons that got updated or changed in the

1. Find the icon in the `icons-svg.lock` file and change the `updated` field to `0`.
1. Commit the change – but ensure the git branch name starts with `icon/` (more details above).
1. You may consider to run `yarn workspace @dnb/eufemia figma:reset` – it will delete everything and refetch the icons.

## How to convert icons only?

During development of the conversion script `convertSvgToJsx` you may consider to run `yarn workspace @dnb/eufemia dev:icons`. Its the same process, when calling `yarn build`. It will convert SVGs to JSXs and create all the needed index files in watch mode.

## Icons CI/CD process description

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
bell_medium as BellMedium,
bell as Bell,
} from '@dnb/eufemia/src/icons'
import * as PrimaryIconsMedium from '@dnb/eufemia/src/icons/primary_icons_medium'
import * as SecondaryIconsMedium from '@dnb/eufemia/src/icons/secondary_icons_medium'
import * as PrimaryIconsMedium from '@dnb/eufemia/src/icons/dnb/primary_icons_medium'
import * as SecondaryIconsMedium from '@dnb/eufemia/src/icons/dnb/secondary_icons_medium'
import { getListOfIcons } from '../../../../shared/parts/icons/ListAllIcons'

import { Icon, P, IconPrimary, Button } from '@dnb/eufemia/src'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import ComponentBox from '../../../../shared/tags/ComponentBox'
import { Button, Icon, P } from '@dnb/eufemia/src'
import styled from '@emotion/styled'
import { hamburger as hamburgerIcon } from '@dnb/eufemia/src/icons/secondary_icons'
import { hamburger as hamburgerIcon } from '@dnb/eufemia/src/icons'

export const LargeButtonsAndIconsExample = () => (
<ComponentBox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ Because `importmap` is still not supported by the majority of browsers, we use a
"imports": {
"react": "...",
"react-dom": "...",
"../icons/primary_icons.js": "https://unpkg.com/@dnb/eufemia/esm/dnb-ui-icons.min.mjs",
"../icons/primary_icons_medium.js": "https://unpkg.com/@dnb/eufemia/esm/dnb-ui-icons.min.mjs"
"../icons/dnb/primary_icons.js": "https://unpkg.com/@dnb/eufemia/esm/dnb-ui-icons.min.mjs",
"../icons/dnb/primary_icons_medium.js": "https://unpkg.com/@dnb/eufemia/esm/dnb-ui-icons.min.mjs"
}
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ And here an example with several imports:
```js
import { Button, Icon } from '@dnb/eufemia/components'
import { H1, P, Link } from '@dnb/eufemia/elements'
import { hamburger as hamburgerIcon } from '@dnb/eufemia/icons/secondary_icons'
import { hamburger as hamburgerIcon } from '@dnb/eufemia/icons'
```

### Events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import { useStaticQuery, graphql } from 'gatsby'
import { hamburger as hamburgerIcon } from '@dnb/eufemia/src/icons/secondary_icons'
import { hamburger as hamburgerIcon } from '@dnb/eufemia/src/icons'
import { close as closeIcon } from '@dnb/eufemia/src/icons/primary_icons'
import PortalLogo from './graphics/logo'
import { Icon, Button } from '@dnb/eufemia/src'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import React from 'react'
import PropTypes from 'prop-types'
import { Icon } from '@dnb/eufemia/src/components'
import { P } from '@dnb/eufemia/src/elements'
import * as PrimaryIcons from '@dnb/eufemia/src/icons/primary_icons'
import * as SecondaryIcons from '@dnb/eufemia/src/icons/secondary_icons'
import * as PrimaryIconsMedium from '@dnb/eufemia/src/icons/primary_icons_medium'
import * as SecondaryIconsMedium from '@dnb/eufemia/src/icons/secondary_icons_medium'
import iconsMetaData from '@dnb/eufemia/src/icons/icons-meta.json'
import * as PrimaryIcons from '@dnb/eufemia/src/icons/dnb/primary_icons'
import * as SecondaryIcons from '@dnb/eufemia/src/icons/dnb/secondary_icons'
import * as PrimaryIconsMedium from '@dnb/eufemia/src/icons/dnb/primary_icons_medium'
import * as SecondaryIconsMedium from '@dnb/eufemia/src/icons/dnb/secondary_icons_medium'
import iconsMetaData from '@dnb/eufemia/src/icons/dnb/icons-meta.json'
import AutoLinkHeader from '../../tags/AutoLinkHeader'
import {
listStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react'
import { Link, navigate } from 'gatsby'
import { Button, Tabs } from '@dnb/eufemia/src/components'
import { fullscreen as fullscreenIcon } from '@dnb/eufemia/src/icons/secondary_icons'
import { fullscreen as fullscreenIcon } from '@dnb/eufemia/src/icons'
import AutoLinkHeader from './AutoLinkHeader'
import { tabsWrapperStyle } from './Tabbar.module.scss'

Expand Down
1 change: 0 additions & 1 deletion packages/dnb-eufemia/assets/icons/dnb/fund_in.svg

This file was deleted.

1 change: 0 additions & 1 deletion packages/dnb-eufemia/assets/icons/dnb/fund_out.svg

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions packages/dnb-eufemia/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const config = {
'<rootDir>/stories/',
],
transformIgnorePatterns: ['/node_modules/(?!(ora|globby)/)'],
setupFiles: ['core-js'], // is needed by "globby" inside of convertSvgToJsx
transform: {
'^.+\\.(js|jsx|ts|tsx)$': 'babel-jest',
'^.+\\.(md|txt|css|scss)$': 'jest-raw-loader',
Expand Down
3 changes: 2 additions & 1 deletion packages/dnb-eufemia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"build:types:dev": "nodemon --exec 'babel-node --extensions .js,.ts,.tsx ./scripts/prebuild/generateTypes.js' --ext js --watch './src/**/*' --watch './scripts/**/*'",
"build:types:esm": "yarn tsc --project tsconfig.definitions.json --declarationDir ./build/esm --rootDir src",
"precommit": "yarn lint-staged",
"dev:icons": "nodemon --exec 'babel-node --extensions .js,.ts,.tsx ./scripts/tools/convertIcons' --ignore '/icons/**' --ignore '*.json'",
"dev:icons": "nodemon --exec 'babel-node --extensions .js,.ts,.tsx ./scripts/tools/convertIcons' --ext ts --ignore '/icons/**' --ignore '*.json'",
"dev:packages": "nodemon --exec 'yarn build:packages && yarn build:copy' --ext js,html,json,css,scss --watch './src/**/*' --ignore './umd/*'",
"dev:resources": "nodemon --exec 'babel-node --extensions .js,.ts,.tsx ./scripts/prebuild/resources/makeResourcesPackage.js' --ext js,html,json,css,scss --watch './build/style/**/*' --watch './scripts/**/*' --ignore '*.json'",
"dev:tasks": "nodemon --exec 'babel-node --extensions .js,.ts,.tsx ./scripts/prebuild/dev.js' --watch 'rollup.config.js' --ext js,html,json,css,scss --watch './src/components/**/*' --watch './src/style/**/*' --watch './scripts/**/*' --ignore '*.json'",
Expand Down Expand Up @@ -156,6 +156,7 @@
"@testing-library/react": "12.1.2",
"@testing-library/react-hooks": "7.0.2",
"@testing-library/user-event": "13.5.0",
"@types/fs-extra": "11.0.1",
"@types/jest": "29.2.6",
"@types/jest-axe": "3.5.5",
"@types/jest-image-snapshot": "6.1.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/dnb-eufemia/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import branchName from 'current-git-branch'
const excludes = [
{
name: 'dnbIcons',
global: [path.resolve('./src/icons/primary_icons.js')],
external: '../../icons/primary_icons.js',
global: [path.resolve('./src/icons/dnb/primary_icons.ts')],
external: '../../icons/dnb/primary_icons.ts',
},
{
name: 'dnbIcons',
global: [path.resolve('./src/icons/primary_icons_medium.js')],
external: '../../icons/primary_icons_medium.js',
global: [path.resolve('./src/icons/dnb/primary_icons_medium.ts')],
external: '../../icons/dnb/primary_icons_medium.ts',
},
]

Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-eufemia/scripts/figma/helpers/docHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const getLocalVersionFromLockFile = async ({ figmaFile }) => {
}

export const getFigmaDoc = async ({
figmaFile,
figmaFile = null,
localFile = null,
forceRefetch = null,
preventUpdate = null,
Expand Down
Loading

0 comments on commit 942c271

Please sign in to comment.