mirror of https://github.com/grafana/grafana
Use bookmark icon for Saved Items, add support for solid bookmark icon (#46775)
* Use bookmark icon for Saved Items, add support for solid bookmark icon * Add some unit tests * Refactor utils into own file * Update test title * Fix import * consistent function stylepull/46803/head
parent
4631bb2c54
commit
5f67d78219
@ -0,0 +1,18 @@ |
||||
import { getIconSubDir } from './utils'; |
||||
|
||||
describe('Icon utils', () => { |
||||
describe('getIconSubDir', () => { |
||||
it.each` |
||||
name | type | expected |
||||
${'gf-panel'} | ${undefined} | ${'custom'} |
||||
${'grafana'} | ${undefined} | ${'mono'} |
||||
${'bookmark'} | ${'default'} | ${'unicons'} |
||||
${'bookmark'} | ${'solid'} | ${'solid'} |
||||
${'bookmark'} | ${undefined} | ${'mono'} |
||||
${'folder'} | ${'mono'} | ${'mono'} |
||||
`('it returns the correct iconSubDir for icon $name with type $type', ({ name, type, expected }) => {
|
||||
const iconSubDir = getIconSubDir(name, type); |
||||
expect(iconSubDir).toEqual(expected); |
||||
}); |
||||
}); |
||||
}); |
||||
@ -0,0 +1,37 @@ |
||||
import { IconName, IconSize } from '../../types/icon'; |
||||
|
||||
const alwaysMonoIcons: IconName[] = ['grafana', 'favorite', 'heart-break', 'heart', 'panel-add', 'library-panel']; |
||||
|
||||
export function getIconSubDir(name: IconName, type: string): string { |
||||
if (name?.startsWith('gf-')) { |
||||
return 'custom'; |
||||
} else if (alwaysMonoIcons.includes(name)) { |
||||
return 'mono'; |
||||
} else if (type === 'default') { |
||||
return 'unicons'; |
||||
} else if (type === 'solid') { |
||||
return 'solid'; |
||||
} else { |
||||
return 'mono'; |
||||
} |
||||
} |
||||
|
||||
/* Transform string with px to number and add 2 pxs as path in svg is 2px smaller */ |
||||
export function getSvgSize(size: IconSize) { |
||||
switch (size) { |
||||
case 'xs': |
||||
return 12; |
||||
case 'sm': |
||||
return 14; |
||||
case 'md': |
||||
return 16; |
||||
case 'lg': |
||||
return 18; |
||||
case 'xl': |
||||
return 24; |
||||
case 'xxl': |
||||
return 36; |
||||
case 'xxxl': |
||||
return 48; |
||||
} |
||||
} |
||||
@ -1,4 +1,4 @@ |
||||
# unicons folder is imported via webpack |
||||
# https://github.com/Iconscout/unicons/tarball/d0859416ab8d8e60dcfa1c0b50716874fcf11778 |
||||
# just the line icons |
||||
unicons |
||||
# unicons and solid folders are imported via webpack |
||||
# https://github.com/Iconscout/unicons/tarball/d0859416ab8d8e60dcfa1c0b50716874fcf11778 |
||||
unicons |
||||
solid |
||||
|
||||
Loading…
Reference in new issue