67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package line
|
|
|
|
import "errors"
|
|
|
|
// BubbleContainer -
|
|
type BubbleContainer struct {
|
|
Type string `json:"type"`
|
|
Direction NullString `json:"direction"`
|
|
Header *BoxComponent `json:"header,omitempty"`
|
|
Hero *ImageComponent `json:"hero,omitempty"`
|
|
Body *BoxComponent `json:"body,omitempty"`
|
|
Footer *BoxComponent `json:"footer,omitempty"`
|
|
Styles interface{} `json:"styles,omitempty"`
|
|
}
|
|
|
|
// CarouselContainer -
|
|
type CarouselContainer struct {
|
|
Type string `json:"type"`
|
|
Contents []*BubbleContainer `json:"contents"`
|
|
}
|
|
|
|
// NewBubbleContainer -
|
|
func NewBubbleContainer(direction string) *BubbleContainer {
|
|
obj := &BubbleContainer{}
|
|
obj.Type = "bubble"
|
|
|
|
switch direction {
|
|
case "ltr":
|
|
case "rtl":
|
|
obj.Direction = String(direction)
|
|
default:
|
|
obj.Direction = String("ltr")
|
|
}
|
|
|
|
return obj
|
|
}
|
|
|
|
// NewCarouselContainer -
|
|
func NewCarouselContainer() *CarouselContainer {
|
|
obj := &CarouselContainer{}
|
|
obj.Type = "carousel"
|
|
|
|
return obj
|
|
}
|
|
|
|
// AddContent -
|
|
func (p *CarouselContainer) AddContent(items ...*BubbleContainer) (err error) {
|
|
if len(items) == 0 {
|
|
return errors.New("no item")
|
|
}
|
|
if len(items) > 10 {
|
|
return errors.New("too many items")
|
|
}
|
|
if len(items)+len(p.Contents) > 10 {
|
|
return errors.New("too many items")
|
|
}
|
|
|
|
for _, v := range items {
|
|
if v == nil {
|
|
continue
|
|
}
|
|
p.Contents = append(p.Contents, v)
|
|
}
|
|
|
|
return
|
|
}
|