-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
151 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { Badge } from "./badge"; | ||
|
||
const meta = { | ||
title: "DATA DISPLAY/Badge", | ||
component: Badge, | ||
tags: ["autodocs"], | ||
argTypes: {}, | ||
} satisfies Meta<typeof Badge>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Primary: Story = { | ||
args: { | ||
children: "Low", | ||
size: "md", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useMemo } from "react"; | ||
import { twMerge } from "tailwind-merge"; | ||
import { useComponentStyle } from "../../customization/styles/theme.context"; | ||
import { IBadge } from "./badge.types"; | ||
|
||
export const Badge = (props: IBadge) => { | ||
const theme = useComponentStyle("Badge"); | ||
const { | ||
children, | ||
style, | ||
className = "", | ||
variant = "solid", | ||
size = "md", | ||
color = "", | ||
...restProps | ||
} = props; | ||
|
||
const classes = useMemo(() => { | ||
return twMerge( | ||
theme.base({ | ||
variant, | ||
size, | ||
}), | ||
className | ||
); | ||
}, [className, theme, variant, size]); | ||
|
||
return ( | ||
<div | ||
className={classes} | ||
style={{ | ||
...(variant === "solid" && { | ||
backgroundColor: color, | ||
borderColor: color, | ||
}), | ||
...(variant === "outline" && { | ||
borderColor: color, | ||
color: color, | ||
}), | ||
...(variant === "subtle" && { | ||
backgroundColor: `${color}15`, | ||
color: color, | ||
}), | ||
...style, | ||
}} | ||
{...restProps} | ||
> | ||
<span>{children}</span> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { DetailedHTMLProps } from "react"; | ||
import { HTMLAttributes } from "react"; | ||
|
||
export interface IBadge | ||
extends DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement> { | ||
children?: React.ReactNode; | ||
variant?: "outline" | "solid" | "subtle"; | ||
size?: "sm" | "md" | "lg"; | ||
color?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { cva } from "class-variance-authority"; | ||
|
||
const base = cva( | ||
[ | ||
"zn-rounded-sm", | ||
"zn-w-fit", | ||
"zn-border", | ||
"zn-border-primary-500", | ||
"zn-font-bold", | ||
"zn-uppercase", | ||
], | ||
{ | ||
variants: { | ||
variant: { | ||
solid: ["zn-bg-primary-500", "zn-text-white"], | ||
outline: ["zn-bg-transparent", "zn-text-primary-500"], | ||
subtle: [ | ||
"zn-bg-primary-100", | ||
"zn-border-transparent", | ||
"zn-text-primary-500", | ||
|
||
"dark:zn-bg-primary-800", | ||
"dark:zn-text-primary-300", | ||
], | ||
}, | ||
size: { | ||
sm: ["zn-px-1.5", "zn-py-0.5", "zn-text-xs"], | ||
md: ["zn-px-2", "zn-py-0.5", "zn-text-sm"], | ||
lg: ["zn-px-3", "zn-py-1", "zn-text-base"], | ||
}, | ||
}, | ||
} | ||
); | ||
|
||
const badgeStyles = { | ||
base, | ||
}; | ||
|
||
export { badgeStyles }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters