-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
fix: pagination cleanup #359
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {style} from '@vanilla-extract/css'; | ||
|
||
export const pageItemButton = style({ | ||
transition: 'none', | ||
}); |
8 changes: 5 additions & 3 deletions
8
...ui/src/lib/primitives/Pagination/page.tsx → ...rc/lib/primitives/Pagination/PageItem.tsx
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,18 +1,20 @@ | ||
import {ParentProps} from 'solid-js'; | ||
import {IconButton} from '../IconButton'; | ||
import {buttonPaginationProps} from './buttons'; | ||
import {ButtonPaginationProps} from './createPaginationButtons'; | ||
import * as styles from './PageItem.css'; | ||
|
||
const Page = (props: ParentProps<buttonPaginationProps>) => { | ||
const PageItem = (props: ParentProps<ButtonPaginationProps>) => { | ||
return ( | ||
<IconButton | ||
theme={props.selected ? 'primary' : 'secondary'} | ||
as="li" | ||
pill | ||
class={styles.pageItemButton} | ||
onClick={() => props.onClick?.(props.value)} | ||
> | ||
{props.value} | ||
</IconButton> | ||
); | ||
}; | ||
|
||
export default Page; | ||
export default PageItem; |
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,7 @@ | ||
import {style} from '@vanilla-extract/css'; | ||
import {themeVars} from '../../theme'; | ||
|
||
export const pagination = style({ | ||
display: 'flex', | ||
gap: themeVars.spacing[2], | ||
}); | ||
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,54 +1,82 @@ | ||
import {For, mergeProps, ParentProps, Setter} from 'solid-js'; | ||
import {Box} from '../Box'; | ||
import {SvgIcon, SvgIconProps} from '../Icon'; | ||
import {IconButton} from '../IconButton'; | ||
import {createPaginationButtons} from './buttons'; | ||
import Page from './page'; | ||
import {createPaginationButtons} from './createPaginationButtons'; | ||
import PageItem from './PageItem'; | ||
import * as styles from './Pagination.css'; | ||
|
||
export interface PaginationProps { | ||
pageNumber?: number; | ||
onChange: Setter<number>; | ||
lastPage?: number; | ||
} | ||
|
||
function NextIcon(props: SvgIconProps) { | ||
return ( | ||
<SvgIcon | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke-width="1.5" | ||
stroke="currentColor" | ||
{...props} | ||
> | ||
<path | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
d="M8.25 4.5l7.5 7.5-7.5 7.5" | ||
/> | ||
</SvgIcon> | ||
); | ||
} | ||
|
||
function PrevIcon(props: SvgIconProps) { | ||
return ( | ||
<SvgIcon | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke-width="1.5" | ||
stroke="currentColor" | ||
{...props} | ||
> | ||
<path | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
d="M15.75 19.5L8.25 12l7.5-7.5" | ||
/> | ||
</SvgIcon> | ||
); | ||
} | ||
|
||
export const Pagination = (props: ParentProps<PaginationProps>) => { | ||
const merged = mergeProps( | ||
{pageNumber: 1, lastPage: 1} as Required<PaginationProps>, | ||
props, | ||
); | ||
|
||
const itemButtons = createPaginationButtons( | ||
() => merged.lastPage, | ||
() => merged.pageNumber, | ||
page => props.onChange(page), | ||
false, | ||
); | ||
|
||
const handlerNextChange = () => { | ||
merged.onChange(prev => prev + 1); | ||
}; | ||
const isPrevDisabled = () => merged.pageNumber === 1; | ||
const isNextDisabled = () => merged.pageNumber === merged.lastPage; | ||
|
||
const handlerPrevChange = () => { | ||
merged.onChange(prev => prev - 1); | ||
}; | ||
const handlerNextChange = () => merged.onChange(prev => prev + 1); | ||
const handlerPrevChange = () => merged.onChange(prev => prev - 1); | ||
|
||
return ( | ||
<Box display="flex" flexDirection="column" placeItems="center"> | ||
<Box display="flex" gap="2"> | ||
<IconButton | ||
onClick={handlerNextChange} | ||
pill | ||
disabled={merged.pageNumber === 1} | ||
> | ||
{'<'} | ||
</IconButton> | ||
<For each={itemButtons()}>{page => <Page {...page} />}</For> | ||
<IconButton | ||
onclick={handlerPrevChange} | ||
pill | ||
disabled={merged.pageNumber === merged.lastPage} | ||
> | ||
{'>'} | ||
</IconButton> | ||
</Box> | ||
</Box> | ||
<div class={styles.pagination}> | ||
<IconButton pill disabled={isPrevDisabled()} onClick={handlerPrevChange}> | ||
<PrevIcon /> | ||
</IconButton> | ||
<For each={itemButtons()}> | ||
{pageItemProps => <PageItem {...pageItemProps} />} | ||
</For> | ||
<IconButton pill disabled={isNextDisabled()} onClick={handlerNextChange}> | ||
<NextIcon /> | ||
</IconButton> | ||
</div> | ||
); | ||
}; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@riccardoperra perchè usare custom css quando abbiamo il box che settando le giuste properties otteniamo le stesse cose?