cal/components/ActiveLink.tsx
nicolas ebc42f0c96 Merge branch 'main' into feature/zoom-integration
# Conflicts:
#	lib/calendarClient.ts
#	lib/emails/new-event.ts
#	pages/[user]/book.tsx
#	pages/api/availability/[user].ts
#	pages/api/book/[user].ts
#	pages/integrations/index.tsx
2021-06-20 16:37:51 +02:00

22 lines
630 B
TypeScript

import {useRouter} from 'next/router'
import Link from 'next/link'
import React, {Children} from 'react'
const ActiveLink = ({ children, activeClassName, ...props }) => {
const { asPath } = useRouter()
const child = Children.only(children)
const childClassName = child.props.className || ''
const className =
asPath === props.href || asPath === props.as
? `${childClassName} ${activeClassName}`.trim()
: childClassName
return <Link {...props}>{React.cloneElement(child, { className })}</Link>;
}
ActiveLink.defaultProps = {
activeClassName: 'active'
} as Partial<Props>
export default ActiveLink