Skip to content

Commit

Permalink
feat(ui): add alert component
Browse files Browse the repository at this point in the history
  • Loading branch information
fellipeutaka committed Feb 13, 2024
1 parent d46d8a5 commit 402a258
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"require": "./dist/alert-dialog.js",
"types": "./dist/alert-dialog.d.ts"
},
"./alert": {
"import": "./dist/alert.mjs",
"require": "./dist/alert.js",
"types": "./dist/alert.d.ts"
},
"./avatar": {
"import": "./dist/avatar.mjs",
"require": "./dist/avatar.js",
Expand Down Expand Up @@ -153,6 +158,7 @@
"build": "tsup",
"dev": "tsup --watch",
"lint": "eslint src --fix --max-warnings 0",
"format": "prettier --write src",
"clean": "rimraf .turbo node_modules dist"
},
"dependencies": {
Expand Down
70 changes: 70 additions & 0 deletions packages/ui/src/alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { forwardRef } from "react";

import { tv, type VariantProps } from "@fellipeutaka/styles";

export const AlertStyles = {
Root: tv({
base: [
"relative w-full rounded-lg border border-border p-4",
"[&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",
],
variants: {
variant: {
default: ["bg-background text-foreground"],
destructive: [
"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",
],
},
},
defaultVariants: {
variant: "default",
},
}),
Title: tv({
base: ["mb-1 font-medium leading-none tracking-tight"],
}),
Description: tv({
base: ["text-sm", "[&_p]:leading-relaxed"],
}),
};

export const AlertRoot = forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement> &
VariantProps<(typeof AlertStyles)["Root"]>
>(({ className, variant, ...props }, ref) => (
<div
ref={ref}
role="alert"
className={AlertStyles.Root({ variant, className })}
{...props}
/>
));
AlertRoot.displayName = "Alert";

export const AlertTitle = forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, children, ...props }, ref) => (
<h5 ref={ref} className={AlertStyles.Title({ className })} {...props}>
{children}
</h5>
));
AlertTitle.displayName = "AlertTitle";

export const AlertDescription = forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={AlertStyles.Description({ className })}
{...props}
/>
));
AlertDescription.displayName = "AlertDescription";

export const Alert = Object.assign(AlertRoot, {
Title: AlertTitle,
Description: AlertDescription,
});
8 changes: 4 additions & 4 deletions packages/ui/src/avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import * as React from "react";
import { forwardRef } from "react";

import { tv } from "@fellipeutaka/styles";
import * as AvatarPrimitive from "@radix-ui/react-avatar";
Expand All @@ -23,7 +23,7 @@ export type AvatarProps = React.ComponentPropsWithoutRef<
typeof AvatarPrimitive.Root
>;

const Root = React.forwardRef<
const Root = forwardRef<
React.ElementRef<typeof AvatarPrimitive.Root>,
AvatarProps
>(({ className, ...props }, ref) => (
Expand All @@ -39,7 +39,7 @@ export type AvatarImageProps = React.ComponentPropsWithoutRef<
typeof AvatarPrimitive.Image
>;

const Image = React.forwardRef<
const Image = forwardRef<
React.ElementRef<typeof AvatarPrimitive.Image>,
AvatarImageProps
>(({ className, ...props }, ref) => (
Expand All @@ -55,7 +55,7 @@ export type AvatarFallbackProps = React.ComponentPropsWithoutRef<
typeof AvatarPrimitive.Fallback
>;

const Fallback = React.forwardRef<
const Fallback = forwardRef<
React.ElementRef<typeof AvatarPrimitive.Fallback>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
>(({ className, ...props }, ref) => (
Expand Down

0 comments on commit 402a258

Please sign in to comment.