Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

@fluentui/react-utilities

Package Overview
Dependencies
Maintainers
13
Versions
853
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fluentui/react-utilities - npm Package Compare versions

Comparing version 0.0.0-nightlyd514b3e0ee20220121.1 to 0.0.0-nightlyd80c90385320220216.1

lib-commonjs/hooks/useMergedEventCallbacks.d.ts

75

CHANGELOG.json

@@ -5,5 +5,5 @@ {

{
"date": "Fri, 21 Jan 2022 04:16:25 GMT",
"tag": "@fluentui/react-utilities_v0.0.0-nightlyd514b3e0ee20220121.1",
"version": "0.0.0-nightlyd514b3e0ee20220121.1",
"date": "Wed, 16 Feb 2022 04:14:15 GMT",
"tag": "@fluentui/react-utilities_v0.0.0-nightlyd80c90385320220216.1",
"version": "0.0.0-nightlyd80c90385320220216.1",
"comments": {

@@ -14,8 +14,29 @@ "prerelease": [

"package": "@fluentui/react-utilities",
"commit": "89feafb688fbb160fb8519724479b3c68a79d090",
"commit": "685891ff65eff67542456c5908f5ee1c2f121f4c",
"comment": "Release nightly v9"
},
{
"author": "beachball",
"package": "@fluentui/react-utilities",
"comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightlyd80c90385320220216.1",
"commit": "685891ff65eff67542456c5908f5ee1c2f121f4c"
}
]
}
},
{
"date": "Thu, 10 Feb 2022 08:50:32 GMT",
"tag": "@fluentui/react-utilities_v9.0.0-rc.1",
"version": "9.0.0-rc.1",
"comments": {
"prerelease": [
{
"author": "behowell@microsoft.com",
"package": "@fluentui/react-utilities",
"commit": "317209bb5cd57c40f35bc42060acb7e3cce5ec95",
"comment": "Rename component hooks add the suffix _unstable, as their API has not been finalized yet"
},
{
"author": "behowell@microsoft.com",
"package": "@fluentui/react-utilities",
"commit": "7cc28ed8320b00f42d91c63882f10316db2205c5",

@@ -31,2 +52,44 @@ "comment": "getSlots: remove slotNames param, and infer from state.components instead"

{
"author": "bsunderhus@microsoft.com",
"package": "@fluentui/react-utilities",
"commit": "c0d4e63ee58e60e2c6674efbacc0783cd520984e",
"comment": "Removes nullRender from react-utilities"
},
{
"author": "olfedias@microsoft.com",
"package": "@fluentui/react-utilities",
"commit": "aa6cfd8ac825b5a280206808101de549a91094fc",
"comment": "update applyTriggerPropsToChildren() to return React.ReactElement or null"
},
{
"author": "behowell@microsoft.com",
"package": "@fluentui/react-utilities",
"commit": "53b01d71e335715fda91b33e3d7bbd9d471d5ed3",
"comment": "Refactor component Slot typings"
},
{
"author": "Humberto.Morimoto@microsoft.com",
"package": "@fluentui/react-utilities",
"commit": "0bc161458eae5ae8d387172430496ce9829b1bb1",
"comment": "Adding ComponentSlotProps to allow ref to be passed in composite components."
},
{
"author": "Humberto.Morimoto@microsoft.com",
"package": "@fluentui/react-utilities",
"commit": "e0b8e1fa6980077e7b311fd1c72c28d3e4305db0",
"comment": "Renaming most *Shorthand* composition types to *SlotProps* so they better reflect what the types do."
},
{
"author": "lingfangao@hotmail.com",
"package": "@fluentui/react-utilities",
"commit": "c00913d50e2dd15bbfbb0757cefe43b192ff1d7f",
"comment": "Bump Fluent UI packages to 9.0.0-rc"
},
{
"author": "behowell@microsoft.com",
"package": "@fluentui/react-utilities",
"commit": "f30e7585a8d2abd9db06c4076f39a779008b0eca",
"comment": "Update trigger utilities to handle nested triggers"
},
{
"author": "elcraig@microsoft.com",

@@ -40,4 +103,4 @@ "package": "@fluentui/react-utilities",

"package": "@fluentui/react-utilities",
"comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightlyd514b3e0ee20220121.1",
"commit": "89feafb688fbb160fb8519724479b3c68a79d090"
"comment": "Bump @fluentui/keyboard-keys to v9.0.0-rc.1",
"commit": "e6c855f6d9019d6c73668d15fc9bc3a13291a6c8"
}

@@ -44,0 +107,0 @@ ],

29

CHANGELOG.md
# Change Log - @fluentui/react-utilities
This log was last generated on Fri, 21 Jan 2022 04:16:25 GMT and should not be manually modified.
This log was last generated on Wed, 16 Feb 2022 04:14:15 GMT and should not be manually modified.
<!-- Start content -->
## [0.0.0-nightlyd514b3e0ee20220121.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v0.0.0-nightlyd514b3e0ee20220121.1)
## [0.0.0-nightlyd80c90385320220216.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v0.0.0-nightlyd80c90385320220216.1)
Fri, 21 Jan 2022 04:16:25 GMT
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-beta.4..@fluentui/react-utilities_v0.0.0-nightlyd514b3e0ee20220121.1)
Wed, 16 Feb 2022 04:14:15 GMT
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-rc.1..@fluentui/react-utilities_v0.0.0-nightlyd80c90385320220216.1)
### Changes
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/89feafb688fbb160fb8519724479b3c68a79d090) by email not defined)
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/685891ff65eff67542456c5908f5ee1c2f121f4c) by email not defined)
- Bump @fluentui/keyboard-keys to v0.0.0-nightlyd80c90385320220216.1 ([commit](https://github.com/microsoft/fluentui/commit/685891ff65eff67542456c5908f5ee1c2f121f4c) by beachball)
## [9.0.0-rc.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.0.0-rc.1)
Thu, 10 Feb 2022 08:50:32 GMT
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-beta.4..@fluentui/react-utilities_v9.0.0-rc.1)
### Changes
- Rename component hooks add the suffix _unstable, as their API has not been finalized yet ([PR #21365](https://github.com/microsoft/fluentui/pull/21365) by behowell@microsoft.com)
- getSlots: remove slotNames param, and infer from state.components instead ([PR #21134](https://github.com/microsoft/fluentui/pull/21134) by behowell@microsoft.com)
- add useTriggerElement() hook ([PR #21225](https://github.com/microsoft/fluentui/pull/21225) by olfedias@microsoft.com)
- Removes nullRender from react-utilities ([PR #21576](https://github.com/microsoft/fluentui/pull/21576) by bsunderhus@microsoft.com)
- update applyTriggerPropsToChildren() to return React.ReactElement or null ([PR #21609](https://github.com/microsoft/fluentui/pull/21609) by olfedias@microsoft.com)
- Refactor component Slot typings ([PR #21518](https://github.com/microsoft/fluentui/pull/21518) by behowell@microsoft.com)
- Adding ComponentSlotProps to allow ref to be passed in composite components. ([PR #20890](https://github.com/microsoft/fluentui/pull/20890) by Humberto.Morimoto@microsoft.com)
- Renaming most *Shorthand* composition types to *SlotProps* so they better reflect what the types do. ([PR #20891](https://github.com/microsoft/fluentui/pull/20891) by Humberto.Morimoto@microsoft.com)
- Bump Fluent UI packages to 9.0.0-rc ([PR #21623](https://github.com/microsoft/fluentui/pull/21623) by lingfangao@hotmail.com)
- Update trigger utilities to handle nested triggers ([PR #21495](https://github.com/microsoft/fluentui/pull/21495) by behowell@microsoft.com)
- [breaking] Remove useControllableValue hook (use useControllableState instead) ([PR #20865](https://github.com/microsoft/fluentui/pull/20865) by elcraig@microsoft.com)
- Bump @fluentui/keyboard-keys to v0.0.0-nightlyd514b3e0ee20220121.1 ([commit](https://github.com/microsoft/fluentui/commit/89feafb688fbb160fb8519724479b3c68a79d090) by beachball)
- Bump @fluentui/keyboard-keys to v9.0.0-rc.1 ([commit](https://github.com/microsoft/fluentui/commit/e6c855f6d9019d6c73668d15fc9bc3a13291a6c8) by beachball)

@@ -20,0 +37,0 @@ ## [9.0.0-beta.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.0.0-beta.4)

@@ -14,3 +14,3 @@ import { DispatchWithoutAction } from 'react';

*/
export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React_2.ReactElement<any, string | React_2.JSXElementConstructor<any>> | ((props: TTriggerProps) => React_2.ReactNode) | null | undefined, triggerProps: TTriggerProps) => React_2.ReactNode;
export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React_2.ReactElement<any, string | React_2.JSXElementConstructor<any>> | ((props: TTriggerProps) => React_2.ReactElement | null) | null | undefined, triggerProps: TTriggerProps) => React_2.ReactElement | null;

@@ -75,23 +75,20 @@ /**

export declare type ComponentProps<Shorthands extends ObjectShorthandPropsRecord, Primary extends keyof Shorthands = 'root'> = Omit<{
[Key in keyof Shorthands]?: ShorthandProps<NonNullable<Shorthands[Key]>>;
}, Primary & 'root'> & PropsWithoutRef<Shorthands[Primary]>;
/**
* Defines the Props type for a component given its slots and the definition of which one is the primary slot,
* defaulting to root if one is not provided.
*/
export declare type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<Slots, Primary & 'root'> & PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;
export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord> = {
/**
* Defines the State object of a component given its slots.
*/
export declare type ComponentState<Slots extends SlotPropsRecord> = {
components: {
[Key in keyof Shorthands]-?: React_2.ComponentType<NonNullable<Shorthands[Key]> extends ObjectShorthandProps<infer P> ? P : NonNullable<Shorthands[Key]>> | (NonNullable<Shorthands[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
[Key in keyof Slots]-?: React_2.ComponentType<ExtractSlotProps<Slots[Key]>> | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
};
} & Shorthands;
} & {
[Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
};
/**
* Matches any shorthand props type.
*
* This should ONLY be used in type templates as in `extends DefaultObjectShorthandProps`;
* it shouldn't be used as the type of a slot.
*/
export declare type DefaultObjectShorthandProps = ObjectShorthandProps<Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
as?: keyof JSX.IntrinsicElements;
}>;
/**
* Default context value to use in case there is no SSRProvider. This is fine for client-only apps.

@@ -111,2 +108,31 @@ *

/**
* HTML element types that are not allowed to have children.
*
* Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
*/
declare type EmptyIntrisicElements = 'area' | 'base' | 'br' | 'col' | 'embed' | 'hr' | 'img' | 'input' | 'link' | 'meta' | 'param' | 'source' | 'track' | 'wbr';
/**
* Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.
*/
export declare type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;
/**
* Allows a component to be tagged as a FluentUI trigger component.
*
* Triggers are special-case components: they attach event listeners and other props on their child,
* and use them to trigger another component to show. Examples include `MenuTrigger` and `Tooltip`.
*
* A component can be tagged as a trigger as follows:
* ```ts
* const MyComponent: React.FC<MyComponentProps> & FluentTriggerComponent = ...;
*
* MyComponent.isFluentTriggerComponent = true; // MUST also set this to true
* ```
*/
export declare type FluentTriggerComponent = {
isFluentTriggerComponent?: boolean;
};
/**
* An array of FORM tag properties and events.

@@ -156,9 +182,9 @@ *

*/
export declare const getPartitionedNativeProps: ({ primarySlotTagName, props, excludedPropNames, }: {
export declare const getPartitionedNativeProps: <Props extends Pick<React_2.HTMLAttributes<HTMLElement>, "style" | "className">, ExcludedPropKeys extends Extract<keyof Props, string> = never>({ primarySlotTagName, props, excludedPropNames, }: {
/** The primary slot's element type (e.g. 'div') */
primarySlotTagName: keyof JSX.IntrinsicElements;
/** The component's props object */
props: Pick<React_2.HTMLAttributes<HTMLElement>, 'style' | 'className'>;
props: Props;
/** List of native props to exclude from the returned value */
excludedPropNames?: string[] | undefined;
excludedPropNames?: ExcludedPropKeys[] | undefined;
}) => {

@@ -169,3 +195,3 @@ root: {

};
primary: React_2.HTMLAttributes<any>;
primary: Omit<Props, ExcludedPropKeys>;
};

@@ -195,8 +221,30 @@

*/
export declare function getSlots<R extends ObjectShorthandPropsRecord>(state: ComponentState<R>): {
export declare function getSlots<R extends SlotPropsRecord>(state: ComponentState<R>): {
slots: Slots<R>;
slotProps: SlotProps<R>;
slotProps: ObjectSlotProps<R>;
};
/**
* Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).
*
* In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,
* it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.
* This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.
*
* For example, the following returns `<div id="child" />`:
* ```jsx
* getTriggerChild(
* <Tooltip>
* <MenuTrigger>
* <div id="child" />
* </MenuTrigger>
* </Tooltip>
* );
* ```
*/
export declare const getTriggerChild: (children: React_2.ReactNode) => React_2.ReactElement & {
ref?: React_2.Ref<unknown>;
};
/**
* An array of HTML element properties and events.

@@ -235,23 +283,17 @@ *

/**
* Define the slot arguments for a slot that supports one or more intrinsic element types, such as 'div'.
* For slots that support custom components, use {@link ObjectShorthandProps} instead.
*
* The first param is the slot's default type if no `as` prop is specified.
* The second param is an optional union of alternative types that can be specified for the `as` prop.
*
* ```
* IntrinsicShorthandProps<'div'> // Slot is always div
* IntrinsicShorthandProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
* IntrinsicShorthandProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
* ```
* Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:
* * Removes legacy string ref.
* * Disallows children for empty tags like 'img'.
*/
export declare type IntrinsicShorthandProps<DefaultAs extends keyof JSX.IntrinsicElements, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<DefaultAs> extends false ? 'Error: first parameter to IntrinsicShorthandProps must be a single element type, not a union of types' : ({
as?: DefaultAs;
} & ObjectShorthandProps<React_2.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
[As in AlternateAs]: {
as: As;
} & ObjectShorthandProps<React_2.PropsWithRef<JSX.IntrinsicElements[As]>>;
}[AlternateAs];
declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React_2.PropsWithRef<JSX.IntrinsicElements[Type]> & (Type extends EmptyIntrisicElements ? {
children?: never;
} : {});
/**
* Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).
* See the {@link FluentTriggerComponent} type for more info.
*/
export declare const isFluentTrigger: (element: React_2.ReactElement) => boolean | undefined;
/**
* Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.

@@ -282,20 +324,6 @@ *

/**
* Simple constant function for returning null, used to render empty templates in JSX.
*/
export declare const nullRender: () => null;
/**
* Defines the slot props for a slot that supports a Component type.
*
* For intrinsic elements like 'div', use {@link IntrinsicShorthandProps} instead.
*/
export declare type ObjectShorthandProps<Props extends {
children?: React_2.ReactNode;
} = {}> = Props & {
children?: Props['children'] | ShorthandRenderFunction<Props>;
declare type ObjectSlotProps<S extends SlotPropsRecord> = {
[K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : ExtractSlotProps<S[K]> extends React_2.ComponentType<infer P> ? P : never;
};
export declare type ObjectShorthandPropsRecord = Record<string, DefaultObjectShorthandProps | undefined>;
/**

@@ -337,7 +365,2 @@ * This is part of a hack to infer the element type from a native element *props* type.

/**
* Similar to React.Children.only, but drills into fragments rather than treating them as a single child
*/
export declare const onlyChild: <P>(child: boolean | React_2.ReactText | React_2.ReactFragment | React_2.ReactPortal | React_2.ReactElement<P, string | React_2.JSXElementConstructor<any>> | null | undefined) => React_2.ReactElement<P, string | React_2.JSXElementConstructor<any>>;
export declare const optionProperties: Record<string, number>;

@@ -347,3 +370,3 @@

* Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
* IntrinsicShorthandProps). This allows IntrinsicShorthandProps to be used with React.forwardRef.
* IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
*

@@ -362,2 +385,7 @@ * The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional

/**
* If type T includes `null`, remove it and add `undefined` instead.
*/
export declare type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;
/**
* Resets generated IDs, should be used only in tests.

@@ -370,10 +398,15 @@ *

/**
* Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
* Resolves shorthands into slot props, to ensure normalization of the signature
* being passed down to getSlots method
* @param value - the base ShorthandProps
* @param options - options to resolve ShorthandProps
* @param value - the base shorthand props
* @param options - options to resolve shorthand props
*/
export declare function resolveShorthand<Props extends DefaultObjectShorthandProps, Required extends boolean = false>(value: ShorthandProps<Props>, options?: ResolveShorthandOptions<Props, Required>): Required extends false ? Props | undefined : Props;
export declare const resolveShorthand: ResolveShorthandFunction;
export declare type ResolveShorthandOptions<Props extends Record<string, any>, Required extends boolean = false> = {
export declare type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {
<P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, true>): ReplaceNullWithUndefined<P>;
<P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>): ReplaceNullWithUndefined<P> | undefined;
};
export declare type ResolveShorthandOptions<Props, Required extends boolean = false> = {
required?: Required;

@@ -390,6 +423,2 @@ defaultProps?: Props;

export declare type ShorthandProps<Props extends DefaultObjectShorthandProps> = React_2.ReactChild | React_2.ReactNodeArray | React_2.ReactPortal | number | null | undefined | Props;
export declare type ShorthandRenderFunction<Props> = (Component: React_2.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React_2.ReactNode;
/**

@@ -402,10 +431,51 @@ * Checks if the keyboard event should preventDefault() for Enter and Spacebar keys

declare type SlotProps<S extends ObjectShorthandPropsRecord> = {
[K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : NonNullable<S[K]> extends ObjectShorthandProps<infer P> ? P : never;
};
/**
* The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,
* or a component like `typeof Button`.
*
* If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).
*
* By default, slots can be set to `null` to prevent them from being rendered. If a slot must always be rendered,
* wrap with `NonNullable` (see examples below).
*
* @example
* ```
* // Intrinsic element examples:
* Slot<'div'> // Slot is always div
* Slot<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
* Slot<'span', 'div' | 'pre'> // Defaults to span, but allows as="div" or as="pre"
* NonNullable<Slot<'div'>> // Slot that will always be rendered (can't be set to null by the user)
*
* // Component examples:
* Slot<typeof Button> // Slot is always a Button, and accepts all of Button's Props
* NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)
* ```
*/
export declare type Slot<Type extends keyof JSX.IntrinsicElements | React_2.ComponentType | UnknownSlotProps, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<Extract<Type, string>> extends true ? WithSlotShorthandValue<Type extends keyof JSX.IntrinsicElements ? {
as?: Type;
} & WithSlotRenderFunction<IntrisicElementProps<Type>> : Type extends React_2.ComponentType<infer Props> ? WithSlotRenderFunction<Props> : Type> | {
[As in AlternateAs]: {
as: As;
} & WithSlotRenderFunction<IntrisicElementProps<As>>;
}[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
export declare type Slots<S extends ObjectShorthandPropsRecord> = {
[K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? As : S[K] extends ObjectShorthandProps<infer P> ? React_2.ElementType<NonNullable<P>> : React_2.ElementType<NonNullable<S[K]>>;
/**
* Matches any component's Slots type (such as ButtonSlots).
*
* This should ONLY be used in type templates as in `extends SlotPropsRecord`;
* it shouldn't be used as a component's Slots type.
*/
export declare type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;
export declare type SlotRenderFunction<Props> = (Component: React_2.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React_2.ReactNode;
export declare type Slots<S extends SlotPropsRecord> = {
[K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? As : ExtractSlotProps<S[K]> extends React_2.ComponentType<infer P> ? React_2.ElementType<NonNullable<P>> : React_2.ElementType<ExtractSlotProps<S[K]>>;
};
/**
* The shorthand value of a slot allows specifying its child
*/
export declare type SlotShorthandValue = React_2.ReactChild | React_2.ReactNodeArray | React_2.ReactPortal;
export declare const SSRContext: React_2.Context<SSRContextValue>;

@@ -472,2 +542,12 @@

/**
* Matches any slot props type.
*
* This should ONLY be used in type templates as in `extends UnknownSlotProps`;
* it shouldn't be used as the type of a slot.
*/
export declare type UnknownSlotProps = Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
as?: keyof JSX.IntrinsicElements;
};
/**
* Hook to store a value and generate callbacks for setting the value to true or false.

@@ -595,2 +675,21 @@ * The identity of the callbacks will always stay the same.

/**
* Combine two event callbacks into a single callback function that calls each one in order.
*
* This is useful to add an event listener to an existing element without overwriting the current listener, if any.
*
* For example:
* ```ts
* state.slot.onChange = useMergedCallbacks(state.slot.onChange, ev => {
* // Handle onChange
* });
* ```
*
* @param callback1 - The first callback to be called
* @param callback2 - The second callback to be called
*
* @returns An event callback that calls the callbacks in order, and is stable between renders
*/
export declare function useMergedEventCallbacks<Args extends unknown[]>(callback1: ((...args: Args) => void) | undefined, callback2: ((...args: Args) => void) | undefined): (...args: Args) => void;
/**
* React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that

@@ -662,21 +761,2 @@ * updates all provided refs

/**
* A hook that handles "trigger" pattern.
*
* Clones a passed element or calls render props. Merges props including refs and callbacks, callbacks are kept stable
* by reference.
*/
export declare function useTriggerElement<TriggerProps extends React_2.HTMLProps<unknown>>(options: UseTriggerElementOptions<TriggerProps>): React_2.ReactNode;
export declare type UseTriggerElementOptions<TriggerProps> = {
/** An actual trigger element or render props function. */
children: React_2.ReactElement | ((props: TriggerProps) => React_2.ReactNode) | null | undefined;
/** A ref to trigger element. */
ref: React_2.Ref<unknown> | undefined;
/** Props that are passed to a parent component and should be forwarded down. */
outerProps: React_2.HTMLProps<unknown>;
/** Custom props including callbacks. */
overrideProps: TriggerProps;
};
/**
* Hook which synchronously executes a callback when the component is about to unmount.

@@ -695,2 +775,19 @@ *

/**
* Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`
* to be a render function that takes those props.
*/
declare type WithSlotRenderFunction<Props extends {
children?: unknown;
}> = Props & {
children?: Props['children'] | SlotRenderFunction<Props>;
};
/**
* Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.
*/
declare type WithSlotShorthandValue<Props extends {
children?: unknown;
}> = Props | Extract<SlotShorthandValue, Props['children']>;
export { }
import * as React from 'react';
import { AsIntrinsicElement, ComponentState, ObjectShorthandPropsRecord, ObjectShorthandProps, UnionToIntersection } from './types';
export declare type Slots<S extends ObjectShorthandPropsRecord> = {
[K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? As : S[K] extends ObjectShorthandProps<infer P> ? React.ElementType<NonNullable<P>> : React.ElementType<NonNullable<S[K]>>;
import type { AsIntrinsicElement, ComponentState, ExtractSlotProps, SlotPropsRecord, UnionToIntersection } from './types';
export declare type Slots<S extends SlotPropsRecord> = {
[K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? As : ExtractSlotProps<S[K]> extends React.ComponentType<infer P> ? React.ElementType<NonNullable<P>> : React.ElementType<ExtractSlotProps<S[K]>>;
};
declare type SlotProps<S extends ObjectShorthandPropsRecord> = {
[K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : NonNullable<S[K]> extends ObjectShorthandProps<infer P> ? P : never;
declare type ObjectSlotProps<S extends SlotPropsRecord> = {
[K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : ExtractSlotProps<S[K]> extends React.ComponentType<infer P> ? P : never;
};

@@ -26,6 +26,6 @@ /**

*/
export declare function getSlots<R extends ObjectShorthandPropsRecord>(state: ComponentState<R>): {
export declare function getSlots<R extends SlotPropsRecord>(state: ComponentState<R>): {
slots: Slots<R>;
slotProps: SlotProps<R>;
slotProps: ObjectSlotProps<R>;
};
export {};

@@ -10,4 +10,2 @@ "use strict";

const nullRender_1 = /*#__PURE__*/require("./nullRender");
const omit_1 = /*#__PURE__*/require("../utils/omit");

@@ -56,3 +54,3 @@ /**

if (state[slotName] === undefined) {
return [nullRender_1.nullRender, undefined];
return [null, undefined];
}

@@ -59,0 +57,0 @@

export * from './getSlots';
export * from './nullRender';
export * from './resolveShorthand';
export * from './types';

@@ -11,4 +11,2 @@ "use strict";

tslib_1.__exportStar(require("./nullRender"), exports);
tslib_1.__exportStar(require("./resolveShorthand"), exports);

@@ -15,0 +13,0 @@

@@ -1,12 +0,16 @@

import type { DefaultObjectShorthandProps, ShorthandProps } from './types';
export declare type ResolveShorthandOptions<Props extends Record<string, any>, Required extends boolean = false> = {
import type { ReplaceNullWithUndefined, SlotShorthandValue, UnknownSlotProps } from './types';
export declare type ResolveShorthandOptions<Props, Required extends boolean = false> = {
required?: Required;
defaultProps?: Props;
};
export declare type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {
<P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, true>): ReplaceNullWithUndefined<P>;
<P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>): ReplaceNullWithUndefined<P> | undefined;
};
/**
* Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
* Resolves shorthands into slot props, to ensure normalization of the signature
* being passed down to getSlots method
* @param value - the base ShorthandProps
* @param options - options to resolve ShorthandProps
* @param value - the base shorthand props
* @param options - options to resolve shorthand props
*/
export declare function resolveShorthand<Props extends DefaultObjectShorthandProps, Required extends boolean = false>(value: ShorthandProps<Props>, options?: ResolveShorthandOptions<Props, Required>): Required extends false ? Props | undefined : Props;
export declare const resolveShorthand: ResolveShorthandFunction;

@@ -10,10 +10,10 @@ "use strict";

/**
* Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
* Resolves shorthands into slot props, to ensure normalization of the signature
* being passed down to getSlots method
* @param value - the base ShorthandProps
* @param options - options to resolve ShorthandProps
* @param value - the base shorthand props
* @param options - options to resolve shorthand props
*/
function resolveShorthand(value, options) {
const resolveShorthand = (value, options) => {
const {

@@ -39,5 +39,5 @@ required = false,

} : resolvedShorthand;
}
};
exports.resolveShorthand = resolveShorthand;
//# sourceMappingURL=resolveShorthand.js.map
import * as React from 'react';
export declare type ShorthandRenderFunction<Props> = (Component: React.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React.ReactNode;
export declare type ObjectShorthandPropsRecord = Record<string, DefaultObjectShorthandProps | undefined>;
export declare type ShorthandProps<Props extends DefaultObjectShorthandProps> = React.ReactChild | React.ReactNodeArray | React.ReactPortal | number | null | undefined | Props;
export declare type SlotRenderFunction<Props> = (Component: React.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React.ReactNode;
/**
* Matches any shorthand props type.
* Matches any component's Slots type (such as ButtonSlots).
*
* This should ONLY be used in type templates as in `extends DefaultObjectShorthandProps`;
* This should ONLY be used in type templates as in `extends SlotPropsRecord`;
* it shouldn't be used as a component's Slots type.
*/
export declare type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;
/**
* The shorthand value of a slot allows specifying its child
*/
export declare type SlotShorthandValue = React.ReactChild | React.ReactNodeArray | React.ReactPortal;
/**
* Matches any slot props type.
*
* This should ONLY be used in type templates as in `extends UnknownSlotProps`;
* it shouldn't be used as the type of a slot.
*/
export declare type DefaultObjectShorthandProps = ObjectShorthandProps<Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
export declare type UnknownSlotProps = Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
as?: keyof JSX.IntrinsicElements;
}>;
};
/**
* Defines the slot props for a slot that supports a Component type.
*
* For intrinsic elements like 'div', use {@link IntrinsicShorthandProps} instead.
* Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.
*/
export declare type ObjectShorthandProps<Props extends {
children?: React.ReactNode;
} = {}> = Props & {
children?: Props['children'] | ShorthandRenderFunction<Props>;
declare type WithSlotShorthandValue<Props extends {
children?: unknown;
}> = Props | Extract<SlotShorthandValue, Props['children']>;
/**
* Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`
* to be a render function that takes those props.
*/
declare type WithSlotRenderFunction<Props extends {
children?: unknown;
}> = Props & {
children?: Props['children'] | SlotRenderFunction<Props>;
};
/**
* Define the slot arguments for a slot that supports one or more intrinsic element types, such as 'div'.
* For slots that support custom components, use {@link ObjectShorthandProps} instead.
* HTML element types that are not allowed to have children.
*
* The first param is the slot's default type if no `as` prop is specified.
* The second param is an optional union of alternative types that can be specified for the `as` prop.
* Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
*/
declare type EmptyIntrisicElements = 'area' | 'base' | 'br' | 'col' | 'embed' | 'hr' | 'img' | 'input' | 'link' | 'meta' | 'param' | 'source' | 'track' | 'wbr';
/**
* Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:
* * Removes legacy string ref.
* * Disallows children for empty tags like 'img'.
*/
declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React.PropsWithRef<JSX.IntrinsicElements[Type]> & (Type extends EmptyIntrisicElements ? {
children?: never;
} : {});
/**
* The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,
* or a component like `typeof Button`.
*
* If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).
*
* By default, slots can be set to `null` to prevent them from being rendered. If a slot must always be rendered,
* wrap with `NonNullable` (see examples below).
*
* @example
* ```
* IntrinsicShorthandProps<'div'> // Slot is always div
* IntrinsicShorthandProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
* IntrinsicShorthandProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
* // Intrinsic element examples:
* Slot<'div'> // Slot is always div
* Slot<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
* Slot<'span', 'div' | 'pre'> // Defaults to span, but allows as="div" or as="pre"
* NonNullable<Slot<'div'>> // Slot that will always be rendered (can't be set to null by the user)
*
* // Component examples:
* Slot<typeof Button> // Slot is always a Button, and accepts all of Button's Props
* NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)
* ```
*/
export declare type IntrinsicShorthandProps<DefaultAs extends keyof JSX.IntrinsicElements, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<DefaultAs> extends false ? 'Error: first parameter to IntrinsicShorthandProps must be a single element type, not a union of types' : ({
as?: DefaultAs;
} & ObjectShorthandProps<React.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
export declare type Slot<Type extends keyof JSX.IntrinsicElements | React.ComponentType | UnknownSlotProps, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<Extract<Type, string>> extends true ? WithSlotShorthandValue<Type extends keyof JSX.IntrinsicElements ? {
as?: Type;
} & WithSlotRenderFunction<IntrisicElementProps<Type>> : Type extends React.ComponentType<infer Props> ? WithSlotRenderFunction<Props> : Type> | {
[As in AlternateAs]: {
as: As;
} & ObjectShorthandProps<React.PropsWithRef<JSX.IntrinsicElements[As]>>;
}[AlternateAs];
} & WithSlotRenderFunction<IntrisicElementProps<As>>;
}[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
/**

@@ -72,3 +109,3 @@ * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.

* Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
* IntrinsicShorthandProps). This allows IntrinsicShorthandProps to be used with React.forwardRef.
* IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
*

@@ -79,10 +116,25 @@ * The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional

export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
export declare type ComponentProps<Shorthands extends ObjectShorthandPropsRecord, Primary extends keyof Shorthands = 'root'> = Omit<{
[Key in keyof Shorthands]?: ShorthandProps<NonNullable<Shorthands[Key]>>;
}, Primary & 'root'> & PropsWithoutRef<Shorthands[Primary]>;
export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord> = {
/**
* Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.
*/
export declare type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;
/**
* Defines the Props type for a component given its slots and the definition of which one is the primary slot,
* defaulting to root if one is not provided.
*/
export declare type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<Slots, Primary & 'root'> & PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;
/**
* If type T includes `null`, remove it and add `undefined` instead.
*/
export declare type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;
/**
* Defines the State object of a component given its slots.
*/
export declare type ComponentState<Slots extends SlotPropsRecord> = {
components: {
[Key in keyof Shorthands]-?: React.ComponentType<NonNullable<Shorthands[Key]> extends ObjectShorthandProps<infer P> ? P : NonNullable<Shorthands[Key]>> | (NonNullable<Shorthands[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
[Key in keyof Slots]-?: React.ComponentType<ExtractSlotProps<Slots[Key]>> | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
};
} & Shorthands;
} & {
[Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
};
/**

@@ -89,0 +141,0 @@ * This is part of a hack to infer the element type from a native element *props* type.

@@ -8,2 +8,3 @@ export * from './useControllableState';

export * from './useIsomorphicLayoutEffect';
export * from './useMergedEventCallbacks';
export * from './useMergedRefs';

@@ -15,4 +16,3 @@ export * from './useMount';

export * from './useTimeout';
export * from './useTriggerElement';
export * from './useUnmount';
export * from './useForceUpdate';

@@ -23,2 +23,4 @@ "use strict";

tslib_1.__exportStar(require("./useMergedEventCallbacks"), exports);
tslib_1.__exportStar(require("./useMergedRefs"), exports);

@@ -36,4 +38,2 @@

tslib_1.__exportStar(require("./useTriggerElement"), exports);
tslib_1.__exportStar(require("./useUnmount"), exports);

@@ -40,0 +40,0 @@

@@ -5,2 +5,2 @@ import * as React from 'react';

*/
export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React.ReactElement<any, string | React.JSXElementConstructor<any>> | ((props: TTriggerProps) => React.ReactNode) | null | undefined, triggerProps: TTriggerProps) => React.ReactNode;
export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React.ReactElement<any, string | React.JSXElementConstructor<any>> | ((props: TTriggerProps) => React.ReactElement | null) | null | undefined, triggerProps: TTriggerProps) => React.ReactElement | null;

@@ -10,3 +10,3 @@ "use strict";

const onlyChild_1 = /*#__PURE__*/require("./onlyChild");
const isFluentTrigger_1 = /*#__PURE__*/require("./isFluentTrigger");
/**

@@ -21,9 +21,29 @@ * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.

} else if (children) {
return React.cloneElement(onlyChild_1.onlyChild(children), triggerProps);
}
return cloneTriggerTree(children, triggerProps);
} // Components in React should return either JSX elements or "null", otherwise React will throw:
// Nothing was returned from render.
// This usually means a return statement is missing. Or, to render nothing, return null.
return children;
return children || null;
};
exports.applyTriggerPropsToChildren = applyTriggerPropsToChildren;
/**
* Clones a React element tree, and applies the given props to the first grandchild that is not
* a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).
*/
const cloneTriggerTree = (child, triggerProps) => {
if (!React.isValidElement(child) || child.type === React.Fragment) {
throw new Error('A trigger element must be a single element for this component. ' + "Please ensure that you're not using React Fragments.");
}
if (isFluentTrigger_1.isFluentTrigger(child)) {
const grandchild = cloneTriggerTree(child.props.children, triggerProps);
return React.cloneElement(child, undefined, grandchild);
} else {
return React.cloneElement(child, triggerProps);
}
};
//# sourceMappingURL=applyTriggerPropsToChildren.js.map

@@ -18,9 +18,9 @@ import * as React from 'react';

*/
export declare const getPartitionedNativeProps: ({ primarySlotTagName, props, excludedPropNames, }: {
export declare const getPartitionedNativeProps: <Props extends Pick<React.HTMLAttributes<HTMLElement>, "style" | "className">, ExcludedPropKeys extends Extract<keyof Props, string> = never>({ primarySlotTagName, props, excludedPropNames, }: {
/** The primary slot's element type (e.g. 'div') */
primarySlotTagName: keyof JSX.IntrinsicElements;
/** The component's props object */
props: Pick<React.HTMLAttributes<HTMLElement>, 'style' | 'className'>;
props: Props;
/** List of native props to exclude from the returned value */
excludedPropNames?: string[] | undefined;
excludedPropNames?: ExcludedPropKeys[] | undefined;
}) => {

@@ -31,3 +31,3 @@ root: {

};
primary: React.HTMLAttributes<any>;
primary: Omit<Props, ExcludedPropKeys>;
};

@@ -5,5 +5,6 @@ export * from './applyTriggerPropsToChildren';

export * from './getRTLSafeKey';
export * from './getTriggerChild';
export * from './isFluentTrigger';
export * from './omit';
export * from './onlyChild';
export * from './properties';
export * from './shouldPreventDefaultOnKeyDown';

@@ -17,6 +17,8 @@ "use strict";

tslib_1.__exportStar(require("./getTriggerChild"), exports);
tslib_1.__exportStar(require("./isFluentTrigger"), exports);
tslib_1.__exportStar(require("./omit"), exports);
tslib_1.__exportStar(require("./onlyChild"), exports);
tslib_1.__exportStar(require("./properties"), exports);

@@ -23,0 +25,0 @@

import * as React from 'react';
import { AsIntrinsicElement, ComponentState, ObjectShorthandPropsRecord, ObjectShorthandProps, UnionToIntersection } from './types';
export declare type Slots<S extends ObjectShorthandPropsRecord> = {
[K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? As : S[K] extends ObjectShorthandProps<infer P> ? React.ElementType<NonNullable<P>> : React.ElementType<NonNullable<S[K]>>;
import type { AsIntrinsicElement, ComponentState, ExtractSlotProps, SlotPropsRecord, UnionToIntersection } from './types';
export declare type Slots<S extends SlotPropsRecord> = {
[K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? As : ExtractSlotProps<S[K]> extends React.ComponentType<infer P> ? React.ElementType<NonNullable<P>> : React.ElementType<ExtractSlotProps<S[K]>>;
};
declare type SlotProps<S extends ObjectShorthandPropsRecord> = {
[K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : NonNullable<S[K]> extends ObjectShorthandProps<infer P> ? P : never;
declare type ObjectSlotProps<S extends SlotPropsRecord> = {
[K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : ExtractSlotProps<S[K]> extends React.ComponentType<infer P> ? P : never;
};

@@ -26,6 +26,6 @@ /**

*/
export declare function getSlots<R extends ObjectShorthandPropsRecord>(state: ComponentState<R>): {
export declare function getSlots<R extends SlotPropsRecord>(state: ComponentState<R>): {
slots: Slots<R>;
slotProps: SlotProps<R>;
slotProps: ObjectSlotProps<R>;
};
export {};
import * as React from 'react';
import { nullRender } from './nullRender';
import { omit } from '../utils/omit';

@@ -43,3 +42,3 @@ /**

if (state[slotName] === undefined) {
return [nullRender, undefined];
return [null, undefined];
}

@@ -46,0 +45,0 @@

export * from './getSlots';
export * from './nullRender';
export * from './resolveShorthand';
export * from './types';
export * from './getSlots';
export * from './nullRender';
export * from './resolveShorthand';
export * from './types';
//# sourceMappingURL=index.js.map

@@ -1,12 +0,16 @@

import type { DefaultObjectShorthandProps, ShorthandProps } from './types';
export declare type ResolveShorthandOptions<Props extends Record<string, any>, Required extends boolean = false> = {
import type { ReplaceNullWithUndefined, SlotShorthandValue, UnknownSlotProps } from './types';
export declare type ResolveShorthandOptions<Props, Required extends boolean = false> = {
required?: Required;
defaultProps?: Props;
};
export declare type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {
<P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, true>): ReplaceNullWithUndefined<P>;
<P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>): ReplaceNullWithUndefined<P> | undefined;
};
/**
* Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
* Resolves shorthands into slot props, to ensure normalization of the signature
* being passed down to getSlots method
* @param value - the base ShorthandProps
* @param options - options to resolve ShorthandProps
* @param value - the base shorthand props
* @param options - options to resolve shorthand props
*/
export declare function resolveShorthand<Props extends DefaultObjectShorthandProps, Required extends boolean = false>(value: ShorthandProps<Props>, options?: ResolveShorthandOptions<Props, Required>): Required extends false ? Props | undefined : Props;
export declare const resolveShorthand: ResolveShorthandFunction;
import { isValidElement } from 'react';
/**
* Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
* Resolves shorthands into slot props, to ensure normalization of the signature
* being passed down to getSlots method
* @param value - the base ShorthandProps
* @param options - options to resolve ShorthandProps
* @param value - the base shorthand props
* @param options - options to resolve shorthand props
*/
export function resolveShorthand(value, options) {
export const resolveShorthand = (value, options) => {
const {

@@ -30,3 +30,3 @@ required = false,

} : resolvedShorthand;
}
};
//# sourceMappingURL=resolveShorthand.js.map
import * as React from 'react';
export declare type ShorthandRenderFunction<Props> = (Component: React.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React.ReactNode;
export declare type ObjectShorthandPropsRecord = Record<string, DefaultObjectShorthandProps | undefined>;
export declare type ShorthandProps<Props extends DefaultObjectShorthandProps> = React.ReactChild | React.ReactNodeArray | React.ReactPortal | number | null | undefined | Props;
export declare type SlotRenderFunction<Props> = (Component: React.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React.ReactNode;
/**
* Matches any shorthand props type.
* Matches any component's Slots type (such as ButtonSlots).
*
* This should ONLY be used in type templates as in `extends DefaultObjectShorthandProps`;
* This should ONLY be used in type templates as in `extends SlotPropsRecord`;
* it shouldn't be used as a component's Slots type.
*/
export declare type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;
/**
* The shorthand value of a slot allows specifying its child
*/
export declare type SlotShorthandValue = React.ReactChild | React.ReactNodeArray | React.ReactPortal;
/**
* Matches any slot props type.
*
* This should ONLY be used in type templates as in `extends UnknownSlotProps`;
* it shouldn't be used as the type of a slot.
*/
export declare type DefaultObjectShorthandProps = ObjectShorthandProps<Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
export declare type UnknownSlotProps = Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
as?: keyof JSX.IntrinsicElements;
}>;
};
/**
* Defines the slot props for a slot that supports a Component type.
*
* For intrinsic elements like 'div', use {@link IntrinsicShorthandProps} instead.
* Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.
*/
export declare type ObjectShorthandProps<Props extends {
children?: React.ReactNode;
} = {}> = Props & {
children?: Props['children'] | ShorthandRenderFunction<Props>;
declare type WithSlotShorthandValue<Props extends {
children?: unknown;
}> = Props | Extract<SlotShorthandValue, Props['children']>;
/**
* Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`
* to be a render function that takes those props.
*/
declare type WithSlotRenderFunction<Props extends {
children?: unknown;
}> = Props & {
children?: Props['children'] | SlotRenderFunction<Props>;
};
/**
* Define the slot arguments for a slot that supports one or more intrinsic element types, such as 'div'.
* For slots that support custom components, use {@link ObjectShorthandProps} instead.
* HTML element types that are not allowed to have children.
*
* The first param is the slot's default type if no `as` prop is specified.
* The second param is an optional union of alternative types that can be specified for the `as` prop.
* Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
*/
declare type EmptyIntrisicElements = 'area' | 'base' | 'br' | 'col' | 'embed' | 'hr' | 'img' | 'input' | 'link' | 'meta' | 'param' | 'source' | 'track' | 'wbr';
/**
* Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:
* * Removes legacy string ref.
* * Disallows children for empty tags like 'img'.
*/
declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React.PropsWithRef<JSX.IntrinsicElements[Type]> & (Type extends EmptyIntrisicElements ? {
children?: never;
} : {});
/**
* The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,
* or a component like `typeof Button`.
*
* If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).
*
* By default, slots can be set to `null` to prevent them from being rendered. If a slot must always be rendered,
* wrap with `NonNullable` (see examples below).
*
* @example
* ```
* IntrinsicShorthandProps<'div'> // Slot is always div
* IntrinsicShorthandProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
* IntrinsicShorthandProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
* // Intrinsic element examples:
* Slot<'div'> // Slot is always div
* Slot<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
* Slot<'span', 'div' | 'pre'> // Defaults to span, but allows as="div" or as="pre"
* NonNullable<Slot<'div'>> // Slot that will always be rendered (can't be set to null by the user)
*
* // Component examples:
* Slot<typeof Button> // Slot is always a Button, and accepts all of Button's Props
* NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)
* ```
*/
export declare type IntrinsicShorthandProps<DefaultAs extends keyof JSX.IntrinsicElements, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<DefaultAs> extends false ? 'Error: first parameter to IntrinsicShorthandProps must be a single element type, not a union of types' : ({
as?: DefaultAs;
} & ObjectShorthandProps<React.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
export declare type Slot<Type extends keyof JSX.IntrinsicElements | React.ComponentType | UnknownSlotProps, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<Extract<Type, string>> extends true ? WithSlotShorthandValue<Type extends keyof JSX.IntrinsicElements ? {
as?: Type;
} & WithSlotRenderFunction<IntrisicElementProps<Type>> : Type extends React.ComponentType<infer Props> ? WithSlotRenderFunction<Props> : Type> | {
[As in AlternateAs]: {
as: As;
} & ObjectShorthandProps<React.PropsWithRef<JSX.IntrinsicElements[As]>>;
}[AlternateAs];
} & WithSlotRenderFunction<IntrisicElementProps<As>>;
}[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
/**

@@ -72,3 +109,3 @@ * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.

* Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
* IntrinsicShorthandProps). This allows IntrinsicShorthandProps to be used with React.forwardRef.
* IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
*

@@ -79,10 +116,25 @@ * The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional

export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
export declare type ComponentProps<Shorthands extends ObjectShorthandPropsRecord, Primary extends keyof Shorthands = 'root'> = Omit<{
[Key in keyof Shorthands]?: ShorthandProps<NonNullable<Shorthands[Key]>>;
}, Primary & 'root'> & PropsWithoutRef<Shorthands[Primary]>;
export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord> = {
/**
* Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.
*/
export declare type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;
/**
* Defines the Props type for a component given its slots and the definition of which one is the primary slot,
* defaulting to root if one is not provided.
*/
export declare type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<Slots, Primary & 'root'> & PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;
/**
* If type T includes `null`, remove it and add `undefined` instead.
*/
export declare type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;
/**
* Defines the State object of a component given its slots.
*/
export declare type ComponentState<Slots extends SlotPropsRecord> = {
components: {
[Key in keyof Shorthands]-?: React.ComponentType<NonNullable<Shorthands[Key]> extends ObjectShorthandProps<infer P> ? P : NonNullable<Shorthands[Key]>> | (NonNullable<Shorthands[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
[Key in keyof Slots]-?: React.ComponentType<ExtractSlotProps<Slots[Key]>> | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
};
} & Shorthands;
} & {
[Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
};
/**

@@ -89,0 +141,0 @@ * This is part of a hack to infer the element type from a native element *props* type.

@@ -8,2 +8,3 @@ export * from './useControllableState';

export * from './useIsomorphicLayoutEffect';
export * from './useMergedEventCallbacks';
export * from './useMergedRefs';

@@ -15,4 +16,3 @@ export * from './useMount';

export * from './useTimeout';
export * from './useTriggerElement';
export * from './useUnmount';
export * from './useForceUpdate';

@@ -8,2 +8,3 @@ export * from './useControllableState';

export * from './useIsomorphicLayoutEffect';
export * from './useMergedEventCallbacks';
export * from './useMergedRefs';

@@ -15,5 +16,4 @@ export * from './useMount';

export * from './useTimeout';
export * from './useTriggerElement';
export * from './useUnmount';
export * from './useForceUpdate';
//# sourceMappingURL=index.js.map

@@ -5,2 +5,2 @@ import * as React from 'react';

*/
export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React.ReactElement<any, string | React.JSXElementConstructor<any>> | ((props: TTriggerProps) => React.ReactNode) | null | undefined, triggerProps: TTriggerProps) => React.ReactNode;
export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React.ReactElement<any, string | React.JSXElementConstructor<any>> | ((props: TTriggerProps) => React.ReactElement | null) | null | undefined, triggerProps: TTriggerProps) => React.ReactElement | null;
import * as React from 'react';
import { onlyChild } from './onlyChild';
import { isFluentTrigger } from './isFluentTrigger';
/**

@@ -11,7 +11,27 @@ * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.

} else if (children) {
return /*#__PURE__*/React.cloneElement(onlyChild(children), triggerProps);
return cloneTriggerTree(children, triggerProps);
} // Components in React should return either JSX elements or "null", otherwise React will throw:
// Nothing was returned from render.
// This usually means a return statement is missing. Or, to render nothing, return null.
return children || null;
};
/**
* Clones a React element tree, and applies the given props to the first grandchild that is not
* a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).
*/
const cloneTriggerTree = (child, triggerProps) => {
if (! /*#__PURE__*/React.isValidElement(child) || child.type === React.Fragment) {
throw new Error('A trigger element must be a single element for this component. ' + "Please ensure that you're not using React Fragments.");
}
return children;
if (isFluentTrigger(child)) {
const grandchild = cloneTriggerTree(child.props.children, triggerProps);
return /*#__PURE__*/React.cloneElement(child, undefined, grandchild);
} else {
return /*#__PURE__*/React.cloneElement(child, triggerProps);
}
};
//# sourceMappingURL=applyTriggerPropsToChildren.js.map

@@ -18,9 +18,9 @@ import * as React from 'react';

*/
export declare const getPartitionedNativeProps: ({ primarySlotTagName, props, excludedPropNames, }: {
export declare const getPartitionedNativeProps: <Props extends Pick<React.HTMLAttributes<HTMLElement>, "style" | "className">, ExcludedPropKeys extends Extract<keyof Props, string> = never>({ primarySlotTagName, props, excludedPropNames, }: {
/** The primary slot's element type (e.g. 'div') */
primarySlotTagName: keyof JSX.IntrinsicElements;
/** The component's props object */
props: Pick<React.HTMLAttributes<HTMLElement>, 'style' | 'className'>;
props: Props;
/** List of native props to exclude from the returned value */
excludedPropNames?: string[] | undefined;
excludedPropNames?: ExcludedPropKeys[] | undefined;
}) => {

@@ -31,3 +31,3 @@ root: {

};
primary: React.HTMLAttributes<any>;
primary: Omit<Props, ExcludedPropKeys>;
};

@@ -5,5 +5,6 @@ export * from './applyTriggerPropsToChildren';

export * from './getRTLSafeKey';
export * from './getTriggerChild';
export * from './isFluentTrigger';
export * from './omit';
export * from './onlyChild';
export * from './properties';
export * from './shouldPreventDefaultOnKeyDown';

@@ -5,6 +5,7 @@ export * from './applyTriggerPropsToChildren';

export * from './getRTLSafeKey';
export * from './getTriggerChild';
export * from './isFluentTrigger';
export * from './omit';
export * from './onlyChild';
export * from './properties';
export * from './shouldPreventDefaultOnKeyDown';
//# sourceMappingURL=index.js.map
{
"name": "@fluentui/react-utilities",
"version": "0.0.0-nightlyd514b3e0ee20220121.1",
"version": "0.0.0-nightlyd80c90385320220216.1",
"description": "A set of general React-specific utilities.",

@@ -36,3 +36,3 @@ "main": "lib-commonjs/index.js",

"dependencies": {
"@fluentui/keyboard-keys": "0.0.0-nightlyd514b3e0ee20220121.1",
"@fluentui/keyboard-keys": "0.0.0-nightlyd80c90385320220216.1",
"tslib": "^2.1.0"

@@ -39,0 +39,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc