Skip to content

Commit

Permalink
🐛 Qa ui fixes (#1838)
Browse files Browse the repository at this point in the history
* fix blog card component

* fix admonition text

* fix navbar styles

* update toc padding

* fix sidebar navbar association

* fix sidebar navigation

* update reading progress bar

* add BlockBg component

* update BlockBg component

* remove log

* fix build error

---------

Co-authored-by: Nick DeJesus <[email protected]>
  • Loading branch information
FahadAminShovon and dayhaysoos authored Oct 18, 2024
1 parent a859236 commit df9b18f
Show file tree
Hide file tree
Showing 15 changed files with 437 additions and 39 deletions.
27 changes: 27 additions & 0 deletions site-new/assets/icons/ArrowLeft.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from "react";
import { SVGProps } from "react";
const ArrowLeft = (props: SVGProps<SVGSVGElement>) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width={16}
height={17}
fill="none"
{...props}
>
<path
fill="#000"
d="M13.335 7.833v1.334h-8V10.5H4V9.167H2.668V7.833h1.333V6.5h1.334v1.333h8Z"
/>
<path
fill="#000"
fillRule="evenodd"
d="M6.668 5.167H5.335V6.5h1.333V5.167Zm0 0h1.333V3.833H6.668v1.334Z"
clipRule="evenodd"
/>
<path
fill="#000"
d="M6.668 11.833H5.335V10.5h1.333v1.333ZM6.668 11.833h1.333v1.334H6.668v-1.334Z"
/>
</svg>
);
export default ArrowLeft;
4 changes: 2 additions & 2 deletions site-new/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const sidebars: SidebarsConfig = {
className: "glossary-icon no-caret",
},
],
web5Sidebar: [
docsSidebarWeb5Sidebar: [
// {
// type: "doc",
// id: "web5/index",
Expand All @@ -75,7 +75,7 @@ const sidebars: SidebarsConfig = {
customProps: { sidebarHeader: "test" },
},
],
tbdexSidebar: [
docsSidebarTbdexSidebar: [
{
id: "tbdex/index",
type: "doc",
Expand Down
2 changes: 1 addition & 1 deletion site-new/src/components/Admonition/Admonition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const Admonition = ({ variant, children, classes }: AdmonitionProps) => {
</div>
<div className="sidebar">
{typeof children === "string" ? (
<p className="mb-0">{children}</p>
<p className="mb-0 lg:text-lg">{children}</p>
) : (
children
)}
Expand Down
143 changes: 143 additions & 0 deletions site-new/src/components/BlockBg/BlockBg.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { cn } from "@site/lib/utils";
import { useMemo } from "react";

function getRandomNumber({ min, max }: { min: number; max: number }): number {
if (min > max) {
throw new Error("Minimum should be less than or equal to maximum.");
}
return Math.floor(Math.random() * (max - min + 1)) + min;
}

function populateGrid(grid: number[][], decreaseBlockLevel: number): void {
const rows = grid.length;
const cols = grid[0].length;

for (let i = 0; i < rows; i++) {
for (let j = 0; j < cols; j++) {
if (grid[i][j] === 0) {
// sometimes populate the grid randomly without checking if the cell is occupied
if (Math.floor(Math.random() * 2) % 2 === 0) {
grid[i][j] = 1;
continue;
}
let isOccupied = false;
if (i > 0 && grid[i - 1][j] === 1) {
isOccupied = true;
}
if (j > 0 && grid[i][j - 1] === 1) {
isOccupied = true;
}
if (i < rows - 1 && grid[i + 1][j] === 1) {
isOccupied = true;
}
if (j < cols - 1 && grid[i][j + 1] === 1) {
isOccupied = true;
}
if (!isOccupied) {
grid[i][j] = 1;
}
}
}
}

let randomIterations = decreaseBlockLevel;

while (randomIterations--) {
for (let i = 0; i < rows; i++) {
for (let j = 0; j < cols; j++) {
if (grid[i][j] === 1 && Math.floor(Math.random() * 2) % 2 === 0) {
grid[i][j] = 0;
}
}
}
}
}

const widths = {
0: "25%",
1: "50%",
2: "75%",
3: "100%",
} as const;

const BlockBg = ({
maxSize,
minSize,
rows = 12,
columns = 12,
className,
children,
decreaseBlockLevel = 2,
}: {
minSize: number;
maxSize: number;
rows?: number;
columns?: number;
className?: string;
children?: React.ReactNode;
decreaseBlockLevel?: number;
}) => {
const grid = useMemo(() => {
const generatedGrid = new Array(rows)
.fill(0)
.map(() => new Array(columns).fill(0));
populateGrid(generatedGrid, decreaseBlockLevel);
return generatedGrid;
}, []);

return (
<div
className={`${className} relative grid overflow-clip *:[grid-area:1/1]`}
>
<div className={cn("absolute inset-0 z-0")}>
{grid.map((row, i) => {
// generate a random height for the row
const height = getRandomNumber({ min: minSize, max: maxSize });
return (
<div
className="grid h-full w-full grid-rows-1"
key={i}
style={{
height,
gridTemplateColumns: `repeat(${rows}, minmax(0,1fr))`,
}}
>
{row.map((col, j) => {
if (!col) return null;
// sometime use height as width sometime use height sometimes take full width
const randomNumber = Math.floor(Math.random() * 4) as 0 | 1 | 3;

const width =
Math.floor(Math.random() * 2) % 2 === 0
? height
: Math.floor(Math.random() * 2) % 2 === 0
? getRandomNumber({ min: minSize, max: maxSize })
: widths[randomNumber];

const randomHeight =
(Number.parseInt(widths[randomNumber].split("%")[0], 10) *
height) /
100;
return (
<div
key={j}
className="bg-[--block-color]"
style={{
height: randomHeight,
width,
gridColumnStart: j + 1,
}}
/>
);
})}
</div>
);
})}
</div>

<div className="z-10">{children}</div>
</div>
);
};

export default BlockBg;
1 change: 1 addition & 0 deletions site-new/src/components/BlockBg/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as BlockBg } from "./BlockBg";
30 changes: 19 additions & 11 deletions site-new/src/components/BlogCard.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import clsx from "clsx";
import Heading from "@theme/Heading";

type BlogCardProps = {
date?: Date;
author?: string;
title?: string;
tags?: string[];
image?: string | null;
description?: string;
size?: "large" | "small";
description?: React.ReactNode;
};

function BlogCard({
Expand All @@ -16,32 +17,39 @@ function BlogCard({
title = "Title",
tags = [],
image = require("/static/img/test-image16x9.png").default,
description = "Some description here",
description,
size = "small",
}: BlogCardProps) {
const cardSizeClass = size === "large" ? "max-w-[840px]" : "max-w-[400px]";

return (
<div
className={clsx(
"group border-[gray] border-2 border-solid bg-dark-grey hover:bg-tbd-yellow text-[#FFF] group-hover:text-tbd-gray",
cardSizeClass
"group border-2 border-solid border-[gray] bg-dark-grey text-[#FFF] hover:bg-tbd-yellow group-hover:text-tbd-gray",
cardSizeClass,
)}
>
<img className="h-auto max-w-full block" src={image} />
<img className="block h-auto max-w-full" src={image} />
<div className="p-4 group-hover:text-tbd-gray">
<div>{date.toLocaleDateString()}</div>
<div className="text-tbd-yellow group-hover:text-tbd-gray">{`@${author}`}</div>
<h2 className="text-4xl tracking-wide group-hover:text-tbd-gray">
<p className="mb-0 font-basis text-xs">{date.toLocaleDateString()}</p>
<div className="font-semibold text-tbd-yellow group-hover:text-tbd-gray">{`@${author}`}</div>
<Heading as="h2" className="group-hover:text-tbd-gray">
{title}
</h2>
</Heading>
{typeof description === "string" ? (
<p className="mb-twist-core-spacing-10 font-medium lg:text-[18px] lg:leading-[150%]">
{description}
</p>
) : (
description
)}
<div className="flex">
{tags.map((t) => (
<div
key={t}
className="border-[#FFF] group-hover:border-dark-grey border-2 border-solid p-2 m-1.5 h-8 justify-center flex items-center"
className="m-1.5 flex h-8 items-center justify-center border-[0.5px] border-solid border-[#FFF] p-2 group-hover:border-dark-grey"
>
<span className="text-[gray] mr-2">#</span>
<span className="mr-2 text-[gray]">#</span>
{`${t}`}
</div>
))}
Expand Down
11 changes: 1 addition & 10 deletions site-new/src/components/ReadingProgress/ReadingProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import RocketProgress from "@site/assets/icons/RocketProgress";

const ReadingProgress = () => {
const rocketRef = useRef<HTMLSpanElement | null>(null);
const rocketBgRef = useRef<HTMLSpanElement | null>(null);

useEffect(() => {
const updateProgressBar = () => {
Expand All @@ -14,25 +13,17 @@ const ReadingProgress = () => {
if (rocketRef.current) {
rocketRef.current.style.left = `calc(${Math.max(scrollPercent)}%)`;
}

if (rocketBgRef.current) {
rocketBgRef.current.style.width = `calc(${Math.max(scrollPercent)}%)`;
}
};
document.addEventListener("scroll", updateProgressBar);

return () => {
document.removeEventListener("scroll", updateProgressBar);
};
}, [rocketRef, rocketBgRef]);
}, [rocketRef]);

return (
<div className="fixed top-[--ifm-navbar-height] z-20 h-[36px] w-full bg-black">
<div className="relative w-full">
<span
className="absolute inline-block h-[36px] w-0 bg-tbd-yellow"
ref={rocketBgRef}
/>
<span ref={rocketRef} className="absolute inline-block">
<RocketProgress />
</span>
Expand Down
49 changes: 49 additions & 0 deletions site-new/src/components/SpotLightCard/SpotLightCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { cn, textClassesMap, ToneTypes } from "@site/lib/utils";
import React from "react";
import Heading from "@theme/Heading";

type SpotLightCardProps = {
src: string;
alt?: string;
className?: string;
tone?: ToneTypes;
title: string;
handle: string;
children?: React.ReactNode;
};

const SpotLightCard = ({
src,
alt,
className,
tone = "yellow",
title,
handle,
children,
}: SpotLightCardProps) => {
return (
<div className={cn("border-[0.5px] border-solid", className)}>
<img
src={src}
alt={alt}
className="block aspect-[312/225] w-full object-cover lg:aspect-[584/328.5]"
/>
<div className="bg-black p-twist-core-spacing-9 lg:p-twist-core-spacing-12">
<p
className={cn(
"publication mb-[15px] lg:mb-[27px]",
textClassesMap[tone],
)}
>
{title}
</p>
<Heading as="h3" className="mb-twist-core-spacing-4 lg:mb-[14px]">
{handle}
</Heading>
{typeof children === "string" ? <p>{children}</p> : children}
</div>
</div>
);
};

export default SpotLightCard;
1 change: 1 addition & 0 deletions site-new/src/components/SpotLightCard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as SpotLightCard } from "./SpotLightCard";
Loading

0 comments on commit df9b18f

Please sign in to comment.