-
Notifications
You must be signed in to change notification settings - Fork 10
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
Showing
12 changed files
with
303 additions
and
113 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
"@marigold/components": patch | ||
"@marigold/types": patch | ||
--- | ||
|
||
feat(compoents): Make `<Text>` and `<Link>` polymorphic | ||
|
||
**`<Text>`** | ||
- the `as` prop supports arbitrary inputs | ||
- supporst ref | ||
- supports style props (text-align, color, cursor, user-select) | ||
|
||
**`<Link>`** | ||
- the `as` prop supports arbitrary inputs | ||
- does not support `ref`! | ||
- improved accessibility (react-aria) |
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
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,17 +1,32 @@ | ||
import React from 'react'; | ||
import { ComponentProps } from '@marigold/types'; | ||
import { Box } from '../Box'; | ||
import React, { useRef } from 'react'; | ||
import { useLink } from '@react-aria/link'; | ||
import { PolymorphicComponent, PolymorphicProps } from '@marigold/types'; | ||
|
||
export type LinkProps = { | ||
variant?: string; | ||
} & ComponentProps<'a'>; | ||
import { Text, TextOwnProps } from '../Text'; | ||
|
||
export const Link: React.FC<LinkProps> = ({ | ||
variant = 'normal', | ||
export type LinkOwnProps = { disabled?: boolean } & TextOwnProps; | ||
export type LinkProps = PolymorphicProps<LinkOwnProps, 'a'>; | ||
|
||
export const Link = (({ | ||
as = 'a', | ||
variant = 'link', | ||
children, | ||
disabled, | ||
...props | ||
}) => ( | ||
<Box {...props} as="a" variant={`link.${variant}`}> | ||
{children} | ||
</Box> | ||
); | ||
}: LinkProps) => { | ||
const ref = useRef<any>(); | ||
const { linkProps } = useLink( | ||
{ | ||
...props, | ||
elementType: typeof as === 'string' ? as : 'span', | ||
isDisabled: disabled, | ||
}, | ||
ref | ||
); | ||
|
||
return ( | ||
<Text {...props} {...linkProps} as={as} variant={variant} ref={ref}> | ||
{children} | ||
</Text> | ||
); | ||
}) as PolymorphicComponent<LinkOwnProps, 'a'>; |
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.
b6614f1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: