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

Create ManageServerCard component #178

Merged
merged 4 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 28 additions & 0 deletions packages/ui/src/components/ManageServerCard.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Meta, StoryFn } from "@storybook/react";
import { mockServer } from "~ui/test/props";
import { ManageServerCard, ManageServerCardProps } from "./ManageServerCard";
export default {
component: ManageServerCard,
} as Meta;

//👇 We create a “template” of how args map to rendering
const Template: StoryFn<typeof ManageServerCard> = (args: ManageServerCardProps) => (
<ManageServerCard {...args} />
);

//👇 Each story then reuses that template
export const Primary = Template.bind({});
Primary.args = {
server: mockServer(),
role: "Test Role",
};

export const WithImage = Template.bind({});
WithImage.args = {
server: mockServer({
name: "AnswerOverflow",
id: "952724385238761475",
icon: "4e610bdea5aacf259013ed8cada0bc1d",
}),
role: "Test Role",
};
58 changes: 58 additions & 0 deletions packages/ui/src/components/ManageServerCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { ServerPublic } from "@answeroverflow/api";
import Link from "next/link";
import { Button } from "./primitives/Button";
import { ServerIcon } from "./ServerIcon";
import Image from "next/image";

export type ManageServerCardProps = {
server: ServerPublic;
role: string;
};

export function ManageServerCard({ server, role }: ManageServerCardProps) {
const ServerNameAndRole = () => (
<div className="flex flex-col gap-1">
<span className="text-base font-bold text-black dark:text-neutral-300">{server.name}</span>
<span className="text-sm text-gray-600 dark:text-neutral-400">{role}</span>
</div>
);

const ServerIconWithBlurredBackground = () => {
return (
<div className="relative mx-auto aspect-video rounded-lg">
{server.icon && (
<Image
src={`https://cdn.discordapp.com/icons/${server.id}/${server.icon}.png`}
alt={server.name}
fill
className="h-full w-full overflow-hidden rounded-lg object-cover opacity-25"
/>
)}
<div className="relative z-10 h-full w-full rounded-lg bg-black/5 shadow-md backdrop-blur-md " />
<div className="absolute inset-0 z-20 flex items-center justify-center">
<ServerIcon server={server} size={"lg"} />
</div>
</div>
);
};

return (
<div className="grid max-w-xs grid-cols-2 grid-rows-3 gap-3 rounded-lg">
<div className="col-span-2 col-start-1 row-span-2 row-start-1">
<ServerIconWithBlurredBackground />
</div>
<div className="col-span-2 col-start-1 row-span-1 row-start-3">
<ServerNameAndRole />
</div>
<div className="col-span-1 col-start-2 row-span-1 row-start-3 flex">
<div className="ml-auto">
<Link href={`https://discord.gg/`} target={"Blank"} referrerPolicy="no-referrer">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will open an issue for this - we shouldn't have buttons inside links (needs a component change for button)

<Button type="solid" color="black">
Manage
</Button>
</Link>
</div>
</div>
</div>
);
}
1 change: 1 addition & 0 deletions packages/ui/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from "./ServerInviteDriver";
export * from "./Pricing";
export * from "./AOHead";
export * from "./analytics/Chart";
export * from "./ManageServerCard";