Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(component): add Link component #51

Merged
merged 4 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';