@pepperi-addons/ngx-composite-lib-react 0.0.2 → 0.0.4
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
export interface PepGroupButtonsSettingsReactProps {
|
|
3
3
|
pepResetConfigurationField?: string;
|
|
4
4
|
hideReset?: boolean;
|
|
@@ -11,4 +11,4 @@ export interface PepGroupButtonsSettingsReactProps {
|
|
|
11
11
|
btnsArray?: any[];
|
|
12
12
|
onBtnKeyChange?: (e: any) => void;
|
|
13
13
|
}
|
|
14
|
-
export declare function PepGroupButtonsSettingsReact(props: PepGroupButtonsSettingsReactProps):
|
|
14
|
+
export declare function PepGroupButtonsSettingsReact(props: PepGroupButtonsSettingsReactProps): React.DetailedReactHTMLElement<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import React from 'react';
|
|
3
|
-
import { PepGroupButtons } from '@pepperi-addons/ngx-lib-react';
|
|
4
2
|
export function PepGroupButtonsSettingsReact(props) {
|
|
5
3
|
const { pepResetConfigurationField, hideReset, resetHostEvents, groupType, subHeader, btnKey, useNone, excludeKeys, btnsArray, onBtnKeyChange, } = props;
|
|
6
4
|
const onReset = React.useCallback(() => {
|
|
@@ -12,7 +10,7 @@ export function PepGroupButtonsSettingsReact(props) {
|
|
|
12
10
|
});
|
|
13
11
|
}
|
|
14
12
|
}, [pepResetConfigurationField, resetHostEvents]);
|
|
15
|
-
// Build items for the
|
|
13
|
+
// Build items for the settings element (we will pass as custom group)
|
|
16
14
|
const computedItems = React.useMemo(() => {
|
|
17
15
|
const arr = [];
|
|
18
16
|
switch (groupType) {
|
|
@@ -58,6 +56,49 @@ export function PepGroupButtonsSettingsReact(props) {
|
|
|
58
56
|
}
|
|
59
57
|
return filtered;
|
|
60
58
|
}, [groupType, btnsArray, excludeKeys, useNone]);
|
|
61
|
-
|
|
59
|
+
const hostRef = React.useRef(null);
|
|
60
|
+
const elRef = React.useRef(null);
|
|
61
|
+
React.useLayoutEffect(() => {
|
|
62
|
+
const host = hostRef.current;
|
|
63
|
+
if (!host)
|
|
64
|
+
return () => { };
|
|
65
|
+
let el = elRef.current;
|
|
66
|
+
if (!el) {
|
|
67
|
+
el = document.createElement('pep-group-buttons-settings');
|
|
68
|
+
elRef.current = el;
|
|
69
|
+
}
|
|
70
|
+
const listeners = [];
|
|
71
|
+
// Set properties BEFORE connecting to the DOM
|
|
72
|
+
const propsToSet = {
|
|
73
|
+
pepResetConfigurationField,
|
|
74
|
+
hideReset,
|
|
75
|
+
resetHostEvents,
|
|
76
|
+
groupType: 'custom',
|
|
77
|
+
subHeader,
|
|
78
|
+
btnKey,
|
|
79
|
+
useNone,
|
|
80
|
+
excludeKeys,
|
|
81
|
+
btnsArray: computedItems,
|
|
82
|
+
};
|
|
83
|
+
Object.entries(propsToSet).forEach(([k, v]) => {
|
|
84
|
+
if (typeof v === 'undefined')
|
|
85
|
+
return;
|
|
86
|
+
try {
|
|
87
|
+
el[k] = v;
|
|
88
|
+
}
|
|
89
|
+
catch { }
|
|
90
|
+
});
|
|
91
|
+
if (typeof onBtnKeyChange === 'function') {
|
|
92
|
+
const handler = (e) => onBtnKeyChange(e);
|
|
93
|
+
el.addEventListener('btnkeyChange', handler);
|
|
94
|
+
listeners.push(['btnkeyChange', handler]);
|
|
95
|
+
}
|
|
96
|
+
if (!el.isConnected)
|
|
97
|
+
host.appendChild(el);
|
|
98
|
+
return () => {
|
|
99
|
+
listeners.forEach(([n, h]) => el.removeEventListener(n, h));
|
|
100
|
+
};
|
|
101
|
+
}, [pepResetConfigurationField, hideReset, resetHostEvents, subHeader, btnKey, useNone, excludeKeys, computedItems, onBtnKeyChange]);
|
|
102
|
+
return React.createElement('div', { ref: hostRef });
|
|
62
103
|
}
|
|
63
104
|
//# sourceMappingURL=PepGroupButtonsSettingsReact.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pepperi-addons/ngx-composite-lib-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "React wrappers for @pepperi-addons/ngx-composite-lib web components, plus registration bundles.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
"*.d.ts",
|
|
12
12
|
"components/*.js",
|
|
13
13
|
"components/*.d.ts",
|
|
14
|
+
"utils/*.js",
|
|
15
|
+
"utils/*.d.ts",
|
|
14
16
|
"elements/*",
|
|
15
17
|
"README.md"
|
|
16
18
|
],
|
|
@@ -19,6 +21,7 @@
|
|
|
19
21
|
"types": "./index.d.ts",
|
|
20
22
|
"default": "./index.js"
|
|
21
23
|
},
|
|
24
|
+
"./components/PepGroupButtonsSettingsReact.js": "./components/PepGroupButtonsSettingsReact.js",
|
|
22
25
|
"./elements/register.js": "./elements/register.js",
|
|
23
26
|
"./elements/register.auto.js": "./elements/register.auto.js",
|
|
24
27
|
"./elements/styles.css": "./elements/styles.css",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare type AnyProps = Record<string, any> & {
|
|
3
|
+
children?: React.ReactNode;
|
|
4
|
+
};
|
|
5
|
+
declare type WebComponent = HTMLElement & Record<string, any>;
|
|
6
|
+
export declare function createPepWrapper<T extends WebComponent = WebComponent>(tagName: string, displayName: string): React.ForwardRefExoticComponent<Pick<AnyProps, string> & React.RefAttributes<T>>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React, { useEffect, useRef, forwardRef } from 'react';
|
|
2
|
+
export function createPepWrapper(tagName, displayName) {
|
|
3
|
+
const Cmp = forwardRef((props, ref) => {
|
|
4
|
+
const localRef = useRef(null);
|
|
5
|
+
const setRef = (el) => {
|
|
6
|
+
localRef.current = el;
|
|
7
|
+
if (typeof ref === 'function')
|
|
8
|
+
ref(el);
|
|
9
|
+
else if (ref && 'current' in ref)
|
|
10
|
+
ref.current = el;
|
|
11
|
+
};
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const el = localRef.current;
|
|
14
|
+
const listeners = [];
|
|
15
|
+
if (el) {
|
|
16
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
17
|
+
if (key === 'children' || key === 'style' || key === 'className')
|
|
18
|
+
return;
|
|
19
|
+
if (key.startsWith('on') && typeof value === 'function') {
|
|
20
|
+
const eventName = key.slice(2, 3).toLowerCase() + key.slice(3);
|
|
21
|
+
const handler = (e) => value(e);
|
|
22
|
+
el.addEventListener(eventName, handler);
|
|
23
|
+
listeners.push([eventName, handler]);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
try {
|
|
27
|
+
el[key] = value;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// ignore set errors
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return () => {
|
|
36
|
+
const current = localRef.current;
|
|
37
|
+
listeners.forEach(([n, h]) => current?.removeEventListener(n, h));
|
|
38
|
+
};
|
|
39
|
+
}, [props]);
|
|
40
|
+
const { children, className, style } = props;
|
|
41
|
+
return React.createElement(tagName, { ref: setRef, className, style }, children);
|
|
42
|
+
});
|
|
43
|
+
Cmp.displayName = displayName;
|
|
44
|
+
return Cmp;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=create-wrapper.js.map
|