Skip to content

Commit

Permalink
fix(baseline): checkmarks weren't reflecting mobile status (#11002)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA authored Apr 25, 2024
1 parent 81ec2a7 commit 242c2f8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
59 changes: 42 additions & 17 deletions client/src/document/baseline-indicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,35 @@ import { useLocation } from "react-router";

import "./baseline-indicator.scss";

import type { SupportStatus } from "../../../libs/types/web-features";
import type {
SupportStatus,
browserIdentifier,
} from "../../../libs/types/web-features";

const ENGINES = [
{ name: "Blink", browsers: ["Chrome", "Edge"] },
{ name: "Gecko", browsers: ["Firefox"] },
{ name: "WebKit", browsers: ["Safari"] },
interface BrowserGroup {
name: string;
ids: browserIdentifier[];
}

const ENGINES: {
name: string;
browsers: BrowserGroup[];
}[] = [
{
name: "Blink",
browsers: [
{ name: "Chrome", ids: ["chrome", "chrome_android"] },
{ name: "Edge", ids: ["edge"] },
],
},
{
name: "Gecko",
browsers: [{ name: "Firefox", ids: ["firefox", "firefox_android"] }],
},
{
name: "WebKit",
browsers: [{ name: "Safari", ids: ["safari", "safari_ios"] }],
},
];

const LOCALIZED_BCD_IDS = {
Expand Down Expand Up @@ -52,25 +75,27 @@ export function BaselineIndicator({ status }: { status: SupportStatus }) {
pathname
)}&level=${level}`;

const supported = (browser: string) => {
const version: string | undefined = status.support?.[browser.toLowerCase()];
return Boolean(status.baseline || version);
const supported = (browser: BrowserGroup) => {
return browser.ids
.map((id) => status.support?.[id])
.every((version) => Boolean(version));
};

const engineTitle = (browsers: string[]) =>
const engineTitle = (browsers: BrowserGroup[]) =>
browsers
.map((browser, index, array) => {
const previous = index > 0 ? supported(array[index - 1]) : undefined;
const current = supported(browser);
const name = browser.name;
return typeof previous === "undefined"
? current
? `Supported in ${browser}`
: `Not widely supported in ${browser}`
? `Supported in ${name}`
: `Not widely supported in ${name}`
: current === previous
? ` and ${browser}`
? ` and ${name}`
: current
? `, and supported in ${browser}`
: `, and not widely supported in ${browser}`;
? `, and supported in ${name}`
: `, and not widely supported in ${name}`;
})
.join("");

Expand Down Expand Up @@ -105,12 +130,12 @@ export function BaselineIndicator({ status }: { status: SupportStatus }) {
<span key={name} className="engine" title={engineTitle(browsers)}>
{browsers.map((browser) => (
<span
key={browser}
className={`browser ${browser.toLowerCase()} ${
key={browser.ids[0]}
className={`browser ${browser.ids[0]} ${
supported(browser) ? "supported" : ""
}`}
role="img"
aria-label={`${browser} ${
aria-label={`${browser.name} ${
supported(browser) ? "check" : "cross"
}`}
/>
Expand Down
2 changes: 1 addition & 1 deletion libs/types/web-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface FeatureData {
| [usage_stats_url, usage_stats_url, ...usage_stats_url[]]; // A single URL or an array of two or more
}

type browserIdentifier =
export type browserIdentifier =
| "chrome"
| "chrome_android"
| "edge"
Expand Down

0 comments on commit 242c2f8

Please sign in to comment.