Skip to content

Commit

Permalink
SOV-3389: Context Link component
Browse files Browse the repository at this point in the history
  • Loading branch information
pietro-maximoff committed Nov 21, 2023
1 parent edacb4b commit b0fcedc
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.link {
@apply text-gray-10 text-base font-semibold leading-5 cursor-pointer
underline-offset-[0.4rem] underline decoration-gray-30 decoration-dashed decoration-1;
}

.link:hover {
@apply text-gray-30;
}
48 changes: 48 additions & 0 deletions packages/ui/src/2_molecules/ContextLink/ContextLink.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Story } from '@storybook/react';

import React, { ComponentProps } from 'react';

import { ContextLink } from './ContextLink';

export default {
title: 'Molecule/ContextLink',
component: ContextLink,
};

const Template: Story<ComponentProps<typeof ContextLink>> = args => (
<div className="mt-20 flex justify-center">
<ContextLink {...args} />
</div>
);

export const Basic = Template.bind({});
Basic.args = {
children: <div>Up to 8.55% APR</div>,
tooltipContent: (
<div>
<p>Before liquidity mining rewards: 2%</p>
<p>After liquidity mining rewards: 8.55%</p>
</div>
),
};
Basic.argTypes = {
tooltipContent: {
control: 'text',
description:
'The content of the context link tooltip. Can be text, other components, or HTML elements.',
},
children: {
control: 'text',
description:
'The content of the context link. Can be text, other components, or HTML elements.',
},
className: {
control: 'text',
description: 'The class to apply to the context link',
},
dataAttribute: {
control: 'text',
description:
'The data id to apply as HTML attribute to this component instance. This should be unique per component instance on the page',
},
};
41 changes: 41 additions & 0 deletions packages/ui/src/2_molecules/ContextLink/ContextLink.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import React from 'react';

import { ContextLink } from './ContextLink';

describe('ContextLink', () => {
it('should render children and show tooltip on hover', () => {
const { getByText } = render(
<ContextLink tooltipContent="Tooltip">Link</ContextLink>,
);
const link = getByText('Link');
userEvent.hover(link);
const tooltip = getByText('Tooltip');
expect(tooltip).toBeInTheDocument();
});

it('should render tooltip with a custom class', () => {
const { getByText } = render(
<ContextLink tooltipContent="Tooltip" className="custom-class">
Link
</ContextLink>,
);
const link = getByText('Link');
const classes = link.getAttribute('class');
expect(classes).toContain('custom-class');
});

it('should render tooltip with a data attribute', () => {
const { getByText, getByTestId } = render(
<ContextLink tooltipContent="Tooltip" dataAttribute="tooltip-data">
Link
</ContextLink>,
);
const link = getByText('Link');
userEvent.hover(link);
const tooltip = getByTestId('tooltip-data');
expect(tooltip).toBeInTheDocument();
});
});
32 changes: 32 additions & 0 deletions packages/ui/src/2_molecules/ContextLink/ContextLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { FC, ReactNode } from 'react';

import classNames from 'classnames';

import { Tooltip } from '../Tooltip';
import styles from './ContextLink.module.css';

export type ContextLinkProps = {
/**
* The content of the context link.
**/
children: ReactNode;
tooltipContent: ReactNode;
className?: string;
dataAttribute?: string;
};

export const ContextLink: FC<ContextLinkProps> = ({
children,
tooltipContent,
className,
dataAttribute,
}) => (
<Tooltip
content={tooltipContent}
className={classNames(styles.link, className)}
tooltipClassName={styles.tooltip}
dataAttribute={dataAttribute}
>
<div>{children}</div>
</Tooltip>
);

0 comments on commit b0fcedc

Please sign in to comment.