Documentation
¶
Overview ¶
templ: version: v0.2.778
templ: version: v0.2.778
templ: version: v0.2.778
templ: version: v0.2.778
templ: version: v0.2.778
templ: version: v0.2.778
templ: version: v0.2.778
templ: version: v0.2.778
templ: version: v0.2.778
templ: version: v0.2.778
templ: version: v0.2.778
templ: version: v0.2.778
templ: version: v0.2.778
templ: version: v0.2.778
templ: version: v0.2.778
templ: version: v0.2.778
Index ¶
- Constants
- Variables
- func Accordion(props AccordionProps) templ.Component
- func Alert(props AlertProps) templ.Component
- func AlertDescription() templ.Component
- func AlertTitle() templ.Component
- func Avatar(props AvatarProps) templ.Component
- func AvatarInitials(name string) string
- func AvatarSizeClasses(size AvatarSize) string
- func Button(props ButtonProps) templ.Component
- func Card(props CardProps) templ.Component
- func CardContent() templ.Component
- func CardDescription() templ.Component
- func CardFooter() templ.Component
- func CardHeader() templ.Component
- func CardTitle() templ.Component
- func DarkIcon() templ.Component
- func Datepicker(props DatepickerProps) templ.Component
- func Footer() templ.Component
- func Icon(props IconProps) templ.Component
- func Input(props InputProps) templ.Component
- func LightIcon() templ.Component
- func Modal(props ModalProps) templ.Component
- func ModalBody() templ.Component
- func ModalClose(id string) templ.Component
- func ModalFooter() templ.Component
- func ModalHeader() templ.Component
- func ModalTrigger(id string) templ.Component
- func Navbar() templ.Component
- func NavbarMobileMenu() templ.Component
- func Sheet(props SheetProps) templ.Component
- func SheetClose(text string) templ.Component
- func SheetRoot() templ.Component
- func SheetTrigger(text string, side SheetSide) templ.Component
- func Sidebar() templ.Component
- func SidebarRight() templ.Component
- func Tabs(props TabsProps) templ.Component
- func ThemeSwitcher() templ.Component
- type AccordionItem
- type AccordionProps
- type AlertProps
- type AlertVariant
- type AvatarProps
- type AvatarSize
- type ButtonProps
- type ButtonSize
- type ButtonVariant
- type CardProps
- type DatepickerProps
- type IconProps
- type InputProps
- type InputType
- type ModalProps
- type SheetProps
- type SheetSide
- type SidebarRightLItem
- type Tab
- type TabsProps
Constants ¶
const ( Default ButtonVariant = "default" Destructive ButtonVariant = "destructive" Outline ButtonVariant = "outline" Secondary ButtonVariant = "secondary" Ghost ButtonVariant = "ghost" Link ButtonVariant = "link" Md ButtonSize = "md" Sm ButtonSize = "sm" Lg ButtonSize = "lg" ButtonIcon ButtonSize = "icon" )
Constants for button variants and sizes.
Variables ¶
var SidebarRightLinks = []SidebarRightLItem{
{
ImageSrc: "https://templ.guide/img/logo.svg",
Url: "https://templ.guide",
Text: "Elevate your Go projects with type-safe, efficient HTML templating.",
},
{
ImageSrc: "https://alpinejs.dev/alpine_long.svg",
Url: "https://alpinejs.dev",
Text: "Simplify your JavaScript with a lightweight, powerful framework.",
},
{
ImageSrc: "https://tailwindcss.com/_next/static/media/tailwindcss-logotype-white.944c5d0ef628083bb316f9b3d643385c86bcdb3d.svg",
Url: "https://tailwindcss.com",
Text: "Create beautiful, responsive designs with ease.",
},
}
var TemplFiles embed.FS
Functions ¶
func Accordion ¶
func Accordion(props AccordionProps) templ.Component
Accordion renders an accordion component based on the provided props. It uses Alpine.js for interactivity and state management.
Usage:
@components.Accordion(components.AccordionProps{
Items: []components.AccordionItem{
{
ID: "item-1",
Trigger: templ.Raw("Is it accessible?"),
Content: templ.Raw("Yes. It adheres to the WAI-ARIA design pattern."),
},
{
ID: "item-2",
Trigger: templ.Raw("Is it styled?"),
Content: templ.Raw("Yes. It comes with default styles that match the other components' aesthetic."),
},
},
Class: "w-full sm:max-w-[70%]",
Attributes: templ.Attributes{"data-testid": "my-accordion"},
})
Props:
- Items: A slice of AccordionItem structs, each representing an item in the accordion.
- Class: Additional CSS classes to apply to the accordion container. Default: "" (empty string)
- Attributes: Additional HTML attributes to apply to the accordion container element. Default: nil
func Alert ¶
func Alert(props AlertProps) templ.Component
Alert renders an alert component based on the provided props and children. It can be customized with two visual styles: Default and Destructive. All content, including icons, should be passed in as children.
Usage:
@components.Alert(components.AlertProps{Variant: components.DestructiveAlert}) {
@components.ExclamationTriangleIcon()
@components.AlertTitle{"Error"}
@components.AlertDescription{"Your session has expired. Please log in again."}
}
Props:
- Variant: The visual style of the alert (DefaultAlert or DestructiveAlert). Default: DefaultAlert
- Class: Additional CSS classes to apply to the alert. Default: "" (empty string)
func AlertDescription ¶
AlertDescription renders the description of the alert.
func Avatar ¶
func Avatar(props AvatarProps) templ.Component
Avatar renders an avatar component based on the provided props. It displays an image if ImageSrc is provided, otherwise it shows initials.
Usage:
@components.Avatar(components.AvatarProps{
ImageSrc: "https://example.com/avatar.jpg",
Name: "John Doe",
Size: components.AvatarSizeMedium,
Class: "border-2 border-blue-500",
})
Props:
- ImageSrc: The URL of the avatar image. Default: "" (empty string)
- Name: The name used to generate initials if ImageSrc is empty. Default: "" (empty string)
- Size: The size of the avatar (AvatarSizeSmall, AvatarSizeMedium, AvatarSizeLarge). Default: AvatarSizeMedium
- Class: Additional CSS classes to apply to the avatar. Default: "" (empty string)
- Attributes: Additional HTML attributes to apply to the avatar element. Default: nil
func AvatarInitials ¶
getInitials generates initials from the given name.
func AvatarSizeClasses ¶
func AvatarSizeClasses(size AvatarSize) string
getSizeClasses returns the CSS classes for the given avatar size.
func Button ¶
func Button(props ButtonProps) templ.Component
Button renders a button or anchor component based on the provided props. It can be customized with various visual styles, sizes, and behaviors.
Usage:
@components.Button(components.ButtonProps{
Text: "Click me",
Variant: components.Primary,
Size: components.Md,
FullWidth: false,
Attributes: templ.Attributes{
"aria-label": "Click this button",
"data-testid": "main-button",
},
})
Props:
- Class: Additional CSS classes to apply to the button. Default: "" (empty string)
- Text: The text content of the button. Default: "" (empty string)
- Variant: The visual style of the button (e.g., Default, Destructive, Outline). Default: Default
- Size: The size of the button (Md, Sm, Lg, Icon). Default: Md
- FullWidth: Whether the button should take up the full width of its container. Default: false
- Href: If provided, renders the button as an anchor tag with this URL. Default: "" (empty string)
- Target: The target attribute for the anchor tag (only used when Href is provided). Default: "" (empty string)
- Disabled: Can be either a bool or a string. If bool (Go), it directly controls the disabled state. If string, it's treated as a JavaScript expression for dynamic disabling. Default: nil
- Type: The type of the button. Default: "button"
- Attributes: Additional HTML attributes to apply to the button or anchor element. Default: nil
func Card ¶
Card renders a card component based on the provided props. It can be customized with additional classes and attributes.
Usage:
@components.Card(components.CardProps{
Class: "custom-card",
Attributes: templ.Attributes{"data-testid": "my-card"},
}) {
// Card content goes here
}
Props:
- Class: Additional CSS classes to apply to the card. Default: "" (empty string)
- Attributes: Additional HTML attributes to apply to the card element. Default: nil
func CardContent ¶
CardContent renders the main content section of a card.
Usage:
@components.CardContent() {
// Main card content goes here
}
func CardDescription ¶
CardDescription renders the description of a card.
Usage:
@components.CardDescription() {
This is a detailed description of the card's content.
}
func CardFooter ¶
CardFooter renders the footer section of a card.
Usage:
@components.CardFooter() {
@components.Button(components.ButtonProps{Text: "Submit"})
}
func CardHeader ¶
CardHeader renders the header section of a card.
Usage:
@components.CardHeader() {
@components.CardTitle() { Card Title }
@components.CardDescription() { Card description goes here }
}
func CardTitle ¶
CardTitle renders the title of a card.
Usage:
@components.CardTitle() {
My Card Title
}
func Datepicker ¶
func Datepicker(props DatepickerProps) templ.Component
Datepicker renders an enhanced datepicker component with an input field and a calendar view. It uses Alpine.js for interactivity and provides various formatting options and improved navigation. This version supports dark mode using Tailwind CSS variables.
Usage:
@components.Datepicker(components.DatepickerProps{
ID: "my-datepicker",
Name: "selected-date",
Placeholder: "Select a date",
Format: "YYYY-MM-DD",
Class: "w-full",
})
Props:
- ID: The unique identifier for the datepicker input. Default: "" (empty string)
- Name: The name attribute for the datepicker input. Default: "" (empty string)
- Placeholder: The placeholder text for the datepicker input. Default: "" (empty string)
- Format: The date format to use. Default: "M d, Y"
- Class: Additional CSS classes to apply to the datepicker container. Default: "" (empty string)
- Attributes: Additional HTML attributes to apply to the datepicker input element. Default: nil
func Icon ¶
Icon renders a Lucide icon as an SVG element.
Usage:
@components.Icon(components.IconProps{
Name: "user",
Size: "24",
Color: "blue",
Fill: "none",
Stroke: "currentColor",
Class: "my-icon-class",
})
func Input ¶
func Input(props InputProps) templ.Component
Input renders an input component based on the provided props. It can be customized with various types, sizes, and behaviors.
Usage:
@components.Input(components.InputProps{
Type: components.Email,
Placeholder: "Enter your email",
ID: "email-input",
Class: "custom-input",
Attributes: templ.Attributes{
"aria-label": "Email input",
"data-testid": "email-input",
},
})
Props:
- Type: The type of the input field (e.g., Text, Email, Password). Default: Text
- Placeholder: The placeholder text for the input field. Default: "" (empty string)
- Value: The current value of the input field. Default: "" (empty string)
- Name: The name attribute of the input field. Default: "" (empty string)
- ID: The unique identifier for the input field. Default: "" (empty string)
- Class: Additional CSS classes to apply to the input field. Default: "" (empty string)
- Disabled: Can be either a bool or a string. If bool (Go), it directly controls the disabled state. If string, it's treated as a JavaScript expression for dynamic disabling. Default: nil
- FileAccept: Specifies which file types are accepted (only for file type). Default: "" (empty string)
- Attributes: Additional HTML attributes to apply to the input element. Default: nil
func Modal ¶
func Modal(props ModalProps) templ.Component
Modal renders a modal dialog component. It uses Alpine.js for state management and animations.
Usage:
@components.ModalTrigger("default-modal") {
@components.Button(components.ButtonProps{Text: "Open Modal"})
}
@components.Modal(components.ModalProps{ID: "default-modal", Class: "max-w-md"}) {
@components.ModalHeader() {
Are you absolutely sure?
}
@components.ModalBody() {
This action cannot be undone. This will permanently delete your account and remove your data from our servers.
}
@components.ModalFooter() {
<div class="flex gap-2">
@components.ModalClose("default-modal") {
@components.Button(components.ButtonProps{
Text: "Cancel",
})
}
@components.ModalClose("default-modal") {
@components.Button(components.ButtonProps{
Text: "Continue",
Variant: components.Secondary,
})
}
</div>
}
}
The Modal component should be used in conjunction with ModalTrigger to open it.
func ModalBody ¶
ModalBody renders the main content area of the modal.
Usage:
@components.ModalBody() {
<p>This is the modal content.</p>
}
func ModalClose ¶
ModalClose renders an element that closes the modal when clicked.
Usage:
@components.ModalClose("example-modal") {
@components.Button(components.ButtonProps{
Text: "Close",
Variant: components.Secondary,
})
}
The 'id' parameter should match the ID of the Modal you want to close.
func ModalFooter ¶
ModalFooter renders the footer section of the modal, typically containing action buttons.
Usage:
@components.ModalFooter() {
@components.ModalClose("example-modal") {
@components.Button(components.ButtonProps{
Text: "Close",
Variant: components.Secondary,
})
}
}
func ModalHeader ¶
ModalHeader renders the header section of the modal.
Usage:
@components.ModalHeader() {
Modal Title
@components.ModalClose("example-modal")
}
func ModalTrigger ¶
ModalTrigger renders an element that opens the modal when clicked.
Usage:
@components.ModalTrigger("example-modal") {
@components.Button(components.ButtonProps{Text: "Open Modal"})
}
The 'id' parameter should match the ID of the Modal you want to open.
func NavbarMobileMenu ¶
func Sheet ¶
func Sheet(props SheetProps) templ.Component
Sheet renders the main sheet component with backdrop and content.
Usage:
@components.Sheet(components.SheetProps{
Title: "Sheet Title",
Description: "Sheet description goes here",
Side: components.Right,
}) {
// Sheet content goes here
}
Props:
- Title: The heading text for the sheet. Default: "" (empty string)
- Description: The subheading or description text for the sheet. Default: "" (empty string)
- Side: Determines from which side the sheet will appear. Default: Right
func SheetClose ¶
SheetClose renders a button that closes the sheet when clicked.
Usage:
@components.SheetClose("Close")
Props:
- text: The text content of the close button
func SheetRoot ¶
SheetRoot renders the root component for the Sheet, setting up the Alpine.js data and event handlers.
Usage:
@components.SheetRoot() {
// Sheet trigger and content go here
}
func SheetTrigger ¶
SheetTrigger renders a trigger element that opens the sheet when clicked.
Usage:
@components.SheetTrigger("Open Sheet", components.Right) {
<button>Open Sheet</button>
}
Props:
- text: The text content of the trigger (unused in the current implementation)
- side: The side from which the sheet should appear
func SidebarRight ¶
func Tabs ¶
Tabs renders a tabbed interface component based on the provided props. It uses Alpine.js for interactivity and state management.
Usage:
@components.Tabs(components.TabsProps{
Tabs: []components.Tab{
{ID: "1", Title: "Tab 1", Content: Tab1Content()},
{ID: "2", Title: "Tab 2", Content: Tab2Content()},
},
TabsContainerClass: "w-full max-w-md",
ContentContainerClass: "mt-4",
})
Props:
- Tabs: An array of Tab structs, each representing a tab in the interface.
- TabsContainerClass: Additional CSS classes for the tabs container. Default: "" (empty string)
- ContentContainerClass: Additional CSS classes for the content container. Default: "" (empty string)
func ThemeSwitcher ¶
Types ¶
type AccordionItem ¶
type AccordionItem struct {
// ID is the unique identifier for the accordion item.
// It is used to manage the open/closed state of the item.
ID string
// Trigger is the content of the accordion item's header/trigger.
// This is typically text, but can be any templ.Component.
Trigger templ.Component
// Content is the expandable content of the accordion item.
// This can be any templ.Component.
Content templ.Component
}
AccordionItem represents a single item in the Accordion component.
type AccordionProps ¶
type AccordionProps struct {
// Items is a slice of AccordionItem structs representing each item in the accordion.
Items []AccordionItem
// Class specifies additional CSS classes to apply to the accordion container.
// Default: "" (empty string)
Class string
// Attributes allows passing additional HTML attributes to the accordion container element.
// Default: nil
Attributes templ.Attributes
}
AccordionProps defines the properties for the Accordion component.
type AlertProps ¶
type AlertProps struct {
// Variant determines the visual style of the alert.
// Default: DefaultAlert
Variant AlertVariant
// Class specifies additional CSS classes to apply to the alert.
// Default: "" (empty string)
Class string
}
AlertProps defines the properties for the Alert component.
type AlertVariant ¶
type AlertVariant string
AlertVariant represents the visual style of the alert.
const ( DefaultAlert AlertVariant = "default" DestructiveAlert AlertVariant = "destructive" )
Constants for alert variants.
type AvatarProps ¶
type AvatarProps struct {
// ImageSrc is the URL of the avatar image.
// If empty, initials will be used.
ImageSrc string
// Name is used to generate initials if ImageSrc is empty.
Name string
// Size determines the size of the avatar.
// Default: AvatarSizeMedium
Size AvatarSize
// Class specifies additional CSS classes to apply to the avatar.
Class string
// Attributes allows passing additional HTML attributes to the avatar element.
Attributes templ.Attributes
}
AvatarProps defines the properties for the Avatar component.
type AvatarSize ¶
type AvatarSize string
AvatarSize represents the size of the avatar.
const ( AvatarSizeSmall AvatarSize = "small" AvatarSizeMedium AvatarSize = "medium" AvatarSizeLarge AvatarSize = "large" )
type ButtonProps ¶
type ButtonProps struct {
// Class specifies additional CSS classes to apply to the button.
// Default: "" (empty string)
Class string
// Text is the content of the button.
// Default: "" (empty string)
Text string
// Variant determines the visual style of the button.
// Default: Default
Variant ButtonVariant
// Size sets the size of the button.
// Default: Md
Size ButtonSize
// FullWidth determines whether the button should take up the full width of its container.
// Default: false
FullWidth bool
// Href, if provided, renders the button as an anchor tag with this URL.
// Default: "" (empty string)
Href string
// Target specifies the target attribute for the anchor tag (only used when Href is provided).
// Default: "" (empty string)
Target string
// Disabled can be either a bool or a string.
// If bool (Go), it directly controls the disabled state.
// If string, it's treated as a JavaScript expression for dynamic disabling.
Disabled any
// Type specifies the type of the button. Default: "button"
// Default: "" (empty string)
Type string
// Attributes allows passing additional HTML attributes to the button or anchor element.
// Default: nil
Attributes templ.Attributes
}
ButtonProps defines the properties for the Button component.
type ButtonVariant ¶
type ButtonVariant string
ButtonVariant represents the visual style of the button.
type CardProps ¶
type CardProps struct {
// Class specifies additional CSS classes to apply to the card.
// Default: "" (empty string)
Class string
// Attributes allows passing additional HTML attributes to the card element.
// Default: nil
Attributes templ.Attributes
}
CardProps defines the properties for the Card component.
type DatepickerProps ¶
type DatepickerProps struct {
// ID is the unique identifier for the datepicker input.
ID string
// Name is the name attribute for the datepicker input.
Name string
// Placeholder is the placeholder text for the datepicker input.
Placeholder string
// Format specifies the date format to use. Options: "M d, Y", "MM-DD-YYYY", "DD-MM-YYYY", "YYYY-MM-DD", "D d M, Y"
// Default: "M d, Y"
Format string
// Class specifies additional CSS classes to apply to the datepicker container.
Class string
// Attributes allows passing additional HTML attributes to the datepicker input element.
Attributes templ.Attributes
}
DatepickerProps defines the properties for the Datepicker component.
type IconProps ¶
type IconProps struct {
Name string // Name of the icon
Size string // Size of the icon (default: "24")
Color string // Color of the icon (default: "currentColor")
Fill string // Fill color of the icon (default: "none")
Stroke string // Stroke color of the icon (overrides Color if set)
Class string // Additional CSS classes
}
IconProps defines the properties for the Icon component.
func (IconProps) GenerateSVG ¶
GenerateSVG generates the SVG for the icon
type InputProps ¶
type InputProps struct {
// Type specifies the type of the input field.
// Default: Text
Type InputType
// Placeholder is the placeholder text for the input field.
// Default: "" (empty string)
Placeholder string
// Value is the current value of the input field.
// Default: "" (empty string)
Value string
// Name is the name attribute of the input field.
// Default: "" (empty string)
Name string
// ID is the unique identifier for the input field.
// Default: "" (empty string)
ID string
// Class specifies additional CSS classes to apply to the input field.
// Default: "" (empty string)
Class string
// Disabled can be either a bool or a string.
// If bool (Go), it directly controls the disabled state.
// If string, it's treated as a JavaScript expression for dynamic disabling.
// Default: nil
Disabled any
// FileAccept specifies which file types are accepted (only for file type).
// Default: "" (empty string)
FileAccept string
// Attributes allows passing additional HTML attributes to the input element.
// Default: nil
Attributes templ.Attributes
}
InputProps defines the properties for the Input component.
type ModalProps ¶
type ModalProps struct {
// ID is a unique identifier for the modal.
// It's used to control opening and closing.
// This should be unique across your application.
ID string
// Class specifies additional CSS classes to apply to the modal container.
Class string
}
ModalProps defines the properties for the Modal component.
type SheetProps ¶
type SheetProps struct {
// Title is the heading text for the sheet.
// Default: "" (empty string)
Title string
// Description is the subheading or description text for the sheet.
// Default: "" (empty string)
Description string
// Side determines from which side the sheet will appear.
// Default: Right
Side SheetSide
}
SheetProps defines the properties for the Sheet component.
type SheetSide ¶
type SheetSide string
SheetSide represents the side from which the sheet will appear.
type SidebarRightLItem ¶
type Tab ¶
type Tab struct {
// ID is the unique identifier for the tab.
ID string
// Title is the text displayed on the tab button.
Title string
// Content is the templ.Component to be rendered when the tab is active.
Content templ.Component
}
Tab represents a single tab in the Tabs component.
type TabsProps ¶
type TabsProps struct {
// Tabs is an array of Tab structs representing each tab in the component.
Tabs []Tab
// TabsContainerClass specifies additional CSS classes for the tabs container.
// Default: "" (empty string)
TabsContainerClass string
// ContentContainerClass specifies additional CSS classes for the content container.
// Default: "" (empty string)
ContentContainerClass string
}
TabsProps defines the properties for the Tabs component.