Skip to content

Commit

Permalink
Improved proptypes
Browse files Browse the repository at this point in the history
  • Loading branch information
iaron committed Oct 23, 2019
1 parent baeb8b1 commit a465286
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
4 changes: 2 additions & 2 deletions react/Shelf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import OrdenationTypes, {
import ProductList from './components/ProductList'
import { productListSchemaPropTypes } from './utils/propTypes'
import productsQuery from './queries/productsQuery.gql'
import ShelfContent from './components/ShelfContent'
import { shelfContentPropTypes } from './utils/propTypes'

import { parseToProductImpression, normalizeBuyable } from './utils/normalize'

Expand Down Expand Up @@ -89,7 +89,7 @@ const Shelf = ({ data, productList = ProductList.defaultProps, paginationDotsVis
Shelf.propTypes = {
/** Graphql data response. */
data: PropTypes.shape({
products: ShelfContent.propTypes.products,
products: shelfContentPropTypes.products,
}),
/** Category Id. */
category: PropTypes.string,
Expand Down
31 changes: 12 additions & 19 deletions react/components/ShelfContent.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import PropTypes from 'prop-types'
import { path } from 'ramda'
import React, { Component } from 'react'
import { IconCaret } from 'vtex.store-icons'
import classNames from 'classnames'
import { NoSSR } from 'vtex.render-runtime'
import { Slider, Slide, Dots, SliderContainer } from 'vtex.slider'
import { withCssHandles } from 'vtex.css-handles'
import { getGapPaddingValues } from '../utils/paddingEnum'
import { resolvePaginationDotsVisibility } from '../utils/resolvePaginationDots'
import ScrollTypes from '../utils/ScrollTypes'
import ShelfItem from './ShelfItem'
import { shelfItemPropTypes } from '../utils/propTypes'
import { shelfContentPropTypes } from '../utils/propTypes'
import shelf from './shelf.css'

const CSS_HANDLES = ['arrow', 'arrowLeft', 'arrowRight', 'shelfContentContainer', 'sliderContainer', 'slide']
Expand Down Expand Up @@ -165,32 +163,27 @@ ShelfContent.defaultProps = {

ShelfContent.propTypes = {
/** List of products */
products: PropTypes.arrayOf(shelfItemPropTypes.item),
products: shelfContentPropTypes.products,
/** Max Items per page */
itemsPerPage: PropTypes.number.isRequired,
itemsPerPage: shelfContentPropTypes.itemsPerPage,
/** Minimum Items per page */
minItemsPerPage: PropTypes.number.isRequired,
minItemsPerPage: shelfContentPropTypes.minItemsPerPage,
/** Max items in shelf */
maxItems: PropTypes.number.isRequired,
maxItems: shelfContentPropTypes.maxItems,
/** Show Arrows */
arrows: PropTypes.bool.isRequired,
arrows: shelfContentPropTypes.arrows,
/** Scroll type */
scroll: PropTypes.string.isRequired,
scroll: shelfContentPropTypes.scroll,
/** Should display navigation dots below the Shelf */
paginationDotsVisibility: PropTypes.oneOf([
'visible',
'hidden',
'desktopOnly',
'mobileOnly',
]),
paginationDotsVisibility: shelfContentPropTypes.paginationDotsVisibility,
/** Container width */
width: PropTypes.number,
width: shelfContentPropTypes.width,
/** Props to ProductsSummary */
summary: PropTypes.any,
summary: shelfContentPropTypes.summary,
/** Is mobile */
isMobile: PropTypes.bool,
isMobile: shelfContentPropTypes.isMobile,
/** Gap between Shelf Items */
gap: PropTypes.oneOf(getGapPaddingValues()),
gap: shelfContentPropTypes.gap,
}

export default withCssHandles(CSS_HANDLES)(ShelfContent)
31 changes: 31 additions & 0 deletions react/utils/propTypes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types'

import { getScrollValues } from './ScrollTypes'
import { getGapPaddingValues } from './paddingEnum'

export const shelfItemPropTypes = {
item: PropTypes.shape({
Expand Down Expand Up @@ -74,3 +75,33 @@ export const productListSchemaPropTypes = {
/** Product Summary schema props */
summary: PropTypes.any,
}

export const shelfContentPropTypes = {
/** List of products */
products: PropTypes.arrayOf(shelfItemPropTypes.item),
/** Max Items per page */
itemsPerPage: PropTypes.number.isRequired,
/** Minimum Items per page */
minItemsPerPage: PropTypes.number.isRequired,
/** Max items in shelf */
maxItems: PropTypes.number.isRequired,
/** Show Arrows */
arrows: PropTypes.bool.isRequired,
/** Scroll type */
scroll: PropTypes.string.isRequired,
/** Should display navigation dots below the Shelf */
paginationDotsVisibility: PropTypes.oneOf([
'visible',
'hidden',
'desktopOnly',
'mobileOnly',
]),
/** Container width */
width: PropTypes.number,
/** Props to ProductsSummary */
summary: PropTypes.any,
/** Is mobile */
isMobile: PropTypes.bool,
/** Gap between Shelf Items */
gap: PropTypes.oneOf(getGapPaddingValues()),
}

0 comments on commit a465286

Please sign in to comment.