VListChildren.mjs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { mergeProps as _mergeProps, resolveDirective as _resolveDirective, createVNode as _createVNode } from "vue";
  2. // Components
  3. import { VListGroup } from "./VListGroup.mjs";
  4. import { VListItem } from "./VListItem.mjs";
  5. import { VListSubheader } from "./VListSubheader.mjs";
  6. import { VDivider } from "../VDivider/index.mjs"; // Utilities
  7. import { createList } from "./list.mjs";
  8. import { genericComponent, propsFactory } from "../../util/index.mjs"; // Types
  9. export const makeVListChildrenProps = propsFactory({
  10. items: Array,
  11. returnObject: Boolean
  12. }, 'VListChildren');
  13. export const VListChildren = genericComponent()({
  14. name: 'VListChildren',
  15. props: makeVListChildrenProps(),
  16. setup(props, _ref) {
  17. let {
  18. slots
  19. } = _ref;
  20. createList();
  21. return () => slots.default?.() ?? props.items?.map(_ref2 => {
  22. let {
  23. children,
  24. props: itemProps,
  25. type,
  26. raw: item
  27. } = _ref2;
  28. if (type === 'divider') {
  29. return slots.divider?.({
  30. props: itemProps
  31. }) ?? _createVNode(VDivider, itemProps, null);
  32. }
  33. if (type === 'subheader') {
  34. return slots.subheader?.({
  35. props: itemProps
  36. }) ?? _createVNode(VListSubheader, itemProps, null);
  37. }
  38. const slotsWithItem = {
  39. subtitle: slots.subtitle ? slotProps => slots.subtitle?.({
  40. ...slotProps,
  41. item
  42. }) : undefined,
  43. prepend: slots.prepend ? slotProps => slots.prepend?.({
  44. ...slotProps,
  45. item
  46. }) : undefined,
  47. append: slots.append ? slotProps => slots.append?.({
  48. ...slotProps,
  49. item
  50. }) : undefined,
  51. title: slots.title ? slotProps => slots.title?.({
  52. ...slotProps,
  53. item
  54. }) : undefined
  55. };
  56. const listGroupProps = VListGroup.filterProps(itemProps);
  57. return children ? _createVNode(VListGroup, _mergeProps({
  58. "value": itemProps?.value
  59. }, listGroupProps), {
  60. activator: _ref3 => {
  61. let {
  62. props: activatorProps
  63. } = _ref3;
  64. const listItemProps = {
  65. ...itemProps,
  66. ...activatorProps,
  67. value: props.returnObject ? item : itemProps.value
  68. };
  69. return slots.header ? slots.header({
  70. props: listItemProps
  71. }) : _createVNode(VListItem, listItemProps, slotsWithItem);
  72. },
  73. default: () => _createVNode(VListChildren, {
  74. "items": children,
  75. "returnObject": props.returnObject
  76. }, slots)
  77. }) : slots.item ? slots.item({
  78. props: itemProps
  79. }) : _createVNode(VListItem, _mergeProps(itemProps, {
  80. "value": props.returnObject ? item : itemProps.value
  81. }), slotsWithItem);
  82. });
  83. }
  84. });
  85. //# sourceMappingURL=VListChildren.mjs.map