From da7f366fa3411b0e9f6b04f1c77053f854b5435a Mon Sep 17 00:00:00 2001 From: Lewis Ugege Date: Wed, 10 Jul 2019 12:30:49 +0100 Subject: [PATCH] feat(atom): setup link atom - setup link atom - setup styleguidist for the link - write tests for the link atom [Finishes #167191395] --- src/components/UI/atoms/Link/Link.jsx | 78 +++++++++++++++++++++++ src/components/UI/atoms/Link/Link.md | 31 +++++++++ src/components/UI/atoms/Link/Link.spec.js | 43 +++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 src/components/UI/atoms/Link/Link.jsx create mode 100644 src/components/UI/atoms/Link/Link.md create mode 100644 src/components/UI/atoms/Link/Link.spec.js diff --git a/src/components/UI/atoms/Link/Link.jsx b/src/components/UI/atoms/Link/Link.jsx new file mode 100644 index 0000000..94d01f4 --- /dev/null +++ b/src/components/UI/atoms/Link/Link.jsx @@ -0,0 +1,78 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import styled from 'styled-components'; +import { fontSizes } from '/fonts'; + +/** + * @description - Link Component + * + * @prop {boolean} isTag + * @prop {string} fontSize + * @prop {string} href + * @prop {children} children - children + * + * @return {component} Link + */ +const Link = ({ + href, + isTag, + fontSize, + onClick, + children, +}) => ( + + {children} + +); + +Link.propTypes = { + children: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.number, + PropTypes.element, + ]).isRequired, + href: PropTypes.string, + isTag: PropTypes.bool, + fontSize: PropTypes.oneOf(Object.keys(fontSizes)), + onClick: PropTypes.func, +}; + +Link.defaultProps = { + display: 'inline-block', + fontSize: 'normal', +}; + +Link.Container = styled.a` + ${({ + theme, + isTag, + fontSize, + }) => ` + padding: 0; + display: inline-block; + text-decoration: none; + text-align: center; + transition: .5s border ease-in-out; + border: solid 1px transparent; + font-size: ${theme.fontSizes[fontSize]}; + font-family: 'Roboto'; + color: ${theme.textColors.primary}; + &:visited { + color: ${theme.textColors.primary}; + } + background: ${isTag === true && '#F4EDED'}; + padding: ${isTag === true && '0.8rem'}; + color: ${isTag === true && theme.textColors.primary}; + box-shadow: ${isTag === true && '16px 16px 32px rgba(0, 0, 0, 0.05)'}; + width: ${isTag === true && '25.8rem'}; + &:hover { + border: ${isTag === true && `solid 1px ${theme.textColors.primary}`}; + } +`} +`; +export default Link; diff --git a/src/components/UI/atoms/Link/Link.md b/src/components/UI/atoms/Link/Link.md new file mode 100644 index 0000000..7e273cd --- /dev/null +++ b/src/components/UI/atoms/Link/Link.md @@ -0,0 +1,31 @@ +Link Default: + +```jsx +Default Link +``` + +Link with the tag attributes +```jsx + + Google Link + +``` + +Link with onClick attribute +```jsx + const onClick = (e) => { + e.preventDefault(); + alert('Hello World'); + } + + + Say Hello! + +``` diff --git a/src/components/UI/atoms/Link/Link.spec.js b/src/components/UI/atoms/Link/Link.spec.js new file mode 100644 index 0000000..f72a4ed --- /dev/null +++ b/src/components/UI/atoms/Link/Link.spec.js @@ -0,0 +1,43 @@ +import React from 'react'; +import { render, cleanup } from '/helpers/testUtils'; +import Link from './Link'; +import Title from '../Title/Title'; +import 'jest-dom/extend-expect'; + +afterEach(cleanup); + +describe('Link', () => { + it('should render the Link component', () => { + const { getByText } = render(Authors Haven); + + expect(getByText('Authors Haven')).toBeTruthy(); + }); + + it('should apply default style', () => { + const { getByText } = render(Authors Haven); + + expect(getByText('Authors Haven')).toHaveStyle(` + font-size: '1.6' + display: inline-block; + text-decoration: none; + `); + }); + + it('should render a tag styled component', () => { + const { container } = render( + + Welcome + , + ); + expect(container.firstChild).toBeTruthy(); + }); + + it('should render react component as children', () => { + const { container } = render( + + Welcome + , + ); + expect(container.firstChild).toBeTruthy(); + }); +});