Skip to content

Commit

Permalink
Tweakd dark mode of PaginationItem component
Browse files Browse the repository at this point in the history
Added dark mode storybook component
  • Loading branch information
mahyarkarimi committed Dec 27, 2023
1 parent 88fe269 commit de73dcf
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chakra-pagination",
"version": "1.0.2",
"version": "1.0.3",
"description": "",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand All @@ -19,6 +19,10 @@
"paginator",
"pagination"
],
"repository": {
"type": "git",
"url": "https://github.com/mahyarkarimi/chakra-pagination.git"
},
"author": "Mahyar Karimi",
"license": "MIT",
"peerDependencies": {
Expand Down
51 changes: 45 additions & 6 deletions src/components/Pagination.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import React from 'react';
import React, { useEffect } from 'react';
import type { Meta, StoryObj } from '@storybook/react';

import { Pagination as PaginationComponent } from './Pagination';
import { useState } from 'react';
import { ChakraProvider } from '@chakra-ui/react';
import { Box, ChakraProvider, ColorModeScript, DarkMode, useColorMode } from '@chakra-ui/react';
import { extendTheme } from '@chakra-ui/react'

const decorators = [
(Story, context) => {
return (
<ChakraProvider>
<Story />
</ChakraProvider>
);
}
];

const meta = {
component: PaginationComponent,
decorators
} satisfies Meta<typeof PaginationComponent>;

export default meta;
Expand All @@ -17,12 +29,39 @@ export const Pagination: Story = {
colorScheme: 'teal',
total: 100
},
render: ({ colorScheme, total, ...props}) => {
parameters: {
backgrounds: { default: 'light' },
},
render: ({ colorScheme, total, ...props }) => {
const [page, setPage] = useState(1);
const { setColorMode } = useColorMode();

useEffect(() => {
setColorMode('light')
}, []);
return (
<PaginationComponent {...props} currentPage={page} onPageChange={setPage} total={total} colorScheme={colorScheme} />
)
}
};

export const DarkPagination: Story = {
args: {
colorScheme: 'teal',
total: 55
},
parameters: {
backgrounds: { default: 'dark' },
},
render: ({ colorScheme, total, ...props }) => {
const { setColorMode } = useColorMode();
const [page, setPage] = useState(1);

useEffect(() => {
setColorMode('dark')
}, []);
return (
<ChakraProvider>
<PaginationComponent currentPage={page} onPageChange={setPage} total={total} colorScheme={colorScheme} />
</ChakraProvider>
<PaginationComponent {...props} currentPage={page} onPageChange={setPage} total={total} colorScheme={colorScheme} />
)
}
};
7 changes: 4 additions & 3 deletions src/components/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo } from 'react';
import { Stack, Button, Text, ThemeTypings } from '@chakra-ui/react';
import { Stack, Button, Text, ThemeTypings, useColorModeValue } from '@chakra-ui/react';
import { usePagination } from './usePagination';

type PaginationItemProps = {
Expand All @@ -19,6 +19,8 @@ type PaginationProps = {
};

function PaginationItem({ isCurrent = false, page, onPageChange, colorScheme }: PaginationItemProps) {
const value = useColorModeValue(`${colorScheme}.100`, `${colorScheme}.800`)

if (isCurrent) {
return (
<Button
Expand All @@ -42,10 +44,9 @@ function PaginationItem({ isCurrent = false, page, onPageChange, colorScheme }:
size='sm'
fontSize='xs'
width='4'
bg='gray.200'
textColor={colorScheme}
_hover={{
bg: `${colorScheme}.100`,
bg: value,
}}
onClick={() => onPageChange(page)}
>
Expand Down

0 comments on commit de73dcf

Please sign in to comment.