This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: csonchen <cson_chensheng@163.com>
- Loading branch information
Showing
4 changed files
with
101 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react'; | ||
import { Pagination as BSPagination } from 'react-bootstrap'; | ||
import { PaginationProps } from '../../interface'; | ||
|
||
export default class Pagination extends React.Component<PaginationProps> { | ||
initPageItems = () => { | ||
const { items, activePage, maxButtons = 5, onSelectChange } = this.props; | ||
const pageItems: JSX.Element[] = []; | ||
let startPage; | ||
let endPage; | ||
if (maxButtons < items) { | ||
startPage = Math.max( | ||
Math.min(activePage - Math.floor(maxButtons / 2), items - maxButtons + 1), | ||
1, | ||
); | ||
endPage = startPage + maxButtons - 1; | ||
} else { | ||
startPage = 1; | ||
endPage = items; | ||
} | ||
for (let number = startPage; number <= endPage; number++) { | ||
pageItems.push( | ||
<BSPagination.Item | ||
key={number} | ||
active={number === activePage} | ||
onClick={() => onSelectChange(number)} | ||
> | ||
{number} | ||
</BSPagination.Item>, | ||
); | ||
} | ||
return pageItems; | ||
}; | ||
|
||
render() { | ||
const { | ||
first, | ||
prev, | ||
next, | ||
last, | ||
activePage, | ||
items, | ||
maxButtons, | ||
onSelectChange, | ||
...restProps | ||
} = this.props; | ||
const pageItems = this.initPageItems(); | ||
|
||
return ( | ||
<BSPagination {...restProps}> | ||
{first && <BSPagination.First onClick={() => onSelectChange(1)} />} | ||
{prev && <BSPagination.Prev onClick={() => onSelectChange(activePage - 1)} />} | ||
{pageItems} | ||
{next && <BSPagination.Next onClick={() => onSelectChange(activePage + 1)} />} | ||
{last && <BSPagination.Last onClick={() => onSelectChange(items)} />} | ||
</BSPagination> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,28 @@ | ||
import Alert from './Alert'; | ||
import Badge from './Badge'; | ||
import Button from './Button'; | ||
import DatePicker from './DatePicker'; | ||
import Dropdown from './Dropdown'; | ||
import DropdownButton from './DropdownButton'; | ||
import Icon from './Icon'; | ||
import InputDropdown from './InputDropdown'; | ||
import Loader from './Loader'; | ||
import Navigation from './Navigation'; | ||
import Notification from './/Notification/Notification'; | ||
import NotificationList from './Notification/NotificationList'; | ||
import Modal from './Modal'; | ||
import Panel from './Panel'; | ||
import Popover from './Popover'; | ||
import RangePicker from './RangePicker'; | ||
import Steps from './Steps'; | ||
import SubMenu from './SubMenu'; | ||
import Switch from './Switch'; | ||
import Tabs from './Tabs'; | ||
import TimePicker from './TimePicker'; | ||
import Tooltip from './Tooltip'; | ||
import Tree from './Tree'; | ||
import UsageBar from './UsageBar'; | ||
import VirtualList from './VirtualList'; | ||
import VirtualSelectBox from './VirtualSelectBox'; | ||
import { | ||
Breadcrumb, | ||
BreadcrumbItem, | ||
Button as BsButton, | ||
ButtonGroup, | ||
ButtonToolbar, | ||
Container, | ||
Col, | ||
Collapse, | ||
Form, | ||
FormCheck, | ||
FormControl, | ||
FormGroup, | ||
FormLabel, | ||
InputGroup, | ||
ListGroup, | ||
ListGroupItem, | ||
Nav, | ||
Navbar, | ||
NavItem, | ||
NavDropdown, | ||
Overlay, | ||
OverlayTrigger, | ||
Pagination, | ||
ProgressBar, | ||
Row, | ||
SplitButton, | ||
Tab, | ||
ToggleButtonGroup, | ||
ToggleButton, | ||
} from 'react-bootstrap'; | ||
|
||
export { | ||
Alert, | ||
Badge, | ||
Breadcrumb, | ||
BreadcrumbItem, | ||
BsButton, | ||
Button, | ||
ButtonGroup, | ||
ButtonToolbar, | ||
Collapse, | ||
Container, | ||
Col, | ||
DatePicker, | ||
Dropdown, | ||
DropdownButton, | ||
Form, | ||
FormCheck, | ||
FormControl, | ||
FormGroup, | ||
FormLabel, | ||
Icon, | ||
InputDropdown, | ||
InputGroup, | ||
Loader, | ||
ListGroup, | ||
ListGroupItem, | ||
Nav, | ||
Navbar, | ||
NavDropdown, | ||
NavItem, | ||
Navigation, | ||
NotificationList, | ||
Notification, | ||
Modal, | ||
Overlay, | ||
OverlayTrigger, | ||
ProgressBar, | ||
Pagination, | ||
Panel, | ||
Popover, | ||
RangePicker, | ||
Row, | ||
SplitButton, | ||
Steps, | ||
SubMenu, | ||
Switch, | ||
Tab, | ||
Tabs, | ||
TimePicker, | ||
Tooltip, | ||
Tree, | ||
ToggleButtonGroup, | ||
ToggleButton, | ||
UsageBar, | ||
VirtualList, | ||
VirtualSelectBox, | ||
}; | ||
export * from 'react-bootstrap'; | ||
export { default as Alert } from './Alert'; | ||
export { default as Badge } from './Badge'; | ||
export { default as Button } from './Button'; | ||
export { default as DatePicker } from './DatePicker'; | ||
export { default as Dropdown } from './Dropdown'; | ||
export { default as DropdownButton } from './DropdownButton'; | ||
export { default as Icon } from './Icon'; | ||
export { default as InputDropdown } from './InputDropdown'; | ||
export { default as Loader } from './Loader'; | ||
export { default as Navigation } from './Navigation'; | ||
export { default as Notification } from './/Notification/Notification'; | ||
export { default as NotificationList } from './Notification/NotificationList'; | ||
export { default as Modal } from './Modal'; | ||
export { default as Panel } from './Panel'; | ||
export { default as Pagination } from './Pagination'; | ||
export { default as Popover } from './Popover'; | ||
export { default as RangePicker } from './RangePicker'; | ||
export { default as Steps } from './Steps'; | ||
export { default as SubMenu } from './SubMenu'; | ||
export { default as Switch } from './Switch'; | ||
export { default as Tabs } from './Tabs'; | ||
export { default as TimePicker } from './TimePicker'; | ||
export { default as Tooltip } from './Tooltip'; | ||
export { default as Tree } from './Tree'; | ||
export { default as UsageBar } from './UsageBar'; | ||
export { default as VirtualList } from './VirtualList'; | ||
export { default as VirtualSelectBox } from './VirtualSelectBox'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters