-
Notifications
You must be signed in to change notification settings - Fork 364
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
1 parent
4998735
commit b365c6c
Showing
6 changed files
with
105 additions
and
34 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,45 @@ | ||
import { Link } from '@tanstack/react-router'; | ||
import { LinkComponent } from '@tanstack/react-router'; | ||
import { createLink } from '@tanstack/react-router'; | ||
import * as React from 'react'; | ||
|
||
import { Button } from 'src/components/Button/Button'; | ||
import { omitProps } from 'src/utilities/omittedProps'; | ||
|
||
import type { LinkProps } from '@tanstack/react-router'; | ||
import type { ButtonProps } from 'src/components/Button/Button'; | ||
import type { ButtonProps, ButtonType } from 'src/components/Button/Button'; | ||
|
||
export interface TanstackLinkProps extends LinkProps { | ||
buttonType: NonNullable<ButtonProps['buttonType']>; | ||
export interface TanstackLinkProps | ||
extends Omit<ButtonProps, 'buttonType' | 'href'> { | ||
linkType: 'link' | ButtonType; | ||
tooltipAnalyticsEvent?: (() => void) | undefined; | ||
tooltipText?: string; | ||
} | ||
|
||
export const TanstackLink = ({ | ||
buttonType, | ||
children, | ||
...linkProps | ||
}: TanstackLinkProps) => { | ||
const LinkComponent = React.forwardRef<HTMLButtonElement, TanstackLinkProps>( | ||
(props, ref) => { | ||
const _props = omitProps(props, ['linkType']); | ||
|
||
return <Button component="a" ref={ref} {..._props} />; | ||
} | ||
); | ||
|
||
const CreatedLinkComponent = createLink(LinkComponent); | ||
|
||
export const TanstackLink: LinkComponent<typeof LinkComponent> = (props) => { | ||
return ( | ||
<Link {...linkProps}> | ||
<Button buttonType={buttonType} component="span"> | ||
{typeof children === 'function' | ||
? children({ isActive: false, isTransitioning: false }) | ||
: children} | ||
</Button> | ||
</Link> | ||
<CreatedLinkComponent | ||
preload="intent" | ||
{...props} | ||
sx={(theme) => ({ | ||
...(props.linkType === 'link' && { | ||
'&:hover': { | ||
textDecoration: 'underline', | ||
}, | ||
fontFamily: theme.font.normal, | ||
fontSize: '0.875rem', | ||
minWidth: 'initial', | ||
padding: 0, | ||
}), | ||
})} | ||
/> | ||
); | ||
}; |
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