Documentation
¶
Overview ¶
Package primitives provides low-level layout primitives for ForgeUI.
Primitives are the building blocks for more complex components. They provide type-safe wrappers around common CSS layout patterns. All primitives return templ.Component and accept children as templ.Component.
Layout primitives:
- Box: Polymorphic container element
- Flex: Flexbox container
- Grid: CSS Grid container
Stack helpers:
- VStack: Vertical stack (flex column)
- HStack: Horizontal stack (flex row)
Utility primitives:
- Center: Centers content both horizontally and vertically
- Container: Responsive container with max-width
- Spacer: Flexible spacer that fills available space
- Text: Typography primitive
Index ¶
- func Box(opts ...BoxOption) templ.Component
- func Center(children ...templ.Component) templ.Component
- func Container(children ...templ.Component) templ.Component
- func Flex(opts ...FlexOption) templ.Component
- func Grid(opts ...GridOption) templ.Component
- func HStack(gap string, children ...templ.Component) templ.Component
- func Provider(opts ...ProviderOption) templ.Component
- func ProviderDispatch(providerName, eventName, data string) string
- func ProviderMethod(providerName, method string, args ...string) string
- func ProviderScriptUtilities() templ.Component
- func ProviderStack(providers ...templ.Component) templ.Component
- func ProviderValue(providerName, key string) string
- func Spacer() templ.Component
- func Text(opts ...TextOption) templ.Component
- func VStack(gap string, children ...templ.Component) templ.Component
- type BoxOption
- func WithAs(tag string) BoxOption
- func WithAttrs(attrs templ.Attributes) BoxOption
- func WithBackground(bg string) BoxOption
- func WithChildren(children ...templ.Component) BoxOption
- func WithClass(class string) BoxOption
- func WithHeight(h string) BoxOption
- func WithMargin(m string) BoxOption
- func WithPadding(padding string) BoxOption
- func WithRounded(rounded string) BoxOption
- func WithShadow(shadow string) BoxOption
- func WithWidth(w string) BoxOption
- type BoxProps
- type FlexOption
- func FlexAlign(align string) FlexOption
- func FlexAttrs(attrs templ.Attributes) FlexOption
- func FlexChildren(children ...templ.Component) FlexOption
- func FlexClass(class string) FlexOption
- func FlexDirection(direction string) FlexOption
- func FlexGap(gap string) FlexOption
- func FlexJustify(justify string) FlexOption
- func FlexWrap(wrap string) FlexOption
- type FlexProps
- type GridOption
- func GridAttrs(attrs templ.Attributes) GridOption
- func GridChildren(children ...templ.Component) GridOption
- func GridClass(class string) GridOption
- func GridCols(cols int) GridOption
- func GridColsLG(cols int) GridOption
- func GridColsMD(cols int) GridOption
- func GridColsSM(cols int) GridOption
- func GridColsXL(cols int) GridOption
- func GridGap(gap string) GridOption
- type GridProps
- type ProviderOption
- func WithProviderAttrs(attrs templ.Attributes) ProviderOption
- func WithProviderChildren(children ...templ.Component) ProviderOption
- func WithProviderClass(class string) ProviderOption
- func WithProviderDebug(debug bool) ProviderOption
- func WithProviderHook(name, code string) ProviderOption
- func WithProviderInit(init string) ProviderOption
- func WithProviderMethods(methods string) ProviderOption
- func WithProviderName(name string) ProviderOption
- func WithProviderState(state map[string]any) ProviderOption
- type ProviderProps
- type TextOption
- func TextAlign(align string) TextOption
- func TextAs(tag string) TextOption
- func TextAttrs(attrs templ.Attributes) TextOption
- func TextChildren(children ...templ.Component) TextOption
- func TextClass(class string) TextOption
- func TextColor(color string) TextOption
- func TextSize(size string) TextOption
- func TextWeight(weight string) TextOption
- type TextProps
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Center ¶
Center creates a centered container using flexbox. Centers both horizontally and vertically.
func Container ¶
Container creates a responsive container with max-width constraints. Commonly used for page layouts.
func HStack ¶
HStack creates a horizontal stack (flex row). This is a convenience wrapper around Flex for horizontal layouts.
func Provider ¶
func Provider(opts ...ProviderOption) templ.Component
Provider creates a provider context component that shares state with children.
func ProviderDispatch ¶
ProviderDispatch returns an Alpine expression to dispatch a provider event.
func ProviderMethod ¶
ProviderMethod returns an Alpine expression to call a provider method.
func ProviderScriptUtilities ¶
ProviderScriptUtilities returns a script tag with helper functions for working with providers.
func ProviderStack ¶
ProviderStack creates a nested stack of providers.
func ProviderValue ¶
ProviderValue returns an Alpine expression to access a provider's state.
Types ¶
type BoxOption ¶
type BoxOption func(*BoxProps)
BoxOption is a functional option for configuring Box
func WithBackground ¶
WithBackground sets background classes
func WithChildren ¶
WithChildren adds child components
func WithRounded ¶
WithRounded sets border-radius classes
type BoxProps ¶
type BoxProps struct {
As string // HTML tag (div, span, section, article, etc.)
Class string // custom classes
P string // padding
M string // margin
Bg string // background
Rounded string // border-radius
Shadow string // box-shadow
W string // width
H string // height
Children []templ.Component
Attributes templ.Attributes
}
BoxProps defines properties for the Box component
type FlexOption ¶
type FlexOption func(*FlexProps)
FlexOption is a functional option for configuring Flex
func FlexChildren ¶
func FlexChildren(children ...templ.Component) FlexOption
FlexChildren adds child components
func FlexDirection ¶
func FlexDirection(direction string) FlexOption
FlexDirection sets the flex direction
type FlexProps ¶
type FlexProps struct {
Direction string // row, col, row-reverse, col-reverse
Wrap string // wrap, nowrap, wrap-reverse
Justify string // start, end, center, between, around, evenly
Align string // start, end, center, stretch, baseline
Gap string // gap size
Class string
Children []templ.Component
Attributes templ.Attributes
}
FlexProps defines properties for the Flex component
type GridOption ¶
type GridOption func(*GridProps)
GridOption is a functional option for configuring Grid
func GridChildren ¶
func GridChildren(children ...templ.Component) GridOption
GridChildren adds child components
type GridProps ¶
type GridProps struct {
Cols int // number of columns
ColsSM int // columns at sm breakpoint
ColsMD int // columns at md breakpoint
ColsLG int // columns at lg breakpoint
ColsXL int // columns at xl breakpoint
Gap string // gap size
Class string
Children []templ.Component
Attributes templ.Attributes
}
GridProps defines properties for the Grid component
type ProviderOption ¶
type ProviderOption func(*ProviderProps)
ProviderOption is a functional option for configuring a Provider.
func WithProviderAttrs ¶
func WithProviderAttrs(attrs templ.Attributes) ProviderOption
WithProviderAttrs adds custom HTML attributes to the provider wrapper.
func WithProviderChildren ¶
func WithProviderChildren(children ...templ.Component) ProviderOption
WithProviderChildren sets the children that will have access to this provider.
func WithProviderClass ¶
func WithProviderClass(class string) ProviderOption
WithProviderClass adds custom CSS classes to the provider wrapper.
func WithProviderDebug ¶
func WithProviderDebug(debug bool) ProviderOption
WithProviderDebug enables debug mode for the provider.
func WithProviderHook ¶
func WithProviderHook(name, code string) ProviderOption
WithProviderHook adds a lifecycle hook to the provider.
func WithProviderInit ¶
func WithProviderInit(init string) ProviderOption
WithProviderInit sets initialization code for the provider.
func WithProviderMethods ¶
func WithProviderMethods(methods string) ProviderOption
WithProviderMethods adds JavaScript methods to the provider.
func WithProviderName ¶
func WithProviderName(name string) ProviderOption
WithProviderName sets the provider's unique identifier.
func WithProviderState ¶
func WithProviderState(state map[string]any) ProviderOption
WithProviderState sets the provider's initial state.
type ProviderProps ¶
type ProviderProps struct {
// Name is the unique identifier for this provider (e.g., "sidebar", "theme")
Name string
// State is the initial state as a map of key-value pairs
State map[string]any
// Methods is raw JavaScript code defining provider methods
Methods string
// OnInit is JavaScript code that runs when the provider initializes
OnInit string
// Class adds custom CSS classes to the provider wrapper
Class string
// Attributes adds custom HTML attributes to the provider wrapper
Attributes templ.Attributes
// Children are the child components that will have access to this provider
Children []templ.Component
// Debug enables console logging for state changes
Debug bool
// Hooks define lifecycle hooks for the provider
Hooks map[string]string
}
ProviderProps defines the configuration for a Provider component.
type TextOption ¶
type TextOption func(*TextProps)
TextOption is a functional option for configuring Text
func TextChildren ¶
func TextChildren(children ...templ.Component) TextOption
TextChildren adds child components
type TextProps ¶
type TextProps struct {
As string // HTML tag (p, span, div, h1-h6)
Size string // text size class
Weight string // font weight class
Color string // text color class
Align string // text alignment
Class string
Children []templ.Component
Attributes templ.Attributes
}
TextProps defines properties for the Text component