@entur/utils 0.12.4-beta.3 → 0.12.5
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.
- package/dist/ConditionalWrapper.d.ts +7 -0
- package/dist/PolymorphicComponent.d.ts +38 -0
- package/dist/getNodeText.d.ts +1 -0
- package/dist/index.d.ts +13 -82
- package/dist/mergeRefs.d.ts +1 -0
- package/dist/types/variants.d.ts +1 -0
- package/dist/useDebounce.d.ts +1 -0
- package/dist/useForceUpdate.d.ts +1 -0
- package/dist/useOnClickOutside.d.ts +2 -0
- package/dist/useOnEscape.d.ts +2 -0
- package/dist/useOnMount.d.ts +1 -0
- package/dist/useRandomId.d.ts +1 -0
- package/dist/useWindowDimensions.d.ts +6 -0
- package/dist/warnAboutMissingStyles.d.ts +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export type PropsOf<C extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>> = JSX.LibraryManagedAttributes<C, React.ComponentPropsWithoutRef<C>>;
|
|
3
|
+
type AsProp<C extends React.ElementType> = {
|
|
4
|
+
/**
|
|
5
|
+
* An override of the default HTML tag.
|
|
6
|
+
* Can also be another React component.
|
|
7
|
+
*/
|
|
8
|
+
as?: C;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Allows for extending a set of props (`ExtendedProps`) by an overriding set of props
|
|
12
|
+
* (`OverrideProps`), ensuring that any duplicates are overridden by the overriding
|
|
13
|
+
* set of props.
|
|
14
|
+
*/
|
|
15
|
+
export type ExtendableProps<ExtendedProps = Record<string, unknown>, OverrideProps = Record<string, unknown>> = OverrideProps & Omit<ExtendedProps, keyof OverrideProps>;
|
|
16
|
+
/**
|
|
17
|
+
* Allows for inheriting the props from the specified element type so that
|
|
18
|
+
* props like children, className & style work, as well as element-specific
|
|
19
|
+
* attributes like aria roles. The component (`C`) must be passed in.
|
|
20
|
+
*/
|
|
21
|
+
export type InheritableElementProps<C extends React.ElementType, Props = Record<string, unknown>> = ExtendableProps<PropsOf<C>, Props>;
|
|
22
|
+
/**
|
|
23
|
+
* A more sophisticated version of `InheritableElementProps` where
|
|
24
|
+
* the passed in `as` prop will determine which props can be included
|
|
25
|
+
*/
|
|
26
|
+
export type PolymorphicComponentProps<C extends React.ElementType, Props = Record<string, unknown>> = InheritableElementProps<C, Props & AsProp<C>>;
|
|
27
|
+
/**
|
|
28
|
+
* Utility type to extract the `ref` prop from a polymorphic component
|
|
29
|
+
*/
|
|
30
|
+
export type PolymorphicRef<C extends React.ElementType> = React.ComponentPropsWithRef<C>['ref'];
|
|
31
|
+
/**
|
|
32
|
+
* A wrapper of `PolymorphicComponentProps` that also includes the `ref`
|
|
33
|
+
* prop for the polymorphic component
|
|
34
|
+
*/
|
|
35
|
+
export type PolymorphicComponentPropsWithRef<C extends React.ElementType, Props = Record<string, unknown>> = PolymorphicComponentProps<C, Props> & {
|
|
36
|
+
ref?: PolymorphicRef<C>;
|
|
37
|
+
};
|
|
38
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getNodeText: (node: React.ReactNode | string | number | string[] | number[]) => string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,82 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
condition: boolean;
|
|
15
|
-
wrapper: any;
|
|
16
|
-
children: any;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Allows for extending a set of props (`ExtendedProps`) by an overriding set of props
|
|
21
|
-
* (`OverrideProps`), ensuring that any duplicates are overridden by the overriding
|
|
22
|
-
* set of props.
|
|
23
|
-
*/
|
|
24
|
-
export declare type ExtendableProps<ExtendedProps = Record<string, unknown>, OverrideProps = Record<string, unknown>> = OverrideProps & Omit<ExtendedProps, keyof OverrideProps>;
|
|
25
|
-
|
|
26
|
-
export declare const getNodeText: (node: React.ReactNode | string | number | string[] | number[]) => string;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Allows for inheriting the props from the specified element type so that
|
|
30
|
-
* props like children, className & style work, as well as element-specific
|
|
31
|
-
* attributes like aria roles. The component (`C`) must be passed in.
|
|
32
|
-
*/
|
|
33
|
-
export declare type InheritableElementProps<C extends default_2.ElementType, Props = Record<string, unknown>> = ExtendableProps<PropsOf<C>, Props>;
|
|
34
|
-
|
|
35
|
-
export declare const mergeRefs: <T extends HTMLElement>(...refs: (React.MutableRefObject<T> | React.ForwardedRef<T> | ((node: T | null) => void) | undefined)[]) => (node: T) => void;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* A more sophisticated version of `InheritableElementProps` where
|
|
39
|
-
* the passed in `as` prop will determine which props can be included
|
|
40
|
-
*/
|
|
41
|
-
export declare type PolymorphicComponentProps<C extends default_2.ElementType, Props = Record<string, unknown>> = InheritableElementProps<C, Props & AsProp<C>>;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* A wrapper of `PolymorphicComponentProps` that also includes the `ref`
|
|
45
|
-
* prop for the polymorphic component
|
|
46
|
-
*/
|
|
47
|
-
export declare type PolymorphicComponentPropsWithRef<C extends default_2.ElementType, Props = Record<string, unknown>> = PolymorphicComponentProps<C, Props> & {
|
|
48
|
-
ref?: PolymorphicRef<C>;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Utility type to extract the `ref` prop from a polymorphic component
|
|
53
|
-
*/
|
|
54
|
-
export declare type PolymorphicRef<C extends default_2.ElementType> = default_2.ComponentPropsWithRef<C>['ref'];
|
|
55
|
-
|
|
56
|
-
export declare type PropsOf<C extends keyof JSX.IntrinsicElements | default_2.JSXElementConstructor<any>> = JSX.LibraryManagedAttributes<C, default_2.ComponentPropsWithoutRef<C>>;
|
|
57
|
-
|
|
58
|
-
export declare function useDebounce<T extends (...args: any[]) => any>(callBack: T, debounceTime: number): T;
|
|
59
|
-
|
|
60
|
-
export declare const useForceUpdate: () => () => void;
|
|
61
|
-
|
|
62
|
-
export declare const useOnClickOutside: (refs: (default_2.RefObject<HTMLElement> | default_2.MutableRefObject<any>)[], handler: () => void) => void;
|
|
63
|
-
|
|
64
|
-
export declare const useOnEscape: (ref: default_2.RefObject<any> | default_2.MutableRefObject<any>, handler: () => void) => void;
|
|
65
|
-
|
|
66
|
-
export declare function useOnMount(callback: () => void): void;
|
|
67
|
-
|
|
68
|
-
export declare const useRandomId: (prefix?: string) => string;
|
|
69
|
-
|
|
70
|
-
export declare const useWindowDimensions: () => WindowDimensions;
|
|
71
|
-
|
|
72
|
-
export declare type VariantType = 'success' | 'negative' | 'warning' | 'information';
|
|
73
|
-
|
|
74
|
-
/** Warns the developer if they have forgotten to include styles */
|
|
75
|
-
export declare function warnAboutMissingStyles(...namespaces: string[]): void;
|
|
76
|
-
|
|
77
|
-
declare type WindowDimensions = {
|
|
78
|
-
width: number | undefined;
|
|
79
|
-
height: number | undefined;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export { }
|
|
1
|
+
export * from './PolymorphicComponent';
|
|
2
|
+
export * from './useDebounce';
|
|
3
|
+
export * from './useRandomId';
|
|
4
|
+
export * from './useOnMount';
|
|
5
|
+
export * from './mergeRefs';
|
|
6
|
+
export * from './useForceUpdate';
|
|
7
|
+
export * from './useOnClickOutside';
|
|
8
|
+
export * from './useOnEscape';
|
|
9
|
+
export * from './useWindowDimensions';
|
|
10
|
+
export * from './ConditionalWrapper';
|
|
11
|
+
export * from './warnAboutMissingStyles';
|
|
12
|
+
export * from './types/variants';
|
|
13
|
+
export * from './getNodeText';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mergeRefs: <T extends HTMLElement>(...refs: (React.MutableRefObject<T> | React.ForwardedRef<T> | ((node: T | null) => void) | undefined)[]) => (node: T) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type VariantType = 'success' | 'negative' | 'warning' | 'information';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useDebounce<T extends (...args: any[]) => any>(callBack: T, debounceTime: number): T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useForceUpdate: () => () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useOnMount(callback: () => void): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useRandomId: (prefix?: string) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entur/utils",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.5",
|
|
4
4
|
"license": "EUPL-1.2",
|
|
5
5
|
"main": "dist/utils.cjs.js",
|
|
6
6
|
"module": "dist/utils.esm.js",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"vite": "^7.1.3",
|
|
42
42
|
"vite-plugin-dts": "^4.5.4"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "5dd9d318f1d79f6f522f978de27b551fda1e91cc"
|
|
45
45
|
}
|