Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to customize the node slot? #42

Closed
hirisov opened this issue Feb 12, 2023 · 1 comment
Closed

How to customize the node slot? #42

hirisov opened this issue Feb 12, 2023 · 1 comment

Comments

@hirisov
Copy link

hirisov commented Feb 12, 2023

Hello,

amazing package, thanks for your great work! Can you please help how can I customize the node "template" with default slot? Basically I would like to append an icon after the text with the ID of the node, eg. for opening a modal to insert a new node after/under that node. I tried to find the structure or the default slot both in docs and the source, but couldn't really figure it out.

regards, Gabor

@phphe
Copy link
Owner

phphe commented Feb 18, 2023

https://hetree.phphe.com/v2/api#default

Example

<template>
  <div>
    Checked: {{ checked }}
    <Draggable v-model="treeData" ref="tree" @check:node="onCheckNode">
      <template #default="{ node, stat }">
        <button @click="stat.open = !stat.open">
          {{ stat.open ? '-' : '+' }}
        </button>
        <input type="checkbox" v-model="stat.checked" />
        {{ node.text }}
      </template>
    </Draggable>
  </div>
</template>

<script>
  import { BaseTree, Draggable, pro } from '@he-tree/vue'
  import '@he-tree/vue/style/default.css'

  export default {
    components: { Draggable },
    data() {
      return {
        treeData: [
          {
            text: 'Projects',
            children: [
              {
                text: 'Frontend',
                children: [
                  {
                    text: 'Vue',
                    children: [
                      {
                        text: 'Nuxt',
                      },
                    ],
                  },
                  {
                    text: 'React',
                    children: [
                      {
                        text: 'Next',
                      },
                    ],
                  },
                  {
                    text: 'Angular',
                  },
                ],
              },
              {
                text: 'Backend',
              },
            ],
          },
          { text: 'Photos' },
          { text: 'Videos' },
        ],
        checked: [],
      }
    },
    methods: {
      onCheckNode() {
        this.checked = this.$refs.tree.getChecked().map((v) => v.data.text)
      },
    },
  }
</script>

@phphe phphe closed this as completed Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants