Skip to content

Commit

Permalink
fix: fix scrollintoview action
Browse files Browse the repository at this point in the history
  • Loading branch information
yoonhyejin committed Aug 2, 2024
1 parent d27b819 commit aadf03a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs-website/adoptionStoriesIndexes.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"name": "Pinterest",
"slug": "pinterest",
"imageUrl": "/img/logos/companies/pinterest.png",
"imageSize": "default",
"imageSize": "small",
"link": "https://www.youtube.com/watch?v=YoxTg8tQSwg&feature=youtu.be",
"linkType": "blog",
"tagline": "DataHub Project @ Pinterest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import clsx from "clsx";
import Link from "@docusaurus/Link";
import styles from "./styles.module.scss";

export default function LearnItemCard({ company }) {
const LearnItemCard = React.forwardRef(({ company, isSelected }, ref) => {
return (
<div className={clsx("col col--4", styles.featureCol)}>
<div className={clsx("card", styles.card)} id={company.slug}>
<div className={clsx("col col--4", styles.featureCol)} id={company.slug} ref={ref}>
<div className={clsx("card", styles.card, { [styles.selected]: isSelected })}>
<div className={styles.card_image}>
<img src={`/img/adoption-stories/adoption-stories-${company.slug}.png`} alt={company.name} />
</div>
Expand All @@ -20,4 +20,6 @@ export default function LearnItemCard({ company }) {
</div>
</div>
);
}
});

export default LearnItemCard;
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@
align-self: stretch;
flex-grow: 1;
&:hover {
opacity: 0.9;
}

&.selected {
border-color: var(--ifm-color-primary);
box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
scroll-margin-top: 100px;
}


hr {
margin: 0;
}
Expand Down
24 changes: 17 additions & 7 deletions docs-website/src/pages/adoption-stories/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import React, { useState } from "react";
import clsx from "clsx";
import { HtmlClassNameProvider, ThemeClassNames } from "@docusaurus/theme-common";
import React, { useState, useEffect, useRef } from "react";
import Layout from "@theme/Layout";
import LearnItemCard from "./_components/LearnItemCard";
import styles from "./styles.module.scss";
Expand All @@ -11,6 +9,7 @@ function AdoptionStoriesListPageContent() {
const companies = (customerStoriesIndexes?.companies || []).filter((company) => company.link);
const [activeFilters, setActiveFilters] = useState([]);
const categories = ["B2B & B2C", "E-Commerce", "Financial & Fintech", "And More"];
const selectedCardRef = useRef(null);

const filteredItems = activeFilters.length
? companies.filter((company) => activeFilters.includes(company.category))
Expand All @@ -24,6 +23,14 @@ function AdoptionStoriesListPageContent() {
}
};

const selectedSlug = window.location.hash.substring(1);

useEffect(() => {
if (selectedCardRef.current) {
selectedCardRef.current.scrollIntoView({ behavior: "smooth", block: "start", inline: "nearest" });
}
}, [selectedSlug]);

return (
<Layout>
<header className={"hero"}>
Expand Down Expand Up @@ -54,7 +61,12 @@ function AdoptionStoriesListPageContent() {
<div className="container">
<div className="row">
{filteredItems.map((company) => (
<LearnItemCard key={company.name} company={company} />
<LearnItemCard
key={company.name}
company={company}
isSelected={company.slug === selectedSlug}
ref={company.slug === selectedSlug ? selectedCardRef : null}
/>
))}
</div>
</div>
Expand All @@ -63,7 +75,5 @@ function AdoptionStoriesListPageContent() {
}

export default function AdoptionStoriesListPage() {
return (
<AdoptionStoriesListPageContent />
);
return <AdoptionStoriesListPageContent />;
}

0 comments on commit aadf03a

Please sign in to comment.