Skip to content

Commit

Permalink
feat: add icon component
Browse files Browse the repository at this point in the history
  • Loading branch information
hcarmonas committed Jun 22, 2022
1 parent 656007d commit 3856ad8
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/assets/img/icon/icon-file-upload.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/img/icon/icon-remove.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/img/icon/icon-success-green.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/components/Icon/Icon.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { shallowMount } from '@vue/test-utils';
import Icon from './Icon.vue';

// Initializing wrapper variable
let wrapper = null;

// Mount the component to make a wrapper before each test
beforeEach(() => {
wrapper = shallowMount(Icon, {
propsData: {
id: 'icon',
type: 'remove',
},
});
});

describe('Icon - Unit', () => {
it('should mount the component', () => {
expect(wrapper.vm).toBeDefined();
});

it('should icon visibility using prop', async () => {
expect(wrapper.props().type).toBe('remove');
});
});
51 changes: 51 additions & 0 deletions src/components/Icon/Icon.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Icon from './Icon.vue';

export default {
title: 'Components/UI Elements/Icon',
component: Icon,
argTypes: {
type: {
control: {
type: 'select',
options: ['remove', 'error', 'filter', 'info'],
},
defaultValue: 'remove',
},
},

parameters: {
componentSubtitle: 'Dynamic icon',
},
};

const Template = (args, { argTypes }) => ({
props: Object.keys(argTypes),
components: { Icon },
template: '<Icon v-bind="$props" @click="handleClick"/>',
});

Template.bind({});

export const Remove = Template.bind({});
Remove.args = {
id: 'icon-1',
type: 'remove',
};

export const Error = Template.bind({});
Error.args = {
id: 'icon-1',
type: 'error',
};

export const Filter = Template.bind({});
Filter.args = {
id: 'icon-1',
type: 'filter',
};

export const Info = Template.bind({});
Info.args = {
id: 'icon-1',
type: 'info',
};
33 changes: 33 additions & 0 deletions src/components/Icon/Icon.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<Component :is="dynamicIcon" @click="click" />
</template>

<script>
export default {
name: 'Icon',
props: {
/** Specify a custom id */
id: {
type: String,
required: true,
},
/** Specify icon name, You can use any icon that you have inside the
* components ui, it is not necessary to pass the "icon-",
* just what comes after that. */
type: {
type: String,
required: true,
},
},
computed: {
dynamicIcon() {
return () => import(`@img/icon/icon-${this.type}.svg`);
},
},
methods: {
click() {
this.$emit('click');
},
},
};
</script>
10 changes: 10 additions & 0 deletions src/components/Icon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**Demo**

```html
<PageSize v-model="size" @change="handleChange" />
```

| Prop name | Type | Required | Default |
| --------- | -------- | -------- | ------- |
| id | `String` | `true` | --- |
| value | `Number` | `true` | --- |
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export { default as Checkbox } from '@components/Checkbox/Checkbox';
export { default as Chip } from '@components/Chip/Chip';
export { default as FilterSelectList } from '@components/FilterComponent/FilterSelectList/FilterSelectList';
export { default as FilterComponent } from '@components/FilterComponent/FilterComponent';
export { default as Icon } from '@components/Icon/Icon';
export { default as Input } from '@components/Input/Input';
export { default as InputMinusPlus } from '@components/InputMinusPlus/InputMinusPlus';
export { default as List } from '@components/List/List';
Expand Down

0 comments on commit 3856ad8

Please sign in to comment.