@pagamio/frontend-commons-lib 0.8.260 → 0.8.262

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.
@@ -3,7 +3,6 @@ import 'react-phone-number-input/style.css';
3
3
  import React from 'react';
4
4
  import type { InputProps } from '../../form-engine';
5
5
  interface PhoneInputSpecificProps {
6
- onCountryChange?: (country: Country) => void;
7
6
  defaultCountry?: Country;
8
7
  }
9
8
  type PhoneInputProps = InputProps & PhoneInputSpecificProps;
@@ -1,26 +1,23 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { ParseError, isPossiblePhoneNumber, parsePhoneNumberWithError } from 'libphonenumber-js';
3
- import ReachPhoneNumberInput from 'react-phone-number-input';
3
+ import PhoneNumberInput from 'react-phone-number-input';
4
4
  import 'react-phone-number-input/style.css';
5
- import React, { useState } from 'react';
6
- const PhoneInput = React.forwardRef(({ field, error, onChange, onBlur, value, onCountryChange, ...props }, ref) => {
5
+ import React, { useCallback, useState } from 'react';
6
+ const PhoneInput = React.forwardRef(({ field, error, onChange, onBlur, value }, _ref) => {
7
+ const defaultCountry = field.defaultCountry ?? 'ZA';
7
8
  const [isTouched, setIsTouched] = useState(false);
8
9
  const [localError, setLocalError] = useState(null);
9
- const defaultCountry = field.defaultCountry ?? 'ZA';
10
10
  const isValid = !value || isPossiblePhoneNumber(value);
11
- const handleChange = (newValue) => {
11
+ const handleChange = useCallback((newValue) => {
12
12
  onChange?.(newValue);
13
13
  setLocalError(null);
14
14
  if (newValue) {
15
15
  try {
16
- const phoneNumber = parsePhoneNumberWithError(newValue, { defaultCountry });
17
- if (phoneNumber && onCountryChange) {
18
- onCountryChange(phoneNumber.country);
19
- }
16
+ parsePhoneNumberWithError(newValue, { defaultCountry });
20
17
  }
21
- catch (error) {
22
- if (error instanceof ParseError) {
23
- switch (error.message) {
18
+ catch (parseError) {
19
+ if (parseError instanceof ParseError) {
20
+ switch (parseError.message) {
24
21
  case 'NOT_A_NUMBER':
25
22
  setLocalError('Please enter a valid phone number.');
26
23
  break;
@@ -37,22 +34,18 @@ const PhoneInput = React.forwardRef(({ field, error, onChange, onBlur, value, on
37
34
  setLocalError('Invalid phone number.');
38
35
  }
39
36
  }
40
- else {
41
- console.error('Unexpected error:', error);
42
- }
43
37
  }
44
38
  }
45
- };
46
- const handleBlur = () => {
39
+ }, [onChange, defaultCountry]);
40
+ const handleBlur = useCallback(() => {
47
41
  setIsTouched(true);
48
42
  onBlur?.();
49
- };
50
- return (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: field.name, className: "block text-sm font-medium text-foreground", children: field.label }), _jsx(ReachPhoneNumberInput, { international: true, defaultCountry: defaultCountry, value: value || '', onChange: handleChange, id: field.name, onBlur: handleBlur, placeholder: field.placeholder, numberInputProps: {
51
- className: `mt-1 block w-full p-2 border rounded-md shadow-sm
43
+ }, [onBlur]);
44
+ return (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: field.name, className: "block text-sm font-medium text-foreground", children: field.label }), _jsx(PhoneNumberInput, { international: true, defaultCountry: defaultCountry, value: value || undefined, onChange: handleChange, id: field.name, onBlur: handleBlur, placeholder: field.placeholder, numberInputProps: {
45
+ className: `mt-1 block w-full p-2 border rounded-md shadow-sm
52
46
  ${error || localError ? 'border-red-500' : 'border-input'}
53
47
  ${field.disabled ? 'text-muted-foreground bg-muted' : ''}`,
54
48
  disabled: field.disabled,
55
- ref: ref,
56
- }, ...props }), (error || localError || (!isValid && isTouched)) && (_jsx("p", { className: "mt-2 text-sm text-red-500", children: error?.message ?? localError ?? 'Please enter a valid phone number' }))] }));
49
+ } }), (error || localError || (!isValid && isTouched)) && (_jsx("p", { className: "mt-2 text-sm text-red-500", children: error?.message ?? localError ?? 'Please enter a valid phone number' }))] }));
57
50
  });
58
51
  export default PhoneInput;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { InputProps } from '../../../types';
3
+ declare const ColorInput: React.ForwardRefExoticComponent<Omit<InputProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
4
+ export default ColorInput;
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ColorInput as MantineColorInput } from '@mantine/core';
3
+ import React from 'react';
4
+ const ColorInput = React.forwardRef(({ field, error, value, onChange, ...props }, ref) => {
5
+ return (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: field.name, className: "block text-sm font-medium text-foreground", children: field.label }), _jsx(MantineColorInput, { ref: ref, id: field.name, value: value || '', onChange: (color) => onChange(color), disabled: field.disabled, placeholder: field.placeholder || 'Pick a color', format: "hex", swatches: [
6
+ '#25262b',
7
+ '#868e96',
8
+ '#fa5252',
9
+ '#e64980',
10
+ '#be4bdb',
11
+ '#7950f2',
12
+ '#4c6ef5',
13
+ '#228be6',
14
+ '#15aabf',
15
+ '#12b886',
16
+ '#40c057',
17
+ '#82c91e',
18
+ '#fab005',
19
+ '#fd7e14',
20
+ ], error: error?.message, className: "mt-1" })] }));
21
+ });
22
+ export default ColorInput;
@@ -0,0 +1 @@
1
+ export { default as ColorInput } from './ColorInput';
@@ -0,0 +1 @@
1
+ export { default as ColorInput } from './ColorInput';
@@ -31,9 +31,10 @@ export const setupInputRegistry = async () => {
31
31
  return getRegistryPromise();
32
32
  };
33
33
  const doSetup = async () => {
34
- const [{ default: CardExpiryInput }, { default: CheckboxInput }, { default: CreditCardInput }, { default: DateInput }, { default: EmailInput }, { default: LabelInput }, { default: MultiSelectInputComponent }, { default: NumberInput }, { default: PasswordInput }, { default: RadioInput }, { default: SelectInput }, { default: TextareaInputFW }, { default: TimeInput }, { default: ToggleSwitchInput }, { default: UploadFieldForm }, { default: PhoneInput },] = await Promise.all([
34
+ const [{ default: CardExpiryInput }, { default: CheckboxInput }, { default: ColorInput }, { default: CreditCardInput }, { default: DateInput }, { default: EmailInput }, { default: LabelInput }, { default: MultiSelectInputComponent }, { default: NumberInput }, { default: PasswordInput }, { default: RadioInput }, { default: SelectInput }, { default: TextareaInputFW }, { default: TimeInput }, { default: ToggleSwitchInput }, { default: UploadFieldForm }, { default: PhoneInput },] = await Promise.all([
35
35
  import('../components/inputs/card-expiry-input/CardExpiryInput'),
36
36
  import('../components/inputs/checkbox-input/CheckboxInput'),
37
+ import('../components/inputs/color-input/ColorInput'),
37
38
  import('../components/inputs/credit-card-input/CreditCardInput'),
38
39
  import('../components/inputs/date-input/DateInput'),
39
40
  import('../components/inputs/email-input/EmailInput'),
@@ -51,6 +52,7 @@ const doSetup = async () => {
51
52
  ]);
52
53
  registerInput('card-expiry-input', CardExpiryInput);
53
54
  registerInput('checkbox', CheckboxInput);
55
+ registerInput('color', ColorInput);
54
56
  registerInput('credit-card', CreditCardInput);
55
57
  registerInput('date', DateInput);
56
58
  registerInput('email', EmailInput);
@@ -130,7 +130,7 @@ export interface DependencyValidation {
130
130
  /**
131
131
  * Available field types supported by the form engine
132
132
  */
133
- export type FieldType = 'card-expiry-input' | 'checkbox' | 'credit-card' | 'date' | 'email' | 'file' | 'multi-select' | 'number' | 'password' | 'radio' | 'searchable-multi-select' | 'select' | 'switch' | 'tel' | 'text' | 'textarea' | 'time';
133
+ export type FieldType = 'card-expiry-input' | 'checkbox' | 'color' | 'credit-card' | 'date' | 'email' | 'file' | 'multi-select' | 'number' | 'password' | 'radio' | 'searchable-multi-select' | 'select' | 'switch' | 'tel' | 'text' | 'textarea' | 'time';
134
134
  /**
135
135
  * Defines the structure of a form field
136
136
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pagamio/frontend-commons-lib",
3
3
  "description": "Pagamio library for Frontend reusable components like the form engine and table container",
4
- "version": "0.8.260",
4
+ "version": "0.8.262",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": false