tp-react-elements 1.1.2 → 1.1.3

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,3 +1,3 @@
1
- var Month = {};
1
+ var InputRangeField = {};
2
2
 
3
- export { Month as __exports };
3
+ export { InputRangeField as __exports };
@@ -1,3 +1,3 @@
1
- var InputRangeField = {};
1
+ var Month = {};
2
2
 
3
- export { InputRangeField as __exports };
3
+ export { Month as __exports };
@@ -1,3 +1,3 @@
1
- var DateRange = {};
1
+ var DateRangePicker = {};
2
2
 
3
- export { DateRange as __exports };
3
+ export { DateRangePicker as __exports };
@@ -1,3 +1,3 @@
1
- var DateRangePicker = {};
1
+ var DateRange = {};
2
2
 
3
- export { DateRangePicker as __exports };
3
+ export { DateRange as __exports };
@@ -1,3 +1,3 @@
1
- var Calendar = {};
1
+ var DefinedRange = {};
2
2
 
3
- export { Calendar as __exports };
3
+ export { DefinedRange as __exports };
@@ -1,3 +1,3 @@
1
- var DefinedRange = {};
1
+ var Calendar = {};
2
2
 
3
- export { DefinedRange as __exports };
3
+ export { Calendar as __exports };
@@ -7,7 +7,7 @@ import ListItemText from '@mui/material/ListItemText';
7
7
  import MenuItem from '@mui/material/MenuItem';
8
8
  import OutlinedInput from '@mui/material/OutlinedInput';
9
9
  import Select from '@mui/material/Select';
10
- import require$$0__default, { useState, useMemo } from 'react';
10
+ import require$$0__default, { useState, useRef, useMemo } from 'react';
11
11
  import { useWatch } from 'react-hook-form';
12
12
  import FormBottomField from '../FormBottomField/FormBottomField.esm.js';
13
13
  import 'dayjs';
@@ -15,45 +15,25 @@ import { renderLabel } from '../../../utils/Constants/FormConstants.esm.js';
15
15
 
16
16
  const ITEM_HEIGHT = 48;
17
17
  const ITEM_PADDING_TOP = 3;
18
- const MenuProps = {
19
- PaperProps: {
20
- style: {
21
- maxHeight: ITEM_HEIGHT * 5.5 + ITEM_PADDING_TOP,
22
- // width: 250,
23
- },
24
- },
25
- autoFocus: false,
26
- disableAutoFocusItem: true,
27
- };
28
- // const useStyles = makeStyles(() => ({
29
- // option: {
30
- // fontSize: "10px", // Adjust the font size as needed
31
- // },
32
- // option2: {
33
- // fontSize: "11px",
34
- // },
35
- // }));
36
18
  const extractValuesToArray = (inputString) => {
37
19
  if (!inputString)
38
20
  return [];
39
21
  return inputString.split(',').map((value) => value.trim()).filter(Boolean);
40
22
  };
