Skip to content

Commit

Permalink
started moving newItem into a dedicated component
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanTreffler committed Sep 9, 2020
1 parent 906f459 commit 9e012ad
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 58 deletions.
61 changes: 3 additions & 58 deletions src/components/AppNavigationItem/AppNavigationItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ the placeholder is the previous title of the element.
<AppNavigationItem title="Editable Item" :editable="true"
editPlaceholder="your_placeholder_here" icon="icon-folder" @update:title="function(value){alert(value)}" />
```

### 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)}" />
```
### Undo element
Just set the `undo` and `title` props. When clicking the undo button, an `undo` event is emitted.

Expand All @@ -119,14 +112,13 @@ Just set the `pinned` prop.
'app-navigation-entry--opened': opened,
'app-navigation-entry--pinned': pinned,
'app-navigation-entry--editing' : editingActive,
'app-navigation-entry--newItemActive': newItemActive,
'app-navigation-entry--deleted': undo,
'app-navigation-entry--collapsible': collapsible,
'active': isActive
}"
class="app-navigation-entry">
<!-- Icon and title -->
<a v-if="!undo && !newItem"
<a v-if="!undo"
class="app-navigation-entry-link"
href="#"
@click="onClick">
Expand Down Expand Up @@ -156,26 +148,6 @@ Just set the `pinned` prop.
</div>
</div>

<!-- New Item -->
<div v-if="newItem" 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>

<!-- Counter and Actions -->
<div v-if="hasUtils" class="app-navigation-entry__utils">
<slot name="counter" />
Expand Down Expand Up @@ -279,22 +251,14 @@ export default {
default: false,
},
/**
* When clicked a inline text input with a confirm and cancel button appears insted of the title.
* When the user confirms the input the 'new-item' event gets emitted.
*/
newItem: {
type: Boolean,
default: false,
},
/**
* Only for 'editable' items, sets label for the edit action button.
*/
editLabel: {
type: String,
default: '',
},
/**
* Only for items in 'editable' or 'newItem' mode, sets the placeholder text for the editing form.
* Only for items in 'editable' mode, sets the placeholder text for the editing form.
*/
editPlaceholder: {
type: String,
Expand Down Expand Up @@ -348,11 +312,9 @@ export default {
data() {
return {
newItemValue: '',
editingValue: '',
opened: this.open,
editingActive: false,
newItemActive: false,
}
},
computed: {
Expand Down Expand Up @@ -450,23 +412,6 @@ export default {
this.editingActive = false
},
// 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
},
// Undo methods
handleUndo() {
this.$emit('undo')
Expand All @@ -475,7 +420,7 @@ export default {
}
</script>

<style lang="scss" scoped>
<style lang="scss">
@import '../../fonts/scss/iconfont-vue';
.app-navigation-entry {
Expand Down
121 changes: 121 additions & 0 deletions src/components/AppNavigationItem/AppNavigationNewItem.vue
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>

0 comments on commit 9e012ad

Please sign in to comment.