Skip to content

Commit

Permalink
Proper response layout for utility selector + refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
oyamauchi committed Aug 31, 2023
1 parent ca170d7 commit 51c471a
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 95 deletions.
32 changes: 0 additions & 32 deletions src/calculator-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,38 +74,6 @@ const HOUSEHOLD_SIZE_OPTIONS: OptionParam[] = [1, 2, 3, 4, 5, 6, 7, 8].map(
},
);

export const utilityFormTemplate = (
utilityId: string,
utilityOptions: OptionParam[],
onChange: (utilityId: string) => void,
) => {
return html`
<form>
<div>
<label for="utility">
Electric Utility
<sl-tooltip
content="Choose the company you pay your electric bill to."
hoist
>
${questionIcon(18, 18)}
</sl-tooltip>
<br />
${select({
id: 'utility',
required: true,
options: utilityOptions,
currentValue: utilityId,
tabIndex: 0,
onChange: event =>
onChange((event.target as HTMLInputElement).value),
})}
</label>
</div>
</form>
`;
};

export const formTemplate = (
[
project,
Expand Down
33 changes: 12 additions & 21 deletions src/state-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@ import { LitElement, html, nothing } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { Task, TaskStatus, initialState } from '@lit-labs/task';
import { baseStyles, gridStyles } from './styles';
import {
formTemplate,
formStyles,
utilityFormTemplate,
} from './calculator-form';
import { formTemplate, formStyles } from './calculator-form';
import { FilingStatus, OwnerStatus } from './calculator-types';
import { CALCULATOR_FOOTER } from './calculator-footer';
import { fetchApi } from './api/fetch';
import {
stateIncentivesTemplate,
stateIncentivesStyles,
cardStyles,
dividerStyles,
separatorStyles,
iconTabStyles,
} from './state-incentive-details';
import { OptionParam } from './select';
import { STATES } from './states';
import { Project } from './projects';
import {
utilitySelectorStyles,
utilitySelectorTemplate,
} from './utility-selector';

const loadingTemplate = () => html`
<div class="card card-content">Loading...</div>
Expand All @@ -44,7 +42,7 @@ export class RewiringAmericaStateCalculator extends LitElement {
gridStyles,
...formStyles,
stateIncentivesStyles,
dividerStyles,
utilitySelectorStyles,
separatorStyles,
iconTabStyles,
];
Expand Down Expand Up @@ -198,19 +196,12 @@ export class RewiringAmericaStateCalculator extends LitElement {
this.isFormComplete() &&
this._utilityOptionsTask.status === TaskStatus.COMPLETE &&
this._utilityOptionsTask.value
? html` <div class="divider">
<h1 class="divider__section">
Incentives available to you in ${STATES[this.state]}
</h1>
<div class="spacer"></div>
<div class="divider__section card card-content">
${utilityFormTemplate(
this.utility,
this._utilityOptionsTask.value,
newUtility => (this.utility = newUtility),
)}
</div>
</div>`
? utilitySelectorTemplate(
this.state,
this.utility,
this._utilityOptionsTask.value,
newUtility => (this.utility = newUtility),
)
: nothing;

return html`
Expand Down
45 changes: 3 additions & 42 deletions src/state-incentive-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const stateIncentivesStyles = css`
}
}
@media only screen and (max-width: 600px) {
@media only screen and (max-width: 640px) {
.grid-section {
margin: 0 1rem;
min-width: 200px;
Expand Down Expand Up @@ -140,7 +140,7 @@ export const cardStyles = css`
}
/* Extra small devices */
@media only screen and (max-width: 600px) {
@media only screen and (max-width: 640px) {
.card {
margin: 0 1rem;
min-width: 200px;
Expand All @@ -155,45 +155,6 @@ export const cardStyles = css`
}
`;

export const dividerStyles = css`
.divider {
display: flex;
flex-wrap: wrap;
& h1 {
font-size: 2.25rem;
font-weight: 700;
line-height: 125%;
}
& .spacer {
flex-grow: 1;
height: 2rem;
}
}
.divider__section {
width: 25rem;
}
/* Extra small devices */
@media only screen and (max-width: 600px) {
.divider {
margin: 0 1rem;
min-width: 200px;
& h1 {
text-align: center;
}
& .card {
/* Margin is provided by the outer element */
margin: 0;
}
}
}
`;

export const iconTabStyles = css`
.icon-tab-bar {
display: flex;
Expand Down Expand Up @@ -270,7 +231,7 @@ export const separatorStyles = css`
height: 1px;
}
@media only screen and (max-width: 600px) {
@media only screen and (max-width: 640px) {
.separator {
display: none;
}
Expand Down
99 changes: 99 additions & 0 deletions src/utility-selector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { css, html } from 'lit';
import { questionIcon } from './icons';
import { OptionParam, select } from './select';
import { STATES } from './states';

export const utilitySelectorStyles = css`
.utility-selector {
display: grid;
& h1 {
font-weight: 700;
line-height: 125%;
text-align: center;
font-size: 1.75rem;
}
& .spacer {
height: 1.5rem;
}
}
/* Extra small devices: map above selector */
@media only screen and (max-width: 640px) {
.utility-selector {
grid-template-columns: 1fr;
margin: 0 1rem;
min-width: 200px;
& .card {
/* Margin is provided by the outer element */
margin: 0;
}
}
}
/* Medium and large: map and selector side by side */
@media only screen and (min-width: 640px) {
.utility-selector {
grid-template-columns: 5fr 2fr 5fr;
}
}
@media only screen and (min-width: 768px) {
.utility-selector {
& h1 {
text-align: left;
font-size: 2.25rem;
}
}
}
`;

const utilityFormTemplate = (
utilityId: string,
utilityOptions: OptionParam[],
onChange: (utilityId: string) => void,
) => {
return html`
<form>
<div>
<label for="utility">
Electric Utility
<sl-tooltip
content="Choose the company you pay your electric bill to."
hoist
>
${questionIcon(18, 18)}
</sl-tooltip>
<br />
${select({
id: 'utility',
required: true,
options: utilityOptions,
currentValue: utilityId,
tabIndex: 0,
onChange: event =>
onChange((event.target as HTMLInputElement).value),
})}
</label>
</div>
</form>
`;
};

export const utilitySelectorTemplate = (
state: string,
utilityId: string,
utilityOptions: OptionParam[],
onChange: (utilityId: string) => void,
) =>
html` <div class="utility-selector">
<h1>Incentives available to you in ${STATES[state]}</h1>
<div class="spacer"></div>
<div class="card card-content">
${utilityFormTemplate(utilityId, utilityOptions, onChange)}
</div>
</div>`;

0 comments on commit 51c471a

Please sign in to comment.