Skip to content

Commit

Permalink
iterating
Browse files Browse the repository at this point in the history
  • Loading branch information
gnomadic committed Oct 24, 2024
1 parent a5c7063 commit 8989c76
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 76 deletions.
25 changes: 0 additions & 25 deletions src/primitives/Badge/StatusBadge.stories.tsx

This file was deleted.

48 changes: 0 additions & 48 deletions src/primitives/Badge/StatusBadge.tsx

This file was deleted.

23 changes: 23 additions & 0 deletions src/primitives/StatusBadge/StatusBadge.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Meta, Title, Primary, Stories, Controls, Story } from "@storybook/blocks";
import * as StatusBadgeStories from "./StatusBadge.stories";
import { StatusBadge } from "./StatusBadge";

# StatusBadge

<Meta of={StatusBadgeStories} />

The StatusBadge component renders a Status in a Badge.

# Example

## Default

<Story of={StatusBadgeStories.Default} />

# Controls

<Controls />

# Other variations

<Stories />
42 changes: 42 additions & 0 deletions src/primitives/StatusBadge/StatusBadge.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { Meta, StoryObj } from "@storybook/react";
import { expect, within } from "@storybook/test";

import { Status, StatusBadge } from "./StatusBadge";

const meta: Meta<typeof StatusBadge> = {
title: "Primitives/StatusBadge",
args: {
status: Status.INPROGRESS,
},
argTypes: {
status: {
control: "select",
options: Object.values(Status),
},
},

component: StatusBadge,
};

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

export const Default: Story = {};

export const Ended: Story = {
args: {
status: Status.ENDED,
},
};

export const Empty: Story = {
args: {
status: Status.HIDDEN,
},
};

// export const AsString: Story = {
// args: {
// status: "Active"
// },
// };
62 changes: 62 additions & 0 deletions src/primitives/StatusBadge/StatusBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
import { match, P } from "ts-pattern";

export enum Status {
INPROGRESS = "Active",
ENDED = "Ended",
HIDDEN = "Hidden",
}

interface StatusBadgeProps {
status: `${Status}`;
}

const statusMap = {
[Status.INPROGRESS]: {
variant: "InProgress" as const,
display: "In Progress",
},
[Status.ENDED]: {
variant: "Ended" as const,
display: "Ended",
},
[Status.HIDDEN]: {
variant: "Hidden" as const,
display: "",
},
};

const badgeVariants = cva(
"ui-inline-flex ui-items-center ui-rounded-full ui-border ui-font-sans ui-text-xs ui-font-semibold ",
{
variants: {
variant: {
InProgress: "ui-bg-blue-100 ui-px-2.5 ui-py-0.5",
Ended: "ui-bg-orange-100 ui-px-2.5 ui-py-0.5",
Hidden: "ui-hidden",
},
},
},
);

export const StatusBadge = ({ status }: StatusBadgeProps) => {
const key: Status = match({ status })
.with({ status: "Active" }, () => Status.INPROGRESS)
.with({ status: "In Progress" }, () => Status.INPROGRESS)

Check failure on line 47 in src/primitives/StatusBadge/StatusBadge.tsx

View workflow job for this annotation

GitHub Actions / test

Type '"In Progress"' is not assignable to type 'KnownPattern<"Active" | "Ended" | "Hidden"> | undefined'.
.with({ status: "Ended" }, () => Status.ENDED)
.otherwise(() => Status.HIDDEN);

const { variant, display } = statusMap[key];

return <Badge variant={variant}>{display} </Badge>;
};

interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}

function Badge({ className, variant, ...props }: BadgeProps) {
return <div className={cn(badgeVariants({ variant }), className)} {...props} />;
}
12 changes: 9 additions & 3 deletions src/tokens/colors.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { Colors } from "./types";

export const colors: Colors = {
grey: {
"ui-grey": {
"50": "#f7f7f7",
"400": "#555555",
"500": "#000000",
},
white: "#ffffff",
black: "#000000",
"ui-blue": {
"100": "#D3EDFE",
},
"ui-orange": {
"100": "#FFD9CD",
},
"ui-white": "#ffffff",
"ui-black": "#000000",
};

0 comments on commit 8989c76

Please sign in to comment.