-
Notifications
You must be signed in to change notification settings - Fork 111
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
0c1fc5b
commit 7b31422
Showing
11 changed files
with
72 additions
and
127 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 |
---|---|---|
|
@@ -3,3 +3,5 @@ import { Meta, Title } from '@storybook/blocks' | |
<Meta title='Foundations/Motion' /> | ||
|
||
<Title>Motion</Title> | ||
|
||
TODO |
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,38 +1,29 @@ | ||
import { useCallback, MouseEvent, ComponentPropsWithoutRef } from 'react' | ||
import type { ReactNode } from 'react' | ||
|
||
import cn from 'classnames' | ||
import LinkTo from '@storybook/addon-links/react' | ||
|
||
import { Text, TextProps } from '../../components/text' | ||
|
||
import styles from './Link.module.css' | ||
|
||
type LinkProps = TextProps & | ||
ComponentPropsWithoutRef<'a'> & { | ||
stopPropagation?: boolean | ||
} | ||
type LinkProps = { className?: string; children?: ReactNode } & ( | ||
| { href: string } | ||
| { kind: string; story: string } | ||
) | ||
|
||
export const Link = (props: LinkProps) => { | ||
const { | ||
className, | ||
onClick, | ||
stopPropagation = true, | ||
children, | ||
...other | ||
} = props | ||
const { className, children, ...other } = props | ||
|
||
const handleClick = useCallback( | ||
(e: MouseEvent<HTMLAnchorElement>) => { | ||
onClick?.(e) | ||
if (stopPropagation) { | ||
e.stopPropagation() | ||
} | ||
}, | ||
[onClick, stopPropagation] | ||
) | ||
if ('href' in other) { | ||
const { href } = other | ||
return ( | ||
<a className={className} href={href} target='_blank' rel='noreferrer'> | ||
{children} | ||
</a> | ||
) | ||
} | ||
|
||
const { kind, story } = other | ||
return ( | ||
<Text className={cn(styles.root, className)} {...other} asChild> | ||
<a onClick={handleClick}>{children}</a> | ||
</Text> | ||
// @ts-expect-error className is available | ||
<LinkTo className={className} kind={kind} story={story}> | ||
{children} | ||
</LinkTo> | ||
) | ||
} |
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
Oops, something went wrong.