Skip to content

Commit 43b6241

Browse files
committed
Introduce a dedicated intersection marker and state to control the application of the sticky header's box-shadow styling
1 parent 8a537bb commit 43b6241

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

‎packages/ui/src/components/editor/settings/Section/Section.module.scss‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
.container {
2+
position: relative;
23
display: flex;
34
flex-direction: column;
45
gap: var(--padding-24px);
56
}
67

8+
.class_marker {
9+
position: absolute;
10+
top: 4px;
11+
height: 1px;
12+
}
13+
714
.header {
815
position: sticky;
916
z-index: 1;
@@ -16,6 +23,8 @@
1623
); // to align with the sidebar title
1724
padding-bottom: var(--padding-10px);
1825
background-color: var(--vscode-editor-background);
26+
transition: box-shadow var(--transition-duration-250)
27+
var(--transition-timing-function);
1928

2029
&--stuck {
2130
box-shadow: var(--vscode-scrollbar-shadow) 0 6px 6px -6px;

‎packages/ui/src/components/editor/settings/Section/Section.tsx‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ type Props = {
1212
export const Section = forwardRef<HTMLDivElement, Props>((props, ref) => {
1313
const marker_ref = useRef<HTMLDivElement>(null)
1414
const container_ref = useRef<HTMLDivElement | null>(null)
15+
const class_marker_ref = useRef<HTMLDivElement>(null)
1516
const [is_stuck, set_is_stuck] = useState(false)
17+
const [add_stuck_class, set_add_stuck_class] = useState(false)
1618

1719
useEffect(() => {
1820
props.on_stuck_change?.(is_stuck)
@@ -21,36 +23,49 @@ export const Section = forwardRef<HTMLDivElement, Props>((props, ref) => {
2123
useEffect(() => {
2224
const marker = marker_ref.current
2325
const container = container_ref.current
24-
if (!marker || !container) return
26+
const class_marker = class_marker_ref.current
27+
if (!marker || !container || !class_marker) return
2528

2629
let is_marker_stuck = false
30+
let is_class_marker_stuck = false
2731
let is_container_visible = true
2832

29-
const update_stuck_state = () => {
33+
const update_states = () => {
3034
set_is_stuck(is_marker_stuck && is_container_visible)
35+
set_add_stuck_class(is_class_marker_stuck && is_container_visible)
3136
}
3237

3338
const marker_observer = new IntersectionObserver(
3439
([entry]) => {
3540
is_marker_stuck = !entry.isIntersecting
36-
update_stuck_state()
41+
update_states()
42+
},
43+
{ threshold: 1 }
44+
)
45+
46+
const class_marker_observer = new IntersectionObserver(
47+
([entry]) => {
48+
is_class_marker_stuck = !entry.isIntersecting
49+
update_states()
3750
},
3851
{ threshold: 1 }
3952
)
4053

4154
const container_observer = new IntersectionObserver(
4255
([entry]) => {
4356
is_container_visible = entry.isIntersecting
44-
update_stuck_state()
57+
update_states()
4558
},
4659
{ threshold: 0 }
4760
)
4861

4962
marker_observer.observe(marker)
63+
class_marker_observer.observe(class_marker)
5064
container_observer.observe(container)
5165

5266
return () => {
5367
marker_observer.disconnect()
68+
class_marker_observer.disconnect()
5469
container_observer.disconnect()
5570
}
5671
}, [])
@@ -67,8 +82,11 @@ export const Section = forwardRef<HTMLDivElement, Props>((props, ref) => {
6782
}}
6883
className={styles.container}
6984
>
85+
<div className={styles.class_marker} ref={class_marker_ref} />
7086
<div
71-
className={cn(styles.header, { [styles['header--stuck']]: is_stuck })}
87+
className={cn(styles.header, {
88+
[styles['header--stuck']]: add_stuck_class
89+
})}
7290
>
7391
<div className={styles.header__marker} ref={marker_ref} />
7492
<div className={styles.header__title}>{props.title}</div>

0 commit comments

Comments
 (0)