Skip to content

Commit

Permalink
Finalize integration of multiselect into state calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangster committed Sep 20, 2023
1 parent 007016f commit 95021b1
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 290 deletions.
4 changes: 0 additions & 4 deletions .parcelrc

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"cypress": "^12.6.0",
"eslint": "^8.45.0",
"parcel": "v2.8.3",
"parcel-reporter-static-files-copy": "^1.5.2",
"postcss": "^8.4.21",
"postcss-modules": "^6.0.0",
"posthtml": "^0.16.6",
Expand Down
2 changes: 2 additions & 0 deletions src/calculator-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export const formTemplate = (
.map(([value, data]) => ({ value, label: data.label }))
.sort((a, b) => a.label.localeCompare(b.label)),
currentValues: projects,
placeholder: 'None selected',
maxOptionsVisible: 1,
placement: 'top',
})}
</label>
</div> `
Expand Down
31 changes: 26 additions & 5 deletions src/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ export interface SelectParam {
disabled?: boolean;
}

export interface MultiSelectParam {
export interface SLSelectParam {
id: string;
label?: string;
currentValues: string[];
options: OptionParam[];
helpText?: string;
placeholder?: string;
placement?: string;
required?: boolean;
ariaLabel?: string;
}

export interface SingleSelectParam extends SLSelectParam {
currentValue: string;
onChange?: (event: SlChangeEvent) => void;
}

export interface MultiSelectParam extends SLSelectParam {
currentValues: string[];
maxOptionsVisible?: number;
}

Expand Down Expand Up @@ -72,6 +83,7 @@ export const multiselect = ({
helpText,
placeholder,
maxOptionsVisible,
placement,
}: MultiSelectParam) => {
return html`
<div>
Expand All @@ -83,10 +95,12 @@ export const multiselect = ({
help-text="${ifDefined(helpText)}"
placeholder="${ifDefined(placeholder)}"
max-options-visible="${ifDefined(maxOptionsVisible)}"
placement="${ifDefined(placement)}"
hoist
multiple
clearable
>
<sl-icon slot="expand-icon" name="caret-down-fill"></sl-icon>
<sl-icon slot="expand-icon"></sl-icon>
${options.map(o => multioption(o))}
</sl-select>
<span class="focus"></span>
Expand Down Expand Up @@ -223,6 +237,9 @@ export const selectStyles = css`
sl-select {
--sl-input-height-medium: 2.8215rem;
--sl-input-font-family: var(--ra-embed-font-family);
--sl-input-focus-ring-color: var(--select-focus);
--sl-input-focus-ring-style: solid;
--sl-focus-ring-width: 1px;
Expand Down Expand Up @@ -260,7 +277,11 @@ export const selectStyles = css`
}
sl-select::part(expand-icon) {
width: 0.75em;
height: 0.5em;
content: '';
justify-self: end;
width: 0.6em;
height: 0.4em;
background-color: var(--select-arrow);
clip-path: polygon(100% 0%, 0 0%, 50% 100%);
}
`;
11 changes: 6 additions & 5 deletions src/state-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ export class RewiringAmericaStateCalculator extends LitElement {
utility: string = '';

@property({ type: Array })
projects: Project[] = ['battery'];
projects: Project[] = [];

@property({ type: String })
selectedProjectTab: Project = 'battery';
selectedProjectTab: Project | undefined;

@property({ type: String })
selectedOtherTab: Project = 'battery';
Expand Down Expand Up @@ -247,10 +247,11 @@ export class RewiringAmericaStateCalculator extends LitElement {
: stateIncentivesTemplate(
results,
this.projects,
this.selectedProjectTab,
this.selectedOtherTab,
newOtherSelection =>
(this.selectedOtherTab = newOtherSelection),
newSelection => (this.selectedProjectTab = newSelection),
newOtherSelection => (this.selectedOtherTab = newOtherSelection),
this.selectedOtherTab,
this.selectedProjectTab,
),
error: errorTemplate,
})}
Expand Down
19 changes: 13 additions & 6 deletions src/state-incentive-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ const gridTemplate = (
export const stateIncentivesTemplate = (
response: APIResponse,
selectedProjects: Project[],
selectedProjectTab: Project,
selectedOtherTab: Project,
onTabSelected: (newSelection: Project) => void,
onOtherTabSelected: (newOtherSelection: Project) => void,
onTabSelected: (newSelection: Project) => void,
selectedOtherTab: Project,
selectedProjectTab?: Project,
) => {
const allEligible = response.incentives.filter(i => i.eligible);

Expand All @@ -419,16 +419,23 @@ export const stateIncentivesTemplate = (
.sort(([a], [b]) => shortLabel(a).localeCompare(shortLabel(b)))
.map(([project]) => project);

const projectTab = selectedProjectTab ?? selectedProjects[0];
const selectedIncentives = incentivesByProject[projectTab] ?? [];
const otherIncentivesLabel =
selectedIncentives.length == 0
? 'Incentives available to you'
: 'Other incentives available to you';

return html` ${atAGlanceTemplate(response)}
${gridTemplate(
"Incentives you're interested in",
incentivesByProject[selectedProjectTab] ?? [],
selectedIncentives,
selectedProjects,
selectedProjects.includes(selectedProjectTab) ? selectedProjectTab : selectedProjects[0],
selectedProjects.includes(projectTab) ? projectTab : selectedProjects[0],
onTabSelected,
)}
${gridTemplate(
'Other incentives available to you',
otherIncentivesLabel,
incentivesByProject[selectedOtherTab] ?? [],
otherTabs,
// If a nonexistent tab is selected, pretend the first one is selected.
Expand Down
3 changes: 0 additions & 3 deletions static/assets/icons/caret-down-fill.svg

This file was deleted.

Loading

0 comments on commit 95021b1

Please sign in to comment.