@@ -3,7 +3,8 @@ import React from 'react'
33import clsx from 'clsx'
44import Tabs from '@material-ui/core/Tabs'
55import Tab from '@material-ui/core/Tab'
6- import { makeStyles } from '@material-ui/core/styles'
6+ import { makeStyles , useTheme } from '@material-ui/core/styles'
7+ import useMediaQuery from '@material-ui/core/useMediaQuery'
78import Image from '../Image'
89
910export const styles = theme => ( {
@@ -35,7 +36,47 @@ export const styles = theme => ({
3536 /**
3637 * Styles applied to the root element of the Tabs element
3738 */
38- tabsRoot : {
39+ tabsRoot : { } ,
40+ /**
41+ * Styles applied the to the root element of the Tabs element when `thumbnailPosition` is `left` or `right`.
42+ */
43+ tabsVertical : {
44+ [ theme . breakpoints . up ( 'sm' ) ] : {
45+ flexDirection : 'column' ,
46+ } ,
47+ } ,
48+ /**
49+ * Styles applied to the root element of the Tabs element when `thumbnailPosition` is `left`.
50+ */
51+ tabsRootLeft : {
52+ [ theme . breakpoints . down ( 'xs' ) ] : {
53+ marginTop : theme . spacing ( 2 ) ,
54+ } ,
55+ [ theme . breakpoints . up ( 'sm' ) ] : {
56+ marginRight : theme . spacing ( 2 ) ,
57+ } ,
58+ } ,
59+ /**
60+ * Styles applied to the root element of the Tabs element when `thumbnailPosition` is `right`.
61+ */
62+ tabsRootRight : {
63+ [ theme . breakpoints . down ( 'xs' ) ] : {
64+ marginTop : theme . spacing ( 2 ) ,
65+ } ,
66+ [ theme . breakpoints . up ( 'sm' ) ] : {
67+ marginLeft : theme . spacing ( 2 ) ,
68+ } ,
69+ } ,
70+ /**
71+ * Styles applied to the root element of the Tabs element when `thumbnailPosition` is `top`.
72+ */
73+ tabsRootTop : {
74+ marginBottom : theme . spacing ( 2 ) ,
75+ } ,
76+ /**
77+ * Styles applied to the root element of the Tabs element when `thumbnailPosition` is `bottom`.
78+ */
79+ tabsRootBottom : {
3980 marginTop : theme . spacing ( 2 ) ,
4081 } ,
4182 /**
@@ -79,17 +120,34 @@ const useStyles = makeStyles(styles, { name: 'RSFCarouselThumbnails' })
79120 * be clicked to switch to the given slide. Internally, `CarouselThumbnails` uses MaterialUI's
80121 * [`Tabs`](https://material-ui.com/api/tabs) component to indicate which slide is selected
81122 */
82- function CarouselThumbnails ( { thumbnails, selected, setSelected, classes, className } ) {
123+ function CarouselThumbnails ( {
124+ thumbnails,
125+ selected,
126+ setSelected,
127+ classes,
128+ className,
129+ thumbnailPosition,
130+ } ) {
83131 const styles = useStyles ( { classes } )
132+ const theme = useTheme ( )
133+ const isSmall = useMediaQuery ( theme . breakpoints . down ( 'xs' ) )
134+ const isVertical = ! isSmall && [ 'left' , 'right' ] . includes ( thumbnailPosition )
84135
85136 return (
86137 < div className = { clsx ( className , styles . thumbs ) } >
87138 < Tabs
88139 value = { selected }
89140 variant = "scrollable"
90141 onChange = { ( _ , index ) => setSelected ( index ) }
142+ orientation = { isVertical ? 'vertical' : 'horizontal' }
91143 classes = { {
92- root : styles . tabsRoot ,
144+ root : clsx ( styles . tabsRoot , {
145+ [ styles . tabsVertical ] : isVertical ,
146+ [ styles . tabsRootLeft ] : thumbnailPosition === 'left' ,
147+ [ styles . tabsRootRight ] : thumbnailPosition === 'right' ,
148+ [ styles . tabsRootTop ] : thumbnailPosition === 'top' ,
149+ [ styles . tabsRootBottom ] : thumbnailPosition === 'bottom' ,
150+ } ) ,
93151 indicator : styles . tabsIndicator ,
94152 } }
95153 >
@@ -134,14 +192,19 @@ CarouselThumbnails.propTypes = {
134192 setSelected : PropTypes . func ,
135193
136194 /**
137- * Array of objects containing the data for an image to be used for each thumbnail
195+ * Array of objects containing the data for an image to be used for each thumbnail.
138196 */
139197 thumbnails : PropTypes . arrayOf (
140198 PropTypes . shape ( {
141199 src : PropTypes . string ,
142200 alt : PropTypes . string ,
143201 } ) ,
144202 ) ,
203+
204+ /**
205+ * Position of the thumbnails, relative to the main carousel image.
206+ */
207+ thumbnailPosition : PropTypes . oneOf ( [ 'bottom' , 'top' , 'left' , 'right' ] ) ,
145208}
146209
147210export default React . memo ( CarouselThumbnails )
0 commit comments