Skip to content

Commit

Permalink
Add classnames
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusps committed May 24, 2019
1 parent 0f3c9bb commit 57cbd90
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 40 deletions.
5 changes: 2 additions & 3 deletions react/next/components/Arrow.tsx
@@ -1,4 +1,5 @@
import React, { memo, FC, ComponentType } from 'react'
import csx from 'classnames'
import { IconCaret } from 'vtex.store-icons'

import Clickable from './Clickable'
Expand All @@ -16,9 +17,7 @@ const Arrow: FC<Props> = props => {
const { custom, orientation, action, className, controls, disabled } = props
return (
<Clickable
className={`${className} ${
orientation === 'left' ? 'left-1' : 'right-1'
}`}
className={csx(className, orientation === 'left' ? 'left-1' : 'right-1')}
onClick={() => action()}
aria-controls={controls}
aria-label={`${orientation === 'left' ? 'Previous' : 'Next'} Slide`}
Expand Down
6 changes: 5 additions & 1 deletion react/next/components/Clickable.tsx
@@ -1,4 +1,5 @@
import React, { FC } from 'react'
import csx from 'classnames'
import { Button } from '../typings/global'

/**
Expand All @@ -10,7 +11,10 @@ const Clickable: FC<Button> = props => {

return (
<button
className={`${className} absolute ma2 transparent flex items-center justify-center bn outline-0 pointer`}
className={csx(
className,
'absolute ma2 transparent flex items-center justify-center bn outline-0 pointer'
)}
style={{
background: 'transparent',
...style,
Expand Down
11 changes: 7 additions & 4 deletions react/next/components/Dots.tsx
@@ -1,4 +1,5 @@
import React, { memo, FC } from 'react'
import csx from 'classnames'

const DOTS_DEFAULT_SIZE = 0.625

Expand Down Expand Up @@ -98,12 +99,14 @@ const Dots: FC<Props> = props => {
index === getSelectedDot(passVisibleSlides, currentSlide, slidesToShow)
return (
<div
className={`${classNames!.dot} ${
isActive ? 'bg-emphasis' : 'bg-muted-3'
} grow dib br-100 pa2 mr2 ml2 bw0 pointer outline-0`}
className={csx(
classNames!.dot,
isActive ? 'bg-emphasis' : 'bg-muted-3',
'grow dib br-100 pa2 mr2 ml2 bw0 pointer outline-0'
)}
style={{
height: `${DOTS_DEFAULT_SIZE}rem`,
width: `${DOTS_DEFAULT_SIZE}rem`
width: `${DOTS_DEFAULT_SIZE}rem`,
}}
key={index}
tabIndex={index}
Expand Down
3 changes: 2 additions & 1 deletion react/next/components/Slide.tsx
@@ -1,4 +1,5 @@
import React, { FC } from 'react'
import csx from 'classnames'
import { Div } from '../typings/global'

interface Props extends Div {
Expand All @@ -12,7 +13,7 @@ const Slide: FC<Props> = props => {
const { width, style, className, children, ...rest } = props
return (
<div
className={`${className} flex relative`}
className={csx(className, 'flex relative')}
style={{
width: `${width}px`,
...style,
Expand Down
3 changes: 2 additions & 1 deletion react/next/components/SliderTrack.tsx
@@ -1,4 +1,5 @@
import React, { FC } from 'react'
import csx from 'classnames'
import { transitionType, Div } from '../typings/global'

interface Props extends Div {
Expand All @@ -15,7 +16,7 @@ const SliderTrack: FC<Props> = ({
...rest
}) => (
<div
className={`${className} flex relative pa0 ma0`}
className={csx(className, 'flex relative pa0 ma0')}
style={{
willChange: 'transform',
transition: `transform ${transition.speed}ms ${transition.timing}`,
Expand Down
46 changes: 24 additions & 22 deletions react/next/components/Thumbnails.tsx
@@ -1,4 +1,5 @@
import React, { memo, FC } from 'react'
import csx from 'classnames'

interface Props {
currentSlide: number
Expand All @@ -24,38 +25,39 @@ interface Props {
const Thumbnails: FC<Props> = props => {
const { goToSlide, thumbnails, currentSlide, controls, classNames } = props

const getThumbClass = (index: number) =>
`${classNames!.thumbnail} ${
currentSlide === index
? `${classNames!.selectedThumbnail} ba bw1 b--emphasis `
: ''
} pointer ma2 h-auto w-90`
const selectedThumbClass = csx(
classNames!.selectedThumbnail,
'ba bw1 b--emphasis'
)

const renderTumbnails = () => {
const { items } = thumbnails!
return items.map((item, i) => (
<img
src={item.url}
key={item.forSlide}
className={getThumbClass(item.forSlide)}
onClick={() => goToSlide(item.forSlide)}
role="button"
ria-controls={controls}
aria-label={`Thumbnail ${i + 1} of ${items!.length}`}
/>
))
}
const getThumbClass = (index: number) =>
csx(
classNames!.thumbnail,
'pointer ma2 h-auto w-90',
currentSlide === index && selectedThumbClass
)

return (
<div
className={`${classNames!.thumbnails} flex flex-column justify-start`}
className={csx(classNames!.thumbnails, 'flex flex-column justify-start')}
style={{
width: thumbnails!.width,
}}
role="group"
aria-label="Carousel Tumbnails"
>
{renderTumbnails()}
{thumbnails &&
thumbnails.items.map((item, i) => (
<img
src={item.url}
key={item.forSlide}
className={getThumbClass(item.forSlide)}
onClick={() => goToSlide(item.forSlide)}
role="button"
ria-controls={controls}
aria-label={`Thumbnail ${i + 1} of ${thumbnails.items!.length}`}
/>
))}
</div>
)
}
Expand Down
15 changes: 9 additions & 6 deletions react/next/index.tsx
@@ -1,4 +1,5 @@
import React, { FC, useReducer, useRef, useEffect } from 'react'
import csx from 'classnames'

import { SliderProps } from './typings/global'
import { getItemClientSideWidth, populateSlides } from './utils/index'
Expand Down Expand Up @@ -189,7 +190,7 @@ const SliderNext: FC<SliderProps> = props => {
)
}

const renderTumbnails = (): React.ReactNode => {
const renderThumbnails = (): React.ReactNode => {
return (
<Thumbnails
{...state}
Expand All @@ -213,11 +214,13 @@ const SliderNext: FC<SliderProps> = props => {

const hasThumbsleft = props.thumbnails && props.thumbnails.position === 'left'

const containerClasses = `${props.classNames!.sliderContainer} flex w-100`
const containerClasses = csx(props.classNames!.sliderContainer, 'flex w-100')

const sliderContainerClasses = `${
props.classNames!.sliderContainer
} ${hasThumbsleft && 'order-1'} flex items-center relative overflow-hidden`
const sliderContainerClasses = csx(
props.classNames!.sliderContainer,
hasThumbsleft && 'order-1',
'flex items-center relative overflow-hidden'
)

return (
<section
Expand Down Expand Up @@ -247,7 +250,7 @@ const SliderNext: FC<SliderProps> = props => {
{shouldShowArrows && renderRightArrow()}
{props.showDots && renderDotsList()}
</div>
{props.thumbnails && renderTumbnails()}
{props.thumbnails && renderThumbnails()}
</section>
)
}
Expand Down
2 changes: 0 additions & 2 deletions react/next/typings/global.d.ts
Expand Up @@ -69,8 +69,6 @@ interface SliderProps {
showDots?: boolean
/** Custom transition */
transition?: transitionType
/** If should show tumbnails or not */
showTumbnails?: boolean
/** Thumbnails props */
thumbnails?: {
/** Array of thumbnails */
Expand Down

0 comments on commit 57cbd90

Please sign in to comment.