Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
283 commits
Select commit Hold shift + click to select a range
e4072ae
lint it up
Oct 17, 2019
edf5e35
types typo
Oct 17, 2019
a588ca6
ButtonTableList tweaks
Oct 17, 2019
05fc7c8
fix up SelectMenu.Item
Oct 17, 2019
2b59e42
lint
Oct 17, 2019
699d591
use display to show/hide selected icon
Oct 17, 2019
85f2aaa
add selected prop
Oct 17, 2019
9dc0bcb
switch up details-menu ordering
Oct 17, 2019
d5c5cf9
lint
Oct 18, 2019
00472b5
don't import CE
Oct 18, 2019
774f54c
remove text decoration
Oct 18, 2019
3a33e97
add link
Oct 21, 2019
e19df84
merge in master
Oct 31, 2019
27bbef0
Merge branch 'release-15.1.0' into select-menu
Nov 5, 2019
4feab80
fix up px
Nov 6, 2019
3fef875
Merge branch 'master' of github.com:primer/components into select-menu
Nov 13, 2019
66a48ba
tab navigation
Nov 14, 2019
051b944
initial filter work
Nov 14, 2019
9ef1ccf
typos
Nov 14, 2019
e00bab1
filtering
Nov 14, 2019
f2e19aa
refactor panels + list
Nov 14, 2019
55d0c5a
lint
Nov 14, 2019
130fadf
update snaps
Nov 14, 2019
73de961
typo in types
Nov 14, 2019
4ea2e23
add fragment component
Nov 15, 2019
e014a10
lint
Nov 15, 2019
be14646
update deps
Nov 15, 2019
4f02f97
add new types
Nov 16, 2019
9340a98
add static filter
Nov 19, 2019
1e26ef2
lint
Nov 19, 2019
c84f9aa
fix failing test
Nov 19, 2019
ffcc83e
type typo
Nov 19, 2019
f48bd11
add types packages
Nov 20, 2019
14c13ee
remove filter input
Nov 20, 2019
6562514
delete static filter
Nov 20, 2019
b6af090
refactor all the things lol
Nov 21, 2019
c554f25
add link styles for nested links
Nov 21, 2019
4d7e885
fix text input type
Nov 21, 2019
448fe11
add autofocus to Filter types
Nov 21, 2019
e47cc6f
update text input
Nov 21, 2019
d279932
remove unnecessary prop on filter
Nov 21, 2019
071aef6
KeyboardNav hook
Nov 21, 2019
cd010f4
fix linting errors
Nov 21, 2019
8b1b66d
Expose MenuContext and track filterText in context
dmarcey Nov 21, 2019
2866e50
Remove unused import.
dmarcey Nov 21, 2019
7670755
typo
Nov 21, 2019
6eef60f
Merge branch 'select-menu' of github.com:primer/components into selec…
Nov 21, 2019
d4bd9e5
update hook
Nov 22, 2019
f5382fa
remove e.Handled
Nov 22, 2019
8cbbf78
refactor styles
Nov 22, 2019
d094741
open menu if not open yet
Nov 22, 2019
167ea40
add event listener to details in useKeyboardNav
dmarcey Nov 22, 2019
a1ee357
Prettier lint fix.
dmarcey Nov 22, 2019
37293f6
add hooks folder, export filter hook
Nov 23, 2019
496f0bb
remove details-menu
Nov 23, 2019
6640706
new hooks folder
Nov 23, 2019
bb4da83
move context into top level component
Nov 23, 2019
5267dfb
Move Context into separate file to fix circular dependency
dmarcey Nov 25, 2019
02cd588
Don't store extra filterText state in useFilter
dmarcey Nov 25, 2019
3fdac49
Merge branch 'master' into select-menu
dmarcey Nov 25, 2019
3980d31
Fix SelectMenuFilterProps
dmarcey Nov 25, 2019
cb9e952
Change Select Item to link
Nov 25, 2019
85416a8
autofocus filter for select menu
Nov 25, 2019
04df0b9
fix docs
Nov 25, 2019
8b56618
hide items with hidden attribute
Nov 25, 2019
c2483b9
add comment
Nov 25, 2019
0ebffeb
refactor modal a bit
Nov 27, 2019
b557400
rename filter -> menuFilter
Dec 3, 2019
5bbd404
style fixes
Dec 3, 2019
c037c2a
lint fix
Dec 3, 2019
a883599
use non strict versions
Dec 3, 2019
990918b
fix types for tabs
Dec 10, 2019
7576427
add prop types to TabPanel
Dec 10, 2019
d4518c9
types typo
Dec 10, 2019
bf13579
fix types
Dec 10, 2019
7387c6f
add initial tab to select menu type
Dec 12, 2019
f8e6bc4
tab style fixes
Dec 12, 2019
397e3d4
lint
Dec 12, 2019
ced2f37
log menu context
Dec 19, 2019
71aadc3
lint
Dec 19, 2019
97faf21
lintntntntntnt
Dec 19, 2019
56e4ef5
put initial tab in context
Dec 20, 2019
df0bda4
lint
Dec 20, 2019
43c3010
use data attribute
Dec 20, 2019
515f758
remove data attribute
Dec 20, 2019
12e05d2
Replace deprecated theme.maxWidths with theme.sizes
dcastil Jan 10, 2020
4646aba
Merge branch 'master' into select-menu
Feb 6, 2020
11b5585
update snaps
Feb 6, 2020
392d0ef
rename context provider
Feb 6, 2020
d9475c0
update focus styles
Feb 6, 2020
8fef8d9
rename SelectMenu.Loading to LoadingOctoface
Feb 7, 2020
bac293a
add code comment to TextInput
Feb 7, 2020
730a864
use ul and li for menu + clean up styles
Feb 13, 2020
8292da6
update box shadow
Feb 13, 2020
ecd3dc4
match selected styles to Primer CSS
Feb 13, 2020
31e98ae
update Divider
Feb 13, 2020
220cc91
add footer docs
Feb 13, 2020
e94ece2
update Divdier, Footer & tabs documentation
Feb 13, 2020
3590d78
refactor Tabs and Tab
Feb 14, 2020
2806f7b
lint
Feb 18, 2020
ad0dc0b
refactor Heading and List into wrapping components
Feb 18, 2020
1beadf6
remove SelectMenu.Summary
Feb 18, 2020
3d11e33
update docs
Feb 18, 2020
877dee7
update types
Feb 18, 2020
56bbce1
add List back
Feb 18, 2020
217d8ca
fix tab border issue
Feb 18, 2020
4595146
updat3e docs
Feb 18, 2020
b692ac5
props cleanup
Feb 18, 2020
7c15fde
remove export
Feb 18, 2020
31df2fa
linting
Feb 18, 2020
0252590
docs
Feb 18, 2020
58e8862
update filter docs
Feb 18, 2020
578d444
lint
Feb 18, 2020
31a1d9c
docs
Feb 18, 2020
368069d
move files around
Feb 18, 2020
1b0e628
fix tests
Feb 18, 2020
c0f0a61
spread out theme
Feb 19, 2020
8d815fd
Update Heading Component
taylorcjohnson Mar 16, 2020
8ed569a
Update Heading component documentation
taylorcjohnson Mar 16, 2020
71f5c10
version 17
Mar 16, 2020
20584c1
Update Heading component TypeScript type definition
taylorcjohnson Mar 17, 2020
5d8db4d
fix focus management
Mar 19, 2020
c9b6b4f
add code comment
Mar 19, 2020
ae04253
fix filter background color
Mar 19, 2020
309584d
dont use ul
Mar 19, 2020
1c5a4fd
fix uncontrolled input error
Mar 19, 2020
17b715f
rearrange docs
Mar 19, 2020
eed0eae
Merge branch 'master' into select-menu
Mar 19, 2020
bcb1664
update border radius and focus color
Mar 19, 2020
17bef76
fix tab border radius
Mar 19, 2020
f3eda9b
Merge branch 'major' into patch-2
dcastil Mar 23, 2020
f76bfad
Dropdown refactor
Mar 24, 2020
8f5b237
update types
Mar 24, 2020
413eb17
Merge pull request #662 from dcastil/patch-2
Mar 25, 2020
4f67e44
remove outline
Mar 25, 2020
78e90ea
don't manage filter input value
Mar 25, 2020
63fb124
clean up some state
Mar 25, 2020
f356308
remove unneeded onchange
Mar 25, 2020
0e72654
make tabs more reusable
Mar 27, 2020
8c5805e
update docs
Mar 27, 2020
e095471
update docs
Mar 27, 2020
2cd5619
close menu when clicking on item
Mar 27, 2020
c0278b3
update docs
Mar 27, 2020
0da3c30
update tests
Mar 27, 2020
c038e01
tests
Mar 27, 2020
4a03f84
remove extra components
Mar 27, 2020
9817535
remove other components
Mar 27, 2020
e583321
update types
Mar 27, 2020
ba4aa9f
lint + skip failing tests for now
Mar 27, 2020
06b2463
update nav yml
Mar 27, 2020
f8ebf52
clean up some type definitions, add some comments
Mar 27, 2020
4e3ae6f
Update box shadow to match Primer CSS Next
colebemis Mar 27, 2020
f07eb1e
Update snapshots
colebemis Mar 30, 2020
ece599e
Extract Dialog header into separate component
BinaryMuse Mar 30, 2020
b97046e
Allow color and flex props to be set on Dialog.Header
BinaryMuse Mar 30, 2020
b866a9d
Drop Dialog.HeaderText
BinaryMuse Mar 30, 2020
795c3e8
Check for text children differently
BinaryMuse Mar 30, 2020
1faf1db
fix up MenuContext types
Mar 31, 2020
2c70bc5
omit as prop from select menu item
Mar 31, 2020
1235efd
move SelectMenu.Header out of modal
Mar 31, 2020
447c26d
remove filter prop from modal styles
Mar 31, 2020
2a1f757
clean up tab function
Mar 31, 2020
a2920d9
tweak filter docs
Mar 31, 2020
73d239b
add filter docs
Mar 31, 2020
9071bec
pass theme down
Mar 31, 2020
84f9c18
pass theme down
Mar 31, 2020
fdcdb22
tweak filter theme props
Mar 31, 2020
5738109
pass theme down in modal
Mar 31, 2020
3538187
Update src/SelectMenu/SelectMenuTabs.js
Mar 31, 2020
eb2022d
Update src/SelectMenu/hooks/KeyboardHook.js
Mar 31, 2020
f1e3ab5
props fix
Mar 31, 2020
dfa4238
lint
Mar 31, 2020
026005b
Merge branch 'master' into major
Mar 31, 2020
fed5694
Merge branch 'major' into select-menu
Mar 31, 2020
a2001f8
update snaps
Mar 31, 2020
350b74c
fix code examples
Mar 31, 2020
fdec085
update background color
Mar 31, 2020
fdbe53f
fix spacing
Mar 31, 2020
b94b0bc
rename keyboard nav hook file
Mar 31, 2020
8bb7892
move styles into component files
Mar 31, 2020
2c44f59
update keyboard hook to use state instead of dom attributes
Mar 31, 2020
2436836
Model WIP
BinaryMuse Mar 31, 2020
b260b42
Tweak Pagination model
BinaryMuse Mar 31, 2020
ddc309c
spread as out on select menu
Mar 31, 2020
e8dca25
test updates
Mar 31, 2020
93450ac
Add WIP Pagination component
BinaryMuse Mar 31, 2020
d24e744
Finish up base functionalty and styling
BinaryMuse Apr 1, 2020
cd141f7
Ensure breaks when margin is 0
BinaryMuse Apr 1, 2020
c800b51
Fix when last page isn't final page
BinaryMuse Apr 1, 2020
152ae81
:keyboard:
BinaryMuse Apr 1, 2020
361a999
Finish primary Pagination docs
BinaryMuse Apr 1, 2020
bb0bf78
Remove test for unwanted behavior
BinaryMuse Apr 1, 2020
c7122c5
test clicking on items works
Apr 1, 2020
d05bee6
Refactor theme
BinaryMuse Apr 1, 2020
42c31eb
Add props and theme info for Pagination
BinaryMuse Apr 1, 2020
c0dc5fb
Fill out types and props
BinaryMuse Apr 1, 2020
e712849
Update tests and lint
BinaryMuse Apr 1, 2020
94a6d31
Update snapshot from theme changes
BinaryMuse Apr 1, 2020
8f6013c
update "as" test, fix theme errors
Apr 1, 2020
96d3309
lint
Apr 1, 2020
33eb7d3
Remove Set usage
BinaryMuse Apr 1, 2020
7eb1592
Add TS TypeDoc comments for some props
BinaryMuse Apr 1, 2020
b5a24ad
Remove old default DialogHeader flex props
BinaryMuse Apr 1, 2020
2b32cf6
No Array.prototype.entries in IE
BinaryMuse Apr 1, 2020
d3ded89
Base Pagination font size on theme
BinaryMuse Apr 1, 2020
5e0fa02
wordsing
BinaryMuse Apr 1, 2020
eadc341
Update snapshots from theme change
BinaryMuse Apr 1, 2020
b8b43cf
Merge pull request #732 from primer/update-box-shadow
Apr 1, 2020
7b9e94c
Fixes to Dialog.Header props
BinaryMuse Apr 1, 2020
6b11b9a
Update Heading component tests
taylorcjohnson Apr 1, 2020
cc0dde3
update type
Apr 1, 2020
1c73597
Merge remote-tracking branch 'origin/major' into mkt/pagination-compo…
BinaryMuse Apr 1, 2020
be6ed30
Merge pull request #736 from primer/mkt/dialog-header-extraction
Apr 1, 2020
f58e2d7
Fix tests and snapshots
BinaryMuse Apr 1, 2020
bb9c5ed
Remove unused variable
BinaryMuse Apr 1, 2020
65c8038
update direction docs and type
Apr 1, 2020
98af424
Merge branch 'taylorcjohnson-heading-update' of https://github.com/ta…
BinaryMuse Apr 1, 2020
ec9d169
switch styling order of dropdown
Apr 1, 2020
4446796
Update test snapshots
BinaryMuse Apr 1, 2020
fbd493f
Fix lint
BinaryMuse Apr 1, 2020
ba41cd4
Merge remote-tracking branch 'origin/major' into mkt/pagination-compo…
BinaryMuse Apr 1, 2020
95acd04
Merge pull request #739 from primer/mkt/pagination-component
Apr 1, 2020
5dcf00d
whoops
Apr 1, 2020
6523bd2
let user manage open state
Apr 1, 2020
c7e86bc
call users onToggle
Apr 1, 2020
45f4102
update details docs
Apr 1, 2020
a25fa3d
update type
Apr 1, 2020
6f468b7
change docs
Apr 1, 2020
8cea74e
typos
Apr 1, 2020
51b9736
update prop types on Dropdown
Apr 1, 2020
8223f35
add open prop to dropdown
Apr 1, 2020
34419f8
docs updates again
Apr 1, 2020
b233d3b
lint
Apr 1, 2020
38e61f6
refactor once more
Apr 2, 2020
9461b18
docs updates
Apr 2, 2020
e86583c
update type
Apr 2, 2020
914a2a1
chnage type
Apr 2, 2020
f386962
Update index.d.ts
Apr 2, 2020
539905a
Merge branch 'major' into dropdown-refactor
Apr 2, 2020
879c8b5
lint
Apr 2, 2020
0fcd12c
open tweak
Apr 2, 2020
05174f5
Update SelectMenu.js
Apr 2, 2020
573f5d1
removed unused snapshot
Apr 2, 2020
546021c
Merge pull request #729 from primer/dropdown-refactor
Apr 2, 2020
559af65
Update tests so theme isn't included in snapshots
BinaryMuse Apr 2, 2020
786fbc1
Merge pull request #740 from primer/mkt/no-theme-in-snapshots
Apr 2, 2020
364cf60
Merge branch 'major' into select-menu
Apr 2, 2020
47dbde9
Merge pull request #600 from primer/select-menu
Apr 2, 2020
6cf5046
add missing header type
Apr 2, 2020
adc5d2e
Merge pull request #741 from primer/type-tweaks
Apr 2, 2020
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
2 changes: 2 additions & 0 deletions docs/content/Buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ To create a button group, wrap `Button` elements in the `ButtonGroup` element. `
<Button>Button</Button>
<Button>Button</Button>
</ButtonGroup>

<ButtonTableList>Button Table List </ButtonTableList>
```

