Documentation
Feedback
Guides
VTEX IO Apps

VTEX IO Apps
VTEX Slider
Official extension
Version: 0.8.3
Latest version: 0.8.3

Description

The VTEX Slider is a slider that aims a good support for SSR and can display one or more slides per page.

:loudspeaker: Disclaimer: Don't fork this project; use, contribute, or open issue with your feature request

Table of Contents

Usage

To import it you can add to you manifest.json the following:


_10
{
_10
"dependencies": {
_10
"vtex.slider": "0.x"
_10
}
_10
}

And then in your component you can import the components exported from the slider:


_10
import { Slider, Slide } from 'vtex.slider'

You can use it in your code like a React component with the jsx tags:


_21
_21
handleChangeSlide = i => {
_21
this.setState({ currentSlide: i })
_21
}
_21
_21
render() {
_21
const { currentSlide } = this.state
_21
// ...
_21
_21
const { myProducts } = this.props
_21
_21
return (
_21
<Slider currentSlide={currentSlide} onChangeSlide={this.handleChangeSlide}>
_21
{myProducts.map(product => (
_21
<Slide key={product.id}>
_21
<DisplayProductComponent product={product} />
_21
</Slide>
_21
))}
_21
</Slider>
_21
)
_21
}

If you want to show multiple items in the same page at the same time you can use the prop perPage:


_28
render() {
_28
const { currentSlide } = this.state
_28
const { myProducts } = this.props
_28
_28
// The keys of the object represent the size of the window in px.
_28
// In this case if the window is 1300px large or bigger it will show 5 items,
_28
// If it has 900px or any size until 1299px it will show 4 items
_28
const perPage = {
_28
1300: 5,
_28
900: 4,
_28
700: 2,
_28
600: 1,
_28
}
_28
_28
return (
_28
<Slider
_28
currentSlide={currentSlide}
_28
onChangeSlide={this.handleChangeSlide}
_28
perPage={perPage}
_28
>
_28
{myProducts.map(product => (
_28
<Slide key={product.id}>
_28
<DisplayProductComponent product={product} />
_28
</Slide>
_28
))}
_28
</Slider>
_28
)
_28
}

Bellow is an example with all the components together:


_68
arrowRender = ({ orientation, onClick }) => {
_68
return (
_68
<div className="arrow-container-class" onClick={onClick}>
_68
<MyArrowComponent orientation={orientation} />
_68
</div>
_68
)
_68
}
_68
_68
arrowContainerRender = ({ children }) => {
_68
return (
_68
<MyContainerComponent>
_68
{children}
_68
</MyContainerComponent>
_68
)
_68
}
_68
_68
render() {
_68
const { currentSlide } = this.state
_68
const { myProducts } = this.props
_68
_68
const perPage = {
_68
1300: 5,
_68
1100: 4,
_68
900: 3,
_68
700: 2,
_68
300: 1
_68
}
_68
_68
return (
_68
<SliderContainer className="mw9">
_68
<Slider
_68
loop
_68
easing="ease"
_68
duration={500}
_68
perPage={perPage}
_68
currentSlide={currentSlide}
_68
arrowRender={this.arrowRender}
_68
onChangeSlide={this.handleChangeSlide}
_68
arrowsContainerComponent={this.arrowContainerRender}
_68
>
_68
{myProducts.map(product => (
_68
<Slide
_68
className="slide-css-class"
_68
sliderTransitionDuration={500}
_68
key={product.id}
_68
defaultWidth={280}
_68
>
_68
<ProductComponent product={product} />
_68
</Slide>
_68
))}
_68
</Slider>
_68
<Dots
_68
loop
_68
showDotsPerPage
_68
perPage={this.perPage}
_68
currentSlide={currentSlide}
_68
totalSlides={myProducts.length}
_68
onChangeSlide={this.handleChangeSlide}
_68
classes={{
_68
root: 'pv4',
_68
notActiveDot: 'bg-muted-3',
_68
dot: 'dot pointer br-100',
_68
activeDot: 'bg-emphasis'
_68
}}
_68
/>
_68
</SliderContainer>
_68
)
_68
}

Configuration

Slider

