initDisplayMode<T extends string>(options: DisplayModeOptions<T>): void
Initialize display mode detection for the app.
The display mode may be based on the viewport dimensions and if the device is mobile. Also note that you can use isMobile without the display mode framework.
The display modes are strings that should be passed as a type parameter to initDisplayMode. You can create an alias in your code for getting the typed version of addDisplayModeSubscriber, getDisplayMode, and useDisplayMode
import { addDisplayModeSubscriber as pureAddDisplayModeSubscriber, getDisplayMode as pureGetDisplayMode, useDisplayMode as pureUseDisplayMode,} from "@pistonite/celera";export const MyDisplayModes = ["mode1", "mode2"] as const;export type MyDisplayMode = (typeof MyDisplayModes)[number];export const addDisplayModeSubscriber = pureAddDisplayModeSubscriber<MyDisplayMode>;export const getDisplayMode = pureGetDisplayMode<MyDisplayMode>;export const useDisplayMode = pureUseDisplayMode<MyDisplayMode>; Copy
import { addDisplayModeSubscriber as pureAddDisplayModeSubscriber, getDisplayMode as pureGetDisplayMode, useDisplayMode as pureUseDisplayMode,} from "@pistonite/celera";export const MyDisplayModes = ["mode1", "mode2"] as const;export type MyDisplayMode = (typeof MyDisplayModes)[number];export const addDisplayModeSubscriber = pureAddDisplayModeSubscriber<MyDisplayMode>;export const getDisplayMode = pureGetDisplayMode<MyDisplayMode>;export const useDisplayMode = pureUseDisplayMode<MyDisplayMode>;
Note that this is not necessary in some simple use cases. For example, adjusting styles based on the viewport width can be done with CSS:
@media screen and (max-width: 800px) { /* styles for narrow mode * /} Copy
@media screen and (max-width: 800px) { /* styles for narrow mode * /}
Use this only if the display mode needs to be detected programmatically.
Initialize display mode detection for the app.
The display mode may be based on the viewport dimensions and if the device is mobile. Also note that you can use isMobile without the display mode framework.
The display modes are strings that should be passed as a type parameter to initDisplayMode. You can create an alias in your code for getting the typed version of addDisplayModeSubscriber, getDisplayMode, and useDisplayMode
Note that this is not necessary in some simple use cases. For example, adjusting styles based on the viewport width can be done with CSS:
Use this only if the display mode needs to be detected programmatically.