first commit

This commit is contained in:
Stefan Hacker
2026-04-03 09:38:48 +02:00
commit 37ad745546
47450 changed files with 3120798 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
import * as React from 'react';
import type { ILayerProps } from './Layer.types';
export declare const LayerBase: React.FunctionComponent<ILayerProps>;
+209
View File
@@ -0,0 +1,209 @@
import { __assign } from "tslib";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore "react-portal-compat-context" uses v9 configs via path aliases
import { usePortalCompat } from '@fluentui/react-portal-compat-context';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Fabric } from '../../Fabric';
import { classNamesFunction, css, getDocument, setPortalAttribute, setVirtualParent, FocusRectsProvider, FocusRectsContext, IsFocusVisibleClassName, } from '../../Utilities';
import { registerLayer, getDefaultTarget, unregisterLayer, getLayerHost, createDefaultLayerHost, } from './Layer.notification';
import { useIsomorphicLayoutEffect, useMergedRefs, useWarnings } from '@fluentui/react-hooks';
var getClassNames = classNamesFunction();
var getFocusVisibility = function (providerRef) {
if (providerRef === null || providerRef === void 0 ? void 0 : providerRef.current) {
return providerRef.current.classList.contains(IsFocusVisibleClassName);
}
return false;
};
export var LayerBase = React.forwardRef(function (props, ref) {
var registerPortalEl = usePortalCompat();
var rootRef = React.useRef(null);
var mergedRef = useMergedRefs(rootRef, ref);
var layerRef = React.useRef(undefined);
var fabricElementRef = React.useRef(null);
var focusContext = React.useContext(FocusRectsContext);
// Tracks if the layer mount events need to be raised.
// Required to allow the DOM to render after the layer element is added.
var _a = React.useState(false), needRaiseLayerMount = _a[0], setNeedRaiseLayerMount = _a[1];
// Sets the focus visible className when the FocusRectsProvider for the layer is rendered
// This allows the current focus visibility style to be carried over to the layer content
var focusRectsRef = React.useCallback(function (el) {
var isFocusVisible = getFocusVisibility(focusContext === null || focusContext === void 0 ? void 0 : focusContext.providerRef);
if (el && isFocusVisible) {
el.classList.add(IsFocusVisibleClassName);
}
}, [focusContext]);
var children = props.children, className = props.className, eventBubblingEnabled = props.eventBubblingEnabled, fabricProps = props.fabricProps, hostId = props.hostId, insertFirst = props.insertFirst, _b = props.onLayerDidMount, onLayerDidMount = _b === void 0 ? function () { return undefined; } : _b,
// eslint-disable-next-line @typescript-eslint/no-deprecated
_c = props.onLayerMounted,
// eslint-disable-next-line @typescript-eslint/no-deprecated
onLayerMounted = _c === void 0 ? function () { return undefined; } : _c, onLayerWillUnmount = props.onLayerWillUnmount, styles = props.styles, theme = props.theme;
var fabricRef = useMergedRefs(fabricElementRef, fabricProps === null || fabricProps === void 0 ? void 0 : fabricProps.ref, focusRectsRef);
var classNames = getClassNames(styles, {
theme: theme,
className: className,
isNotHost: !hostId,
});
// Returns the user provided hostId props element, the default target selector,
// or undefined if document doesn't exist.
var getHost = function (doc, shadowRoot) {
var _a, _b;
if (shadowRoot === void 0) { shadowRoot = null; }
var root = shadowRoot !== null && shadowRoot !== void 0 ? shadowRoot : doc;
if (hostId) {
var layerHost = getLayerHost(hostId);
if (layerHost) {
return (_a = layerHost.rootRef.current) !== null && _a !== void 0 ? _a : null;
}
return (_b = root.getElementById(hostId)) !== null && _b !== void 0 ? _b : null;
}
else {
var defaultHostSelector = getDefaultTarget();
// Find the host.
var host = defaultHostSelector ? root.querySelector(defaultHostSelector) : null;
// If no host is available, create a container for injecting layers in.
// Having a container scopes layout computation.
if (!host) {
host = createDefaultLayerHost(doc, shadowRoot);
}
return host;
}
};
// Removes the current layer element's parentNode and runs onLayerWillUnmount prop if provided.
var removeLayerElement = function () {
onLayerWillUnmount === null || onLayerWillUnmount === void 0 ? void 0 : onLayerWillUnmount();
var elem = layerRef.current;
// Clear ref before removing from the DOM
layerRef.current = undefined;
if (elem && elem.parentNode) {
elem.parentNode.removeChild(elem);
}
};
// If a doc or host exists, it will remove and update layer parentNodes.
var createLayerElement = function () {
var _a, _b, _c, _d;
var doc = getDocument(rootRef.current);
var shadowRoot = ((_b = (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.getRootNode()) === null || _b === void 0 ? void 0 : _b.host)
? (_c = rootRef === null || rootRef === void 0 ? void 0 : rootRef.current) === null || _c === void 0 ? void 0 : _c.getRootNode()
: undefined;
if (!doc || (!doc && !shadowRoot)) {
return;
}
var host = getHost(doc, shadowRoot);
if (!host) {
return;
}
// Tabster in V9 sets aria-hidden on the elements outside of the modal dialog. And it doesn't set aria-hidden
// on the virtual children of the dialog. But the host element itself is not a virtual child of a dialog, it
// might contain virtual children. noDirectAriaHidden flag makes Tabster to poke inside the element and set
// aria-hidden on the children (if they are not virtual children of the active V9 dialog) not on the host element.
// To avoid importing Tabster as a dependency here, we just set a flag on the host element which is checked by
// Tabster.
if (!host.__tabsterElementFlags) {
host.__tabsterElementFlags = {};
}
host.__tabsterElementFlags.noDirectAriaHidden = true;
// Remove and re-create any previous existing layer elements.
removeLayerElement();
var el = ((_d = host.ownerDocument) !== null && _d !== void 0 ? _d : doc).createElement('div');
el.className = classNames.root;
setPortalAttribute(el);
setVirtualParent(el, rootRef.current);
insertFirst ? host.insertBefore(el, host.firstChild) : host.appendChild(el);
layerRef.current = el;
setNeedRaiseLayerMount(true);
};
useIsomorphicLayoutEffect(function () {
createLayerElement();
// Check if the user provided a hostId prop and register the layer with the ID.
if (hostId) {
registerLayer(hostId, createLayerElement);
}
var unregisterPortalEl = layerRef.current ? registerPortalEl(layerRef.current) : undefined;
return function () {
if (unregisterPortalEl) {
unregisterPortalEl();
}
removeLayerElement();
if (hostId) {
unregisterLayer(hostId, createLayerElement);
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps -- should run if the hostId updates.
}, [hostId]);
React.useEffect(function () {
if (layerRef.current && needRaiseLayerMount) {
onLayerMounted === null || onLayerMounted === void 0 ? void 0 : onLayerMounted();
onLayerDidMount === null || onLayerDidMount === void 0 ? void 0 : onLayerDidMount();
setNeedRaiseLayerMount(false);
}
}, [needRaiseLayerMount, onLayerMounted, onLayerDidMount]);
useDebugWarnings(props);
return (React.createElement("span", { className: "ms-layer", ref: mergedRef }, layerRef.current &&
ReactDOM.createPortal(React.createElement(FocusRectsProvider, { layerRoot: true, providerRef: fabricRef },
React.createElement(Fabric, __assign({}, (!eventBubblingEnabled && getFilteredEvents()), fabricProps, { className: css(classNames.content, fabricProps === null || fabricProps === void 0 ? void 0 : fabricProps.className), ref: fabricRef }), children)), layerRef.current)));
});
LayerBase.displayName = 'LayerBase';
var filteredEventProps;
var onFilterEvent = function (ev) {
// We should just be able to check ev.bubble here and only stop events that are bubbling up. However, even though
// mouseenter and mouseleave do NOT bubble up, they are showing up as bubbling. Therefore we stop events based on
// event name rather than ev.bubble.
if (ev.eventPhase === Event.BUBBLING_PHASE &&
ev.type !== 'mouseenter' &&
ev.type !== 'mouseleave' &&
ev.type !== 'touchstart' &&
ev.type !== 'touchend') {
ev.stopPropagation();
}
};
function getFilteredEvents() {
if (!filteredEventProps) {
filteredEventProps = {};
[
'onClick',
'onContextMenu',
'onDoubleClick',
'onDrag',
'onDragEnd',
'onDragEnter',
'onDragExit',
'onDragLeave',
'onDragOver',
'onDragStart',
'onDrop',
'onMouseDown',
'onMouseEnter',
'onMouseLeave',
'onMouseMove',
'onMouseOver',
'onMouseOut',
'onMouseUp',
'onTouchMove',
'onTouchStart',
'onTouchCancel',
'onTouchEnd',
'onKeyDown',
'onKeyPress',
'onKeyUp',
'onFocus',
'onBlur',
'onChange',
'onInput',
'onInvalid',
'onSubmit',
].forEach(function (name) { return (filteredEventProps[name] = onFilterEvent); });
}
return filteredEventProps;
}
function useDebugWarnings(props) {
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line react-hooks/rules-of-hooks -- build-time conditional
useWarnings({
name: 'Layer',
props: props,
deprecations: { onLayerMounted: 'onLayerDidMount' },
});
}
}
//# sourceMappingURL=Layer.base.js.map
File diff suppressed because one or more lines are too long
+3
View File
@@ -0,0 +1,3 @@
import * as React from 'react';
import type { ILayerProps } from './Layer.types';
export declare const Layer: React.FunctionComponent<ILayerProps>;
+8
View File
@@ -0,0 +1,8 @@
import { styled } from '../../Utilities';
import { LayerBase } from './Layer.base';
import { getStyles } from './Layer.styles';
export var Layer = styled(LayerBase, getStyles, undefined, {
scope: 'Layer',
fields: ['hostId', 'theme', 'styles'],
});
//# sourceMappingURL=Layer.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"Layer.js","sourceRoot":"../src/","sources":["components/Layer/Layer.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,MAAM,CAAC,IAAM,KAAK,GAAyC,MAAM,CAC/D,SAAS,EACT,SAAS,EACT,SAAS,EACT;IACE,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC;CACtC,CACF,CAAC","sourcesContent":["import * as React from 'react';\nimport { styled } from '../../Utilities';\nimport { LayerBase } from './Layer.base';\nimport { getStyles } from './Layer.styles';\nimport type { ILayerProps, ILayerStyleProps, ILayerStyles } from './Layer.types';\n\nexport const Layer: React.FunctionComponent<ILayerProps> = styled<ILayerProps, ILayerStyleProps, ILayerStyles>(\n LayerBase,\n getStyles,\n undefined,\n {\n scope: 'Layer',\n fields: ['hostId', 'theme', 'styles'],\n },\n);\n"]}
@@ -0,0 +1,63 @@
import { ILayerHost } from './LayerHost.types';
/**
* Register a layer for a given host id
* @param hostId - Id of the layer host
* @param layer - Layer instance
*/
export declare function registerLayer(hostId: string, callback: () => void): void;
/**
* Unregister a layer for a given host id
* @param hostId - Id of the layer host
* @param layer - Layer instance
*/
export declare function unregisterLayer(hostId: string, callback: () => void): void;
/**
* Gets the number of layers currently registered with a host id.
* @param hostId - Id of the layer host.
* @returns The number of layers currently registered with the host.
*/
export declare function getLayerCount(hostId: string): number;
/**
* Gets the Layer Host instance associated with a hostId, if applicable.
* @param hostId - Id of the layer host
* @returns A component ref for the associated layer host.
*/
export declare function getLayerHost(hostId: string): ILayerHost | undefined;
/**
* Registers a Layer Host with an associated hostId.
* @param hostId - Id of the layer host
* @param layerHost - layer host instance
*/
export declare function registerLayerHost(hostId: string, layerHost: ILayerHost): void;
/**
* Unregisters a Layer Host from the associated hostId.
* @param hostId - Id of the layer host
* @param layerHost - layer host instance
*/
export declare function unregisterLayerHost(hostId: string, layerHost: ILayerHost): void;
/**
* When no default layer host is provided, this function is executed to create the default host.
*/
export declare function createDefaultLayerHost(doc: Document, shadowRoot?: ShadowRoot | null): Node | null;
/**
* This function can be optionally called to clean up the default layer host as needed.
*/
export declare function cleanupDefaultLayerHost(doc: Document, shadowRoot?: ShadowRoot | null): void;
/**
* Used for notifying applicable Layers that a host is available/unavailable and to re-evaluate Layers that
* care about the specific host.
*/
export declare function notifyHostChanged(id: string): void;
/**
* Sets the default target selector to use when determining the host in which
* Layered content will be injected into. If not provided, an element will be
* created at the end of the document body.
*
* Passing in a falsy value will clear the default target and reset back to
* using a created element at the end of document body.
*/
export declare function setDefaultTarget(selector?: string): void;
/**
* Get the default target selector when determining a host
*/
export declare function getDefaultTarget(): string | undefined;
+149
View File
@@ -0,0 +1,149 @@
var _layersByHostId = {};
var _layerHostsById = {};
var defaultHostId = 'fluent-default-layer-host';
var _defaultHostSelector = "#".concat(defaultHostId);
/**
* Register a layer for a given host id
* @param hostId - Id of the layer host
* @param layer - Layer instance
*/
export function registerLayer(hostId, callback) {
if (!_layersByHostId[hostId]) {
_layersByHostId[hostId] = [];
}
_layersByHostId[hostId].push(callback);
var layerHosts = _layerHostsById[hostId];
if (layerHosts) {
for (var _i = 0, layerHosts_1 = layerHosts; _i < layerHosts_1.length; _i++) {
var layerHost = layerHosts_1[_i];
layerHost.notifyLayersChanged();
}
}
}
/**
* Unregister a layer for a given host id
* @param hostId - Id of the layer host
* @param layer - Layer instance
*/
export function unregisterLayer(hostId, callback) {
var layers = _layersByHostId[hostId];
if (layers) {
var idx = layers.indexOf(callback);
if (idx >= 0) {
layers.splice(idx, 1);
if (layers.length === 0) {
delete _layersByHostId[hostId];
}
}
}
var layerHosts = _layerHostsById[hostId];
if (layerHosts) {
for (var _i = 0, layerHosts_2 = layerHosts; _i < layerHosts_2.length; _i++) {
var layerHost = layerHosts_2[_i];
layerHost.notifyLayersChanged();
}
}
}
/**
* Gets the number of layers currently registered with a host id.
* @param hostId - Id of the layer host.
* @returns The number of layers currently registered with the host.
*/
export function getLayerCount(hostId) {
var layers = _layerHostsById[hostId];
return layers ? layers.length : 0;
}
/**
* Gets the Layer Host instance associated with a hostId, if applicable.
* @param hostId - Id of the layer host
* @returns A component ref for the associated layer host.
*/
export function getLayerHost(hostId) {
var layerHosts = _layerHostsById[hostId];
return (layerHosts && layerHosts[0]) || undefined;
}
/**
* Registers a Layer Host with an associated hostId.
* @param hostId - Id of the layer host
* @param layerHost - layer host instance
*/
export function registerLayerHost(hostId, layerHost) {
var layerHosts = _layerHostsById[hostId] || (_layerHostsById[hostId] = []);
// Insert this at the start of an array to avoid race conditions between mount and unmount.
// If a LayerHost is re-mounted, and mount of the new instance may occur before the unmount of the old one.
// Putting the new instance at the start of this array ensures that calls to `getLayerHost` will immediately
// get the new one even if the old one is around briefly.
layerHosts.unshift(layerHost);
}
/**
* Unregisters a Layer Host from the associated hostId.
* @param hostId - Id of the layer host
* @param layerHost - layer host instance
*/
export function unregisterLayerHost(hostId, layerHost) {
var layerHosts = _layerHostsById[hostId];
if (layerHosts) {
var idx = layerHosts.indexOf(layerHost);
if (idx >= 0) {
layerHosts.splice(idx, 1);
}
if (layerHosts.length === 0) {
delete _layerHostsById[hostId];
}
}
}
/**
* When no default layer host is provided, this function is executed to create the default host.
*/
export function createDefaultLayerHost(doc, shadowRoot) {
if (shadowRoot === void 0) { shadowRoot = null; }
var host = doc.createElement('div');
host.setAttribute('id', defaultHostId);
host.style.cssText = 'position:fixed;z-index:1000000';
if (shadowRoot) {
shadowRoot.appendChild(host);
}
else {
doc === null || doc === void 0 ? void 0 : doc.body.appendChild(host);
}
// doc?.body.appendChild(host);
return host;
}
/**
* This function can be optionally called to clean up the default layer host as needed.
*/
export function cleanupDefaultLayerHost(doc, shadowRoot) {
if (shadowRoot === void 0) { shadowRoot = null; }
var root = shadowRoot !== null && shadowRoot !== void 0 ? shadowRoot : doc;
var host = root.querySelector("#".concat(defaultHostId));
if (host) {
root.removeChild(host);
}
}
/**
* Used for notifying applicable Layers that a host is available/unavailable and to re-evaluate Layers that
* care about the specific host.
*/
export function notifyHostChanged(id) {
if (_layersByHostId[id]) {
_layersByHostId[id].forEach(function (callback) { return callback(); });
}
}
/**
* Sets the default target selector to use when determining the host in which
* Layered content will be injected into. If not provided, an element will be
* created at the end of the document body.
*
* Passing in a falsy value will clear the default target and reset back to
* using a created element at the end of document body.
*/
export function setDefaultTarget(selector) {
_defaultHostSelector = selector;
}
/**
* Get the default target selector when determining a host
*/
export function getDefaultTarget() {
return _defaultHostSelector;
}
//# sourceMappingURL=Layer.notification.js.map
File diff suppressed because one or more lines are too long
+2
View File
@@ -0,0 +1,2 @@
import type { ILayerStyleProps, ILayerStyles } from './Layer.types';
export declare const getStyles: (props: ILayerStyleProps) => ILayerStyles;
+36
View File
@@ -0,0 +1,36 @@
import { ZIndexes, getGlobalClassNames } from '../../Styling';
var GlobalClassNames = {
root: 'ms-Layer',
rootNoHost: 'ms-Layer--fixed',
content: 'ms-Layer-content',
};
export var getStyles = function (props) {
var className = props.className, isNotHost = props.isNotHost, theme = props.theme;
var classNames = getGlobalClassNames(GlobalClassNames, theme);
return {
root: [
classNames.root,
theme.fonts.medium,
isNotHost && [
classNames.rootNoHost,
{
position: 'fixed',
zIndex: ZIndexes.Layer,
top: 0,
left: 0,
bottom: 0,
right: 0,
visibility: 'hidden',
},
],
className,
],
content: [
classNames.content,
{
visibility: 'visible',
},
],
};
};
//# sourceMappingURL=Layer.styles.js.map
@@ -0,0 +1 @@
{"version":3,"file":"Layer.styles.js","sourceRoot":"../src/","sources":["components/Layer/Layer.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAG9D,IAAM,gBAAgB,GAAG;IACvB,IAAI,EAAE,UAAU;IAChB,UAAU,EAAE,iBAAiB;IAC7B,OAAO,EAAE,kBAAkB;CAC5B,CAAC;AAEF,MAAM,CAAC,IAAM,SAAS,GAAG,UAAC,KAAuB;IACvC,IAAA,SAAS,GAAuB,KAAK,UAA5B,EAAE,SAAS,GAAY,KAAK,UAAjB,EAAE,KAAK,GAAK,KAAK,MAAV,CAAW;IAE9C,IAAM,UAAU,GAAG,mBAAmB,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;IAEhE,OAAO;QACL,IAAI,EAAE;YACJ,UAAU,CAAC,IAAI;YACf,KAAK,CAAC,KAAK,CAAC,MAAM;YAClB,SAAS,IAAI;gBACX,UAAU,CAAC,UAAU;gBACrB;oBACE,QAAQ,EAAE,OAAO;oBACjB,MAAM,EAAE,QAAQ,CAAC,KAAK;oBACtB,GAAG,EAAE,CAAC;oBACN,IAAI,EAAE,CAAC;oBACP,MAAM,EAAE,CAAC;oBACT,KAAK,EAAE,CAAC;oBACR,UAAU,EAAE,QAAQ;iBACrB;aACF;YACD,SAAS;SACV;QACD,OAAO,EAAE;YACP,UAAU,CAAC,OAAO;YAClB;gBACE,UAAU,EAAE,SAAS;aACtB;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { ZIndexes, getGlobalClassNames } from '../../Styling';\nimport type { ILayerStyleProps, ILayerStyles } from './Layer.types';\n\nconst GlobalClassNames = {\n root: 'ms-Layer',\n rootNoHost: 'ms-Layer--fixed',\n content: 'ms-Layer-content',\n};\n\nexport const getStyles = (props: ILayerStyleProps): ILayerStyles => {\n const { className, isNotHost, theme } = props;\n\n const classNames = getGlobalClassNames(GlobalClassNames, theme);\n\n return {\n root: [\n classNames.root,\n theme.fonts.medium,\n isNotHost && [\n classNames.rootNoHost,\n {\n position: 'fixed',\n zIndex: ZIndexes.Layer,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n visibility: 'hidden',\n },\n ],\n className,\n ],\n content: [\n classNames.content,\n {\n visibility: 'visible',\n },\n ],\n };\n};\n"]}
+98
View File
@@ -0,0 +1,98 @@
import * as React from 'react';
import type { IFabricProps } from '../../Fabric';
import type { IStyle, ITheme } from '../../Styling';
import type { IRefObject, IStyleFunctionOrObject } from '../../Utilities';
/**
* {@docCategory Layer}
*/
export interface ILayer {
}
/**
* {@docCategory Layer}
*/
export interface ILayerProps extends React.HTMLAttributes<HTMLDivElement>, React.RefAttributes<HTMLDivElement> {
/**
* Optional callback to access the ILayer interface. Use this instead of ref for accessing
* the public methods and properties of the component.
*/
componentRef?: IRefObject<ILayer>;
/**
* Call to provide customized styling that will layer on top of the variant rules
*/
styles?: IStyleFunctionOrObject<ILayerStyleProps, ILayerStyles>;
/**
* Theme provided by HOC.
*/
theme?: ITheme;
/**
* Additional css class to apply to the Layer
* @defaultvalue undefined
*/
className?: string;
/**
* Callback for when the layer is mounted.
* @deprecated Use `onLayerDidMount`.
*/
onLayerMounted?: () => void;
/**
* Callback for when the layer is mounted.
*/
onLayerDidMount?: () => void;
/**
* Callback for when the layer is unmounted.
*/
onLayerWillUnmount?: () => void;
/**
* The optional id property provided on a LayerHost that this Layer should render within. The LayerHost does
* not need to be immediately available but once has been rendered, and if missing, we'll avoid trying
* to render the Layer content until the host is available. If an id is not provided, we will render the Layer
* content in a fixed position element rendered at the end of the document.
*/
hostId?: string;
/**
* When enabled, Layer allows events to bubble up from Layer content.
* Traditionally Layer has not had this behavior. This prop preserves backwards compatibility by
* default while allowing users to opt in to the new event bubbling functionality.
*/
eventBubblingEnabled?: boolean;
/**
* Whether the layer should be added as the first child of the host.
* If true, the layer will be inserted as the first child of the host
* By default, the layer will be appended at the end to the host
*/
insertFirst?: boolean;
/**
* Props bag to forward to the Fabric component to allow customization of its behavior.
*/
fabricProps?: IFabricProps;
}
/**
* {@docCategory Layer}
*/
export interface ILayerStyleProps {
/**
* Accept theme prop.
*/
theme: ITheme;
/**
* Accept custom classNames
*/
className?: string;
/**
* Check if Host
*/
isNotHost?: boolean;
}
/**
* {@docCategory Layer}
*/
export interface ILayerStyles {
/**
* Style for the root element when fixed.
*/
root?: IStyle;
/**
* Style for the Fabric component.
*/
content?: IStyle;
}
+2
View File
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=Layer.types.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"Layer.types.js","sourceRoot":"../src/","sources":["components/Layer/Layer.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { IFabricProps } from '../../Fabric';\nimport type { IStyle, ITheme } from '../../Styling';\nimport type { IRefObject, IStyleFunctionOrObject } from '../../Utilities';\n\n/**\n * {@docCategory Layer}\n */\nexport interface ILayer {}\n\n/**\n * {@docCategory Layer}\n */\nexport interface ILayerProps extends React.HTMLAttributes<HTMLDivElement>, React.RefAttributes<HTMLDivElement> {\n /**\n * Optional callback to access the ILayer interface. Use this instead of ref for accessing\n * the public methods and properties of the component.\n */\n componentRef?: IRefObject<ILayer>;\n\n /**\n * Call to provide customized styling that will layer on top of the variant rules\n */\n styles?: IStyleFunctionOrObject<ILayerStyleProps, ILayerStyles>;\n\n /**\n * Theme provided by HOC.\n */\n theme?: ITheme;\n\n /**\n * Additional css class to apply to the Layer\n * @defaultvalue undefined\n */\n className?: string;\n\n /**\n * Callback for when the layer is mounted.\n * @deprecated Use `onLayerDidMount`.\n */\n onLayerMounted?: () => void;\n\n /**\n * Callback for when the layer is mounted.\n */\n onLayerDidMount?: () => void;\n\n /**\n * Callback for when the layer is unmounted.\n */\n onLayerWillUnmount?: () => void;\n\n /**\n * The optional id property provided on a LayerHost that this Layer should render within. The LayerHost does\n * not need to be immediately available but once has been rendered, and if missing, we'll avoid trying\n * to render the Layer content until the host is available. If an id is not provided, we will render the Layer\n * content in a fixed position element rendered at the end of the document.\n */\n hostId?: string;\n\n /**\n * When enabled, Layer allows events to bubble up from Layer content.\n * Traditionally Layer has not had this behavior. This prop preserves backwards compatibility by\n * default while allowing users to opt in to the new event bubbling functionality.\n */\n eventBubblingEnabled?: boolean;\n\n /**\n * Whether the layer should be added as the first child of the host.\n * If true, the layer will be inserted as the first child of the host\n * By default, the layer will be appended at the end to the host\n */\n insertFirst?: boolean;\n\n /**\n * Props bag to forward to the Fabric component to allow customization of its behavior.\n */\n fabricProps?: IFabricProps;\n}\n\n/**\n * {@docCategory Layer}\n */\nexport interface ILayerStyleProps {\n /**\n * Accept theme prop.\n */\n theme: ITheme;\n\n /**\n * Accept custom classNames\n */\n className?: string;\n\n /**\n * Check if Host\n */\n isNotHost?: boolean;\n}\n\n/**\n * {@docCategory Layer}\n */\nexport interface ILayerStyles {\n /**\n * Style for the root element when fixed.\n */\n root?: IStyle;\n /**\n * Style for the Fabric component.\n */\n content?: IStyle;\n}\n"]}
+3
View File
@@ -0,0 +1,3 @@
import * as React from 'react';
import type { ILayerHostProps } from './LayerHost.types';
export declare const LayerHost: React.FunctionComponent<ILayerHostProps>;
+29
View File
@@ -0,0 +1,29 @@
import { __assign } from "tslib";
import * as React from 'react';
import { useUnmount } from '@fluentui/react-hooks';
import { css, getId } from '../../Utilities';
import { notifyHostChanged, registerLayerHost, unregisterLayerHost } from './Layer.notification';
export var LayerHost = function (props) {
var className = props.className;
var layerHostId = React.useState(function () { return getId(); })[0];
var _a = props.id, hostId = _a === void 0 ? layerHostId : _a;
var layerHostRef = React.useRef({
hostId: hostId,
rootRef: React.useRef(null),
notifyLayersChanged: function () {
// Nothing, since the default implementation of Layer Host does not need to react to layer changes.
},
});
React.useImperativeHandle(props.componentRef, function () { return layerHostRef.current; });
React.useEffect(function () {
registerLayerHost(hostId, layerHostRef.current);
notifyHostChanged(hostId);
// eslint-disable-next-line react-hooks/exhaustive-deps -- should only run on first render
}, []);
useUnmount(function () {
unregisterLayerHost(hostId, layerHostRef.current);
notifyHostChanged(hostId);
});
return React.createElement("div", __assign({}, props, { className: css('ms-LayerHost', className), ref: layerHostRef.current.rootRef }));
};
//# sourceMappingURL=LayerHost.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"LayerHost.js","sourceRoot":"../src/","sources":["components/Layer/LayerHost.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAGjG,MAAM,CAAC,IAAM,SAAS,GAA6C,UAAA,KAAK;IAC9D,IAAA,SAAS,GAAK,KAAK,UAAV,CAAW;IAErB,IAAA,WAAW,GAAI,KAAK,CAAC,QAAQ,CAAC,cAAM,OAAA,KAAK,EAAE,EAAP,CAAO,CAAC,GAAjC,CAAkC;IAE5C,IAAA,KAA6B,KAAK,GAAV,EAApB,MAAM,mBAAG,WAAW,KAAA,CAAW;IAE3C,IAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAa;QAC5C,MAAM,QAAA;QACN,OAAO,EAAE,KAAK,CAAC,MAAM,CAAwB,IAAI,CAAC;QAClD,mBAAmB,EAAE;YACnB,mGAAmG;QACrG,CAAC;KACF,CAAC,CAAC;IAEH,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC,YAAY,EAAE,cAAM,OAAA,YAAY,CAAC,OAAO,EAApB,CAAoB,CAAC,CAAC;IAE1E,KAAK,CAAC,SAAS,CAAC;QACd,iBAAiB,CAAC,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;QAChD,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAC1B,0FAA0F;IAC5F,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,UAAU,CAAC;QACT,mBAAmB,CAAC,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;QAClD,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,OAAO,wCAAS,KAAK,IAAE,SAAS,EAAE,GAAG,CAAC,cAAc,EAAE,SAAS,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC;AAC1G,CAAC,CAAC","sourcesContent":["import * as React from 'react';\nimport { useUnmount } from '@fluentui/react-hooks';\nimport { css, getId } from '../../Utilities';\nimport { notifyHostChanged, registerLayerHost, unregisterLayerHost } from './Layer.notification';\nimport type { ILayerHost, ILayerHostProps } from './LayerHost.types';\n\nexport const LayerHost: React.FunctionComponent<ILayerHostProps> = props => {\n const { className } = props;\n\n const [layerHostId] = React.useState(() => getId());\n\n const { id: hostId = layerHostId } = props;\n\n const layerHostRef = React.useRef<ILayerHost>({\n hostId,\n rootRef: React.useRef<HTMLDivElement | null>(null),\n notifyLayersChanged: () => {\n // Nothing, since the default implementation of Layer Host does not need to react to layer changes.\n },\n });\n\n React.useImperativeHandle(props.componentRef, () => layerHostRef.current);\n\n React.useEffect(() => {\n registerLayerHost(hostId, layerHostRef.current);\n notifyHostChanged(hostId);\n // eslint-disable-next-line react-hooks/exhaustive-deps -- should only run on first render\n }, []);\n\n useUnmount(() => {\n unregisterLayerHost(hostId, layerHostRef.current);\n notifyHostChanged(hostId);\n });\n\n return <div {...props} className={css('ms-LayerHost', className)} ref={layerHostRef.current.rootRef} />;\n};\n"]}
+31
View File
@@ -0,0 +1,31 @@
import * as React from 'react';
import type { IRefObject } from '../../Utilities';
/**
* Represents a mounted layer host, and provides access to its `hostId` and root element.
*/
export interface ILayerHost {
/**
* The hostId for this host, to be propagatd to layers using Customizer.
*/
hostId: string;
/**
* An element ref to the layer host's content root.
* This is the element to which layers will be added.
*/
rootRef: React.MutableRefObject<HTMLDivElement | null>;
/**
* Notifies the layer host that layers may have been added or removed within its root element.
*/
notifyLayersChanged(): void;
}
export interface ILayerHostProps extends React.HTMLAttributes<HTMLElement> {
/**
* Optional callback to access the ILayerHost interface. Use this instead of ref for accessing
* the public methods and properties of the component.
*/
componentRef?: IRefObject<ILayerHost>;
/**
* Defines the id for the layer host that Layers can target (using the hostId property.)
*/
id?: string;
}
+2
View File
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=LayerHost.types.js.map
@@ -0,0 +1 @@
{"version":3,"file":"LayerHost.types.js","sourceRoot":"../src/","sources":["components/Layer/LayerHost.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { IRefObject } from '../../Utilities';\n\n/**\n * Represents a mounted layer host, and provides access to its `hostId` and root element.\n */\nexport interface ILayerHost {\n /**\n * The hostId for this host, to be propagatd to layers using Customizer.\n */\n hostId: string;\n /**\n * An element ref to the layer host's content root.\n * This is the element to which layers will be added.\n */\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n rootRef: React.MutableRefObject<HTMLDivElement | null>;\n /**\n * Notifies the layer host that layers may have been added or removed within its root element.\n */\n notifyLayersChanged(): void;\n}\n\nexport interface ILayerHostProps extends React.HTMLAttributes<HTMLElement> {\n /**\n * Optional callback to access the ILayerHost interface. Use this instead of ref for accessing\n * the public methods and properties of the component.\n */\n componentRef?: IRefObject<ILayerHost>;\n\n /**\n * Defines the id for the layer host that Layers can target (using the hostId property.)\n */\n id?: string;\n}\n"]}
+7
View File
@@ -0,0 +1,7 @@
export * from './Layer';
export * from './Layer.base';
export * from './Layer.types';
export * from './LayerHost';
export * from './LayerHost.types';
export { createDefaultLayerHost, cleanupDefaultLayerHost, getDefaultTarget as getLayerHostSelector, getLayerCount, getLayerHost, notifyHostChanged, registerLayer, registerLayerHost, setDefaultTarget as setLayerHostSelector, unregisterLayer, unregisterLayerHost, } from './Layer.notification';
export { getStyles as getLayerStyles } from './Layer.styles';
+8
View File
@@ -0,0 +1,8 @@
export * from './Layer';
export * from './Layer.base';
export * from './Layer.types';
export * from './LayerHost';
export * from './LayerHost.types';
export { createDefaultLayerHost, cleanupDefaultLayerHost, getDefaultTarget as getLayerHostSelector, getLayerCount, getLayerHost, notifyHostChanged, registerLayer, registerLayerHost, setDefaultTarget as setLayerHostSelector, unregisterLayer, unregisterLayerHost, } from './Layer.notification';
export { getStyles as getLayerStyles } from './Layer.styles';
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Layer/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,gBAAgB,IAAI,oBAAoB,EACxC,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,gBAAgB,IAAI,oBAAoB,EACxC,eAAe,EACf,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,SAAS,IAAI,cAAc,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export * from './Layer';\nexport * from './Layer.base';\nexport * from './Layer.types';\nexport * from './LayerHost';\nexport * from './LayerHost.types';\nexport {\n createDefaultLayerHost,\n cleanupDefaultLayerHost,\n getDefaultTarget as getLayerHostSelector,\n getLayerCount,\n getLayerHost,\n notifyHostChanged,\n registerLayer,\n registerLayerHost,\n setDefaultTarget as setLayerHostSelector,\n unregisterLayer,\n unregisterLayerHost,\n} from './Layer.notification';\nexport { getStyles as getLayerStyles } from './Layer.styles';\n"]}