Skip to content

Commit

Permalink
feat(component): add Link component (#51)
Browse files Browse the repository at this point in the history
* feat(component): add link component

add a new Link component to add links to email

resolves #43

Signed-off-by: Niloy Sikdar <niloysikdar30@gmail.com>

* docs(storybook): link stories

add stories for Link component

resolves #43

Signed-off-by: Niloy Sikdar <niloysikdar30@gmail.com>

* fix(component): fix Link component

fix Link component with the updated structure and props

resolves #43

Signed-off-by: Niloy Sikdar <niloysikdar30@gmail.com>
  • Loading branch information
niloysikdar authored Jul 5, 2022
1 parent 3c2015c commit 71390e7
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/Button/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Button } from './Button';
export { Button, ButtonProps } from './Button';
35 changes: 35 additions & 0 deletions src/components/Link/Link.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ComponentStory, ComponentMeta } from '@storybook/react';

import { Email } from '../Email/Email';
import { Section } from '../Section/Section';
import { Column } from '../Column/Column';
import { Link } from './Link';

export default {
component: Link,
} as ComponentMeta<typeof Link>;

//“template” of how args map to rendering
const Template: ComponentStory<typeof Link> = (args) => (
<Email>
<Section>
<Column>
<h2>
Please <Link {...args} /> to access
</h2>
</Column>
</Section>
</Email>
);

export const Default = Template.bind({});

Default.args = {
children: 'Click here',
href: 'https://github.com/leopardslab/react-email',
classes: {
root: {
color: 'red',
},
},
};
31 changes: 31 additions & 0 deletions src/components/Link/Link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ReactNode, HTMLAttributeAnchorTarget } from 'react';
import { BaseStyleProp } from '../types';
import { makeStyles } from '../../utils/makeStyles';

type LinkStyles = 'root';

export interface LinkProps extends BaseStyleProp<LinkStyles> {
children?: ReactNode;
href: string;
target?: HTMLAttributeAnchorTarget;
}

const useStyles = makeStyles({
root: {},
});

export const Link = ({
children,
href,
target = '_blank',
classes,
className,
}: LinkProps): JSX.Element => {
const styles = useStyles({ classes });

return (
<a href={href} target={target} style={styles.root} className={className}>
{children}
</a>
);
};
1 change: 1 addition & 0 deletions src/components/Link/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Link, LinkProps } from './Link';
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './Email';
export * from './Section';
export * from './Column';
export * from './Button';
export * from './Link';

0 comments on commit 71390e7

Please sign in to comment.