Skip to content

Commit d487a23

Browse files
committed
Add background-image component
1 parent 04b4aa2 commit d487a23

File tree

5 files changed

+90
-62
lines changed

5 files changed

+90
-62
lines changed

package-lock.json

Lines changed: 6 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"preview": "rspress preview"
1212
},
1313
"dependencies": {
14-
"@rstack-dev/doc-ui": "1.7.2"
1514
},
1615
"devDependencies": {
1716
"@biomejs/biome": "^1.9.4",

theme/components/Landingpage/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BackgroundImage } from '@rstack-dev/doc-ui/background-image';
1+
import { BackgroundImage } from '../background-image';
22
import { Hero } from '../hero';
33
import styles from './index.module.scss';
44

@@ -8,7 +8,7 @@ import { useNavigate } from 'rspress/runtime';
88
const LandingPage = () => {
99
const navigate = useNavigate();
1010
const onClickGetStarted = useCallback(() => {
11-
navigate('/guide/start/quick-start');
11+
navigate('/guide');
1212
}, [navigate]);
1313

1414
return (
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.background {
2+
width: 100%;
3+
position: absolute;
4+
top: calc(-1 * var(--rp-nav-height));
5+
left: 0;
6+
7+
z-index: -1;
8+
filter: blur(2px);
9+
10+
pointer-events: none;
11+
user-select: none;
12+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { type FC, useEffect, useState } from 'react';
2+
import styles from './index.module.scss';
3+
4+
const useTopArrived = () => {
5+
const [scrollY, setScrollY] = useState(0);
6+
const topArrived = scrollY < 100;
7+
8+
useEffect(() => {
9+
const handleScroll = () => {
10+
setScrollY(window.scrollY);
11+
};
12+
window.addEventListener('scroll', handleScroll, {
13+
capture: false,
14+
passive: true,
15+
});
16+
return () => {
17+
window.removeEventListener('scroll', handleScroll);
18+
};
19+
}, []);
20+
21+
return {
22+
topArrived,
23+
};
24+
};
25+
26+
export type BackgroundProps = {
27+
navBarTopArrived?: boolean;
28+
};
29+
30+
export const BackgroundImage: FC<BackgroundProps> = ({
31+
navBarTopArrived = true,
32+
}) => {
33+
const { topArrived } = useTopArrived();
34+
35+
useEffect(() => {
36+
if (!navBarTopArrived) {
37+
return;
38+
}
39+
if (topArrived) {
40+
document.body.classList.remove('notTopArrived');
41+
} else {
42+
document.body.classList.add('notTopArrived');
43+
}
44+
}, [topArrived, navBarTopArrived]);
45+
46+
return (
47+
<>
48+
<style>
49+
{`:root {
50+
--rp-c-bg: #0b0c0e;
51+
}
52+
:root:not(.dark) {
53+
--rp-c-bg: #fff;
54+
}
55+
.rspress-nav {
56+
transition: background 0.4s;
57+
}
58+
body:not(.notTopArrived) .rspress-nav {
59+
background: transparent !important;
60+
}
61+
`}
62+
</style>
63+
<img
64+
className={styles.background}
65+
src="https://assets.rspack.dev/rspack/assets/landingpage-background-compressed.png"
66+
alt="background"
67+
/>
68+
</>
69+
);
70+
};

0 commit comments

Comments
 (0)