Skip to content

Commit e473429

Browse files
committed
Move styles to CSS
1 parent ce8c7a3 commit e473429

File tree

6 files changed

+56
-43
lines changed

6 files changed

+56
-43
lines changed

examples/basic/basic.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,21 @@ let renderCount = 0;
88
export class Basic extends PureComponent {
99
render() {
1010
return (
11-
<div style={{ height: 1500, margin: "0 30px" }}>
11+
<div>
1212
<h2>Content before the Sticky...</h2>
13-
<div style={{ marginBottom: 200 }} />
14-
<StickyContainer
15-
style={{ height: 500, background: "#ddd", padding: "0 30px" }}
16-
>
13+
<div className="gap short" />
14+
<StickyContainer className="container">
1715
<Sticky>
1816
{({ style }) => (
1917
<Header style={style} renderCount={renderCount++} />
2018
)}
2119
</Sticky>
2220

23-
<h2 className="text-center" style={{ marginTop: 150 }}>
24-
{"<StickyContainer />"}
25-
</h2>
21+
<h2 className="text-center">{"<StickyContainer />"}</h2>
2622
</StickyContainer>
27-
<div style={{ marginBottom: 200 }} />
28-
<h2>Content after the Sticky...</h2>
23+
<div className="gap tall">
24+
<h2>Content after the Sticky...</h2>
25+
</div>
2926
</div>
3027
);
3128
}

examples/header.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import React from "react";
22

33
export class Header extends React.Component {
4+
static defaultProps = {
5+
className: ""
6+
};
47
render() {
5-
const { style, renderCount } = this.props;
8+
const { style, renderCount, className } = this.props;
69
return (
7-
<div
8-
style={{
9-
height: 80,
10-
overflow: "auto",
11-
background: "#aaa",
12-
...style
13-
}}
14-
>
10+
<div className={"header " + className} style={style}>
1511
<h2>
1612
<span className="pull-left">
1713
{"<Sticky /> "}

examples/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ReactDOM.render(
1010
<Router>
1111
<div>
1212
<style>{styles}</style>
13-
<div className="header">
13+
<div className="navbar">
1414
<Link to="/basic">Basic</Link> <Link to="/relative">Relative</Link>{" "}
1515
<Link to="/stacked">Stacked</Link>
1616
</div>

examples/relative/relative.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,17 @@ let renderCount = 0;
88
export class Relative extends PureComponent {
99
render() {
1010
return (
11-
<div style={{ margin: 30 }}>
12-
<StickyContainer
13-
style={{
14-
height: 250,
15-
overflowY: "auto",
16-
background: "#ddd",
17-
padding: "0 30px"
18-
}}
19-
>
20-
<div style={{ height: 500 }}>
21-
<div style={{ height: 50 }} />
11+
<div>
12+
<StickyContainer className="container relative">
13+
<div className="gap tall">
14+
<div className="gap short" />
2215
<Sticky relative={true}>
2316
{({ style }) => (
2417
<Header style={style} renderCount={renderCount++} />
2518
)}
2619
</Sticky>
27-
28-
<h2 className="text-center" style={{ marginTop: 150 }}>
29-
overflowing container
30-
</h2>
20+
<div className="gap short" />
21+
<h2>scrolling container</h2>
3122
</div>
3223
</StickyContainer>
3324
</div>

examples/stacked/stacked.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ import ReactDOM from "react-dom";
44
import { Sticky, StickyContainer } from "../../src";
55
import { Header } from "../header";
66

7+
const containerBg = i => `hsl(${i * 40}, 70%, 90%)`;
8+
const headerBg = i => `hsl(${i * 40}, 70%, 50%)`;
9+
710
export class Stacked extends PureComponent {
811
render() {
912
return (
1013
<div>
1114
{[1, 2, 3, 4, 5, 6, 7, 8].map(i => (
1215
<StickyContainer
1316
key={i}
14-
style={{ height: 500, background: `hsl(${i * 40}, 70%, 90%)` }}
17+
className="container"
18+
style={{ background: containerBg(i) }}
1519
>
1620
<Sticky>
1721
{({ style }) => (
18-
<Header
19-
style={{ ...style, background: `hsl(${i * 40}, 70%, 50%)` }}
20-
/>
22+
<Header style={{ ...style, background: headerBg(i) }} />
2123
)}
2224
</Sticky>
2325

24-
<h2 className="text-center" style={{ marginTop: 150 }}>
25-
{`<StickyContainer #${i} />`}
26-
</h2>
26+
<h2 className="text-center">{`<StickyContainer #${i} />`}</h2>
2727
</StickyContainer>
2828
))}
2929
</div>

examples/styles.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export default `
22
body {
3+
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
34
padding: 0;
45
margin: 0;
56
margin-top: 2rem;
@@ -15,11 +16,39 @@ h2 {
1516
line-height: 1.5rem;
1617
}
1718
18-
.header {
19+
.navbar {
1920
position: fixed;
2021
top: 0;
2122
padding: .5rem;
2223
background: white;
2324
z-index: 10;
2425
}
26+
27+
.header {
28+
height: 80px;
29+
overflow: auto;
30+
background: #aaa;
31+
}
32+
33+
.container {
34+
height: 500px;
35+
background: #ddd;
36+
padding: 0 2rem;
37+
}
38+
39+
.gap {
40+
height: 500px;
41+
}
42+
43+
.gap.short {
44+
height: 250px;
45+
}
46+
47+
.gap.tall {
48+
height: 1000px;
49+
}
50+
51+
.container.relative {
52+
overflow-y: auto;
53+
}
2554
`;

0 commit comments

Comments
 (0)