1
votes

Is it possible to make sub web components in Dart ?

Say, for example, I have a x-chatwindow custom element and I would like it to have an x-textarea and x-textinput sub component.

A fictional implementation would be :

<x-chatwindow>
    <x-textarea/>
    <x-textinput/>
</x-chatwindow>
2

2 Answers

2
votes

Is there a specific problem you are facing?

You can use the <content></content> inside your ChatWindowComponent template:

<element name="x-chat-window" constructor="ChatWindowComponent" extends="div">
  <template>
    <content></content>
  </template>
</element>

Then the page where you use them:

<!DOCTYPE html>
<html>
  <head>
    <link rel="components" href="components/chat_window.html" />
    <link rel="components" href="components/text_area.html" />
    <link rel="components" href="components/text_input.html" />
  </head>
  <body>
    <x-chat-window>
      <x-text-area></x-text-area>
      <x-text-input></x-text-input>
    </x-chat-window>
  </body>
</html>
1
votes

Answer tested on "Dart M3", "Dart Editor build 20259" and "web_ui 0.4.2 + 5"

In addition to Kai Sellgren's answer, WebComponents can be hidden inside other WebComponents. In your case inside "xchatwindow.html", textarea and text input could be linked as;

<!DOCTYPE html>

<head>
  <link rel="components" href="components/xtextarea.html">
  <link rel="components" href="components/xtextinput.html">
</head>
<body>
  <element name="x-chat-window" constructor="FormComponent" extends="div">

...