github.com/kubeshop/testkube@v1.17.23/docs/src/theme/DocCard/index.js (about) 1 import React from "react"; 2 import clsx from "clsx"; 3 import Link from "@docusaurus/Link"; 4 import { 5 findFirstCategoryLink, 6 useDocById, 7 } from "@docusaurus/theme-common/internal"; 8 import isInternalUrl from "@docusaurus/isInternalUrl"; 9 import { translate } from "@docusaurus/Translate"; 10 import styles from "./styles.module.css"; 11 import { useColorMode } from "@docusaurus/theme-common"; 12 13 function CardContainer({ href, children }) { 14 return ( 15 <Link 16 href={href} 17 className={clsx("card padding--md", styles.cardContainer)} 18 > 19 {children} 20 </Link> 21 ); 22 } 23 function CardLayout({ href, icon, logo, title, description }) { 24 return ( 25 <CardContainer href={href}> 26 <h2 className={clsx("text--truncate", styles.cardTitle)} title={title}> 27 {icon || ( 28 <img 29 src={logo} 30 width={32} 31 height={32} 32 style={ 33 useColorMode().colorMode !== "dark" 34 ? { 35 WebkitFilter: "invert(1)", 36 filter: "invert(1)", 37 } 38 : undefined 39 } 40 /> 41 )}{" "} 42 {title} 43 </h2> 44 {description && ( 45 <p 46 className={clsx("text--truncate", styles.cardDescription)} 47 title={description} 48 > 49 {description} 50 </p> 51 )} 52 </CardContainer> 53 ); 54 } 55 function CardCategory({ item }) { 56 const href = findFirstCategoryLink(item); 57 // Unexpected: categories that don't have a link have been filtered upfront 58 if (!href) { 59 return null; 60 } 61 return ( 62 <CardLayout 63 href={href} 64 icon="🗃️" 65 title={item.label} 66 description={translate( 67 { 68 message: "{count} items", 69 id: "theme.docs.DocCard.categoryDescription", 70 description: 71 "The default description for a category card in the generated index about how many items this category includes", 72 }, 73 { count: item.items.length } 74 )} 75 /> 76 ); 77 } 78 79 const testExecutorLogo = new Map([ 80 [ 81 "/test-types/executor-artillery", 82 "https://raw.githubusercontent.com/kubeshop/testkube-dashboard/main/packages/web/src/assets/images/artilleryIcon.svg", 83 ], 84 [ 85 "/test-types/executor-curl", 86 "https://raw.githubusercontent.com/kubeshop/testkube-dashboard/main/packages/web/src/assets/images/curlIcon.svg", 87 ], 88 [ 89 "/test-types/executor-cypress", 90 "https://raw.githubusercontent.com/kubeshop/testkube-dashboard/main/packages/web/src/assets/images/cypressIcon.svg", 91 ], 92 [ 93 "/test-types/executor-ginkgo", 94 "https://raw.githubusercontent.com/kubeshop/testkube-dashboard/main/packages/web/src/assets/images/ginkgoIcon.svg", 95 ], 96 [ 97 "/test-types/executor-gradle", 98 "https://raw.githubusercontent.com/kubeshop/testkube-dashboard/main/packages/web/src/assets/images/gradleIcon.svg", 99 ], 100 [ 101 "/test-types/executor-jmeter", 102 "https://raw.githubusercontent.com/kubeshop/testkube-dashboard/main/packages/web/src/assets/images/jmeterIcon.svg", 103 ], 104 [ 105 "/test-types/executor-k6", 106 "https://raw.githubusercontent.com/kubeshop/testkube-dashboard/main/packages/web/src/assets/images/k6Icon.svg", 107 ], 108 [ 109 "/test-types/executor-kubepug", 110 "https://raw.githubusercontent.com/kubeshop/testkube-dashboard/main/packages/web/src/assets/images/kubepug.svg", 111 ], 112 [ 113 "/test-types/executor-maven", 114 "https://raw.githubusercontent.com/kubeshop/testkube-dashboard/main/packages/web/src/assets/images/mavenIcon.svg", 115 ], 116 [ 117 "/test-types/executor-postman", 118 "https://raw.githubusercontent.com/kubeshop/testkube-dashboard/main/packages/web/src/assets/images/postmanIcon.svg", 119 ], 120 [ 121 "/test-types/executor-soapui", 122 "https://raw.githubusercontent.com/kubeshop/testkube-dashboard/main/packages/web/src/assets/images/soapIcon.svg", 123 ], 124 [ 125 "/test-types/executor-playwright", 126 "https://raw.githubusercontent.com/kubeshop/testkube-dashboard/main/packages/web/src/assets/images/playwrightIcon.svg", 127 ], 128 [ 129 "/test-types/executor-zap", 130 "https://raw.githubusercontent.com/kubeshop/testkube-dashboard/main/packages/web/src/assets/images/zapIcon.svg", 131 ], 132 ]); 133 134 function CardLink({ item }) { 135 const executorLogo = testExecutorLogo.get(item.href); 136 const icon = executorLogo 137 ? undefined 138 : isInternalUrl(item.href) 139 ? "📄️" 140 : "🔗"; 141 const doc = useDocById(item.docId ?? undefined); 142 return ( 143 <CardLayout 144 href={item.href} 145 icon={icon} 146 logo={executorLogo} 147 title={item.label} 148 description={doc?.description} 149 /> 150 ); 151 } 152 export default function DocCard({ item }) { 153 switch (item.type) { 154 case "link": 155 return <CardLink item={item} />; 156 case "category": 157 return <CardCategory item={item} />; 158 case "intro": 159 return <CardIntro item={item} />; 160 case "tool_icons": 161 return <CardToolIcons item={item} />; 162 default: 163 throw new Error(`unknown item type ${JSON.stringify(item)}`); 164 } 165 } 166 167 function CardIntro({ item }) { 168 return ( 169 <CardLayout 170 href={item.href} 171 icon={item.icon} 172 title={item.label} 173 description={item.description} 174 /> 175 ); 176 } 177 178 function CardToolIcons({ item }) { 179 const executorLogo = testExecutorLogo.get(item.href); 180 const icon = executorLogo 181 return ( 182 <CardLayout 183 href={item.href} 184 logo={executorLogo} 185 description={item.description} 186 /> 187 ); 188 }