diff --git a/.changeset/pagination-anchor-links.md b/.changeset/pagination-anchor-links.md new file mode 100644 index 0000000000..99664f8913 --- /dev/null +++ b/.changeset/pagination-anchor-links.md @@ -0,0 +1,13 @@ +--- +"flowbite-react": minor +--- + +Add `getPageUrl` prop to Pagination for SEO-friendly anchor links + +### Changes + +- [x] add `getPageUrl` prop that renders pagination buttons as `` elements instead of ` ); @@ -50,34 +88,39 @@ export const PaginationButton = forwardRef - {children} - - ); -} +export const PaginationNavigation = forwardRef( + ({ children, className, disabled = false, theme: customTheme, clearTheme, applyTheme, ...props }, ref) => { + const provider = useThemeProvider(); + const theme = useResolveTheme( + [paginationTheme, provider.theme?.pagination, customTheme], + [get(provider.clearTheme, "pagination"), clearTheme], + [get(provider.applyTheme, "pagination"), applyTheme], + ); + + const mergedClassName = twMerge(disabled && theme.pages.selector.disabled, className); + + if ("href" in props && props.href && !disabled) { + const { href, ...anchorProps } = props; + return ( + } href={href} className={mergedClassName} {...anchorProps}> + {children} + + ); + } + + const { href: _, ...buttonProps } = props as PaginationNavigationAsButton; + return ( + + ); + }, +); PaginationNavigation.displayName = "PaginationNavigation";