Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add authority logos at bottom of results #22

Merged
merged 1 commit into from
Sep 27, 2023
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
10 changes: 10 additions & 0 deletions src/api/calculator-types-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ export interface Incentive {
}

export interface APIResponse {
authorities: {
[authorityId: string]: {
name: string;
logo?: {
src: string;
width: number;
height: number;
};
};
};
savings: {
tax_credit: number;
pos_rebate: number;
Expand Down
69 changes: 69 additions & 0 deletions src/authority-logos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { css, html, nothing } from 'lit';
import { APIResponse } from './api/calculator-types-v1';

export const authorityLogosStyles = css`
.authority-logos {
width: 100%;
max-width: 1280px;
Copy link
Member

Choose a reason for hiding this comment

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

We should probably have a variable for this and ensure we're doing maximum widths consistently on all the elements?


background-color: white;
}

.authority-logos h2 {
text-align: center;
color: #111;
font-size: 2rem;
font-weight: 500;
line-height: 125%;

margin: 48px 24px 64px 24px;
}

/* Tighter margins for the header on small screens */
@media only screen and (max-width: 640px) {
.authority-logos h2 {
font-size: 1.5rem;
margin-top: 32px;
margin-bottom: 48px;
}
}

.authority-logos__container {
display: flex;

flex-wrap: wrap;
justify-content: center;
align-items: flex-start;
gap: 64px;

margin-bottom: 80px;
}
`;

/**
* Displays the white area at the bottom of the calculator results with logos
* of the authorities whose incentives are displayed.
*/
export const authorityLogosTemplate = (response: APIResponse) => {
if (Object.keys(response.authorities).length === 0) {
return nothing;
}

const logos = Object.values(response.authorities)
.filter(auth => !!auth.logo)
.map(
auth =>
html`<img
src="${auth.logo!.src}"
width="${auth.logo!.width}"
height="${auth.logo!.height}"
/>`,
);

return html`
<div class="authority-logos">
<h2>Incentive data brought to you by</h2>
<div class="authority-logos__container">${logos}</div>
</div>
`;
};
2 changes: 2 additions & 0 deletions src/state-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { iconTabBarStyles } from './icon-tab-bar';

import '@shoelace-style/shoelace/dist/components/spinner/spinner';
import { STATES } from './states';
import { authorityLogosStyles } from './authority-logos';

const loadingTemplate = () => html`
<div class="card card-content">
Expand Down Expand Up @@ -50,6 +51,7 @@ export class RewiringAmericaStateCalculator extends LitElement {
utilitySelectorStyles,
separatorStyles,
iconTabBarStyles,
authorityLogosStyles,
];

/* supported properties to control showing/hiding of each card in the widget */
Expand Down
4 changes: 3 additions & 1 deletion src/state-incentive-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { APIResponse, Incentive, ItemType } from './api/calculator-types-v1';
import { exclamationPoint, questionIcon, upRightArrow } from './icons';
import { PROJECTS, Project, shortLabel } from './projects';
import { iconTabBarTemplate } from './icon-tab-bar';
import { authorityLogosTemplate } from './authority-logos';

export const stateIncentivesStyles = css`
.loading {
Expand Down Expand Up @@ -430,5 +431,6 @@ export const stateIncentivesTemplate = (
// If a nonexistent tab is selected, pretend the first one is selected.
otherTabs.includes(selectedOtherTab) ? selectedOtherTab : otherTabs[0],
onTabSelected,
)}`;
)}
${authorityLogosTemplate(response)}`;
};