Skip to content

Instantly share code, notes, and snippets.

@knightspore
Created October 26, 2021 08:58
Show Gist options
  • Save knightspore/b9a699a11b386582fa1b6f54f3745268 to your computer and use it in GitHub Desktop.
Save knightspore/b9a699a11b386582fa1b6f54f3745268 to your computer and use it in GitHub Desktop.
InDebted Code Samples
import Star from "@ui/atoms/Svg/icons/simple/star.svg";
export default function ReviewCardStars({ rating, t }) {
return (
<div className="grid grid-cols-1 mt-10 gap-y-3">
<div className="z-10 flex gap-x-3">
{[1, 2, 3, 4, 5].map((n) => {
if (n <= rating) {
return <Star key={n * n} />;
}
})}
</div>
<p className="text-freshblue-100 body-sm">{rating + " " + t}</p>
</div>
);
}
import Image from "next/image";
export default function ComponentName({ source, w, h, alt, fit, styles, layout, position }) {
return (
<div className="absolute inset-0">
<div
className={`absolute inset-0 z-10 overflow-hidden mix-blend-color ${
styles ? styles : "bg-gradient-to-l gradient-dark"
}`}
></div>
<Image
priority={true}
className="inset-0 z-0 overflow-hidden"
src={source}
width={w}
height={h}
objectFit={fit}
layout={layout ? layout : "responsive"}
alt={alt}
objectPosition={position}
/>
</div>
);
}
import CardArrowButton from "@ui/atoms/Cards/CardArrowButton";
import Section from "@ui/atoms/Layout/Section";
import CustomRefinementList from "@ui/molecules/Search/CustomRefinementList";
import CustomSearchBox from "@ui/molecules/Search/CustomSearchBox";
import NewsroomCustomHits from "@ui/molecules/Search/NewsroomCustomHits";
import getTranslation from "@utils/getTranslation";
import algoliasearch from "algoliasearch";
import { motion } from "framer-motion";
import { useState } from "react";
import { InstantSearch } from "react-instantsearch-dom";
export default function NewsroomFeedSection({ heading, downloads, search }) {
const [showAll, setShowAll] = useState("false");
const misc = getTranslation("misc");
const variants = {
visible: { opacity: 1, height: "auto" },
hidden: { opacity: 0, height: 0 },
};
const searchClient = algoliasearch(
process.env.NEXT_PUBLIC_ALGOLIA_APP_ID,
process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY
);
const handleClick = () => {
setShowAll(!showAll);
};
return (
<Section id="newsroom-feed" styles="block bg-transparent">
<InstantSearch indexName={search} searchClient={searchClient}>
<div className="grid gap-4x lg:grid-cols-3">
<div className="lg:col-span-2 space-y-2x">
<div className="flex flex-col justify-between gap-2x lg:items-center lg:flex-row">
<h2 className="h4 lg:h3">{heading}</h2>
<CustomSearchBox />
</div>
<CustomRefinementList
styles="flex flex-wrap items-center flex-gap-4"
attribute="category"
defaultRefinement={["Event", "Announcement", "Press", "Video"]}
operator="or"
/>
<motion.div
initial="hidden"
animate="visible"
variants={variants}
className="grid grid-cols-1 transition-all duration-250 pr-2x space-y-3x"
>
<NewsroomCustomHits start={1} end={6} />
{showAll && <NewsroomCustomHits start={7} />}
<div
className="flex flex-row-reverse text-freshblue-500"
onClick={handleClick()}
>
<CardArrowButton text={showAll ? misc.loadLess : misc.loadMore} size="20px" />
</div>
</motion.div>
</div>
<div className="col-span-1 space-y-2x">{downloads?.length && downloads}</div>
</div>
</InstantSearch>
</Section>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment