Skip to content

Commit

Permalink
Merge pull request #180 from Dias999/feature/Storybook-Link
Browse files Browse the repository at this point in the history
feat: storybook / TSDocs - Link
  • Loading branch information
MrMaz authored Aug 20, 2024
2 parents fd5737c + 608a657 commit 029a741
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/react-material-ui/__tests__/Link.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import '@testing-library/jest-dom';
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import Link from '../src/components/Link/Link';
import { Link } from '../src/components/Link/Link';

describe('Link component', () => {
it('should render correctly', () => {
Expand Down
23 changes: 20 additions & 3 deletions packages/react-material-ui/src/components/Link/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import React from 'react';
import MuiLink, { LinkProps } from '@mui/material/Link';

const Link = (props: LinkProps) => {
export type { LinkProps };

/**
* The `Link` component is a wrapper around the MUI `Link` component with
* additional customization for default color and styles. It's props extend from [Material UI's Link](https://mui.com/material-ui/api/link/#props)
* component props, so every prop is interchangeable between those two.
*
* @see [Storybook - Link](https://storybook.rockets.tools/?path=/docs/link)
*
* @example
* ```tsx
* <Link href="https://example.com" color="secondary.main">
* Visit Example
* </Link>
* ```
*
* @see [MUI Link](https://mui.com/api/link/)
* @param linkProps - MUI {@link [LinkProps](https://mui.com/material-ui/api/link/#props)}
*/
export const Link = (props: LinkProps) => {
const { children, color = 'primary.dark', sx } = props;

return (
Expand All @@ -19,5 +38,3 @@ const Link = (props: LinkProps) => {
</MuiLink>
);
};

export default Link;
2 changes: 1 addition & 1 deletion packages/react-material-ui/src/components/Link/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from './Link';
export { Link, LinkProps } from './Link';
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import validator from '@rjsf/validator-ajv6';
import { Box, Button, Container, Card, CircularProgress } from '@mui/material';

import Text from '../../../components/Text';
import Link from '../../../components/Link';
import { Link } from '../../../components/Link';
import { SchemaForm } from '../../../components/SchemaForm';
import { Image } from '../../../components/Image';

Expand Down
2 changes: 1 addition & 1 deletion packages/react-material-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export { FormTemplate, FormTemplateProps } from './components/FormTemplate';
export { HeaderAccount, HeaderAccountProps } from './components/HeaderAccount';

export { Image, ImageProps } from './components/Image';
export { default as Link } from './components/Link';
export { Link, LinkProps } from './components/Link';

export { Navbar, NavbarProps } from './components/Navbar';

Expand Down
69 changes: 69 additions & 0 deletions stories/Link.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Link } from '@concepta/react-material-ui';

const meta: Meta<typeof Link> = {
component: Link,
tags: ['autodocs'],
args: {
children: 'This is a Link',
href: '#',
},
argTypes: {
color: { control: 'color' },
sx: { control: 'object' },
component: { control: 'text' },
},
};

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {},
};

export const CustomColorLink: Story = {
args: {
color: 'secondary.main',
},
};

export const CustomStyles: Story = {
args: {
sx: {
fontSize: '20px',
padding: '10px',
backgroundColor: 'lightgray',
borderRadius: '4px',
},
},
};

export const LinkWithUnderline: Story = {
args: {
sx: {
textDecoration: 'underline',
},
},
};

export const VariantH2: Story = {
args: {
variant: 'h2',
},
};

export const LinkAsButton: Story = {
args: {
component: 'button',
sx: {
padding: '10px 20px',
backgroundColor: 'primary.main',
color: 'white',
borderRadius: '5px',
border: 'none',
cursor: 'pointer',
},
},
};

0 comments on commit 029a741

Please sign in to comment.