Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions components/baseline-indicator/hook.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
try {
const indicator = document.querySelector(".baseline-indicator");
if (indicator instanceof HTMLDetailsElement) {
indicator.addEventListener("toggle", () => {
const { openByDefault } = indicator.dataset;
if (openByDefault === undefined) {
indicator.addEventListener("toggle", () => {
saveState(indicator.open);
});
saveState(indicator.open);
});
saveState(indicator.open);
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion components/baseline-indicator/server.css
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@
padding-right: 1rem;
padding-bottom: 1.5rem;

a {
font-weight: 500;
}

p {
margin-top: 0;
margin-bottom: 1rem;
Expand All @@ -231,7 +235,6 @@

li {
margin: 0;
font-weight: 500;
list-style: none;

a.learn-more {
Expand Down
33 changes: 33 additions & 0 deletions components/baseline-indicator/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@
const SURVEY_URL =
"https://survey.alchemer.com/s3/7634825/MDN-baseline-feedback";

/** @type {Record<string, { url: string, votes: number }>} */
let signalsData = {};

try {
const signalsRes = await fetch(
"https://web-platform-dx.github.io/developer-signals/web-features-signals.json",
);
signalsData = await signalsRes.json();
} catch {
// noop
}

export class BaselineIndicator extends ServerComponent {
static inlineScript = inlineScript;

Expand Down Expand Up @@ -80,6 +92,8 @@

const feedbackLink = `${SURVEY_URL}?page=${encodeURIComponent(context.url)}&level=${level}`;

const signalsLink = signalsData[status.feature.id]?.url;

Check failure on line 95 in components/baseline-indicator/server.js

View workflow job for this annotation

GitHub Actions / lint

Property 'id' does not exist on type 'FeatureData'.

const isBrowserSupported =
/** @param {import("./types.js").BrowserGroup} browser */ (browser) => {
return browser.ids.map((id) => status.support?.[id]).every(Boolean);
Expand Down Expand Up @@ -128,9 +142,13 @@
}
};

const openByDefault = Boolean(signalsLink);

return html`<details
class="baseline-indicator ${level}"
data-glean-toggle-open="baseline_toggle_open"
?open=${openByDefault}
?data-open-by-default=${openByDefault}
>
<summary>
<span
Expand Down Expand Up @@ -183,6 +201,21 @@
<span class="icon icon-chevron"></span>
</summary>
<div class="extra">
${signalsLink
? html`<p>
${context.l10n.raw({
id: "baseline-signals",
elements: {
link: {
tag: "a",
href: signalsLink,
target: "_blank",
"data-glean-id": "baseline_link_signals",
},
},
})}
</p>`
: nothing}
${level === "high" && low_date
? html`<p>
${context.l10n.raw({
Expand Down
1 change: 1 addition & 0 deletions l10n/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ baseline-not-extra = This feature is not Baseline because it does not work in so
baseline-supported-in = Supported in { $browsers }
baseline-unsupported-in = Not widely supported in { $browsers }
baseline-supported-and-unsupported-in = Supported in { $supported }, but not widely supported in { $unsupported }
baseline-signals = Want more support for this feature? <a data-l10n-name="link">Tell us why!</a>

homepage-hero-title = Resources for Developers,<br> by Developers
homepage-hero-description = Documenting <a data-l10n-name="css">CSS</a>, <a data-l10n-name="html">HTML</a>, and <a data-l10n-name="js">JavaScript</a>, since 2005.
Expand Down
Loading