Skip to content

Commit bef31f3

Browse files
Fix the testing type badges (#6211)
1 parent 3304a1f commit bef31f3

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

src/components/badge/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import React from "react";
22
import s from "./style.module.css";
33
import { BadgeProps } from "./types";
44

5-
function classNames(...classes) {
5+
function classNames(...classes: string[]) {
66
return classes.filter(Boolean).join(" ");
77
}
88

99
export default function Badge({ type, path, children }: BadgeProps) {
1010
return (
1111
<>
1212
{path && (
13-
<a href={path}>
13+
<a href={path} style={{ borderBottom: 'none' }}>
1414
<div className={classNames(`${s.badge}`, `${s[type]}`)}>
1515
{children}
1616
</div>

src/components/product-heading/index.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import Icon from '@cypress-design/react-icon'
22
import Badge from "@site/src/components/badge"
33
import s from './style.module.css'
4+
import {useDoc} from '@docusaurus/theme-common/internal';
5+
import E2EOnlyBadge from "@site/src/components/e2e-only-badge";
6+
import ComponentOnlyBadge from "@site/src/components/component-only-badge";
47

58
import React from 'react';
69

710
// Define the types for the props
811
interface ProductHeadingProps {
912
product: 'app' | 'cloud' | 'accessibility' | 'ui-coverage'
1013
plan?: 'team' | 'business' | 'enterprise'
14+
badge?: React.ReactNode
1115
}
1216

1317
// Build the Button component with the specified props
14-
const ProductHeading: React.FC<ProductHeadingProps> = ({
18+
const DocProductHeading: React.FC<ProductHeadingProps> = ({
1519
product, // The product to display
1620
plan, // The plan to display for Cloud product
21+
badge, // The badge to display
1722
}) => {
1823
const productName = product === 'ui-coverage' ? 'UI Coverage' : product === 'accessibility' ? 'Cypress Accessibility' : product === 'cloud' ? 'Cypress Cloud' : 'Cypress App'
1924
const iconName = product === 'ui-coverage' ? 'technology-ui-coverage' : product === 'accessibility' ? 'cypress-accessibility-outline' : 'technology-cypress'
@@ -26,15 +31,14 @@ const ProductHeading: React.FC<ProductHeadingProps> = ({
2631
}
2732

2833
return (
29-
<div className={s.productHeading}>
34+
<div className={s.productHeading} style={{display: 'flex', alignItems: 'center', gap: '0.5rem'}}>
3035
<Icon
3136
name={iconName}
3237
className={s.productHeadingIcon}
3338
/>
3439
<span className={s.productHeadingText}>
3540
{productName}
3641
</span>
37-
3842
<a
3943
href={`https://www.cypress.io/${linkPath}?utm_source=docs&utm_medium=product-heading-${product}&utm_content=${badgeContent}`}
4044
target="_blank"
@@ -43,9 +47,18 @@ const ProductHeading: React.FC<ProductHeadingProps> = ({
4347
>
4448
{ product !== 'app' && <Badge type="success">{badgeContent}</Badge>}
4549
</a>
46-
50+
<span className={s.productHeadingBadge}>{badge}</span>
4751
</div>
4852
)
4953
}
5054

51-
export default ProductHeading
55+
const ProductHeading: React.FC<Omit<ProductHeadingProps, 'badge'>> = (props) => {
56+
const { frontMatter } = useDoc();
57+
const e2eSpecific = (frontMatter as any).e2eSpecific;
58+
const componentSpecific = (frontMatter as any).componentSpecific;
59+
const testTypePill = (e2eSpecific && <E2EOnlyBadge />) || (componentSpecific && <ComponentOnlyBadge />);
60+
return <DocProductHeading {...props} badge={testTypePill} />;
61+
};
62+
63+
export default ProductHeading;
64+
export { ProductHeading, DocProductHeading };

src/components/product-heading/style.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@
1616
.productHeadingText {
1717
font-size: 1.2rem;
1818
margin-right: 0.5rem;
19+
}
20+
21+
.productHeadingBadge {
22+
margin-left: auto;
23+
display: flex;
24+
align-items: center;
1925
}

src/theme/DocItem/Content/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ function useSyntheticTitle() {
2828
}
2929
return metadata.title;
3030
}
31-
export default function DocItemContent({children}) {
32-
33-
const { frontMatter: {e2eSpecific, componentSpecific} } = useDoc();
34-
const testTypePill = e2eSpecific && <E2EOnlyBadge /> || componentSpecific && <ComponentOnlyBadge />
31+
export default function DocItemContent({children}: {children: React.ReactNode}) {
3532

3633
const syntheticTitle = useSyntheticTitle();
3734
return (
@@ -41,7 +38,6 @@ return (
4138
<div className={s.mainContentHeader}>
4239
<div className={s.headerWrapper}>
4340
<Heading as="h1">{syntheticTitle}</Heading>
44-
{testTypePill}
4541
</div>
4642
</div>
4743
</header>

0 commit comments

Comments
 (0)