Skip to content

Commit 35b0cba

Browse files
committed
feat(TreeSelect): Base Support
1 parent 9a69fbb commit 35b0cba

File tree

5 files changed

+113
-1
lines changed

5 files changed

+113
-1
lines changed

src/components/app/AppTopbar.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ const items = ref([
5858
{ label: 'Dropdown', icon: 'pi pi-fw pi-user-edit', route: '/demo/dropdown' },
5959
{ label: 'Listbox', icon: 'pi pi-fw pi-user-edit', route: '/demo/listbox' },
6060
{ label: 'MultiSelect', icon: 'pi pi-fw pi-user-edit', route: '/demo/multiSelect' },
61+
{ label: 'RadioButton', icon: 'pi pi-fw pi-user-edit', route: '/demo/radioButton' },
6162
{ label: 'SelectButton', icon: 'pi pi-fw pi-user-edit', route: '/demo/selectButton' },
6263
{ label: 'ToggleButton', icon: 'pi pi-fw pi-user-edit', route: '/demo/toggleButton' },
63-
{ label: 'RadioButton', icon: 'pi pi-fw pi-user-edit', route: '/demo/radioButton' },
64+
{ label: 'TreeSelect', icon: 'pi pi-fw pi-user-edit', route: '/demo/treeSelect' },
6465
],
6566
},
6667
{

src/formkit/PrimeTreeSelect.vue

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script setup lang='ts'>
2+
const props = defineProps({
3+
context: Object,
4+
})
5+
6+
const context = props.context
7+
const attrs = computed(() => context?.attrs)
8+
9+
function handleInput(e: any) {
10+
context?.node.input(props.context?._value)
11+
}
12+
13+
const styleClass = computed(() => (context?.state.validationVisible && !context?.state.valid) ? `${attrs.value?.class} p-invalid` : attrs.value?.class)
14+
</script>
15+
16+
<template>
17+
<div class="p-formkit">
18+
<TreeSelect
19+
v-model="context._value"
20+
:input-id="context.id"
21+
:disabled="attrs._disabled ?? false"
22+
:readonly="attrs._readonly ?? false"
23+
:input-style="attrs.style"
24+
:input-class="styleClass"
25+
:tabindex="attrs.tabindex"
26+
:aria-label="attrs.ariaLabel"
27+
:aria-labelledby="attrs.ariaLabelledby"
28+
:options="attrs?.options"
29+
:placeholder="attrs.placeholder"
30+
:selection-mode="attrs.selectionMode"
31+
:pt="attrs.pt"
32+
:pt-options="attrs.ptOptions"
33+
:unstyled="attrs.unstyled ?? false"
34+
@change="handleInput"
35+
/>
36+
</div>
37+
</template>

src/formkit/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import PrimeRadioButton from './PrimeRadioButton.vue'
2222
import PrimeRating from './PrimeRating.vue'
2323
import PrimeSlider from './PrimeSlider.vue'
2424
import PrimeToggleButton from './PrimeToggleButton.vue'
25+
import PrimeTreeSelect from './PrimeTreeSelect.vue'
2526
import PrimeSelectButton from './PrimeSelectButton.vue'
2627
import PrimeTriStateCheckbox from './PrimeTriStateCheckbox.vue'
2728

@@ -112,6 +113,9 @@ export const primeTriStateCheckboxDefinition: FormKitTypeDefinition = createInpu
112113
export const primeCascadeSelectDefinition: FormKitTypeDefinition = createInput(PrimeCascadeSelect, {
113114
props: [],
114115
})
116+
export const primeTreeSelectDefinition: FormKitTypeDefinition = createInput(PrimeTreeSelect, {
117+
props: [],
118+
})
115119

116120
export const primeInputs = {
117121
primeAutoComplete: primeAutoCompleteDefinition,
@@ -137,4 +141,5 @@ export const primeInputs = {
137141
primeSelectButton: primeSelectButtonDefinition,
138142
primeTriStateCheckbox: primeTriStateCheckboxDefinition,
139143
primeCascadeSelect: primeCascadeSelectDefinition,
144+
primeTreeSelect: primeTreeSelectDefinition,
140145
}

src/modules/primevue.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import TabPanel from 'primevue/tabpanel'
7575
import ToggleButton from 'primevue/togglebutton'
7676
import Tree from 'primevue/tree'
7777
import TreeTable from 'primevue/treetable'
78+
import TreeSelect from 'primevue/treeselect'
7879
import TriStateCheckbox from 'primevue/tristatecheckbox'
7980

8081
import 'primevue/resources/primevue.min.css'
@@ -181,6 +182,7 @@ export const install: UserModule = ({ app, router, isClient }) => {
181182
app.component('ToggleButton', ToggleButton)
182183
app.component('Tree', Tree)
183184
app.component('TreeTable', TreeTable)
185+
app.component('TreeSelect', TreeSelect)
184186
app.component('TriStateCheckbox', TriStateCheckbox)
185187

186188
app.use(PrimeVue, { ripple: false })

src/pages/demo/TreeSelect.vue

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<script setup lang='ts'>
2+
import PrimeInput from '@/components/demo/PrimeInput.vue'
3+
4+
const primeAttributes = 'placeholder, options'
5+
6+
const options = ref([
7+
{
8+
key: '0',
9+
label: 'Documents',
10+
data: 'Documents Folder',
11+
icon: 'pi pi-fw pi-inbox',
12+
children: [
13+
{
14+
key: '0-0',
15+
label: 'Work',
16+
data: 'Work Folder',
17+
icon: 'pi pi-fw pi-cog',
18+
children: [
19+
{ key: '0-0-0', label: 'Expenses.doc', icon: 'pi pi-fw pi-file', data: 'Expenses Document' },
20+
{ key: '0-0-1', label: 'Resume.doc', icon: 'pi pi-fw pi-file', data: 'Resume Document' },
21+
],
22+
},
23+
{
24+
key: '0-1',
25+
label: 'Home',
26+
data: 'Home Folder',
27+
icon: 'pi pi-fw pi-home',
28+
children: [{ key: '0-1-0', label: 'Invoices.txt', icon: 'pi pi-fw pi-file', data: 'Invoices for this month' }],
29+
},
30+
],
31+
},
32+
{
33+
key: '1',
34+
label: 'Events',
35+
data: 'Events Folder',
36+
icon: 'pi pi-fw pi-calendar',
37+
children: [
38+
{ key: '1-0', label: 'Meeting', icon: 'pi pi-fw pi-calendar-plus', data: 'Meeting' },
39+
{ key: '1-1', label: 'Product Launch', icon: 'pi pi-fw pi-calendar-plus', data: 'Product Launch' },
40+
{ key: '1-2', label: 'Report Review', icon: 'pi pi-fw pi-calendar-plus', data: 'Report Review' },
41+
],
42+
},
43+
])
44+
45+
const schema
46+
= [
47+
{
48+
$formkit: 'primeTreeSelect',
49+
name: 'treeSelectValue',
50+
label: 'Tree Select',
51+
selectionMode: 'multiple',
52+
options,
53+
placeholder: 'Make your selection',
54+
},
55+
]
56+
57+
const data = { }
58+
</script>
59+
60+
<template>
61+
<div>
62+
<PrimeInput
63+
header="TreeSelect" :schema="schema" :data="data"
64+
:prime-attributes="primeAttributes"
65+
/>
66+
</div>
67+
</template>

0 commit comments

Comments
 (0)