-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add LinkButton component, update FeaturedLink usage in PricingC…
…ards
- Loading branch information
1 parent
581566e
commit 92db0e0
Showing
7 changed files
with
173 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from "react"; | ||
import { | ||
ButtonPropsBase, | ||
commonButtonInterior, | ||
commonButtonProps, | ||
} from "./Button"; | ||
import cn from "./utils/cn"; | ||
|
||
export type LinkButtonProps = ButtonPropsBase & { | ||
disabled?: boolean; | ||
onClick?: (event: React.MouseEvent<HTMLAnchorElement>) => void; | ||
} & React.AnchorHTMLAttributes<HTMLAnchorElement>; | ||
|
||
const LinkButton: React.FC<LinkButtonProps> = ({ | ||
variant = "primary", | ||
size, | ||
leftIcon, | ||
rightIcon, | ||
children, | ||
className, | ||
disabled, | ||
onClick, | ||
...rest | ||
}) => { | ||
const handleClick = (e: React.MouseEvent<HTMLAnchorElement>) => { | ||
if (disabled) { | ||
e.preventDefault(); | ||
return; | ||
} | ||
onClick?.(e); | ||
}; | ||
|
||
return ( | ||
<a | ||
{...commonButtonProps({ | ||
variant, | ||
size, | ||
leftIcon, | ||
rightIcon, | ||
className: cn(className, { | ||
"ui-button-disabled dark:ui-button-disabled-dark": disabled, | ||
}), | ||
})} | ||
role="button" | ||
aria-disabled={disabled} | ||
onClick={handleClick} | ||
{...(rest as React.AnchorHTMLAttributes<HTMLAnchorElement>)} | ||
> | ||
{commonButtonInterior({ leftIcon, rightIcon, children })} | ||
</a> | ||
); | ||
}; | ||
|
||
export default LinkButton; |
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,40 @@ | ||
import React from "react"; | ||
import { Meta, StoryFn } from "@storybook/react"; | ||
import LinkButton, { LinkButtonProps } from "../LinkButton"; | ||
|
||
export default { | ||
title: "Components/Link Button", | ||
component: LinkButton, | ||
parameters: { | ||
docs: { | ||
description: { | ||
component: | ||
"A variant of the `Button` component that renders an `anchor` element instead of a `button` element, with all the typing constraints and props one would expect from an anchor.", | ||
}, | ||
}, | ||
}, | ||
} as Meta; | ||
|
||
const Template: StoryFn<LinkButtonProps> = (args) => <LinkButton {...args} />; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
href: "#", | ||
variant: "primary", | ||
children: "Default Link Button", | ||
}; | ||
|
||
export const External = Template.bind({}); | ||
External.args = { | ||
href: "https://www.ably.com", | ||
children: "External Link Button", | ||
target: "_blank", | ||
rel: "noopener noreferrer", | ||
}; | ||
|
||
export const Disabled = Template.bind({}); | ||
Disabled.args = { | ||
href: "#", | ||
children: "Disabled Link Button", | ||
disabled: true, | ||
}; |
27 changes: 27 additions & 0 deletions
27
src/core/LinkButton/__snapshots__/LinkButton.stories.tsx.snap
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,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Components/Link Button Default smoke-test 1`] = ` | ||
<a class="ui-button-primary" | ||
href="#" | ||
> | ||
Default Link Button | ||
</a> | ||
`; | ||
|
||
exports[`Components/Link Button Disabled smoke-test 1`] = ` | ||
<a class="ui-button-primary ui-button-disabled dark:ui-button-disabled-dark" | ||
href="#" | ||
> | ||
Disabled Link Button | ||
</a> | ||
`; | ||
|
||
exports[`Components/Link Button External smoke-test 1`] = ` | ||
<a class="ui-button-primary" | ||
href="https://www.ably.com" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
External Link Button | ||
</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
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