diff --git a/components/index.scss b/components/index.scss
index dd756ab1..e9e3a20e 100644
--- a/components/index.scss
+++ b/components/index.scss
@@ -17,6 +17,7 @@
@import "./price/price.scss";
@import "./radioButton/radioButton.scss";
@import "./slidingPanel/slidingPanel.scss";
+@import "./slidingPanel/slidingPanelHeader.scss";
@import "./spinner/spinner.scss";
@import "./rating/rating.scss";
@import "~react-select/scss/default.scss";
diff --git a/components/slidingPanel/slidingPanel.js b/components/slidingPanel/slidingPanel.js
index 9d83a03b..58b83951 100644
--- a/components/slidingPanel/slidingPanel.js
+++ b/components/slidingPanel/slidingPanel.js
@@ -1,4 +1,6 @@
-import React, { Component, PropTypes } from 'react';
+import React, { Component } from 'react';
+import PropTypes from 'prop-types';
+import SlidingPanelHeader from './slidingPanelHeader';
import { getClassNamesWithMods, getDataAttributes } from '../_helpers';
export default class SlidingPanel extends Component {
@@ -48,6 +50,11 @@ export default class SlidingPanel extends Component {
* Defines if the panel is open.
*/
active: PropTypes.bool,
+
+ /**
+ * Defines title for header. Optional. If it's defined header will be shown.
+ */
+ title: PropTypes.string,
}
static defaultProps = {
@@ -72,17 +79,13 @@ export default class SlidingPanel extends Component {
this.panel.addEventListener('transitionend', this.handleTransitionEnd);
- this.closeButton = this.panel.querySelector('[rel="close"]');
- if (this.closeButton) {
- this.closeButton.addEventListener('click', this.handleClose);
- }
+ this.closeButtons = this.panel.querySelectorAll('[rel="close"]');
+ this.closeButtons.forEach(b => b.addEventListener('click', this.handleClose));
}
componentWillUnmount() {
this.panel.removeEventListener('transitionend', this.handleTransitionEnd);
- if (this.closeButton) {
- this.closeButton.removeEventListener('click', this.handleClose);
- }
+ this.closeButtons.forEach(b => b.removeEventListener('click', this.handleClose));
}
/**
@@ -141,6 +144,7 @@ export default class SlidingPanel extends Component {
const {
dataAttrs,
children,
+ title,
} = this.props;
const overlayMods = [];
@@ -167,7 +171,10 @@ export default class SlidingPanel extends Component {
ref={(e) => { this.panel = e; }}
{...getDataAttributes(dataAttrs)}
>
- {children}
+ {title && }
+
+ {children}
+
);
diff --git a/components/slidingPanel/slidingPanel.md b/components/slidingPanel/slidingPanel.md
index a7359dc9..45ef4cf4 100644
--- a/components/slidingPanel/slidingPanel.md
+++ b/components/slidingPanel/slidingPanel.md
@@ -4,11 +4,14 @@ Basic Sliding Panel:
setState({ isSlidingPanelOpen: !state.isSlidingPanelOpen })}
>Open panel
- setState({ isSlidingPanelOpen: false })}>
+ setState({ isSlidingPanelOpen: false })}
+ title="Panel Title"
+ >
This is an example
Of how simple it is to use
Our sliding panel.
Close
-
diff --git a/components/slidingPanel/slidingPanel.scss b/components/slidingPanel/slidingPanel.scss
index 43d34611..01af6eb8 100644
--- a/components/slidingPanel/slidingPanel.scss
+++ b/components/slidingPanel/slidingPanel.scss
@@ -24,7 +24,6 @@
margin: var(--tx-sliding-panel-panel-margin);
max-width: var(--tx-sliding-panel-panel-max-width);
min-width: var(--tx-sliding-panel-panel-min-width);
- padding: var(--tx-sliding-panel-panel-padding);
position: var(--tx-sliding-panel-panel-position);
right: var(--tx-sliding-panel-panel-right);
top: var(--tx-sliding-panel-panel-top);
@@ -36,3 +35,7 @@
transform: var(--tx-sliding-panel-panel-open-transform);
}
}
+
+.ui-sliding-panel__content {
+ padding: var(--tx-sliding-panel-panel-padding);
+}
diff --git a/components/slidingPanel/slidingPanelHeader.js b/components/slidingPanel/slidingPanelHeader.js
new file mode 100644
index 00000000..854d8346
--- /dev/null
+++ b/components/slidingPanel/slidingPanelHeader.js
@@ -0,0 +1,28 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+
+const SlidingPanelHeader = ({ title }) => {
+ if (!title) {
+ return ;
+ }
+
+ return (
+
+
+ {title}
+
+
+ ×
+
+
+ );
+};
+
+SlidingPanelHeader.propTypes = {
+ title: PropTypes.string.isRequired,
+};
+
+export default SlidingPanelHeader;
diff --git a/components/slidingPanel/slidingPanelHeader.scss b/components/slidingPanel/slidingPanelHeader.scss
new file mode 100644
index 00000000..98063a36
--- /dev/null
+++ b/components/slidingPanel/slidingPanelHeader.scss
@@ -0,0 +1,38 @@
+.ui-sliding-panel-header {
+ background-color: var(--tx-generic-color-blank);
+ border-bottom: solid 2px var(--tx-generic-color-secondary-darker);
+ flex-shrink: 0;
+ height: 65px;
+ min-height: 65px;
+ text-align: center;
+}
+
+.ui-sliding-panel-header__title {
+ line-height: 65px;
+ margin: 0;
+ padding: 0 50px;
+}
+
+.ui-sliding-panel-header__close-button {
+ background: none;
+ border: none;
+ box-shadow: none;
+ color: var(--tx-generic-color-secondary-darker);
+ cursor: pointer;
+ font-family: Arial, sans-serif;
+ font-size: 40px;
+ font-weight: 400;
+ height: 25px;
+ line-height: 25px;
+ overflow: visible;
+ padding: 0;
+ position: absolute;
+ right: var(--tx-sliding-panel-panel-padding);
+ text-align: right;
+ top: 20px;
+ width: 20px;
+
+ &:hover {
+ color: var(--tx-generic-color-secondary-darkest);
+ }
+}
diff --git a/package.json b/package.json
index 76ab7ac2..79d184ad 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
"styleguide-build": "styleguidist build",
"test": "TZ=utc jest -c ./tests/jest.config.json",
"update-snapshots": "TZ=utc jest -c ./tests/jest.config.json -u",
- "cov": "jest -c ./tests/jest.config.json --coverage --no-cache",
+ "cov": "TZ=utc jest -c ./tests/jest.config.json --coverage --no-cache",
"coverage:coveralls": "cat ./coverage/lcov.info | coveralls",
"lint": "eslint --color '{components,tests,utils,scripts}/**/*.js'",
"transpile": "npm run build"
diff --git a/tests/unit/slidingPanel/__snapshots__/slidingPanel.spec.js.snap b/tests/unit/slidingPanel/__snapshots__/slidingPanel.spec.js.snap
index 5f4b3489..f704c400 100644
--- a/tests/unit/slidingPanel/__snapshots__/slidingPanel.spec.js.snap
+++ b/tests/unit/slidingPanel/__snapshots__/slidingPanel.spec.js.snap
@@ -12,7 +12,11 @@ exports[`SlidingPanel #render() closes the panel when active prop changes to fal
@@ -30,7 +34,11 @@ exports[`SlidingPanel #render() closes the panel when active prop changes to fal
@@ -48,11 +56,15 @@ exports[`SlidingPanel #render() enables [rel="close"] element provided on the ch
-
- Test
-
+
+ Test
+
+
@@ -70,11 +82,15 @@ exports[`SlidingPanel #render() enables [rel="close"] element provided on the ch
-
- Test
-
+
+ Test
+
+
@@ -91,7 +107,11 @@ exports[`SlidingPanel #render() opens the panel when active prop changes to true
@@ -109,7 +129,11 @@ exports[`SlidingPanel #render() opens the panel when active prop changes to true
@@ -127,7 +151,11 @@ exports[`SlidingPanel #render() render active by default and when clicking on th
@@ -145,7 +173,11 @@ exports[`SlidingPanel #render() render active by default and when clicking on th
@@ -163,7 +195,11 @@ exports[`SlidingPanel #render() render active by default but with closeOnOverlay
@@ -181,7 +217,57 @@ exports[`SlidingPanel #render() render active by default but with closeOnOverlay
+
+
+`;
+
+exports[`SlidingPanel #render() render header if title prop is passed 1`] = `
+
+
+
+
+
+
+ Test Title
+
+
+ ×
+
+
+
+
+ Test
+
@@ -203,7 +289,11 @@ exports[`SlidingPanel #render() render with default props and mods provided 1`]
diff --git a/tests/unit/slidingPanel/__snapshots__/slidingPanelHeader.spec.js.snap b/tests/unit/slidingPanel/__snapshots__/slidingPanelHeader.spec.js.snap
new file mode 100644
index 00000000..4b77b0f1
--- /dev/null
+++ b/tests/unit/slidingPanel/__snapshots__/slidingPanelHeader.spec.js.snap
@@ -0,0 +1,29 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`SlidingPanel #render() render noscript without title 1`] = `
+
+
+
+`;
+
+exports[`SlidingPanel #render() render with title 1`] = `
+
+
+
+ Test Title
+
+
+ ×
+
+
+
+`;
diff --git a/tests/unit/slidingPanel/slidingPanel.spec.js b/tests/unit/slidingPanel/slidingPanel.spec.js
index 3b005f21..e8c0a3f9 100644
--- a/tests/unit/slidingPanel/slidingPanel.spec.js
+++ b/tests/unit/slidingPanel/slidingPanel.spec.js
@@ -13,14 +13,26 @@ describe('SlidingPanel', () => {
const overlayElement = renderTree.find('.ui-sliding-panel-overlay');
const panelElement = overlayElement.find('.ui-sliding-panel');
+ const mainContent = panelElement.find('.ui-sliding-panel__content');
jest.runAllTimers();
-
expect(renderTree).toMatchSnapshot();
expect(overlayElement.hasClass('ui-sliding-panel-overlay_hidden')).toEqual(true);
expect(panelElement.hasClass('ui-sliding-panel_test')).toEqual(true);
- expect(panelElement.text()).toEqual('Test');
+ expect(mainContent.text()).toEqual('Test');
+ });
+
+ it('render header if title prop is passed', () => {
+ const renderTree = mount(
+ Test
+ );
+ const header = renderTree.find('.ui-sliding-panel-header');
+
+ jest.runAllTimers();
+
+ expect(renderTree).toMatchSnapshot();
+ expect(header).toHaveLength(1);
});
it('render active by default and when clicking on the overlay it closes it', () => {
diff --git a/tests/unit/slidingPanel/slidingPanelHeader.spec.js b/tests/unit/slidingPanel/slidingPanelHeader.spec.js
new file mode 100644
index 00000000..ece70608
--- /dev/null
+++ b/tests/unit/slidingPanel/slidingPanelHeader.spec.js
@@ -0,0 +1,34 @@
+import { mount } from 'enzyme';
+import React from 'react';
+import SlidingPanelHeader from '../../../components/slidingPanel/slidingPanelHeader';
+
+jest.useFakeTimers();
+
+describe('SlidingPanel', () => {
+ describe('#render()', () => {
+ it('render noscript without title', () => {
+ const renderTree = mount(
+
+ );
+
+ jest.runAllTimers();
+
+ expect(renderTree).toMatchSnapshot();
+ expect(renderTree.find('noscript')).toHaveLength(1);
+ });
+
+ it('render with title', () => {
+ const title = 'Test Title';
+ const renderTree = mount(
+
+ );
+
+ const titleEl = renderTree.find('.ui-sliding-panel-header__title');
+
+ jest.runAllTimers();
+
+ expect(renderTree).toMatchSnapshot();
+ expect(titleEl.text()).toEqual(title);
+ });
+ });
+});