Private
Public Access
1
0

feat: Fluent UI Outlook Lite + connections mockup

This commit is contained in:
2026-04-14 18:52:25 +00:00
parent 1199eff6c3
commit dfa4010406
34820 changed files with 1003813 additions and 205 deletions

View File

@@ -0,0 +1,64 @@
import * as React from 'react';
import { SLOT_ELEMENT_TYPE_SYMBOL } from './constants';
import { isSlot } from './isSlot';
import * as slot from './slot';
/**
* @internal
* Assertion method to ensure state slots properties are properly declared.
* A properly declared slot must be declared by using the `slot` method.
*
* @example
* ```tsx
* export const renderInput_unstable = (state: InputState): JSXElement => {
assertSlots<InputSlots>(state);
return (
<state.root>
{state.contentBefore && <state.contentBefore />}
<state.input />
{state.contentAfter && <state.contentAfter />}
</state.root>
);
};
* ```
*/ export function assertSlots(state) {
/**
* This verification is not necessary in production
* as we're verifying static properties that will not change between environments
*/ if (process.env.NODE_ENV !== 'production') {
const typedState = state;
// eslint-disable-next-line @typescript-eslint/no-deprecated
for (const slotName of Object.keys(typedState.components)){
const slotElement = typedState[slotName];
if (slotElement === undefined) {
continue;
}
// this means a slot is being declared without using, slot.always or slot.optional or even resolveShorthand on the state hook,
// but the render method is using the new `assertSlots` method. That scenario can be solved by simply updating the slot element with the proper element type
// FIXME: this slot will still fail to support child render function scenario
if (!isSlot(slotElement)) {
typedState[slotName] = slot.always(slotElement, {
// eslint-disable-next-line @typescript-eslint/no-deprecated
elementType: typedState.components[slotName]
});
// eslint-disable-next-line no-console
console.warn(`@fluentui/react-utilities [${assertSlots.name}]:
"state.${slotName}" is not a slot!
Be sure to create slots properly by using "slot.always" or "slot.optional".`);
} else {
// This means a slot is being declared by using resolveShorthand on the state hook,
// but the render method is using the new `assertSlots` method. That scenario can be solved by simply updating the slot element with the proper element type
const { [SLOT_ELEMENT_TYPE_SYMBOL]: elementType } = slotElement;
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (elementType !== typedState.components[slotName]) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
slotElement[SLOT_ELEMENT_TYPE_SYMBOL] = typedState.components[slotName];
// eslint-disable-next-line no-console
console.warn(`@fluentui/react-utilities [${assertSlots.name}]:
"state.${slotName}" element type differs from "state.components.${slotName}",
${elementType} !== ${typedState.components[slotName]}.
Be sure to create slots properly by using "slot.always" or "slot.optional" with the correct elementType.`);
}
}
}
}
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,12 @@
/**
* @internal
* Internal reference for the render function
*/ export const SLOT_RENDER_FUNCTION_SYMBOL = Symbol.for('fui.slotRenderFunction');
/**
* @internal
* Internal reference for the render function
*/ export const SLOT_ELEMENT_TYPE_SYMBOL = Symbol.for('fui.slotElementType');
/**
* @internal
* Internal cache of the original className prop for the slot, before being modified by the useStyles hook.
*/ export const SLOT_CLASS_NAME_PROP_SYMBOL = Symbol.for('fui.slotClassNameProp');

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/compose/constants.ts"],"sourcesContent":["/**\n * @internal\n * Internal reference for the render function\n */\nexport const SLOT_RENDER_FUNCTION_SYMBOL = Symbol.for('fui.slotRenderFunction');\n/**\n * @internal\n * Internal reference for the render function\n */\nexport const SLOT_ELEMENT_TYPE_SYMBOL = Symbol.for('fui.slotElementType');\n/**\n * @internal\n * Internal cache of the original className prop for the slot, before being modified by the useStyles hook.\n */\nexport const SLOT_CLASS_NAME_PROP_SYMBOL = Symbol.for('fui.slotClassNameProp');\n"],"names":["SLOT_RENDER_FUNCTION_SYMBOL","Symbol","for","SLOT_ELEMENT_TYPE_SYMBOL","SLOT_CLASS_NAME_PROP_SYMBOL"],"mappings":"AAAA;;;CAGC,GACD,OAAO,MAAMA,8BAA8BC,OAAOC,GAAG,CAAC,0BAA0B;AAChF;;;CAGC,GACD,OAAO,MAAMC,2BAA2BF,OAAOC,GAAG,CAAC,uBAAuB;AAC1E;;;CAGC,GACD,OAAO,MAAME,8BAA8BH,OAAOC,GAAG,CAAC,yBAAyB"}

