@bl33dz/fa814698dcde12f86a37ac31dd3aedf9 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/perisai-ui.es.js +1477 -1414
- package/dist/perisai-ui.umd.js +1 -1
- package/env.d.ts +5 -0
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/ui/tree/index.ts +1 -0
- package/src/ui/tree/tree-node.vue +57 -0
- package/src/ui/tree/tree.vue +43 -0
package/env.d.ts
ADDED
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -6,8 +6,8 @@ import './globals.css'
|
|
|
6
6
|
export * from './shadcn/breadcrumb';
|
|
7
7
|
export * from './shadcn/accordion';
|
|
8
8
|
export * from './shadcn/spinner';
|
|
9
|
-
export * from './shadcn/tree';
|
|
10
9
|
|
|
10
|
+
export * from './ui/tree';
|
|
11
11
|
export { default as InputOTP } from './ui/InputOTP.vue';
|
|
12
12
|
export { default as InputOTPGroup } from './ui/InputOTPGroup.vue';
|
|
13
13
|
export { default as InputOTPSeparator } from './ui/InputOTPSeparator.vue';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Tree } from './tree.vue';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from "vue"
|
|
3
|
+
|
|
4
|
+
const props = defineProps<{
|
|
5
|
+
node: any
|
|
6
|
+
level: number
|
|
7
|
+
expandedIds: Array<string | number>
|
|
8
|
+
}>()
|
|
9
|
+
|
|
10
|
+
const emit = defineEmits<{
|
|
11
|
+
(e: "toggle", id: string | number): void
|
|
12
|
+
(e: "nodeClick", node: any): void
|
|
13
|
+
}>()
|
|
14
|
+
|
|
15
|
+
const isExpanded = computed(() => props.expandedIds.includes(props.node.id))
|
|
16
|
+
|
|
17
|
+
const handleClick = () => {
|
|
18
|
+
emit("toggle", props.node.id)
|
|
19
|
+
emit("nodeClick", props.node)
|
|
20
|
+
}
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<template>
|
|
24
|
+
<li>
|
|
25
|
+
<button
|
|
26
|
+
type="button"
|
|
27
|
+
class="flex w-full items-center gap-1 px-2 py-1 text-xs text-slate-200 hover:bg-slate-800/80 rounded-md transition-colors"
|
|
28
|
+
:style="{ paddingLeft: `${8 + level * 12}px` }"
|
|
29
|
+
@click="handleClick"
|
|
30
|
+
>
|
|
31
|
+
<span
|
|
32
|
+
v-if="node.children?.length"
|
|
33
|
+
class="inline-flex w-3 justify-center text-muted-foreground transition-transform duration-200"
|
|
34
|
+
:class="isExpanded ? 'rotate-90' : 'rotate-0'"
|
|
35
|
+
>
|
|
36
|
+
▶
|
|
37
|
+
</span>
|
|
38
|
+
|
|
39
|
+
<span class="truncate">{{ node.title }}</span>
|
|
40
|
+
</button>
|
|
41
|
+
|
|
42
|
+
<ul
|
|
43
|
+
v-if="isExpanded && node.children?.length"
|
|
44
|
+
class="ml-4 mt-0.5 space-y-0.5 pl-2"
|
|
45
|
+
>
|
|
46
|
+
<TreeNode
|
|
47
|
+
v-for="child in node.children"
|
|
48
|
+
:key="child.id"
|
|
49
|
+
:node="child"
|
|
50
|
+
:level="level + 1"
|
|
51
|
+
:expanded-ids="expandedIds"
|
|
52
|
+
@toggle="emit('toggle', $event)"
|
|
53
|
+
@nodeClick="emit('nodeClick', $event)"
|
|
54
|
+
/>
|
|
55
|
+
</ul>
|
|
56
|
+
</li>
|
|
57
|
+
</template>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref } from "vue"
|
|
3
|
+
import TreeNode from "./tree-node.vue"
|
|
4
|
+
|
|
5
|
+
export interface TreeItem {
|
|
6
|
+
id: string | number
|
|
7
|
+
title: string
|
|
8
|
+
icon?: any
|
|
9
|
+
children?: TreeItem[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const props = defineProps<{
|
|
13
|
+
items: TreeItem[]
|
|
14
|
+
}>()
|
|
15
|
+
|
|
16
|
+
const emit = defineEmits<{
|
|
17
|
+
(e: "nodeClick", node: TreeItem): void
|
|
18
|
+
}>()
|
|
19
|
+
|
|
20
|
+
const expandedIds = ref<Array<string | number>>([])
|
|
21
|
+
|
|
22
|
+
const toggleNode = (id: string | number) => {
|
|
23
|
+
const list = expandedIds.value.slice()
|
|
24
|
+
const idx = list.indexOf(id)
|
|
25
|
+
if (idx >= 0) list.splice(idx, 1)
|
|
26
|
+
else list.push(id)
|
|
27
|
+
expandedIds.value = list
|
|
28
|
+
}
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<template>
|
|
32
|
+
<ul class="space-y-0.5">
|
|
33
|
+
<TreeNode
|
|
34
|
+
v-for="node in items"
|
|
35
|
+
:key="node.id"
|
|
36
|
+
:node="node"
|
|
37
|
+
:level="0"
|
|
38
|
+
:expanded-ids="expandedIds"
|
|
39
|
+
@toggle="toggleNode"
|
|
40
|
+
@nodeClick="emit('nodeClick', $event)"
|
|
41
|
+
/>
|
|
42
|
+
</ul>
|
|
43
|
+
</template>
|