Skip to content

Commit

Permalink
#34 Add ArrowButton common component.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Nunes committed Aug 3, 2018
1 parent 90e0759 commit eb22850
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 26 deletions.
1 change: 1 addition & 0 deletions .stylelintrc
Expand Up @@ -12,6 +12,7 @@
"ignoreFiles": [
"src/assets/styles/vendor/*.css",
"src/pages/*.js",
"src/components/*.js",
"src/templates/*.js"
]
}
11 changes: 7 additions & 4 deletions src/components/Works/Work/Work.js
Expand Up @@ -2,7 +2,10 @@ import React from 'react';
import Lightbox from 'react-image-lightbox';
import PropTypes from 'prop-types';
import { navigateTo } from 'gatsby-link';

import Icon from '../../common/Icon';
import ArrowButton from '../../common/ArrowButton';

import colors from '../../../assets/colors';
import styles from './Work.module.css';

Expand Down Expand Up @@ -71,10 +74,10 @@ class Work extends React.Component {
<span className={styles.dateText}>{data.frontmatter.date}</span>
</div>
<p>{data.excerpt}</p>
<div className={styles.readmore} onClick={() => navigateTo(route)}>
<span className={styles.text}>read more</span>
<Icon icon="arrowRight2" color={colors.text} spin={false} />
</div>
<ArrowButton
action={() => navigateTo(route)}
text="read more"
/>
</div>
);
}
Expand Down
21 changes: 0 additions & 21 deletions src/components/Works/Work/Work.module.css
Expand Up @@ -97,24 +97,3 @@
margin-left: 1rem;
}
}

.readmore {
display: flex;
flex-direction: row;
align-items: center;
color: var(--text);
cursor: pointer;

& .text {
font-size: 1.5rem;
margin-right: 1rem;
font-weight: 600;
text-transform: uppercase;
}

&:hover {
& .text {
text-decoration: underline;
}
}
}
61 changes: 61 additions & 0 deletions src/components/common/ArrowButton/ArrowButton.js
@@ -0,0 +1,61 @@
import React from 'react';
import PropTypes from 'prop-types';

import Icon from '../Icon';

import colors from '../../../assets/colors';
import styles from './ArrowButton.module.css';

const Text = ({ text, direction }) => (
<span
className={`
${styles.text}
${direction === 'r' ? styles.r : styles.l}
`}
>
{text}
</span>
);

const IconRenderer = ({ arrowIcon }) => (
<Icon icon={arrowIcon} color={colors.text} spin={false} />
);

const ArrowButton = ({ action, text, direction }) => {
const arrowIcon = direction === 'r' ? 'arrowRight' : 'arrowLeft';

const renderButton = () => {
if (direction === 'r') {
return (
<React.Fragment>
<Text text={text} direction={direction} />
<IconRenderer arrowIcon={arrowIcon} />
</React.Fragment>
);
}
return (
<React.Fragment>
<IconRenderer arrowIcon={arrowIcon} />
<Text text={text} direction={direction} />
</React.Fragment>
);
};

return (
<div className={styles.root} onClick={action}>
{renderButton()}
</div>
);
};

ArrowButton.defaultProps = {
direction: 'r',
};

ArrowButton.propTypes = {
action: PropTypes.func.isRequired,
text: PropTypes.string.isRequired,
direction: PropTypes.string,
};

export default ArrowButton;
29 changes: 29 additions & 0 deletions src/components/common/ArrowButton/ArrowButton.module.css
@@ -0,0 +1,29 @@
@import "../../../assets/styles/config.css";

.root {
display: flex;
flex-direction: row;
align-items: center;
color: var(--text);
cursor: pointer;

& .text {
font-size: 1.5rem;
font-weight: 600;
text-transform: uppercase;

&.l {
margin-left: 1rem;
}

&.r {
margin-right: 1rem;
}
}

&:hover {
& .text {
text-decoration: underline;
}
}
}
1 change: 1 addition & 0 deletions src/components/common/ArrowButton/index.js
@@ -0,0 +1 @@
export { default } from './ArrowButton';
4 changes: 3 additions & 1 deletion src/components/common/Icon/icons.js

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

@@ -1,5 +1,6 @@
---
title: This new work will test the WorkSingle layout
author: M.C. Teixeira
date: '2018-08-01T19:15:18+01:00'
thumbnail: /assets/img2.jpg
heroImage: /assets/img1-thumb.jpg
Expand Down

0 comments on commit eb22850

Please sign in to comment.