Package carousel

import "gitlab.com/zoralab/bissetii/pkg/components/internal/carousel"

Package carousel is for rendering the default horizontal slide carousel.

The HTML template codes are written in Go’s string format under the corresponding group. This allows one to embed the HTML codes instead of parsing it from file.

Constants

All Bissetii Compressed Compiled CSS

const (
	CSSAMP = `amp-carousel{background-color:transparent;margin:0 0 3rem}`

	CSSCritical = `@-webkit-keyframes carousel-animate-to-next{75%,99%{left:0%}95%,98%{left:100%}}@-moz-keyframes carousel-animate-to-next{75%,99%{left:0%}95%,98%{left:100%}}@-ms-keyframes carousel-animate-to-next{75%,99%{left:0%}95%,98%{left:100%}}@-o-keyframes carousel-animate-to-next{75%,99%{left:0%}95%,98%{left:100%}}@keyframes carousel-animate-to-next{75%,99%{left:0%}95%,98%{left:100%}}@-webkit-keyframes carousel-animate-to-start{75%,99%{left:0}95%,98%{left:-300%}}@-moz-keyframes carousel-animate-to-start{75%,99%{left:0}95%,98%{left:-300%}}@-ms-keyframes carousel-animate-to-start{75%,99%{left:0}95%,98%{left:-300%}}@-o-keyframes carousel-animate-to-start{75%,99%{left:0}95%,98%{left:-300%}}@keyframes carousel-animate-to-start{75%,99%{left:0}95%,98%{left:-300%}}@-webkit-keyframes carousel-animate-snap{96%,100%{scroll-snap-align:center}97%,99%{scroll-snap-align:none}}@-moz-keyframes carousel-animate-snap{96%,100%{scroll-snap-align:center}97%,99%{scroll-snap-align:none}}@-ms-keyframes carousel-animate-snap{96%,100%{scroll-snap-align:center}97%,99%{scroll-snap-align:none}}@-o-keyframes carousel-animate-snap{96%,100%{scroll-snap-align:center}97%,99%{scroll-snap-align:none}}@keyframes carousel-animate-snap{96%,100%{scroll-snap-align:center}97%,99%{scroll-snap-align:none}}.Carousel{display:block;height:fit-content;padding:0;perspective:2rem;background-color:transparent;margin:0 0 3rem}.Carousel ol,.Carousel ul{padding:0;margin:0;list-style-type:none}.Carousel nav{background-color:transparent}.Carousel .viewport{display:flex;width:100%;height:100%;counter-reset:item;overflow:scroll hidden;scroll-behavior:smooth;scroll-snap-type:x mandatory;position:absolute;top:0;right:0;bottom:0;left:0}.Carousel .viewport li{position:relative;flex:0 0 100%;counter-increment:item;width:100%;height:100%}.Carousel .viewport li article,.Carousel .viewport li article>*{width:100%;height:100%;object-fit:contain}.Carousel .viewport li nav{position:absolute;top:0;left:0;width:100%;height:100%;scroll-snap-align:center;animation-name:carousel-animate-to-next,carousel-animate-snap;animation-timing-function:ease;animation-duration:5s;animation-iteration-count:infinite}.Carousel .viewport li nav a{position:absolute;top:50%;width:30%;height:100%;font-size:0;border:none;outline:0;transform:translateY(-50%)}.Carousel .viewport li nav a.next{right:-1rem}.Carousel .viewport li nav a.previous{left:-1rem}.Carousel .viewport li:last-child nav{animation-name:carousel-animate-to-start,carousel-animate-snap}.Carousel nav.nav-panel{position:absolute;bottom:2rem;left:0;right:0;text-align:center}.Carousel nav.nav-panel ol,.Carousel nav.nav-panel ol li,.Carousel nav.nav-panel ul,.Carousel nav.nav-panel ul li{display:inline-block}.Carousel nav.nav-panel ol a,.Carousel nav.nav-panel ol li a,.Carousel nav.nav-panel ul a,.Carousel nav.nav-panel ul li a{display:inline-block;margin:var(--margin-carousel-nav-panel-anchor);width:var(--width-height-carousel-nav-panel-anchor);height:var(--width-height-carousel-nav-panel-anchor);background-color:var(--background-color-carousel-nav-panel-anchor);background-clip:content-box;border:none;border-radius:50%;font-size:0;-webkit-transition:var(--transition-carousel-nav-panel-anchor);-ms-transition:var(--transition-carousel-nav-panel-anchor);-moz-transition:var(--transition-carousel-nav-panel-anchor);-o-transition:var(--transition-carousel-nav-panel-anchor);transition:var(--transition-carousel-nav-panel-anchor)}.Carousel:hover .viewport li nav,.Carousel:focus-within .viewport li nav{animation-name:none}`

	CSSTablet     = ``

	CSSDesktop    = ``

	CSSWidescreen = ``

	CSSPrint      = ``
)

