Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Pagination): add new component #2352

Merged
merged 6 commits into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import { Pagination } from 'semantic-ui-react'

const PaginationExamplePagination = () => (
<Pagination defaultActivePage={5} totalPages={10} />
)

export default PaginationExamplePagination
16 changes: 16 additions & 0 deletions docs/app/Examples/addons/Pagination/Types/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'

import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'

const PaginationTypesExamples = () => (
<ExampleSection title='Types'>
<ComponentExample
title='Pagination'
description='A component to render a pagination.'
examplePath='addons/Pagination/Types/PaginationExamplePagination'
/>
</ExampleSection>
)

export default PaginationTypesExamples
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { Component } from 'react'
import { Grid, Input, Pagination, Segment } from 'semantic-ui-react'

export default class PaginationExampleControlled extends Component {
state = { activePage: 1 }

handleInputChange = (e, { value }) => this.setState({ activePage: value })

handlePaginationChange = (e, { activePage }) => this.setState({ activePage })

render() {
const { activePage } = this.state

return (
<Grid columns={2} verticalAlign='middle'>
<Grid.Column>
<Segment secondary>
<div>activePage: {activePage}</div>
<Input min={1} max={5} onChange={this.handleInputChange} type='range' value={activePage} />
</Segment>
</Grid.Column>
<Grid.Column>
<Pagination activePage={activePage} onPageChange={this.handlePaginationChange} totalPages={5} />
</Grid.Column>
</Grid>
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import { Pagination } from 'semantic-ui-react'

const PaginationExampleShorthand = () => (
<Pagination
defaultActivePage={1}
firstItem={null}
lastItem={null}
pointing
secondary
totalPages={3}
/>
)

export default PaginationExampleShorthand
114 changes: 114 additions & 0 deletions docs/app/Examples/addons/Pagination/Usage/PaginationExampleOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import React, { Component } from 'react'
import { Grid, Form, Pagination, Segment } from 'semantic-ui-react'

export default class PaginationExampleCustomization extends Component {
state = {
activePage: 5,
boundaryRange: 1,
siblingRange: 1,
showEllipsis: true,
showFirstAndLastNav: true,
showPreviousAndNextNav: true,
totalPages: 50,
}

handleCheckboxChange = (e, { checked, name }) => this.setState({ [name]: checked })

handleInputChange = (e, { name, value }) => this.setState({ [name]: value })

handlePaginationChange = (e, { activePage }) => this.setState({ activePage })

render() {
const {
activePage,
boundaryRange,
siblingRange,
showEllipsis,
showFirstAndLastNav,
showPreviousAndNextNav,
totalPages,
} = this.state

return (
<Grid columns={1}>
<Grid.Column>
<Pagination
activePage={activePage}
boundaryRange={boundaryRange}
onPageChange={this.handlePaginationChange}
size='mini'
totalPages={totalPages}
// Heads up! All items are powered by shorthands, if you want to hide one of them, just pass `null` as value
ellipsisItem={showEllipsis ? undefined : null}
firstItem={showFirstAndLastNav ? undefined : null}
lastItem={showFirstAndLastNav ? undefined : null}
prevItem={showPreviousAndNextNav ? undefined : null}
nextItem={showPreviousAndNextNav ? undefined : null}
/>
</Grid.Column>

<Grid.Column>
<Form as={Segment}>
<Form.Group widths={2}>
<Form.Input
label='Active page'
name='activePage'
min={1}
onChange={this.handleInputChange}
type='number'
value={activePage}
/>
<Form.Input
label='Total pages'
name='totalPages'
min={1}
onChange={this.handleInputChange}
type='number'
value={totalPages}
/>
</Form.Group>
<Form.Group widths={2}>
<Form.Input
label='Boundary pages range'
name='boundaryRange'
min={0}
onChange={this.handleInputChange}
type='number'
value={boundaryRange}
/>
<Form.Input
label='Sibling pages range'
name='siblingRange'
min={0}
onChange={this.handleInputChange}
type='number'
value={siblingRange}
/>
</Form.Group>
<Form.Group inline>
<Form.Checkbox
checked={showEllipsis}
label='Show ellipsis'
name='showEllipsis'
onChange={this.handleCheckboxChange}
/>
<Form.Checkbox
checked={showFirstAndLastNav}
label='Show first and last nav pages'
name='showFirstAndLastNav'
onChange={this.handleCheckboxChange}
/>
<Form.Checkbox
checked={showPreviousAndNextNav}
label='Show previous and next nav pages'
name='showPreviousAndNextNav'
onChange={this.handleCheckboxChange}
/>
</Form.Group>
</Form>
</Grid.Column>

</Grid>
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import { Icon, Pagination } from 'semantic-ui-react'

const PaginationExampleShorthand = () => (
<Pagination
defaultActivePage={5}
ellipsisItem={{ content: <Icon name='ellipsis horizontal' />, icon: true }}
firstItem={{ content: <Icon name='angle double left' />, icon: true }}
lastItem={{ content: <Icon name='angle double right' />, icon: true }}
prevItem={{ content: <Icon name='angle left' />, icon: true }}
nextItem={{ content: <Icon name='angle right' />, icon: true }}
totalPages={10}
/>
)

export default PaginationExampleShorthand
31 changes: 31 additions & 0 deletions docs/app/Examples/addons/Pagination/Usage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react'

import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'

const PaginationUsageExamples = () => (
<ExampleSection title='Usage'>
<ComponentExample
title='Controlled'
description='A pagination can be controlled component.'
examplePath='addons/Pagination/Usage/PaginationExampleControlled'
/>
<ComponentExample
title='Options'
description='A pagination has configurable options.'
examplePath='addons/Pagination/Usage/PaginationExampleOptions'
/>
<ComponentExample
title='Menu Props'
description='A pagination is a wrapper for Menu component, you can use Menu props with Pagination.'
examplePath='addons/Pagination/Usage/PaginationExampleMenuProps'
/>
<ComponentExample
title='Shorthand'
description='A pagination has support of shorthand API for its items.'
examplePath='addons/Pagination/Usage/PaginationExampleShorthand'
/>
</ExampleSection>
)

export default PaginationUsageExamples
13 changes: 13 additions & 0 deletions docs/app/Examples/addons/Pagination/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react'

import Types from './Types'
import Usage from './Usage'

const PaginationExamples = () => (
<div>
<Types />
<Usage />
</div>
)

export default PaginationExamples
8 changes: 7 additions & 1 deletion docs/app/Examples/collections/Menu/Types/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react'
import { Link } from 'react-router-dom'
import { Message } from 'semantic-ui-react'

import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'
Expand Down Expand Up @@ -67,7 +69,11 @@ const Types = () => (
title='Pagination'
description='A pagination menu is specially formatted to present links to pages of content.'
examplePath='collections/Menu/Types/MenuExamplePagination'
/>
>
<Message info>
For fully featured pagination, see <Link to='/addons/pagination'>Pagination</Link> addon.
</Message>
</ComponentExample>
</ExampleSection>
)

Expand Down
10 changes: 6 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Addons
export { default as Confirm, ConfirmProps } from './dist/commonjs/addons/Confirm';
export { default as Pagination, PaginationProps } from './dist/commonjs/addons/Pagination';
export { default as PaginationItem, PaginationItemProps } from './dist/commonjs/addons/Pagination/PaginationItem';
export { default as Portal, PortalProps } from './dist/commonjs/addons/Portal';
export { default as Radio, RadioProps } from './dist/commonjs/addons/Radio';
export { default as Ref, RefProps } from './dist/commonjs/addons/Ref';
export {
default as Responsive,
ResponsiveProps,
ResponsiveWidthShorthand
} from './dist/commonjs/addons/Responsive';
export { default as Confirm, ConfirmProps } from './dist/commonjs/addons/Confirm';
export { default as Portal, PortalProps } from './dist/commonjs/addons/Portal';
export { default as Radio, RadioProps } from './dist/commonjs/addons/Radio';
export { default as Ref, RefProps } from './dist/commonjs/addons/Ref';
export { default as Select, SelectProps } from './dist/commonjs/addons/Select';
export { default as TextArea, TextAreaProps } from './dist/commonjs/addons/TextArea';
export {
Expand Down
58 changes: 58 additions & 0 deletions src/addons/Pagination/Pagination.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as React from 'react';

import { SemanticShorthandItem } from '../..';
import { default as PaginationItem, PaginationItemProps } from './PaginationItem';

export interface PaginationProps {
[key: string]: any;

/** A pagination item can have an aria label. */
ariaLabel?: string;

/** Initial activePage value. */
defaultActivePage?: number | string;

/** Index of the currently active page. */
activePage?: number | string;

/** Number of always visible pages at the beginning and end. */
boundaryRange?: number | string;

/** A shorthand for PaginationItem. */
ellipsisItem?: SemanticShorthandItem<PaginationItemProps>;

/** A shorthand for PaginationItem. */
firstItem?: SemanticShorthandItem<PaginationItemProps>;

/** A shorthand for PaginationItem. */
lastItem?: SemanticShorthandItem<PaginationItemProps>;

/** A shorthand for PaginationItem. */
nextItem?: SemanticShorthandItem<PaginationItemProps>;

/** A shorthand for PaginationItem. */
pageItem?: SemanticShorthandItem<PaginationItemProps>;

/** A shorthand for PaginationItem. */
prevItem?: SemanticShorthandItem<PaginationItemProps>;

/**
* Called on change of an active page.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All props.
*/
onPageChange?: (event: React.MouseEvent<HTMLAnchorElement>, data: PaginationProps) => void;

/** Number of always visible pages before and after the current one. */
siblingRange?: number | string;

/** Total number of pages. */
totalPages: number | string;
}

declare class Pagination extends React.Component<PaginationProps, {}> {
static Item: typeof PaginationItem;
}

export default Pagination;
Loading