Skip to content

Commit

Permalink
feat: add UserCard component to storybook design system (#1295)
Browse files Browse the repository at this point in the history
  • Loading branch information
OgDev-01 committed Jun 23, 2023
1 parent 8324707 commit 6867011
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
58 changes: 58 additions & 0 deletions components/atoms/UserCard/user-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { getAvatarByUsername } from "lib/utils/github";
import Image from "next/image";
import React from "react";

type MetaObj = {
name: "Followers" | "Following" | "Highlights";
count: number;
};
interface UserCardProps {
username: string;
meta: MetaObj[];
name: string;
}
const UserCard = ({ username, name, meta }: UserCardProps) => {
const avatarUrl = getAvatarByUsername(username);

return (
<div className="mt-10 bg-white border w-max rounded-2xl border-zinc-200">
<div className="flex flex-col items-center gap-6 px-6 -translate-y-12 ">
<div className="flex flex-col items-center gap-2">
<Image
className="border border-white rounded-full"
width={110}
height={110}
src={avatarUrl}
alt={`${username}'s avatar image`}
/>
<div>
<h3 className="text-lg text-center">{name}</h3>
<p className="text-center text-light-slate-9">{`@${username}`}</p>
</div>
</div>
<div className="flex items-center gap-5 text-lg text-center">
{meta.map(({ name, count }, i) => (
<div key={i.toLocaleString()}>
<p className="text-center text-light-slate-9">{name}</p>
{count > 0 ? count : "-"}
</div>
))}
{/* <div>
<p className="text-center text-light-slate-9">Followers</p>
{followersCount > 0 ? followersCount : "-"}
</div>
<div>
<p className="text-center text-light-slate-9">Following</p>
{followingCount > 0 ? followingCount : "-"}
</div>
<div>
<p className="text-center text-light-slate-9">Highlights</p>
{highlightsCount > 0 ? highlightsCount : "-"}
</div> */}
</div>
</div>
</div>
);
};

export default UserCard;
34 changes: 34 additions & 0 deletions stories/atoms/user-card.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import UserCard from "components/atoms/UserCard/user-card";
import { ComponentMeta, ComponentStory } from "@storybook/react";

const storyConfig = {
title: "Design System/Atoms/UserCard",
} as ComponentMeta<typeof UserCard>;

export default storyConfig;

const UserCardTemplate: ComponentStory<typeof UserCard> = (args) => <UserCard {...args} />;

export const UserCardStory = UserCardTemplate.bind({});

export const NoActivities = UserCardTemplate.bind({});

UserCardStory.args = {
username: "foxyblocks",
name: "Chris Schlensker",
meta: [
{ name: "Followers", count: 3 },
{ name: "Following", count: 103 },
{ name: "Highlights", count: 55 },
],
};

NoActivities.args = {
username: "foxyblocks",
name: "Chris Schlensker",
meta: [
{ name: "Followers", count: 0 },
{ name: "Following", count: 0 },
{ name: "Highlights", count: 0 },
],
};

0 comments on commit 6867011

Please sign in to comment.