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

First cut at RI state calculator #15

Closed
wants to merge 21 commits into from
Closed
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"source": [
"src/calculator.ts",
"src/rewiring-fonts.css",
"src/index.html"
"src/index.html",
"src/rhode-island.html"
],
"outputFormat": "global",
"context": "browser",
Expand Down
63 changes: 63 additions & 0 deletions src/api/calculator-types-v1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
export type IncentiveType =
| 'tax_credit'
| 'pos_rebate'
| 'rebate'
| 'account_credit'
| 'performance_rebate';
export type AuthorityType = 'federal' | 'state' | 'utility';

export type AmountType = 'dollar_amount' | 'percent' | 'dollars_per_unit';
export interface Amount {
type: AmountType;
number: number;
maximum?: number;
representative?: number;
unit?: string;
}

export type ItemType =
| 'battery_storage_installation'
| 'efficiency_rebates'
| 'electric_panel'
| 'electric_stove'
| 'electric_vehicle_charger'
| 'electric_wiring'
| 'geothermal_heating_installation'
| 'heat_pump_air_conditioner_heater'
| 'heat_pump_clothes_dryer'
| 'heat_pump_water_heater'
| 'new_electric_vehicle'
| 'rooftop_solar_installation'
| 'used_electric_vehicle'
| 'weatherization';

export interface Item {
type: ItemType;
name: string;
url: string;
}

export interface Incentive {
type: IncentiveType;
authority_type: AuthorityType;
authority_name: string | null;
program: string;
program_url?: string;
item: Item;
amount: Amount;
start_date: number;
end_date: number;
short_description?: string;

eligible: boolean;
}

export interface APIResponse {
savings: {
tax_credit: number;
pos_rebate: number;
rebate: number;
account_credit: number;
};
incentives: Incentive[];
}
236 changes: 137 additions & 99 deletions src/calculator-form.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { html, css } from 'lit';
import { html, css, nothing } from 'lit';
import { downIcon, questionIcon } from './icons';
import { select, selectStyles, OptionParam } from './select';
import { inputStyles } from './styles/input';
import './currency-input';
import '@shoelace-style/shoelace/dist/themes/light.css';
import '@shoelace-style/shoelace/dist/components/tooltip/tooltip.js';
import { PROJECTS } from './projects';

const buttonStyles = css`
button {
button.calculate {
appearance: none;
font-family: inherit;
font-size: 16px;
Expand All @@ -24,7 +25,7 @@ const buttonStyles = css`
width: 100%;
}

