Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should support slot definition as slot content #108

Closed
SgLy opened this issue Nov 10, 2023 · 1 comment
Closed

Should support slot definition as slot content #108

SgLy opened this issue Nov 10, 2023 · 1 comment
Assignees
Labels
bug Something isn't working module:core

Comments

@SgLy
Copy link
Contributor

SgLy commented Nov 10, 2023

like:

<slot name="my-slot" slot="outer-slot" />

test cases:

// glass-easel/tests/core/slot.test.ts
test('should support slot as slot content', () => {
  const comp = componentSpace
    .define()
    .options({
      multipleSlots: true,
    })
    .template(
      tmpl(`
        <div>comp</div>
        <slot name="comp-slot"></slot>
      `),
    )
    .registerComponent()

  const child = componentSpace
    .define()
    .options({
      multipleSlots: true,
    })
    .usingComponents({ comp })
    .template(
      tmpl(`
        <comp>
          <div>child</div>
          <slot name="child-slot" slot="comp-slot" />
        </comp>
      `),
    )
    .registerComponent()

  const parent = componentSpace
    .define()
    .usingComponents({ child })
    .template(
      tmpl(`
        <child>
          <div slot="child-slot">content</div>
        </child>
      `),
    )
    .registerComponent()

  const parentElem = glassEasel.Component.createWithContext(
    'root',
    parent.general(),
    testBackend,
  )
  expect(domHtml(parentElem)).toBe(
    '<child><comp><div>comp</div><div>content</div></comp></child>',
  )
})

test('should support slot as slot content with virtual host and placeholder', () => {
  const placeholder = componentSpace
    .define()
    .options({
      multipleSlots: true,
      virtualHost: true,
    })
    .template(
      tmpl(`
        <div>placeholder</div>
        <slot name="content"></slot>
      `),
    )
    .registerComponent()

  const child = componentSpace
    .define()
    .options({
      multipleSlots: true,
      virtualHost: true,
    })
    .usingComponents({ comp: 'comp', placeholder })
    .placeholders({ comp: 'placeholder' })
    .template(
      tmpl(`
        <comp>
          <div>child</div>
          <slot name="content" slot="content" />
        </comp>
      `),
    )
    .registerComponent()

  const parent = componentSpace
    .define()
    .usingComponents({ child })
    .template(
      tmpl(`
        <child>
          <div slot="content">content</div>
        </child>
      `),
    )
    .registerComponent()

  const parentElem = glassEasel.Component.createWithContext(
    'root',
    parent.general(),
    testBackend,
  )
  expect(domHtml(parentElem)).toBe('<div>placeholder</div><div>content</div>')

  componentSpace
    .define('comp')
    .options({
      multipleSlots: true,
    })
    .template(
      tmpl(`
        <div>comp</div>
        <slot name="content"></slot>
      `),
    )
    .registerComponent()

  expect(domHtml(parentElem)).toBe('<comp><div>comp</div><div>content</div></comp>')
})
@SgLy SgLy added bug Something isn't working module:core labels Nov 10, 2023
@LastLeaf
Copy link
Member

Fixed in 19f3f91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module:core
Projects
None yet
Development

No branches or pull requests

2 participants