Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

feature: Panels pagination redesign and add new prop 'focus' for button

kruzhambusf392cf28e44a
diff --git a/src/pages/Project/View/Panels.jsx b/src/pages/Project/View/Panels.jsx
index e24bd448e..5f93c9945 100644
--- a/src/pages/Project/View/Panels.jsx
+++ b/src/pages/Project/View/Panels.jsx
@@ -1,7 +1,9 @@
import React, {
memo, useState, useEffect, useMemo, Fragment,
} from 'react'
-import { ArrowSmallUpIcon, ArrowSmallDownIcon } from '@heroicons/react/24/solid'
+import {
+ ArrowSmallUpIcon, ArrowSmallDownIcon, ArrowLongRightIcon, ArrowLongLeftIcon,
+} from '@heroicons/react/24/solid'
import {
FunnelIcon, MapIcon, Bars4Icon, ArrowsPointingOutIcon, ChartPieIcon, PuzzlePieceIcon,
} from '@heroicons/react/24/outline'
@@ -21,10 +23,12 @@ import _floor from 'lodash/floor'
import _size from 'lodash/size'
import _slice from 'lodash/slice'
import _sum from 'lodash/sum'
+import _ceil from 'lodash/ceil'
import Progress from 'ui/Progress'
import PulsatingCircle from 'ui/icons/PulsatingCircle'
import Modal from 'ui/Modal'
+import Button from 'ui/Button'
import Chart from 'ui/Chart'
import LiveVisitorsDropdown from './components/LiveVisitorsDropdown'
import InteractiveMap from './components/InteractiveMap'
@@ -439,6 +443,7 @@ const Panel = ({
const keys = useMemo(() => _keys(data).sort((a, b) => data[b] - data[a]), [data])
const keysToDisplay = useMemo(() => _slice(keys, currentIndex, currentIndex + 5), [keys, currentIndex])
const total = useMemo(() => _reduce(keys, (prev, curr) => prev + data[curr], 0), [keys]) // eslint-disable-line
+ const totalPages = useMemo(() => _ceil(_size(keys) / ENTRIES_PER_PANEL), [keys])
const [activeFragment, setActiveFragment] = useState(0)
const [modal, setModal] = useState(false)
const canGoPrev = () => page > 0
@@ -643,32 +648,50 @@ const Panel = ({
{_size(keys) > 5 && (
<div className='absolute bottom-0 w-card-toggle-sm sm:w-card-toggle'>
<div className='flex justify-between select-none mb-2'>
- <span
- className={cx('text-gray-500 dark:text-gray-200 font-light', {
- hoverable: canGoPrev(),
- disabled: !canGoPrev(),
- })}
- role='button'
- onClick={onPrevious}
- tabIndex={0}
- >
- &lt;
- &nbsp;
- {t('project.prev')}
- </span>
- <span
- className={cx('text-gray-500 dark:text-gray-200 font-light', {
- hoverable: canGoNext(),
- disabled: !canGoNext(),
- })}
- role='button'
- onClick={onNext}
- tabIndex={0}
- >
- {t('project.next')}
- &nbsp;
- &gt;
- </span>
+ <div>
+ <span className='text-gray-500 dark:text-gray-200 font-light text-xs'>
+ {_size(keys)}
+ {' '}
+ {/* {t('project.results')} */}
+ results
+ </span>
+ <span className='text-gray-500 dark:text-gray-200 font-light text-xs'>
+ .
+ {' '}
+ Page
+ {' '}
+ {/* {t('project.page')} */}
+ {page + 1}
+ {' '}
+ /
+ {' '}
+ {totalPages}
+ </span>
+ </div>
+ <div className='flex justify-between w-[4.5rem]'>
+ <Button
+ className={cx('text-gray-500 dark:text-gray-200 font-light shadow bg-gray-100 hover:bg-gray-200 dark:bg-gray-800 hover:dark:bg-slate-700 border-none px-1.5 py-0.5', {
+ 'opacity-50 cursor-not-allowed': !canGoPrev(),
+ })}
+ type='button'
+ onClick={onPrevious}
+ disabled={!canGoPrev()}
+ focus={false}
+ >
+ <ArrowLongLeftIcon className='w-5 h-5' />
+ </Button>
+ <Button
+ className={cx('text-gray-500 dark:text-gray-200 font-light shadow bg-gray-100 hover:bg-gray-200 dark:bg-gray-800 hover:dark:bg-slate-700 border-none px-1.5 py-0.5', {
+ 'opacity-50 cursor-not-allowed': !canGoNext(),
+ })}
+ onClick={onNext}
+ disabled={!canGoNext()}
+ type='button'
+ focus={false}
+ >
+ <ArrowLongRightIcon className='w-5 h-5' />
+ </Button>
+ </div>
</div>
</div>
)}
diff --git a/src/ui/Button.jsx b/src/ui/Button.jsx
index 0e95519ae..6d33fff35 100644
--- a/src/ui/Button.jsx
+++ b/src/ui/Button.jsx
@@ -8,7 +8,7 @@ import Spin from './icons/Spin'
import './ButtonChristmas.css'
const Button = ({
- text, children, primary, secondary, danger, onClick, white, small, regular, large, giant, type, className, loading, semiSmall, semiDanger, noBorder,
+ text, children, primary, secondary, danger, onClick, white, small, regular, large, giant, type, className, loading, semiSmall, semiDanger, noBorder, focus,
}) => {
// const themeType = useSelector((state) => state.ui.theme.type)
@@ -16,7 +16,7 @@ const Button = ({
<button
type={type}
onClick={onClick}
- className={cx('relative inline-flex select-none items-center border leading-4 font-medium rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500', {
+ className={cx('relative inline-flex select-none items-center border leading-4 font-medium rounded-md', {
'shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 border-transparent': primary,
'text-indigo-700 bg-indigo-100 hover:bg-indigo-200 border-transparent': secondary,
'text-gray-700 bg-white hover:bg-gray-50 border-transparent': white,
@@ -29,6 +29,7 @@ const Button = ({
'px-6 py-3 text-base': giant,
'px-3 py-2 text-sm': regular,
'cursor-not-allowed': loading,
+ 'focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500': focus,
}, className)}
>
{/* {themeType === THEME_TYPE.christmas ? (
@@ -75,6 +76,7 @@ Button.propTypes = {
type: PropTypes.string,
className: PropTypes.string,
loading: PropTypes.bool,
+ focus: PropTypes.bool,
}
Button.defaultProps = {
@@ -94,6 +96,7 @@ Button.defaultProps = {
type: 'button',
className: '',
children: null,
+ focus: true,
}
export default memo(Button)