@fluentui/react-utilities 9.0.0-rc.1 → 9.0.0-rc.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/CHANGELOG.json +194 -1
  2. package/CHANGELOG.md +146 -68
  3. package/dist/{react-utilities.d.ts → index.d.ts} +14 -272
  4. package/{lib → dist}/tsdoc-metadata.json +0 -0
  5. package/lib/compose/getSlots.js.map +1 -1
  6. package/lib/compose/index.js.map +1 -1
  7. package/lib/compose/resolveShorthand.js.map +1 -1
  8. package/lib/compose/types.js +1 -5
  9. package/lib/compose/types.js.map +1 -1
  10. package/lib/hooks/index.js +1 -5
  11. package/lib/hooks/index.js.map +1 -1
  12. package/lib/hooks/useControllableState.js +1 -2
  13. package/lib/hooks/useControllableState.js.map +1 -1
  14. package/lib/hooks/useEventCallback.js.map +1 -1
  15. package/lib/hooks/useFirstMount.js.map +1 -1
  16. package/lib/hooks/useForceUpdate.js.map +1 -1
  17. package/lib/hooks/useId.js +9 -3
  18. package/lib/hooks/useId.js.map +1 -1
  19. package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -1
  20. package/lib/hooks/useMergedEventCallbacks.js.map +1 -1
  21. package/lib/hooks/useMergedRefs.js.map +1 -1
  22. package/lib/hooks/useOnClickOutside.js.map +1 -1
  23. package/lib/hooks/useOnScrollOutside.js.map +1 -1
  24. package/lib/hooks/usePrevious.js.map +1 -1
  25. package/lib/hooks/useTimeout.js +1 -2
  26. package/lib/hooks/useTimeout.js.map +1 -1
  27. package/lib/index.js +4 -4
  28. package/lib/index.js.map +1 -1
  29. package/lib/ssr/SSRContext.js.map +1 -1
  30. package/lib/ssr/canUseDOM.js.map +1 -1
  31. package/lib/ssr/index.js.map +1 -1
  32. package/lib/utils/applyTriggerPropsToChildren.js.map +1 -1
  33. package/lib/utils/clamp.js.map +1 -1
  34. package/lib/utils/getNativeElementProps.js +4 -2
  35. package/lib/utils/getNativeElementProps.js.map +1 -1
  36. package/lib/utils/getRTLSafeKey.js.map +1 -1
  37. package/lib/utils/getReactCallbackName.js.map +1 -1
  38. package/lib/utils/getTriggerChild.js.map +1 -1
  39. package/lib/utils/index.js.map +1 -1
  40. package/lib/utils/isFluentTrigger.js.map +1 -1
  41. package/lib/utils/omit.js.map +1 -1
  42. package/lib/utils/properties.js +18 -6
  43. package/lib/utils/properties.js.map +1 -1
  44. package/lib/utils/shouldPreventDefaultOnKeyDown.js +4 -0
  45. package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
  46. package/lib-commonjs/compose/getSlots.js.map +1 -1
  47. package/lib-commonjs/compose/index.js.map +1 -1
  48. package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
  49. package/lib-commonjs/compose/types.js +1 -5
  50. package/lib-commonjs/compose/types.js.map +1 -1
  51. package/lib-commonjs/hooks/index.js +2 -10
  52. package/lib-commonjs/hooks/index.js.map +1 -1
  53. package/lib-commonjs/hooks/useControllableState.js +1 -3
  54. package/lib-commonjs/hooks/useControllableState.js.map +1 -1
  55. package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
  56. package/lib-commonjs/hooks/useFirstMount.js.map +1 -1
  57. package/lib-commonjs/hooks/useForceUpdate.js.map +1 -1
  58. package/lib-commonjs/hooks/useId.js +9 -3
  59. package/lib-commonjs/hooks/useId.js.map +1 -1
  60. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
  61. package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +1 -1
  62. package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
  63. package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
  64. package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
  65. package/lib-commonjs/hooks/usePrevious.js.map +1 -1
  66. package/lib-commonjs/hooks/useTimeout.js +1 -3
  67. package/lib-commonjs/hooks/useTimeout.js.map +1 -1
  68. package/lib-commonjs/index.js +158 -5
  69. package/lib-commonjs/index.js.map +1 -1
  70. package/lib-commonjs/ssr/SSRContext.js.map +1 -1
  71. package/lib-commonjs/ssr/canUseDOM.js.map +1 -1
  72. package/lib-commonjs/ssr/index.js.map +1 -1
  73. package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -1
  74. package/lib-commonjs/utils/clamp.js.map +1 -1
  75. package/lib-commonjs/utils/getNativeElementProps.js +3 -1
  76. package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
  77. package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -1
  78. package/lib-commonjs/utils/getReactCallbackName.js.map +1 -1
  79. package/lib-commonjs/utils/getTriggerChild.js.map +1 -1
  80. package/lib-commonjs/utils/index.js.map +1 -1
  81. package/lib-commonjs/utils/isFluentTrigger.js.map +1 -1
  82. package/lib-commonjs/utils/omit.js.map +1 -1
  83. package/lib-commonjs/utils/properties.js +19 -7
  84. package/lib-commonjs/utils/properties.js.map +1 -1
  85. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js +4 -0
  86. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
  87. package/package.json +12 -10
  88. package/lib/compose/getSlots.d.ts +0 -30
  89. package/lib/compose/index.d.ts +0 -3
  90. package/lib/compose/resolveShorthand.d.ts +0 -16
  91. package/lib/compose/types.d.ts +0 -155
  92. package/lib/hooks/index.d.ts +0 -16
  93. package/lib/hooks/useBoolean.d.ts +0 -17
  94. package/lib/hooks/useBoolean.js +0 -28
  95. package/lib/hooks/useBoolean.js.map +0 -1
  96. package/lib/hooks/useConst.d.ts +0 -12
  97. package/lib/hooks/useConst.js +0 -30
  98. package/lib/hooks/useConst.js.map +0 -1
  99. package/lib/hooks/useControllableState.d.ts +0 -31
  100. package/lib/hooks/useEventCallback.d.ts +0 -13
  101. package/lib/hooks/useFirstMount.d.ts +0 -11
  102. package/lib/hooks/useForceUpdate.d.ts +0 -4
  103. package/lib/hooks/useId.d.ts +0 -15
  104. package/lib/hooks/useIsomorphicLayoutEffect.d.ts +0 -11
  105. package/lib/hooks/useMergedEventCallbacks.d.ts +0 -18
  106. package/lib/hooks/useMergedRefs.d.ts +0 -13
  107. package/lib/hooks/useMount.d.ts +0 -6
  108. package/lib/hooks/useMount.js +0 -17
  109. package/lib/hooks/useMount.js.map +0 -1
  110. package/lib/hooks/useOnClickOutside.d.ts +0 -29
  111. package/lib/hooks/useOnScrollOutside.d.ts +0 -5
  112. package/lib/hooks/usePrevious.d.ts +0 -1
  113. package/lib/hooks/useTimeout.d.ts +0 -8
  114. package/lib/hooks/useUnmount.d.ts +0 -6
  115. package/lib/hooks/useUnmount.js +0 -17
  116. package/lib/hooks/useUnmount.js.map +0 -1
  117. package/lib/index.d.ts +0 -4
  118. package/lib/ssr/SSRContext.d.ts +0 -33
  119. package/lib/ssr/canUseDOM.d.ts +0 -4
  120. package/lib/ssr/index.d.ts +0 -2
  121. package/lib/utils/applyTriggerPropsToChildren.d.ts +0 -5
  122. package/lib/utils/clamp.d.ts +0 -8
  123. package/lib/utils/getNativeElementProps.d.ts +0 -31
  124. package/lib/utils/getRTLSafeKey.d.ts +0 -4
  125. package/lib/utils/getReactCallbackName.d.ts +0 -25
  126. package/lib/utils/getTriggerChild.d.ts +0 -22
  127. package/lib/utils/index.d.ts +0 -9
  128. package/lib/utils/isFluentTrigger.d.ts +0 -22
  129. package/lib/utils/omit.d.ts +0 -14
  130. package/lib/utils/properties.d.ts +0 -148
  131. package/lib/utils/shouldPreventDefaultOnKeyDown.d.ts +0 -7
  132. package/lib-commonjs/compose/getSlots.d.ts +0 -30
  133. package/lib-commonjs/compose/index.d.ts +0 -3
  134. package/lib-commonjs/compose/resolveShorthand.d.ts +0 -16
  135. package/lib-commonjs/compose/types.d.ts +0 -155
  136. package/lib-commonjs/hooks/index.d.ts +0 -16
  137. package/lib-commonjs/hooks/useBoolean.d.ts +0 -17
  138. package/lib-commonjs/hooks/useBoolean.js +0 -39
  139. package/lib-commonjs/hooks/useBoolean.js.map +0 -1
  140. package/lib-commonjs/hooks/useConst.d.ts +0 -12
  141. package/lib-commonjs/hooks/useConst.js +0 -40
  142. package/lib-commonjs/hooks/useConst.js.map +0 -1
  143. package/lib-commonjs/hooks/useControllableState.d.ts +0 -31
  144. package/lib-commonjs/hooks/useEventCallback.d.ts +0 -13
  145. package/lib-commonjs/hooks/useFirstMount.d.ts +0 -11
  146. package/lib-commonjs/hooks/useForceUpdate.d.ts +0 -4
  147. package/lib-commonjs/hooks/useId.d.ts +0 -15
  148. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.d.ts +0 -11
  149. package/lib-commonjs/hooks/useMergedEventCallbacks.d.ts +0 -18
  150. package/lib-commonjs/hooks/useMergedRefs.d.ts +0 -13
  151. package/lib-commonjs/hooks/useMount.d.ts +0 -6
  152. package/lib-commonjs/hooks/useMount.js +0 -27
  153. package/lib-commonjs/hooks/useMount.js.map +0 -1
  154. package/lib-commonjs/hooks/useOnClickOutside.d.ts +0 -29
  155. package/lib-commonjs/hooks/useOnScrollOutside.d.ts +0 -5
  156. package/lib-commonjs/hooks/usePrevious.d.ts +0 -1
  157. package/lib-commonjs/hooks/useTimeout.d.ts +0 -8
  158. package/lib-commonjs/hooks/useUnmount.d.ts +0 -6
  159. package/lib-commonjs/hooks/useUnmount.js +0 -27
  160. package/lib-commonjs/hooks/useUnmount.js.map +0 -1
  161. package/lib-commonjs/index.d.ts +0 -4
  162. package/lib-commonjs/ssr/SSRContext.d.ts +0 -33
  163. package/lib-commonjs/ssr/canUseDOM.d.ts +0 -4
  164. package/lib-commonjs/ssr/index.d.ts +0 -2
  165. package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +0 -5
  166. package/lib-commonjs/utils/clamp.d.ts +0 -8
  167. package/lib-commonjs/utils/getNativeElementProps.d.ts +0 -31
  168. package/lib-commonjs/utils/getRTLSafeKey.d.ts +0 -4
  169. package/lib-commonjs/utils/getReactCallbackName.d.ts +0 -25
  170. package/lib-commonjs/utils/getTriggerChild.d.ts +0 -22
  171. package/lib-commonjs/utils/index.d.ts +0 -9
  172. package/lib-commonjs/utils/isFluentTrigger.d.ts +0 -22
  173. package/lib-commonjs/utils/omit.d.ts +0 -14
  174. package/lib-commonjs/utils/properties.d.ts +0 -148
  175. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.d.ts +0 -7
