Skip to content

Commit 62babfd

Browse files
Unified ColGrid component, VersionConditional adjustments
1 parent 97aa8cd commit 62babfd

File tree

7 files changed

+152
-325
lines changed

7 files changed

+152
-325
lines changed

src/components/ColGrid.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as React from "react";
2+
import clsx from "clsx";
3+
4+
export type GridColCount = 1 | 2 | 3;
5+
6+
export interface ColGridProps extends React.HTMLAttributes<HTMLDivElement> {
7+
children: React.ReactNode;
8+
className?: string;
9+
colCount: GridColCount;
10+
}
11+
12+
function getGridColsClass(colCount: GridColCount): string {
13+
if (colCount === 1) {
14+
return "grid grid-cols-1";
15+
}
16+
if (colCount === 2) {
17+
return "grid grid-cols-1 sm:grid-cols-2";
18+
}
19+
if (colCount === 3) {
20+
return "grid grid-cols-1 xl:grid-cols-3";
21+
}
22+
return "";
23+
}
24+
25+
export default function ColGrid({
26+
children,
27+
className = "",
28+
colCount = 1,
29+
...props
30+
}: ColGridProps) {
31+
return (
32+
<div
33+
className={clsx(getGridColsClass(colCount), "gap-4", className)}
34+
{...props}
35+
>
36+
{children}
37+
</div>
38+
);
39+
}

src/components/Common/CardWithImageHorizontal.tsx

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,54 @@ import Badge from "@site/src/components/Common/Badge";
66
import isInternalUrl from "@docusaurus/isInternalUrl";
77

88
export interface CardWithImageHorizontalProps {
9-
title: string;
10-
description: ReactNode;
11-
imgSrc: string;
12-
imgAlt?: string;
13-
url?: string;
14-
buttonVariant?: ButtonVariant;
15-
ctaLabel?: string;
16-
iconName?: IconName;
9+
title: string;
10+
description: ReactNode;
11+
imgSrc: string;
12+
imgAlt?: string;
13+
url?: string;
14+
buttonVariant?: ButtonVariant;
15+
ctaLabel?: string;
16+
iconName?: IconName;
1717
}
1818

1919
export default function CardWithImageHorizontal({
20-
title,
21-
description,
22-
imgSrc,
23-
imgAlt = "",
24-
url,
25-
buttonVariant = "secondary",
26-
ctaLabel = "Read now",
27-
iconName,
20+
title,
21+
description,
22+
imgSrc,
23+
imgAlt = "",
24+
url,
25+
buttonVariant = "secondary",
26+
ctaLabel = "Read now",
2827
}: CardWithImageHorizontalProps) {
29-
return (
30-
<div className="card group !grid [grid-template-columns:repeat(auto-fit,minmax(15rem,1fr))] items-center gap-4 overflow-hidden rounded-2xl border border-black/10 dark:border-white/10 bg-muted/40 p-4 transition-colors">
31-
<div className="aspect-[400/209] overflow-hidden rounded-xl relative flex items-center">
32-
<img
33-
src={imgSrc}
34-
alt={imgAlt}
35-
className="pointer-events-none w-full h-auto object-contain transition-transform origin-bottom duration-500 group-hover:scale-105"
36-
/>
37-
{url && !isInternalUrl(url) && (
38-
<Badge className="absolute top-2 right-2" variant="default" size="sm">
39-
External
40-
</Badge>
41-
)}
42-
</div>
43-
<div className="flex flex-col min-w-0 justify-center gap-1">
44-
<Heading as="h4" className="!mb-1">
45-
{title}
46-
</Heading>
47-
<p className="!mb-3 text-sm">{description}</p>
48-
{url && (
49-
<Button variant={buttonVariant} url={url}>
50-
{ctaLabel}
51-
</Button>
52-
)}
53-
</div>
54-
</div>
55-
);
56-
}
28+
return (
29+
<div className="card group !grid grid-cols-1 xl:grid-cols-[minmax(10rem,_230px)_1fr] 2xl:grid-cols-[minmax(10rem,_270px)_1fr] items-center gap-4 overflow-hidden rounded-2xl border border-black/10 dark:border-white/10 bg-muted/40 p-4 transition-colors">
30+
<div className="aspect-[537/281] overflow-hidden rounded-xl relative flex items-center">
31+
<img
32+
src={imgSrc}
33+
alt={imgAlt}
34+
className="pointer-events-none w-full h-auto object-contain transition-transform origin-bottom duration-500 group-hover:scale-105"
35+
/>
36+
{url && !isInternalUrl(url) && (
37+
<Badge
38+
className="absolute top-2 right-2"
39+
variant="default"
40+
size="sm"
41+
>
42+
External
43+
</Badge>
44+
)}
45+
</div>
46+
<div className="flex flex-col min-w-0 justify-center gap-1">
47+
<Heading as="h4" className="!mb-1">
48+
{title}
49+
</Heading>
50+
<p className="!mb-3 text-sm">{description}</p>
51+
{url && (
52+
<Button variant={buttonVariant} url={url}>
53+
{ctaLabel}
54+
</Button>
55+
)}
56+
</div>
57+
</div>
58+
);
59+
}

src/components/OneColGrid.tsx

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/components/ThreeColGrid.tsx

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/components/TwoColGrid.tsx

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/components/VersionConditional.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@ import { ReactNode } from "react";
22
import { useActiveDocContext } from "@docusaurus/plugin-content-docs/client";
33

44
interface VersionConditionalProps {
5-
minimumVersion: string;
6-
children: ReactNode;
5+
minimumVersion: string;
6+
children: ReactNode;
77
}
88

99
export default function VersionConditional({
10-
minimumVersion,
11-
children,
10+
minimumVersion,
11+
children,
1212
}: VersionConditionalProps) {
13-
const pluginId = "default";
14-
const { activeVersion } = useActiveDocContext(pluginId);
13+
const pluginId = "default";
14+
const { activeVersion } = useActiveDocContext(pluginId);
1515

16-
if (minimumVersion > activeVersion.label) {
17-
return null;
18-
}
16+
if (
17+
activeVersion.label.localeCompare(minimumVersion, undefined, {
18+
numeric: true,
19+
}) < 0
20+
) {
21+
return null;
22+
}
1923

20-
return <>{children}</>;
21-
}
24+
return <>{children}</>;
25+
}

0 commit comments

Comments
 (0)