diff --git a/src/components/Shelf/Shelf.tsx b/src/components/Shelf/Shelf.tsx index 08dd0832c..1a5246f7b 100644 --- a/src/components/Shelf/Shelf.tsx +++ b/src/components/Shelf/Shelf.tsx @@ -69,6 +69,7 @@ const Shelf: React.FC = ({ items={playlist.playlist} tilesToShow={tilesToShow} + wrapWithEmptyTiles={featured && playlist.playlist.length === 1} cycleMode={'restart'} showControls={!matchMedia('(hover: none)').matches && !loading} transitionTime={'0.3s'} diff --git a/src/components/TileDock/TileDock.module.scss b/src/components/TileDock/TileDock.module.scss index 864d0d750..dcf699f85 100644 --- a/src/components/TileDock/TileDock.module.scss +++ b/src/components/TileDock/TileDock.module.scss @@ -25,3 +25,10 @@ transform: translateY(-100%); z-index: 1; } +.emptyTile::before { + content: ''; + display: block; + padding-top: 56.25%; + background: rgba(255, 255, 255, 0.12); + border-radius: 4px; +} diff --git a/src/components/TileDock/TileDock.tsx b/src/components/TileDock/TileDock.tsx index 14e9e8dab..72b64eb23 100644 --- a/src/components/TileDock/TileDock.tsx +++ b/src/components/TileDock/TileDock.tsx @@ -15,6 +15,7 @@ export type TileDockProps = { minimalTouchMovement?: number; showControls?: boolean; animated?: boolean; + wrapWithEmptyTiles?: boolean; transitionTime?: string; renderTile: (item: T, isInView: boolean) => JSX.Element; renderLeftControl?: (handleClick: () => void) => JSX.Element; @@ -26,7 +27,7 @@ type Tile = { key: string; }; -const makeTiles = (originalList: T[], slicedItems: T[]): Tile[] => { +const makeTiles = (originalList: T[], slicedItems: T[]): Tile[] => { const itemIndices: string[] = []; return slicedItems.map((item) => { @@ -39,7 +40,7 @@ const makeTiles = (originalList: T[], slicedItems: T[]): Tile[] => { }); }; -const sliceItems = ( +const sliceItems = ( items: T[], isMultiPage: boolean, index: number, @@ -59,19 +60,22 @@ const sliceItems = ( return makeTiles(items, itemsSlice); }; -const TileDock = ({ - items, - tilesToShow = 6, - cycleMode = 'endless', - spacing = 12, - minimalTouchMovement = 30, - showControls = true, - animated = !window.matchMedia('(prefers-reduced-motion)').matches, - transitionTime = '0.6s', - renderTile, - renderLeftControl, - renderRightControl, -}: TileDockProps) => { +const TileDock = ( + { + items, + tilesToShow = 6, + cycleMode = 'endless', + spacing = 12, + minimalTouchMovement = 30, + showControls = true, + animated = !window.matchMedia('(prefers-reduced-motion)').matches, + transitionTime = '0.6s', + wrapWithEmptyTiles = false, + renderTile, + renderLeftControl, + renderRightControl, + }: TileDockProps +) => { const [index, setIndex] = useState(0); const [slideToIndex, setSlideToIndex] = useState(0); const [transform, setTransform] = useState(-100); @@ -83,7 +87,7 @@ const TileDock = ({ const frameRef = useRef() as React.MutableRefObject; const tileWidth: number = 100 / tilesToShow; const isMultiPage: boolean = items?.length > tilesToShow; - const transformWithOffset: number = isMultiPage ? 100 - tileWidth * (tilesToShow + 1) + transform : 0; + const transformWithOffset: number = isMultiPage ? 100 - tileWidth * (tilesToShow + 1) + transform : wrapWithEmptyTiles ? -100 : 0; const tileList: Tile[] = useMemo(() => { return sliceItems(items, isMultiPage, index, tilesToShow, cycleMode); @@ -168,7 +172,7 @@ const TileDock = ({ const ulStyle = { transform: `translate3d(${transformWithOffset}%, 0, 0)`, // prettier-ignore - webkitTransform: `translate3d(${transformWithOffset}%, 0, 0)`, + WebkitTransform: `translate3d(${transformWithOffset}%, 0, 0)`, transition: transitionBasis, marginLeft: -spacing / 2, marginRight: -spacing / 2, @@ -188,9 +192,18 @@ const TileDock = ({ onTouchEnd={handleTouchEnd} onTransitionEnd={handleTransitionEnd} > + {wrapWithEmptyTiles ? ( +
  • + ) : null} {tileList.map((tile: Tile, listIndex) => { - // Todo: - // const isTabable = isAnimating || !isMultiPage || (listIndex > tilesToShow - 1 && listIndex < tilesToShow * 2); const isInView = !isMultiPage || (listIndex > tilesToShow - slideOffset && listIndex < tilesToShow * 2 + 1 - slideOffset); @@ -210,6 +223,17 @@ const TileDock = ({
  • ); })} + {wrapWithEmptyTiles ? ( +
  • + ) : null} {showRightControl && !!renderRightControl && (
    {renderRightControl(() => slide('right'))}