-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
94 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {useDraftModeEnvironment} from './useDraftMode' | ||
|
||
/** | ||
* Detects if the application is considered to be in a "Live Preview" mode. | ||
* Live Preview means that the application is either: | ||
* - being previewed inside Sanity Presentation Tool | ||
* - being previewed in Draft Mode, with a `browserToken` given to `defineLive`, also known as "Standalone Live Preview'" | ||
* When in Live Preview mode, you typically want UI to update as new content comes in, without any manual intervention. | ||
* This is very different from Live Production mode, where you usually want to delay updates that might cause layout shifts, | ||
* to avoid interrupting the user that is consuming your content. | ||
* This hook lets you adapt to this difference, making sure production doesn't cause layout shifts that worsen the UX, | ||
* while in Live Preview mode layout shift is less of an issue and it's better for the editorial experience to auto refresh in real time. | ||
* | ||
* The hook returns `null` initially, to signal it doesn't yet know if it's live previewing or not. | ||
* Then `true` if it is, and `false` otherwise. | ||
* @public | ||
*/ | ||
export function useIsLivePreview(): boolean | null { | ||
const environment = useDraftModeEnvironment() | ||
return environment === 'checking' | ||
? null | ||
: environment === 'presentation-iframe' || | ||
environment === 'presentation-window' || | ||
environment === 'live' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {useDraftModeEnvironment} from './useDraftMode' | ||
|
||
/** | ||
* Detects if the application is being previewed inside Sanity Presentation Tool. | ||
* Presentation Tool can open the application in an iframe, or in a new window. | ||
* When in this context there are some UI you usually don't want to show, | ||
* for example a Draft Mode toggle, or a "Viewing draft content" indicators, these are unnecessary and add clutter to | ||
* the editorial experience. | ||
* The hook returns `null` initially, when it's not yet sure if the application is running inside Presentation Tool, | ||
* then `true` if it is, and `false` otherwise. | ||
* @public | ||
*/ | ||
export function useIsPresentationTool(): boolean | null { | ||
const environment = useDraftModeEnvironment() | ||
return environment === 'checking' | ||
? null | ||
: environment === 'presentation-iframe' || environment === 'presentation-window' | ||
} |