Links are used as navigational elements and can be used on their own or inline with text.
Usage Guidelines
When to use
Use links when you want users to:
- Navigate to a different page within the application
- Navigate to an entirely different site
- Jump to an element on the same page
- Link to emails or phone numbers
When not to use
Use a button instead of a link for actions that will change data or manipulate how it is displayed, change a state, or trigger an action. Buttons should never be used for navigational actions. See button docs for further information.
Basic Usage
Links provide a lightweight option for navigation but like other interactive elements, too many links will clutter a page and make it difficult for users to identify their next steps. This is especially true for inline links, which should be used sparingly.
import React from 'react';import { Hyperlink } from 'react-magma-dom';export function Example() {return (<Hyperlink target="_blank" to="https://www.google.com"></Hyperlink>);}
StyledAs
Sometimes links can be styled as buttons in order to give them more weight on the page, but this is only on the surface. Underneath the styles, they are still a link component. The styledAs
prop can be used to style the Hyperlink
component as another component. The options are Link
(default) and Button
.
import React from 'react';import {ButtonColor,ButtonTextTransform,Hyperlink,Spacer,SpacerAxis,} from 'react-magma-dom';export function Example() {return (<><HyperlinktextTransform={ButtonTextTransform.none}styledAs="Button"target="_blank"to="https://www.google.com"></Hyperlink><Spacer size="8" axis={SpacerAxis.horizontal} /><Hyperlinkcolor={ButtonColor.secondary}textTransform={ButtonTextTransform.none}styledAs="Button"target="_blank"to="https://www.google.com"></Hyperlink><Spacer size="8" axis={SpacerAxis.horizontal} /><Hyperlinkcolor={ButtonColor.danger}styledAs="Button"target="_blank"to="https://www.google.com"></Hyperlink><Spacer size="8" axis={SpacerAxis.horizontal} /><Hyperlinkcolor={ButtonColor.marketing}styledAs="Button"target="_blank"to="https://www.google.com"></Hyperlink></>);}
Icon
import React from 'react';import {Hyperlink,HyperlinkIconPosition,magma,Spacer,SpacerAxis,Paragraph,Flex,FlexBehavior,FlexJustify,TypographyVisualStyle,} from 'react-magma-dom';import {KeyboardArrowLeftIcon,KeyboardArrowRightIcon,CalendarTodayIcon,OpenInNewIcon,} from 'react-magma-icons';export function Example() {return (<><Flexbehavior={FlexBehavior.container}justify={FlexJustify.spaceBetween}><span style={{ flex: '0 0 auto' }}><Hyperlinktarget="_blank"to="./"hasUnderline={false}icon={<KeyboardArrowLeftIcon aria-hidden />}iconPosition={HyperlinkIconPosition.left}>Back</Hyperlink></span><span style={{ flex: '0 0 auto' }}><Hyperlinktarget="_blank"to="./"hasUnderline={false}icon={<KeyboardArrowRightIcon aria-hidden />}iconPosition={HyperlinkIconPosition.right}>Next</Hyperlink></span></Flex><Spacer size={'8px'} axis={SpacerAxis.both} /><HyperlinkstyledAs="Button"target="_blank"to="./"icon={<KeyboardArrowLeftIcon aria-hidden />}iconPosition={HyperlinkIconPosition.left}>Back</Hyperlink><Spacer size={'8px'} axis={SpacerAxis.horizontal} /><HyperlinkstyledAs="Button"target="_blank"to="./"icon={[<KeyboardArrowLeftIcon aria-hidden key={0} />,<KeyboardArrowRightIcon aria-hidden key={1} />,]}iconPosition={HyperlinkIconPosition.both}>Guess</Hyperlink><Spacer size={'8px'} axis={SpacerAxis.horizontal} /><HyperlinkstyledAs="Button"target="_blank"to="./"icon={<KeyboardArrowRightIcon aria-hidden />}iconPosition={HyperlinkIconPosition.right}>Next</Hyperlink><Spacer size={'8px'} axis={SpacerAxis.both} /><Paragraph visualStyle={TypographyVisualStyle.headingSmall}><Hyperlinktarget="_blank"to="https://www.google.com"hasUnderline={false}icon={[<CalendarTodayIconkey={0}size={magma.iconSizes.xLarge}style={{ marginRight: magma.spaceScale.spacing03 }}aria-hidden/>,<OpenInNewIconkey={1}size={magma.iconSizes.xLarge}style={{ marginLeft: magma.spaceScale.spacing03 }}aria-hidden/>,]}iconPosition={HyperlinkIconPosition.both}>Schedule an appointment</Hyperlink></Paragraph><Paragraph visualStyle={TypographyVisualStyle.bodyLarge}><Hyperlinktarget="_blank"to="https://www.google.com"hasUnderline={false}icon={[<CalendarTodayIconkey={0}size={magma.iconSizes.large}aria-hidden/>,<OpenInNewIcon key={1} size={magma.iconSizes.large} aria-hidden />,]}iconPosition={HyperlinkIconPosition.both}>Schedule an appointment</Hyperlink></Paragraph><Paragraph visualStyle={TypographyVisualStyle.bodySmall}><Hyperlinktarget="_blank"to="https://www.google.com"hasUnderline={false}icon={[<CalendarTodayIconkey={0}size={magma.iconSizes.small}aria-hidden/>,<OpenInNewIcon key={1} size={magma.iconSizes.small} aria-hidden />,]}iconPosition={HyperlinkIconPosition.both}>Schedule an appointment</Hyperlink></Paragraph><Paragraph visualStyle={TypographyVisualStyle.bodyXSmall}><Hyperlinktarget="_blank"to="https://www.google.com"hasUnderline={false}icon={[<CalendarTodayIconkey={0}size={magma.iconSizes.xSmall}aria-hidden/>,<OpenInNewIcon key={1} size={magma.iconSizes.xSmall} aria-hidden />,]}iconPosition={HyperlinkIconPosition.both}>Schedule an appointment</Hyperlink></Paragraph></>);}
hasUnderline
The underline text decoration can be turned off. When a hyperlink is used within other elements like paragraphs, the underline is still mandatory.
import React from 'react';import {Hyperlink,Spacer,SpacerAxis,magma,HyperlinkIconPosition,} from 'react-magma-dom';import { OpenInNewIcon } from 'react-magma-icons';export function Example() {return (<><Hyperlinktarget="_blank"to="https://www.google.com"hasUnderline={false}></Hyperlink><Spacer size={'8px'} axis={SpacerAxis.both} />Cupcake ipsum dolor sit amet wafer biscuit toffee. Chocolate bar brownielemon drops tootsie roll pudding muffin powder pudding.{' '}<Hyperlinktarget="_blank"to="https://sallysbakingaddiction.com/triple-chocolate-layer-cake/"icon={<OpenInNewIcon size={magma.iconSizes.small} aria-hidden />}iconPosition={HyperlinkIconPosition.right}>I love chocolate cake</Hyperlink>{' '}Pastry dragée cheesecake chocolate bar donut jujubes candy canes sugarplum bonbon. Toffee pie macaroon apple pie gummi bears gummi bearsshortbread.</>);}
Render Props Usage
Use this when you want to render something that is from another library. For example, the Link
component from react-router
.
import React from 'react';import { Hyperlink } from 'react-magma-dom';// We support Link components from libraries such as react-router/reach-router/gatsby that use the `to` prop in place of `href`const Link = ({ to, ...rest }) => <a href={to} {...rest} />;export function Example() {return (<Hyperlink styledAs="Button" to="./">{linkProps => <Link {...linkProps}>Render Props Google</Link>}</Hyperlink>);}
Inverse
isInverse
is an optional boolean prop, that may be passed in when the hyperlink is to be displayed on a dark background.
import React from 'react';import { Card, CardBody, Hyperlink, Paragraph } from 'react-magma-dom';export function Example() {return (<Card isInverse><CardBody><Paragraph><Hyperlink isInverse target="_blank" to="https://www.google.com">Google inverse link</Hyperlink></Paragraph><HyperlinkisInversestyledAs="Button"target="_blank"to="https://www.google.com">Inverse link styled as button</Hyperlink></CardBody></Card>);}
Hyperlink Props
This component uses forwardRef
. The ref is applied to the a
element.
All of the standard anchor attributes can be provided as props and will be applied to the a
element that gets rendered.
children
Description
The content of the component
Type
React.ReactNode
Default
-
color
Description
The color of the button, indicating its function in the UI
Type
enum, one of:
ButtonColor.danger
ButtonColor.marketing
ButtonColor.primary
ButtonColor.secondary
ButtonColor.subtle
ButtonColor.success
Default
ButtonColor.primary
hasUnderline
Type
boolean
Default
-
icon
Description
Icon to display within the component
Type
ReactElement | Array
Default
-
iconPosition
Description
Position within the link for the icon to appear
Type
enum, one of:
HyperlinkIconPosition.both
HyperlinkIconPosition.left
HyperlinkIconPosition.right
Default
HyperlinkIconPosition.right
isFullWidth
Description
Set the button to display full-width.
Type
boolean
Default
false
isInverse
Description
If true, the component will have inverse styling to better appear on a dark background
Type
boolean
Default
false
isLoading
Description
Set the button to a loading state
Type
boolean
Default
false
shape
Description
Defines the border radius
Type
enum, one of:
ButtonShape.fill
ButtonShape.leftCap
ButtonShape.rightCap
ButtonShape.round
Default
ButtonShape.fill
size
Description
The relative size of the button
Type
enum, one of:
ButtonSize.large
ButtonSize.medium
ButtonSize.small
Default
ButtonSize.medium
styledAs
Description
How the hyperlink is styled (can look like either a plain link or a button)
Type
|
Default
-
textTransform
Description
Determines whether the button appears in all-caps
Type
enum, one of:
ButtonTextTransform.none
ButtonTextTransform.uppercase
Default
ButtonTextTransform.uppercase
to
Description
The href value of the link
Type
string
Default
-
variant
Description
The variant of the button
Type
enum, one of:
ButtonVariant.link
ButtonVariant.solid
Default
ButtonVariant.solid
On this page