summaryrefslogtreecommitdiff
path: root/web-ui/src/common/back_link
diff options
context:
space:
mode:
Diffstat (limited to 'web-ui/src/common/back_link')
-rw-r--r--web-ui/src/common/back_link/back_link.js42
-rw-r--r--web-ui/src/common/back_link/back_link.scss35
-rw-r--r--web-ui/src/common/back_link/back_link.spec.js41
3 files changed, 118 insertions, 0 deletions
diff --git a/web-ui/src/common/back_link/back_link.js b/web-ui/src/common/back_link/back_link.js
new file mode 100644
index 00000000..bb5ffbea
--- /dev/null
+++ b/web-ui/src/common/back_link/back_link.js
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2017 ThoughtWorks, Inc.
+ *
+ * Pixelated is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pixelated is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import React from 'react';
+
+import './back_link.scss';
+
+const icon = <i className='fa fa-angle-left' aria-hidden='true' />;
+
+const button = (text, options) => (
+ <button className='link' {...options}>{icon}<span>{text}</span></button>
+);
+
+const link = (text, options) => (
+ <a className='link' {...options}>{icon}<span>{text}</span></a>
+);
+
+const BackLink = ({ text, ...other }) => (
+ <div className='link-content'>
+ { other.href ? link(text, other) : button(text, other) }
+ </div>
+);
+
+BackLink.propTypes = {
+ text: React.PropTypes.string.isRequired
+};
+
+export default BackLink;
diff --git a/web-ui/src/common/back_link/back_link.scss b/web-ui/src/common/back_link/back_link.scss
new file mode 100644
index 00000000..5541d9d9
--- /dev/null
+++ b/web-ui/src/common/back_link/back_link.scss
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2017 ThoughtWorks, Inc.
+ *
+ * Pixelated is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pixelated is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+@import "~scss/base/colors";
+
+.link {
+ color: $dark_blue;
+ font-style: italic;
+ font-size: 0.8em;
+ margin: 0;
+ padding: 0;
+ border: 0;
+ background: transparent;
+
+ .fa {
+ font-size: 1.6em;
+ position: relative;
+ top: 3px;
+ margin-right: 0.3em;
+ }
+}
diff --git a/web-ui/src/common/back_link/back_link.spec.js b/web-ui/src/common/back_link/back_link.spec.js
new file mode 100644
index 00000000..5f49a6f9
--- /dev/null
+++ b/web-ui/src/common/back_link/back_link.spec.js
@@ -0,0 +1,41 @@
+import { shallow } from 'enzyme';
+import expect from 'expect';
+import React from 'react';
+import BackLink from 'src/common/back_link/back_link';
+
+describe('BackLink', () => {
+ context('as link', () => {
+ let backLink;
+
+ beforeEach(() => {
+ backLink = shallow(<BackLink text='Back to inbox' href='/' />);
+ });
+
+ it('renders link with text', () => {
+ expect(backLink.find('a').text()).toEqual('Back to inbox');
+ });
+
+ it('adds link action', () => {
+ expect(backLink.find('a').props().href).toEqual('/');
+ });
+ });
+
+ context('as button', () => {
+ let backLink;
+ let mockClick;
+
+ beforeEach(() => {
+ mockClick = expect.createSpy();
+ backLink = shallow(<BackLink text='Back to inbox' onClick={mockClick} />);
+ });
+
+ it('renders button with text', () => {
+ expect(backLink.find('button').text()).toEqual('Back to inbox');
+ });
+
+ it('adds button click event', () => {
+ backLink.find('button').simulate('click');
+ expect(mockClick).toHaveBeenCalled();
+ });
+ });
+});