forked from tnonate/thenewoil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCriterias.astro
112 lines (98 loc) · 3.55 KB
/
Criterias.astro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
---
import { Markdown } from "@astropub/md";
export type Directions = "row" | "col";
export interface Tool {
name: string;
logo?: string;
link?: string;
referral_link?: string;
values: Record<string, string | string[] | undefined>;
}
export interface Data {
criterias: string[];
tools: Record<string, Tool>;
}
interface Props {
data: Data;
direction?: Directions;
nonReferralLinkText: string;
}
const GRID_DIRECTION_CLASSES = {
col: "grid-flow-row grid-cols-[repeat(var(--length),auto)]",
row: "grid-flow-col grid-rows-[repeat(var(--length),auto)]"
} as Record<Directions, string>;
const { data, direction: directionKey = "col", nonReferralLinkText = "Non-referral link" } = Astro.props;
const directionClasses = GRID_DIRECTION_CLASSES[directionKey];
---
<div
class={`overflow-auto border-4 rounded-lg border-gradient-secondary border-bg-primary dark:border-bg-primary-dark grid w-full auto-cols-fr ${directionClasses}`}
style={{ "--length": data.criterias.length + 1 }}
>
<div class="h-full rounded-none border-b-4 border-gradient-secondary-center p-4 text-center"></div>
{
data.criterias.map((criteria: string, index: number) => {
const isLastCriteria = index === data.criterias.length - 1;
return (
<div
class={`h-full p-4 text-center ${
directionKey === "col" || (directionKey === "row" && !isLastCriteria)
? "border-b-4 border-gradient-secondary-center"
: ""
}`}
>
{criteria}
</div>
);
})
}
{
Object.values(data.tools).map((tool: Tool, toolIndex: number) => {
const isLastTool = toolIndex === Object.values(data.tools).length - 1;
return (
<>
<div
class={` flex w-full flex-col items-center p-4 text-center ${
directionKey === "row" || (directionKey === "col" && !isLastTool)
? "border-b-4 border-gradient-secondary-center"
: ""
}`}
>
{tool.logo && (
<a class="border-none" href={tool.referral_link ? tool.referral_link : tool.link}>
<img src={tool.logo} alt={`${tool.name} logo`} />
</a>
)}
<div class="flex flex-col items-center">
{(tool.referral_link || tool.link) && (
<a href={tool.referral_link ? tool.referral_link : tool.link}>{tool.name}</a>
)}
{tool.referral_link && tool.link && <a href={tool.link}>{nonReferralLinkText}</a>}
{!tool.referral_link && !tool.link && <p>{tool.name}</p>}
</div>
</div>
{data.criterias.map((criteria: string, index: number) => {
const isLastCriteria = index === data.criterias.length - 1;
const criteriaValue = tool.values[criteria];
if (criteriaValue === undefined)
throw Error(`Error: criteria "${criteria}" not defined on tool "${tool.name}"`);
return (
<div
class={`h-full p-4 ${
(directionKey === "col" && !isLastTool) || (directionKey === "row" && !isLastCriteria)
? "border-b-4 border-gradient-secondary-center"
: ""
}`}
>
{Array.isArray(criteriaValue) ? (
criteriaValue.map((text) => <Markdown of={String(text)} />)
) : (
<Markdown of={String(criteriaValue)} />
)}
</div>
);
})}
</>
);
})
}
</div>