diff --git a/packages/chakra-components/src/components/Pagination/EllipsisButton.tsx b/packages/chakra-components/src/components/Pagination/EllipsisButton.tsx
new file mode 100644
index 00000000..56aa8914
--- /dev/null
+++ b/packages/chakra-components/src/components/Pagination/EllipsisButton.tsx
@@ -0,0 +1,48 @@
+import { useState } from 'react'
+import { useStyleConfig } from '@chakra-ui/system'
+import { Button, ButtonProps, Input, InputProps } from '@chakra-ui/react'
+
+type EllipsisButtonProps = ButtonProps & {
+ gotoPage: (page: number) => void
+ inputProps?: InputProps
+}
+
+export const EllipsisButton = ({ gotoPage, inputProps, ...rest }: EllipsisButtonProps) => {
+ const [ellipsisInput, setEllipsisInput] = useState(false)
+ const styles = useStyleConfig('EllipsisButton', rest)
+
+ if (ellipsisInput) {
+ return (
+ {
+ if (e.target instanceof HTMLInputElement && e.key === 'Enter') {
+ const pageNumber = Number(e.target.value)
+ gotoPage(pageNumber)
+ setEllipsisInput(false)
+ }
+ }}
+ onBlur={() => setEllipsisInput(false)}
+ autoFocus
+ />
+ )
+ }
+
+ return (
+
+ )
+}
diff --git a/packages/chakra-components/src/components/Pagination.tsx b/packages/chakra-components/src/components/Pagination/Pagination.tsx
similarity index 72%
rename from packages/chakra-components/src/components/Pagination.tsx
rename to packages/chakra-components/src/components/Pagination/Pagination.tsx
index 21cc7b2e..15bde823 100644
--- a/packages/chakra-components/src/components/Pagination.tsx
+++ b/packages/chakra-components/src/components/Pagination/Pagination.tsx
@@ -1,9 +1,11 @@
-import { Button, ButtonGroup, ButtonGroupProps, ButtonProps, Input, InputProps, Text } from '@chakra-ui/react'
-import { ReactElement, useMemo, useState } from 'react'
+import { ButtonGroup, ButtonGroupProps, ButtonProps, InputProps, Text } from '@chakra-ui/react'
+import { ReactElement, useMemo } from 'react'
import { generatePath, Link as RouterLink, useLocation, useNavigate, useParams } from 'react-router-dom'
-import { usePagination, useRoutedPagination } from '@vocdoni/react-providers'
+import { useLocalize, usePagination, useRoutedPagination } from '@vocdoni/react-providers'
import { PaginationResponse } from '@vocdoni/sdk'
-import { Trans } from 'react-i18next'
+import { useMultiStyleConfig, chakra } from '@chakra-ui/system'
+import { EllipsisButton } from './EllipsisButton'
+import { PaginatorButton } from './PaginatorButton'
export type PaginationProps = ButtonGroupProps & {
maxButtons?: number | false
@@ -16,57 +18,19 @@ type PaginatorButtonProps = {
currentPage: number
} & ButtonProps
-const PageButton = ({ page, currentPage, ...rest }: PaginatorButtonProps) => (
-
-)
-
-const RoutedPageButton = ({ page, currentPage, to, ...rest }: PaginatorButtonProps & { to: string }) => (
-
-)
-
-type EllipsisButtonProps = ButtonProps & {
- gotoPage: (page: number) => void
- inputProps?: InputProps
+const PageButton = ({ page, currentPage, ...rest }: PaginatorButtonProps) => {
+ return (
+
+ {page + 1}
+
+ )
}
-const EllipsisButton = ({ gotoPage, inputProps, ...rest }: EllipsisButtonProps) => {
- const [ellipsisInput, setEllipsisInput] = useState(false)
-
- if (ellipsisInput) {
- return (
- {
- if (e.target instanceof HTMLInputElement && e.key === 'Enter') {
- const pageNumber = Number(e.target.value)
- gotoPage(pageNumber)
- setEllipsisInput(false)
- }
- }}
- onBlur={() => setEllipsisInput(false)}
- autoFocus
- />
- )
- }
-
+const RoutedPageButton = ({ page, currentPage, to, ...rest }: PaginatorButtonProps & { to: string }) => {
return (
-
+
+ {page + 1}
+
)
}
@@ -139,6 +103,9 @@ const PaginationButtons = ({
goToPage: GotoPageType
} & ButtonGroupProps &
Pick) => {
+ const styles = useMultiStyleConfig('Pagination')
+ const t = useLocalize()
+
const pages = usePaginationPages(
currentPage,
totalPages,
@@ -152,34 +119,34 @@ const PaginationButtons = ({
)
return (
- <>
-
+
+
{totalPages === undefined ? (
<>
-
-
+
>
) : (
pages
)}
{totalItems && (
-
-
- Showing a total of {{ count: totalItems }} results
-
+
+ {t('pagination.total_results', {
+ count: totalItems,
+ })}
)}
- >
+
)
}
diff --git a/packages/chakra-components/src/components/Pagination/PaginatorButton.tsx b/packages/chakra-components/src/components/Pagination/PaginatorButton.tsx
new file mode 100644
index 00000000..17412fc9
--- /dev/null
+++ b/packages/chakra-components/src/components/Pagination/PaginatorButton.tsx
@@ -0,0 +1,7 @@
+import { useStyleConfig } from '@chakra-ui/system'
+import { Button, ButtonProps, forwardRef } from '@chakra-ui/react'
+
+export const PaginatorButton = forwardRef((props, ref) => {
+ const styles = useStyleConfig('PageButton', props)
+ return
+})
diff --git a/packages/chakra-components/src/components/Pagination/index.ts b/packages/chakra-components/src/components/Pagination/index.ts
new file mode 100644
index 00000000..fe3b56b9
--- /dev/null
+++ b/packages/chakra-components/src/components/Pagination/index.ts
@@ -0,0 +1 @@
+export * from './Pagination'
diff --git a/packages/chakra-components/src/components/index.ts b/packages/chakra-components/src/components/index.ts
index 945cfbd7..4f27e695 100644
--- a/packages/chakra-components/src/components/index.ts
+++ b/packages/chakra-components/src/components/index.ts
@@ -6,3 +6,5 @@ export * from './Election'
export * from './layout'
// Organization components
export * from './Organization'
+// Pagination components
+export * from './Pagination'
diff --git a/packages/chakra-components/src/i18n/locales.ts b/packages/chakra-components/src/i18n/locales.ts
index addaa82b..3b90f4e0 100644
--- a/packages/chakra-components/src/i18n/locales.ts
+++ b/packages/chakra-components/src/i18n/locales.ts
@@ -38,6 +38,9 @@ export const locales = {
not_voted_in_ended_election: "You did not vote in this election and it's already finished",
},
loading: 'Loading...',
+ pagination: {
+ total_results: 'Showing a total of {{ count }} results',
+ },
question_types: {
approval_tooltip:
"Approval voting lets you vote for as many options as you like. The one with the most votes wins. It's a simple way to show your support for all the choices you approve of.",
diff --git a/packages/chakra-components/src/theme/index.ts b/packages/chakra-components/src/theme/index.ts
index 00710637..b5435ab9 100644
--- a/packages/chakra-components/src/theme/index.ts
+++ b/packages/chakra-components/src/theme/index.ts
@@ -9,6 +9,7 @@ import {
QuestionsTypeBadgeTheme,
} from './questions'
import { ResultsTheme as ElectionResults } from './results'
+import { PaginationTheme as Pagination } from './pagination'
import { VoteWeightTheme } from './vote'
export const theme = {
@@ -19,6 +20,7 @@ export const theme = {
ElectionSchedule,
ElectionTitle,
HorizontalRuler: HorizontalRulerTheme,
+ Pagination,
ConfirmModal: ConfirmModalTheme,
QuestionsConfirmation: QuestionsConfirmationTheme,
QuestionsTip: QuestionsTipTheme,
diff --git a/packages/chakra-components/src/theme/pagination.ts b/packages/chakra-components/src/theme/pagination.ts
new file mode 100644
index 00000000..0928a83c
--- /dev/null
+++ b/packages/chakra-components/src/theme/pagination.ts
@@ -0,0 +1,24 @@
+import { createMultiStyleConfigHelpers } from '@chakra-ui/styled-system'
+
+export const PaginationAnatomy = [
+ // Top level wrapper
+ 'wrapper',
+ // wrapper for buttons
+ 'buttonGroup',
+ // total results text
+ 'totalResults',
+]
+
+const { defineMultiStyleConfig: defineVoteWeightTipStyle, definePartsStyle: defineVoteWeightParts } =
+ createMultiStyleConfigHelpers(PaginationAnatomy)
+
+export const PaginationTheme = defineVoteWeightTipStyle({
+ baseStyle: defineVoteWeightParts({
+ wrapper: {},
+ buttonGroup: {
+ flexWrap: 'wrap',
+ rowGap: '2',
+ },
+ totalResults: {},
+ }),
+})