@pepperi-addons/ngx-lib-react 0.0.1

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/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './pep-select.js';
2
+ export * from './pep-button.js';
3
+ export * from './pep-textbox.js';
package/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './pep-select.js';
2
+ export * from './pep-button.js';
3
+ export * from './pep-textbox.js';
4
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@pepperi-addons/ngx-lib-react",
3
+ "version": "0.0.1",
4
+ "description": "Thin React wrappers for Pepperi Angular Elements (Web Components) to improve DX in React.",
5
+ "license": "MIT",
6
+ "author": "Pepperi",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://example.com/repo.git"
10
+ },
11
+ "keywords": [
12
+ "pepperi",
13
+ "react",
14
+ "web-components",
15
+ "angular-elements"
16
+ ],
17
+ "main": "index.js",
18
+ "module": "index.js",
19
+ "types": "index.d.ts",
20
+ "peerDependencies": {
21
+ "react": ">=17",
22
+ "react-dom": ">=17"
23
+ },
24
+ "dependencies": {},
25
+ "files": [
26
+ "*.js",
27
+ "*.d.ts",
28
+ "README.md",
29
+ "elements/*"
30
+ ]
31
+ }
@@ -0,0 +1,21 @@
1
+ /// <reference types="react" />
2
+ export declare type PepStyleType = 'weak' | 'regular' | 'strong';
3
+ export declare type PepStyleStateType = 'system' | 'success' | 'caution';
4
+ export declare type PepSizeType = '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
5
+ export declare type PepIconPosition = 'start' | 'end';
6
+ export interface PepButtonClickEvent {
7
+ source?: any;
8
+ event?: Event;
9
+ }
10
+ export interface PepButtonProps extends React.HTMLAttributes<HTMLElement> {
11
+ value?: string;
12
+ styleType?: PepStyleType;
13
+ styleStateType?: PepStyleStateType;
14
+ sizeType?: PepSizeType;
15
+ disabled?: boolean;
16
+ iconName?: string;
17
+ iconPosition?: PepIconPosition;
18
+ className?: string;
19
+ onButtonClick?: (e: PepButtonClickEvent) => void;
20
+ }
21
+ export declare const PepButton: React.FC<PepButtonProps>;
package/pep-button.js ADDED
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from 'react';
3
+ export const PepButton = ({ value, styleType, styleStateType, sizeType, disabled, iconName, iconPosition, className, onButtonClick, ...rest }) => {
4
+ const ref = useRef(null);
5
+ // Sync non-string/boolean props as properties
6
+ useEffect(() => {
7
+ const el = ref.current;
8
+ if (!el)
9
+ return;
10
+ if (typeof disabled !== 'undefined')
11
+ el.disabled = !!disabled;
12
+ if (typeof iconName !== 'undefined')
13
+ el.iconName = iconName;
14
+ if (typeof iconPosition !== 'undefined')
15
+ el.iconPosition = iconPosition;
16
+ }, [disabled, iconName, iconPosition]);
17
+ // Attach events
18
+ useEffect(() => {
19
+ const el = ref.current;
20
+ if (!el || !onButtonClick)
21
+ return;
22
+ const handler = (e) => { var _a; return onButtonClick((_a = e.detail) !== null && _a !== void 0 ? _a : e); };
23
+ el.addEventListener('buttonClick', handler);
24
+ return () => el.removeEventListener('buttonClick', handler);
25
+ }, [onButtonClick]);
26
+ return (_jsx("pep-button", { ref: ref, value: value, "style-type": styleType, "style-state-type": styleStateType, "size-type": sizeType, class: className, ...rest }));
27
+ };
28
+ //# sourceMappingURL=pep-button.js.map
@@ -0,0 +1,19 @@
1
+ /// <reference types="react" />
2
+ export interface PepOption {
3
+ key: string;
4
+ value: string;
5
+ }
6
+ export interface PepSelectProps extends React.HTMLAttributes<HTMLElement> {
7
+ keyProp?: string;
8
+ value?: string;
9
+ label?: string;
10
+ placeholder?: string;
11
+ type?: 'select' | 'multi';
12
+ disabled?: boolean;
13
+ readonly?: boolean;
14
+ mandatory?: boolean;
15
+ options?: PepOption[];
16
+ addValueToOptionsIfNotExist?: boolean;
17
+ onValueChange?: (value: string) => void;
18
+ }
19
+ export declare const PepSelect: React.FC<PepSelectProps>;
package/pep-select.js ADDED
@@ -0,0 +1,40 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from 'react';
3
+ export const PepSelect = ({ keyProp, value, label, placeholder, type, disabled, readonly, mandatory, options, addValueToOptionsIfNotExist, onValueChange, ...rest }) => {
4
+ const ref = useRef(null);
5
+ // Sync complex props via properties
6
+ useEffect(() => {
7
+ const el = ref.current;
8
+ if (!el)
9
+ return;
10
+ if (options)
11
+ el.options = options;
12
+ if (typeof addValueToOptionsIfNotExist !== 'undefined')
13
+ el.addValueToOptionsIfNotExist = !!addValueToOptionsIfNotExist;
14
+ }, [options, addValueToOptionsIfNotExist]);
15
+ // Sync booleans via properties to be safe
16
+ useEffect(() => {
17
+ const el = ref.current;
18
+ if (!el)
19
+ return;
20
+ if (typeof disabled !== 'undefined')
21
+ el.disabled = !!disabled;
22
+ if (typeof readonly !== 'undefined')
23
+ el.readonly = !!readonly;
24
+ if (typeof mandatory !== 'undefined')
25
+ el.mandatory = !!mandatory;
26
+ }, [disabled, readonly, mandatory]);
27
+ // Events
28
+ useEffect(() => {
29
+ const el = ref.current;
30
+ if (!el || !onValueChange)
31
+ return;
32
+ const handler = (e) => { var _a, _b; return onValueChange((_a = e.detail) !== null && _a !== void 0 ? _a : (_b = e.target) === null || _b === void 0 ? void 0 : _b.value); };
33
+ el.addEventListener('valueChange', handler);
34
+ return () => el.removeEventListener('valueChange', handler);
35
+ }, [onValueChange]);
36
+ return (_jsx("pep-select", { ref: ref,
37
+ // attributes (strings)
38
+ value: value, label: label, placeholder: placeholder, type: type, ...rest }, keyProp));
39
+ };
40
+ //# sourceMappingURL=pep-select.js.map
@@ -0,0 +1,23 @@
1
+ /// <reference types="react" />
2
+ export declare type PepTextboxFieldType = 'text' | 'int' | 'real' | 'currency' | 'percentage' | 'email' | 'phone' | 'link' | 'duration';
3
+ export interface PepTextboxProps extends React.HTMLAttributes<HTMLElement> {
4
+ keyProp?: string;
5
+ value?: string;
6
+ label?: string;
7
+ placeholder?: string;
8
+ type?: PepTextboxFieldType;
9
+ accessory?: string;
10
+ minFractionDigits?: number;
11
+ maxFractionDigits?: number;
12
+ mandatory?: boolean;
13
+ readonly?: boolean;
14
+ disabled?: boolean;
15
+ minValue?: number;
16
+ maxValue?: number;
17
+ regex?: string | RegExp;
18
+ regexError?: string;
19
+ onValueChange?: (value: string) => void;
20
+ onKeyup?: (e: any) => void;
21
+ onValidationChange?: (isValid: boolean) => void;
22
+ }
23
+ export declare const PepTextbox: React.FC<PepTextboxProps>;
package/pep-textbox.js ADDED
@@ -0,0 +1,65 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from 'react';
3
+ export const PepTextbox = ({ keyProp, value, label, placeholder, type, accessory, minFractionDigits, maxFractionDigits, mandatory, readonly, disabled, minValue, maxValue, regex, regexError, onValueChange, onKeyup, onValidationChange, ...rest }) => {
4
+ const ref = useRef(null);
5
+ // Sync complex/boolean props as properties on the element
6
+ useEffect(() => {
7
+ const el = ref.current;
8
+ if (!el)
9
+ return;
10
+ if (typeof accessory !== 'undefined')
11
+ el.accessory = accessory;
12
+ if (typeof minFractionDigits !== 'undefined')
13
+ el.minFractionDigits = minFractionDigits;
14
+ if (typeof maxFractionDigits !== 'undefined')
15
+ el.maxFractionDigits = maxFractionDigits;
16
+ if (typeof mandatory !== 'undefined')
17
+ el.mandatory = !!mandatory;
18
+ if (typeof readonly !== 'undefined')
19
+ el.readonly = !!readonly;
20
+ if (typeof disabled !== 'undefined')
21
+ el.disabled = !!disabled;
22
+ if (typeof minValue !== 'undefined')
23
+ el.minValue = minValue;
24
+ if (typeof maxValue !== 'undefined')
25
+ el.maxValue = maxValue;
26
+ if (typeof regex !== 'undefined')
27
+ el.regex = regex;
28
+ if (typeof regexError !== 'undefined')
29
+ el.regexError = regexError;
30
+ }, [
31
+ accessory,
32
+ minFractionDigits,
33
+ maxFractionDigits,
34
+ mandatory,
35
+ readonly,
36
+ disabled,
37
+ minValue,
38
+ maxValue,
39
+ regex,
40
+ regexError,
41
+ ]);
42
+ // Attach events
43
+ useEffect(() => {
44
+ const el = ref.current;
45
+ if (!el)
46
+ return;
47
+ const handlers = [];
48
+ if (onValueChange) {
49
+ const h = (e) => { var _a, _b; return onValueChange((_a = e.detail) !== null && _a !== void 0 ? _a : (_b = e.target) === null || _b === void 0 ? void 0 : _b.value); };
50
+ handlers.push(['valueChange', h]);
51
+ }
52
+ if (onKeyup) {
53
+ const h = (e) => onKeyup(e);
54
+ handlers.push(['keyup', h]);
55
+ }
56
+ if (onValidationChange) {
57
+ const h = (e) => { var _a, _b; return onValidationChange(!!((_a = e.detail) !== null && _a !== void 0 ? _a : (_b = e.target) === null || _b === void 0 ? void 0 : _b.value)); };
58
+ handlers.push(['validationChange', h]);
59
+ }
60
+ handlers.forEach(([name, h]) => el.addEventListener(name, h));
61
+ return () => handlers.forEach(([name, h]) => el.removeEventListener(name, h));
62
+ }, [onValueChange, onKeyup, onValidationChange]);
63
+ return (_jsx("pep-textbox", { ref: ref, value: value, label: label, placeholder: placeholder, type: type, ...rest }, keyProp));
64
+ };
65
+ //# sourceMappingURL=pep-textbox.js.map