All Projects β†’ maragudk β†’ Gomponents

maragudk / Gomponents

Licence: mit
Declarative view components in Go, that can render to HTML5.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects
declarative
70 projects

Projects that are alternatives of or similar to Gomponents

Komponents Deprecated
πŸ“¦ React-inspired UIKit Components - ⚠️ Deprecated
Stars: ✭ 202 (+312.24%)
Mutual labels:  declarative-ui, component, ui-components
Scrollbear
A modern tool that maintains scroll position when images loaded
Stars: ✭ 523 (+967.35%)
Mutual labels:  view, dom
Toastnotifications
Toast notifications for WPF allows you to create and display rich notifications in WPF applications. It's highly configurable with set of built-in options like positions, behaviours, themes and many others. It's extendable, it gives you possibility to create custom and interactive notifications in simply manner.
Stars: ✭ 507 (+934.69%)
Mutual labels:  component, ui-components
Curtainsjs
curtains.js is a lightweight vanilla WebGL javascript library that turns HTML DOM elements into interactive textured planes.
Stars: ✭ 1,039 (+2020.41%)
Mutual labels:  html5, dom
Nanocomponent
πŸšƒ - create performant HTML components
Stars: ✭ 355 (+624.49%)
Mutual labels:  component, dom
Vue Swatches
🎨 Help the user picking beautiful colors!
Stars: ✭ 456 (+830.61%)
Mutual labels:  component, ui-components
Qmlweb
A QML engine in a web browser. Current state: fixing things…
Stars: ✭ 703 (+1334.69%)
Mutual labels:  declarative-ui, html5
Qmlcore
QML to Javascript/HTML5 translator, both for mobile and desktop targets
Stars: ✭ 258 (+426.53%)
Mutual labels:  declarative-ui, html5
Drab
Remote controlled frontend framework for Phoenix.
Stars: ✭ 833 (+1600%)
Mutual labels:  view, dom
Crab
JavaScript library for building user interfaces with Custom Elements, Shadow DOM and React like API
Stars: ✭ 22 (-55.1%)
Mutual labels:  view, dom
Html
HTML helper library
Stars: ✭ 8 (-83.67%)
Mutual labels:  view, component
React Music Player
🎡 Maybe the best beautiful HTML5 responsive player component for react :)
Stars: ✭ 321 (+555.1%)
Mutual labels:  component, html5
Frontendwingman
Frontend Wingman, Learn frontend faster!
Stars: ✭ 315 (+542.86%)
Mutual labels:  html5, dom
Html5 Dom Document Php
A better HTML5 parser for PHP.
Stars: ✭ 477 (+873.47%)
Mutual labels:  html5, dom
Redom
Tiny (2 KB) turboboosted JavaScript library for creating user interfaces.
Stars: ✭ 3,123 (+6273.47%)
Mutual labels:  html5, dom
Xy Ui
πŸŽ¨ι’ε‘ζœͺζ₯ηš„εŽŸη”Ÿ web components UIη»„δ»ΆεΊ“
Stars: ✭ 603 (+1130.61%)
Mutual labels:  ui-components, html5
Fingereyes Xr
FingerEyes-Xr for HTML5, A JavaScript library for building professional GIS System.
Stars: ✭ 9 (-81.63%)
Mutual labels:  view, html5
object-dom
HTML Object Declarative Dom
Stars: ✭ 20 (-59.18%)
Mutual labels:  dom, declarative-ui
prax
Experimental rendering library geared towards hybrid SSR+SPA apps. Focus on radical simplicity and performance. Tiny and dependency-free.
Stars: ✭ 18 (-63.27%)
Mutual labels:  dom, view
Slim.js
Fast & Robust Front-End Micro-framework based on modern standards
Stars: ✭ 789 (+1510.2%)
Mutual labels:  html5, dom

gomponents

GoDoc codecov

gomponents are declarative view components in Go, that can render to HTML5. gomponents aims to make it easy to build HTML5 pages of reusable components, without the use of a template language. Think server-side-rendered React, but without the virtual DOM and diffing.

The implementation is very usable, but the API may change until version 1 is reached.

Check out the blog post gomponents: declarative view components in Go for background.

Features

  • Build reusable view components
  • Write declarative HTML5 in Go without all the strings, so you get
    • Type safety
    • Auto-completion
    • Nice formatting with gofmt
  • Simple API that's easy to learn and use (you know most already if you know HTML)
  • No external dependencies

Usage

Get the library using go get:

go get -u github.com/maragudk/gomponents

The preferred way to use gomponents is with so-called dot-imports (note the dot before the gomponents/html import), to give you that smooth, native HTML feel:

package main

import (
	"net/http"

	g "github.com/maragudk/gomponents"
	c "github.com/maragudk/gomponents/components"
	. "github.com/maragudk/gomponents/html"
)

func main() {
	_ = http.ListenAndServe("localhost:8080", http.HandlerFunc(handler))
}

func handler(w http.ResponseWriter, r *http.Request) {
	_ = Page("Hi!", r.URL.Path).Render(w)
}

func Page(title, currentPath string) g.Node {
	return Doctype(
		HTML(
			Lang("en"),
			Head(
				TitleEl(title),
				StyleEl(Type("text/css"), g.Raw(".is-active{ font-weight: bold }")),
			),
			Body(
				Navbar(currentPath),
				H1(title),
				P(g.Textf("Welcome to the page at %v.", currentPath)),
			),
		),
	)
}

func Navbar(currentPath string) g.Node {
	return Nav(
		NavbarLink("/", "Home", currentPath),
		NavbarLink("/about", "About", currentPath),
	)
}

func NavbarLink(href, name, currentPath string) g.Node {
	return A(Href(href), c.Classes{"is-active": currentPath == href}, g.Text(name))
}

Some people don't like dot-imports, and luckily it's completely optional. If you don't like dot-imports, just use regular imports.

You could also use the provided HTML5 document template to simplify your code a bit:

package main

import (
	"net/http"

	g "github.com/maragudk/gomponents"
	c "github.com/maragudk/gomponents/components"
	. "github.com/maragudk/gomponents/html"
)

func main() {
	_ = http.ListenAndServe("localhost:8080", http.HandlerFunc(handler))
}

func handler(w http.ResponseWriter, r *http.Request) {
	_ = Page("Hi!", r.URL.Path).Render(w)
}

func Page(title, currentPath string) g.Node {
	return c.HTML5(c.HTML5Props{
		Title:    title,
		Language: "en",
		Head: []g.Node{
			StyleEl(Type("text/css"), g.Raw(".is-active{ font-weight: bold }")),
		},
		Body: []g.Node{
			Navbar(currentPath),
			H1(title),
			P(g.Textf("Welcome to the page at %v.", currentPath)),
		},
	})
}

func Navbar(currentPath string) g.Node {
	return Nav(
		NavbarLink("/", "Home", currentPath),
		NavbarLink("/about", "About", currentPath),
	)
}

func NavbarLink(href, name, currentPath string) g.Node {
	return A(Href(href), c.Classes{"is-active": currentPath == href}, g.Text(name))
}

For more complete examples, see the examples directory.

What's up with the specially named elements and attributes?

Unfortunately, there are four main name clashes in HTML elements and attributes, so they need an El or Attr suffix, respectively, to be able to co-exist in the same package in Go:

  • data (DataEl/DataAttr)
  • form (FormEl/FormAttr)
  • style (StyleEl/StyleAttr)
  • title (TitleEl/TitleAttr)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].