Skip to content

Commit

Permalink
[NO-JIRA] Blur navigation bar
Browse files Browse the repository at this point in the history
  • Loading branch information
George Gillams committed Feb 7, 2020
1 parent 8003068 commit b24d068
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 7 deletions.
70 changes: 70 additions & 0 deletions src/NavigationBar/BlurEffectView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { cssModules } from '../helpers/cssModules';
import STYLES from './blur-effect.scss';

const getClassName = cssModules(STYLES);

class BlurEffectView extends Component {
constructor(props) {
super(props);
this.myRef = React.createRef();
this.mainScrollElement;
this.mainScrollElementClone;
}

static propTypes = {
className: PropTypes.string,
};

static defaultProps = {
className: null,
};

adjustCloneScroll = () => {
if (!this.mainScrollElement || !this.mainScrollElementClone) {
return;
}
const yValue = this.mainScrollElement.offsetTop - window.pageYOffset;
this.mainScrollElementClone.style.transform = `translatey(${yValue}px)`;
};

recreateBlurClone = () => {
if (!this.mainScrollElement || !this.myRef || !this.myRef.current) {
return;
}

const newMainScrollElementClone = this.mainScrollElement.cloneNode(true);
newMainScrollElementClone.style.filter = 'blur(10px)';
newMainScrollElementClone.id += `_clone${Math.random(0, 10)}`;
if (this.mainScrollElementClone) {
this.myRef.current.removeChild(this.mainScrollElementClone);
}
this.mainScrollElementClone = newMainScrollElementClone;
this.myRef.current.append(this.mainScrollElementClone);
this.adjustCloneScroll();
};

componentDidMount() {
this.mainScrollElement = document.getElementById('mainScrollView');
this.recreateBlurClone();
this.interval = setInterval(this.recreateBlurClone, 2000);
window.addEventListener('scroll', e => {
this.adjustCloneScroll();
});
}

render() {
const { className, ...rest } = this.props;

return (
<div
ref={this.myRef}
aria-hidden="true"
className={getClassName('blur-effect__outer', className)}
/>
);
}
}

export default BlurEffectView;
2 changes: 2 additions & 0 deletions src/NavigationBar/NavigationBar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { BurgerButton } from '../Button';
import BlurEffectView from './BlurEffectView';
import { cssModules } from '../helpers/cssModules';

import STYLES from './navigation-bar.scss';
Expand Down Expand Up @@ -106,6 +107,7 @@ class NavigationBar extends Component {
)}
<div className={getClassName('navigation-bar__bar-placeholder')} />
<div className={outerClassNameFinal.join(' ')} {...rest}>
<BlurEffectView />
<div className={getClassName('navigation-bar__bar')} {...rest}>
<div
className={getClassName(
Expand Down
15 changes: 15 additions & 0 deletions src/NavigationBar/blur-effect.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@import '~bpk-mixins';
@import '../Tokens/common';

.blur-effect {
&__outer {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: -1;
overflow: hidden;
pointer-events: none;
}
}
130 changes: 123 additions & 7 deletions src/NavigationBar/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';

import { NavigationBar, NavigationItem } from './index';
import { Paragraph } from '../Typography';

const menuItems = [
<NavigationItem name="Test 1" />,
Expand All @@ -16,10 +17,125 @@ const menuItems = [
const accountMenuItem = <button>account</button>;
const logo = <span style={{ color: 'hotpink' }}>LOGO</span>;

storiesOf('NavigationBar', module).add('Default', () => (
<NavigationBar
menuItems={menuItems}
accountMenuItem={accountMenuItem}
logo={logo}
/>
));
storiesOf('NavigationBar', module)
.add('Default', () => (
<NavigationBar
menuItems={menuItems}
accountMenuItem={accountMenuItem}
logo={logo}
/>
))
.add('With scroll', () => (
<div>
<NavigationBar
menuItems={menuItems}
accountMenuItem={accountMenuItem}
logo={logo}
/>
<div id="mainScrollView">
<a href="http://localhost:9001/iframe.html?id=navigationbar--with-scroll">
OPEN IN FULL WINDOW MODE TO TEST SCROLL
</a>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse dolor sit amet
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipsum dolor
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Ipsum
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Dolor
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Dolor, dollor πŸ’΅
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
πŸ‘ πŸ‘‹ 🏈 πŸŽ‰ πŸ˜‚ βœ… πŸ€·β€β™€οΈ πŸ€ͺ
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
<br />
<Paragraph style={{ display: 'block', marginBottom: '2rem' }}>
Lorem ipse
</Paragraph>
</div>
</div>
));

0 comments on commit b24d068

Please sign in to comment.