-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
117 additions
and
63 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
packages/chakra-components/src/components/Pagination/EllipsisButton.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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useState } from 'react' | ||
import { useStyleConfig } from '@chakra-ui/system' | ||
import { Button, ButtonProps, Input, InputProps } from '@chakra-ui/react' | ||
|
||
type EllipsisButtonProps = ButtonProps & { | ||
gotoPage: (page: number) => void | ||
inputProps?: InputProps | ||
} | ||
|
||
export const EllipsisButton = ({ gotoPage, inputProps, ...rest }: EllipsisButtonProps) => { | ||
const [ellipsisInput, setEllipsisInput] = useState(false) | ||
const styles = useStyleConfig('EllipsisButton', rest) | ||
|
||
if (ellipsisInput) { | ||
return ( | ||
<Input | ||
placeholder='Page #' | ||
width='50px' | ||
sx={styles} | ||
{...inputProps} | ||
onKeyDown={(e) => { | ||
if (e.target instanceof HTMLInputElement && e.key === 'Enter') { | ||
const pageNumber = Number(e.target.value) | ||
gotoPage(pageNumber) | ||
setEllipsisInput(false) | ||
} | ||
}} | ||
onBlur={() => setEllipsisInput(false)} | ||
autoFocus | ||
/> | ||
) | ||
} | ||
|
||
return ( | ||
<Button | ||
as='a' | ||
href='#goto-page' | ||
sx={styles} | ||
{...rest} | ||
onClick={(e) => { | ||
e.preventDefault() | ||
setEllipsisInput(true) | ||
}} | ||
> | ||
... | ||
</Button> | ||
) | ||
} |
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
7 changes: 7 additions & 0 deletions
7
packages/chakra-components/src/components/Pagination/PaginatorButton.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useStyleConfig } from '@chakra-ui/system' | ||
import { Button, ButtonProps, forwardRef } from '@chakra-ui/react' | ||
|
||
export const PaginatorButton = forwardRef<ButtonProps, 'div'>((props, ref) => { | ||
const styles = useStyleConfig('PageButton', props) | ||
return <Button sx={styles} {...props} /> | ||
}) |
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 @@ | ||
export * from './Pagination' |
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,24 @@ | ||
import { createMultiStyleConfigHelpers } from '@chakra-ui/styled-system' | ||
|
||
export const PaginationAnatomy = [ | ||
// Top level wrapper | ||
'wrapper', | ||
// wrapper for buttons | ||
'buttonGroup', | ||
// total results text | ||
'totalResults', | ||
] | ||
|
||
const { defineMultiStyleConfig: defineVoteWeightTipStyle, definePartsStyle: defineVoteWeightParts } = | ||
createMultiStyleConfigHelpers(PaginationAnatomy) | ||
|
||
export const PaginationTheme = defineVoteWeightTipStyle({ | ||
baseStyle: defineVoteWeightParts({ | ||
wrapper: {}, | ||
buttonGroup: { | ||
flexWrap: 'wrap', | ||
rowGap: '2', | ||
}, | ||
totalResults: {}, | ||
}), | ||
}) |