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

Feature/306 #315

Open
wants to merge 5 commits into
base: feature/update
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 0 additions & 3 deletions _src /test/app/App.html

This file was deleted.

1 change: 0 additions & 1 deletion _src /test/app/App.js

This file was deleted.

14 changes: 0 additions & 14 deletions _src /test/app/App.scss

This file was deleted.

12 changes: 0 additions & 12 deletions _src /test/app/App.vue

This file was deleted.

16 changes: 0 additions & 16 deletions _src /test/button/Button.html

This file was deleted.

2 changes: 0 additions & 2 deletions _src /test/button/Button.js

This file was deleted.

15 changes: 0 additions & 15 deletions _src /test/button/Button.scss

This file was deleted.

14 changes: 0 additions & 14 deletions _src /test/button/Button.selectors.json

This file was deleted.

34 changes: 0 additions & 34 deletions _src /test/button/Button.stories.js

This file was deleted.

12 changes: 0 additions & 12 deletions _src /test/button/Button.vue

This file was deleted.

10 changes: 10 additions & 0 deletions src/atoms/app/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
.js-focus-visible :focus:not([data-focus-visible-added]) {
@apply outline-none;
}

.js-focus-visible .focus-visible {
@apply outline-focus;
}
}
2 changes: 1 addition & 1 deletion src/atoms/blockquote/Blockquote.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.a-blockquote {
@apply my-2;
@apply py-2 pr-2 pl-4;
@apply border-l-4 border-solid border-light;
@apply border-l-4 border-solid border-gray-300;
@apply leading-relaxed;
}
2 changes: 1 addition & 1 deletion src/atoms/label/Label.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
},
primary: {
label: [
'text-gray-600'
'text-gray-800'
]
},
hidden: {
Expand Down
34 changes: 34 additions & 0 deletions src/molecules/input/Input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div :class="getClass('input')">
<!-- @slot Label (Named slot) -->
<slot name="label" v-bind="{ label, id }">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

<a-label
:class="[
'transition-all ease-linear transition-300',
{
'text-xs inline-flex': variant ==='primary'
},
{
'flex-shrink-0 mr-4': variant !=='primary'
},
Comment on lines +6 to +12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these classes added here instead of config?

{
'transform translate-x-6 translate-y-9 scale-125': (variant === 'primary' && (!value && !hasFocus))
}
]"
:for="id"
>
{{ label }}
</a-label>
</slot>
<input
v-bind="$attrs"
v-on="listeners"
:value="value"
:id="id"
:class="[
getClass('input__field'),
value ? getClass('input__field__filled') : ''
]"
>
<!-- @slot Icon (Named slot) -->
<slot name="icon" v-bind:variant="variant" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

</div>
78 changes: 78 additions & 0 deletions src/molecules/input/Input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// @vue/component
import getClass from '../../../utils/helpers/get-class.js'

export default {
mixins: [getClass],
inheritAttrs: false,
props: {
/**
* Prop to handle v-model
*/
value: {
type: String,
default: null
},
/**
* Input id
*/
id: {
type: String,
required: true
},
/**
* Label text
*/
label: {
type: String,
required: true
}
},
computed: {
listeners () {
return {
...this.$listeners,
input: event => this.$emit('input', event.target.value),
focus: () => this.isFocused(true),
blur: () => this.isFocused(false)
}
}
},
data () {
return {
hasFocus: false,
config: {
base: {
input: [
'relative'
],
input__field: [
'w-full', 'h-12',
'px-4'
],
input__field__filled: [
'border-formfilled'
]
},
primary: {
input__field: [
'border', 'border-solid', 'border-form',
'placeholder-primary'
]
},
inline: {
input: [
'flex', 'items-center'
],
input__field: [
'border', 'border-solid', 'border-form', 'placeholder-primary'
]
}
}
}
},
methods: {
isFocused (value) {
this.hasFocus = value
}
}
}
92 changes: 92 additions & 0 deletions src/molecules/input/Input.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { mount, shallowMount } from '@vue/test-utils'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'shallowMount' is declared but its value is never read

import AInput from './Input.vue'
import ALabel from './../../atoms/label/Label.vue'

describe('Input', () => {
it('has default structure', () => {
const wrapper = mount(AInput, {
propsData: {
id: 'input-id',
label: 'input label',
type: 'text'
}
})
const input = wrapper.find('input')
expect(wrapper.element.tagName === 'DIV')

expect(input.attributes().id).toBeDefined()
expect(input.attributes().id).toBe('input-id')
expect(input.attributes().type).toBeDefined()
expect(input.attributes().type).toBe('text')
})

it('renders email input when type set to email', () => {
const wrapper = mount(AInput, {
propsData: {
id: 'input-id',
label: 'input label',
type: 'email'
}
})

const input = wrapper.find('input')
expect(input.attributes('type')).toBe('email')
})

it('renders slots content when passed', () => {
const wrapper = mount(AInput, {
propsData: {
id: 'input-id',
label: 'Alpaca UI'
},
scopedSlots: {
label: '<label for="input-id">{{ props.label }}</label>'
}
})

const label = wrapper.find('label')

expect(label.exists()).toBe(true)
expect(label.text()).toEqual('Alpaca UI')
expect(label.attributes().for).toBeDefined()
expect(label.attributes().for).toBe('input-id')
})

it('renders label slot with component', () => {
const wrapper = mount(AInput, {
propsData: {
id: 'input-id',
label: 'Alpaca UI'
},
scopedSlots: {
label: '<a-label :for="props.id">{{ props.label }}</a-label>'
},
stubs: {
'a-label': ALabel
}
})

const label = wrapper.find('label')

expect(label.exists()).toBe(true)
expect(label.text()).toEqual('Alpaca UI')
expect(label.attributes().for).toBeDefined()
expect(label.attributes().for).toBe('input-id')
})

it('emits an input event', () => {
const wrapper = mount(AInput, {
propsData: {
id: 'input-id',
label: 'input label'
}
})

const textInput = wrapper.find('input')
textInput.setValue('Sample text')

expect(wrapper.emitted('input')).toBeTruthy()
expect(wrapper.emitted().input[0].length).toBe(1)
expect(wrapper.emitted().input[0][0]).toEqual('Sample text')
})
})
Loading