Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Icons): move all icons assets to dnb subfolder: assets/icons/dnb/*.svg #2187

Merged
merged 3 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/dnb-design-system-portal/src/docs/icons.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ListAllIcons from 'dnb-design-system-portal/src/shared/parts/icons/ListAl
This is a list of all icons available sorted in categories. Its a list where primary and secondary icons are combined. You may be interested to [read more](/icons/details) about what [the difference](/icons/primary) is and [how to import](/icons/secondary#react-example-usage).

- for Web there are both [icons as SVG](https://github.com/dnbexperience/eufemia/tree/main/packages/dnb-eufemia/assets/icons) and ready to use [React Components](/icons/secondary#react-example-usage).
joakbjerk marked this conversation as resolved.
Show resolved Hide resolved
- for Android there is a [custom XML (drawable) package](https://github.com/dnbexperience/eufemia/tree/main/packages/dnb-eufemia/assets/icons/eufemia-icons-xml.tgz) and a [categorized XML (drawable) package](https://github.com/dnbexperience/eufemia/tree/main/packages/dnb-eufemia/assets/icons/eufemia-icons-xml-categorized.tgz).
- for Android there is a [custom XML (drawable) package](https://github.com/dnbexperience/eufemia/tree/main/packages/dnb-eufemia/assets/icons/dnb/eufemia-icons-xml.tgz) and a [categorized XML (drawable) package](https://github.com/dnbexperience/eufemia/tree/main/packages/dnb-eufemia/assets/icons/dnb/eufemia-icons-xml-categorized.tgz).
- the support for iOS with the PDF format was discontinued in [v10](/uilib/about-the-lib/releases/eufemia/v10-info/).

<ListAllIcons groupBy="category" />
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ do not contain the properties anymore. Properties are only a part of a theme fil

As long as you don't import them in your application, you don't need to make any changes in your codebase.

### SVG assets

All `svg` icon files where moved inside a subfolder in `/assets/icons/dnb/...`.
tujoworker marked this conversation as resolved.
Show resolved Hide resolved

### StepIndicator

1. Find the `active_item` property and replace it with `current_step`.
Expand Down
4 changes: 2 additions & 2 deletions packages/dnb-eufemia/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
/umd
/style
/icons
/assets/icons/*.pdf
/assets/icons/*.xml
/assets/icons/*/*.pdf
/assets/icons/*/*.xml
/dnb-ui-resources
**/test-files/dist
/docs
Expand Down
2 changes: 2 additions & 0 deletions packages/dnb-eufemia/scripts/figma/FigmaAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ log.start('> Figma: Preparing for connecting to the Figma API ...')