Prop nameTypeisRequireddefaultValueDescription
arrowRenderfunc:no_entry_sign::no_entry_sign:A render function that will receive as props an orientation prop and an onClick callback
arrowsContainerComponentfunc/string:no_entry_sign::no_entry_sign:The component used to contain both arrows. Either a string to use a DOM element or a component
childrenelement/array:heavy_check_mark::no_entry_sign:The slides to render
classesobject:no_entry_sign:No extra classes applied to any elementClasses to apply to the Slider elements
currentSlidenumber:no_entry_sign:0Current slide on the screen, if you have perPage > 1, then the current slide is the most left slide on the screen (You should not use this variable to display the index of the slide on the screen if you're using loop={true}).
cursorstring:no_entry_sign:'-webkit-grab'Css value of cursor when mouse is hovering the slider frame
cursorOnMouseDownstring:no_entry_sign:'-webkit-grabbing'Css value of cursor when mouse is down
durationnumber:no_entry_sign:250Duration of transitions
easingstring:no_entry_sign:'ease-out'Transition function
loopbool:no_entry_sign:falseIf the slides should be looping
onChangeSlidefunc:heavy_check_mark::no_entry_sign:Function to change the value of currentSlide. The function should expect a number as it's only parameter
perPagenumber/object:no_entry_sign:1Amount of slides to be on the screen, if a number is passed, then that's the number of slides that will be shown, if an object with breakpoints is passed, then the component will check the size of the screen to see how many slides will be on the screen at the same time
minPerPagenumber:no_entry_sign:1Minimum amount of slides to be on the screen, can be used to control how many itens will be displayed in the smallest screen size
resizeDebouncenumber:no_entry_sign:250Resize debounce timer in milliseconds
rootTagstring:no_entry_sign:'div'Tag to be rendered in the root of the slider
sliderFrameTagstring:no_entry_sign:'ul'Tag to be rendered in the slider frame element
thresholdnumber:no_entry_sign:50Minimum of pixels to drag until the slider change the currentSlide
navigationStepnumber | 'page':no_entry_sign:'page'How many elements should pass when you click in the arrows to navigate

Slide

Prop nameTypeisRequireddefaultValueDescription
childrennode:heavy_check_mark::no_entry_sign:Node to render
classNamestring:no_entry_sign::no_entry_sign:Classes to pass to the root element of the Slide
defaultWidthnumber:no_entry_sign::no_entry_sign:Default width of the slide (only applied in the first render)
tagstring:no_entry_sign:liTag to be rendered in the root element
fitImgbool:no_entry_sign:trueIf the slide component should try to fit the img (only works if children is an img element)
resizeDebouncenumber:no_entry_sign:250Time of debounce of resize event listener
sliderTransitionDurationnumber:no_entry_sign:250Duration of transition passed to Slider (must be the same), if nothing is passed to any of the components it will apply the same default value

SliderContainer

Prop nameTypeisRequireddefaultValueDescription
autoplaybool:no_entry_sign:falseIf the slider should be passing automatically
autoplayIntervalnumber:no_entry_sign:5000Time in milliseconds of the interval to change the currentSlider
childrennode:heavy_check_mark::no_entry_sign:Children of the component to render
classNamestring:no_entry_sign::no_entry_sign:Classes to be applied to the root element
onNextSlidefunc:no_entry_sign::no_entry_sign:Function to be called if autoplay={true}
pauseOnHoverbool:no_entry_sign:trueIf the interval should not be executed when the mouse is hovering the component
tagstring:no_entry_sign:'div'Tag to render the component

Dots

Prop nameTypeisRequireddefaultValueDescription
classesobject:no_entry_sign:No extra classes applied to any elementClasses to style the elements of the component
dotPropsobject:no_entry_sign::no_entry_sign:Extra props to be applied to the dot element
dotSizenumber/string:no_entry_sign::no_entry_sign:The size of the dots, can be a number (in this case it will use px unit), or a string (you have to pass the number with the unit e.g '3rem')
dotTagstring:no_entry_sign:'li'Tag to be rendered in the dot element
loopbool:no_entry_sign:falseIf the slides should be looping
onChangeSlidefunc:heavy_check_mark::no_entry_sign:Function to change the currentSlide
perPagenumber/object:no_entry_sign:1This prop works the same way the perPage of Slider and this component should receive the same value of Slider
resizeDebouncenumber:no_entry_sign:250Debounce time in milliseconds
rootTagstring:no_entry_sign:'ul'Tag to be rendered as the root element of the component
totalSlidesnumber:heavy_check_mark::no_entry_sign:Total value of sliders that will be rendered
minPerPagenumber:no_entry_sign:1This prop works the same way the minPerPage of Slider and this component should receive the same value of Slider
showDotsPerPagebool:no_entry_sign:falseIf this frag is true, then every dot represent a page of slides (e.g. if perPage = 2 and you have 4 elements, then you have 2 dots), if false, then it will render one dot to each slide

Styles API

You can style this app by using the props classeName and classes of the components. But if you want to style every slider of your app you need to use the CSS namespaces to do it.

CSS namespaces

:construction: :construction: :construction:

Tests

{"base64":"  ","img":{"width":99,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","length":724,"url":"https://s3.amazonaws.com/assets.coveralls.io/badges/coveralls_48.svg"}}

Travis CI

{"base64":"  ","img":{"width":98,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","length":730,"url":"https://api.travis-ci.com/vtex-apps/slider.svg?branch=master"}}

See also
VTEX App Store
VTEX IO Apps