Skip to content

Commit

Permalink
Add Button.Link component and use it for download PDF button
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmielnik committed Jan 30, 2020
1 parent ee99469 commit 1f8e5cc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cv",
"version": "1.5.1",
"version": "1.5.2",
"description": "Kamil Mielnik's Curriculum Vitae",
"engines": {
"node": ">=12.4.0"
Expand All @@ -16,6 +16,7 @@
"prettier:js:fix": "npm run prettier:js -- --fix",
"prettier:scss": "prettier --list-different './**/*.scss'",
"prettier:scss:fix": "npm run prettier:scss -- --write --no-list-different",
"publish": "npm run build && npm run deploy",
"start": "better-npm-run start"
},
"betterScripts": {
Expand Down
10 changes: 7 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import styles from './App.module.scss';

const PDF_FILENAME = 'KamilMielnik.pdf';
const print = () => window.print();
const downloadPdf = () => window.open(window.location.href + PDF_FILENAME);

const App = () => (
<div className={styles.app}>
Expand All @@ -33,9 +32,14 @@ const App = () => (
Print
</Button>

<Button className={styles.button} title="Download PDF" type="button" onClick={downloadPdf}>
<Button.Link
className={styles.button}
href={PDF_FILENAME}
title="Download PDF"
type="button"
>
Download PDF
</Button>
</Button.Link>
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/components/Button/Button.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
padding: 6px 20px;
text-transform: uppercase;
font-size: 18px;

&:hover {
text-decoration: none;
}
}
5 changes: 4 additions & 1 deletion src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { FunctionComponent, HTMLProps } from 'react';
import classNames from 'classnames';

import Link from './Link';
import styles from './Button.module.scss';

interface Props extends HTMLProps<HTMLButtonElement> {
Expand All @@ -13,4 +14,6 @@ const Button: FunctionComponent<Props> = ({ className, children, ...props }) =>
</button>
);

export default Button;
export default Object.assign(Button, {
Link
});
14 changes: 14 additions & 0 deletions src/components/Button/Link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, { FunctionComponent, HTMLProps } from 'react';
import classNames from 'classnames';

import styles from './Button.module.scss';

interface Props extends HTMLProps<HTMLAnchorElement> {}

const Link: FunctionComponent<Props> = ({ className, children, ...props }) => (
<a className={classNames(styles.button, className)} {...props}>
{children}
</a>
);

export default Link;

0 comments on commit 1f8e5cc

Please sign in to comment.