-
Notifications
You must be signed in to change notification settings - Fork 42
/
sticky-save-and-share-bar.js
75 lines (67 loc) · 2.04 KB
/
sticky-save-and-share-bar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from "react";
import styled, { css } from "styled-components";
import { rgba } from "polished";
import SaveAndShareBar from "@times-components/save-and-share-bar";
import Sticky, {
computeProgressStyles,
selectors,
mediaQuery
} from "@times-components/sticky";
import { breakpoints, colours } from "@times-components/styleguide";
import { ServerClientRender } from "@times-components/utils";
import { ArticleKeylineItem } from "./keylines";
const SaveShareContainer = styled.div`
background-color: ${colours.functional.white};
height: 60px;
${props =>
props.isClient && [
selectors.sizer(css`
border-bottom: 1px solid transparent;
will-change: border-bottom-color;
`),
selectors.sticky(css`
will-change: height, box-shadow;
`),
computeProgressStyles(
progress => css`
height: ${60 - progress * 10}px;
box-shadow: 0 2px 5px 0 ${rgba(0, 0, 0, 0.2 * progress)};
${selectors.stickySizer(css`
border-bottom-color: ${rgba(
colours.functional.keyline,
Math.max(0, 1 - 2 * progress)
)};
`)};
`
)
]};
`;
// This is to avoid transition styles being server side rendered which we
// do not need. They'll be quite large and are unnecessary on initial render
function SaveShareContainerWrapper(props) {
return (
<ServerClientRender
client={() => <SaveShareContainer isClient {...props} />}
server={() => <SaveShareContainer {...props} />}
/>
);
}
const StyledKeylineItem = styled(ArticleKeylineItem)`
${selectors.containsSticky(css`
border-bottom-color: transparent;
`)};
`;
const shouldBeSticky = mediaQuery(`(max-width: ${breakpoints.huge}px)`);
function StickySaveAndShareBar(props) {
return (
<StyledKeylineItem>
<Sticky
Component={SaveShareContainerWrapper}
shouldBeSticky={shouldBeSticky}
>
<SaveAndShareBar {...props} />
</Sticky>
</StyledKeylineItem>
);
}
export default StickySaveAndShareBar;