-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(web-react): Tablink and HeaderLink now accept a NextLink #DS-1018
- TabLink and HeaderLink now accept a NextLink and have forwardRef support
- Loading branch information
1 parent
c0ec4aa
commit bc3efbf
Showing
9 changed files
with
126 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,31 @@ | ||
import React from 'react'; | ||
import React, { ElementType, forwardRef } from 'react'; | ||
import classNames from 'classnames'; | ||
import { useStyleProps } from '../../hooks'; | ||
import { HeaderLinkProps } from '../../types'; | ||
import { PolymorphicRef, SpiritHeaderLinkProps } from '../../types'; | ||
import { useHeaderStyleProps } from './useHeaderStyleProps'; | ||
|
||
const HeaderLink = (props: HeaderLinkProps) => { | ||
const { children, isCurrent, ...restProps } = props; | ||
|
||
/* We need an exception for components exported with forwardRef */ | ||
/* eslint no-underscore-dangle: ['error', { allow: ['_HeaderLink'] }] */ | ||
const _HeaderLink = <E extends ElementType = 'a'>( | ||
props: SpiritHeaderLinkProps<E>, | ||
ref: PolymorphicRef<E>, | ||
): JSX.Element => { | ||
const { elementType: ElementTag = 'a', children, isCurrent, ...restProps } = props; | ||
const { classProps } = useHeaderStyleProps({ isCurrentLink: isCurrent }); | ||
const { styleProps, props: otherProps } = useStyleProps(restProps); | ||
|
||
return ( | ||
<a {...otherProps} className={classNames(classProps.headerLink, styleProps.className)} style={styleProps.style}> | ||
<ElementTag | ||
{...otherProps} | ||
className={classNames(classProps.headerLink, styleProps.className)} | ||
style={styleProps.style} | ||
ref={ref} | ||
> | ||
{children} | ||
</a> | ||
</ElementTag> | ||
); | ||
}; | ||
|
||
export const HeaderLink = forwardRef<HTMLAnchorElement, SpiritHeaderLinkProps<ElementType>>(_HeaderLink); | ||
|
||
export default HeaderLink; |
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
4 changes: 2 additions & 2 deletions
4
packages/web-react/src/components/Tabs/stories/TabLink.stories.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
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