Skip to content

Commit

Permalink
feat(common): pagination, pagination item (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyechan99 committed Apr 16, 2024
1 parent c6bd799 commit 8e0b23a
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import styled from '@emotion/styled';

interface PaginationProps extends React.PropsWithChildren {}

export const Pagination = ({ children }: PaginationProps) => {
return (
<PaginationNav role="navigation" aria-label="pagination">
{children}
</PaginationNav>
);
};

const PaginationNav = styled.nav``;
15 changes: 15 additions & 0 deletions src/components/Pagination/PaginationContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import styled from '@emotion/styled';

interface PaginationProps extends React.PropsWithChildren {}

export const PaginationContent = ({ children }: PaginationProps) => {
return <PaginationList>{children}</PaginationList>;
};
const PaginationList = styled.ul`
list-style: none;
margin: 0px;
padding: 0px;
display: flex;
flex-direction: row;
gap: 0.5rem;
`;
32 changes: 32 additions & 0 deletions src/components/Pagination/PaginationItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { css } from '@emotion/react';
import styled from '@emotion/styled';

interface PaginationProps extends React.PropsWithChildren {
active?: boolean;
}

export const PaginationItem = ({ active = false, children }: PaginationProps) => {
return <PaginationListItem active={active}>{children}</PaginationListItem>;
};

const PaginationListItem = styled.li<PaginationProps>`
width: 2.5rem;
height: 2.5rem;
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
border-radius: 0.25rem;
font-weight: 500;
${({ active }) =>
active
? css`
background-color: var(--primary);
color: var(--background);
`
: css`
&:hover {
background-color: var(--gray-200);
}
`}
`;
4 changes: 4 additions & 0 deletions src/components/Pagination/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable react-refresh/only-export-components */
export * from './Pagination';
export * from './PaginationContent';
export * from './PaginationItem';
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './Dropdown';
export * from './HoverCard';
export * from './Input';
export * from './Label';
export * from './Pagination';
export * from './Select';
export * from './Switch';
export * from './Textarea';
Expand Down
36 changes: 36 additions & 0 deletions src/stories/common/Pagination.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Meta, StoryObj } from '@storybook/react';
import * as React from 'react';

import { Pagination, PaginationContent, PaginationItem } from '../../';

const meta = {
title: 'common/Pagination',
component: Pagination,
tags: ['autodocs'],
args: {},
parameters: {
layout: 'centered',
componentSubtitle: 'Base Pagination',
},
} satisfies Meta<typeof Pagination>;

export default meta;

type Story = StoryObj<typeof Pagination>;

export const Default: Story = {
args: {},
decorators: [
() => {
return (
<Pagination>
<PaginationContent>
<PaginationItem>1</PaginationItem>
<PaginationItem active>2</PaginationItem>
<PaginationItem>3</PaginationItem>
</PaginationContent>
</Pagination>
);
},
],
};

0 comments on commit 8e0b23a

Please sign in to comment.