export const fetchFigmaIcons = async ({
figmaFile = process.env.FIGMA_ICONS_FILE,
assetsDir = process.env.ASSETS_ICONS_DIR,
...args
} = {}) => {
if (!figmaFile) {
Expand All @@ -30,6 +31,7 @@ export const fetchFigmaIcons = async ({
const icons = await extractIconsAsSVG({
figmaFile,
figmaDoc,
assetsDir,
...args,
})
log.succeed(`> Figma: Icons conversion done (${icons?.length} icons)`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ import {
const localFile = require.resolve('./files/FigmaTestDoc.json')
const iconsLockFile = require.resolve('./files/icons-svg.lock')

jest.mock('fs', () => {
const origFs = jest.requireActual('fs')
return {
...origFs,
writeFile: jest.fn((file, content, encoding, cb) => {
cb()
}),
}
})

jest.mock('fs-extra', () => {
const writeStream = {
end: () => {},
Expand Down Expand Up @@ -78,12 +88,16 @@ jest.mock('fs-extra', () => {

return 'unknown'
}),
unlink: jest.fn().mockResolvedValue(),
writeFile: jest.fn(),
move: jest.fn(),
unlink: jest.fn(),
stat: jest.fn((file) => {
const size = file.includes('eufemia-icons-xml.tgz') ? 100 : 200
return { size }
}),
existsSync: jest.fn(() => {
return true
}),
createWriteStream: jest.fn(() => {
return writeStream
}),
Expand Down Expand Up @@ -153,13 +167,6 @@ describe('assetsExtractors', () => {
const succeed = jest.fn()
jest.spyOn(log, 'succeed').mockImplementation(succeed)

const writeFile = jest.fn()
jest.spyOn(fs, 'writeFile').mockImplementation(writeFile)
const unlink = jest.fn()
jest.spyOn(fs, 'unlink').mockImplementation(unlink)
const move = jest.fn()
jest.spyOn(fs, 'move').mockImplementation(move)

const figmaDoc = await getFigmaDoc({
forceRefetch: false,
preventUpdate: true,
Expand Down Expand Up @@ -227,38 +234,93 @@ describe('assetsExtractors', () => {
expect.stringContaining('finished to create eufemia-icons-xml.tgz')
)

expect(move).toHaveBeenCalledTimes(2)
expect(move).toHaveBeenNthCalledWith(
expect(fs.move).toHaveBeenCalledTimes(2)
expect(fs.move).toHaveBeenNthCalledWith(
1,
expect.stringContaining('/assets/icons/bell_medium.xml'),
expect.stringContaining('/assets/icons/bell/bell_medium.xml')
expect.stringContaining('/assets/icons/dnb/bell_medium.xml'),
expect.stringContaining('/assets/icons/dnb/bell/bell_medium.xml')
)
expect(move).toHaveBeenNthCalledWith(
expect(fs.move).toHaveBeenNthCalledWith(
2,
expect.stringContaining('/assets/icons/bell.xml'),
expect.stringContaining('/assets/icons/bell/bell.xml')
expect.stringContaining('/assets/icons/dnb/bell.xml'),
expect.stringContaining('/assets/icons/dnb/bell/bell.xml')
)

expect(fs.unlink).toHaveBeenCalledTimes(5)
expect(fs.unlink).toHaveBeenNthCalledWith(
1,
expect.stringContaining('/assets/icons/dnb/tmp.tgz')
)
expect(fs.unlink).toHaveBeenNthCalledWith(
2,
expect.stringContaining('/assets/icons/dnb/bell/bell_medium.xml')
)
expect(fs.unlink).toHaveBeenNthCalledWith(
3,
expect.stringContaining('/assets/icons/dnb/bell/bell.xml')
)
expect(fs.unlink).toHaveBeenNthCalledWith(
4,
expect.stringContaining('/assets/icons/dnb/bell_medium.xml')
)
expect(fs.unlink).toHaveBeenNthCalledWith(
5,
expect.stringContaining('/assets/icons/dnb/bell.xml')
)

expect(unlink).toHaveBeenCalledTimes(3)
expect(unlink).toHaveBeenNthCalledWith(
expect(fs.readFile).toHaveBeenCalledTimes(8)
expect(fs.readFile).toHaveBeenNthCalledWith(
1,
expect.stringContaining('/assets/icons/tmp.tgz')
expect.stringContaining(
'/scripts/figma/tasks/__tests__/files/FigmaTestDoc.json'
)
)
expect(unlink).toHaveBeenNthCalledWith(
expect(fs.readFile).toHaveBeenNthCalledWith(
2,
expect.stringContaining('/assets/icons/bell_medium.xml')
expect.stringContaining(
'/scripts/figma/tasks/__tests__/files/icons-svg.lock'
),
'utf-8'
)
expect(unlink).toHaveBeenNthCalledWith(
expect(fs.readFile).toHaveBeenNthCalledWith(
3,
expect.stringContaining('/assets/icons/bell.xml')
expect.stringContaining('/assets/icons/dnb/bell_medium.svg'),
'utf-8',
expect.any(Function)
)
expect(fs.readFile).toHaveBeenNthCalledWith(
4,
expect.stringContaining('/assets/icons/dnb/bell_medium.svg'),
'utf-8'
)
expect(fs.readFile).toHaveBeenNthCalledWith(
5,
expect.stringContaining('/assets/icons/dnb/bell.svg'),
'utf-8',
expect.any(Function)
)
expect(fs.readFile).toHaveBeenNthCalledWith(
6,
expect.stringContaining('/assets/icons/dnb/bell.svg'),
'utf-8'
)
expect(fs.readFile).toHaveBeenNthCalledWith(
7,
expect.stringContaining('/assets/icons/dnb/bell_medium.svg'),
'utf-8'
)
expect(fs.readFile).toHaveBeenNthCalledWith(
8,
expect.stringContaining('/assets/icons/dnb/bell.svg'),
'utf-8'
)

expect(tar.create).toHaveBeenCalledTimes(3)
expect(tar.create).toHaveBeenNthCalledWith(
1,
{
cwd: expect.stringContaining('/assets/icons'),
file: expect.stringContaining('/assets/icons/tmp.tgz'),
file: expect.stringContaining('/assets/icons/dnb/tmp.tgz'),
gzip: true,
},
['bell_medium.xml', 'bell.xml']
Expand All @@ -268,7 +330,7 @@ describe('assetsExtractors', () => {
{
cwd: expect.stringContaining('/assets/icons'),
file: expect.stringContaining(
'/assets/icons/eufemia-icons-xml.tgz'
'/assets/icons/dnb/eufemia-icons-xml.tgz'
),
gzip: true,
},
Expand All @@ -279,15 +341,15 @@ describe('assetsExtractors', () => {
{
cwd: expect.stringContaining('/assets/icons'),
file: expect.stringContaining(
'/assets/icons/eufemia-icons-xml-categorized.tgz'
'/assets/icons/dnb/eufemia-icons-xml-categorized.tgz'
),
gzip: true,
},
['bell/bell_medium.xml', 'bell/bell.xml']
)

expect(writeFile).toHaveBeenCalledTimes(4)
expect(writeFile).toHaveBeenNthCalledWith(
expect(fs.writeFile).toHaveBeenCalledTimes(4)
expect(fs.writeFile).toHaveBeenNthCalledWith(
1,
expect.stringContaining('/dnb-eufemia/src/icons/icons-svg.lock'),
expect.stringContaining(
Expand Down Expand Up @@ -321,21 +383,23 @@ describe('assetsExtractors', () => {
})
)
)
expect(writeFile).toHaveBeenNthCalledWith(
expect(fs.writeFile).toHaveBeenNthCalledWith(
2,
expect.stringContaining('/dnb-eufemia/assets/icons/bell_medium.svg'),
expect.stringContaining(
'/dnb-eufemia/assets/icons/dnb/bell_medium.svg'
),
expect.stringContaining(
`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M10 21.75a2.087 2.087 0 0 0 4.005 0M12 3a7.5 7.5 0 0 1 7.5 7.5c0 7.046 1.5 8.25 1.5 8.25H3s1.5-1.916 1.5-8.25A7.5 7.5 0 0 1 12 3Zm0 0V.75"/></svg>`
)
)
expect(writeFile).toHaveBeenNthCalledWith(
expect(fs.writeFile).toHaveBeenNthCalledWith(
3,
expect.stringContaining('/dnb-eufemia/assets/icons/bell.svg'),
expect.stringContaining('/dnb-eufemia/assets/icons/dnb/bell.svg'),
expect.stringContaining(
`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><path stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M6.756 14.067a1.299 1.299 0 0 0 2.492 0M8 2.4a4.667 4.667 0 0 1 4.667 4.667c0 4.384.933 5.133.933 5.133H2.4s.933-1.192.933-5.133A4.667 4.667 0 0 1 8 2.4Zm0 0V1"/></svg>`
)
)
expect(writeFile).toHaveBeenNthCalledWith(
expect(fs.writeFile).toHaveBeenNthCalledWith(
4,
expect.stringContaining('/dnb-eufemia/src/icons/icons-meta.json'),
expect.stringContaining(
Expand Down
Loading