Skip to content

Commit 73ce845

Browse files
committed
feat(demo): add schema based repeater demo
1 parent ce10c14 commit 73ce845

File tree

5 files changed

+99
-4
lines changed

5 files changed

+99
-4
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import { primeInputs } from '@sfxcode/formkit-primevue'
2323
}))
2424
```
2525

26+
### Schema Helper Functions
27+
28+
[useFormKitSchema](https://github.com/sfxcode/formkit-primevue/blob/main/src/composables/useFormKitSchema.ts) provide functions to simplify the usage of elements, components, lists, ...
29+
30+
2631
### Basic Styling
2732

2833
Basic styling is provided with the **formkit-primevue.scss** file.
@@ -40,7 +45,14 @@ You can use it or take it as base for your own styling.
4045
- All inputs are wrapped in a div with a **p-formkit** class
4146
- Most Prime Components have access to class / styles attributes
4247
- PT and PTOptions are available ([https://primevue.org/passthrough/](https://primevue.org/passthrough/))
43-
- [Styling](https://formkit-primevue.netlify.app/demo/styling), [Grid](https://formkit-primevue.netlify.app/demo/grid) and [PT](https://formkit-primevue.netlify.app/demo/passThrough) demo available
48+
- [Styling](https://formkit-primevue.netlify.app/demo/styling) and [PT](https://formkit-primevue.netlify.app/demo/passThrough) demo available
49+
50+
### Samples
51+
52+
Some samples for common tasks are available
53+
54+
- Repeater (with the help of the useFormKitSchema compsable)
55+
- Grid
4456

4557
## Showcases
4658

@@ -50,9 +62,11 @@ You can use it or take it as base for your own styling.
5062

5163
## Supported Inputs
5264

65+
- AutoComplete
5366
- Calendar
5467
- CascadeSelect
5568
- Checkbox
69+
- Chips
5670
- Dropdown
5771
- Editor (HTML Editor)
5872
- InputMask
@@ -63,7 +77,6 @@ You can use it or take it as base for your own styling.
6377
- MultiSelect
6478
- Password
6579
- Ranking
66-
- Chips
6780
- Knob
6881
- ColorPicker
6982
- Listbox

dev/components/app/AppTopbar.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const items = ref([
9595
label: 'Samples',
9696
items: [
9797
{ label: 'Grid', icon: 'pi pi-fw pi-user-edit', route: '/samples/grid' },
98+
{ label: 'Repeater', icon: 'pi pi-fw pi-user-edit', route: '/samples/repeater' },
9899
],
99100
},
100101
],

dev/components/demo/PrimeInput.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async function submitHandler() {
3737
{{ header }}
3838
</h2>
3939
<slot />
40-
<div class="flex flex-wrap gap-12">
40+
<div class="flex flex-wrap gap-8">
4141
<div class="min-w-30rem basis-1/3 md:basis-1/4">
4242
<FormKit
4343
id="form"

dev/pages/samples/Repeater.vue

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<script setup lang='ts'>
2+
import { useFormKitSchema } from 'my-library'
3+
4+
const { addElement, addList, addListGroup, addComponent, addListGroupFunctions } = useFormKitSchema()
5+
function addFlexElement(children: any[]) {
6+
return addElement('div', children, { class: 'min-w-40rem flex gap-4' })
7+
}
8+
9+
function addGroupButtons() {
10+
const addButtonComponent = (onClick: string = '', label: string = '', icon: string = '', severity: string = '', render: string = 'true', styleClass: string = 'p-button-sm ml-2'): object => {
11+
return addComponent('Button', { onClick, label, icon, class: styleClass, severity }, render)
12+
}
13+
14+
return addElement('div', [
15+
addButtonComponent('$removeNode($node, $index)', '', 'pi pi-times', 'danger'),
16+
addButtonComponent('$copyNode($node, $index)', '', 'pi pi-plus'),
17+
addButtonComponent('$moveNodeUp($node, $index)', '', 'pi pi-arrow-up', 'secondary', '$index != 0'),
18+
addElement('span', [], { class: 'ml-2 mr-10' }, '$index == 0'),
19+
addButtonComponent('$moveNodeDown($node, $index)', '', 'pi pi-arrow-down', 'secondary', '$index < $node.value.length -1'),
20+
addElement('span', [], { class: 'ml-2 mr-10' }, '$index == $node.value.length -1'),
21+
], { class: 'pt-6' })
22+
}
23+
24+
const data = ref()
25+
26+
function createDefaultValue(): object {
27+
return { name: 'Sword', damage: '2D20' }
28+
}
29+
30+
onMounted(() => {
31+
const defaultData = { name: 'Fighter', attacks: [{ name: 'Sword', damage: '2D20' }, { name: 'Dagger', damage: '2D6' }] }
32+
addListGroupFunctions(defaultData, createDefaultValue())
33+
data.value = defaultData
34+
})
35+
36+
const schema
37+
= [
38+
{
39+
$formkit: 'primeInputText',
40+
label: 'Name',
41+
name: 'name',
42+
},
43+
addElement('hr', [], { class: 'mt-4 mb-4' }),
44+
addList('attacks', [
45+
addFlexElement([
46+
addElement('div', ['Attacks'], { class: 'text-xl mb-2' }),
47+
addComponent('Button', { onClick: '$addNode($node)', label: 'Add', class: 'p-button-sm', icon: 'pi pi-plus' }, '$node.value.length == 0'),
48+
]),
49+
addListGroup(
50+
[
51+
addFlexElement([
52+
{
53+
$formkit: 'primeInputText',
54+
label: 'Name',
55+
name: 'name',
56+
},
57+
{
58+
$formkit: 'primeInputText',
59+
label: 'Damage',
60+
name: 'damage',
61+
style: 'width:70px;',
62+
},
63+
addGroupButtons(),
64+
]),
65+
],
66+
),
67+
], true, 'true'),
68+
]
69+
</script>
70+
71+
<template>
72+
<div v-if="data" class="">
73+
<PrimeInput
74+
header="Repeater" :schema="schema" :data="data"
75+
/>
76+
</div>
77+
</template>
78+
79+
<style lang='scss' scoped>
80+
81+
</style>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@sfxcode/formkit-primevue",
33
"type": "module",
4-
"version": "1.9.0",
4+
"version": "1.9.1",
55
"author": {
66
"name": "Tom",
77
"email": "[email protected]"

0 commit comments

Comments
 (0)