Skip to content

Commit

Permalink
adding application badge
Browse files Browse the repository at this point in the history
  • Loading branch information
gnomadic committed Nov 13, 2024
1 parent 2a36a60 commit c884800
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/components/Badges/ApplicationBadge/ApplicationBadge.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Meta, Canvas, Story, Description, Controls, Stories } from "@storybook/blocks";

import { ApplicationBadge } from "./ApplicationBadge";
import * as ApplicationBadgeStories from "./ApplicationBadge.stories";

<Meta
title="Components/ApplicationBadge"
component={ApplicationBadge}
of={ApplicationBadgeStories}
/>

# ApplicationBadge

The `ApplicationBadge` component is a UI element that indicates either the status of an Application. It supports various states, each represented by a distinct badge.

# Example

<Story of={ApplicationBadgeStories.PendingBadge} />

# Controls

<Controls of={ApplicationBadgeStories.PendingBadge} />

# Other variations

<Stories />
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Meta, StoryObj } from "@storybook/react";

import { ApplicationBadge, ApplicationStatus } from "./ApplicationBadge";

const meta: Meta<typeof ApplicationBadge> = {
title: "Components/ApplicationBadge",
component: ApplicationBadge,
};

export default meta;
type Story = StoryObj<typeof ApplicationBadge>;

export const PendingBadge: Story = {
argTypes: {
status: {
control: "select",
options: Object.values(ApplicationStatus),
description: "The Application Status.",
},
// badge: {
// control: "select",
// options: Object.values(ApplicationStatus),
// description: "The application status",
// },
// Exclude the type from the controls
// status: {
// table: {
// disable: true,
// },
// },
},
args: {
status: ApplicationStatus.Pending,
},
};

export const ApprovedBadge: Story = {
args: {
status: ApplicationStatus.Approved,
},
parameters: {
docs: {
storyDescription: "Displays the `Approved` Application status badge.",
},
},
};

export const RejectedBadge: Story = {
args: {
status: ApplicationStatus.Rejected,
},
parameters: {
docs: {
storyDescription: "Displays the `Rejected` Application status badge.",
},
},
};
49 changes: 49 additions & 0 deletions src/components/Badges/ApplicationBadge/ApplicationBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as React from "react";

import { tv } from "tailwind-variants";
import { match } from "ts-pattern";

import { Badge } from "@/primitives/Badge/Badge";

export enum ApplicationStatus {
Pending = "pending",
Approved = "approved",
Rejected = "rejected",
}

export const ApplicationBadgeVariants = tv({
variants: {
variant: {
pending: "border-transparent bg-yellow-100 text-black",
approved: "border-transparent bg-green-100 text-black",
rejected: "border-transparent bg-red-100 text-black",
},
},
});

interface ApplicationBadgeProps {
status: ApplicationStatus;
}

export const ApplicationBadge: React.FC<ApplicationBadgeProps> = (props) => {
const { variant, text } = match(props)
.with({ status: ApplicationStatus.Pending }, () => ({
variant: ApplicationBadgeVariants({ variant: "pending" }),
text: "Pending",
}))
.with({ status: ApplicationStatus.Approved }, () => ({
variant: ApplicationBadgeVariants({ variant: "approved" }),
text: "Approved",
}))
.with({ status: ApplicationStatus.Rejected }, () => ({
variant: ApplicationBadgeVariants({ variant: "rejected" }),
text: "Rejected",
}))

.otherwise(() => ({
variant: "border border-red-400 bg-white text-red-400",
text: "Error: Invalid Application Status",
}));

return <Badge className={variant}>{text}</Badge>;
};

0 comments on commit c884800

Please sign in to comment.