Skip to content
Merged
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
40 changes: 40 additions & 0 deletions src/components/Header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const HEADER_LOGO = `
<svg viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
{/* Leaf */}
<path
d="M16 4C20 4 24 7 26 12C24 18 20 22 16 24C12 22 8 18 6 12C8 7 12 4 16 4Z"
fill="rgb(34, 197, 94)"
className="drop-shadow-sm"
/>
{/* Leaf vein */}
<path
d="M16 6L16 22"
stroke="rgb(21, 128, 61)"
strokeWidth="1"
className="opacity-60"
/>
{/* Small bar chart at bottom */}
<g transform="translate(10, 25)">
<rect x="0" y="2" width="2" height="4" fill="rgb(34, 197, 94)" />
<rect x="3" y="0" width="2" height="6" fill="rgb(234, 179, 8)" />
<rect x="6" y="1" width="2" height="5" fill="rgb(239, 68, 68)" />
<rect x="9" y="3" width="2" height="3" fill="rgb(34, 197, 94)" />
</g>
</svg>
`;

export const createHeader = () => {
const header = document.createElement("header");
header.classList.add("cv-header");

header.innerHTML = HEADER_LOGO;
const logo = header.querySelector("svg");
logo.classList.add("cv-header__logo");

const title = document.createElement("h1");
title.classList.add("cv-header__title");
title.innerText = "Carbon Visualizer";
header.append(title);

return header;
}
21 changes: 19 additions & 2 deletions src/core/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class Panel {

// Load panel-specific JavaScript
await this.loadPanelJS();

// Load universal components
await this.loadHeader();
}

async loadPanelHTML() {
Expand Down Expand Up @@ -96,6 +99,20 @@ class Panel {
}
}

async loadHeader() {
try {
// Import component module and insert onto the page
const componentUrl = this.browserAPI.runtime.getURL('src/components/Header.js');
const componentModule = await import(componentUrl);

const header = componentModule.createHeader();
const fallbackHeader = this.container.querySelector('header.cv-header');
fallbackHeader.replaceWith(header);
} catch (error) {
console.error(error);
}
}

async waitForElements() {
// Wait a small amount for DOM to be ready
await new Promise(resolve => setTimeout(resolve, 50));
Expand All @@ -120,8 +137,8 @@ class Panel {

getFallbackHTML() {
return `
<header class="cv-panel__header">
<h2 class="cv-panel__title">Carbon Visualizer - ${this.type}</h2>
<header class="cv-header">
<h1 class="cv-header__title">Carbon Visualizer - ${this.type}</h1>
</header>
<main class="cv-panel__content">
<p>Panel content for ${this.type}</p>
Expand Down
4 changes: 2 additions & 2 deletions src/panels/results/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</head>
<body>
<div id="cv-panel-content">
<header class="cv-panel__header">
<h1 class="cv-panel__title">Carbon Visualizer</h1>
<header class="cv-header">
<h1 class="cv-header__title">Carbon Visualizer</h1>
</header>

<main class="cv-panel__content">
Expand Down
4 changes: 2 additions & 2 deletions src/panels/welcome/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</head>
<body>
<div id="cv-panel-content">
<header class="cv-panel__header">
<h1 class="cv-panel__title">Carbon Visualizer</h1>
<header class="cv-header">
<h1 class="cv-header__title">Carbon Visualizer</h1>
</header>

<main class="cv-panel__content">
Expand Down
22 changes: 17 additions & 5 deletions src/styles/core.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,28 @@
}

/* Panel header */
.cv-panel__header {
padding: 1rem 1.5rem 0.5rem;
border-bottom: 1px solid var(--cv-white);
.cv-header {
display: flex;
gap: 1rem;
align-items: center;
padding: 1rem 1.5rem;
/* TODO: The `border-bottom` color is equal to `--cv-color-gray-50` and should be replaced with the variable when implemented */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can create a ticket for this if needed. I think we could add :root to the selector for all of the color variables, or maybe we could to add the .cv class to the topmost .cv-panel div (I think?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would be great! I'm not seeing an existing ticket for implementing our .cv styles, but we could include moving and renaming --cv-black and --cv-white in that work too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea- I will create that today 😊

border-bottom: 1px solid oklch(from oklch(50.0% 0.000 0) 50% calc(0 + (sin(0.6 * pi) * c)) h);
background-color: var(--cv-white);
}

.cv-header__logo {
--header-logo-dimensions: 2rem;

width: var(--header-logo-dimensions);
height: var(--header-logo-dimensions);
}

.cv-panel__title {
.cv-header__title {
margin: 0;
font-size: 1.125rem;
font-weight: 600;
color: var(--cv-white);
color: var(--cv-black);
}

/* Panel content */
Expand Down