View File

@@ -0,0 +1,75 @@
import * as React from 'react';
import { omit } from '../../utils/omit';
import { isSlot } from '../isSlot';
import { SLOT_RENDER_FUNCTION_SYMBOL } from '../constants';
/**
* Given the state and an array of slot names, will break out `slots` and `slotProps`
* collections.
*
* The root is derived from a mix of `components` props and `as` prop.
*
* Slots will render as null if they are rendered as primitives with undefined children.
*
* The slotProps will always omit the `as` prop within them, and for slots that are string
* primitives, the props will be filtered according to the slot type by the type system.
* For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable
* anchor props. Note that this is only enforced at build time by Typescript -- there is no
* runtime code filtering props in this function.
*
* @deprecated use slot.always or slot.optional combined with assertSlots instead
*
* @param state - State including slot definitions
* @returns An object containing the `slots` map and `slotProps` map.
*/ export function getSlots(state) {
const typeState = state;
// eslint-disable-next-line @typescript-eslint/no-deprecated
const slots = {};
const slotProps = {};
// eslint-disable-next-line @typescript-eslint/no-deprecated
const slotNames = Object.keys(typeState.components);
for (const slotName of slotNames){
const [slot, props] = getSlot(typeState, slotName);
// eslint-disable-next-line @typescript-eslint/no-deprecated
slots[slotName] = slot;
slotProps[slotName] = props;
}
// eslint-disable-next-line @typescript-eslint/no-deprecated
return {
slots,
slotProps: slotProps
};
}
function getSlot(state, slotName) {
var _state_components, _state_components1;
const props = state[slotName];
if (props === undefined) {
return [
null,
undefined
];
}
// TS Error: Property 'as' does not exist on type 'UnknownSlotProps | undefined'.ts(2339)
const { as: asProp, children, ...rest } = props;
const renderFunction = isSlot(props) ? props[SLOT_RENDER_FUNCTION_SYMBOL] : undefined;
const slot = ((_state_components = state.components) === null || _state_components === void 0 ? void 0 : _state_components[slotName]) === undefined || // eslint-disable-line @typescript-eslint/no-deprecated
// eslint-disable-next-line @typescript-eslint/no-deprecated
typeof state.components[slotName] === 'string' ? asProp || ((_state_components1 = state.components) === null || _state_components1 === void 0 ? void 0 : _state_components1[slotName]) || 'div' : state.components[slotName];
const asserted = slot;
if (renderFunction || typeof children === 'function') {
const render = renderFunction || children;
return [
React.Fragment,
{
children: render(asserted, rest)
}
];
}
const shouldOmitAsProp = typeof slot === 'string' && asProp;
const slotProps = shouldOmitAsProp ? omit(props, [
'as'
]) : props;
return [
asserted,
slotProps
];
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,53 @@
import * as React from 'react';
/**
* Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma
*
* @internal
* This is an internal temporary method, this method will cease to exist eventually!
*
* * ❗️❗️ **DO NOT USE IT EXTERNALLY** ❗️❗️
*
* @deprecated use slot.always or slot.optional combined with assertSlots instead
*/ export function getSlotsNext(state) {
const typedState = state;
// eslint-disable-next-line @typescript-eslint/no-deprecated
const slots = {};
const slotProps = {};
// eslint-disable-next-line @typescript-eslint/no-deprecated
const slotNames = Object.keys(typedState.components);
for (const slotName of slotNames){
// eslint-disable-next-line @typescript-eslint/no-deprecated
const [slot, props] = getSlotNext(typedState, slotName);
// eslint-disable-next-line @typescript-eslint/no-deprecated
slots[slotName] = slot;
slotProps[slotName] = props;
}
// eslint-disable-next-line @typescript-eslint/no-deprecated
return {
slots,
slotProps: slotProps
};
}
/**
* @deprecated use slot.always or slot.optional combined with assertSlots instead
*/ function getSlotNext(state, slotName) {
var _state_components, _state_components1;
const props = state[slotName];
if (props === undefined) {
return [
null,
undefined
];
}
// TS Error: Property 'as' does not exist on type 'UnknownSlotProps | undefined'.ts(2339)
const { as: asProp, ...propsWithoutAs } = props;
const slot = ((_state_components = state.components) === null || _state_components === void 0 ? void 0 : _state_components[slotName]) === undefined || // eslint-disable-line @typescript-eslint/no-deprecated
// eslint-disable-next-line @typescript-eslint/no-deprecated
typeof state.components[slotName] === 'string' ? asProp || ((_state_components1 = state.components) === null || _state_components1 === void 0 ? void 0 : _state_components1[slotName]) || 'div' : state.components[slotName];
const shouldOmitAsProp = typeof slot === 'string' && asProp;
const slotProps = shouldOmitAsProp ? propsWithoutAs : props;
return [
slot,
slotProps
];
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/compose/deprecated/getSlotsNext.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComponentState, SlotPropsRecord, UnknownSlotProps } from '../types';\nimport { ObjectSlotProps, Slots } from './getSlots';\n\n/**\n * Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma\n *\n * @internal\n * This is an internal temporary method, this method will cease to exist eventually!\n *\n * * ❗️❗️ **DO NOT USE IT EXTERNALLY** ❗️❗️\n *\n * @deprecated use slot.always or slot.optional combined with assertSlots instead\n */\nexport function getSlotsNext<R extends SlotPropsRecord>(\n state: unknown,\n): {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n slots: Slots<R>;\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n slotProps: ObjectSlotProps<R>;\n} {\n const typedState = state as ComponentState<R>;\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const slots = {} as Slots<R>;\n const slotProps = {} as R;\n\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const slotNames: (keyof R)[] = Object.keys(typedState.components);\n for (const slotName of slotNames) {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const [slot, props] = getSlotNext(typedState, slotName);\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n slots[slotName] = slot as Slots<R>[typeof slotName];\n slotProps[slotName] = props;\n }\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n return { slots, slotProps: slotProps as unknown as ObjectSlotProps<R> };\n}\n\n/**\n * @deprecated use slot.always or slot.optional combined with assertSlots instead\n */\nfunction getSlotNext<R extends SlotPropsRecord, K extends keyof R>(\n state: ComponentState<R>,\n slotName: K,\n): readonly [React.ElementType<R[K]> | null, R[K]] {\n const props = state[slotName];\n\n if (props === undefined) {\n return [null, undefined as R[K]];\n }\n\n type NonUndefined<T> = T extends undefined ? never : T;\n // TS Error: Property 'as' does not exist on type 'UnknownSlotProps | undefined'.ts(2339)\n const { as: asProp, ...propsWithoutAs } = props as NonUndefined<typeof props>;\n\n const slot = (\n state.components?.[slotName] === undefined || // eslint-disable-line @typescript-eslint/no-deprecated\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n typeof state.components[slotName] === 'string'\n ? // eslint-disable-next-line @typescript-eslint/no-deprecated\n asProp || state.components?.[slotName] || 'div'\n : // eslint-disable-next-line @typescript-eslint/no-deprecated\n state.components[slotName]\n ) as React.ElementType<R[K]>;\n\n const shouldOmitAsProp = typeof slot === 'string' && asProp;\n const slotProps: UnknownSlotProps = shouldOmitAsProp ? propsWithoutAs : props;\n\n return [slot as React.ElementType<R[K]>, slotProps as R[K]];\n}\n"],"names":["React","getSlotsNext","state","typedState","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlotNext","undefined","as","asProp","propsWithoutAs","shouldOmitAsProp"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAI/B;;;;;;;;;CASC,GACD,OAAO,SAASC,aACdC,KAAc;IAOd,MAAMC,aAAaD;IACnB,4DAA4D;IAC5D,MAAME,QAAQ,CAAC;IACf,MAAMC,YAAY,CAAC;IAEnB,4DAA4D;IAC5D,MAAMC,YAAyBC,OAAOC,IAAI,CAACL,WAAWM,UAAU;IAChE,KAAK,MAAMC,YAAYJ,UAAW;QAChC,4DAA4D;QAC5D,MAAM,CAACK,MAAMC,MAAM,GAAGC,YAAYV,YAAYO;QAC9C,4DAA4D;QAC5DN,KAAK,CAACM,SAAS,GAAGC;QAClBN,SAAS,CAACK,SAAS,GAAGE;IACxB;IACA,4DAA4D;IAC5D,OAAO;QAAER;QAAOC,WAAWA;IAA2C;AACxE;AAEA;;CAEC,GACD,SAASQ,YACPX,KAAwB,EACxBQ,QAAW;QAaTR,mBAIcA;IAfhB,MAAMU,QAAQV,KAAK,CAACQ,SAAS;IAE7B,IAAIE,UAAUE,WAAW;QACvB,OAAO;YAAC;YAAMA;SAAkB;IAClC;IAGA,yFAAyF;IACzF,MAAM,EAAEC,IAAIC,MAAM,EAAE,GAAGC,gBAAgB,GAAGL;IAE1C,MAAMD,OACJT,EAAAA,oBAAAA,MAAMO,UAAU,cAAhBP,wCAAAA,iBAAkB,CAACQ,SAAS,MAAKI,aAAa,uDAAuD;IACrG,4DAA4D;IAC5D,OAAOZ,MAAMO,UAAU,CAACC,SAAS,KAAK,WAElCM,YAAUd,qBAAAA,MAAMO,UAAU,cAAhBP,yCAAAA,kBAAkB,CAACQ,SAAS,KAAI,QAE1CR,MAAMO,UAAU,CAACC,SAAS;IAGhC,MAAMQ,mBAAmB,OAAOP,SAAS,YAAYK;IACrD,MAAMX,YAA8Ba,mBAAmBD,iBAAiBL;IAExE,OAAO;QAACD;QAAiCN;KAAkB;AAC7D"}

View File

@@ -0,0 +1,17 @@
import * as slot from '../slot';
/**
*
* Resolves shorthands into slot props, to ensure normalization of the signature
* being passed down to getSlots method
* @param value - the base shorthand props
* @param options - options to resolve shorthand props
*
* @deprecated use slot.always, slot.optional, slot.resolveShorthand combined with assertSlots instead
*/ // eslint-disable-next-line @typescript-eslint/no-deprecated
export const resolveShorthand = (value, options)=>slot.optional(value, {
...options,
renderByDefault: options === null || options === void 0 ? void 0 : options.required,
// elementType as undefined is the way to identify between a slot and a resolveShorthand call
// in the case elementType is undefined assertSlots will fail, ensuring it'll only work with slot method.
elementType: undefined
});

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/compose/deprecated/resolveShorthand.ts"],"sourcesContent":["import * as slot from '../slot';\nimport type { UnknownSlotProps, SlotShorthandValue, WithoutSlotRenderFunction } from '../types';\n\n/**\n * @deprecated - use slot.always or slot.optional combined with assertSlots instead\n */\nexport type ResolveShorthandOptions<Props, Required extends boolean = false> = Required extends true\n ? { required: true; defaultProps?: Props }\n : { required?: Required; defaultProps?: Props };\n\n/**\n * @deprecated use slot.always or slot.optional combined with assertSlots instead\n */\nexport type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {\n <P extends Props>(\n value: P | SlotShorthandValue | undefined,\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n options: ResolveShorthandOptions<P, true>,\n ): WithoutSlotRenderFunction<P>;\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <P extends Props>(value: P | SlotShorthandValue | null | undefined, options?: ResolveShorthandOptions<P, boolean>):\n | WithoutSlotRenderFunction<P>\n | undefined;\n};\n\n/**\n *\n * Resolves shorthands into slot props, to ensure normalization of the signature\n * being passed down to getSlots method\n * @param value - the base shorthand props\n * @param options - options to resolve shorthand props\n *\n * @deprecated use slot.always, slot.optional, slot.resolveShorthand combined with assertSlots instead\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport const resolveShorthand: ResolveShorthandFunction<UnknownSlotProps> = (value, options) =>\n slot.optional<UnknownSlotProps>(value, {\n ...options,\n renderByDefault: options?.required,\n // elementType as undefined is the way to identify between a slot and a resolveShorthand call\n // in the case elementType is undefined assertSlots will fail, ensuring it'll only work with slot method.\n elementType: undefined!,\n }) as WithoutSlotRenderFunction<UnknownSlotProps>;\n"],"names":["slot","resolveShorthand","value","options","optional","renderByDefault","required","elementType","undefined"],"mappings":"AAAA,YAAYA,UAAU,UAAU;AAyBhC;;;;;;;;CAQC,GACD,4DAA4D;AAC5D,OAAO,MAAMC,mBAA+D,CAACC,OAAOC,UAClFH,KAAKI,QAAQ,CAAmBF,OAAO;QACrC,GAAGC,OAAO;QACVE,eAAe,EAAEF,oBAAAA,8BAAAA,QAASG,QAAQ;QAClC,6FAA6F;QAC7F,yGAAyG;QACzGC,aAAaC;IACf,GAAkD"}

View File

@@ -0,0 +1,17 @@
import * as React from 'react';
import { getNativeElementProps } from '../utils/getNativeElementProps';
/**
* Given an element tagname and user props, filters the props to only allowed props for the given
* element type.
*
* Equivalent to {@link getNativeElementProps}, but more type-safe.
*
* @param tagName - The slot's default element type (e.g. 'div')
* @param props - The component's props object
* @param excludedPropNames - List of native props to exclude from the returned value
*/ export const getIntrinsicElementProps = (tagName, // eslint-disable-next-line @typescript-eslint/no-restricted-types -- in order to not introduce Type Restriction CHANGe which is kinda "breaking change from Types POV", we don't enforce our custom `RefAttributes` in this API, to be compatible with scenarios where non v9 interfaces might be used. This may/will change with React 19
props, excludedPropNames)=>{
var _props_as;
// eslint-disable-next-line @typescript-eslint/no-deprecated
return getNativeElementProps((_props_as = props.as) !== null && _props_as !== void 0 ? _props_as : tagName, props, excludedPropNames);
};

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/compose/getIntrinsicElementProps.ts"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps } from '../utils/getNativeElementProps';\nimport type { InferredElementRefType, UnknownSlotProps } from './types';\nimport type { DistributiveOmit } from '../utils/types';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype HTMLAttributes = React.HTMLAttributes<any>;\n\n/**\n * Given an element tagname and user props, filters the props to only allowed props for the given\n * element type.\n *\n * Equivalent to {@link getNativeElementProps}, but more type-safe.\n *\n * @param tagName - The slot's default element type (e.g. 'div')\n * @param props - The component's props object\n * @param excludedPropNames - List of native props to exclude from the returned value\n */\nexport const getIntrinsicElementProps = <\n Props extends UnknownSlotProps,\n ExcludedPropKeys extends Extract<keyof Props, string> = never,\n>(\n tagName: NonNullable<Props['as']>,\n // eslint-disable-next-line @typescript-eslint/no-restricted-types -- in order to not introduce Type Restriction CHANGe which is kinda \"breaking change from Types POV\", we don't enforce our custom `RefAttributes` in this API, to be compatible with scenarios where non v9 interfaces might be used. This may/will change with React 19\n props: Props & React.RefAttributes<InferredElementRefType<Props>>,\n excludedPropNames?: ExcludedPropKeys[],\n): DistributiveOmit<Props, ExcludedPropKeys | Exclude<keyof Props, 'as' | keyof HTMLAttributes>> => {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n return getNativeElementProps<\n DistributiveOmit<Props, Exclude<keyof Props, keyof HTMLAttributes | keyof UnknownSlotProps> | ExcludedPropKeys>\n >(props.as ?? tagName, props, excludedPropNames);\n};\n"],"names":["React","getNativeElementProps","getIntrinsicElementProps","tagName","props","excludedPropNames","as"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,qBAAqB,QAAQ,iCAAiC;AAOvE;;;;;;;;;CASC,GACD,OAAO,MAAMC,2BAA2B,CAItCC,SACA,2UAA2U;AAC3UC,OACAC;QAKED;IAHF,4DAA4D;IAC5D,OAAOH,sBAELG,CAAAA,YAAAA,MAAME,EAAE,cAARF,uBAAAA,YAAYD,SAASC,OAAOC;AAChC,EAAE"}

View File

@@ -0,0 +1,21 @@
import { SLOT_CLASS_NAME_PROP_SYMBOL } from '../compose/constants';
/**
* Get the className prop set on the slot by the user, without including the default classes added by the component.
* Custom style hooks should merge this className _after_ any additional classes added by the hook, to ensure that
* classes added by the user take precedence over the custom style hook.
*
* Example usage in a custom style hook:
* ```ts
* state.root.className = mergeClasses(
* state.root.className,
* customStyles.root,
* getSlotClassNameProp_unstable(state.root));
* ```
*
* @returns The className prop set on the slot by the user, or undefined if not set.
*/ export const getSlotClassNameProp = (slot)=>{
if (SLOT_CLASS_NAME_PROP_SYMBOL in slot && typeof slot[SLOT_CLASS_NAME_PROP_SYMBOL] === 'string') {
return slot[SLOT_CLASS_NAME_PROP_SYMBOL];
}
return undefined;
};

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/compose/getSlotClassNameProp.ts"],"sourcesContent":["import { SLOT_CLASS_NAME_PROP_SYMBOL } from '../compose/constants';\nimport type { UnknownSlotProps } from '../compose/types';\n\n/**\n * Get the className prop set on the slot by the user, without including the default classes added by the component.\n * Custom style hooks should merge this className _after_ any additional classes added by the hook, to ensure that\n * classes added by the user take precedence over the custom style hook.\n *\n * Example usage in a custom style hook:\n * ```ts\n * state.root.className = mergeClasses(\n * state.root.className,\n * customStyles.root,\n * getSlotClassNameProp_unstable(state.root));\n * ```\n *\n * @returns The className prop set on the slot by the user, or undefined if not set.\n */\nexport const getSlotClassNameProp = (slot: UnknownSlotProps): string | undefined => {\n if (SLOT_CLASS_NAME_PROP_SYMBOL in slot && typeof slot[SLOT_CLASS_NAME_PROP_SYMBOL] === 'string') {\n return slot[SLOT_CLASS_NAME_PROP_SYMBOL];\n }\n return undefined;\n};\n"],"names":["SLOT_CLASS_NAME_PROP_SYMBOL","getSlotClassNameProp","slot","undefined"],"mappings":"AAAA,SAASA,2BAA2B,QAAQ,uBAAuB;AAGnE;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMC,uBAAuB,CAACC;IACnC,IAAIF,+BAA+BE,QAAQ,OAAOA,IAAI,CAACF,4BAA4B,KAAK,UAAU;QAChG,OAAOE,IAAI,CAACF,4BAA4B;IAC1C;IACA,OAAOG;AACT,EAAE"}

View File

@@ -0,0 +1,14 @@
import * as slot from './slot';
export { isResolvedShorthand } from './isResolvedShorthand';
export { SLOT_CLASS_NAME_PROP_SYMBOL, SLOT_ELEMENT_TYPE_SYMBOL, SLOT_RENDER_FUNCTION_SYMBOL } from './constants';
export { isSlot } from './isSlot';
export { assertSlots } from './assertSlots';
export { getIntrinsicElementProps } from './getIntrinsicElementProps';
export { getSlotClassNameProp as getSlotClassNameProp_unstable } from './getSlotClassNameProp';
// eslint-disable-next-line @typescript-eslint/no-deprecated
export { getSlots } from './deprecated/getSlots';
// eslint-disable-next-line @typescript-eslint/no-deprecated
export { resolveShorthand } from './deprecated/resolveShorthand';
// eslint-disable-next-line @typescript-eslint/no-deprecated
export { getSlotsNext } from './deprecated/getSlotsNext';
export { slot };

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/compose/index.ts"],"sourcesContent":["import * as slot from './slot';\n\nexport type {\n AsIntrinsicElement,\n ComponentProps,\n ComponentState,\n EventData,\n EventHandler,\n ExtractSlotProps,\n ForwardRefComponent,\n RefAttributes,\n InferredElementRefType,\n IsSingleton,\n Slot,\n SlotClassNames,\n SlotComponentType,\n SlotPropsRecord,\n SlotRenderFunction,\n SlotShorthandValue,\n UnknownSlotProps,\n} from './types';\n\nexport { isResolvedShorthand } from './isResolvedShorthand';\nexport { SLOT_CLASS_NAME_PROP_SYMBOL, SLOT_ELEMENT_TYPE_SYMBOL, SLOT_RENDER_FUNCTION_SYMBOL } from './constants';\nexport { isSlot } from './isSlot';\nexport { assertSlots } from './assertSlots';\nexport { getIntrinsicElementProps } from './getIntrinsicElementProps';\nexport { getSlotClassNameProp as getSlotClassNameProp_unstable } from './getSlotClassNameProp';\n\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport type { ObjectSlotProps, Slots } from './deprecated/getSlots';\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport { getSlots } from './deprecated/getSlots';\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport type { ResolveShorthandFunction, ResolveShorthandOptions } from './deprecated/resolveShorthand';\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport { resolveShorthand } from './deprecated/resolveShorthand';\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport { getSlotsNext } from './deprecated/getSlotsNext';\n\nexport { slot };\nexport type { SlotOptions } from './slot';\nexport type { PropsWithoutChildren, PropsWithoutRef } from '../utils/types';\n"],"names":["slot","isResolvedShorthand","SLOT_CLASS_NAME_PROP_SYMBOL","SLOT_ELEMENT_TYPE_SYMBOL","SLOT_RENDER_FUNCTION_SYMBOL","isSlot","assertSlots","getIntrinsicElementProps","getSlotClassNameProp","getSlotClassNameProp_unstable","getSlots","resolveShorthand","getSlotsNext"],"mappings":"AAAA,YAAYA,UAAU,SAAS;AAsB/B,SAASC,mBAAmB,QAAQ,wBAAwB;AAC5D,SAASC,2BAA2B,EAAEC,wBAAwB,EAAEC,2BAA2B,QAAQ,cAAc;AACjH,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SAASC,wBAAwB,QAAQ,6BAA6B;AACtE,SAASC,wBAAwBC,6BAA6B,QAAQ,yBAAyB;AAI/F,4DAA4D;AAC5D,SAASC,QAAQ,QAAQ,wBAAwB;AAGjD,4DAA4D;AAC5D,SAASC,gBAAgB,QAAQ,gCAAgC;AACjE,4DAA4D;AAC5D,SAASC,YAAY,QAAQ,4BAA4B;AAEzD,SAASZ,IAAI,GAAG"}

View File

@@ -0,0 +1,33 @@
import * as React from 'react';
/**
* Guard method that validates if a shorthand is a slot
* can be used to extends properties provided by a slot
*
* @example
* ```
* const backdropSlot = resolveShorthand(backdrop, {
* defaultProps: {
* onClick: useEventCallback(event => {
* if (isResolvedShorthand(backdrop)) {
* backdrop.onClick?.(event)
* }
* // do something after passing click down the line
* }),
* },
* })
* ```
* @example
* ```
* const handleBackDropClick = (event) => {
* // do your thing
* }
* const backdropSlot = resolveShorthand(backdrop, {
* defaultProps: {
* onClick: useEventCallback(
* mergeCallbacks(isResolvedShorthand(backdrop) ? backdrop.onClick : undefined, handleBackdropClick)
* )
* })
* ```
*/ export function isResolvedShorthand(shorthand) {
return shorthand !== null && typeof shorthand === 'object' && !Array.isArray(shorthand) && !React.isValidElement(shorthand);
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/compose/isResolvedShorthand.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ExtractSlotProps, Slot, UnknownSlotProps } from './types';\n\n/**\n * Guard method that validates if a shorthand is a slot\n * can be used to extends properties provided by a slot\n *\n * @example\n * ```\n * const backdropSlot = resolveShorthand(backdrop, {\n * defaultProps: {\n * onClick: useEventCallback(event => {\n * if (isResolvedShorthand(backdrop)) {\n * backdrop.onClick?.(event)\n * }\n * // do something after passing click down the line\n * }),\n * },\n * })\n * ```\n * @example\n * ```\n * const handleBackDropClick = (event) => {\n * // do your thing\n * }\n * const backdropSlot = resolveShorthand(backdrop, {\n * defaultProps: {\n * onClick: useEventCallback(\n * mergeCallbacks(isResolvedShorthand(backdrop) ? backdrop.onClick : undefined, handleBackdropClick)\n * )\n * })\n * ```\n */\nexport function isResolvedShorthand<Shorthand extends Slot<UnknownSlotProps>>(\n shorthand?: Shorthand,\n): shorthand is ExtractSlotProps<Shorthand> {\n return (\n shorthand !== null && typeof shorthand === 'object' && !Array.isArray(shorthand) && !React.isValidElement(shorthand)\n );\n}\n"],"names":["React","isResolvedShorthand","shorthand","Array","isArray","isValidElement"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAG/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BC,GACD,OAAO,SAASC,oBACdC,SAAqB;IAErB,OACEA,cAAc,QAAQ,OAAOA,cAAc,YAAY,CAACC,MAAMC,OAAO,CAACF,cAAc,CAACF,MAAMK,cAAc,CAACH;AAE9G"}

View File

@@ -0,0 +1,7 @@
import { SLOT_ELEMENT_TYPE_SYMBOL } from './constants';
/**
* Guard method to ensure a given element is a slot.
* This is mainly used internally to ensure a slot is being used as a component.
*/ export function isSlot(element) {
return Boolean(element === null || element === void 0 ? void 0 : element.hasOwnProperty(SLOT_ELEMENT_TYPE_SYMBOL));
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/compose/isSlot.ts"],"sourcesContent":["import { SLOT_ELEMENT_TYPE_SYMBOL } from './constants';\nimport { SlotComponentType } from './types';\n\n/**\n * Guard method to ensure a given element is a slot.\n * This is mainly used internally to ensure a slot is being used as a component.\n */\nexport function isSlot<Props extends {}>(element: unknown): element is SlotComponentType<Props> {\n return Boolean((element as {} | undefined)?.hasOwnProperty(SLOT_ELEMENT_TYPE_SYMBOL));\n}\n"],"names":["SLOT_ELEMENT_TYPE_SYMBOL","isSlot","element","Boolean","hasOwnProperty"],"mappings":"AAAA,SAASA,wBAAwB,QAAQ,cAAc;AAGvD;;;CAGC,GACD,OAAO,SAASC,OAAyBC,OAAgB;IACvD,OAAOC,QAASD,oBAAAA,8BAAD,AAACA,QAA4BE,cAAc,CAACJ;AAC7D"}

View File

@@ -0,0 +1,70 @@
import * as React from 'react';
import { SLOT_CLASS_NAME_PROP_SYMBOL, SLOT_ELEMENT_TYPE_SYMBOL, SLOT_RENDER_FUNCTION_SYMBOL } from './constants';
/**
* Creates a slot from a slot shorthand or properties (`props.SLOT_NAME` or `props` itself)
* @param value - the value of the slot, it can be a slot shorthand, a slot component or a slot properties
* @param options - values you can pass to alter the signature of a slot, those values are:
*
* * `elementType` - the base element type of a slot, defaults to `'div'`
* * `defaultProps` - similar to a React component declaration, you can provide a slot default properties to be merged with the shorthand/properties provided.
*/ export function always(value, options) {
const { defaultProps, elementType } = options;
const props = resolveShorthand(value);
/**
* Casting is required here as SlotComponentType is a function, not an object.
* Although SlotComponentType has a function signature, it is still just an object.
* This is required to make a slot callable (JSX compatible), this is the exact same approach
* that is used on `@types/react` components
*/ const propsWithMetadata = {
...defaultProps,
...props,
[SLOT_ELEMENT_TYPE_SYMBOL]: elementType,
[SLOT_CLASS_NAME_PROP_SYMBOL]: (props === null || props === void 0 ? void 0 : props.className) || (defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.className)
};
if (props && typeof props.children === 'function') {
propsWithMetadata[SLOT_RENDER_FUNCTION_SYMBOL] = props.children;
propsWithMetadata.children = defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.children;
}
return propsWithMetadata;
}
/**
* Creates a slot from a slot shorthand or properties (`props.SLOT_NAME` or `props` itself)
* @param value - the value of the slot, it can be a slot shorthand, a slot component or a slot properties
* @param options - values you can pass to alter the signature of a slot, those values are:
*
* * `elementType` - the base element type of a slot, defaults to `'div'`
* * `defaultProps` - similar to a React component declaration, you can provide a slot default properties to be merged with the shorthand/properties provided
* * `renderByDefault` - a boolean that indicates if a slot will be rendered even if it's base value is `undefined`.
* By default if `props.SLOT_NAME` is `undefined` then `state.SLOT_NAME` becomes `undefined`
* and nothing will be rendered, but if `renderByDefault = true` then `state.SLOT_NAME` becomes an object
* with the values provided by `options.defaultProps` (or `{}`). This is useful for cases such as providing a default content
* in case no shorthand is provided, like the case of the `expandIcon` slot for the `AccordionHeader`
*/ export function optional(value, options) {
if (value === null || value === undefined && !options.renderByDefault) {
return undefined;
}
return always(value, options);
}
/**
* Helper function that converts a slot shorthand or properties to a slot properties object
* The main difference between this function and `slot` is that this function does not return the metadata required for a slot to be considered a properly renderable slot, it only converts the value to a slot properties object
* @param value - the value of the slot, it can be a slot shorthand or a slot properties object
*/ export function resolveShorthand(value) {
if (typeof value === 'string' || typeof value === 'number' || isIterable(value) || // eslint-disable-next-line @typescript-eslint/no-explicit-any
React.isValidElement(value)) {
return {
children: value
};
}
if (value && typeof value !== 'object' && process.env.NODE_ENV !== 'production') {
// TODO: would be nice to have a link to slot documentation in this error message
// eslint-disable-next-line no-console
console.error(`@fluentui/react-utilities [slot.${resolveShorthand.name}]:
A slot got an invalid value "${value}" (${typeof value}).
A valid value for a slot is a slot shorthand or slot properties object.
Slot shorthands can be strings, numbers, arrays or JSX elements`);
}
return value;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isIterable = (value)=>typeof value === 'object' && value !== null && Symbol.iterator in value;

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
import * as React from 'react';

File diff suppressed because one or more lines are too long