-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started moving newItem into a dedicated component
- Loading branch information
1 parent
906f459
commit 9e012ad
Showing
2 changed files
with
124 additions
and
58 deletions.
There are no files selected for viewing
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
121 changes: 121 additions & 0 deletions
121
src/components/AppNavigationItem/AppNavigationNewItem.vue
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,121 @@ | ||
<docs> | ||
### New Item element | ||
Add the prop `:new-item=true`. | ||
|
||
``` | ||
<AppNavigationItem title="New Item" icon="icon-add" :new-item="true" @new-item="function(value){alert(value)}" /> | ||
``` | ||
</docs> | ||
<template> | ||
<!-- Navigation item, can be either an <li> or a <router-link> depending on the props --> | ||
<nav-element v-bind="navElement" | ||
:class="{ | ||
'app-navigation-entry--newItemActive': newItemActive, | ||
}" | ||
class="app-navigation-entry"> | ||
<!-- New Item --> | ||
<div class="app-navigation-entry-div" @click="handleNewItem"> | ||
<div :class="{ 'icon-loading-small': loading, [icon]: icon && isIconShown }" | ||
class="app-navigation-entry-icon"> | ||
<slot v-if="!loading" v-show="isIconShown" name="icon" /> | ||
</div> | ||
|
||
<span v-if="!newItemActive" class="app-navigation-entry__title" :title="title"> | ||
{{ title }} | ||
</span> | ||
|
||
<!-- new Item input --> | ||
<div v-if="newItemActive" class="newItemContainer"> | ||
<InputConfirmCancel v-model="newItemValue" | ||
:placeholder="editPlaceholder !== '' ? editPlaceholder : title" | ||
@cancel="cancelNewItem" | ||
@confirm="handleNewItemDone" /> | ||
</div> | ||
</div> | ||
</nav-element> | ||
</template> | ||
|
||
<script> | ||
import { directive as ClickOutside } from 'v-click-outside' | ||
import isMobile from '../../mixins/isMobile' | ||
import InputConfirmCancel from './InputConfirmCancel.vue' | ||
export default { | ||
name: 'AppNavigationNewItem', | ||
components: { | ||
InputConfirmCancel, | ||
}, | ||
directives: { | ||
ClickOutside, | ||
}, | ||
mixins: [isMobile], | ||
props: { | ||
/** | ||
* The title of the element. | ||
*/ | ||
title: { | ||
type: String, | ||
required: true, | ||
}, | ||
/** | ||
* Refers to the icon on the left, this prop accepts a class | ||
* like 'icon-category-enabled'. | ||
*/ | ||
icon: { | ||
type: String, | ||
default: '', | ||
}, | ||
/** | ||
* Displays a loading animated icon on the left of the element | ||
* instead of the icon. | ||
*/ | ||
loading: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
/** | ||
* Only for 'editable' items, sets label for the edit action button. | ||
*/ | ||
editLabel: { | ||
type: String, | ||
default: '', | ||
}, | ||
/** | ||
* Sets the placeholder text for the editing form. | ||
*/ | ||
editPlaceholder: { | ||
type: String, | ||
default: '', | ||
}, | ||
}, | ||
data() { | ||
return { | ||
newItemValue: '', | ||
newItemActive: false, | ||
} | ||
}, | ||
computed: { | ||
}, | ||
methods: { | ||
// New Item methods | ||
handleNewItem() { | ||
this.newItemActive = true | ||
this.onMenuToggle(false) | ||
this.$nextTick(() => { | ||
// this.$refs.newItemInput.focus() | ||
}) | ||
}, | ||
cancelNewItem() { | ||
this.newItemActive = false | ||
}, | ||
handleNewItemDone() { | ||
this.$emit('new-item', this.newItemValue) | ||
this.newItemValue = '' | ||
this.newItemActive = false | ||
}, | ||
}, | ||
} | ||
</script> |