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

Avatar Selector for RSVP Page #276

Merged
merged 6 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
24 changes: 24 additions & 0 deletions app/rsvp/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use client";
import AvatarSelector from "@/components/AvatarSelector/AvatarSelector";
import styles from "./styles.module.scss";
import { Formik } from "formik";

const RSVPTestingPage: React.FC = () => {
return (
<div className={styles.screen}>
<h1>RSVP Testing Page</h1>
<p>This page will be removed shortly.</p>
<br />
<Formik
initialValues={{
avatar: null
}}
onSubmit={() => {}}
>
<AvatarSelector name="avatar" label="Select your avatar:" />
</Formik>
</div>
);
};

export default RSVPTestingPage;
8 changes: 8 additions & 0 deletions app/rsvp/styles.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.screen {
background-size: cover;
background-repeat: no-repeat;
background-position: center;
width: 100vw;
min-height: 100vh;
padding-top: 150px;
}
38 changes: 38 additions & 0 deletions components/AvatarSelector/AvatarSelector.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.avatarSelector {
display: flex;
flex-wrap: wrap;
}

.avatarSelector .avatarIcon {
display: flex;
justify-content: center;
align-items: center;
width: 90px;
height: 90px;
margin: 5px;
cursor: pointer;
border-radius: 50%;
border: 3px solid transparent;
transition: border 0.2s ease-in-out;
&:hover {
cursor: pointer;
}
}

.avatarSelector .avatarIcon.selected {
border-color: #dfad72;
}

.avatarSelector .avatarIconImage {
width: 65px;
height: 65px;
:hover {
cursor: pointer;
}
}

.container {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
57 changes: 57 additions & 0 deletions components/AvatarSelector/AvatarSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"use client";
import { avatars } from "@/modules/avatars";
import { useField } from "formik";
import Image from "next/image";
import styles from "./AvatarSelector.module.scss";
import clsx from "clsx";

export type AvatarSelectorProps = {
name: string;
label: string;
required?: boolean;
};

const AvatarSelector: React.FC<AvatarSelectorProps> = ({
name,
label,
required
}) => {
const [field, meta, helpers] = useField(name);
const { setValue } = helpers;
const { value } = field;

return (
<div className={styles.container}>
<label htmlFor={name}>
{label}
{required && "*"}
</label>
<div className={styles.avatarSelector}>
{avatars.map(avatar => (
<div
style={{
backgroundColor:
avatar.backgroundColor ?? "transparent"
}}
className={clsx(
styles.avatarIcon,
avatar.name === value && styles.selected
)}
key={avatar.name}
onClick={() => {
setValue(avatar.name);
}}
>
<Image
className={styles.avatarIconImage}
src={avatar.icon}
alt={avatar.name}
/>
</div>
))}
</div>
</div>
);
};

export default AvatarSelector;
24 changes: 16 additions & 8 deletions modules/avatars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ import FishAvatar from "@/public/profile/avatars/fish.svg";
import { Avatars } from "@/util/types";

export const avatars = [
{ name: Avatars.BUNNY, icon: BunnyAvatar },
{ name: Avatars.SQUIRREL, icon: ChipmunkAvatar },
{ name: Avatars.GOBLIN, icon: YodaAvatar },
{ name: Avatars.CAT, icon: CatAvatar },
{ name: Avatars.MUSHROOM, icon: MushroomAvatar },
{ name: Avatars.FISHERCAT, icon: FisherAvatar },
{ name: Avatars.CHESTER, icon: GarfieldAvatar },
{ name: Avatars.AXOLOTL, icon: FishAvatar }
{ name: Avatars.BUNNY, icon: BunnyAvatar, backgroundColor: "#f0f0f0" },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AvatarSelector component uses the backgroundColor. I left it at f0f0f0 for all icons for now because, if I recall correctly, these are the HackIllinois 2024 avatar icons, so we can set new background colors (if preferred) once the new icons are ready.

{
name: Avatars.SQUIRREL,
icon: ChipmunkAvatar,
backgroundColor: "#f0f0f0"
},
{ name: Avatars.GOBLIN, icon: YodaAvatar, backgroundColor: "#f0f0f0" },
{ name: Avatars.CAT, icon: CatAvatar, backgroundColor: "#f0f0f0" },
{
name: Avatars.MUSHROOM,
icon: MushroomAvatar,
backgroundColor: "#f0f0f0"
},
{ name: Avatars.FISHERCAT, icon: FisherAvatar, backgroundColor: "#f0f0f0" },
{ name: Avatars.CHESTER, icon: GarfieldAvatar, backgroundColor: "#f0f0f0" },
{ name: Avatars.AXOLOTL, icon: FishAvatar, backgroundColor: "#f0f0f0" }
];
Loading