diff --git a/.changeset/ten-jeans-clap.md b/.changeset/ten-jeans-clap.md new file mode 100644 index 00000000..881d4186 --- /dev/null +++ b/.changeset/ten-jeans-clap.md @@ -0,0 +1,5 @@ +--- +'@giphy/react-components': minor +--- + +add fetchpriority prop to Gif component diff --git a/packages/react-components/src/components/carousel.tsx b/packages/react-components/src/components/carousel.tsx index 9b659420..918edf46 100644 --- a/packages/react-components/src/components/carousel.tsx +++ b/packages/react-components/src/components/carousel.tsx @@ -2,7 +2,7 @@ import { gifPaginator, GifsResult } from '@giphy/js-fetch-api' import { IGif, IUser } from '@giphy/js-types' import { getGifWidth } from '@giphy/js-util' -import React, { ElementType, PureComponent } from 'react' +import React, { ComponentProps, ElementType, PureComponent } from 'react' import styled from 'styled-components' import { debounce } from 'throttle-debounce' import ObserverShared from '../util/observer' @@ -64,6 +64,7 @@ type Props = { borderRadius?: number tabIndex?: number loaderConfig?: IntersectionObserverInit + fetchPriority?: ComponentProps[`fetchPriority`] } & EventProps const defaultProps = Object.freeze({ gutter: 6, user: {}, initialGifs: [] }) @@ -144,6 +145,7 @@ class Carousel extends PureComponent { borderRadius, tabIndex = 0, loaderConfig, + fetchPriority, } = this.props const { gifs, isDoneFetching } = this.state const showLoader = !isDoneFetching @@ -171,6 +173,7 @@ class Carousel extends PureComponent { noLink={noLink} borderRadius={borderRadius} backgroundColor={backgroundColor} + fetchPriority={fetchPriority} /> ) })} diff --git a/packages/react-components/src/components/gif.tsx b/packages/react-components/src/components/gif.tsx index f35efc80..6f2aa13d 100644 --- a/packages/react-components/src/components/gif.tsx +++ b/packages/react-components/src/components/gif.tsx @@ -64,6 +64,7 @@ type GifProps = { borderRadius?: number tabIndex?: number style?: any + fetchPriority?: 'auto' | 'high' | 'low' } type Props = GifProps & EventProps @@ -102,6 +103,7 @@ const Gif = ({ borderRadius = 4, style, tabIndex, + fetchPriority, }: Props) => { // only fire seen once per gif id const [hasFiredSeen, setHasFiredSeen] = useState(false) @@ -273,6 +275,9 @@ const Gif = ({ [`fetchPriority`] } & EventProps const Loader = styled.div<{ $isFirstLoad: boolean }>` @@ -152,6 +153,7 @@ class Grid extends PureComponent { tabIndex = 0, layoutType = 'GRID', loader: LoaderVisual = DotsLoader, + fetchPriority, } = this.props const { gifWidth, gifs, isError, isDoneFetching } = this.state const showLoader = !isDoneFetching @@ -186,6 +188,7 @@ class Grid extends PureComponent { hideAttribution={hideAttribution} noLink={noLink} borderRadius={borderRadius} + fetchPriority={fetchPriority} /> ))}