@autobusal/common 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ import { TFunction } from 'i18next';
2
+ import { Container, Left, Right, PageText, PageLink } from './styles';
3
+ import { PaginationData } from './types';
4
+
5
+ interface Props {
6
+ pages: PaginationData<unknown>
7
+ t: TFunction<'general'>
8
+ }
9
+
10
+ const Pagination = ({ pages, t }: Props): (JSX.Element | null) => {
11
+ if (pages.last_page < 2) {
12
+ return null;
13
+ }
14
+
15
+ const items = pages.links.map((item, index) => {
16
+ if (item.url) {
17
+ return <PageLink key={ index } to={ item.url } $active={ item.active }>{ item.label }</PageLink>;
18
+ }
19
+
20
+ return <PageText key={ index } $active={ item.active }>{ item.label }</PageText>;
21
+ });
22
+
23
+ return (
24
+ <Container>
25
+ <Left>
26
+ { t('pagination.showing', {
27
+ current: pages.current_page,
28
+ max: pages.last_page
29
+ }) }
30
+ </Left>
31
+
32
+ <Right>
33
+ { items }
34
+ </Right>
35
+ </Container>
36
+ );
37
+ };
38
+
39
+ export default Pagination;
@@ -0,0 +1,61 @@
1
+ import styled, { css } from 'styled-components';
2
+ import { Link } from 'react-router-dom';
3
+
4
+ interface LinkType {
5
+ $active: boolean
6
+ }
7
+
8
+ export const Container = styled.div`
9
+ display: flex;
10
+ align-items: center;
11
+ flex-direction: column;
12
+ flex-wrap: wrap;
13
+ gap: 10px;
14
+
15
+ @media (min-width: 480px) {
16
+ flex-direction: row;
17
+ justify-content: space-between;
18
+ }
19
+ `;
20
+
21
+ export const Left = styled.div`
22
+ font-size: ${ props => props.theme.size.s };
23
+ text-align: center;
24
+ color: ${ props => props.theme.font.faded };
25
+ `;
26
+
27
+ export const Right = styled.div`
28
+ display: flex;
29
+ overflow: hidden;
30
+ background-color: ${ props => props.theme.primary.neutral };
31
+ border-radius: 100px;
32
+ `;
33
+
34
+ const PageCss = css<LinkType>`
35
+ display: inline-block;
36
+ width: 34px;
37
+ height: 30px;
38
+ line-height: 30px;
39
+ text-align: center;
40
+ font-size: ${ props => props.theme.size.s };
41
+ cursor: pointer;
42
+ transition: all 0.3s ease;
43
+
44
+ &:hover {
45
+ text-decoration: none;
46
+ background: ${ props => props.theme.background.neutral };
47
+ }
48
+
49
+ ${ props => props.$active && css`
50
+ font-weight: 700;
51
+ background: ${ props => props.theme.primary.normal } !important;
52
+ ` }
53
+ `;
54
+
55
+ export const PageLink = styled(Link)<LinkType>`
56
+ ${ PageCss }
57
+ `;
58
+
59
+ export const PageText = styled.span<LinkType>`
60
+ ${ PageCss }
61
+ `;
@@ -0,0 +1,12 @@
1
+ export interface PaginationData<T> {
2
+ current_page: number
3
+ last_page: number
4
+ data: T[]
5
+ links: LinkData[]
6
+ }
7
+
8
+ export interface LinkData {
9
+ url: string | null
10
+ label: string
11
+ active: boolean
12
+ }
package/index.ts CHANGED
@@ -5,6 +5,7 @@ import { Button } from './Button/Button';
5
5
  import { General, Paragraph } from './Loading/Loading';
6
6
  import Modal from './Modal/Modal';
7
7
  import Meta from './Meta';
8
+ import Pagination from './Pagination/Pagination';
8
9
  import RouteItem from './RouteItem/RouteItem';
9
10
 
10
11
  export {
@@ -15,6 +16,7 @@ export {
15
16
  General,
16
17
  Meta,
17
18
  Modal,
19
+ Pagination,
18
20
  Paragraph,
19
21
  RouteItem
20
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/common",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "dependencies": {