import * as React from 'react'; import { Toggle } from '@fluentui/react/lib/Toggle'; import { Layer, LayerHost } from '@fluentui/react/lib/Layer'; import { AnimationClassNames, mergeStyleSets, getTheme } from '@fluentui/react/lib/Styling'; import { IToggleStyles } from '@fluentui/react/lib/Toggle'; import { useId, useBoolean } from '@fluentui/react-hooks'; export const LayerHostedExample: React.FunctionComponent = () => { const [showLayer, { toggle: toggleShowLayer }] = useBoolean(false); const [showLayerNoId, { toggle: toggleShowLayerNoId }] = useBoolean(false); const [showHost, { toggle: toggleShowHost }] = useBoolean(true); // Use useId() to ensure that the ID is unique on the page. // (It's also okay to use a plain string without getId() and manually ensure uniqueness.) const layerHostId = useId('layerHost'); const content =
In some cases, you may need to contain layered content within an area. Create an instance of a LayerHost along with an id, and provide a hostId on the layer to render it within the specific host. (Note that it's important that you don't include children within the LayerHost. It's meant to contain Layered content only.)
If you do not specify a hostId, the hosted layer will default to being fixed to the page by default.