formkit / docs-content

The content (.md format) — and only the content — for the FormKit documentation site.
17 stars 28 forks source link

how to populate slots in $cmp #141

Closed felixtosh closed 1 month ago

felixtosh commented 1 month ago

I don't see any documentation on how to populate e.g. a componant with this setup:

<template>
  <div>
    <h1>{{ title }}</h1>
    <div class="bg-blue-600"><slot name="default"></slot></div>
    <div class="bg-purple-600"><slot name="test"></slot></div>
  </div>
</template>

I can only populate default by simply adding children, but the examples don't provide guidelines on how to properly deal with slots

fenilli commented 1 month ago

You mean when creating a custom component, or using a schema component?

felixtosh commented 1 month ago

I was trying a basic vue3 component I had imported with two template slots

What I want to achieve: use a repeating component that has some form descriptions / tips / graphics on the left and then a formkit component on the right

felixtosh commented 1 month ago

Simplified:

<COMPONENT>
<slot name="tip"> This is the so and so section, blablbla</slot>
<slot name="forms"> <Formkit 1 /> Formkit 2 /> ... </slot>
</COmponent>

And that repeatedly

fenilli commented 1 month ago

Can you make a simple reproduction so we can undertand better the code?

felixtosh commented 1 month ago
const schema = ref([
  {
    $cmp: "testElement",
    props: {
      title: "Test Title",
    },
    children: [
      {
        $el: "div",
        children: "This is where I add some descriptions ",
      },
      {
        $el: "div",
        name: secondSlot
        children: "This is the slot where I would add the FormKit element as children",
      },
    ],
  },
  {
    $cmp: "testElement",
    props: {
      title: "Test Title",
    },
    children: [
      {
        $el: "div",
        children: "This is where I add some descriptions ",
      },
      {
        $el: "div",
        name: secondSlot
        children: "This is the slot where I would add the FormKit element as children",
      },
    ],
  },
   {
    $cmp: "testElement",
    props: {
      title: "Test Title",
    },
    children: [
      {
        $el: "div",
        children: "This is where I add some descriptions ",
      },
      {
        $el: "div",
        name: secondSlot
        children: "This is the slot where I would add the FormKit element as children",
      },
    ],
  },
 // ... rest of the schema
]);
fenilli commented 1 month ago

Oh ok, so just basic vue components, you want to add a template to a slot in schema:

{
  $cmp: "testElement",
  children: [
    { $el: 'div', children: 'This is the default slot' }
  ],
  __raw__sectionsSchema: {
    slotName: { $el: 'div', children: 'This is the slotName slot' }
  }
}
felixtosh commented 1 month ago

Awesome thanks!