Skip to content

Commit

Permalink
added card for metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
theBstar committed Jul 31, 2024
1 parent 5a40c43 commit 46e9205
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/components/charts/Metric/Metric.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Meta, StoryObj } from "@storybook/react";
import Metric from "./Metric";

const meta: Meta<typeof Metric> = {
title: "Charts/Metric",
component: Metric,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
layout: "centered",
},
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ["autodocs"],
};

export default meta;

type Story = StoryObj<typeof Metric>;

export const Default: Story = {
args: {
title: "CPC",
value: 2.5,
valuePrefix: "$",
change: 0.5,
changeType: "up",
},
};
31 changes: 31 additions & 0 deletions src/components/charts/Metric/Metric.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ArrowDown, ArrowUp } from "@phosphor-icons/react";
import { Card, Flex, Typography } from "antd";


export type MetricProps = {
title: string;
value: number;
valuePrefix?: string;
change: number;
changeType?: "up" | "down";
}

export default function Metric({ title, value, change, valuePrefix, changeType }: MetricProps) {
return (
<Card>
<Flex gap={4} justify="center" align="center" vertical>
<Typography.Text type="secondary">{title}</Typography.Text>
<Typography.Text>
{valuePrefix && `${valuePrefix} `}
{value}
</Typography.Text>
<Flex align="center">
<Typography.Text type="success">
{change}
</Typography.Text>
{changeType === "up" ? <ArrowUp /> : <ArrowDown />}
</Flex>
</Flex>
</Card>
)
}
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ export { default as AppThemeProvider } from "./AppThemeProvider";

export { useThemeManager } from "./useThemeManager";

export { default as Piechart } from "../components/charts/Piechart";
export type { PiechartProps } from "../components/charts/Piechart";
export { default as Piechart } from "./charts/Piechart/Piechart";
export type { PiechartProps } from "./charts/Piechart/Piechart";

export { default as Metric } from "./charts/Metric/Metric";

// Import CSS files
import "../customStyles.css";
Expand Down

0 comments on commit 46e9205

Please sign in to comment.