Skip to content

Commit

Permalink
use the new internal render api (Vue)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinMalfait committed Apr 4, 2021
1 parent 14a88aa commit afb7ffc
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export let Description = defineComponent({
slot: this.slot,
attrs: this.$attrs,
slots: this.$slots,
name: 'Description',
})
},
setup() {
Expand Down
3 changes: 3 additions & 0 deletions packages/@headlessui-vue/src/components/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export let Dialog = defineComponent({
slots: this.$slots,
visible: open,
features: Features.RenderStrategy | Features.Static,
name: 'Dialog',
}),
]),
]),
Expand Down Expand Up @@ -297,6 +298,7 @@ export let DialogOverlay = defineComponent({
slot: { open: api.dialogState.value === DialogStates.Open },
attrs: this.$attrs,
slots: this.$slots,
name: 'DialogOverlay',
})
},
setup() {
Expand Down Expand Up @@ -329,6 +331,7 @@ export let DialogTitle = defineComponent({
slot: { open: api.dialogState.value === DialogStates.Open },
attrs: this.$attrs,
slots: this.$slots,
name: 'DialogTitle',
})
},
setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export let Disclosure = defineComponent({

return () => {
let slot = { open: disclosureState.value === DisclosureStates.Open }
return render({ props: passThroughProps, slot, slots, attrs })
return render({ props: passThroughProps, slot, slots, attrs, name: 'Disclosure' })
}
},
})
Expand Down Expand Up @@ -94,6 +94,7 @@ export let DisclosureButton = defineComponent({
slot,
attrs: this.$attrs,
slots: this.$slots,
name: 'DisclosureButton',
})
},
setup(props) {
Expand Down Expand Up @@ -145,6 +146,7 @@ export let DisclosurePanel = defineComponent({
slots: this.$slots,
features: Features.RenderStrategy | Features.Static,
visible: slot.open,
name: 'DisclosurePanel',
})
},
setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export let FocusTrap = defineComponent({
slot,
attrs: this.$attrs,
slots: this.$slots,
name: 'FocusTrap',
})
},
setup(props) {
Expand Down
1 change: 1 addition & 0 deletions packages/@headlessui-vue/src/components/label/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export let Label = defineComponent({
slot: {},
attrs: this.$attrs,
slots: this.$slots,
name: 'Label',
})
},
setup() {
Expand Down
13 changes: 11 additions & 2 deletions packages/@headlessui-vue/src/components/listbox/listbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export let Listbox = defineComponent({

return () => {
let slot = { open: listboxState.value === ListboxStates.Open, disabled }
return render({ props: passThroughProps, slot, slots, attrs })
return render({ props: passThroughProps, slot, slots, attrs, name: 'Listbox' })
}
},
})
Expand All @@ -218,6 +218,7 @@ export let ListboxLabel = defineComponent({
slot,
attrs: this.$attrs,
slots: this.$slots,
name: 'ListboxLabel',
})
},
setup() {
Expand Down Expand Up @@ -265,6 +266,7 @@ export let ListboxButton = defineComponent({
slot,
attrs: this.$attrs,
slots: this.$slots,
name: 'ListboxButton',
})
},
setup() {
Expand Down Expand Up @@ -347,6 +349,7 @@ export let ListboxOptions = defineComponent({
slots: this.$slots,
features: Features.RenderStrategy | Features.Static,
visible: slot.open,
name: 'ListboxOptions',
})
},
setup() {
Expand Down Expand Up @@ -520,7 +523,13 @@ export let ListboxOption = defineComponent({
onMouseleave: handleLeave,
}

return render({ props: { ...props, ...propsWeControl }, slot, attrs, slots })
return render({
props: { ...props, ...propsWeControl },
slot,
attrs,
slots,
name: 'ListboxOption',
})
}
},
})
85 changes: 77 additions & 8 deletions packages/@headlessui-vue/src/components/menu/menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,20 @@ describe('Rendering', () => {
</MenuItems>
</Menu>
`)
).toThrowErrorMatchingInlineSnapshot(
`"You should only render 1 child or use the \`as=\\"...\\"\` prop"`
).toThrowError(
new Error(
[
'Passing props on "Fragment"!',
'',
'The current component <Menu /> is rendering a "Fragment".',
'However we need to passthrough the following props:',
' - class',
'',
'You can apply a few solutions:',
' - Add an `as="..."` prop, to ensure that we render an actual element instead of a "Fragment".',
' - Render a single element as the child so that we can forward the props onto that element.',
].join('\n')
)
)
})
)
Expand Down Expand Up @@ -289,8 +301,28 @@ describe('Rendering', () => {
</MenuItems>
</Menu>
`)
).toThrowErrorMatchingInlineSnapshot(
`"You should only render 1 child or use the \`as=\\"...\\"\` prop"`
).toThrowError(
new Error(
[
'Passing props on "Fragment"!',
'',
'The current component <MenuButton /> is rendering a "Fragment".',
'However we need to passthrough the following props:',
' - disabled',
' - ref',
' - id',
' - type',
' - aria-haspopup',
' - aria-controls',
' - aria-expanded',
' - onKeydown',
' - onClick',
'',
'You can apply a few solutions:',
' - Add an `as="..."` prop, to ensure that we render an actual element instead of a "Fragment".',
' - Render a single element as the child so that we can forward the props onto that element.',
].join('\n')
)
)
})
)
Expand Down Expand Up @@ -370,8 +402,24 @@ describe('Rendering', () => {
</Menu>
`,
errorCaptured(err: unknown) {
expect((err as Error).message).toMatchInlineSnapshot(
`"You should only render 1 child or use the \`as=\\"...\\"\` prop"`
expect((err as Error).message).toEqual(
[
'Passing props on "Fragment"!',
'',
'The current component <MenuItems /> is rendering a "Fragment".',
'However we need to passthrough the following props:',
' - aria-activedescendant',
' - aria-labelledby',
' - id',
' - onKeydown',
' - role',
' - tabIndex',
' - ref',
'',
'You can apply a few solutions:',
' - Add an `as="..."` prop, to ensure that we render an actual element instead of a "Fragment".',
' - Render a single element as the child so that we can forward the props onto that element.',
].join('\n')
)
return false
},
Expand Down Expand Up @@ -517,8 +565,29 @@ describe('Rendering', () => {
</Menu>
`,
errorCaptured(err: unknown) {
expect((err as Error).message).toMatchInlineSnapshot(
`"You should only render 1 child or use the \`as=\\"...\\"\` prop"`
expect((err as Error).message).toEqual(
[
'Passing props on "Fragment"!',
'',
'The current component <MenuItem /> is rendering a "Fragment".',
'However we need to passthrough the following props:',
' - disabled',
' - id',
' - role',
' - tabIndex',
' - class',
' - aria-disabled',
' - onClick',
' - onFocus',
' - onPointermove',
' - onMousemove',
' - onPointerleave',
' - onMouseleave',
'',
'You can apply a few solutions:',
' - Add an `as="..."` prop, to ensure that we render an actual element instead of a "Fragment".',
' - Render a single element as the child so that we can forward the props onto that element.',
].join('\n')
)

return false
Expand Down
16 changes: 14 additions & 2 deletions packages/@headlessui-vue/src/components/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function useMenuContext(component: string) {
}

export let Menu = defineComponent({
name: 'Menu',
props: { as: { type: [Object, String], default: 'template' } },
setup(props, { slots, attrs }) {
let menuState = ref<StateDefinition['menuState']['value']>(MenuStates.Closed)
Expand Down Expand Up @@ -154,12 +155,13 @@ export let Menu = defineComponent({

return () => {
let slot = { open: menuState.value === MenuStates.Open }
return render({ props, slot, slots, attrs })
return render({ props, slot, slots, attrs, name: 'Menu' })
}
},
})

export let MenuButton = defineComponent({
name: 'MenuButton',
props: {
disabled: { type: Boolean, default: false },
as: { type: [Object, String], default: 'button' },
Expand All @@ -184,6 +186,7 @@ export let MenuButton = defineComponent({
slot,
attrs: this.$attrs,
slots: this.$slots,
name: 'MenuButton',
})
},
setup(props) {
Expand Down Expand Up @@ -241,6 +244,7 @@ export let MenuButton = defineComponent({
})

export let MenuItems = defineComponent({
name: 'MenuItems',
props: {
as: { type: [Object, String], default: 'div' },
static: { type: Boolean, default: false },
Expand Down Expand Up @@ -271,6 +275,7 @@ export let MenuItems = defineComponent({
slots: this.$slots,
features: Features.RenderStrategy | Features.Static,
visible: slot.open,
name: 'MenuItems',
})
},
setup() {
Expand Down Expand Up @@ -369,6 +374,7 @@ export let MenuItems = defineComponent({
})

export let MenuItem = defineComponent({
name: 'MenuItem',
props: {
as: { type: [Object, String], default: 'template' },
disabled: { type: Boolean, default: false },
Expand Down Expand Up @@ -443,7 +449,13 @@ export let MenuItem = defineComponent({
onMouseleave: handleLeave,
}

return render({ props: { ...props, ...propsWeControl }, slot, attrs, slots })
return render({
props: { ...props, ...propsWeControl },
slot,
attrs,
slots,
name: 'MenuItem',
})
}
},
})
6 changes: 5 additions & 1 deletion packages/@headlessui-vue/src/components/popover/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export let Popover = defineComponent({

return () => {
let slot = { open: popoverState.value === PopoverStates.Open }
return render({ props: passThroughProps, slot, slots, attrs })
return render({ props: passThroughProps, slot, slots, attrs, name: 'Popover' })
}
},
})
Expand Down Expand Up @@ -207,6 +207,7 @@ export let PopoverButton = defineComponent({
slot,
attrs: this.$attrs,
slots: this.$slots,
name: 'PopoverButton',
})
},
setup(props) {
Expand Down Expand Up @@ -371,6 +372,7 @@ export let PopoverOverlay = defineComponent({
slots: this.$slots,
features: Features.RenderStrategy | Features.Static,
visible: slot.open,
name: 'PopoverOverlay',
})
},
setup() {
Expand Down Expand Up @@ -412,6 +414,7 @@ export let PopoverPanel = defineComponent({
slots: this.$slots,
features: Features.RenderStrategy | Features.Static,
visible: slot.open,
name: 'PopoverPanel',
})
},
setup(props) {
Expand Down Expand Up @@ -523,6 +526,7 @@ export let PopoverGroup = defineComponent({
slot: {},
attrs: this.$attrs,
slots: this.$slots,
name: 'PopoverGroup',
})
},
setup() {
Expand Down
4 changes: 2 additions & 2 deletions packages/@headlessui-vue/src/components/portal/portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export let Portal = defineComponent({
if (myTarget.value === null) return null
return h(StackProvider, {}, () => [
h(Teleport, { to: myTarget.value }, [
h('div', { ref: element }, [render({ props, slot: {}, attrs, slots })]),
h('div', { ref: element }, [render({ props, slot: {}, attrs, slots, name: 'Portal' })]),
]),
])
}
Expand Down Expand Up @@ -98,7 +98,7 @@ export let PortalGroup = defineComponent({
return () => {
let { target: _, ...passThroughProps } = props

return render({ props: passThroughProps, slot: {}, attrs, slots })
return render({ props: passThroughProps, slot: {}, attrs, slots, name: 'PortalGroup' })
}
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export let RadioGroup = defineComponent({
slot: {},
attrs: this.$attrs,
slots: this.$slots,
name: 'RadioGroup',
}),
]),
])
Expand Down Expand Up @@ -264,6 +265,7 @@ export let RadioGroupOption = defineComponent({
slot,
attrs: this.$attrs,
slots: this.$slots,
name: 'RadioGroupOption',
}),
]),
])
Expand Down
Loading

0 comments on commit afb7ffc

Please sign in to comment.