Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 46 additions & 28 deletions src/sections/Company/Brand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ const SMPBrand = loadable(() => import("./Brand-components/smp"));
const CommunityBrand = loadable(() => import("./Brand-components/community"));
const Button = loadable(() => import("../../../reusecore/Button"));
const NightHawk = loadable(() => import("./Brand-components/nighthawk"));
const ServiceMeshPatterns = loadable(() => import("./Brand-components/servicemeshpatterns"));
const ServiceMeshPatterns = loadable(
() => import("./Brand-components/servicemeshpatterns"),
);
const MeshMasterBrand = loadable(() => import("./Brand-components/meshmaster"));
const MeshMarkBrand = loadable(() => import("./Brand-components/meshmark"));
const KanvasBrand = loadable(() => import("./Brand-components/kanvas"));
const BrandGuide = loadable(() => import("./Brand-components/brand-guide"));
const StickFigures = loadable(() => import("./Brand-components/stickfigures"));
const Catalog = loadable(() => import("./Brand-components/catalog"));
const Academy = loadable(() => import("./Brand-components/academy"));
const SocialBackgrounds = loadable(() => import("./Brand-components/social-backgrounds"));
const SocialBackgrounds = loadable(
() => import("./Brand-components/social-backgrounds"),
);

const getDimensions = (ele) => {
let dummyheight = 0,
dummyoffsetTop = 0,
dummyoffsetBottom = 0;
dummyoffsetTop = 0,
dummyoffsetBottom = 0;
if (ele) {
const { height } = ele.getBoundingClientRect();
const offsetTop = ele.offsetTop;
Expand All @@ -49,6 +53,9 @@ const getDimensions = (ele) => {
// Functions to make scroll with speed control
// Element to move, element or px from, element or px to, time in ms to animate
const scrollTo = (element, sectionId, duration = 2000) => {
// Sections for disabled brand kits are commented out, so their refs
// stay null. Bail out instead of throwing on element.offsetTop.
if (!element) return;
// Update URL hash
if (sectionId) {
window.history.pushState(null, null, `#${sectionId}`);
Expand Down Expand Up @@ -142,22 +149,22 @@ const Brand = () => {
];

const sectionIdMap = {
"layer5": layer5Ref,
layer5: layer5Ref,
"social-backgrounds": SocialBackgroundsRef,
"meshery": mesheryRef,
"meshsync": meshsyncRef,
meshery: mesheryRef,
meshsync: meshsyncRef,
"meshery-operator": mesheryOperatorRef,
"image-hub": imageHubRef,
"smp": smpRef,
"meshmark": meshmarkRef,
smp: smpRef,
meshmark: meshmarkRef,
"service-mesh-patterns": servicemeshpatternsRef,
"nighthawk": nightHawkRef,
"meshmate": meshmateRef,
"meshmaster": meshMasterRef,
"kanvas": kanvasRef,
"catalog": CatalogRef,
"academy": AcademyRef,
"five": stickfiguresRef
nighthawk: nightHawkRef,
meshmate: meshmateRef,
meshmaster: meshMasterRef,
kanvas: kanvasRef,
catalog: CatalogRef,
academy: AcademyRef,
five: stickfiguresRef,
};

// Handle initial hash navigation on page load
Expand Down Expand Up @@ -224,18 +231,22 @@ const Brand = () => {
<div className="section" id="layer5" ref={layer5Ref}>
<Layer5Brand />
</div>
<div className="section" id="social-backgrounds" ref={SocialBackgroundsRef}>
<div
className="section"
id="social-backgrounds"
ref={SocialBackgroundsRef}
>
<SocialBackgrounds />
</div>
// <div className="section" id="meshery" ref={mesheryRef}>
// <MesheryBrand />
// </div>
// <div className="section" id="meshsync" ref={meshsyncRef}>
// <MeshSyncBrand />
// </div>
// <div className="section" id="meshery-operator" ref={mesheryOperatorRef}>
// <MesheryOperatorBrand />
// </div>
{/* <div className="section" id="meshery" ref={mesheryRef}>
<MesheryBrand />
</div>
<div className="section" id="meshsync" ref={meshsyncRef}>
<MeshSyncBrand />
</div>
<div className="section" id="meshery-operator" ref={mesheryOperatorRef}>
<MesheryOperatorBrand />
</div> */}
<div className="section" id="image-hub" ref={imageHubRef}>
<ImageHubBrand />
</div>
Expand All @@ -245,7 +256,11 @@ const Brand = () => {
<div className="section" id="meshmark" ref={meshmarkRef}>
<MeshMarkBrand />
</div>
<div className="section" id="service-mesh-patterns" ref={servicemeshpatternsRef}>
<div
className="section"
id="service-mesh-patterns"
ref={servicemeshpatternsRef}
>
<ServiceMeshPatterns />
</div>
<div className="section" id="nighthawk" ref={nightHawkRef}>
Expand Down Expand Up @@ -357,7 +372,10 @@ const Brand = () => {
visibleSection === "ServiceMeshPatterns" ? "selected" : ""
}`}
onClick={() => {
scrollTo(servicemeshpatternsRef.current, "service-mesh-patterns");
scrollTo(
servicemeshpatternsRef.current,
"service-mesh-patterns",
);
}}
>
<span>Cloud Native Patterns</span>
Expand Down
79 changes: 37 additions & 42 deletions src/sections/Meshery/Meshery-integrations/Honeycomb/Honeycomb.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from "react";
import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
import { HoneycombGrid } from "./Honeycomb.style";

// Hexagon (cell) size for each viewport band. Keeping the hexagons sized to
Expand All @@ -13,65 +13,60 @@ const hexSizeForWidth = (width) => {
return 150;
};

// useLayoutEffect is a no-op (with a warning) during Gatsby's server-side
// render, so fall back to useEffect there and only measure in the browser.
const useIsomorphicLayoutEffect =
typeof window !== "undefined" ? useLayoutEffect : useEffect;

const Honeycomb = (props) => {
const { items, renderItem } = props;
const [height, setHeight] = useState(0);
const [hexSize, setHexSize] = useState(150);
const gridRef = useRef(null);

const setHoneycombHeight = () => {
const layoutHoneycomb = () => {
const grid = gridRef.current;
// Total horizontal available space for hexagons (offsetWidth includes
// the ul horizontal padding, so subtract it to get the usable width).
const availableWidth = grid ? grid.offsetWidth : window.innerWidth;
let usableWidth = availableWidth;
if (grid && typeof window !== "undefined" && window.getComputedStyle) {
const computedStyle = window.getComputedStyle(grid);
const paddingLeft = parseFloat(computedStyle.paddingLeft) || 0;
const paddingRight = parseFloat(computedStyle.paddingRight) || 0;
usableWidth = availableWidth - paddingLeft - paddingRight;
}
if (!grid) return;

const availableWidth = grid.offsetWidth || window.innerWidth;
const W = hexSizeForWidth(availableWidth);
// Horizontal pitch (hexagon width + left/right margins)
const P = W + 6;

// No. of hexagons that can be adjusted in first and second row
const firstRow = Math.max(1, Math.floor((usableWidth - (W / 2 + 25)) / P));
const secondRow = Math.max(1, Math.floor((usableWidth - (W + 28)) / P));
if (!grid.children.length) {
setHexSize(W);
setHeight(0);
return;
}

// Vertical pitch per row: hexagon height + margin-top + margin-bottom
const rowHeight = Math.round(W * 0.8662 + 6);
// Height of a first+second row pair / of a single leftover row
const pairHeight = 2 * rowHeight;
const singleHeight = rowHeight - 6;
// Make sure the hexagons are sized for this viewport, then temporarily
// grow the grid tall enough for every hexagon to wrap into place (the
// shape-outside float pattern repeats indefinitely, so any sufficiently
// tall value lays the rows out identically). Measuring the real content
// afterwards and shrinking the grid to fit avoids leaving blank space
// below the mesh whenever the row count is hard to predict analytically.
grid.style.setProperty("--hex-size", `${W}px`);
const upperBoundHeight = items.length * (W * 1.3) + W;
grid.style.height = `${upperBoundHeight}px`;

// No. of first-second row pairs possible
const pairsCount = Math.floor(items.length / (firstRow + secondRow));
const gridTop = grid.getBoundingClientRect().top;
let maxBottom = 0;
Array.from(grid.children).forEach((li) => {
const bottom = li.getBoundingClientRect().bottom - gridTop;
if (bottom > maxBottom) maxBottom = bottom;
});

let newHeight;
if (pairsCount * (firstRow + secondRow) < items.length) {
// Calculate left off hexagons
const left = items.length - pairsCount * (firstRow + secondRow);
newHeight =
left <= firstRow
? pairsCount * pairHeight + singleHeight
: pairsCount * pairHeight + pairHeight;
} else {
// All hexagons are covered in n pairs of 2 rows (first row with a
// hexagon and second row with b hexagons).
newHeight = pairsCount * pairHeight;
}

if (!isNaN(newHeight)) setHeight(newHeight);
grid.style.height = "";
setHexSize(W);
setHeight(Math.ceil(maxBottom));
};

useIsomorphicLayoutEffect(() => {
layoutHoneycomb();
}, [items]);

useEffect(() => {
window.addEventListener("resize", setHoneycombHeight);
setHoneycombHeight();
window.addEventListener("resize", layoutHoneycomb);
return () => {
window.removeEventListener("resize", setHoneycombHeight);
window.removeEventListener("resize", layoutHoneycomb);
};
}, [items]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ export const HoneycombGrid = styled.div`

display: flex;
text-align: left;
margin: 0;

ul {
font-size: 0;
line-height: 0;
height: ${(props) => (props.$height === 0 ? "unset" : `calc(${props.$height}px + var(--hex-size, 150px) * 0.31)`)};
height: ${(props) => (props.$height === 0 ? "unset" : `${props.$height}px`)};

&:before {
content: "";
Expand Down
Loading