Skip to content

Commit

Permalink
Merge pull request #40 from concord-consortium/188162665-text-inputs
Browse files Browse the repository at this point in the history
Update style of text inputs, disable square lat/long buttons when necessary
  • Loading branch information
pjanik authored Aug 28, 2024
2 parents 67c9445 + ea4d70e commit c0924fd
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/components/location-tab.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
margin-right: 10px;
}
input {
width: 236px;
padding: 7px 8px;
border-radius: $input-border-radius;
box-sizing: border-box;
border: $input-border;
@include text-input;
& {
width: 220px;
padding-left: 8px;
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/components/square-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@
&:active {
background-color: $teal-light-50;
}
&:disabled {
opacity: 0.4;
pointer-events: none;
}
}
5 changes: 3 additions & 2 deletions src/components/square-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import "./square-button.scss";
interface ISquareButtonProps {
onClick?: () => void;
children?: React.ReactNode;
disabled?: boolean;
}

export const SquareButton = (props: ISquareButtonProps) => {
const { children, onClick } = props;
const { children, onClick, disabled } = props;
return (
<button onClick={onClick} className="square-button">
<button onClick={onClick} className="square-button" disabled={disabled}>
{ children }
</button>
);
Expand Down
19 changes: 19 additions & 0 deletions src/components/vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,22 @@ $input-border: solid 1px rgba(23, 121, 145, 0.75);
pointer-events: none;
}
}

@mixin text-input {
color: $text-color;
font-family: $font-family;
font-size: 12px;
border-radius: $input-border-radius;
border: $input-border;
background-color: #fff;
height: 24px;
padding: 3px 6px;
outline: none;

&:hover {
background-color: $teal-light-12;
}
&:active, &:focus {
background-color: $teal-light-25;
}
}
6 changes: 1 addition & 5 deletions src/grasp-seasons/components/seasons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,7 @@
margin-bottom: 17px;

.lat-input, .long-input {
border-radius: 3px;
border: solid 1px rgba(23, 121, 145, 0.75);
background-color: #fff;
height: 24px;
padding: 3px 6px;
@include text-input;
}

.lat-input {
Expand Down
21 changes: 12 additions & 9 deletions src/grasp-seasons/components/seasons.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React, { useState, useEffect, useRef, ChangeEvent, useCallback } from "react";
import Slider from "./slider/slider";
import { changeMonthOfDayOfYear, formatLatLongNumber, getSolarNoonIntensity, isValidLatitude, isValidLongitude } from "../../utils/daylight-utils";
import {
changeMonthOfDayOfYear, formatLatLongNumber, getSolarNoonIntensity, isValidLatitude, isValidLongitude,
limitLatitude, limitLongitude
} from "../../utils/daylight-utils";
import InfiniteDaySlider from "./slider/infinite-day-slider";
import { Dropdown } from "../../components/dropdown";
import MyLocations from "./my-locations";
Expand Down Expand Up @@ -209,8 +212,8 @@ const Seasons: React.FC<IProps> = ({ lang = "en_us", initialState = {}, log = (a
}

const handleLatIncrement = (increment: number) => () => {
setSimState(prevState => ({ ...prevState, lat: prevState.lat + increment }));
setLatitude(formatLatLongNumber(simState.lat + increment));
setSimState(prevState => ({ ...prevState, lat: limitLatitude(prevState.lat + increment) }));
setLatitude(formatLatLongNumber(limitLatitude(simState.lat + increment)));
setLocationSearch("");
}

Expand All @@ -226,8 +229,8 @@ const Seasons: React.FC<IProps> = ({ lang = "en_us", initialState = {}, log = (a
}

const handleLongIncrement = (increment: number) => () => {
setSimState(prevState => ({ ...prevState, long: prevState.long + increment }));
setLongitude(formatLatLongNumber(simState.long + increment));
setSimState(prevState => ({ ...prevState, long: limitLongitude(prevState.long + increment) }));
setLongitude(formatLatLongNumber(limitLongitude(simState.long + increment)));
setLocationSearch("");
}

Expand Down Expand Up @@ -352,10 +355,10 @@ const Seasons: React.FC<IProps> = ({ lang = "en_us", initialState = {}, log = (a
<div className="long-lat-sliders">
<div className="slider-container">
<div className="top-row">
<SquareButton onClick={handleLatIncrement(-5)}><ForwardBackIcon /></SquareButton>
<SquareButton onClick={handleLatIncrement(-5)} disabled={simState.lat <= -90}><ForwardBackIcon /></SquareButton>
<label>{ t("~LATITUDE", simLang) }</label>
<input className="lat-input" type="text" value={latitude} onChange={handleLatInputChange} />
<SquareButton onClick={handleLatIncrement(5)}><ForwardBackIcon style={{transform: "rotate(180deg"}} /></SquareButton>
<SquareButton onClick={handleLatIncrement(5)} disabled={simState.lat >= 90}><ForwardBackIcon style={{transform: "rotate(180deg"}}/></SquareButton>
</div>
<Slider
value={simState.lat}
Expand All @@ -369,10 +372,10 @@ const Seasons: React.FC<IProps> = ({ lang = "en_us", initialState = {}, log = (a
</div>
<div className="slider-container">
<div className="top-row">
<SquareButton onClick={handleLongIncrement(-5)}><ForwardBackIcon /></SquareButton>
<SquareButton onClick={handleLongIncrement(-5)} disabled={simState.long <= -180}><ForwardBackIcon /></SquareButton>
<label>{ t("~LONGITUDE", simLang) }</label>
<input className="long-input" type="text" value={longitude} onChange={handleLongInputChange} />
<SquareButton onClick={handleLongIncrement(5)}><ForwardBackIcon style={{transform: "rotate(180deg"}} /></SquareButton>
<SquareButton onClick={handleLongIncrement(5)} disabled={simState.long >= 180}><ForwardBackIcon style={{transform: "rotate(180deg"}}/></SquareButton>
</div>
<Slider
value={simState.long}
Expand Down
8 changes: 8 additions & 0 deletions src/utils/daylight-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ export function formatLatLongNumber(value: number | string) {
return Number(value).toFixed(2).replace(/\.?0+$/, "");
}

export function limitLatitude(value: number): number {
return Math.min(90, Math.max(-90, value));
}

export function limitLongitude(value: number): number {
return Math.min(180, Math.max(-180, value));
}

export function changeMonthOfDayOfYear(dayOfYearIndex: number, monthsToAdd: number): number {
if (dayOfYearIndex < 0 || dayOfYearIndex >= 365) {
throw new Error("dayOfYearIndex must be between 0 and 364");
Expand Down

0 comments on commit c0924fd

Please sign in to comment.