diff --git a/packages/react-components/src/components/gif.tsx b/packages/react-components/src/components/gif.tsx index aa593a65..79a31db7 100644 --- a/packages/react-components/src/components/gif.tsx +++ b/packages/react-components/src/components/gif.tsx @@ -235,6 +235,10 @@ const Gif = ({ } }, []) const height = forcedHeight || getGifHeight(gif, width) + if (percentWidth && !percentHeight) { + const ratio = Math.round((height / width) * 100) + percentHeight = `${ratio}%` + } const bestRendition = getBestRendition(gif.images, width, height) if (!bestRendition) { if (gif.images) { diff --git a/packages/react-components/src/components/grid.tsx b/packages/react-components/src/components/grid.tsx index 72a621c6..7865d781 100644 --- a/packages/react-components/src/components/grid.tsx +++ b/packages/react-components/src/components/grid.tsx @@ -5,10 +5,12 @@ import { getGifHeight } from '@giphy/js-util' import React, { ComponentProps, ElementType, GetDerivedStateFromProps, PureComponent } from 'react' import styled from 'styled-components' import { debounce } from 'throttle-debounce' +import { fillArray } from '../util/array' import Observer from '../util/observer' import FetchError from './fetch-error' import Gif, { EventProps } from './gif' -import MasonryGrid, { fillArray } from './masonry-grid' +import DotsLoader from './loader' +import MasonryGrid from './masonry-grid' import PingbackContextManager from './pingback-context-manager' import type { GifOverlayProps } from './types' @@ -162,6 +164,7 @@ class Grid extends PureComponent { loaderConfig, tabIndex = 0, layoutType = 'GRID', + loader: LoaderVisual = DotsLoader, fetchPriority, } = this.props const { gifWidth, gifs, isError, isDoneFetching } = this.state @@ -219,16 +222,18 @@ class Grid extends PureComponent { ))} {!showLoader && gifs.length === 0 && noResultsMessage} + {isError ? ( + + ) : ( + showLoader && ( + + + + + + ) + )} - {isError ? ( - - ) : ( - showLoader && ( - - - - ) - )} ) } diff --git a/packages/react-components/src/components/masonry-grid.tsx b/packages/react-components/src/components/masonry-grid.tsx index e285115f..d0dfd0f7 100644 --- a/packages/react-components/src/components/masonry-grid.tsx +++ b/packages/react-components/src/components/masonry-grid.tsx @@ -1,8 +1,5 @@ import React, { CSSProperties, memo, ReactNode } from 'react' - -export function fillArray(length: number, columnOffsets: number[] = []) { - return Array.apply(null, Array(length)).map((_, index) => columnOffsets[index] || 0) -} +import { fillArray } from '../util/array' type Props = { totalHeight: number diff --git a/packages/react-components/src/util/array.ts b/packages/react-components/src/util/array.ts new file mode 100644 index 00000000..0f75e083 --- /dev/null +++ b/packages/react-components/src/util/array.ts @@ -0,0 +1,3 @@ +export function fillArray(length: number, columnOffsets: number[] = []) { + return Array.apply(null, Array(length)).map((_, index: number) => columnOffsets[index] || 0) +}