Skip to content

Commit

Permalink
docs(tree-list): misc fixes [KHCP-9008]
Browse files Browse the repository at this point in the history
  • Loading branch information
portikM committed Mar 14, 2024
1 parent d9dc5f0 commit 86d1b39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 56 deletions.
47 changes: 0 additions & 47 deletions docs/components/tree-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,45 +277,6 @@ Two separate `child-change` events will fire if an item is moved from one parent

Emitted when you click (and don't drag) an item. Returns the selected item's data.

<div class="vertical-container">
<KLabel>Selected: {{ mySelection && mySelection.name || '' }}</KLabel>
<KLabel>Items:</KLabel>
<pre class="json hide-from-percy">{{ JSON.stringify(eventItems, null, 2) }}</pre>
<KTreeList
:items="eventItems"
@selected="(item) => mySelection = item"
@change="({ items }) => eventItems = items"
@child-change="handleChildChange"
/>
</div>

```vue
<template>
<KLabel>Selected: {{ mySelection && mySelection.name || '' }}</KLabel>
<KLabel>Items: </KLabel> {{ myItems }}
<KTreeList
:items="myItems"
@selected="(item) => mySelection = item"
@change="({ items }) => myItems = items"
@child-change="handleChildChange"
/>
</template>
<script setup lang="ts">
import type { TreeListItem } from '@kong/kongponents'
...
const mySelection = ref<TreeListItem | null>(null)
const handleChildChange = (data): void => {
const { parentId, children, target } = data
const changedParent = myItems.value.find(item => item.id === parentId)
changedParent.children = children
}
</script>
```

<script setup lang="ts">
import { ref } from 'vue'
import { InboxIcon, DataObjectIcon } from '@kong/icons'
Expand Down Expand Up @@ -390,17 +351,9 @@ const hideIconsItems = ref<TreeListItem[]>(JSON.parse(JSON.stringify(items)))

const slotItems = ref<TreeListItem[]>(JSON.parse(JSON.stringify(items)))

const eventItems = ref<TreeListItem[]>(JSON.parse(JSON.stringify(items)))

const reset = (): void => {
myList.value = JSON.parse(JSON.stringify(items))
}

const handleChildChange = (data): void => {
const { parentId, children, target } = data
const changedParent = eventItems.value.find(item => item.id === parentId)
changedParent.children = children
}
</script>

<style lang="scss" scoped>
Expand Down
26 changes: 17 additions & 9 deletions sandbox/pages/SandboxTreeList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@
title="Props"
/>
<SandboxSectionComponent title="item">
<KTreeList :items="items" />
<KTreeList :items="items1" />
</SandboxSectionComponent>
<SandboxSectionComponent title="disableDrag">
<KTreeList
disable-drag
:items="items"
:items="items2"
/>
</SandboxSectionComponent>
<SandboxSectionComponent title="maxDepth">
<KTreeList
:items="items"
:items="items3"
:max-depth="4"
/>
</SandboxSectionComponent>
<SandboxSectionComponent title="width">
<KTreeList
:items="items"
:items="items4"
width="300"
/>
</SandboxSectionComponent>
<SandboxSectionComponent title="hideIcons">
<KTreeList
hide-icons
:items="items"
:items="items5"
/>
</SandboxSectionComponent>

Expand All @@ -49,7 +49,7 @@
title="Slots"
/>
<SandboxSectionComponent title="item-icon">
<KTreeList :items="items">
<KTreeList :items="items6">
<template #item-icon="{ item }">
<InboxIcon
v-if="item.id.includes('folder')"
Expand All @@ -59,7 +59,7 @@
</KTreeList>
</SandboxSectionComponent>
<SandboxSectionComponent title="item-label">
<KTreeList :items="items">
<KTreeList :items="items7">
<template #item-label="{ item }">
<span v-if="item.id.includes('folder')">
<strong>{{ item.name }}</strong>
Expand All @@ -82,7 +82,7 @@ import type { TreeListItem } from '@/types'
import { InboxIcon } from '@kong/icons'
import { KUI_COLOR_TEXT_DECORATIVE_PURPLE, KUI_COLOR_TEXT_DECORATIVE_PURPLE_STRONG } from '@kong/design-tokens'
const items = ref<TreeListItem[]>([
const defaultItems = [
{
name: 'Components',
id: 'components-folder',
Expand Down Expand Up @@ -129,5 +129,13 @@ const items = ref<TreeListItem[]>([
id: 'user-types',
}],
},
])
]
const items1 = ref<TreeListItem[]>(JSON.parse(JSON.stringify(defaultItems)))
const items2 = ref<TreeListItem[]>(JSON.parse(JSON.stringify(defaultItems)))
const items3 = ref<TreeListItem[]>(JSON.parse(JSON.stringify(defaultItems)))
const items4 = ref<TreeListItem[]>(JSON.parse(JSON.stringify(defaultItems)))
const items5 = ref<TreeListItem[]>(JSON.parse(JSON.stringify(defaultItems)))
const items6 = ref<TreeListItem[]>(JSON.parse(JSON.stringify(defaultItems)))
const items7 = ref<TreeListItem[]>(JSON.parse(JSON.stringify(defaultItems)))
</script>

0 comments on commit 86d1b39

Please sign in to comment.