Skip to content

Commit

Permalink
feat: tabs selection
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Oct 29, 2024
1 parent 1ca6938 commit d496a7b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
33 changes: 24 additions & 9 deletions components/tabs/tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

// TabsProps is a struct that contains the properties of the Tabs component
type TabsProps struct {
ID string
ClassNames htmx.ClassNames
}

Expand Down Expand Up @@ -41,20 +42,34 @@ func TabsBoxed(props TabsProps, children ...htmx.Node) htmx.Node {
// TabProps is a struct that contains the properties of the Tab component
type TabProps struct {
ClassNames htmx.ClassNames
Name string
Label string
Active bool
Disabled bool
}

// Tab is a component that renders a tab.
func Tab(props TabProps, children ...htmx.Node) htmx.Node {
return htmx.A(
htmx.Merge(
htmx.ClassNames{
"tab": true,
"tab-active": props.Active,
},
props.ClassNames,
return htmx.Fragment(
htmx.Input(
htmx.Type("radio"),
htmx.Name(props.Name),
htmx.Role("tab"),
htmx.Class("tab"),
htmx.Aria("label", props.Label),
htmx.If(props.Disabled, htmx.Disabled()),
htmx.If(props.Active, htmx.Checked()),
),
htmx.Div(
htmx.Merge(
htmx.ClassNames{
"tab-content": true,
"p-10": true,
},
props.ClassNames,
),
htmx.Role("tabpanel"),
htmx.Group(children...),
),
htmx.Role("tab"),
htmx.Group(children...),
)
}
32 changes: 32 additions & 0 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/zeiss/fiber-htmx/components/navbars"
"github.com/zeiss/fiber-htmx/components/swap"
"github.com/zeiss/fiber-htmx/components/tables"
"github.com/zeiss/fiber-htmx/components/tabs"
"github.com/zeiss/fiber-htmx/components/tailwind"
"github.com/zeiss/fiber-htmx/components/utils"
"github.com/zeiss/fiber-htmx/sse"
Expand Down Expand Up @@ -367,6 +368,37 @@ func (c *exampleController) Get() error {
),
),
),
htmx.Div(
htmx.ClassNames{
"bg-base-100": true,
},
tabs.TabsBoxed(
tabs.TabsProps{},
tabs.Tab(
tabs.TabProps{
Name: "my_tabs_1",
Label: "Tab 1",
Active: true,
},
htmx.Text("Tab 1"),
),
tabs.Tab(
tabs.TabProps{
Name: "my_tabs_1",
Label: "Tab 2",
},
htmx.Text("Tab 2"),
),
tabs.Tab(
tabs.TabProps{
Name: "my_tabs_1",
Label: "Tab 3",
},
htmx.Text("Tab 3"),
),
),
),

alerts.Info(
alerts.AlertProps{},
htmx.Text("Hello, World!"),
Expand Down

0 comments on commit d496a7b

Please sign in to comment.