Skip to content

Commit

Permalink
Merge pull request #41 from concord-consortium/188162647-checkbox
Browse files Browse the repository at this point in the history
Add custom checkbox with correct styling
  • Loading branch information
pjanik authored Aug 28, 2024
2 parents c0924fd + aeea67d commit 012ba08
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/assets/images/checkbox.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions src/components/checkbox.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.custom-checkbox {
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;

label {
pointer-events: none;
}

&:hover {
svg {
.outline {
display: block;
}
}
}

&.disabled {
pointer-events: none;
opacity: 0.4;
}

svg {
margin-right: 6px;

.outline {
display: none;
}

.checkmark {
display: none;
}

&.checked {
.checkmark {
display: block;
}
}
}
}
27 changes: 27 additions & 0 deletions src/components/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";
import { clsx } from "clsx";

import CheckboxSVG from "../assets/images/checkbox.svg";

import "./checkbox.scss";

interface ICheckboxProps {
checked: boolean;
onChange: (checked: boolean) => void;
label: string;
disabled?: boolean;
}

// Checkbox component that uses custom CheckoboxSVG instead of the default input style.
export const Checkbox = ({ checked, onChange, label, disabled }: ICheckboxProps) => {
const handleClick = () => {
onChange(!checked);
};

return (
<div className={clsx("custom-checkbox", { disabled })} onClick={handleClick}>
<CheckboxSVG className={clsx("checkbox-icon", { checked })} />
<label>{label}</label>
</div>
);
}
21 changes: 7 additions & 14 deletions src/grasp-seasons/components/seasons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import PlayIcon from "../../assets/images/play-icon.svg";
import PauseIcon from "../../assets/images/pause-icon.svg";

import "./seasons.scss";
import { Checkbox } from "../../components/checkbox";

const ANIM_SPEED = 0.02;
const DAILY_ROTATION_ANIM_SPEED = 0.0003;
Expand Down Expand Up @@ -195,11 +196,6 @@ const Seasons: React.FC<IProps> = ({ lang = "en_us", initialState = {}, log = (a
});
};

const handleSimCheckboxChange = (event: ChangeEvent<HTMLInputElement>) => {
setSimState(prevState => ({ ...prevState, [event.target.name as any as keyof ISimState]: event.target.checked }));
logCheckboxChange(event);
};

const handleLatSliderChange = (event: any, ui: any) => {
setSimState(prevState => ({ ...prevState, lat: ui.value }));
setLatitude(formatLatLongNumber(ui.value));
Expand Down Expand Up @@ -284,15 +280,12 @@ const Seasons: React.FC<IProps> = ({ lang = "en_us", initialState = {}, log = (a
{ playStopLabel }
</button>
</div>
<label>
<input
type="checkbox"
name="dailyRotation"
checked={simState.dailyRotation}
onChange={handleSimCheckboxChange}
/>
{ t("~DAILY_ROTATION", simLang) }
</label>
<Checkbox
checked={simState.dailyRotation}
onChange={checked => setSimState(prevState => ({ ...prevState, dailyRotation: checked }))}
label={ t("~DAILY_ROTATION", simLang) }
disabled={!mainAnimationStarted}
/>
</div>
<div className="tilt-slider">
<label>{ t("~TILT_VIEW", simLang) }</label>
Expand Down

0 comments on commit 012ba08

Please sign in to comment.