## System props
Expand Down
27 changes: 26 additions & 1 deletion docs/content/Details.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ You are responsible for rendering your own `<summary>`. To style your summary el
<Button as="summary">Click me</Button>
<p>This should show and hide</p>
</Details>

```

## With children as a function
Expand All @@ -34,6 +35,27 @@ The render function gets an object with the `open` render prop to allow you to c
</Details>
```

## Manage the open state manually
The `Details` element is built to also let you manage the open state and toggle functionality if necessary. Just provide values to the `open` and `onToggle` props.

**Note:** The `overlay` prop will not function automatically if you chose to provide your own `open` state. You'll need to implement this yourself. You can use the `onClickOutside` prop to implement and customize this behavior.

```jsx live
<State default={false}>
{([open, setOpen]) => {
const handleToggle = (e) => setOpen(e.target.open)
const handleClickOutside = () => setOpen(false)

return (
<Details open={open} onToggle={handleToggle} onClickOutside={handleClickOutside} overlay>
<Button as="summary">Click me</Button>
<p>This should show and hide</p>
</Details>
)
}}
</State>
```

## System props

Details components get `COMMON` system props. Read our [System Props](/system-props) doc page for a full list of available props.
Expand All @@ -43,4 +65,7 @@ Details components get `COMMON` system props. Read our [System Props](/system-pr
| Name | Type | Default | Description |
| :- | :- | :-: | :- |
| defaultOpen | Boolean | | Sets the initial open/closed state |
| overlay | Boolean | false | Sets whether or not element will close when user clicks outside of it
| overlay | Boolean | false | Sets whether or not element will close when user clicks outside of it |
| open | Boolean | | Use the open prop if you'd like to manage the open state |
| onToggle | Function | | Called whenever user clicks on `summary` element. If you are controlling your own `open` state this will be the only function called on click, otherwise it's called before the internal `handleToggle` function.|
| onClickOutside | Function | | Function to call whenever user clicks outside of the Details component. This is optional and only necessary if you are controlling your own `open` state. |
73 changes: 67 additions & 6 deletions docs/content/Dropdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ title: Dropdown
---
The Dropdown component is a lightweight context menu for housing navigation and actions.

Use `Dropdown.Button` as the trigger for the dropdown, or use a custom `summary` element if you would like. **You must use a `summary` tag in order for the dropdown to behave properly!**. You should also add `aria-haspopup="true"` to custom dropdown triggers for accessibility purposes. You can use the `Dropdown.Caret` component to add a caret to a custom dropdown trigger.

Dropdown.Menu wraps your menu content. Be sure to pass a `direction` prop to this component to position the menu in relation to the Dropdown.Button.

## Default example
```jsx live
<Dropdown title="Dropdown">
<Dropdown direction='w'>
<Dropdown.Button>Dropdown</Dropdown.Button>
<Dropdown.Menu direction='sw'>
<Dropdown.Item>Item 1</Dropdown.Item>
<Dropdown.Item>Item 2</Dropdown.Item>
Expand All @@ -16,20 +19,78 @@ Dropdown.Menu wraps your menu content. Be sure to pass a `direction` prop to thi
</Dropdown>
```

## With custom button
```jsx live
<Dropdown>
<summary>
Dropdown
<Dropdown.Caret/>
</summary>
<Dropdown.Menu direction='sw'>
<Dropdown.Item>Item 1</Dropdown.Item>
<Dropdown.Item>Item 2</Dropdown.Item>
<Dropdown.Item>Item 3</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
```

## Manage the open state manually
The `Dropdown` element is built to also let you manage the open state and toggle functionality if necessary. Just provide values to the `open` and `onToggle` props.

**Note:** Closing the dropdown on outside clicks will not function automatically if you chose to provide your own `open` state. You'll need to implement this yourself. You can use the `onClickOutside` prop to implement and customize this behavior.

```jsx live
<State default={false}>
{([open, setOpen]) => {

const handleToggle = (e) => setOpen(e.target.open)
const handleClickOutside = () => setOpen(false)

return (
<Dropdown open={open} onToggle={handleToggle} onClickOutside={handleClickOutside}>
<Dropdown.Button>Dropdown</Dropdown.Button>
<Dropdown.Menu direction='sw'>
<Dropdown.Item>Item 1</Dropdown.Item>
<Dropdown.Item>Item 2</Dropdown.Item>
<Dropdown.Item>Item 3</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
)
}}
</State>
```

## System props

Dropdown, Dropdown.Menu, and Dropdown.Item all get `COMMON` system props. Read our [System Props](/system-props) doc page for a full list of available props.
Dropdown, Dropdown.Menu, Dropdown.Button, Dropdown.Caret, and Dropdown.Item all get `COMMON` system props. Read our [System Props](/system-props) doc page for a full list of available props.

## Component props

The Dropdown component is extended from the [`Details`](/Details) component and gets all props that the [`Details`](/Details) component gets. They are listed below, but you may reference the [`Details`](/Details) docs for more details on how to manage your own `open` state.

#### Dropdown
| Name | Type | Default | Description |
| :- | :- | :-: | :- |
| defaultOpen | Boolean | | Sets the initial open/closed state |
| overlay | Boolean | false | Sets whether or not element will close when user clicks outside of it |
| open | Boolean | | Use the open prop if you'd like to manage the open state |
| onToggle | Function | | Called whenever user clicks on `summary` element. If you are controlling your own `open` state this will be the only function called on click, otherwise it's called before the internal `handleToggle` function.|
| onClickOutside | Function | | Function to call whenever user clicks outside of the Details component. This is optional and only necessary if you are controlling your own `open` state. |



#### Dropdown.Menu
| Name | Type | Default | Description |
| :- | :- | :-: | :- |
| direction | String | 'sw' | Sets the direction of the dropdown menu. |
| title | String or Node | | Sets the text inside of the button, can be either a string or a React node |
| direction | String | 'sw' | Sets the direction of the dropdown menu. Pick from 'ne', 'e', 'se', 's', 'sw', or 'w' |

#### Dropdown.Item
#### Dropdown.Button
| Name | Type | Default | Description |
| :- | :- | :-: | :- |
| onClick | Function | none | Use the `onClick` handler to add additional functionality when the button is clicked, such as fetching data. |

#### Dropdown.Caret
No additional props.

#### Dropdown
#### Dropdown.Item
No additional props.
194 changes: 194 additions & 0 deletions docs/content/Pagination.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
---
title: Pagination
---
import State from '../components/State'

Use the pagination component to create a connected set of links that lead to related pages (for example, previous, next, or page numbers).

## Basic example

The pagination component only requires two properties to render: `pageCount`, which is the total number of pages, and `currentPage`, which is the currently selected page number (which should be managed by the consuming application).

```jsx live
<Pagination
pageCount={15}
currentPage={2}
onPageChange={e => e.preventDefault()}
/>
```

However, to handle state changes when the user clicks a page, you also need to pass `onPageChange`, which is a function that takes a click event and page number as an argument:

```javascript
type PageChangeCallback = (evt: React.MouseEvent, page: number) => void
```

By default, clicking a link in the pagination component will cause the browser to navigate to the URL specified by the page. To cancel navigation and handle state management on your own, you should call `preventDefault` on the event, as in this example:

```jsx live
<State default={1}>
{([page, setPage]) => {
const totalPages = 15
const onPageChange = (evt, page) => {
evt.preventDefault()
setPage(page)
}

return (
<BorderBox p={2}>
<Box>Current page: {page} / {totalPages}</Box>
<Pagination
pageCount={totalPages}
currentPage={page}
onPageChange={onPageChange}
/>
</BorderBox>
)
}}
</State>
```

## Customizing link URLs

To customize the URL generated for each link, you can pass a function to the `hrefBuilder` property. The function should take a page number as an argument and return a URL to use for the link.

```javascript
type HrefBuilder = (page: number) => string
```

```jsx live
<State default={'(nothing clicked yet)'}>
{([lastUrl, setLastUrl]) => {
const onPageChange = (evt, page) => {
evt.preventDefault()
setLastUrl(evt.target.href)
}
const hrefBuilder = (page) => {
return `https://example.com/pages/${page}`
}

