Skip to content

Commit

Permalink
feat: shadcn based alert component
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadshaheer committed Oct 3, 2024
1 parent 506258e commit bc428c2
Show file tree
Hide file tree
Showing 14 changed files with 359 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"lint": "eslint . --ext ./stories/*.stories.tsx --fix && prettier --write ."
},
"dependencies": {
"@signozhq/alert": "workspace:*",
"@signozhq/button": "workspace:*",
"@signozhq/input": "workspace:*",
"@signozhq/tailwind-config": "workspace:*",
Expand Down
64 changes: 64 additions & 0 deletions apps/docs/stories/alert.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Meta, StoryObj } from "@storybook/react";
import { Alert, AlertTitle, AlertDescription } from "@signozhq/alert";

const meta: Meta<typeof Alert> = {
title: "Components/Alert",
component: Alert,
tags: ["autodocs"],
argTypes: {
variant: {
control: "select",
options: ["default", "destructive"],
},
title: {
control: "text",
},
},
};

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

const Template: Story = {
render: ({ variant, title, children }) => (
<Alert variant={variant}>
{title && <AlertTitle>{title}</AlertTitle>}
<AlertDescription>{children}</AlertDescription>
</Alert>
),
};

export const Default: Story = {
...Template,
args: {
variant: "default",
title: "Heads up!",
children:
"You can add components and dependencies to your app using the cli.",
},
};

export const Destructive: Story = {
...Template,
args: {
variant: "destructive",
title: "Error",
children: "Your session has expired. Please log in again.",
},
};

export const TitleOnly: Story = {
...Template,
args: {
title: "Note",
children: null,
},
};

export const DescriptionOnly: Story = {
...Template,
args: {
title: "",
children: "This is a description-only alert.",
},
};
4 changes: 4 additions & 0 deletions packages/alert/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: ["@repo/eslint-config/react.js"],
};
19 changes: 19 additions & 0 deletions packages/alert/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"style": "new-york",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "@signozhq/tailwind-config/tailwind.config.js",
"css": "src/index.css",
"baseColor": "zinc",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "src",
"lib": "@/lib",
"hooks": "@/hooks"
}
}
57 changes: 57 additions & 0 deletions packages/alert/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@signozhq/alert",
"version": "0.0.0",
"sideEffects": false,
"license": "MIT",
"type": "module",
"exports": {
".": {
"types": "./dist/alert.d.ts",
"import": "./dist/alert.js"
}
},
"main": "./dist/alert.js",
"module": "./dist/alert.js",
"types": "./dist/alert.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "vite build",
"dev": "vite build --watch",
"lint": "eslint . --max-warnings 0",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
},
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@signozhq/tailwind-config": "workspace:*",
"@types/node": "^22.5.5",
"@types/react": "^18.2.61",
"@types/react-dom": "^18.2.19",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.20",
"eslint": "^9.11.0",
"postcss": "^8.4.47",
"react-dom": "^18.2.0",
"tailwindcss": "^3.4.12",
"typescript": "^5.3.3",
"vite": "^5.0.0",
"vite-plugin-lib-inject-css": "^2.1.1",
"vite-plugin-dts": "^4.2.1"
},
"dependencies": {
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-slot": "^1.1.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.445.0",
"react": "^18.2.0",
"tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7"
},
"publishConfig": {
"access": "public"
},
"description": "Shadcn based alert component"
}
6 changes: 6 additions & 0 deletions packages/alert/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
60 changes: 60 additions & 0 deletions packages/alert/src/alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import "./index.css"
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "@/lib/utils"

const alertVariants = cva(
"relative w-full rounded-lg border px-4 py-3 text-sm [&>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",
},
}
)

const Alert = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
>(({ className, variant, ...props }, ref) => (
<div
ref={ref}
role="alert"
className={cn(alertVariants({ variant }), className)}
{...props}
/>
))
Alert.displayName = "Alert"

const AlertTitle = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, ...props }, ref) => (
<h5
ref={ref}
className={cn("mb-1 font-medium leading-none tracking-tight", className)}
{...props}
/>
))
AlertTitle.displayName = "AlertTitle"

const AlertDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("text-sm [&_p]:leading-relaxed", className)}
{...props}
/>
))
AlertDescription.displayName = "AlertDescription"

export { Alert, AlertTitle, AlertDescription }
3 changes: 3 additions & 0 deletions packages/alert/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
6 changes: 6 additions & 0 deletions packages/alert/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
7 changes: 7 additions & 0 deletions packages/alert/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sharedConfig = require("@signozhq/tailwind-config/tailwind.config.js");

/** @type {import('tailwindcss').Config} */
module.exports = {
...sharedConfig,
content: [...sharedConfig.content, "./src/**/*.{js,ts,jsx,tsx}"],
};
10 changes: 10 additions & 0 deletions packages/alert/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
},
"forceConsistentCasingInFileNames": true,
"strict": true
}
}
12 changes: 12 additions & 0 deletions packages/alert/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@repo/typescript-config/react-library.json",
"include": ["src"],
"exclude": ["dist", "build", "node_modules"],
"compilerOptions": {
"outDir": "dist",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}
31 changes: 31 additions & 0 deletions packages/alert/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import path from "path";
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";
import react from "@vitejs/plugin-react";
import { resolve } from "path";
import { libInjectCss } from "vite-plugin-lib-inject-css";

export default defineConfig({
build: {
lib: {
entry: resolve(__dirname, "src/alert.tsx"),
name: "Button",
fileName: "alert",
},
rollupOptions: {
external: ["react"],
output: {
globals: {
react: "React",
},
},
treeshake: true,
},
},
plugins: [dts(), react(), libInjectCss()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
});
79 changes: 79 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bc428c2

Please sign in to comment.