mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 01:41:44 +00:00
125 lines
2.2 KiB
Templ
125 lines
2.2 KiB
Templ
package elements
|
|||
|
|
|
||
|
|
import "fmt"
|
||
|
|
|
||
|
|
func Text(content string, options ...Variant) templ.Component {
|
||
|
|
if err := ValidTextVariants(options...); err != nil {
|
||
|
|
return renderParagraph(clsxMerge(TextSizeDefault, TextStyleDefault), content)
|
||
|
|
}
|
||
|
|
return renderParagraph(clsxMerge(options...), content)
|
||
|
|
}
|
||
|
|
|
||
|
|
func ValidTextVariants(variants ...Variant) error {
|
||
|
|
for _, v := range variants {
|
||
|
|
switch v.(type) {
|
||
|
|
case TextSize:
|
||
|
|
case TextStyle:
|
||
|
|
default:
|
||
|
|
return fmt.Errorf("invalid text variant: %v", v)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
templ renderHeading(attrs templ.Attributes, text string) {
|
||
|
|
<h1 { attrs... }>
|
||
|
|
{ text }
|
||
|
|
</h1>
|
||
|
|
}
|
||
|
|
|
||
|
|
templ renderParagraph(attrs templ.Attributes, text string) {
|
||
|
|
<p { attrs... }>
|
||
|
|
{ text }
|
||
|
|
</p>
|
||
|
|
}
|
||
|
|
|
||
|
|
templ renderLink(attrs templ.Attributes, text string) {
|
||
|
|
<a { attrs... }>
|
||
|
|
{ text }
|
||
|
|
</a>
|
||
|
|
}
|
||
|
|
|
||
|
|
templ renderStrong(attrs templ.Attributes, text string) {
|
||
|
|
<strong { attrs... }>
|
||
|
|
{ text }
|
||
|
|
</strong>
|
||
|
|
}
|
||
|
|
|
||
|
|
templ renderEmphasis(attrs templ.Attributes, text string) {
|
||
|
|
<em { attrs... }>
|
||
|
|
{ text }
|
||
|
|
</em>
|
||
|
|
}
|
||
|
|
|
||
|
|
templ renderCode(attrs templ.Attributes, text string) {
|
||
|
|
<code { attrs... }>
|
||
|
|
{ text }
|
||
|
|
</code>
|
||
|
|
}
|
||
|
|
|
||
|
|
type TextSize int
|
||
|
|
|
||
|
|
const (
|
||
|
|
TextSizeDefault TextSize = iota
|
||
|
|
TextSizeSmall
|
||
|
|
TextSizeMedium
|
||
|
|
TextSizeLarge
|
||
|
|
)
|
||
|
|
|
||
|
|
func (s TextSize) Attributes() templ.Attributes {
|
||
|
|
switch s {
|
||
|
|
case TextSizeSmall:
|
||
|
|
return templ.Attributes{
|
||
|
|
"class": "text-sm",
|
||
|
|
}
|
||
|
|
case TextSizeLarge:
|
||
|
|
return templ.Attributes{
|
||
|
|
"class": "text-xl",
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return templ.Attributes{
|
||
|
|
"class": "text-md",
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
type TextStyle int
|
||
|
|
|
||
|
|
const (
|
||
|
|
TextStyleDefault TextStyle = iota
|
||
|
|
TextStyleHeading
|
||
|
|
TextStyleParagraph
|
||
|
|
TextStyleLink
|
||
|
|
TextStyleStrong
|
||
|
|
TextStyleEmphasis
|
||
|
|
TextStyleCode
|
||
|
|
)
|
||
|
|
|
||
|
|
func (s TextStyle) Attributes() templ.Attributes {
|
||
|
|
switch s {
|
||
|
|
case TextStyleHeading:
|
||
|
|
return templ.Attributes{
|
||
|
|
"class": "text-xl font-bold text-xl",
|
||
|
|
}
|
||
|
|
case TextStyleParagraph:
|
||
|
|
return templ.Attributes{
|
||
|
|
"class": "text-base font-normal",
|
||
|
|
}
|
||
|
|
case TextStyleLink:
|
||
|
|
return templ.Attributes{
|
||
|
|
"class": "text-blue-600 font-medium underline",
|
||
|
|
}
|
||
|
|
case TextStyleStrong:
|
||
|
|
return templ.Attributes{
|
||
|
|
"class": "font-semibold text-md",
|
||
|
|
}
|
||
|
|
case TextStyleCode:
|
||
|
|
return templ.Attributes{
|
||
|
|
"class": "text-stone-800 font-mono",
|
||
|
|
}
|
||
|
|
default:
|
||
|
|
return templ.Attributes{
|
||
|
|
"class": "text-base font-normal text-md",
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|