limit icon component size to valid values
This commit is contained in:
parent
815f35be4f
commit
539ea5ebda
2 changed files with 18 additions and 5 deletions
|
@ -12,6 +12,9 @@
|
||||||
/>
|
/>
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
// only allow classes in images.scss e.g. s12
|
||||||
|
const validSizes = [8, 12, 16, 18, 24, 32, 48, 72];
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
name: {
|
name: {
|
||||||
|
@ -22,7 +25,10 @@
|
||||||
size: {
|
size: {
|
||||||
type: Number,
|
type: Number,
|
||||||
required: false,
|
required: false,
|
||||||
default: 0,
|
default: 16,
|
||||||
|
validator(value) {
|
||||||
|
return validSizes.includes(value);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
cssClasses: {
|
cssClasses: {
|
||||||
|
@ -42,6 +48,7 @@
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<svg
|
<svg
|
||||||
:class="[iconSizeClass, cssClasses]">
|
:class="[iconSizeClass, cssClasses]">
|
||||||
|
|
|
@ -11,7 +11,7 @@ describe('Sprite Icon Component', function () {
|
||||||
|
|
||||||
icon = mountComponent(IconComponent, {
|
icon = mountComponent(IconComponent, {
|
||||||
name: 'test',
|
name: 'test',
|
||||||
size: 99,
|
size: 32,
|
||||||
cssClasses: 'extraclasses',
|
cssClasses: 'extraclasses',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -34,12 +34,18 @@ describe('Sprite Icon Component', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should properly compute iconSizeClass', function () {
|
it('should properly compute iconSizeClass', function () {
|
||||||
expect(icon.iconSizeClass).toBe('s99');
|
expect(icon.iconSizeClass).toBe('s32');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('forbids invalid size prop', () => {
|
||||||
|
expect(icon.$options.props.size.validator(NaN)).toBeFalsy();
|
||||||
|
expect(icon.$options.props.size.validator(0)).toBeFalsy();
|
||||||
|
expect(icon.$options.props.size.validator(9001)).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should properly render img css', function () {
|
it('should properly render img css', function () {
|
||||||
const classList = icon.$el.classList;
|
const classList = icon.$el.classList;
|
||||||
const containsSizeClass = classList.contains('s99');
|
const containsSizeClass = classList.contains('s32');
|
||||||
const containsCustomClass = classList.contains('extraclasses');
|
const containsCustomClass = classList.contains('extraclasses');
|
||||||
expect(containsSizeClass).toBe(true);
|
expect(containsSizeClass).toBe(true);
|
||||||
expect(containsCustomClass).toBe(true);
|
expect(containsCustomClass).toBe(true);
|
||||||
|
|
Loading…
Reference in a new issue