41
23
  function MultiSelectV1({ props, variant, }) {
42
- const [personName, setPersonName] = require$$0__default.useState(props.getValues(props.item.name) ? extractValuesToArray(props.getValues(props.item.name)) : []);
43
24
  const [searchText, setSearchText] = useState('');
44
25
  const options = props.item?.options || [];
45
26
  const [filterOptions, setFilterOptions] = useState(props.item.options || []);
46
- const textfieldRef = require$$0__default.useRef(null);
27
+ const textfieldRef = useRef(null);
28
+ // Ref to capture the width of the Select container
29
+ const containerRef = useRef(null);
47
30
  const fieldValue = useWatch({ control: props.control, name: props.item.name });
48
- // Calculate selectAll state based on actual selection
49
31
  const selectAll = useMemo(() => {
50
32
  if (!fieldValue || filterOptions.length === 0)
51
33
  return false;
52
34
  const selectedValues = fieldValue.split(',').filter(Boolean);
53
35
  return filterOptions.every((option) => selectedValues.includes(String(option.value)));
54
36
  }, [fieldValue, filterOptions]);
55
- useMemo(() => filterOptions.map((item) => item.value), [filterOptions]);
56
- useMemo(() => filterOptions.map((item) => item.value), [filterOptions]);
57
37
  require$$0__default.useEffect(() => {
58
38
  if (searchText !== '') {
59
39
  setFilterOptions(options.filter((item) => item.label.toLowerCase().includes(searchText.toLowerCase())));
@@ -63,90 +43,65 @@ function MultiSelectV1({ props, variant, }) {
63
43
  }
64
44
  }, [options, searchText]);
65
45
  const handleChange = (event) => {
66
- const { target: { value }, } = event;
67
- setPersonName(typeof value === 'string' ? value?.split(',') : value);
68
- props.setValue(props.item.name, (typeof value === 'string' ? value?.split(',') : value).join(','));
46
+ const { target: { value } } = event;
47
+ const finalValue = typeof value === 'string' ? value.split(',') : value;
48
+ props.setValue(props.item.name, finalValue.join(','));
69
49
  };
70
50
  const selectedOptions = useMemo(() => options.filter((item) => fieldValue?.split(',').some((value) => value === item.value)), [options, fieldValue]);
71
- const selectedValues = selectedOptions.map((item) => item.label).join(' , ');
72
- const isError = !!props.errors?.[props.item.name];
73
- const isShowBorderError = isError;
74
- return (jsx(Box, { children: jsxs(FormControl, { fullWidth: true, sx: {
75
- '& .css-kichxs-MuiFormLabel-root-MuiInputLabel-root,.css-1holvmy': {
76
- top: '-10px',
77
- },
78
- '& .MuiFormLabel-root': {
79
- top: -10,
80
- },
81
- '& .MuiInputLabel-shrink': {
82
- top: 0,
83
- },
84
- }, children: [renderLabel(variant, props), variant !== 'standard' ? (jsxs(InputLabel, { error: isShowBorderError, id: `${props.item.name}-ms-labelId`, children: [props.item.label, props.item.required ? ' *' : ''] })) : (''), jsxs(Select, { labelId: `${props.item.name}-ms-labelId`, id: `${props.item.name}-ms-select`, multiple: true, displayEmpty: true, sx: {
85
- '& .MuiTypography-root': {
86
- fontSize: '5px !important',
87
- },
88
- }, error: isShowBorderError, disabled: props.item.disable, value: fieldValue ? extractValuesToArray(fieldValue) : [], onChange: handleChange, inputProps: {
89
- 'aria-labelledby': `${props.item.name}-label`,
90
- 'aria-describedby': `${props.item.name}-helper ${props.item.name}-error`,
91
- 'aria-required': props.item.required ? true : undefined,
92
- }, onOpen: () => {
93
- setTimeout(() => {
94
- if (textfieldRef.current) {
95
- textfieldRef.current?.focus();
96
- }
97
- }, 0);
98
- }, onClose: () => {
51
+ const selectedValuesString = selectedOptions.map((item) => item.label).join(' , ');
52
+ const isShowBorderError = !!props.errors?.[props.item.name];
53
+ return (jsx(Box, { children: jsxs(FormControl, { fullWidth: true, ref: containerRef, sx: { '& .MuiFormLabel-root': { top: -10 }, '& .MuiInputLabel-shrink': { top: 0 } }, children: [renderLabel(variant, props), variant !== 'standard' && (jsxs(InputLabel, { error: isShowBorderError, id: `${props.item.name}-ms-labelId`, children: [props.item.label, props.item.required ? ' *' : ''] })), jsxs(Select, { labelId: `${props.item.name}-ms-labelId`, id: `${props.item.name}-ms-select`, multiple: true, displayEmpty: true, error: isShowBorderError, disabled: props.item.disable, value: fieldValue ? extractValuesToArray(fieldValue) : [], onChange: handleChange, onOpen: () => setTimeout(() => textfieldRef.current?.focus(), 0), onClose: () => {
99
54
  setSearchText('');
100
55
  props?.item?.onCloseMenu && props?.item?.onCloseMenu();
101
- }, input: jsx(OutlinedInput, { label: variant !== 'standard' ? props.item.label : '' }), renderValue: (_selected) => (jsx(Tooltip, { title: selectedValues, children: (props.item.placeholder && selectedOptions.length === 0) ? jsx("span", { style: { color: '#0009' }, children: props.item.placeholder }) : jsx("span", { children: selectedOptions.length > (props.item.multiSelectLabelLength || 3)
56
+ }, input: jsx(OutlinedInput, { label: variant !== 'standard' ? props.item.label : '' }), renderValue: () => (jsx(Tooltip, { title: selectedValuesString, children: jsx("span", { style: { display: 'block', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, children: props.item.placeholder && selectedOptions.length === 0 ? (jsx("span", { style: { color: '#0009' }, children: props.item.placeholder })) : (selectedOptions.length > (props.item.multiSelectLabelLength || 3)
102
57
  ? `${selectedOptions.length} Selected`
103
- : selectedValues }) })), MenuProps: MenuProps, autoFocus: false, children: [jsx(Box, { sx: {
104
- width: '100%',
105
- position: 'sticky',
106
- top: '0px',
107
- padding: '7px',
108
- zIndex: 2,
109
- height: '33px',
110
- background: '#fff',
111
- display: options.length === 0 ? 'none' : undefined,
112
- }, children: jsx(TextField, { inputRef: textfieldRef, autoFocus: true, value: searchText, sx: {
113
- width: '100%',
114
- }, placeholder: "Search...", onChange: (e) => {
115
- setSearchText(e.target.value);
116
- }, onKeyDown: (e) => {
117
- if (e.key !== 'Escape') {
118
- e.stopPropagation();
119
- }
120
- } }) }), jsxs(MenuItem, { disabled: filterOptions.length === 0, sx: { zIndex: 0, fontSize: '5px !important' }, children: [jsx(Checkbox, { size: "small", checked: selectAll, onChange: () => {
58
+ : selectedValuesString) }) })), MenuProps: {
59
+ PaperProps: {
60
+ style: {
61
+ maxHeight: ITEM_HEIGHT * 5.5 + ITEM_PADDING_TOP,
62
+ // Match the container width dynamically
63
+ width: containerRef.current ? containerRef.current.clientWidth : 250,
64
+ },
65
+ },
66
+ // Using 'as const' fixes the TS2322 string incompatibility error
67
+ anchorOrigin: {
68
+ vertical: 'bottom',
69
+ horizontal: 'left',
70
+ },
71
+ transformOrigin: {
72
+ vertical: 'top',
73
+ horizontal: 'left',
74
+ },
75
+ autoFocus: false,
76
+ disableAutoFocusItem: true,
77
+ }, children: [jsx(Box, { sx: { width: '100%', position: 'sticky', top: 0, padding: '7px', zIndex: 2, background: '#fff' }, children: jsx(TextField, { inputRef: textfieldRef, fullWidth: true, size: "small", placeholder: "Search...", value: searchText, onChange: (e) => setSearchText(e.target.value),
78
+ // Prevent space key from closing the select while typing in search
79
+ onKeyDown: (e) => e.key !== 'Escape' && e.stopPropagation() }) }), jsxs(MenuItem, { disabled: filterOptions.length === 0, sx: { py: 0.5 }, children: [jsx(Checkbox, { size: "small", checked: selectAll, onChange: () => {
80
+ const currentValues = fieldValue?.split(',').filter(Boolean) || [];
81
+ const filteredIds = filterOptions.map((opt) => String(opt.value));
121
82
  if (selectAll) {
122
- // Deselect all filtered options
123
- const currentValues = fieldValue?.split(',').filter(Boolean) || [];
124
- const filteredValues = filterOptions.map((opt) => String(opt.value));
125
- const newValues = currentValues.filter((v) => !filteredValues.includes(v));
126
- props.setValue(props.item.name, newValues.join(','));
83
+ props.setValue(props.item.name, currentValues.filter((v) => !filteredIds.includes(v)).join(','));
127
84
  }
128
85
  else {
129
- // Select all filtered options
130
- const currentValues = fieldValue?.split(',').filter(Boolean) || [];
131
- const filteredValues = filterOptions.map((opt) => String(opt.value));
132
- const newValues = [...new Set([...currentValues, ...filteredValues])];
133
- props.setValue(props.item.name, newValues.join(','));
86
+ props.setValue(props.item.name, [...new Set([...currentValues, ...filteredIds])].join(','));
134
87
  }
135
- } }), jsx(ListItemText, { primary: 'Select All', sx: {
136
- fontSize: '5px !important',
137
- '& span': {
138
- fontSize: '12px !important',
139
- },
140
- } })] }), filterOptions.length !== 0 ? (filterOptions.map((option) => {
88
+ } }), jsx(ListItemText, { primary: "Select All", primaryTypographyProps: { fontSize: '13px' } })] }), filterOptions.length !== 0 ? (filterOptions.map((option) => {
141
89
  const selectedArray = fieldValue ? extractValuesToArray(fieldValue) : [];
142
90
  const isChecked = selectedArray.includes(String(option.value));
143
- return (jsxs(MenuItem, { value: `${option.value}`, selected: isChecked, sx: { zIndex: 0, fontSize: '11px !important' }, children: [jsx(Checkbox, { checked: isChecked, size: "small" }), jsx(ListItemText, { primary: option.label, sx: {
144
- fontSize: '5px !important',
145
- '& span': {
146
- fontSize: '12px !important',
147
- },
91
+ return (jsxs(MenuItem, { value: `${option.value}`, sx: {
92
+ whiteSpace: 'normal',
93
+ wordBreak: 'break-all',
94
+ alignItems: 'flex-start',
95
+ py: 1,
96
+ }, children: [jsx(Checkbox, { checked: isChecked, size: "small", sx: { mt: -0.5, mr: 1 } }), jsx(ListItemText, { primary: option.label, primaryTypographyProps: {
97
+ fontSize: '13px',
98
+ style: {
99
+ whiteSpace: 'normal',
100
+ wordBreak: 'break-all',
101
+ lineHeight: '1.4'
102
+ }
148
103
  } })] }, option.value));
149
- })) : (jsx(MenuItem, { disabled: true, value: 'NA', children: "No data Found" }, 'NA'))] }), jsx(FormBottomField, { ...props })] }) }, props.item.name));
104
+ })) : (jsx(MenuItem, { disabled: true, children: "No data Found" }))] }), jsx(FormBottomField, { ...props })] }) }, props.item.name));
150
105
  }
151
106
 
152
107
  export { MultiSelectV1 as default };
@@ -1,4 +1,4 @@
1
- import { __exports as Calendar } from '../../../../../_virtual/index.esm6.js';
1
+ import { __exports as Calendar } from '../../../../../_virtual/index.esm7.js';
2
2
  import require$$0__default from 'react';
3
3
  import { __require as requirePropTypes } from '../../../../prop-types/index.esm.js';
4
4
  import { __require as requireDayCell } from '../DayCell/index.esm.js';
@@ -1,4 +1,4 @@
1
- import { __exports as DateRange } from '../../../../../_virtual/index.esm4.js';
1
+ import { __exports as DateRange } from '../../../../../_virtual/index.esm5.js';
2
2
  import require$$0__default from 'react';
3
3
  import { __require as requirePropTypes } from '../../../../prop-types/index.esm.js';
4
4
  import { __require as requireCalendar } from '../Calendar/index.esm.js';
@@ -1,4 +1,4 @@
1
- import { __exports as DateRangePicker } from '../../../../../_virtual/index.esm5.js';
1
+ import { __exports as DateRangePicker } from '../../../../../_virtual/index.esm4.js';
2
2
  import require$$0__default from 'react';
3
3
  import { __require as requirePropTypes } from '../../../../prop-types/index.esm.js';
4
4
  import { __require as requireDateRange } from '../DateRange/index.esm.js';
@@ -1,4 +1,4 @@
1
- import { __exports as DefinedRange } from '../../../../../_virtual/index.esm7.js';
1
+ import { __exports as DefinedRange } from '../../../../../_virtual/index.esm6.js';
2
2
  import require$$0__default from 'react';
3
3
  import { __require as requirePropTypes } from '../../../../prop-types/index.esm.js';
4
4
  import { __require as requireStyles } from '../../styles.esm.js';
@@ -1,4 +1,4 @@
1
- import { __exports as InputRangeField } from '../../../../../_virtual/index.esm14.js';
1
+ import { __exports as InputRangeField } from '../../../../../_virtual/index.esm12.js';
2
2
  import require$$0__default from 'react';
3
3
  import { __require as requirePropTypes } from '../../../../prop-types/index.esm.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { __exports as Month } from '../../../../../_virtual/index.esm12.js';
1
+ import { __exports as Month } from '../../../../../_virtual/index.esm14.js';
2
2
  import require$$0__default from 'react';
3
3
  import { __require as requirePropTypes } from '../../../../prop-types/index.esm.js';
4
4
  import { __require as requireDayCell } from '../DayCell/index.esm.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tp-react-elements",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "React form components library built with React Hook Form and Yup",