forked from koshikraj/ottopus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstillness.tsx
More file actions
56 lines (50 loc) · 1.82 KB
/
Copy pathstillness.tsx
File metadata and controls
56 lines (50 loc) · 1.82 KB
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
'use client'
import { createContext, useContext, type HTMLAttributes } from 'react'
const StillnessContext = createContext(false)
/**
* True when the surrounding water has been held still.
*
* Most ambient motion needs nothing from this — CSS handles it, because
* `data-stillness="held"` flips `--ot-ambient-play` and that inherits. Read it
* only where a component has to make a rendering decision, like not mounting
* bubbles at all.
*/
export function useStillness(): boolean {
return useContext(StillnessContext)
}
export interface StillnessProviderProps extends HTMLAttributes<HTMLDivElement> {
/**
* Hold the water. Set this on any region wrapping a plan that is risky,
* expired, stale, or awaiting re-simulation.
*/
held?: boolean
}
/**
* Stops every ambient animation inside it.
*
* Calm is a signal, not a skin: ambient motion means "nothing needs you", so
* stillness is how the product raises its voice. One risky plan halts
* everything in its region, and the eye goes to the thing that stopped.
*
* Stillness only ever propagates downward. A nested provider can hold a smaller
* region, but it cannot start the water moving again inside a held one — a
* component deep in a risky plan should not be able to opt itself back into
* motion. That is why nothing here ever writes `data-stillness="running"`.
*
* This renders a real element, because the CSS variable has to inherit from
* somewhere. Pass className if it needs to carry layout.
*/
export function StillnessProvider({
held = false,
children,
...props
}: StillnessProviderProps) {
const stopped = useContext(StillnessContext) || held
return (
<StillnessContext.Provider value={stopped}>
<div data-stillness={stopped ? 'held' : undefined} {...props}>
{children}
</div>
</StillnessContext.Provider>
)
}