-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from solfacil/feature/add-icon-component
Feature: add icon component
- Loading branch information
Showing
8 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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 receive the prop type remove', async () => { | ||
expect(wrapper.props().type).toBe('remove'); | ||
}); | ||
|
||
it('should render correct component in template', async () => { | ||
const IconRemove = await import('@img/icon/icon-remove.svg'); | ||
expect(wrapper.findComponent(IconRemove).exists()).toBeTruthy(); | ||
}); | ||
|
||
it('should emits click on click in icon', async () => { | ||
jest.spyOn(wrapper.vm, '$emit'); | ||
|
||
const IconRemove = await import('@img/icon/icon-remove.svg'); | ||
wrapper.findComponent(IconRemove).vm.$emit('click'); | ||
|
||
expect(wrapper.vm.$emit).toHaveBeenCalledWith('click'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<template> | ||
<Component :is="dynamicIcon" :id="id" @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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | --- | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters