Skip to content

Commit eb11fde

Browse files
committed
feat(useFormKitSchema): allow also boolean value for render
1 parent 55fde26 commit eb11fde

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/composables/useFormKitSchema.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
export function useFormKitSchema() {
2-
const addComponent = (component: string = 'Button', props: object = {}, render: string = 'true', formKitAttrs: object = {}): object => {
2+
const addComponent = (component: string = 'Button', props: object = {}, render: string | boolean = true, formKitAttrs: object = {}): object => {
33
return {
44
$cmp: component,
5-
if: render,
5+
if: render.toString(),
66
props,
77
...formKitAttrs,
88
}
99
}
1010

11-
const addElement = (element: string = 'div', children: any[] | string = [], attrs: object = {}, render: string = 'true', formKitAttrs: object = {}) => {
11+
const addElement = (element: string = 'div', children: any[] | string = [], attrs: object = {}, render: string | boolean = true, formKitAttrs: object = {}) => {
1212
return {
1313
$el: element,
14-
if: render,
14+
if: render.toString(),
1515
attrs,
1616
children,
1717
...formKitAttrs,
1818
}
1919
}
2020

21-
const addGroup = (name: string, children: object[] = [], render: string = 'true', formKitAttrs: object = {}) => {
21+
const addGroup = (name: string, children: object[] = [], render: string | boolean = true, formKitAttrs: object = {}) => {
2222
return {
2323
$formkit: 'group',
24-
if: render,
24+
if: render.toString(),
2525
name,
2626
children,
2727
...formKitAttrs,
2828
}
2929
}
3030

31-
const addList = (name: string, children: object[], dynamic: boolean = true, render: string = 'true', formKitAttrs: object = {}) => {
31+
const addList = (name: string, children: object[] = [], dynamic: boolean = true, render: string | boolean = true, formKitAttrs: object = {}) => {
3232
return {
3333
$formkit: 'list',
34-
if: render,
34+
if: render.toString(),
3535
name,
3636
dynamic,
3737
children,
3838
...formKitAttrs,
3939
}
4040
}
4141

42-
const addListGroup = (children: object[] = [], render: string = 'true', formKitAttrs: object = {}) => {
42+
const addListGroup = (children: object[] = [], render: string | boolean = true, formKitAttrs: object = {}) => {
4343
return {
4444
$formkit: 'group',
45-
if: render,
45+
if: render.toString(),
4646
for: ['item', 'index', '$items'], // 👈 $items is in the slot’s scope
4747
key: '$item',
4848
index: '$index',
@@ -51,7 +51,7 @@ export function useFormKitSchema() {
5151
}
5252
}
5353

54-
const addElementsInOuterDiv = (children: object[] = [], innerClass: string = '', outerClass: string = '', label: string = '', help: string = '', render: string = 'true') => {
54+
const addElementsInOuterDiv = (children: object[] = [], innerClass: string = '', outerClass: string = '', label: string = '', help: string = '', render: string | boolean = true) => {
5555
const inner = addElement('div', children, { class: `formkit-inner ${innerClass}`, style: 'position: relative;' })
5656
const labelDiv = addElement('label', [label], { class: 'formkit-label' })
5757
const wrapperDiv = addElement('div', [labelDiv, inner], { class: 'formkit-wrapper' })

test/useFormKitSchema.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ it('add element', () => {
1717
expect(e2.$el).toBe('span')
1818
expect(renderToBoolean(e2)).toBe(false)
1919
expect(e2.children?.length).toBe(1)
20+
// @ts-expect-error: name is not in the type`
2021
expect(e2.attrs?.name).toBe('test')
2122
})
2223

2324
it('add component', () => {
2425
const { addComponent } = useFormKitSchema()
2526

2627
const component = addComponent()
28+
// @ts-expect-error: $cmp is not in the type
2729
expect(component.$cmp).toBe('Button')
2830
expect(renderToBoolean(component)).toBe(true)
2931
})

0 commit comments

Comments
 (0)