@@ -1,33 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * To support SSR, the auto incrementing id counter is stored in a context. This allows it to be reset on every request
4
- * to ensure the client and server are consistent.
5
- *
6
- * @internal
7
- */
8
- export declare type SSRContextValue = {
9
- current: number;
10
- };
11
- /**
12
- * Default context value to use in case there is no SSRProvider. This is fine for client-only apps.
13
- *
14
- * @internal
15
- */
16
- export declare const defaultSSRContextValue: SSRContextValue;
17
- export declare const SSRContext: React.Context<SSRContextValue>;
18
- /**
19
- * @internal
20
- */
21
- export declare function useSSRContext(): SSRContextValue;
22
- /**
23
- * When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids
24
- * are consistent between the client and server.
25
- *
26
- * @public
27
- */
28
- export declare const SSRProvider: React.FC;
29
- /**
30
- * Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay
31
- * browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.
32
- */
33
- export declare function useIsSSR(): boolean;
@@ -1,4 +0,0 @@
1
- /**
2
- * Verifies if an application can use DOM.
3
- */
4
- export declare function canUseDOM(): boolean;
@@ -1,2 +0,0 @@
1
- export * from './canUseDOM';
2
- export * from './SSRContext';
@@ -1,5 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
4
- */
5
- 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;
@@ -1,8 +0,0 @@
1
- /**
2
- * Clamps `value` to a number between the min and max.
3
- *
4
- * @param value - the value to be clamped
5
- * @param min - the lowest valid value
6
- * @param max - the highest valid value
7
- */
8
- export declare const clamp: (value: number, min: number, max: number) => number;
@@ -1,31 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * Given an element tagname and user props, filters the props to only allowed props for the given
4
- * element type.
5
- * @param tagName - Tag name (e.g. "div")
6
- * @param props - Props object
7
- * @param excludedPropNames - List of props to disallow
8
- */
9
- export declare function getNativeElementProps<TAttributes extends React.HTMLAttributes<any>>(tagName: string, props: {}, excludedPropNames?: string[]): TAttributes;
10
- /**
11
- * Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
12
- *
13
- * This function is only for use with components that have a primary slot other than `root`.
14
- * Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.
15
- *
16
- * @returns An object containing the native props for the `root` and primary slots.
17
- */
18
- export declare const getPartitionedNativeProps: <Props extends Pick<React.HTMLAttributes<HTMLElement>, "style" | "className">, ExcludedPropKeys extends Extract<keyof Props, string> = never>({ primarySlotTagName, props, excludedPropNames, }: {
19
- /** The primary slot's element type (e.g. 'div') */
20
- primarySlotTagName: keyof JSX.IntrinsicElements;
21
- /** The component's props object */
22
- props: Props;
23
- /** List of native props to exclude from the returned value */
24
- excludedPropNames?: ExcludedPropKeys[] | undefined;
25
- }) => {
26
- root: {
27
- style: React.CSSProperties | undefined;
28
- className: string | undefined;
29
- };
30
- primary: Omit<Props, ExcludedPropKeys>;
31
- };
@@ -1,4 +0,0 @@
1
- /**
2
- * Finds and swaps a provided key for it's right to left format.
3
- */
4
- export declare const getRTLSafeKey: (key: string, dir: 'ltr' | 'rtl') => string;
@@ -1,25 +0,0 @@
1
- import * as React from 'react';
2
- interface ReactSyntheticEvent extends React.SyntheticEvent<unknown> {
3
- _reactName?: string;
4
- dispatchConfig?: {
5
- registrationName: string;
6
- phasedRegistrationNames: {
7
- bubbled: string;
8
- captured: string;
9
- };
10
- };
11
- }
12
- declare type NonUndefined<A> = A extends undefined ? never : A;
13
- declare type FunctionKeys<T extends object> = {
14
- [K in keyof T]-?: NonUndefined<T[K]> extends Function ? K : never;
15
- }[keyof T];
16
- export declare type ReactCallbackName = FunctionKeys<React.DOMAttributes<unknown>>;
17
- /**
18
- * React.SyntheticEvent contains name of a callback that should be fired, this function returns it.
19
- *
20
- * Ideally, it should also distinguish regular and "capture" callbacks, but it's possible only with React 17 as
21
- * ".eventPhase" there has proper value, see https://github.com/facebook/react/pull/19244. In React 16 all events
22
- * are handled in bubble phase.
23
- */
24
- export declare function getReactCallbackName(event: ReactSyntheticEvent): ReactCallbackName | undefined;
25
- export {};
@@ -1,22 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).
4
- *
5
- * In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,
6
- * it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.
7
- * This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.
8
- *
9
- * For example, the following returns `<div id="child" />`:
10
- * ```jsx
11
- * getTriggerChild(
12
- * <Tooltip>
13
- * <MenuTrigger>
14
- * <div id="child" />
15
- * </MenuTrigger>
16
- * </Tooltip>
17
- * );
18
- * ```
19
- */
20
- export declare const getTriggerChild: (children: React.ReactNode) => React.ReactElement & {
21
- ref?: React.Ref<unknown>;
22
- };
@@ -1,9 +0,0 @@
1
- export * from './applyTriggerPropsToChildren';
2
- export * from './clamp';
3
- export * from './getNativeElementProps';
4
- export * from './getRTLSafeKey';
5
- export * from './getTriggerChild';
6
- export * from './isFluentTrigger';
7
- export * from './omit';
8
- export * from './properties';
9
- export * from './shouldPreventDefaultOnKeyDown';
@@ -1,22 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * Allows a component to be tagged as a FluentUI trigger component.
4
- *
5
- * Triggers are special-case components: they attach event listeners and other props on their child,
6
- * and use them to trigger another component to show. Examples include `MenuTrigger` and `Tooltip`.
7
- *
8
- * A component can be tagged as a trigger as follows:
9
- * ```ts
10
- * const MyComponent: React.FC<MyComponentProps> & FluentTriggerComponent = ...;
11
- *
12
- * MyComponent.isFluentTriggerComponent = true; // MUST also set this to true
13
- * ```
14
- */
15
- export declare type FluentTriggerComponent = {
16
- isFluentTriggerComponent?: boolean;
17
- };
18
- /**
19
- * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).
20
- * See the {@link FluentTriggerComponent} type for more info.
21
- */
22
- export declare const isFluentTrigger: (element: React.ReactElement) => boolean | undefined;
@@ -1,14 +0,0 @@
1
- /**
2
- * Tiny helper to do the minimal amount of work in duplicating an object but omitting some
3
- * props. This ends up faster than using object ...rest or reduce to filter.
4
- *
5
- * This behaves very much like filteredAssign, but does not merge many objects together,
6
- * uses an exclusion object map, and avoids spreads all for optimal performance.
7
- *
8
- * See perf test for background:
9
- * https://jsperf.com/omit-vs-rest-vs-reduce/1
10
- *
11
- * @param obj - The object to clone
12
- * @param exclusions - The array of keys to exclude
13
- */
14
- export declare function omit<TObj extends Record<string, any>, Exclusions extends (keyof TObj)[]>(obj: TObj, exclusions: Exclusions): Omit<TObj, Exclusions[number]>;
@@ -1,148 +0,0 @@
1
- /**
2
- * An array of events that are allowed on every html element type.
3
- *
4
- * @public
5
- */
6
- export declare const baseElementEvents: Record<string, number>;
7
- /**
8
- * An array of element attributes which are allowed on every html element type.
9
- *
10
- * @public
11
- */
12
- export declare const baseElementProperties: Record<string, number>;
13
- /**
14
- * An array of HTML element properties and events.
15
- *
16
- * @public
17
- */
18
- export declare const htmlElementProperties: Record<string, number>;
19
- /**
20
- * An array of LABEL tag properties and events.
21
- *
22
- * @public
23
- */
24
- export declare const labelProperties: Record<string, number>;
25
- /**
26
- * An array of AUDIO tag properties and events.
27
-
28
- * @public
29
- */
30
- export declare const audioProperties: Record<string, number>;
31
- /**
32
- * An array of VIDEO tag properties and events.
33
- *
34
- * @public
35
- */
36
- export declare const videoProperties: Record<string, number>;
37
- /**
38
- * An array of OL tag properties and events.
39
- *
40
- * @public
41
- */
42
- export declare const olProperties: Record<string, number>;
43
- /**
44
- * An array of LI tag properties and events.
45
- *
46
- * @public
47
- */
48
- export declare const liProperties: Record<string, number>;
49
- /**
50
- * An array of A tag properties and events.
51
- *
52
- * @public
53
- */
54
- export declare const anchorProperties: Record<string, number>;
55
- /**
56
- * An array of BUTTON tag properties and events.
57
- *
58
- * @public
59
- */
60
- export declare const buttonProperties: Record<string, number>;
61
- /**
62
- * An array of INPUT tag properties and events.
63
- *
64
- * @public
65
- */
66
- export declare const inputProperties: Record<string, number>;
67
- /**
68
- * An array of TEXTAREA tag properties and events.
69
- *
70
- * @public
71
- */
72
- export declare const textAreaProperties: Record<string, number>;
73
- /**
74
- * An array of SELECT tag properties and events.
75
- *
76
- * @public
77
- */
78
- export declare const selectProperties: Record<string, number>;
79
- export declare const optionProperties: Record<string, number>;
80
- /**
81
- * An array of TABLE tag properties and events.
82
- *
83
- * @public
84
- */
85
- export declare const tableProperties: Record<string, number>;
86
- /**
87
- * An array of TR tag properties and events.
88
- *
89
- * @public
90
- */
91
- export declare const trProperties: Record<string, number>;
92
- /**
93
- * An array of TH tag properties and events.
94
- *
95
- * @public
96
- */
97
- export declare const thProperties: Record<string, number>;
98
- /**
99
- * An array of TD tag properties and events.
100
- *
101
- * @public
102
- */
103
- export declare const tdProperties: Record<string, number>;
104
- export declare const colGroupProperties: Record<string, number>;
105
- export declare const colProperties: Record<string, number>;
106
- /**
107
- * An array of FORM tag properties and events.
108
- *
109
- * @public
110
- */
111
- export declare const formProperties: Record<string, number>;
112
- /**
113
- * An array of IFRAME tag properties and events.
114
- *
115
- * @public
116
- */
117
- export declare const iframeProperties: Record<string, number>;
118
- /**
119
- * An array of IMAGE tag properties and events.
120
- *
121
- * @public
122
- */
123
- export declare const imgProperties: Record<string, number>;
124
- /**
125
- * @deprecated Use imgProperties for img elements.
126
- */
127
- export declare const imageProperties: Record<string, number>;
128
- /**
129
- * An array of DIV tag properties and events.
130
- *
131
- * @public
132
- */
133
- export declare const divProperties: Record<string, number>;
134
- /**
135
- * Gets native supported props for an html element provided the allowance set. Use one of the property
136
- * sets defined (divProperties, buttonPropertes, etc) to filter out supported properties from a given
137
- * props set. Note that all data- and aria- prefixed attributes will be allowed.
138
- * NOTE: getNativeProps should always be applied first when adding props to a react component. The
139
- * non-native props should be applied second. This will prevent getNativeProps from overriding your custom props.
140
- * For example, if props passed to getNativeProps has an onClick function and getNativeProps is added to
141
- * the component after an onClick function is added, then the getNativeProps onClick will override it.
142
- *
143
- * @public
144
- * @param props - The unfiltered input props
145
- * @param allowedPropsNames - The array or record of allowed prop names.
146
- * @returns The filtered props
147
- */
148
- export declare function getNativeProps<T extends Record<string, any>>(props: Record<string, any>, allowedPropNames: string[] | Record<string, number>, excludedPropNames?: string[]): T;
@@ -1,7 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * Checks if the keyboard event should preventDefault() for Enter and Spacebar keys
4
- *
5
- * Useful for situations where a keydown needs to be transformed to a click event
6
- */
7
- export declare function shouldPreventDefaultOnKeyDown(e: KeyboardEvent | React.KeyboardEvent): boolean;
@@ -1,30 +0,0 @@
1
- import * as React from 'react';
2
- import type { AsIntrinsicElement, ComponentState, ExtractSlotProps, SlotPropsRecord, UnionToIntersection } from './types';
3
- export declare type Slots<S extends SlotPropsRecord> = {
4
- [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]>>;
5
- };
6
- declare type ObjectSlotProps<S extends SlotPropsRecord> = {
7
- [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;
8
- };
9
- /**
10
- * Given the state and an array of slot names, will break out `slots` and `slotProps`
11
- * collections.
12
- *
13
- * The root is derived from a mix of `components` props and `as` prop.
14
- *
15
- * Slots will render as null if they are rendered as primitives with undefined children.
16
- *
17
- * The slotProps will always omit the `as` prop within them, and for slots that are string
18
- * primitives, the props will be filtered according to the slot type by the type system.
19
- * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable
20
- * anchor props. Note that this is only enforced at build time by Typescript -- there is no
21
- * runtime code filtering props in this function.
22
- *
23
- * @param state - State including slot definitions
24
- * @returns An object containing the `slots` map and `slotProps` map.
25
- */
26
- export declare function getSlots<R extends SlotPropsRecord>(state: ComponentState<R>): {
27
- slots: Slots<R>;
28
- slotProps: ObjectSlotProps<R>;
29
- };
30
- export {};
@@ -1,3 +0,0 @@
1
- export * from './getSlots';
2
- export * from './resolveShorthand';
3
- export * from './types';
@@ -1,16 +0,0 @@
1
- import type { ReplaceNullWithUndefined, SlotShorthandValue, UnknownSlotProps } from './types';
2
- export declare type ResolveShorthandOptions<Props, Required extends boolean = false> = {
3
- required?: Required;
4
- defaultProps?: Props;
5
- };
6
- export declare type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {
7
- <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, true>): ReplaceNullWithUndefined<P>;
8
- <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>): ReplaceNullWithUndefined<P> | undefined;
9
- };
10
- /**
11
- * Resolves shorthands into slot props, to ensure normalization of the signature
12
- * being passed down to getSlots method
13
- * @param value - the base shorthand props
14
- * @param options - options to resolve shorthand props
15
- */
16
- export declare const resolveShorthand: ResolveShorthandFunction;
@@ -1,155 +0,0 @@
1
- import * as React from 'react';
2
- export declare type SlotRenderFunction<Props> = (Component: React.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React.ReactNode;
3
- /**
4
- * Matches any component's Slots type (such as ButtonSlots).
5
- *
6
- * This should ONLY be used in type templates as in `extends SlotPropsRecord`;
7
- * it shouldn't be used as a component's Slots type.
8
- */
9
- export declare type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;
10
- /**
11
- * The shorthand value of a slot allows specifying its child
12
- */
13
- export declare type SlotShorthandValue = React.ReactChild | React.ReactNodeArray | React.ReactPortal;
14
- /**
15
- * Matches any slot props type.
16
- *
17
- * This should ONLY be used in type templates as in `extends UnknownSlotProps`;
18
- * it shouldn't be used as the type of a slot.
19
- */
20
- export declare type UnknownSlotProps = Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
21
- as?: keyof JSX.IntrinsicElements;
22
- };
23
- /**
24
- * Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.
25
- */
26
- declare type WithSlotShorthandValue<Props extends {
27
- children?: unknown;
28
- }> = Props | Extract<SlotShorthandValue, Props['children']>;
29
- /**
30
- * Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`
31
- * to be a render function that takes those props.
32
- */
33
- declare type WithSlotRenderFunction<Props extends {
34
- children?: unknown;
35
- }> = Props & {
36
- children?: Props['children'] | SlotRenderFunction<Props>;
37
- };
38
- /**
39
- * HTML element types that are not allowed to have children.
40
- *
41
- * Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
42
- */
43
- declare type EmptyIntrisicElements = 'area' | 'base' | 'br' | 'col' | 'embed' | 'hr' | 'img' | 'input' | 'link' | 'meta' | 'param' | 'source' | 'track' | 'wbr';
44
- /**
45
- * Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:
46
- * * Removes legacy string ref.
47
- * * Disallows children for empty tags like 'img'.
48
- */
49
- declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React.PropsWithRef<JSX.IntrinsicElements[Type]> & (Type extends EmptyIntrisicElements ? {
50
- children?: never;
51
- } : {});
52
- /**
53
- * The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,
54
- * or a component like `typeof Button`.
55
- *
56
- * If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).
57
- *
58
- * By default, slots can be set to `null` to prevent them from being rendered. If a slot must always be rendered,
59
- * wrap with `NonNullable` (see examples below).
60
- *
61
- * @example
62
- * ```
63
- * // Intrinsic element examples:
64
- * Slot<'div'> // Slot is always div
65
- * Slot<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
66
- * Slot<'span', 'div' | 'pre'> // Defaults to span, but allows as="div" or as="pre"
67
- * NonNullable<Slot<'div'>> // Slot that will always be rendered (can't be set to null by the user)
68
- *
69
- * // Component examples:
70
- * Slot<typeof Button> // Slot is always a Button, and accepts all of Button's Props
71
- * NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)
72
- * ```
73
- */
74
- 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 ? {
75
- as?: Type;
76
- } & WithSlotRenderFunction<IntrisicElementProps<Type>> : Type extends React.ComponentType<infer Props> ? WithSlotRenderFunction<Props> : Type> | {
77
- [As in AlternateAs]: {
78
- as: As;
79
- } & WithSlotRenderFunction<IntrisicElementProps<As>>;
80
- }[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
81
- /**
82
- * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
83
- *
84
- * ```
85
- * IsSingleton<'a'> // true
86
- * IsSingleton<'a' | 'b' | 'c'> // false
87
- * ```
88
- */
89
- export declare type IsSingleton<T extends string> = {
90
- [K in T]: Exclude<T, K> extends never ? true : false;
91
- }[T];
92
- /**
93
- * Helper type for inferring the type of the as prop from a Props type.
94
- *
95
- * For example:
96
- * ```
97
- * type Example<T> = T extends AsIntrinsicElement<infer As> ? As : never;
98
- * ```
99
- */
100
- export declare type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> = {
101
- as?: As;
102
- };
103
- /**
104
- * Converts a union type (`A | B | C`) to an intersection type (`A & B & C`)
105
- */
106
- export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
107
- /**
108
- * Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
109
- * IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
110
- *
111
- * The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
112
- * types, to prevent unions from being expanded.
113
- */
114
- export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
115
- /**
116
- * Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.
117
- */
118
- export declare type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;
119
- /**
120
- * Defines the Props type for a component given its slots and the definition of which one is the primary slot,
121
- * defaulting to root if one is not provided.
122
- */
123
- export declare type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<Slots, Primary & 'root'> & PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;
124
- /**
125
- * If type T includes `null`, remove it and add `undefined` instead.
126
- */
127
- export declare type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;
128
- /**
129
- * Defines the State object of a component given its slots.
130
- */
131
- export declare type ComponentState<Slots extends SlotPropsRecord> = {
132
- components: {
133
- [Key in keyof Slots]-?: React.ComponentType<ExtractSlotProps<Slots[Key]>> | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
134
- };
135
- } & {
136
- [Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
137
- };
138
- /**
139
- * This is part of a hack to infer the element type from a native element *props* type.
140
- * The only place the original element is found in a native props type (at least that's workable
141
- * for inference) is in the event handlers, so some of the helper types use this event handler
142
- * name to infer the original element type.
143
- *
144
- * Notes:
145
- * - Using an extremely obscure event handler reduces the likelihood that its signature will be
146
- * modified in any component's props.
147
- * - Inferring based on a single prop name instead of a larger type like `DOMAttributes<T>` should be
148
- * less expensive for typescript to evaluate and is less likely to result in type expansion in .d.ts.
149
- */
150
- declare type ObscureEventName = 'onLostPointerCaptureCapture';
151
- /**
152
- * Return type for `React.forwardRef`, including inference of the proper typing for the ref.
153
- */
154
- export declare type ForwardRefComponent<Props> = ObscureEventName extends keyof Props ? Required<Props>[ObscureEventName] extends React.PointerEventHandler<infer Element> ? React.ForwardRefExoticComponent<Props & React.RefAttributes<Element>> : never : never;
155
- export {};
@@ -1,16 +0,0 @@
1
- export * from './useControllableState';
2
- export * from './useBoolean';
3
- export * from './useConst';
4
- export * from './useEventCallback';
5
- export * from './useFirstMount';
6
- export * from './useId';
7
- export * from './useIsomorphicLayoutEffect';
8
- export * from './useMergedEventCallbacks';
9
- export * from './useMergedRefs';
10
- export * from './useMount';
11
- export * from './useOnClickOutside';
12
- export * from './useOnScrollOutside';
13
- export * from './usePrevious';
14
- export * from './useTimeout';
15
- export * from './useUnmount';
16
- export * from './useForceUpdate';
@@ -1,17 +0,0 @@
1
- /** Updater callbacks returned by `useBoolean`. */
2
- export declare type UseBooleanCallbacks = {
3
- /** Set the value to true. Always has the same identity. */
4
- setTrue: () => void;
5
- /** Set the value to false. Always has the same identity. */
6
- setFalse: () => void;
7
- /** Toggle the value. Always has the same identity. */
8
- toggle: () => void;
9
- };
10
- /**
11
- * Hook to store a value and generate callbacks for setting the value to true or false.
12
- * The identity of the callbacks will always stay the same.
13
- *
14
- * @param initialState - Initial value
15
- * @returns Array with the current value and an object containing the updater callbacks.
16
- */
17
- export declare function useBoolean(initialState: boolean): [boolean, UseBooleanCallbacks];
@@ -1,39 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useBoolean = void 0;
7
-
8
- const React = /*#__PURE__*/require("react");
9
-
10
- const useConst_1 = /*#__PURE__*/require("./useConst");
11
- /**
12
- * Hook to store a value and generate callbacks for setting the value to true or false.
13
- * The identity of the callbacks will always stay the same.
14
- *
15
- * @param initialState - Initial value
16
- * @returns Array with the current value and an object containing the updater callbacks.
17
- */
18
-
19
-
20
- function useBoolean(initialState) {
21
- const [value, setValue] = React.useState(initialState);
22
- const setTrue = useConst_1.useConst(() => () => {
23
- setValue(true);
24
- });
25
- const setFalse = useConst_1.useConst(() => () => {
26
- setValue(false);
27
- });
28
- const toggle = useConst_1.useConst(() => () => {
29
- setValue(currentValue => !currentValue);
30
- });
31
- return [value, {
32
- setTrue,
33
- setFalse,
34
- toggle
35
- }];
36
- }
37
-
38
- exports.useBoolean = useBoolean;
39
- //# sourceMappingURL=useBoolean.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/hooks/useBoolean.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;AAYA;;;;;;AAMG;;;AACH,SAAgB,UAAhB,CAA2B,YAA3B,EAAgD;AAC9C,QAAM,CAAC,KAAD,EAAQ,QAAR,IAAoB,KAAK,CAAC,QAAN,CAAe,YAAf,CAA1B;AAEA,QAAM,OAAO,GAAG,UAAA,CAAA,QAAA,CAAS,MAAM,MAAK;AAClC,IAAA,QAAQ,CAAC,IAAD,CAAR;AACD,GAFe,CAAhB;AAGA,QAAM,QAAQ,GAAG,UAAA,CAAA,QAAA,CAAS,MAAM,MAAK;AACnC,IAAA,QAAQ,CAAC,KAAD,CAAR;AACD,GAFgB,CAAjB;AAGA,QAAM,MAAM,GAAG,UAAA,CAAA,QAAA,CAAS,MAAM,MAAK;AACjC,IAAA,QAAQ,CAAC,YAAY,IAAI,CAAC,YAAlB,CAAR;AACD,GAFc,CAAf;AAIA,SAAO,CAAC,KAAD,EAAQ;AAAE,IAAA,OAAF;AAAW,IAAA,QAAX;AAAqB,IAAA;AAArB,GAAR,CAAP;AACD;;AAdD,OAAA,CAAA,UAAA,GAAA,UAAA","sourceRoot":""}
@@ -1,12 +0,0 @@
1
- /**
2
- * Hook to initialize and return a constant value. Unlike `React.useMemo`, this is guaranteed to
3
- * always return the same value (and if the initializer is a function, only call it once).
4
- * This is similar to setting a private member in a class constructor.
5
- *
6
- * If the value should ever change based on dependencies, use `React.useMemo` instead.
7
- *
8
- * @param initialValue - Initial value, or function to get the initial value. Similar to `useState`,
9
- * only the value/function passed in the first time this is called is respected.
10
- * @returns The value. The identity of this value will always be the same.
11
- */
12
- export declare function useConst<T>(initialValue: T | (() => T)): T;