@uncinc/uncinc-react-kitchen-sink 2.1.7 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Header/index.js +4 -4
- package/dist/components/MagicLine/index.js +70 -0
- package/dist/components/MagicLine/stories.js +33 -0
- package/dist/components/MagicLine/stories.scss +38 -0
- package/dist/components/{Header/AnimationWrapper → NavigationScroll}/index.js +6 -6
- package/dist/components/NavigationScroll/stories.js +10 -0
- package/dist/components/NavigationScroll/stories.scss +17 -0
- package/dist/components/{Header/AnimationWrapper → NavigationScroll}/style.scss +4 -5
- package/dist/index.js +2 -0
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import React, { useState } from 'react';
|
|
|
2
2
|
import classnames from 'classnames';
|
|
3
3
|
import Container from '../Layout/Container';
|
|
4
4
|
import Hamburger from '../Hamburger';
|
|
5
|
-
import
|
|
5
|
+
import NavigationScroll from '../NavigationScroll';
|
|
6
6
|
import './style.scss';
|
|
7
7
|
|
|
8
8
|
const Header = ({
|
|
@@ -33,7 +33,7 @@ const Header = ({
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const
|
|
36
|
+
const onUpdateNavigationScroll = (isVisible, hasReachedTop, scrolledPastNavHeight) => {
|
|
37
37
|
const shouldUpdate = state.visible !== isVisible || state.reachedTop !== hasReachedTop || state.scrolledPastNavHeight !== scrolledPastNavHeight;
|
|
38
38
|
|
|
39
39
|
if (shouldUpdate) {
|
|
@@ -66,8 +66,8 @@ const Header = ({
|
|
|
66
66
|
}, /*#__PURE__*/React.createElement(Container, null, subMenu)));
|
|
67
67
|
|
|
68
68
|
if (withAnimation) {
|
|
69
|
-
return /*#__PURE__*/React.createElement(
|
|
70
|
-
onUpdate:
|
|
69
|
+
return /*#__PURE__*/React.createElement(NavigationScroll, {
|
|
70
|
+
onUpdate: onUpdateNavigationScroll,
|
|
71
71
|
hasBackground: true
|
|
72
72
|
}, headerComponent);
|
|
73
73
|
} else {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React, { useRef, useState, useEffect } from 'react';
|
|
2
|
+
import c from 'classnames';
|
|
3
|
+
|
|
4
|
+
const MagicLine = ({
|
|
5
|
+
activeClassName = "Menu__item--active",
|
|
6
|
+
children
|
|
7
|
+
}) => {
|
|
8
|
+
const magicLineParentRef = useRef(null);
|
|
9
|
+
const magicLineRef = useRef(null);
|
|
10
|
+
const currentActiveItem = useRef(null);
|
|
11
|
+
const [loaded, setLoaded] = useState(false);
|
|
12
|
+
const [activeItemInNavigation, _setActiveItemInNavigation] = useState(false);
|
|
13
|
+
|
|
14
|
+
const setActiveItemInNavigation = value => {
|
|
15
|
+
if (value !== activeItemInNavigation) {
|
|
16
|
+
_setActiveItemInNavigation(value);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const MagicLineRefClasses = c('MagicLine__magic_line', {
|
|
21
|
+
'MagicLine__magic_line--visible': activeItemInNavigation && loaded
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const alignMagicLine = () => {
|
|
25
|
+
if (magicLineRef.current && currentActiveItem.current) {
|
|
26
|
+
const left = currentActiveItem.current.getBoundingClientRect().left - magicLineParentRef.current.getBoundingClientRect().left;
|
|
27
|
+
const right = magicLineParentRef.current.getBoundingClientRect().width - left - currentActiveItem.current.getBoundingClientRect().width;
|
|
28
|
+
magicLineRef.current.style.left = `${left}px`;
|
|
29
|
+
magicLineRef.current.style.right = `${right}px`;
|
|
30
|
+
setLoaded(true);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const hoverMagicLine = e => {
|
|
35
|
+
currentActiveItem.current = e.target;
|
|
36
|
+
alignMagicLine();
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const setInitialMagicLine = () => {
|
|
40
|
+
currentActiveItem.current = document.getElementsByClassName(activeClassName)[0];
|
|
41
|
+
alignMagicLine();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
const initialize = () => {
|
|
46
|
+
setInitialMagicLine();
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const handleResize = () => {
|
|
50
|
+
alignMagicLine();
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
document.fonts.ready.then(initialize);
|
|
54
|
+
window.addEventListener('load', initialize);
|
|
55
|
+
window.addEventListener("resize", handleResize);
|
|
56
|
+
return () => {
|
|
57
|
+
window.removeEventListener('load', initialize);
|
|
58
|
+
window.removeEventListener("resize", handleResize);
|
|
59
|
+
};
|
|
60
|
+
}, []);
|
|
61
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
62
|
+
ref: magicLineParentRef,
|
|
63
|
+
className: "MagicLine"
|
|
64
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
65
|
+
ref: magicLineRef,
|
|
66
|
+
className: MagicLineRefClasses
|
|
67
|
+
}), children(setInitialMagicLine, hoverMagicLine, setActiveItemInNavigation));
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default MagicLine;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import c from 'classnames';
|
|
3
|
+
import MagicLine from './';
|
|
4
|
+
import './stories.scss';
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Molecules/MagicLine'
|
|
7
|
+
};
|
|
8
|
+
export const Default = () => /*#__PURE__*/React.createElement(MagicLine, null, (setInitialMagicLine, hoverMagicLine, setActiveItemInNavigation) => {
|
|
9
|
+
const items = ["one", "two with a longer name", "three"];
|
|
10
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
11
|
+
className: "Menu"
|
|
12
|
+
}, items.map(item => {
|
|
13
|
+
const active = item === "three";
|
|
14
|
+
|
|
15
|
+
if (active) {
|
|
16
|
+
setActiveItemInNavigation(true);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const classes = c('Menu__item', {
|
|
20
|
+
'Menu__item--active': active
|
|
21
|
+
});
|
|
22
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
23
|
+
key: item,
|
|
24
|
+
className: classes,
|
|
25
|
+
onMouseEnter: e => {
|
|
26
|
+
hoverMagicLine(e);
|
|
27
|
+
},
|
|
28
|
+
onMouseLeave: e => {
|
|
29
|
+
setInitialMagicLine();
|
|
30
|
+
}
|
|
31
|
+
}, item);
|
|
32
|
+
}));
|
|
33
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
.Menu {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: row;
|
|
4
|
+
|
|
5
|
+
&__item {
|
|
6
|
+
margin: 0 1rem;
|
|
7
|
+
padding: 0 1rem;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.MagicLine {
|
|
12
|
+
position: relative;
|
|
13
|
+
|
|
14
|
+
&__magic_line {
|
|
15
|
+
pointer-events: none;
|
|
16
|
+
position: absolute;
|
|
17
|
+
bottom: 0;
|
|
18
|
+
left: 0;
|
|
19
|
+
right: 100%;
|
|
20
|
+
padding: 0;
|
|
21
|
+
margin: 0;
|
|
22
|
+
background-color: red;
|
|
23
|
+
height: .2rem;
|
|
24
|
+
z-index: 1000000;
|
|
25
|
+
opacity: 0;
|
|
26
|
+
|
|
27
|
+
&--visible {
|
|
28
|
+
opacity: 1;
|
|
29
|
+
transition: left .3s cubic-bezier(0.64, 0.04, 0.35, 1),
|
|
30
|
+
right .3s cubic-bezier(0.64, 0.04, 0.35, 1),
|
|
31
|
+
opacity 0.3s .3s cubic-bezier(0.64, 0.04, 0.35, 1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&:hover .MagicLine__magic_line {
|
|
36
|
+
opacity: 1;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -3,7 +3,7 @@ import classNames from 'classnames';
|
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import './style.scss';
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const NavigationScroll = props => {
|
|
7
7
|
const node = useRef(null);
|
|
8
8
|
const [state, setState] = useState({
|
|
9
9
|
pos: 0,
|
|
@@ -71,8 +71,8 @@ const AnimationWrapper = props => {
|
|
|
71
71
|
children,
|
|
72
72
|
hasBackground
|
|
73
73
|
} = props;
|
|
74
|
-
const classes = classNames('
|
|
75
|
-
'
|
|
74
|
+
const classes = classNames('NavigationScroll', {
|
|
75
|
+
'NavigationScroll--hasBackground': hasBackground,
|
|
76
76
|
's-scrolled-past-nav-height': scrolledPastNavHeight,
|
|
77
77
|
's-reached-page-top': reachedTop,
|
|
78
78
|
's-reached-page-bottom': reachedBottom
|
|
@@ -86,11 +86,11 @@ const AnimationWrapper = props => {
|
|
|
86
86
|
}, children);
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
NavigationScroll.propTypes = {
|
|
90
90
|
children: PropTypes.element.isRequired,
|
|
91
91
|
onUpdate: PropTypes.func
|
|
92
92
|
};
|
|
93
|
-
|
|
93
|
+
NavigationScroll.defaultProps = {
|
|
94
94
|
onUpdate: () => {}
|
|
95
95
|
};
|
|
96
|
-
export default
|
|
96
|
+
export default NavigationScroll;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import c from 'classnames';
|
|
3
|
+
import NavigationScroll from './';
|
|
4
|
+
import './stories.scss';
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Molecules/NavigationScroll'
|
|
7
|
+
};
|
|
8
|
+
export const Default = () => /*#__PURE__*/React.createElement("div", {
|
|
9
|
+
className: "NavigationScrollExample"
|
|
10
|
+
}, /*#__PURE__*/React.createElement(NavigationScroll, null, /*#__PURE__*/React.createElement("nav", null, /*#__PURE__*/React.createElement("div", null, "one"), /*#__PURE__*/React.createElement("div", null, "two"), /*#__PURE__*/React.createElement("div", null, "three"))));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
.NavigationScrollExample {
|
|
2
|
+
min-height: 200vh;
|
|
3
|
+
background: linear-gradient(0deg, rgba(34,193,195,1) 0%, rgba(253,187,45,1) 100%);
|
|
4
|
+
margin: -4rem;
|
|
5
|
+
|
|
6
|
+
nav {
|
|
7
|
+
background-color: grey;
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: row;
|
|
10
|
+
padding: 2rem;
|
|
11
|
+
|
|
12
|
+
& > div {
|
|
13
|
+
flex: 0 0 auto;
|
|
14
|
+
margin: 0 1rem;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@import '
|
|
1
|
+
@import '../../styles/assets/variables';
|
|
2
2
|
|
|
3
3
|
@keyframes animation-wrapper--slide-down {
|
|
4
4
|
from {
|
|
@@ -10,21 +10,20 @@
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
.
|
|
13
|
+
.NavigationScroll {
|
|
14
14
|
position: fixed;
|
|
15
15
|
top: 0;
|
|
16
16
|
left: 0;
|
|
17
17
|
width: 100%;
|
|
18
18
|
display: block;
|
|
19
19
|
z-index: $z-index-4;
|
|
20
|
-
transition: 0.5s
|
|
20
|
+
transition: background-color 0.5s ease-in-out;
|
|
21
21
|
|
|
22
22
|
&--hasBackground {
|
|
23
|
-
background: white;
|
|
23
|
+
background-color: white;
|
|
24
24
|
|
|
25
25
|
&.s-reached-page-bottom {
|
|
26
26
|
animation: animation-wrapper--slide-down 0.3s $animation-timing--cubic-bezier;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,8 @@ export { default as Pagination } from './components/Pagination';
|
|
|
12
12
|
export { default as QuickLayout } from './components/Layout/QuickLayout';
|
|
13
13
|
export { default as Lottie } from './components/Lottie';
|
|
14
14
|
export { default as LottieAnimationWithMousePosition } from './components/Lottie/LottieAnimationWithMousePosition';
|
|
15
|
+
export { default as MagicLine } from './components/MagicLine';
|
|
16
|
+
export { default as NavigationScroll } from './components/NavigationScroll';
|
|
15
17
|
export { default as Image } from './components/Image';
|
|
16
18
|
export { default as ImageBackground } from './components/Image/Background';
|
|
17
19
|
export { default as InlineMenu } from './components/InlineMenu';
|