Skip to content

Commit

Permalink
327 Generic information panel (#354)
Browse files Browse the repository at this point in the history
* Initial commit

* Tidying and change of icon

Removal of comments.

Changed the SVG icon to a React component. 

Changed functions in storybook testing.
  • Loading branch information
jeffplays2005 authored May 15, 2024
1 parent baf69f9 commit fa6400c
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import type { Meta, StoryObj } from "@storybook/react"

import ProfileInformationPanel from "./ProfileInformationPanel"

const meta: Meta<typeof ProfileInformationPanel> = {
component: ProfileInformationPanel
}
export default meta
type Story = StoryObj<typeof ProfileInformationPanel>

interface TestElements {
subtitle: string
description: string
}

const ChildMapper = (children: Array<TestElements>) => {
return children.map((child) => (
<>
<div>
<p className="pb-1 text-base font-normal leading-tight text-stone-300">
{child.subtitle}
</p>
<p className="text-black/opacity-20 pb-1 text-base font-normal leading-tight">
{child.description}
</p>
</div>
</>
))
}

const firstStoryElements: Array<TestElements> = [
{
subtitle: "Dietary requirements",
description: "Allergic to nuts"
},
{
subtitle: "Skiier/Snowboarder",
description: "Both"
}
]

const secondStoryElements = [
{
subtitle: "Name",
description: "John Doe"
},
{
subtitle: "Gender",
description: "Male"
},
{
subtitle: "Student ID",
description: "910867209"
},
{
subtitle: "Date of birth",
description: "23/06/2003"
},
{
subtitle: "Email",
description: "[email protected]"
},
{
subtitle: "Phone number",
description: "021 123 1234"
},
{
subtitle: "Emergency contact info",
description: "Jason, Father, 021 432, 4321"
}
]

const thirdStoryElements = [
{
subtitle: "Membership type",
description: "UoA Student"
},
{
subtitle: "Valid till",
description: "9/12/24"
}
]

export const littleElementsWithEdit = () => {
return (
<>
<ProfileInformationPanel
title="Additional details"
onEdit={() => {
alert("Additional details button clicked")
}}
>
{ChildMapper(firstStoryElements)}
</ProfileInformationPanel>
</>
)
}

export const ManyElementsWithEdit: Story = {
args: {
title: "Personal Details",
onEdit: () => {
alert("Personal details edit button")
},
children: ChildMapper(secondStoryElements)
}
}

export const elementsWithoutEdit = () => {
return (
<ProfileInformationPanel title="Membership">
{ChildMapper(thirdStoryElements)}
</ProfileInformationPanel>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ReactNode } from "react"
import EditIcon from "assets/icons/edit.svg?react"
interface IProfileInformationPanel {
title: string // The title field
children?: ReactNode
onEdit?: () => void // The edit button
}

const ProfileInformationPanel = ({
title,
children,
onEdit
}: IProfileInformationPanel) => {
return (
<div className="absolute w-[90%] flex-row rounded border border-stone-300 bg-white p-5">
<div className="flex flex-nowrap justify-between p-1">
<h3 className="text-dark-blue-100 text-nowrap">{title}</h3>
{onEdit && (
<div
className="inline-flex h-[30px] w-[30px] cursor-pointer items-center justify-center py-[5px] pl-[5px]"
onClick={onEdit}
>
<EditIcon className="absolute h-5 w-[21.69px]" />
</div>
)}
</div>

<div className="flex flex-row flex-wrap items-stretch justify-start gap-x-[50px] gap-y-[10px] p-1 pt-3">
{children}
</div>
</div>
)
}

export default ProfileInformationPanel

0 comments on commit fa6400c

Please sign in to comment.