Skip to content

Commit 48993d1

Browse files
authored
Merge branch 'master' into leecalcote/gatsby-mdx-plugin-upgrade
Signed-off-by: Lee Calcote <leecalcote@gmail.com>
2 parents 214a636 + 75d4d9c commit 48993d1

1 file changed

Lines changed: 52 additions & 6 deletions

File tree

  • src/sections/Learn/Workshop-grid

src/sections/Learn/Workshop-grid/index.js

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useState, useRef } from "react";
22
import { graphql, useStaticQuery, Link } from "gatsby";
33

44
import { Container, Row, Col } from "../../../reusecore/Layout";
@@ -50,6 +50,44 @@ const WorkshopsPage = () => {
5050
}`
5151
);
5252

53+
const [scrollPosition, setScrollPosition] = useState(0);
54+
const scrollRefMap = useRef({});
55+
56+
57+
const toggleActive = (id) => {
58+
const targetElement = scrollRefMap.current[id];
59+
60+
if (open && ID === id) {
61+
setOpen(false);
62+
setContent(false);
63+
setID("");
64+
65+
if (targetElement) {
66+
// Wait for DOM to collapse, then scroll
67+
requestAnimationFrame(() => {
68+
requestAnimationFrame(() => {
69+
const rect = targetElement.getBoundingClientRect();
70+
const y = rect.top + window.scrollY; // adjust for header
71+
window.scrollTo({
72+
top: y,
73+
behavior: "smooth",
74+
});
75+
});
76+
});
77+
}
78+
} else {
79+
if (targetElement) {
80+
const rect = targetElement.getBoundingClientRect();
81+
const y = rect.top + window.scrollY - 20;
82+
setScrollPosition(y);
83+
}
84+
setID(id);
85+
setContent(true);
86+
setOpen(true);
87+
}
88+
};
89+
90+
5391
return (
5492
<WorkshopPageWrapper>
5593
<PageHeader title="Cloud Native Workshops"/>
@@ -60,11 +98,18 @@ const WorkshopsPage = () => {
6098
<Row style={{
6199
flexWrap: "wrap"
62100
}}>
63-
{data.allMdx.nodes.map(({ id, frontmatter, fields }) => (
64-
<Col $xs={12} $sm={6} $lg={4} key={id} className="workshop-grid-col">
65-
<div className="workshop-grid-card">
66-
<WorkshopCard frontmatter={frontmatter} />
67-
<div className="btn-and-status">
101+
{data.allMdx.nodes.map(({ id, frontmatter, fields, body }) => (
102+
<Col {...content && ID === id ? { $xs: 12, $sm: 12, $lg: 12 } : { $xs: 12, $sm: 6, $lg: 4 } } key={id} className="workshop-grid-col">
103+
<div className="workshop-grid-card" ref={(el) => {
104+
if (el) scrollRefMap.current[id] = el;
105+
}}>
106+
<WorkshopCard frontmatter={frontmatter} content={content} ID={ID} id={id} />
107+
<div className={content && ID === id ? "active" : "text-contents"}>
108+
<div className="content">
109+
<MDXRenderer>{body}</MDXRenderer>
110+
</div>
111+
</div>
112+
<div className={content && ID === id ? "btn-and-status-open" : "btn-and-status"}>
68113
<div className="social-icons">
69114
{frontmatter.slack && frontmatter.status === "delivered" ?
70115
<a href={frontmatter.slack} target = "_blank" rel="noreferrer" className="links">
@@ -76,6 +121,7 @@ const WorkshopsPage = () => {
76121
<div className="expand">
77122
<Link to={fields.slug} className="readmeBtn readmreBtn"> Read More <BsArrowRight className="icon" size={30} /></Link>
78123
</div>
124+
79125
<div className="externalLink">
80126
<Link to={fields.slug} className="siteLink"><FaRegWindowMaximize style={{ height: "25px", width: "auto" }} /></Link>
81127
</div>

0 commit comments

Comments
 (0)