hi-tm 0.0.2-beta-0.0.76 → 0.0.2-beta-0.0.78

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,4 @@
1
1
  import React from 'react';
2
2
  import type { CreatableSelectProps } from '../../types/DropDown/CreatableDropDown';
3
- export default function CreatableSelect({ options, value, onChange, onCreateOption, placeholder, isLoading, isDisabled, isClearable, isCreatable, isMultiSelect, noOptionsMessage, noResultsFound, loadingMessage, createOptionMessage, className, tailwindStyle, iconSrc, fetchOptions, label, onAddClick, }: CreatableSelectProps): React.JSX.Element;
3
+ export default function CreatableSelect({ options, value, onChange, onClick, // New prop for handling selection
4
+ onCreateOption, placeholder, isLoading, isDisabled, isClearable, isCreatable, isMultiSelect, noOptionsMessage, noResultsFound, loadingMessage, createOptionMessage, className, tailwindStyle, iconSrc, fetchOptions, label, onAddClick, }: CreatableSelectProps): React.JSX.Element;
@@ -85,7 +85,8 @@ const renderNoResults = (noResults, className, searchIcon) => {
85
85
  return noResults;
86
86
  }
87
87
  };
88
- function CreatableSelect({ options = [], value, onChange, onCreateOption, placeholder = 'Select...', isLoading = false, isDisabled = false, isClearable = true, isCreatable = true, isMultiSelect = false, noOptionsMessage = 'No options available', noResultsFound, loadingMessage = 'Loading...', createOptionMessage = 'Create option', className = '', tailwindStyle = {}, iconSrc, fetchOptions, label, onAddClick, }) {
88
+ function CreatableSelect({ options = [], value, onChange, onClick, // New prop for handling selection
89
+ onCreateOption, placeholder = 'Select...', isLoading = false, isDisabled = false, isClearable = true, isCreatable = true, isMultiSelect = false, noOptionsMessage = 'No options available', noResultsFound, loadingMessage = 'Loading...', createOptionMessage = 'Create option', className = '', tailwindStyle = {}, iconSrc, fetchOptions, label, onAddClick, }) {
89
90
  const styles = {
90
91
  ...defaultStyles,
91
92
  ...tailwindStyle,
@@ -103,6 +104,12 @@ function CreatableSelect({ options = [], value, onChange, onCreateOption, placeh
103
104
  : []);
104
105
  const containerRef = (0, react_1.useRef)(null);
105
106
  const inputRef = (0, react_1.useRef)(null);
107
+ (0, react_1.useEffect)(() => {
108
+ // Only update filteredOptions when options change if we're not in the middle of a search
109
+ if (!hasSearched) {
110
+ setFilteredOptions(options ?? []);
111
+ }
112
+ }, [options, hasSearched]);
106
113
  (0, react_1.useEffect)(() => {
107
114
  if (inputValue === '') {
108
115
  setFilteredOptions(options ?? []);
@@ -124,6 +131,10 @@ function CreatableSelect({ options = [], value, onChange, onCreateOption, placeh
124
131
  const value = e.target.value;
125
132
  setInputValue(value);
126
133
  setIsOpen(true);
134
+ // Pass the input event to onChange
135
+ if (onChange) {
136
+ onChange(e);
137
+ }
127
138
  if (fetchOptions && value.trim() !== '') {
128
139
  setInternalLoading(true);
129
140
  setHasSearched(true);
@@ -142,6 +153,12 @@ function CreatableSelect({ options = [], value, onChange, onCreateOption, placeh
142
153
  setFilteredOptions(options ?? []);
143
154
  setHasSearched(false);
144
155
  }
156
+ else {
157
+ // If we have no fetchOptions function but do have input,
158
+ // filter the options locally instead of making no changes
159
+ setFilteredOptions((options ?? []).filter((option) => option.label.toLowerCase().includes(value.toLowerCase())));
160
+ setHasSearched(true);
161
+ }
145
162
  };
146
163
  const handleKeyDown = (e) => {
147
164
  if (isDisabled)
@@ -217,21 +234,29 @@ function CreatableSelect({ options = [], value, onChange, onCreateOption, placeh
217
234
  e.stopPropagation();
218
235
  const newValues = selectedValues.filter((val) => val.value !== option.value);
219
236
  setSelectedValues(newValues);
220
- onChange(isMultiSelect ? newValues : newValues[0] || null);
237
+ // Use onClick instead of onChange for selection updates
238
+ if (onClick) {
239
+ onClick(isMultiSelect ? newValues : newValues[0] || null);
240
+ }
221
241
  };
222
242
  const selectOption = (option) => {
223
243
  if (isMultiSelect) {
224
- setSelectedValues((prev) => {
225
- if (prev.some((val) => val.value === option.value)) {
226
- return prev;
227
- }
228
- return [...prev, option];
229
- });
230
- onChange([...selectedValues, option]);
244
+ const newValues = [...selectedValues];
245
+ if (!newValues.some((val) => val.value === option.value)) {
246
+ newValues.push(option);
247
+ }
248
+ setSelectedValues(newValues);
249
+ // Use onClick instead of onChange for selection updates
250
+ if (onClick) {
251
+ onClick(newValues);
252
+ }
231
253
  }
232
254
  else {
233
255
  setSelectedValues([option]);
234
- onChange(option);
256
+ // Use onClick instead of onChange for selection updates
257
+ if (onClick) {
258
+ onClick(option);
259
+ }
235
260
  }
236
261
  setInputValue('');
237
262
  setIsOpen(false);
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
- import type { ModernTableProps } from '../../../types/ModernTable';
2
+ import { ModernTableProps } from '../../../types/ModernTable';
3
3
  declare const ModernTable: React.FC<ModernTableProps>;
4
4
  export default ModernTable;
@@ -7,12 +7,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const react_2 = require("react");
9
9
  const image_1 = __importDefault(require("next/image"));
10
+ const Loader_1 = __importDefault(require("../../../elements/Loader"));
10
11
  const formatWithCommas_1 = require("../../../helper/formatWithCommas");
11
- // Simple Loader component to replace the external import
12
- const Loader = () => {
13
- return (react_1.default.createElement("div", { className: "flex items-center justify-center" },
14
- react_1.default.createElement("div", { className: "h-5 w-5 animate-spin rounded-full border-2 border-solid border-blue-500 border-t-transparent" })));
15
- };
16
12
  // Helper function to handle modal styles
17
13
  const modalStyleOperationHandler = (classType) => {
18
14
  if (classType === 'delete') {
@@ -25,7 +21,7 @@ const modalStyleOperationHandler = (classType) => {
25
21
  const ModernTable = ({ rows = [], onEdit, loadingProps = {
26
22
  isLoading: false,
27
23
  loadingText: 'درحال دریافت اطلاعات',
28
- loadingIcon: react_1.default.createElement(Loader, null),
24
+ loadingIcon: react_1.default.createElement(Loader_1.default, null),
29
25
  }, onView, onAction, selectable, onSelectionChange, actions, modalActions, noItemFoundProps, selectedItems = [], iconsSRC,
30
26
  // Child row configuration with defaults
31
27
  childRowConfig = {
@@ -115,19 +111,9 @@ pageIndex = 0, // Default to first page (0-indexed)
115
111
  // Initialize expanded rows if specified in config
116
112
  (0, react_2.useEffect)(() => {
117
113
  if (childRowConfig.expandByDefault && rows) {
118
- // Helper function to collect all parent row IDs at any depth
119
- const collectParentIds = (rowsArray) => {
120
- let ids = [];
121
- rowsArray?.forEach((row) => {
122
- if (row.hasChildren && row.childRows && row.childRows.length > 0) {
123
- ids.push(row.id);
124
- // Recursively collect child row IDs that are also parents
125
- ids = [...ids, ...collectParentIds(row.childRows)];
126
- }
127
- });
128
- return ids;
129
- };
130
- const parentIds = collectParentIds(rows);
114
+ const parentIds = rows
115
+ .filter((row) => row.hasChildren && row.childRows && row.childRows.length > 0)
116
+ .map((row) => row.id);
131
117
  setExpandedRows(parentIds);
132
118
  }
133
119
  }, [rows, childRowConfig.expandByDefault]);
@@ -184,7 +170,7 @@ pageIndex = 0, // Default to first page (0-indexed)
184
170
  case 'warning':
185
171
  return 'text-yellow-700';
186
172
  case 'info':
187
- return 'text-blue-700 bg-[#dceeff] px-4 py-2 rounded-lg';
173
+ return 'text-blue-700';
188
174
  case 'primary':
189
175
  return 'text-[#6b46c1] rounded-lg bg-[#ede9f8] px-4 py-2';
190
176
  case 'secondary':
@@ -200,9 +186,9 @@ pageIndex = 0, // Default to first page (0-indexed)
200
186
  case 'price':
201
187
  return (react_1.default.createElement("p", { className: `${item.contentClass || 'text-start'} text-sm w-full truncate ` }, (0, formatWithCommas_1.formatWithCommas)(item.value)));
202
188
  default:
203
- return (react_1.default.createElement("div", { className: "flex items-center gap-2 w-full", onClick: () => item.onClick && item.onClick(item.id) }, item.hasImage ? (react_1.default.createElement("div", { className: `flex items-center gap-2 w-full ${item.contentClass || ''}` },
189
+ return (react_1.default.createElement("div", { className: "flex items-center gap-2 w-full" }, item.hasImage ? (react_1.default.createElement("div", { className: "flex items-center gap-2 w-full" },
204
190
  react_1.default.createElement(image_1.default, { src: item.imageUrl || '/placeholder.svg', alt: item.value?.toString() || 'Table item', width: item.imageWidth || 24, height: item.imageHeight || 24, className: `${item.imageClass || 'h-6 w-6 object-cover'}` }),
205
- item.value && (react_1.default.createElement("p", { className: `${item.contentClass || 'text-start'} text-sm w-full truncate ` }, item.value)))) : react_1.default.isValidElement(item.value) ? (item.value) : (react_1.default.createElement("p", { className: `${item.contentClass || 'text-start'} text-sm mr-[5px] w-full truncate`, title: item.value?.toString() || '' }, item.value))));
191
+ react_1.default.createElement("p", { className: `${item.contentClass || 'text-start'} text-sm w-full truncate ` }, item.value))) : (react_1.default.createElement("p", { className: `${item.contentClass || 'text-start'} text-sm mr-[5px] w-full truncate`, title: item.value?.toString() || '' }, item.value))));
206
192
  }
207
193
  };
208
194
  // Update selectedRows when selectedItems prop changes
@@ -308,18 +294,16 @@ pageIndex = 0, // Default to first page (0-indexed)
308
294
  moreOptionsIconPath, showAvatars, maxVisibleAvatars = 0, } = mobileCardConfig;
309
295
  // Calculate card classes - add special styling for child cards
310
296
  const cardClasses = `
311
- ${cardStyle?.backgroundColor || 'bg-white'}
312
- ${cardStyle?.borderRadius || 'rounded-lg'}
313
- ${cardStyle?.shadow || 'shadow-sm'}
314
- ${row.isChild ? 'border-l-4 border-l-blue-300' : cardStyle?.border || 'border border-gray-100'}
315
- ${cardStyle?.padding || 'p-4'}
316
- ${cardStyle?.marginBottom || 'mb-4'}
317
- ${row.isChild ? 'bg-opacity-90' : ''}
318
- w-full h-full
319
- `;
320
- // Apply left padding based on nesting level
321
- const nestedPadding = level > 0 ? { paddingLeft: `${level * 0.5}rem` } : {};
322
- return (react_1.default.createElement("div", { className: cardClasses, style: nestedPadding },
297
+ ${cardStyle?.backgroundColor || 'bg-white'}
298
+ ${cardStyle?.borderRadius || 'rounded-lg'}
299
+ ${cardStyle?.shadow || 'shadow-sm'}
300
+ ${row.isChild ? 'border-l-4 border-l-blue-300' : cardStyle?.border || 'border border-gray-100'}
301
+ ${cardStyle?.padding || 'p-4'}
302
+ ${cardStyle?.marginBottom || 'mb-4'}
303
+ ${row.isChild ? 'bg-opacity-90' : ''}
304
+ w-full h-full
305
+ `;
306
+ return (react_1.default.createElement("div", { className: cardClasses },
323
307
  react_1.default.createElement("div", { className: "flex items-start gap-2" },
324
308
  showFolderIcon && (react_1.default.createElement("div", { className: "mr-3 flex-shrink-0" },
325
309
  react_1.default.createElement("div", { className: "w-10 h-10 flex items-center justify-center" }, row.data && row.data.find((item) => item.hasImage)?.imageUrl ? (react_1.default.createElement(image_1.default, { src: row.data.find((item) => item.hasImage)?.imageUrl || '/placeholder.svg', alt: "folder", width: 40, height: 40, className: "h-full w-full object-cover" })) : (react_1.default.createElement(image_1.default, { src: folderIconPath || '/placeholder.svg', alt: "folder", width: 40, height: 40, className: "text-yellow-400" }))))),
@@ -371,8 +355,6 @@ pageIndex = 0, // Default to first page (0-indexed)
371
355
  // Render a single table row (parent or child)
372
356
  const renderTableRow = (row, index, isLastRow) => {
373
357
  // Width for the expand/collapse control column
374
- const level = row.level || 0;
375
- const indentSize = level > 0 ? `${level * Number.parseFloat(childRowConfig.indentSize || '1.5')}rem` : '0';
376
358
  return (react_1.default.createElement("div", { key: `row-container-${row.id}` },
377
359
  react_1.default.createElement("div", { className: `grid w-full items-center ${row.isChild
378
360
  ? childRowConfig.childRowClass || 'bg-blue-300 bg-opacity-10'
@@ -387,14 +369,14 @@ pageIndex = 0, // Default to first page (0-indexed)
387
369
  onView(row.id);
388
370
  }
389
371
  } },
390
- react_1.default.createElement("div", { className: `flex items-center justify-center gap-2 ${!row.hasChildren && 'mr-[4px]'}"`, style: { width: '55px', paddingLeft: indentSize } },
391
- !row.hasChildren && !row.isChild && (react_1.default.createElement("span", { className: "text-xs text-gray-500 font-semibold flex-shrink-0 mr-4 " }, ((pageIndex || 1) - 1) * (itemsPerPage || 10) + index + 1)),
372
+ react_1.default.createElement("div", { className: `flex items-center justify-center gap-2 ${!row.hasChildren && 'mr-[4px]'}"`, style: { width: '55px' } },
373
+ !row.hasChildren && !row.isChild && (react_1.default.createElement("span", { className: "text-xs text-gray-500 font-semibold flex-shrink-0 mr-1 " }, ((pageIndex || 1) - 1) * (itemsPerPage || 10) + index + 1)),
392
374
  react_1.default.createElement("div", { className: "flex items-center justify-center gap-1" },
393
- row.hasChildren && row.childRows && row.childRows?.length > 0 ? (react_1.default.createElement("button", { onClick: (e) => handleRowExpandToggle(row.id, e), className: "transition-transform duration-200 flex-shrink-0 z-60" },
375
+ row.hasChildren && row.childRows && row.childRows?.length > 0 ? (react_1.default.createElement("button", { onClick: (e) => handleRowExpandToggle(row.id, e), className: "transition-transform duration-200 flex-shrink-0" },
394
376
  react_1.default.createElement("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: `transition-transform ${expandedRows.includes(row.id) ? '-rotate-90' : ''}` },
395
377
  react_1.default.createElement("path", { d: "M15 5L8 12L15 19", stroke: "rgba(0, 0, 0, 0.40)", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })))) : row.isChild ? (
396
- // Child row indicator with different colors based on nesting level
397
- react_1.default.createElement("div", { className: `h-2 w-2 rounded-full bg-blue-${Math.min(400 + level * 100, 900)} flex-shrink-0` })) : null,
378
+ // Child row indicator
379
+ react_1.default.createElement("div", { className: "h-2 w-2 rounded-full bg-black/20 flex-shrink-0" })) : null,
398
380
  selectable === true && (react_1.default.createElement("div", { className: `relative flex-shrink-0 flex-row-reverse flex ${row.hasChildren && ''} ` },
399
381
  react_1.default.createElement("input", { type: "checkbox", checked: selectedRows?.includes(row.id), onChange: () => handleCheckboxChange(row.id), className: "peer h-5 w-5 cursor-pointer appearance-none rounded-md border-2 border-gray-300 transition-all checked:border-blue-500 checked:bg-blue-500 hover:border-blue-500", onClick: (e) => e.stopPropagation() }),
400
382
  react_1.default.createElement("svg", { className: "pointer-events-none absolute left-[5px] top-[5px] h-2.5 w-2.5 fill-white opacity-0 transition-opacity peer-checked:opacity-100", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24" },
@@ -41,7 +41,8 @@ export type NoResultsType = ReactNode | string | {
41
41
  export type CreatableSelectProps = {
42
42
  options: SelectOption[] | null;
43
43
  value: SelectOption | SelectOption[] | null;
44
- onChange: (value: SelectOption | SelectOption[] | null) => void;
44
+ onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
45
+ onClick?: (value: SelectOption | SelectOption[] | null) => void;
45
46
  onCreateOption?: (inputValue: string) => Promise<void> | void;
46
47
  placeholder?: string;
47
48
  isLoading?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.0.2-beta-0.0.76",
3
+ "version": "0.0.2-beta-0.0.78",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {