Skip to content

Instantly share code, notes, and snippets.

@dillingham
Created January 7, 2019 23:34
Show Gist options
  • Save dillingham/1b0dedcb72554e10cf7b9faccb4d2915 to your computer and use it in GitHub Desktop.
Save dillingham/1b0dedcb72554e10cf7b9faccb4d2915 to your computer and use it in GitHub Desktop.
bowersbros solution to toolbar buttons
<template>
    <div class="flex w-full justify-end items-center">
        <template v-if="hasButtons">
            <component 
                v-for="button in hasButtons" :key="button.id" :is="'detail-' + button.component" :field="button"/>
        </template>
        <template v-else>
            <div />
        </template>
    </div>
</template>

<script>
import _ from 'lodash';

export default {
    props: ['resource', 'resourceName', 'resourceId'],
    computed: {
        hasButtons() {
            var buttons = [];

            var fields = _.toArray(JSON.parse(JSON.stringify(this.resource.fields)))

            fields.forEach(field => {
                if (field.component === 'button') {
                    buttons.push(field);
                }
            })

            return _.toArray(buttons);
        }
    }
}
</script>
Vue.component('custom-detail-toolbar');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment