Skip to content

Commit

Permalink
Merge pull request #1797 from codyrancher/array-list-grouped
Browse files Browse the repository at this point in the history
Adding the ArrayListGrouped component
  • Loading branch information
vincent99 authored Nov 6, 2020
2 parents 118ee4c + 7b9a65a commit 6f0e572
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
16 changes: 14 additions & 2 deletions components/form/ArrayList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default {
rows.push({ value: '' });
}
return { rows };
return { rows, lastUpdateWasFromValue: false };
},
computed: {
Expand Down Expand Up @@ -152,12 +152,24 @@ export default {
watch: {
value() {
this.lastUpdateWasFromValue = true;
this.rows = (this.value || []).map(v => ({ value: v }));
},
rows: {
deep: true,
handler(newValue, oldValue) {
// lastUpdateWasFromValue is used to break a cycle where when rows are updated
// this was called which then forced rows to updated again
if (!this.lastUpdateWasFromValue) {
this.queueUpdate();
}
this.lastUpdateWasFromValue = false;
}
}
},
created() {
this.queueUpdate = debounce(this.update, 100);
this.queueUpdate = debounce(this.update, 50);
},
methods: {
Expand Down
40 changes: 40 additions & 0 deletions components/form/ArrayListGrouped.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script>
import ArrayList from '@/components/form/ArrayList';
import InfoBox from '@/components/InfoBox';
export default { components: { ArrayList, InfoBox } };
</script>
<template>
<ArrayList class="array-list-grouped" v-bind="$attrs" @input="$emit('input', $event)">
<template v-slot:columns="scope">
<InfoBox>
<slot v-bind="scope"></slot>
</InfoBox>
</template>
<template v-slot:remove-button="scope">
<button class="btn role-link close" @click="scope.remove">
<i class="icon icon-2x icon-x" />
</button>
</template>
</ArrayList>
</template>
<style lang="scss">
.array-list-grouped {
.box {
position: relative;
}
.remove {
position: absolute;
padding: 0px;
top: 0;
right: 0;
}
.info-box {
margin-bottom: 0;
}
}
</style>

0 comments on commit 6f0e572

Please sign in to comment.