Constants for managing the package as a whole.

const (
	// Name is the block name (`{{- define "this-name" -}}`).
	Name = "Carousel"

	// AMPName is the AMP HTML block name.
	AMPName = root.AMPPrefix + Name

	// ParametersComment are the list of comment headers
	// describing inputs.
	ParametersComment = `
{{- /* .Label             = Carousel name (used in aria-label)          */ -}}
{{- /* .Class             = Carousel class attribute                    */ -}}
{{- /* .Timing            = Carousel timing                             */ -}}
{{- /* .Autoplay          = Carousel autoplay flag (true/false)         */ -}}
{{- /* .Height            = Carousel height                             */ -}}
{{- /* .Width             = Carousel width                              */ -}}
{{- /* .Layout            = Carousel style layout (used in AMP)         */ -}}
{{- /* .Slides            = Carousel slides list                        */ -}}
{{- /*      .ID           = Slide ID                                    */ -}}
{{- /*      .Content      = Slide Content                               */ -}}
{{- /*      .Next         = Next slide                                  */ -}}
{{- /*      .Previous     = Previous slide                              */ -}}
`
)

Dependencies are the dependent codes for building independent template.

This is useful for rendering portable template usage like Hugo partials where they do not share a common definition source.

const (
	// DepHTML is the vanilla HTML output type.
	DepHTML = ``

	// DepAMPHTML is the Accelerated Mobile Pages HTML output
	// type.
	DepAMPHTML = ``
)

Full HTML codes for rendering templates without needing to parse file.

const (
	// HTML is the vanilla HTML output type.
	HTML = `
<section class="Carousel {{- if .Class}} {{ .Class -}}{{- end -}}"

	aria-label="{{- .Label -}}"
{{- if or .Width .Height }}

	style="

	{{- if .Height }}

		min-height: {{- .Height -}};

		height: {{- .Height -}};

	{{- end }}

	{{- if .Width }}

		min-width: {{- .Width -}};

		width: {{- .Width -}};

	{{- end -}}
"
{{- end -}}>

	<ol class="viewport">
{{- range $slide := .Slides }}

		<li id="{{- $slide.ID -}}">

			<article>{{- $slide.Content -}}</article>

			<nav>

				<a class="previous"

					href="#{{- $slide.Previous.ID -}}">

					{{- $slide.Previous.ID -}}

				</a>

				<a class="next"

					href="#{{- $slide.Next.ID -}}">

					{{- $slide.Next.ID -}}

				</a>

			</nav>

		</li>
{{- end }}

	</ol>
<nav class="nav-panel"><ol>
{{- range $slide := .Slides }}

	<li><a href="#{{- $slide.ID -}}">{{- $slide.ID -}}</a></li>
{{- end }}
</ol></nav>
</section>
`

	// AMPHTML is the Accelerated Mobile Pages HTML output type.
	AMPHTML = `
<amp-carousel width="{{- .Width -}}"

	height="{{- .Height -}}"

	layout="{{- .Layout -}}"

	type="slides"
{{- if .Autoplay }}

	autoplay
{{- end }}

	delay="{{- .Timing -}}">
{{- range $slide := .Slides }}

	<article>{{- $slide.Content -}}</article>
{{- end }}
</amp-carousel>
`
)

Data

type Data struct {
	Label    string
	Class    string
	Timing   string
	Autoplay bool
	Height   string
	Width    string
	Layout   string
	Slides   []Slide
}

Data is the data structure for rendering the component.

Slide

type Slide struct {
	ID       string
	Content  string
	Next     *Slide
	Previous *Slide
}

Slide is a single content data for each carousel slide.