Skip to content

Commit 2f63149

Browse files
committed
chore: pagination-stories
1 parent bce8242 commit 2f63149

File tree

6 files changed

+205
-11
lines changed

6 files changed

+205
-11
lines changed

src/lib/pagination/compact.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,20 @@ interface CompactPaginationProps {
2929
currentPage: number;
3030
numPages: number;
3131
callback: (newPage: number) => void;
32+
/** Callback function called when end of pages has been reached */
3233
onCloseOnLastPage?: () => void;
3334
label?: ReactNode;
3435
className?: string;
3536
}
3637

37-
const CompactPagination: React.FC<CompactPaginationProps> = ({
38+
function CompactPagination({
3839
currentPage,
3940
numPages,
4041
callback,
4142
onCloseOnLastPage,
4243
label,
4344
className,
44-
}) => {
45+
}: Readonly<CompactPaginationProps>) {
4546
const [{ incrementPage, decrementPage, minPageReached, maxPageReached }] =
4647
usePagination(currentPage, numPages, callback, onCloseOnLastPage);
4748

@@ -51,7 +52,7 @@ const CompactPagination: React.FC<CompactPaginationProps> = ({
5152
{label}
5253
</small>
5354
<ArrowButton
54-
className="ml-4"
55+
className={clsx(label && "ml-4")}
5556
isDisabled={minPageReached}
5657
onPress={decrementPage}
5758
>
@@ -77,6 +78,6 @@ const CompactPagination: React.FC<CompactPaginationProps> = ({
7778
)}
7879
</div>
7980
);
80-
};
81+
}
8182

8283
export default CompactPagination;

src/lib/pagination/standard.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,20 @@ interface StandardPaginationProps {
3939
numPages: number;
4040
callback: (newPage: number) => void;
4141
className?: string;
42+
/** Disables the number buttons, allowing only use of arrows */
4243
disableNumbers?: boolean;
44+
/** Hides the number buttons */
4345
hideNumbers?: boolean;
4446
}
4547

46-
const StandardPagination: React.FC<StandardPaginationProps> = ({
48+
function StandardPagination({
4749
currentPage,
4850
numPages,
4951
callback,
5052
disableNumbers,
5153
hideNumbers,
5254
className,
53-
}) => {
55+
}: Readonly<StandardPaginationProps>) {
5456
const [
5557
{
5658
incrementPage,
@@ -107,6 +109,6 @@ const StandardPagination: React.FC<StandardPaginationProps> = ({
107109
</PageButton>
108110
</div>
109111
);
110-
};
112+
}
111113

112114
export default StandardPagination;

src/lib/pagination/tabs.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,24 @@ import {
1515
} from "react-aria-components";
1616

1717
interface TabsItem {
18+
/** Unique id for each tab panel */
1819
id: Key;
1920
text: string;
21+
/** Value associated with each tab. Passed as an arg to callback function. */
2022
value: any;
2123
Icon?: React.FC<React.SVGAttributes<SVGElement>>;
2224
icon?: React.ReactNode;
2325
disabled?: boolean;
26+
/** Content to display when this tab is selected. */
2427
content: ReactNode;
28+
/** Props for Tab
29+
* {@link https://react-spectrum.adobe.com/react-aria/Tabs.html#tab | TabProps}
30+
*/
31+
tabProps?: TabProps;
32+
/**
33+
* Can be used to provide separate styling for a TabPanel, apart from one passed in panelClassName parent props.
34+
* {@link https://react-spectrum.adobe.com/react-aria/Tabs.html#tabpanel | TabListProps}
35+
*/
2536
tabPanelProps?: TabPanelProps;
2637
}
2738

@@ -30,19 +41,24 @@ interface TabsProps extends Omit<AriaTabsProps, "orientation"> {
3041
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
3142
callback?: Function;
3243
className?: string;
44+
/** ClassName to provide a common style for all TabPanels */
3345
panelClassName?: string;
46+
/**
47+
* Can be used to override default style.
48+
* {@link https://react-spectrum.adobe.com/react-aria/Tabs.html#tablist | TabListProps}
49+
*/
3450
tabListProps?: TabListProps<TabProps>;
3551
}
3652

37-
const Tabs: React.FC<TabsProps> = ({
53+
function Tabs({
3854
items,
3955
className,
4056
tabListProps,
4157
panelClassName,
4258
callback,
4359
defaultSelectedKey,
4460
...props
45-
}) => {
61+
}: Readonly<TabsProps>) {
4662
const [selectedKey, setSelectedKey] = useState<Key | undefined>(
4763
defaultSelectedKey,
4864
);
@@ -114,7 +130,7 @@ const Tabs: React.FC<TabsProps> = ({
114130
className={cn(
115131
"box-border h-fit w-full",
116132
panelClassName,
117-
// custom style for a panel should override global style provided with panelClassName
133+
// custom style for a panel should override parent style provided with panelClassName
118134
item?.tabPanelProps?.className,
119135
)}
120136
{...item.tabPanelProps}
@@ -125,6 +141,6 @@ const Tabs: React.FC<TabsProps> = ({
125141
</Collection>
126142
</AriaTabs>
127143
);
128-
};
144+
}
129145

130146
export default Tabs;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
3+
import { IPreviewArgs } from "./utils";
4+
5+
import Pagination from "../lib/pagination/compact";
6+
import React, { useState } from "react";
7+
8+
const meta = {
9+
component: Pagination,
10+
title: "Pagination/Compact Pagination",
11+
tags: ["autodocs"],
12+
argTypes: {
13+
numPages: {
14+
control: "number",
15+
},
16+
currentPage: {
17+
control: "number",
18+
},
19+
className: {
20+
control: "text",
21+
},
22+
},
23+
} satisfies Meta<typeof Pagination>;
24+
25+
export default meta;
26+
27+
type Story = StoryObj<typeof meta> & IPreviewArgs;
28+
29+
export const CompactPagination: Story = {
30+
args: {
31+
themeUI: "light",
32+
backgroundUI: "light",
33+
numPages: 6,
34+
currentPage: 0,
35+
callback: () => {},
36+
className: "w-full",
37+
label: "Label:",
38+
},
39+
render: function Render(args) {
40+
const [currentPage, setCurrentPage] = useState(1);
41+
42+
return (
43+
<Pagination
44+
{...args}
45+
currentPage={currentPage}
46+
callback={setCurrentPage}
47+
/>
48+
);
49+
},
50+
};
51+
52+
export const CompactPaginationWithCloseCallback: Story = {
53+
args: {
54+
themeUI: "light",
55+
backgroundUI: "light",
56+
numPages: 6,
57+
currentPage: 0,
58+
callback: () => {},
59+
className: "w-full",
60+
label: "Shows close button in end.",
61+
},
62+
render: function Render(args) {
63+
const [currentPage, setCurrentPage] = useState(1);
64+
65+
return (
66+
<Pagination
67+
{...args}
68+
currentPage={currentPage}
69+
callback={setCurrentPage}
70+
onCloseOnLastPage={() => {}}
71+
/>
72+
);
73+
},
74+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
3+
import { IPreviewArgs } from "./utils";
4+
5+
import Pagination from "../lib/pagination/standard";
6+
import React, { useState } from "react";
7+
8+
const meta = {
9+
component: Pagination,
10+
title: "Pagination/Standard Pagination",
11+
tags: ["autodocs"],
12+
argTypes: {
13+
numPages: {
14+
control: "number",
15+
},
16+
currentPage: {
17+
control: "number",
18+
},
19+
className: {
20+
control: "text",
21+
},
22+
disableNumbers: {
23+
control: "boolean",
24+
},
25+
hideNumbers: {
26+
control: "boolean",
27+
},
28+
},
29+
} satisfies Meta<typeof Pagination>;
30+
31+
export default meta;
32+
33+
type Story = StoryObj<typeof meta> & IPreviewArgs;
34+
35+
export const StandardPagination: Story = {
36+
args: {
37+
themeUI: "light",
38+
backgroundUI: "light",
39+
numPages: 6,
40+
currentPage: 0,
41+
callback: () => {},
42+
className: "w-full",
43+
disableNumbers: false,
44+
hideNumbers: false,
45+
},
46+
render: function Render(args) {
47+
const [currentPage, setCurrentPage] = useState(1);
48+
49+
return (
50+
<Pagination
51+
{...args}
52+
currentPage={currentPage}
53+
callback={setCurrentPage}
54+
/>
55+
);
56+
},
57+
};

src/stories/tabs.stories.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
import React from "react";
3+
import { IPreviewArgs } from "./utils";
4+
5+
import TabsComponent from "../lib/pagination/tabs";
6+
import Telegram from "../assets/svgs/telegram.svg";
7+
8+
const meta = {
9+
component: TabsComponent,
10+
title: "Pagination/Tabs",
11+
tags: ["autodocs"],
12+
argTypes: {},
13+
} satisfies Meta<typeof TabsComponent>;
14+
15+
export default meta;
16+
17+
type Story = StoryObj<typeof meta> & IPreviewArgs;
18+
19+
export const Tabs: Story = {
20+
args: {
21+
themeUI: "light",
22+
backgroundUI: "light",
23+
className: "w-[500px]",
24+
defaultSelectedKey: "discord",
25+
panelClassName: "bg-klerosUIComponentsLightBlue p-4",
26+
items: [
27+
{ text: "Discord", value: 0, id: "discord", content: <p>Discord</p> },
28+
{
29+
text: "Telegram",
30+
value: 1,
31+
Icon: Telegram,
32+
id: "telegram",
33+
content: <p>Telegram</p>,
34+
},
35+
{
36+
text: "Disabled",
37+
value: 2,
38+
disabled: true,
39+
id: "disabled",
40+
content: <p>Disabled</p>,
41+
},
42+
],
43+
},
44+
};

0 commit comments

Comments
 (0)