return (
<BorderBox p={2}>
<Box>The last URL clicked was: {lastUrl}</Box>
<Pagination
pageCount={15}
currentPage={2}
onPageChange={onPageChange}
hrefBuilder={hrefBuilder}
/>
</BorderBox>
)
}}
</State>
```

## Customizing which pages are shown

Two props control how many links are displayed in the pagination container at any given time. `marginPageCount` controls how many pages are guaranteed to be displayed on the left and right of the component; `surroundingPageCount` controls how many pages will be displayed to the left and right of the current page.

```jsx live
<Pagination
pageCount={20}
currentPage={10}
marginPageCount={1}
surroundingPageCount={2}
onPageChange={e => e.preventDefault()}
/>
```

The algorithm tries to minimize the amount the component shrinks and grows as the user changes pages; for this reason, if any of the pages in the margin (controlled via `marginPageCount`) intersect with pages in the center (controlled by `surroundingPageCount`), the center section will be shifted away from the margin. Consider the following examples, where pages one through six are shown when any of the first four pages are selected. Only when the fifth page is selected and there is a gap between the margin pages and the center pages does a break element appear.

```jsx live
<Box>
{[1, 2, 3, 4, 5].map(page => (
<Pagination
pageCount={20}
currentPage={page}
marginPageCount={1}
surroundingPageCount={2}
onPageChange={e => e.preventDefault()}
/>
))}
</Box>
```

### Previous/next pagination

To hide all the page numbers and create a simple pagination container with just the Previous and Next buttons, set `showPages` to `false`.

```jsx live
<State default={1}>
{([page, setPage]) => {
const totalPages = 10
const onPageChange = (evt, page) => {
evt.preventDefault()
setPage(page)
}

return (
<BorderBox p={2}>
<Box>Current page: {page} / {totalPages}</Box>
<Pagination
pageCount={totalPages}
currentPage={page}
onPageChange={onPageChange}
showPages={false}
/>
</BorderBox>
)
}}
</State>
```

## System props

Pagination components get `COMMON` system props. Read our [System Props](/system-props) doc page for a full list of available props.

## Component props

| Name | Type | Default | Description |
| :- | :- | :-: | :- |
| currentPage | Number | | **Required.** The currently selected page. |
| hrefBuilder | Function | `#${page}` | A function to generate links based on page number. |
| marginPageCount | Number | 1 | How many pages to always show at the left and right of the component. |
| onPageChange | Function | no-op | Called with event and page number when a page is clicked. |
| pageCount | Number | | **Required.** The total number of pages. |
| showPages | Boolean | `true` | Whether or not to show the individual page links. |
| surroundingPageCount | Number | 2 | How many pages to display on each side of the currently selected page. |

## Theming

The following snippet shows the properties in the theme that control the styling of the pagination component:

```javascript
{
// ... rest of theme ...
pagination: {
fontSize,
fontWeight,
borderRadius,
colors: {
normal: {
fg,
bg,
border
},
disabled: {
fg,
bg,
border
},
hover: {
fg,
bg,
border
},
selected: {
fg,
bg,
border
}
}
}
}
```
Loading