1+ import 'react-responsive-carousel/lib/styles/carousel.min.css' ;
12import styled from '@emotion/styled' ;
23import { connectHits , connectStateResults } from 'react-instantsearch-dom' ;
34import { Stats } from 'react-instantsearch-dom' ;
4- import React from 'react' ;
5+ import { Carousel } from 'react-responsive-carousel' ;
6+ import ReactTooltip from 'react-tooltip' ;
7+ import React , { useRef } from 'react' ;
58
69import { Hit } from '../hit' ;
710import { isEmpty } from '../util' ;
811
912import { Pagination } from './Pagination' ;
1013
14+ const SPONSORS = [ {
15+ name : `Doppler` ,
16+ description : `Universal Secrets Platform` ,
17+ icon : `https://dashboard.doppler.com/imgs/logo_color.png` ,
18+ url : `https://www.doppler.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=yarn&utm_source=github` ,
19+ } , {
20+ name : `WorkOS` ,
21+ description : `all-in-one solution for enterprise-ready apps` ,
22+ icon : `https://assets-global.website-files.com/5ef26797488fe01cc1b89848/61426734f2f4a013c6f2d774_Favicon%2032x32.png` ,
23+ url : `https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=berry&utm_source=github` ,
24+ } ] ;
25+
1126const Hits = connectHits ( ( { hits, onTagClick, onOwnerClick, searchState} ) =>
1227 hits . map ( hit => (
1328 < Hit
@@ -42,17 +57,38 @@ const StatsText = styled.div`
4257 margin-right: 1rem;
4358` ;
4459
45- const Sponsors = styled . a `
46- padding: 0.7rem 0 ;
60+ const SponsorCarousel = styled ( Carousel ) `
61+ margin: auto 0 auto auto ;
4762
48- flex: none;
49- margin-left: auto;
63+ .carousel {
64+ display: flex;
65+ flex-direction: row-reverse;
66+
67+ .slide {
68+ text-align: right;
69+
70+ img {
71+ width: 1.2em;
72+ height: 1.2em;
73+
74+ vertical-align: middle;
75+ }
76+ }
77+ }
78+
79+ .control-dots {
80+ position: relative;
5081
82+ flex: 1;
83+ margin: 0;
84+ line-height: 1em;
85+ }
86+ ` ;
87+
88+ const SponsorContainer = styled . a `
5189 color: inherit;
5290
5391 span {
54- display: inline-block;
55-
5692 color: #85ecf7;
5793 text-decoration: underline;
5894 text-underline-offset: 2px;
@@ -71,30 +107,59 @@ const SearchFooter = styled.div`
71107 margin-bottom: 50px;
72108` ;
73109
74- const ResultsFound = ( { pagination, onTagClick, onOwnerClick, searchState} ) => < >
75- < InfoBar >
76- < InfoContainer >
77- < StatsText >
78- < Stats translations = { { stats : ( num , time ) => `found ${ num . toLocaleString ( `en` ) } packages in ${ time } ms` } } />
79- </ StatsText >
80- < Sponsors href = { `https://www.doppler.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=yarn&utm_source=github` } >
81- Thanks to < span > Doppler</ span > , the Universal Secrets Platform, for sponsoring Yarn!
82- </ Sponsors >
83- </ InfoContainer >
84- </ InfoBar >
85- < ResultsContainer >
86- < Hits onTagClick = { onTagClick } onOwnerClick = { onOwnerClick } searchState = { searchState } />
87- < Pagination pagination = { pagination } />
88- < SearchFooter >
110+ const Sponsor = ( { name, description, icon, url} ) => < >
111+ < SponsorContainer href = { url } data-tip = { `<a style="font-size: 17px;" href="https://opencollective.com/yarnpkg/contribute/gold-tier-24218">Become a Gold sponsor</a>` } >
112+ Thanks to < img src = { icon } alt = { `${ name } icon` } /> < span > { name } </ span > , the { description } , for sponsoring Yarn!
113+ </ SponsorContainer >
114+ </ > ;
115+
116+ const ResultsFound = ( { pagination, onTagClick, onOwnerClick, searchState} ) => {
117+ // We use a ref to have a new selection on each component creation rather than on each rerender
118+ const selectedItem = useRef ( Math . trunc ( Math . random ( ) * SPONSORS . length ) ) ;
119+
120+ return < >
121+ < InfoBar >
122+ < InfoContainer >
123+ < StatsText >
124+ < Stats translations = { { stats : ( num , time ) => `found ${ num . toLocaleString ( `en` ) } packages in ${ time } ms` } } />
125+ </ StatsText >
126+ < SponsorCarousel
127+ axis = { `vertical` }
128+ autoPlay = { true }
129+ infiniteLoop = { true }
130+ interval = { 4000 }
131+ showArrows = { false }
132+ showStatus = { false }
133+ showThumbs = { false }
134+ selectedItem = { selectedItem . current }
135+ >
136+ { SPONSORS . map ( sponsor => < Sponsor key = { sponsor . name } { ...sponsor } /> ) }
137+ </ SponsorCarousel >
138+ < ReactTooltip
139+ place = { `right` }
140+ offset = { { right : 20 } }
141+ effect = { `solid` }
142+ backgroundColor = { `#ffac33` }
143+ delayHide = { 4000 }
144+ html = { true }
145+ clickable = { true }
146+ />
147+ </ InfoContainer >
148+ </ InfoBar >
149+ < ResultsContainer >
150+ < Hits onTagClick = { onTagClick } onOwnerClick = { onOwnerClick } searchState = { searchState } />
151+ < Pagination pagination = { pagination } />
152+ < SearchFooter >
89153 Search by Algolia
90- { ` - ` }
91- < a href = { `https://discourse.algolia.com/t/2016-algolia-community-gift-yarn-package-search/319` } >
154+ { ` - ` }
155+ < a href = { `https://discourse.algolia.com/t/2016-algolia-community-gift-yarn-package-search/319` } >
92156 read how it works
93- </ a >
157+ </ a >
94158 .
95- </ SearchFooter >
96- </ ResultsContainer >
97- </ > ;
159+ </ SearchFooter >
160+ </ ResultsContainer >
161+ </ > ;
162+ } ;
98163
99164const NoPackagesFound = styled . div `
100165 padding: 0 15px;
0 commit comments