-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User can select place / state options.
- Loading branch information
Showing
10 changed files
with
274 additions
and
4 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
export const placeOptions = { | ||
label: "Size of area for data", | ||
options : ["State", "County"] | ||
}; | ||
|
||
export const stateOptions = { | ||
label: "Choose states to include in your dataset from the list below", | ||
options: [ | ||
"Alabama", | ||
"Alaska", | ||
"Arizona", | ||
"Arkansas", | ||
"California", | ||
"Colorado", | ||
"Connecticut", | ||
"Delaware", | ||
"Florida", | ||
"Georgia", | ||
"Hawaii", | ||
"Idaho", | ||
"Illinois", | ||
"Indiana", | ||
"Iowa", | ||
"Kansas", | ||
"Kentucky", | ||
"Louisiana", | ||
"Maine", | ||
"Maryland", | ||
"Massachusetts", | ||
"Michigan", | ||
"Minnesota", | ||
"Mississippi", | ||
"Missouri", | ||
"Montana", | ||
"Nebraska", | ||
"Nevada", | ||
"New Hampshire", | ||
"New Jersey", | ||
"New Mexico", | ||
"New York", | ||
"North Carolina", | ||
"North Dakota", | ||
"Ohio", | ||
"Oklahoma", | ||
"Oregon", | ||
"Pennsylvania", | ||
"Rhode Island", | ||
"South Carolina", | ||
"South Dakota", | ||
"Tennessee", | ||
"Texas", | ||
"Utah", | ||
"Vermont", | ||
"Virginia", | ||
"Washington", | ||
"West Virginia", | ||
"Wisconsin", | ||
"Wyoming" | ||
] | ||
}; | ||
|
||
export const defaultSelectedOptions = { | ||
place: null, | ||
states: [] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
.radioOptions, .checkOptions { | ||
margin-top: 10px; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.radioOptions { | ||
display: flex; | ||
flex-direction: row; | ||
gap: 20px; | ||
} | ||
|
||
.option { | ||
display: flex; | ||
align-items: center; | ||
height: 24px; | ||
flex-basis: 120px; | ||
padding: 6px; | ||
label { | ||
padding-top: 3px; | ||
} | ||
} | ||
|
||
.radio { | ||
-webkit-appearance: none; | ||
-moz-appearance: none; | ||
appearance: none; | ||
width: 17px; | ||
height: 17px; | ||
font-size: 17px; | ||
background-image: url('../assets/radio-button-unchecked.svg'); | ||
color: var(--teal-dark-75); | ||
&:checked { | ||
background-image: url('../assets/radio-button-checked.svg'); | ||
} | ||
} | ||
|
||
.checkbox { | ||
-webkit-appearance: none; | ||
-moz-appearance: none; | ||
appearance: none; | ||
width: 17px; | ||
height: 17px; | ||
font-size: 17px; | ||
background-image: url('../assets/check-box-outline-blank.svg'); | ||
color: var(--teal-dark-75); | ||
&:checked { | ||
background-image: url('../assets/check-box.svg'); | ||
} | ||
} | ||
|
||
.checkOptions { | ||
flex-wrap: wrap; | ||
display: flex; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React from "react"; | ||
import { placeOptions, stateOptions } from "./constants"; | ||
|
||
import css from "./options.scss"; | ||
|
||
interface IProps { | ||
handleSetSelectedOptions: (option: string, value: string|string[]) => void; | ||
selectedPlace: string|null; | ||
selectedStates: string[]; | ||
} | ||
|
||
export const PlaceOptions: React.FC<IProps> = (props) => { | ||
const {handleSetSelectedOptions, selectedPlace, selectedStates} = props; | ||
|
||
const isStateSelected = (state: string) => { | ||
return selectedStates.indexOf(state) > - 1; | ||
}; | ||
|
||
const handleSelectPlace = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
handleSetSelectedOptions("place", e.target.value); | ||
}; | ||
|
||
const handleSelectState = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
let newSelectedStates = [...selectedStates]; | ||
if (e.currentTarget.checked) { | ||
newSelectedStates.push(e.target.value); | ||
newSelectedStates.sort(); | ||
|
||
} else { | ||
if (isStateSelected(e.target.value)) { | ||
newSelectedStates = newSelectedStates.filter((s) => s !== e.target.value); | ||
} | ||
} | ||
handleSetSelectedOptions("states", newSelectedStates); | ||
}; | ||
|
||
const createPlaceOptions = (options: string[]) => { | ||
return ( | ||
<> | ||
{options.map((o) => { | ||
return ( | ||
<div key={`radio-option-${o}`} className={css.option}> | ||
<input | ||
className={css.radio} | ||
id={o} | ||
type="radio" | ||
key={`radio-${o}`} | ||
value={o} | ||
checked={selectedPlace === o} | ||
onChange={handleSelectPlace} | ||
/> | ||
<label className={css.label} htmlFor={o} key={`label-${o}`}>{o}</label> | ||
</div> | ||
); | ||
})} | ||
</> | ||
); | ||
}; | ||
|
||
const createStateOptions = (options: string[]) => { | ||
return ( | ||
<> | ||
{options.map((o) => { | ||
return ( | ||
<div key={`checkbox-option-${o}`} className={css.option}> | ||
<input | ||
id={o} | ||
className={css.checkbox} | ||
type="checkbox" | ||
key={`checkbox-${o}`} | ||
value={o} | ||
checked={isStateSelected(o)} | ||
onChange={handleSelectState} | ||
/> | ||
<label className={css.label} htmlFor={o} key={`label-${o}`}>{o}</label> | ||
</div> | ||
); | ||
})} | ||
</> | ||
); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className={css.instruction}>{placeOptions.label}:</div> | ||
<div className={css.radioOptions}>{createPlaceOptions(placeOptions.options)}</div> | ||
<div className={css.instruction}>{stateOptions.label}:</div> | ||
<div className={css.checkOptions}>{createStateOptions(stateOptions.options)}</div> | ||
</> | ||
); | ||
}; |