button:hover {
button.calculate:hover {
background-color: var(--ra-embed-primary-button-background-hover-color);
}

Expand Down Expand Up @@ -74,110 +75,147 @@ const HOUSEHOLD_SIZE_OPTIONS: OptionParam[] = [1, 2, 3, 4, 5, 6, 7, 8].map(
);

export const formTemplate = (
[zip, ownerStatus, householdIncome, taxFiling, householdSize]: Array<string>,
[
project,
zip,
ownerStatus,
householdIncome,
taxFiling,
householdSize,
]: Array<string>,
showProjectField: boolean,
onSubmit: (e: SubmitEvent) => void,
) => html`
<form @submit=${onSubmit}>
<div class="grid-3-2">
<div>
<label for="zip">
Zip
gridClass: string = 'grid-3-2',
) => {
const projectField = showProjectField
? html`<div>
<label for="project">
Project you're most interested in
<sl-tooltip
content="Your zip code helps determine the amount of discounts and tax credits you qualify for."
hoist
>${questionIcon(18, 18)}</sl-tooltip
><br />
<input
tabindex="0"
id="zip"
placeholder="12345"
name="zip"
required
type="text"
value="${zip}"
minlength="5"
maxlength="5"
inputmode="numeric"
pattern="[0-9]{5}"
/>
</label>
</div>
<div>
<label for="owner_status">
Homeowners Status
<sl-tooltip
content="Homeowners and renters qualify for different incentives."
hoist
>${questionIcon(18, 18)}</sl-tooltip
><br />
${select({
id: 'owner_status',
required: true,
options: OWNER_STATUS_OPTIONS,
currentValue: ownerStatus,
tabIndex: 0,
})}
</label>
</div>
<div>
<label for="household_income">
Household Income
<sl-tooltip
content="Enter your gross income (income before taxes). Include wages and salary plus other forms of income, including pensions, interest, dividends, and rental income. If you are married and file jointly, include your spouse's income"
hoist
>${questionIcon(18, 18)}</sl-tooltip
><br />
<ra-currency-input
id="household_income"
placeholder="$60,000"
name="household_income"
required
value=${householdIncome}
min="0"
max="100000000"
></ra-currency-input>
</label>
</div>
<div>
<label for="tax_filing">
Tax Filing
<sl-tooltip hoist
><div slot="content">
Select "Head of Household" if you have a child or relative living
with you, and you pay more than half the costs of your home.
Select "Joint" if you file your taxes as a married couple."
</div>
${questionIcon(18, 18)}</sl-tooltip
><br />
${select({
id: 'tax_filing',
required: true,
options: TAX_FILING_OPTIONS,
currentValue: taxFiling,
tabIndex: 0,
})}
</label>
</div>
<div>
<label for="household_size">
Household Size
<sl-tooltip
content="Include anyone you live with who you claim as a dependent on your taxes, and your spouse or partner if you file taxes together."
content="Select the project you're most interested in."
hoist
>${questionIcon(18, 18)}</sl-tooltip
><br />
${select({
id: 'household_size',
id: 'project',
required: true,
options: HOUSEHOLD_SIZE_OPTIONS,
currentValue: householdSize,
options: Object.entries(PROJECTS)
.map(([value, data]) => ({ value, label: data.label }))
.sort((a, b) => a.label.localeCompare(b.label)),
currentValue: project,
tabIndex: 0,
})}
</label>
</div> `
: nothing;

return html`
<form @submit=${onSubmit}>
<div class="${gridClass}">
${projectField}
<div>
<label for="zip">
Zip
<sl-tooltip
content="Your zip code helps determine the amount of discounts and tax credits you qualify for."
hoist
>${questionIcon(18, 18)}</sl-tooltip
><br />
<input
tabindex="0"
id="zip"
placeholder="12345"
name="zip"
required
type="text"
value="${zip}"
minlength="5"
maxlength="5"
inputmode="numeric"
pattern="[0-9]{5}"
/>
</label>
</div>
<div>
<label for="owner_status">
Homeowners Status
<sl-tooltip
content="Homeowners and renters qualify for different incentives."
hoist
>${questionIcon(18, 18)}</sl-tooltip
><br />
${select({
id: 'owner_status',
required: true,
options: OWNER_STATUS_OPTIONS,
currentValue: ownerStatus,
tabIndex: 0,
})}
</label>
</div>
<div>
<label for="household_income">
Household Income
<sl-tooltip
content="Enter your gross income (income before taxes). Include wages and salary plus other forms of income, including pensions, interest, dividends, and rental income. If you are married and file jointly, include your spouse's income"
hoist
>${questionIcon(18, 18)}</sl-tooltip
><br />
<ra-currency-input
id="household_income"
placeholder="$60,000"
name="household_income"
required
value=${householdIncome}
min="0"
max="100000000"
></ra-currency-input>
</label>
</div>
<div>
<label for="tax_filing">
Tax Filing
<sl-tooltip hoist
><div slot="content">
Select "Head of Household" if you have a child or relative
living with you, and you pay more than half the costs of your
home. Select "Joint" if you file your taxes as a married
couple."
</div>
${questionIcon(18, 18)}</sl-tooltip
><br />
${select({
id: 'tax_filing',
required: true,
options: TAX_FILING_OPTIONS,
currentValue: taxFiling,
tabIndex: 0,
})}
</label>
</div>
<div>
<label for="household_size">
Household Size
<sl-tooltip
content="Include anyone you live with who you claim as a dependent on your taxes, and your spouse or partner if you file taxes together."
hoist
>${questionIcon(18, 18)}</sl-tooltip
><br />
${select({
id: 'household_size',
required: true,
options: HOUSEHOLD_SIZE_OPTIONS,
currentValue: householdSize,
tabIndex: 0,
})}
</label>
</div>
<div>
<button class="calculate" type="submit">
Calculate! ${downIcon(18, 18)}
</button>
</div>
</div>
<div>
<button type="submit">Calculate! ${downIcon(18, 18)}</button>
</div>
</div>
</form>
`;
</form>
`;
};
2 changes: 2 additions & 0 deletions src/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@ export class RewiringAmericaCalculator extends LitElement {
? nothing
: formTemplate(
[
'',
this.zip,
this.ownerStatus,
this.householdIncome,
this.taxFiling,
this.householdSize,
],
false,
(event: SubmitEvent) => this.submit(event),
)}
</div>
Expand Down
Loading