Skip to content

Commit

Permalink
feat(radio): radio colors
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Apr 14, 2024
1 parent 1af7353 commit 78b2678
Showing 1 changed file with 133 additions and 4 deletions.
137 changes: 133 additions & 4 deletions components/forms/radio.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import htmx "github.com/zeiss/fiber-htmx"

// RadioProps represents the properties for a radio element.
type RadioProps struct {
ClassNames map[string]bool // The class names for the radio element.
ClassNames htmx.ClassNames // The class names for the radio element.
Name string // The name of the radio element.
Value string // The value of the radio element.
Checked bool // Whether the radio element is checked.
Expand All @@ -13,9 +13,138 @@ type RadioProps struct {
// Radio generates a radio element based on the provided properties.
func Radio(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.ClassNames{
"radio": true,
}.Merge(p.ClassNames),
htmx.Merge(
htmx.ClassNames{
"radio": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}

// RadioSuccess component represents a successful radio element.
func RadioSuccess(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
"radio-success": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}

// RadioInfo component represents a info radio element.
func RadioInfo(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
"radio-info": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}

// RadioWarning component represents a warning radio element.
func RadioWarning(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
"radio-warning": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}

// RadioError component represents an error radio element.
func RadioError(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
"radio-error": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}

// RadioPrimary component represents a primary radio element.
func RadioPrimary(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
"radio-primary": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}

// RadioSecondary component represents a secondary radio element.
func RadioSecondary(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
"radio-secondary": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}

// RadioAccent component represents an accent radio element.
func RadioAccent(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
"radio-accent": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
Expand Down

0 comments on commit 78b2678

Please sign in to comment.