Skip to content

deanlj-dev/shadcn-templ

 
 

Repository files navigation

Shadcn/ui port for Go + Templ + Alpine.js + Tailwind CSS

Go Reference License: MIT Go Report Card

Note

This is a work in proccess.

  • Not all the components from shadcn/ui are implemented.
  • There are refinements needed for some of the components - alpine.js naming, unfinished accessibility, improvements I want to make, etc.
  • Some components might contain behavior that existed for previous needs (I detached the developement of this from another project). Hopefully will be fixed in the future.

Overview

A shadcn/ui port using Go, Templ, Alpine.js and Tailwind CSS.

Usage

You have to include the Head component in your head tag (it includes the neccessery scripts - HTMX, Alpine.js and a theme script). You have to serve the CSS var and link to it in your head tag.

Example:

router.HandleFunc("GET /static/css/styles.css", func(w http.ResponseWriter, r *http.Request) {
  w.Header().Set("Content-Type", "text/css")
  w.Write(shadcntempl.CSS)
})
templ Layout() {
  <!DOCTYPE html>
	<html lang="en">
		<head>
      // ...
      @shadcntempl.Head()
			<link rel="stylesheet" href="/static/css/styles.css"/>
      // ...
		</head>
		<body>
			{ children... }
		</body>
	</html>

}

Example

Use in .templ files.

import "github.com/rotemhoresh/shadcn-templ/ui"

templ Page() {
  @ui.Button(ui.ButtonTypeButton, ui.ButtonVariantDefault, ui.ButtonSizeDefault, "additional-classes", templ.Attributes{}) {
    Click me
  }
}

Design

The components props (parameters) is structures like this:

templ Comp(componentSpecificParams, classes string, attrs templ.Attributes)

Any components specific parameters at the begining, then classes and attrs for every component (see example for the params of the Button component).

The components are written with constant referencing to the shadcn/ui source code and the underlying radix components.

Contributing

Contributions are welcome for both new components and improvements for existing ones.

Make sure to read the README and go over the codebase to understand the design choices and overall coding style as well as getting familiar with shadcn/ui.

License

MIT

About

A shadcn/ui port to Go Templ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • templ 80.3%
  • JavaScript 14.7%
  • CSS 3.5%
  • Go 1.3%
  • Makefile 0.2%