Skip to content

Commit

Permalink
feat(slots): added 4 new slots for input
Browse files Browse the repository at this point in the history
`input-before`, `input-start`, `input-end`, `input-after`

re #98
  • Loading branch information
Ilya authored and Ilya committed Mar 29, 2019
1 parent a03694b commit 3f892e0
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 46 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
- 2 themes: Bootstrap 4, Material Design
- autocomplete (you can use custom search)
- control through arrows
- slots (9)
- slots (13)
- events (7)
- props (22)
- props (23)
- loading indicator (helpful for REST requests)
- validation
- support on mobile devices
Expand Down
16 changes: 16 additions & 0 deletions gh-pages-src/pages/Docs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ export default {
},
description: 'Define a custom item appearance'
},
{
name: 'input-before',
description: 'Before input (text field)'
},
{
name: 'input-start',
description: 'Inside the input at the start'
},
{
name: 'input-end',
description: 'Inside the input at the end'
},
{
name: 'input-after',
description: 'After input'
},
{
name: 'before-items',
scopeProperties: {},
Expand Down
32 changes: 28 additions & 4 deletions gh-pages-src/pages/dev/Example5.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,48 @@
v-model="selected"
:items="items"
:error-message="errorMessage"
:successful="!errorMessage && selected"
:disabled="disabled"
:readonly="readonly"
:disable-search="disableSearch"
placeholder="Select name"
@blur="validate"
/>
>
<template
v-if="!errorMessage && selected"
#input-end
>
<span style="color: green; margin-right: 8px;">
</span>
</template>
</cool-select>

<br>

<cool-select
v-model="selected2"
v-model="selected"
:items="items"
:error-message="errorMessage"
:disabled="disabled"
:readonly="readonly"
:disable-search="disableSearch"
placeholder="Select name"
/>
>
<template #input-before>
before
</template>
<template #input-start>
start
</template>

<template #input-end>
end
</template>
<template #input-after>
after
</template>
</cool-select>

<br>
<button @click="disabled = !disabled">
Expand Down Expand Up @@ -67,7 +92,6 @@ export default {
readonly: false,
disableSearch: false,
selected: null,
selected2: null,
items: '[{"first_name":"one"}, {"first_name":"two"}, {"first_name":"three"}, {"first_name":"four"}, {"first_name":"five"}]',
errorMessage: null
}),
Expand Down
85 changes: 52 additions & 33 deletions src/component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,62 @@
@mousedown="onClick"
@focus="onFocus"
>
<div
ref="IZ-select__input"
:class="{
'IZ-select__input': true,
'IZ-select__input--focused': focused,
'IZ-select__input--has-menu': hasMenu,
'IZ-select__input--has-error': hasError,
'IZ-select__input--selection-slot': showSelectionSlot,
'IZ-select__input--disabled': disabled,
'IZ-select__input--readonly': readonly
}"
:style="inputStyles"
>
<div class="IZ-select__input-wrap">
<slot
v-if="showSelectionSlot"
:item="selectedItem"
name="selection"
name="input-before"
/>

<input
ref="IZ-select__input-for-text"
v-bind="inputElCustomAttributes"
:value="inputValue"
:placeholder="placeholder"
:style="inputForTextStyles"
:class="inputForTextClass"
:disabled="disableSearch || disabled"
:readonly="readonly"
:tabindex="disableSearch ? -1 : 1"
type="text"
role="combobox"
autocomplete="off"
@keyup="onSearchKeyUp"
@keydown="onSearchKeyDown"
@input="onSearch"
@focus="onFocus"
<div
ref="IZ-select__input"
:class="{
'IZ-select__input': true,
'IZ-select__input--focused': focused,
'IZ-select__input--has-menu': hasMenu,
'IZ-select__input--has-error': hasError,
'IZ-select__input--successful': successful,
'IZ-select__input--selection-slot': showSelectionSlot,
'IZ-select__input--disabled': disabled,
'IZ-select__input--readonly': readonly
}"
:style="inputStyles"
>
<slot
name="input-start"
/>

<slot
v-if="showSelectionSlot"
:item="selectedItem"
name="selection"
/>

<input
ref="IZ-select__input-for-text"
v-bind="inputElCustomAttributes"
:value="inputValue"
:placeholder="placeholder"
:style="inputForTextStyles"
:class="inputForTextClass"
:disabled="disableSearch || disabled"
:readonly="readonly"
:tabindex="disableSearch ? -1 : 1"
type="text"
role="combobox"
autocomplete="off"
@keyup="onSearchKeyUp"
@keydown="onSearchKeyDown"
@input="onSearch"
@focus="onFocus"
>

<slot
name="input-end"
/>
</div>

<slot
name="input-after"
/>
</div>

<transition name="fade">
Expand Down
5 changes: 5 additions & 0 deletions src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,10 @@ export default {
type: [Array, String, Object],
default: () => '',
note: 'custom "class" attribute for the input field. You can specify dynamic class.'
},
successful: {
type: Boolean,
default: false,
note: 'does the component have a successful state. If true, then apply green colors.'
}
}
4 changes: 4 additions & 0 deletions src/styles/main.styl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
*
box-sizing: border-box;

.IZ-select__input-wrap
display: flex;
align-items: center;

.fade
&-leave-active
position: absolute;
Expand Down
7 changes: 7 additions & 0 deletions src/styles/themes/bootstrap.styl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
input
color: #ff5252 !important;

&.IZ-select__input--successful
border: 1px solid #28a745 !important;
caret-color: #28c346 !important;

&.IZ-select__input--focused
border-color: #80bdff;
outline: 0;
Expand All @@ -50,6 +54,9 @@
&.IZ-select__input--has-error
box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;

&.IZ-select__input--successful
box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25) !important;

&.IZ-select__input--disabled
pointer-events: none;
background-color: #e9ecef;
Expand Down
12 changes: 5 additions & 7 deletions src/styles/themes/material-design.styl
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@
input
color: #ff5252 !important;

//&.IZ-select__input--focused
// border-color: #80bdff;
// outline: 0;
// box-shadow: 0 0 0 0.2rem rgba(128, 189, 255, 0.5);
//
// &.IZ-select__input--has-error
// box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
&.IZ-select__input--successful
border: 1px solid #28a745 !important;
caret-color: #28c346 !important;

// focused состояние не нужно

&.IZ-select__input--disabled
pointer-events: none;
Expand Down

0 comments on commit 3f892e0

Please sign in to comment.