Skip to content

Commit

Permalink
feat: pagination component
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadshaheer committed Oct 13, 2024
1 parent 7e03bd8 commit 5ac84b8
Show file tree
Hide file tree
Showing 14 changed files with 487 additions and 7 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 ./stories/*.stories.tsx --max-warnings 0"
},
"dependencies": {
"@signozhq/pagination": "workspace:*",
"@signozhq/button": "workspace:*",
"@signozhq/input": "workspace:*",
"@signozhq/tailwind-config": "workspace:*",
Expand Down
61 changes: 61 additions & 0 deletions apps/docs/stories/pagination.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { Meta, StoryObj } from "@storybook/react";
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationPrevious,
PaginationLink,
PaginationEllipsis,
PaginationNext,
} from "@signozhq/pagination";

const PaginationComponent = () => (
<Pagination>
<PaginationContent>
<PaginationItem>
<PaginationPrevious href="#" onClick={(e) => e.preventDefault()} />
</PaginationItem>
<PaginationItem>
<PaginationLink href="#" onClick={(e) => e.preventDefault()}>
1
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="#" onClick={(e) => e.preventDefault()} isActive>
2
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="#" onClick={(e) => e.preventDefault()}>
3
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationEllipsis />
</PaginationItem>
<PaginationItem>
<PaginationNext href="#" onClick={(e) => e.preventDefault()} />
</PaginationItem>
</PaginationContent>
</Pagination>
);

const meta: Meta<typeof PaginationComponent> = {
title: "Components/Pagination",
component: PaginationComponent,
argTypes: {},
parameters: {
backgrounds: {
default: "dark",
},
},
};

export default meta;

type Story = StoryObj<typeof PaginationComponent>;

export const Default: Story = {
render: () => <PaginationComponent />,
args: {},
};
4 changes: 4 additions & 0 deletions packages/pagination/.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/pagination/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"
}
}
58 changes: 58 additions & 0 deletions packages/pagination/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@signozhq/pagination",
"version": "0.0.0",
"sideEffects": false,
"license": "MIT",
"type": "module",
"exports": {
".": {
"types": "./dist/pagination.d.ts",
"import": "./dist/pagination.js"
}
},
"main": "./dist/pagination.js",
"module": "./dist/pagination.js",
"types": "./dist/pagination.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": {
"@signozhq/button": "workspace:*",
"@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": "A new package"
}
6 changes: 6 additions & 0 deletions packages/pagination/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
66 changes: 66 additions & 0 deletions packages/pagination/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;
--card: 0 0% 100%;
--card-foreground: 240 10% 3.9%;
--popover: 0 0% 100%;
--popover-foreground: 240 10% 3.9%;
--primary: 240 5.9% 10%;
--primary-foreground: 0 0% 98%;
--secondary: 240 4.8% 95.9%;
--secondary-foreground: 240 5.9% 10%;
--muted: 240 4.8% 95.9%;
--muted-foreground: 240 3.8% 46.1%;
--accent: 240 4.8% 95.9%;
--accent-foreground: 240 5.9% 10%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 0 0% 98%;
--border: 240 5.9% 90%;
--input: 240 5.9% 90%;
--ring: 240 10% 3.9%;
--chart-1: 12 76% 61%;
--chart-2: 173 58% 39%;
--chart-3: 197 37% 24%;
--chart-4: 43 74% 66%;
--chart-5: 27 87% 67%;
--radius: 0.5rem
}
.dark {
--background: 240 10% 3.9%;
--foreground: 0 0% 98%;
--card: 240 10% 3.9%;
--card-foreground: 0 0% 98%;
--popover: 240 10% 3.9%;
--popover-foreground: 0 0% 98%;
--primary: 0 0% 98%;
--primary-foreground: 240 5.9% 10%;
--secondary: 240 3.7% 15.9%;
--secondary-foreground: 0 0% 98%;
--muted: 240 3.7% 15.9%;
--muted-foreground: 240 5% 64.9%;
--accent: 240 3.7% 15.9%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 0 0% 98%;
--border: 240 3.7% 15.9%;
--input: 240 3.7% 15.9%;
--ring: 240 4.9% 83.9%;
--chart-1: 220 70% 50%;
--chart-2: 160 60% 45%;
--chart-3: 30 80% 55%;
--chart-4: 280 65% 60%;
--chart-5: 340 75% 55%
}
}
@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
}
6 changes: 6 additions & 0 deletions packages/pagination/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))
}
122 changes: 122 additions & 0 deletions packages/pagination/src/pagination.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import "./index.css";
import * as React from "react";
import {
ChevronLeftIcon,
ChevronRightIcon,
DividerHorizontalIcon,
} from "@radix-ui/react-icons";

import { cn } from "@/lib/utils";
import { ButtonProps, buttonVariants } from "@signozhq/button";

const Pagination = ({ className, ...props }: React.ComponentProps<"nav">) => (
<nav
role="navigation"
aria-label="pagination"
className={cn("mx-auto flex w-full justify-center", className)}
{...props}
/>
);
Pagination.displayName = "Pagination";

const PaginationContent = React.forwardRef<
HTMLUListElement,
React.ComponentProps<"ul">
>(({ className, ...props }, ref) => (
<ul
ref={ref}
className={cn("flex flex-row items-center gap-1", className)}
{...props}
/>
));
PaginationContent.displayName = "PaginationContent";

const PaginationItem = React.forwardRef<
HTMLLIElement,
React.ComponentProps<"li">
>(({ className, ...props }, ref) => (
<li ref={ref} className={cn("", className)} {...props} />
));
PaginationItem.displayName = "PaginationItem";

type PaginationLinkProps = {
isActive?: boolean;
} & Pick<ButtonProps, "size"> &
React.ComponentProps<"a">;

const PaginationLink = ({
className,
isActive,
size = "icon",
...props
}: PaginationLinkProps) => (
<a
aria-current={isActive ? "page" : undefined}
className={cn(
buttonVariants({
variant: isActive ? "default" : "ghost",
size,
theme: "dark",
}),
className
)}
{...props}
/>
);
PaginationLink.displayName = "PaginationLink";

const PaginationPrevious = ({
className,
...props
}: React.ComponentProps<typeof PaginationLink>) => (
<PaginationLink
aria-label="Go to previous page"
size="default"
className={cn("gap-1 pl-2.5", className)}
{...props}
>
<ChevronLeftIcon className="h-4 w-4" />
</PaginationLink>
);
PaginationPrevious.displayName = "PaginationPrevious";

const PaginationNext = ({
className,
...props
}: React.ComponentProps<typeof PaginationLink>) => (
<PaginationLink
aria-label="Go to next page"
size="default"
className={cn("gap-1 pr-2.5", className)}
{...props}
>
<ChevronRightIcon className="h-4 w-4" />
</PaginationLink>
);
PaginationNext.displayName = "PaginationNext";

const PaginationEllipsis = ({
className,
...props
}: React.ComponentProps<"span">) => (
<span
aria-hidden
className={cn("flex h-9 w-9 items-center justify-center", className)}
{...props}
>
<DividerHorizontalIcon className="h-4 w-4 text-vanilla-100" />

<span className="sr-only">More pages</span>
</span>
);
PaginationEllipsis.displayName = "PaginationEllipsis";

export {
Pagination,
PaginationContent,
PaginationLink,
PaginationItem,
PaginationPrevious,
PaginationNext,
PaginationEllipsis,
};
7 changes: 7 additions & 0 deletions packages/pagination/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/pagination/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/pagination/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/*"]
}
}
}
Loading

0 comments on commit 5ac84b8

Please sign in to comment.