tp-react-elements-dev 1.12.25 → 1.12.26

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.
@@ -9,6 +9,7 @@ import FormTextAreaField from '../FormComponents/FormTextAreaField/FormTextAreaF
9
9
  import FormTextField from '../FormComponents/FormTextField/FormTextField.esm.js';
10
10
  import PasswordField from '../FormComponents/PasswordField/PasswordField.esm.js';
11
11
  import SingleSelect from '../FormComponents/Select/SingleSelect.esm.js';
12
+ import MultiSelectAutocomplete from '../FormComponents/Select/MultiSelectAutocomplete.esm.js';
12
13
  import SingleSelectNonAutoComplete from '../FormComponents/Select/SingleSelectNonAutoComplete.esm.js';
13
14
  import FormActiveSwitch from './FormActiveSwitch.esm.js';
14
15
 
@@ -48,7 +49,8 @@ const RenderForm = (props) => {
48
49
  * This is the core mapping logic that determines which component to render
49
50
  * based on the inputType property of the form item
50
51
  */
51
- switch (props.item?.inputType) {
52
+ const inputType = props.item?.inputType;
53
+ switch (inputType) {
52
54
  /**
53
55
  * Text input cases
54
56
  * These cases handle standard text input, email input, and multi-email input
@@ -68,6 +70,9 @@ const RenderForm = (props) => {
68
70
  case 'select':
69
71
  case 'autocomplete-select': // new alias
70
72
  return jsx(SingleSelect, { props: props, variant: variant });
73
+ // Autocomplete multi-select with checkboxes
74
+ case 'autocomplete-multi-select':
75
+ return jsx(MultiSelectAutocomplete, { props: props, variant: variant });
71
76
  // Dropdown select (non auto-complete)
72
77
  case 'select-v2':
73
78
  case 'basic-select': // new alias
@@ -0,0 +1,6 @@
1
+ import { FormRenderProps, VariantProps } from '../../../utils';
2
+ declare const MultiSelectAutocomplete: ({ props, variant, }: {
3
+ props: FormRenderProps;
4
+ variant: VariantProps;
5
+ }) => import("react/jsx-runtime").JSX.Element;
6
+ export default MultiSelectAutocomplete;
@@ -0,0 +1,66 @@
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { Autocomplete, TextField, Checkbox } from '@mui/material';
3
+ import { useMemo } from 'react';
4
+ import { useWatch, Controller } from 'react-hook-form';
5
+ import FormBottomField from '../FormBottomField/FormBottomField.esm.js';
6
+ import 'dayjs';
7
+ import { renderLabel } from '../../../utils/Constants/FormConstants.esm.js';
8
+
9
+ const MultiSelectAutocomplete = ({ props, variant, }) => {
10
+ const isError = !!props.errors?.[props.item.name];
11
+ const watchedValue = useWatch({ control: props.control, name: props.item.name });
12
+ const isShowBorderError = isError && (!watchedValue || watchedValue.length === 0);
13
+ const options = (props.item.options || []);
14
+ const selectedOptions = useMemo(() => {
15
+ if (!watchedValue)
16
+ return [];
17
+ const values = typeof watchedValue === 'string' ? watchedValue.split(',') : [];
18
+ const valueSet = new Set(values);
19
+ return options.filter((opt) => valueSet.has(String(opt.value)));
20
+ }, [watchedValue, options]);
21
+ return (jsx(Controller, { control: props.control, name: props.item.name, render: ({ field }) => (jsxs(Fragment, { children: [renderLabel(variant, props), jsx(Autocomplete, { ...field, multiple: true, disableCloseOnSelect: true, id: `${props.item.name}-autocomplete-multi`, options: options, value: selectedOptions, getOptionLabel: (option) => String(option.label), isOptionEqualToValue: (option, value) => option.value === value.value, onChange: (_, newValue) => {
22
+ const joined = (newValue || []).map((o) => o.value).join(',');
23
+ props.setValue(props.item.name, joined);
24
+ props?.item?.onChangeFn && props?.item?.onChangeFn(joined);
25
+ props?.clearErrors && props?.clearErrors(props?.item?.name);
26
+ }, onBlur: (e) => {
27
+ props?.item?.onBlurFn && props?.item?.onBlurFn(e);
28
+ }, size: "small", renderOption: (renderProps, option, { selected }) => (jsxs("li", { ...renderProps, style: { fontSize: '11px' }, children: [jsx(Checkbox, { checked: selected, size: "small", sx: { mr: 1, p: '2px' } }), option.label] })), renderTags: (tagValue) => (tagValue.length ? jsx("span", { children: tagValue.map((o) => String(o.label)).join(' , ') }) : null), sx: {
29
+ '& .MuiAutocomplete-input': {
30
+ padding: '0px 0px 0px 5px !important',
31
+ },
32
+ '& .css-erkti9-MuiFormLabel-root-MuiInputLabel-root,.css-8edmr2-MuiFormLabel-root-MuiInputLabel-root': {
33
+ top: '-3px',
34
+ },
35
+ '& .MuiAutocomplete-option': {
36
+ fontSize: '11px',
37
+ zIndex: 2000,
38
+ },
39
+ ...props.item.sx,
40
+ }, ListboxProps: {
41
+ onScroll: (event) => {
42
+ const listboxNode = event.currentTarget;
43
+ if (listboxNode.scrollTop + listboxNode.clientHeight === listboxNode.scrollHeight) ;
44
+ },
45
+ }, disabled: props.item.disable, slotProps: {
46
+ popper: {
47
+ sx: {
48
+ zIndex: 1401,
49
+ },
50
+ },
51
+ listbox: {
52
+ sx: {
53
+ fontSize: '11px',
54
+ },
55
+ },
56
+ }, renderInput: (params) => (jsx(TextField, { ...params, placeholder: props.item.placeholder, error: isShowBorderError, label: variant !== 'standard'
57
+ ? `${props.item.label}${props.item.required ? ' *' : ''}`
58
+ : '', inputProps: {
59
+ ...params.inputProps,
60
+ 'aria-labelledby': `${props.item.name}-label`,
61
+ 'aria-describedby': `${props.item.name}-helper ${props.item.name}-error`,
62
+ 'aria-required': props.item.required ? true : undefined,
63
+ } })) }), jsx(FormBottomField, { ...props })] })) }, props.item.name));
64
+ };
65
+
66
+ export { MultiSelectAutocomplete as default };
@@ -10,7 +10,7 @@ export interface TextFieldInputProps {
10
10
  export interface FormSectionPropsItem {
11
11
  name: string;
12
12
  label: string;
13
- inputType: 'text' | 'password' | 'number' | 'select' | 'autocomplete-select' | 'datepicker' | 'multiselect' | 'select-v2' | 'basic-select' | 'decimal' | 'alpha-numerical' | 'yearpicker' | 'dateRangePicker' | 'monthpicker' | 'multiselect' | 'file' | 'multifile' | 'textarea' | 'phoneNumber' | 'pincode' | 'email' | 'toggleSwitch' | 'rich-text-editor' | 'multiEmail' | 'timepicker' | 'checkbox-group' | 'radio-group' | 'checkbox' | 'custom' | '';
13
+ inputType: 'text' | 'password' | 'number' | 'select' | 'autocomplete-select' | 'autocomplete-multi-select' | 'datepicker' | 'multiselect' | 'select-v2' | 'basic-select' | 'decimal' | 'alpha-numerical' | 'yearpicker' | 'dateRangePicker' | 'monthpicker' | 'multiselect' | 'file' | 'multifile' | 'textarea' | 'phoneNumber' | 'pincode' | 'email' | 'toggleSwitch' | 'rich-text-editor' | 'multiEmail' | 'timepicker' | 'checkbox-group' | 'radio-group' | 'checkbox' | 'custom' | '';
14
14
  options?: OptionsProps[];
15
15
  required?: boolean;
16
16
  errorMessage?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tp-react-elements-dev",
3
- "version": "1.12.25",
3
+ "version": "1.12.26",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "React form components library built with React Hook Form and Yup",