Skip to content

Commit

Permalink
SIKKA-5589[completed] + updated package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
zaaakher committed Nov 7, 2023
1 parent 216a9d8 commit d9043d7
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 7 deletions.
120 changes: 120 additions & 0 deletions components/elements/Pagination.tsx
@@ -0,0 +1,120 @@
import React from "react";
import {
Pagination as PaginationPrimitive,
IPaginationProps,
} from "react-headless-pagination";
import { cn } from "../util";
import { Button } from "./Button";
import { DirectionType } from "../types/commonTypes";

type PaginationProps = {
direction?: DirectionType;
};

export const Pagination: React.FC<PaginationProps> = (props) => {
const [page, setPage] = React.useState<number>(0);
const handlePageChange = (page: number) => {
setPage(page);
};
let totalPages = 123;
return (
<PaginationPrimitive
totalPages={10}
edgePageCount={2}
middlePagesSiblingCount={1}
// truncableClassName={"w-10 px-0.5"}

currentPage={page}
setCurrentPage={handlePageChange}
className="hawa-flex hawa-items-center hawa-w-full hawa-h-10 hawa-text-sm hawa-select-none"
truncableText="..."
truncableClassName="hawa-w-10 hawa-px-0.5 hawa-text-center"
>
<PaginationPrimitive.PrevButton
as={
<Button
aria-label="Previous Table Page"
variant="outline"
size="smallIcon"
className={cn(
"hawa-bg-primary/80",
props.direction === "ltr" && "hawa-rotate-180"
)}
>
<svg
aria-label="Chevron Right Icon"
stroke="currentColor"
fill="currentColor"
strokeWidth="0"
viewBox="0 0 16 16"
height="1em"
width="1em"
>
<path
fillRule="evenodd"
d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"
></path>
</svg>
</Button>
}
className={cn(
"hawa-flex hawa-items-center hawa-mr-2 hawa-text-gray-500 hover:hawa-text-gray-600 dark:hover:hawa-text-gray-200",
{
"hawa-cursor-pointer": page !== 0,
"hawa-opacity-50": page === 0,
}
)}
>
Previous
</PaginationPrimitive.PrevButton>

<nav className="hawa-flex hawa-justify-center hawa-flex-grow">
<ul className="hawa-flex hawa-items-center hawa-gap-1">
<PaginationPrimitive.PageButton
activeClassName="hawa-bg-primary/80 hawa-text-primary-foreground hawa-font-extrabold"
inactiveClassName="hawa-text-gray-500"
className={
"hawa-flex hawa-bg-muted hawa-rounded hawa-items-center hawa-justify-center hover:hawa-text-primary-600 focus:hawa-font-bold focus:hawa-text-primary-600 focus:hawa-outline-none hawa-h-7 hawa-w-7 hawa-cursor-pointer"
}
/>
</ul>
</nav>

<PaginationPrimitive.NextButton
as={
<Button
aria-label="Next Table Page"
variant="outline"
size="smallIcon"
className={cn(props.direction === "rtl" && "hawa-rotate-180")}
>
<svg
aria-label="Chevron Right Icon"
fill="currentColor"
stroke="currentColor"
width="1em"
height="1em"
strokeWidth="0"
viewBox="0 0 16 16"
>
<path
fillRule="evenodd"
d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"
></path>
</svg>
</Button>
}
className={cn(
"hawa-flex hawa-items-center hawa-mr-2 hawa-text-gray-500 hover:hawa-text-gray-600 dark:hover:hawa-text-gray-200",
{
"hawa-cursor-pointer": page !== totalPages - 1,
"hawa-opacity-50": page === totalPages - 1,
}
)}
>
Next
{/* <FiArrowRight size={20} className="ml-3" /> */}
</PaginationPrimitive.NextButton>
</PaginationPrimitive>
);
};
1 change: 1 addition & 0 deletions components/elements/index.tsx
Expand Up @@ -57,3 +57,4 @@ export * from "./ProgressCircle";
export * from "./NavigationMenu";
export * from "./StopPropagationWrapper";
export * from "./FileUploader";
export * from "./Pagination";
29 changes: 28 additions & 1 deletion package.json
@@ -1,6 +1,32 @@
{
"name": "@sikka/hawa",
"version": "0.16.15",
"version": "0.17.0",
"description": "Modern UI Kit made with Tailwind",
"author": {
"name": "Sikka Software",
"email": "contact@sikka.io",
"url": "http://sikka.io"
},
"homepage": "https://hawa.style",
"license": "MIT",
"keywords": [
"ui",
"saas",
"kit",
"tailwind",
"hawa"
],
"repository": {
"type": "git",
"url": "git+https://github.com/sikka-software/hawa.git"
},
"bugs": {
"url": "https://github.com/sikka-software/hawa/issues",
"email": "hawa@sikka.io"
},
"publishConfig": {
"access": "public"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
Expand Down Expand Up @@ -61,6 +87,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-dropzone": "^14.2.3",
"react-headless-pagination": "^1.1.4",
"react-hook-form": "^7.48.1",
"react-select": "^5.7.7",
"tailwind-merge": "^2.0.0",
Expand Down
27 changes: 21 additions & 6 deletions stories/ElementsStories/Input.stories.tsx
Expand Up @@ -33,20 +33,35 @@ export const Default: Story = {
),
};
export const PreviewMode: Story = {
render: () => {
render: (args: any, globals: any) => {
const locale = globals.globals?.locale === "ar" ? "ar" : "en";
setLocale(locale);

const [preview, setPreview] = useState(false);
return (
<div className="hawa-flex hawa-flex-col hawa-gap-4 hawa-max-w-md">
<div
className="hawa-flex hawa-flex-col hawa-gap-4 hawa-max-w-md"
dir={locale === "ar" ? "rtl" : "ltr"}
>
<Button onClick={() => setPreview(!preview)}>
{preview ? "Disable" : "Enable"} Preview
{/* {preview ? "Disable" : "Enable"} Preview */}
{preview ? t("enable-preview") : t("disable-preview")}
</Button>
<Input label={"First Name"} preview={preview} placeholder={"Fulan"} />
<Input label={"Middle Name"} preview={preview} placeholder={"Fulani"} />
<Input
label={"Last Name"}
label={t("first-name")}
preview={preview}
placeholder={"Fulan"}
/>
<Input
label={t("last-name")}
preview={preview}
placeholder={"Al-Fulani"}
/>
<Input
label={t("email")}
preview={preview}
placeholder={"contact@sikka.io"}
/>
<Input label={"Username"} preview={preview} placeholder={"fulan"} />
</div>
);
Expand Down
39 changes: 39 additions & 0 deletions stories/ElementsStories/Pagination.stories.tsx
@@ -0,0 +1,39 @@
import type { Meta, StoryObj } from "@storybook/react";
import { Pagination } from "../../components/elements";
import { ArgsTable, Story, Title } from "@storybook/blocks";
import { setLocale, t } from "../translations/i18n";

const meta = {
title: "Elements/Pagination",
component: Pagination,
parameters: {
// layout: "centered",
docs: {
page: () => (
<>
<h1>{"<Pagination/>"}</h1>
<ArgsTable />
</>
),
},
},
tags: ["autodocs"],
} satisfies Meta<typeof Pagination>;

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

const Template = (args: any, globals: any) => {
const locale = globals.globals?.locale === "ar" ? "ar" : "en";
const direction = locale === "ar" ? "rtl" : "ltr";
setLocale(locale);

return (
<div className="hawa-w-full hawa-p-2" dir={direction}>
<Pagination direction={direction} />
</div>
);
};
export const Default: Story = {
render: Template.bind({}),
};
4 changes: 4 additions & 0 deletions stories/translations/ar.json
@@ -1,4 +1,8 @@
{
"enable-preview": "تمكين المعاينة",
"disable-preview": "تعطيل المعاينة",
"first-name": "الإسم الأول",
"last-name": "إسم العائلة",
"no-data": "لا توجد عناصر",
"actions": "الإجرائات",
"are-you-sure": "هل انت متأكد؟",
Expand Down
4 changes: 4 additions & 0 deletions stories/translations/en.json
@@ -1,4 +1,8 @@
{
"enable-preview": "Enable Preview",
"disable-preview": "Disable Preview",
"first-name": "First Name",
"last-name": "Last Name",
"no-data": "No Data",
"submit": "Submit",
"description": "Description",
Expand Down

0 comments on commit d9043d7

Please sign in to comment.