Skip to content

Commit

Permalink
Merge pull request #17 from UofA-Blueprint/ASC-72
Browse files Browse the repository at this point in the history
ASC-72: Member Header + Input Field
  • Loading branch information
TienDucHo authored Mar 18, 2024
2 parents a0f99b8 + 00de364 commit 5661b94
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 36 deletions.
16 changes: 16 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import InputCodeTest from "@/routes/InputCodeTest";
import ToastTestRoute from "@/routes/ToastTestRoute";
import MediaUploadZoneTestRoute from "@/routes/MediaUploadZoneTestRoute";
import ColorPickerTestRoute from "@/routes/ColorPickerTestRoute";
import InputFieldTestRoute from "./routes/InputFieldTestRoute";

import MemberHeaderTestRoute from "@/routes/MemberHeaderTestRoute";
import { MemberInformation } from "./components/MemberInformation";

const router = createBrowserRouter([
Expand Down Expand Up @@ -61,6 +64,15 @@ const router = createBrowserRouter([
path: "/color-picker-test",
element: <ColorPickerTestRoute />,
},

{
path: "/member-header-test",
element: <MemberHeaderTestRoute />,
},
{
path: "/profile-test",
element: <ProfilePictureTest />,
},
{
path: "/member-information-test",
element: (
Expand All @@ -69,6 +81,10 @@ const router = createBrowserRouter([
</div>
),
},
{
path: "/input-field-test",
element: <InputFieldTestRoute />,
},
]);

function App() {
Expand Down
64 changes: 64 additions & 0 deletions src/components/InputField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { WarningCircle } from "@phosphor-icons/react";
import { useRef, useState } from "react";

export interface InputFieldProps {
type: string;
error: boolean;
label?: string; // Optional; Default to none.
required: boolean;
}

function InputField({ type, error, label, required }: InputFieldProps) {
// todo: functionality
const inputRef = useRef<HTMLInputElement>(null);

function checkLen(event: { preventDefault: () => void }) {
event.preventDefault();
if (inputRef.current) {
if (inputRef.current.value.trim() === "" && required === true) {
console.log("Required Input is empty");
}
}
}

return (
<div className="mt-5 w-[30em]">
{required === false ? (
<label className="font-extrabold block mb-1 ml-1 text-sm text-light-500 dark:text-white">
{label}
</label>
) : (
<label className="font-extrabold block mb-1 ml-1 text-sm text-light-500 dark:text-white">
{label} <span className="text-red-500"> * </span>
</label>
)}

{error !== true ? (
<input
placeholder={"Enter " + type + "..."}
type={type}
ref={inputRef}
onSelect={checkLen}
className="bg-gray-50 border border-gray-300 text-sm rounded-lg focus:outline-none focus:drop-shadow-[0_0px_5px_rgba(0,0,0,0.25)] hover:outline-none hover:drop-shadow-[0_0px_5px_rgba(0,0,0,0.25)] block w-full p-2.5 dark:text-black"
></input>
) : (
<div>
<input
placeholder={"Enter " + type + "..."}
type={type}
ref={inputRef}
onSelect={checkLen}
className="bg-gray-50 border border-red-500 text-light-500 text-sm rounded-lg focus:outline-none focus:drop-shadow-[0_0px_5px_rgba(0,0,0,0.25)] hover:outline-none hover:drop-shadow-[0_0px_5px_rgba(0,0,0,0.25)] block w-full p-2.5 dark:text-black"
></input>

<div className="flex mt-1 align-middle">
<WarningCircle color="red" className="mr-1" size={"1.1em"} />
<span className="text-red-500 text-xs "> Error {type} </span>
</div>
</div>
)}
</div>
);
}

export default InputField;
41 changes: 41 additions & 0 deletions src/components/MemberHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// MemberHeader.tsx
import { ReactNode } from "react";
import ProfilePictures from "./ProfilePictures";
import { twMerge } from "tailwind-merge";

interface MemberHeaderProp {
profilePicChildren: ReactNode;
backgroundColor:
| "tulip"
| "gold"
| "lime"
| "jade"
| "water"
| "air"
| "lilac"
| "candy";
username: string;
}

function MemberHeader({
profilePicChildren,
backgroundColor,
username,
}: MemberHeaderProp) {
return (
<div
className={twMerge("flex flex-col md:flex-row items-center w-full h-36")}
>
<div className="w-32 h-32">
<ProfilePictures backgroundColor={backgroundColor}>
{profilePicChildren}
</ProfilePictures>
</div>
<div className=" pl-2 font-bold justify-center flex pb-2 w-20">
<h1>{username}</h1>
</div>
</div>
);
}

export default MemberHeader;
56 changes: 27 additions & 29 deletions src/components/ProfilePictures.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
import * as Icon from '@phosphor-icons/react'
import { ReactNode } from 'react';
//define the prop types for the component
interface Props {
children: ReactNode;
backgroundColor: 'tulip' | 'gold' | 'lime' | 'jade' | 'water' | 'air' | 'lilac' | 'candy';
}
import * as Icon from "@phosphor-icons/react";
import { ReactNode } from "react";
import { twMerge } from "tailwind-merge";

interface Props {
children: ReactNode;
backgroundColor:
| "tulip"
| "gold"
| "lime"
| "jade"
| "water"
| "air"
| "lilac"
| "candy";
}

const ProfilePictures=(props:Props)=>{

const backgroundColor= `bg-profile-${props.backgroundColor}`
// return(<div>
// <div className="overflow-hidden justify-center items-center rounded-full w-32 h-32">
// {props.children?
// <img className="object-center w-32 h-32" src={props.children} alt="Profile Pic" />
// :
// <div className={`bg-profile-${props.backgroundColor} flex justify-center items-center rounded-full w-32 h-32`}>
// <Icon.PawPrint size={120} color={'white'} />
// </div>
// }

// </div>

// </div>);
const ProfilePictures = (props: Props) => {
const backgroundColor = `bg-profile-${props.backgroundColor}`;
const className = twMerge(
backgroundColor,
"object-cover object-center flex overflow-hidden justify-center items-center rounded-full w-full h-full"
);

return(<div>
<div className={`bg-profile-${props.backgroundColor} object-fill object-center flex overflow-hidden justify-center items-center rounded-full w-32 h-32`}>
{props.children}
</div>
</div>)
return (
<div className="w-full h-full">
<div className={className}>{props.children}</div>
</div>
);
};

export default ProfilePictures;
export default ProfilePictures;
21 changes: 21 additions & 0 deletions src/routes/InputFieldTestRoute.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Button from "@/components/Button";
import InputField from "@/components/InputField";

function InputFieldTestRoute() {
return (
<div className="flex flex-col justify-center items-center min-h-screen bg-neutrals-dark-100">
{/* Required Field */}
<InputField type="text" error={false} label="Input Text" required={true}/>
{/* Optional field */}
<InputField type="text" error={false} label="Input Text" required={false}/>
{/* Error field */}
<InputField type="text" error={true} label="Input Text" required={true}/>
{/* No label */}
<InputField type="text" error={false} required={false}/>


</div>
);
}

export default InputFieldTestRoute;
64 changes: 64 additions & 0 deletions src/routes/MemberHeaderTestRoute.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { ReactNode } from "react";
import MemberHeader from "@/components/MemberHeader";
import ProfilePictures from "@/components/ProfilePictures";
import profilePic from "@/assets/images/face2.jpg";
import profilePic1 from "@/assets/images/face1.jpeg";
import profilePic2 from "@/assets/images/face.jpeg";

import * as Icon from "@phosphor-icons/react";

function MemberHeaderTestRoute() {
return (
<div className="flex flex-col space-y-4 p-4">
<MemberHeader
backgroundColor="tulip"
username="User 1"
profilePicChildren={
<img
className=" w-32 h-32 object-cover rounded-full"
src={profilePic}
alt="Profile pic"
/>
}
/>

<MemberHeader
backgroundColor="gold"
username="User 2"
profilePicChildren={
<img
className=" h-32 w-32 object-cover rounded-full"
src={profilePic1}
alt="Profile pic"
/>
}
/>

<MemberHeader
backgroundColor="lime"
username="User 3"
profilePicChildren={
<img
className=" w-32 h-32 object-cover rounded-full"
src={profilePic2}
alt="Profile pic"
/>
}
/>

<MemberHeader
backgroundColor="jade"
username="User 4"
profilePicChildren={
<img
className=" h-32 w-32 object-cover rounded-full"
src={profilePic}
alt="Profile pic"
/>
}
/>
</div>
);
}

export default MemberHeaderTestRoute;
44 changes: 37 additions & 7 deletions src/routes/ProfilePictureTestRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,49 @@ import profilePic from "@/assets/images/face2.jpg";
import profilePic1 from "@/assets/images/face1.jpeg";
import profilePic2 from "@/assets/images/face.jpeg";

import * as Icon from '@phosphor-icons/react'
import * as Icon from "@phosphor-icons/react";

function ProfilePictureTest() {


return (
<div className="space-y-4 p-4">
<ProfilePictures backgroundColor="tulip"><img className="w-full h-full object-cover rounded-full" src={profilePic} alt="Profile pic" /></ProfilePictures>
<ProfilePictures backgroundColor="tulip"><img className="w-full h-full object-cover rounded-full" src={profilePic1} alt="Profile pic" /></ProfilePictures>
<ProfilePictures backgroundColor="tulip"><img className="w-full h-full object-cover rounded-full" src={profilePic2} alt="Profile pic" /></ProfilePictures>
<div className="w-12 h-12">
<ProfilePictures backgroundColor="tulip">
<img
className="w-full h-full object-cover rounded-full"
src={profilePic}
alt="Profile pic"
/>
</ProfilePictures>
</div>

<ProfilePictures backgroundColor="tulip"><Icon.PawPrint className="w-full h-full object-cover rounded-full" size={100} color={'white'}/></ProfilePictures>
<div className="w-20 h-20">
<ProfilePictures backgroundColor="tulip">
<img
className="w-full h-full object-cover rounded-full"
src={profilePic1}
alt="Profile pic"
/>
</ProfilePictures>
</div>
<div className="w-24 h-24">
<ProfilePictures backgroundColor="tulip">
<img
className="w-full h-full object-cover rounded-full"
src={profilePic2}
alt="Profile pic"
/>
</ProfilePictures>
</div>
<div className="w-12 h-12">
<ProfilePictures backgroundColor="tulip">
<Icon.PawPrint
className="w-full h-full object-cover rounded-full"
size={100}
color={"white"}
/>
</ProfilePictures>
</div>
</div>
);
}

Expand Down

0 comments on commit 5661b94

Please sign in to comment.