go-app icon indicating copy to clipboard operation
go-app copied to clipboard

Custom HTML elements

Open andrewrynhard opened this issue 3 years ago • 10 comments

Have there been any discussions around custom HTML elements? I would like to build HTML with app but need some custom tags.

andrewrynhard avatar Feb 16 '21 19:02 andrewrynhard

Is there a link to the html specification ?

maxence-charriere avatar Feb 16 '21 19:02 maxence-charriere

Maybe this: https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements.

andrewrynhard avatar Feb 16 '21 19:02 andrewrynhard

What a custom element would do compared to a component? Any example on how would you like to use it?

maxence-charriere avatar Feb 16 '21 19:02 maxence-charriere

I specifically need to create an element that is predetermined by a third-party (hotwire.dev) requires (turbo-frame, turbo-stream, etc.).

Something like:

	ui := app.Html().Body(
		app.Head().Body(
			app.Title().Body(app.Text("example")),
			app.Meta().Name("viewport").Content("width=device-width,initial-scale=1"),
			app.Link().Rel("stylesheet").Href("main.css"),
			app.Script().Src("main.ts"),
		),
		app.Body().Body(
			app.Div().Class("app").Body(
				app.Header(),
				app.Nav(),
				app.Main().Body(
                                        app.Custom("turbo-frame").Body(     // <-- HERE 
					    app.Div().Class("flex flex-col h-screen max-w-7xl mx-auto px-4 sm:px-6 md:px-8"),
                                        ),
				),
				app.Aside(),
				app.Footer(),
			),
		),
	)

EDIT: This also probably makes more sense knowing that I intend on rendering the HTML built with the above with PrintHTMLWithIndent and the HTML must have the custom tag names in it.

andrewrynhard avatar Feb 16 '21 20:02 andrewrynhard

Mmm ok lets try another, how would it look like in html ?

maxence-charriere avatar Feb 17 '21 02:02 maxence-charriere

Like so:

<html>
  <head>
  ...
  </head>
  <body>
    <div class="app">
      <header></header>
      <nav>
      </nav>
      <main>
        <turbo-frame>  <!-- HERE -->
          <div> class="flex flex-col h-screen max-w-7xl mx-auto px-4 sm:px-6 md:px-8"></div>
        </turbo-frame>
      </main>
      <aside></aside>
      <footer></footer>
    </div>
  </body>
</html>

andrewrynhard avatar Feb 17 '21 03:02 andrewrynhard

Looks a bit complicated to implement in the package since it involves multiple js calls. Right now I have other priorities but in the meantime, maybe using a Raw() element could solve your problem.

maxence-charriere avatar Feb 17 '21 04:02 maxence-charriere

Looks a bit complicated to implement in the package since it involves multiple js calls. Right now I have other priorities but in the meantime, maybe using a Raw() element could solve your problem.

Understandable. Thanks for the quick responses. Really love what you are doing with this project BTW!

andrewrynhard avatar Feb 17 '21 06:02 andrewrynhard

I would also be very interested in this, especially since a web-components version of material design is in progress: https://github.com/material-components/material-components-web-components

ptxmac avatar Apr 01 '21 11:04 ptxmac

I was about to work on this and stumbled upon HTMLElem and ElemSelfClosing. It should be able to handle custom HTML elements and web components.

chumaumenze avatar Nov 06 '22 15:11 chumaumenze