Skip to content

Commit

Permalink
[explorer] Add link component (MystenLabs#5395)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan-Mysten authored Oct 20, 2022
1 parent f5e4fcf commit 11b99a7
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/explorer/src/ui/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { cva, type VariantProps } from 'class-variance-authority';

import ButtonOrLink, { type ButtonOrLinkProps } from './utils/ButtonOrLink';
import { ButtonOrLink, type ButtonOrLinkProps } from './utils/ButtonOrLink';

const buttonStyles = cva(
[
Expand Down
32 changes: 32 additions & 0 deletions apps/explorer/src/ui/Link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { cva, type VariantProps } from 'class-variance-authority';

import { ButtonOrLink, type ButtonOrLinkProps } from './utils/ButtonOrLink';

const linkStyles = cva(
[
// TODO: Remove when CSS reset is applied.
'cursor-pointer no-underline bg-transparent p-0 border-none',
],
{
variants: {
variant: {
text: 'text-body font-semibold text-sui-grey-75 hover:text-sui-grey-90 active:text-sui-grey-100',
mono: 'font-mono text-bodySmall font-medium text-sui-dark',
},
uppercase: {
true: 'uppercase',
},
},
}
);

export interface LinkProps
extends ButtonOrLinkProps,
VariantProps<typeof linkStyles> {}

export function Link({ variant, ...props }: LinkProps) {
return <ButtonOrLink className={linkStyles({ variant })} {...props} />;
}
24 changes: 24 additions & 0 deletions apps/explorer/src/ui/stories/Link.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { type Meta, type StoryObj } from '@storybook/react';

import { Link, type LinkProps } from '../Link';

export default {
component: Link,
} as Meta;

export const Text: StoryObj<LinkProps> = {
args: {
variant: 'text',
children: 'View more',
},
};

export const Mono: StoryObj<LinkProps> = {
args: {
variant: 'mono',
children: '0x0000000000000000000000000000000000000002',
},
};
2 changes: 1 addition & 1 deletion apps/explorer/src/ui/utils/ButtonOrLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ButtonOrLinkProps
'ref'
> {}

export default forwardRef<
export const ButtonOrLink = forwardRef<
HTMLAnchorElement | HTMLButtonElement,
ButtonOrLinkProps
>(({ href, to, ...props }, ref: any) => {
Expand Down

0 comments on commit 11b99a7

Please sign in to comment.