@sydsoft/base 1.47.0 → 1.49.0

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.
Files changed (151) hide show
  1. package/README.md +8 -1
  2. package/{dist/esm → _dist}/_lib/baseFunctions.d.ts +0 -1
  3. package/{dist/esm → _dist}/_lib/baseFunctions.js +25 -38
  4. package/{dist/esm → _dist}/_lib/inputMask.js +66 -69
  5. package/{dist/esm → _dist}/_lib/listFunctions.js +12 -13
  6. package/_dist/_lib/storage/cookies.d.ts +4 -0
  7. package/_dist/_lib/storage/cookies.js +33 -0
  8. package/_dist/_lib/storage/encData.js +41 -0
  9. package/{dist/esm → _dist}/_lib/storage/localStorage.js +10 -10
  10. package/{dist/esm → _dist}/_lib/storage/sessionStorage.js +10 -10
  11. package/{dist/esm → _dist}/_lib/useInterval.js +5 -5
  12. package/{dist/esm → _dist}/alert/index.js +28 -30
  13. package/_dist/box/Box.js +14 -0
  14. package/_dist/box/BoxContent.js +5 -0
  15. package/_dist/box/BoxFooter.js +10 -0
  16. package/_dist/box/BoxHeader.js +10 -0
  17. package/_dist/countDown/index.js +92 -0
  18. package/{dist/esm → _dist}/dateTime/index.js +25 -31
  19. package/_dist/form/Button.js +82 -0
  20. package/_dist/form/Checkbox.js +22 -0
  21. package/_dist/form/Dialog.js +53 -0
  22. package/_dist/form/Form.js +10 -0
  23. package/_dist/form/FormOlustur.js +50 -0
  24. package/{dist/esm → _dist}/form/Input.js +57 -56
  25. package/_dist/form/Label.js +7 -0
  26. package/{dist/esm → _dist}/form/SearchableInput.d.ts +0 -1
  27. package/_dist/form/SearchableInput.js +260 -0
  28. package/_dist/form/UploadBase.js +84 -0
  29. package/_dist/grid/index.js +96 -0
  30. package/{dist/esm → _dist}/icon/icons.js +1 -1
  31. package/{dist/esm → _dist}/icon/index.d.ts +1 -1
  32. package/_dist/icon/index.js +34 -0
  33. package/_dist/menu/index.js +50 -0
  34. package/_dist/modal/index.js +64 -0
  35. package/{dist/esm → _dist}/popover/index.js +100 -100
  36. package/_dist/tooltip/index.js +202 -0
  37. package/_lib/baseFunctions.ts +94 -0
  38. package/_lib/inputMask.ts +257 -0
  39. package/_lib/listFunctions.ts +106 -0
  40. package/_lib/storage/cookies.ts +39 -0
  41. package/_lib/storage/encData.ts +41 -0
  42. package/_lib/storage/localStorage.ts +67 -0
  43. package/_lib/storage/sessionStorage.ts +67 -0
  44. package/_lib/useInterval.ts +30 -0
  45. package/alert/index.module.css +119 -0
  46. package/alert/index.tsx +131 -0
  47. package/box/Box.module.css +153 -0
  48. package/box/Box.tsx +33 -0
  49. package/box/BoxContent.tsx +18 -0
  50. package/box/BoxFooter.tsx +25 -0
  51. package/box/BoxHeader.tsx +46 -0
  52. package/box/index.ts +10 -0
  53. package/countDown/index.tsx +116 -0
  54. package/dateTime/index.ts +79 -0
  55. package/form/Button.tsx +143 -0
  56. package/form/Checkbox.tsx +48 -0
  57. package/form/Dialog.tsx +109 -0
  58. package/form/Form.tsx +19 -0
  59. package/form/FormOlustur.tsx +105 -0
  60. package/form/Input.tsx +364 -0
  61. package/form/Label.tsx +20 -0
  62. package/form/SearchableInput.tsx +406 -0
  63. package/form/UploadBase.tsx +133 -0
  64. package/form/index.ts +10 -0
  65. package/form/styles/Button.module.css +145 -0
  66. package/form/styles/Input.module.css +221 -0
  67. package/form/styles/Label.module.css +31 -0
  68. package/form/styles/SearchableInput.module.css +80 -0
  69. package/global.d.ts +9 -0
  70. package/grid/index.module.css +805 -0
  71. package/grid/index.tsx +171 -0
  72. package/icon/icons.tsx +33 -0
  73. package/icon/index.tsx +95 -0
  74. package/icon/mui.tsx +5932 -0
  75. package/index.ts +21 -0
  76. package/menu/index.module.css +92 -0
  77. package/menu/index.tsx +143 -0
  78. package/modal/index.module.css +77 -0
  79. package/modal/index.tsx +106 -0
  80. package/npm_recovery_codes.txt +5 -0
  81. package/package.json +18 -11
  82. package/popover/index.module.css +89 -0
  83. package/popover/index.tsx +392 -0
  84. package/tooltip/index.tsx +216 -0
  85. package/tsconfig.json +24 -0
  86. package/dist/esm/_lib/storage/cookies.d.ts +0 -4
  87. package/dist/esm/_lib/storage/cookies.js +0 -34
  88. package/dist/esm/_lib/storage/encData.js +0 -43
  89. package/dist/esm/box/Box.js +0 -15
  90. package/dist/esm/box/BoxContent.js +0 -7
  91. package/dist/esm/box/BoxFooter.js +0 -8
  92. package/dist/esm/box/BoxHeader.js +0 -9
  93. package/dist/esm/countDown/index.js +0 -97
  94. package/dist/esm/form/Button.js +0 -76
  95. package/dist/esm/form/Checkbox.js +0 -23
  96. package/dist/esm/form/Dialog.js +0 -40
  97. package/dist/esm/form/Form.js +0 -12
  98. package/dist/esm/form/FormOlustur.js +0 -52
  99. package/dist/esm/form/Label.js +0 -9
  100. package/dist/esm/form/SearchableInput.js +0 -272
  101. package/dist/esm/form/UploadBase.js +0 -86
  102. package/dist/esm/grid/index.js +0 -97
  103. package/dist/esm/icon/index.js +0 -26
  104. package/dist/esm/menu/index.js +0 -52
  105. package/dist/esm/modal/index.js +0 -66
  106. package/dist/esm/tooltip/index.js +0 -119
  107. /package/{dist/esm → _dist}/_lib/inputMask.d.ts +0 -0
  108. /package/{dist/esm → _dist}/_lib/listFunctions.d.ts +0 -0
  109. /package/{dist/esm → _dist}/_lib/storage/encData.d.ts +0 -0
  110. /package/{dist/esm → _dist}/_lib/storage/localStorage.d.ts +0 -0
  111. /package/{dist/esm → _dist}/_lib/storage/sessionStorage.d.ts +0 -0
  112. /package/{dist/esm → _dist}/_lib/useInterval.d.ts +0 -0
  113. /package/{dist/esm → _dist}/alert/index.d.ts +0 -0
  114. /package/{dist/esm → _dist}/alert/index.module.css +0 -0
  115. /package/{dist/esm → _dist}/box/Box.d.ts +0 -0
  116. /package/{dist/esm → _dist}/box/Box.module.css +0 -0
  117. /package/{dist/esm → _dist}/box/BoxContent.d.ts +0 -0
  118. /package/{dist/esm → _dist}/box/BoxFooter.d.ts +0 -0
  119. /package/{dist/esm → _dist}/box/BoxHeader.d.ts +0 -0
  120. /package/{dist/esm → _dist}/box/index.d.ts +0 -0
  121. /package/{dist/esm → _dist}/box/index.js +0 -0
  122. /package/{dist/esm → _dist}/countDown/index.d.ts +0 -0
  123. /package/{dist/esm → _dist}/dateTime/index.d.ts +0 -0
  124. /package/{dist/esm → _dist}/form/Button.d.ts +0 -0
  125. /package/{dist/esm → _dist}/form/Checkbox.d.ts +0 -0
  126. /package/{dist/esm → _dist}/form/Dialog.d.ts +0 -0
  127. /package/{dist/esm → _dist}/form/Form.d.ts +0 -0
  128. /package/{dist/esm → _dist}/form/FormOlustur.d.ts +0 -0
  129. /package/{dist/esm → _dist}/form/Input.d.ts +0 -0
  130. /package/{dist/esm → _dist}/form/Label.d.ts +0 -0
  131. /package/{dist/esm → _dist}/form/UploadBase.d.ts +0 -0
  132. /package/{dist/esm → _dist}/form/index.d.ts +0 -0
  133. /package/{dist/esm → _dist}/form/index.js +0 -0
  134. /package/{dist/esm → _dist}/form/styles/Button.module.css +0 -0
  135. /package/{dist/esm → _dist}/form/styles/Input.module.css +0 -0
  136. /package/{dist/esm → _dist}/form/styles/Label.module.css +0 -0
  137. /package/{dist/esm → _dist}/form/styles/SearchableInput.module.css +0 -0
  138. /package/{dist/esm → _dist}/grid/index.d.ts +0 -0
  139. /package/{dist/esm → _dist}/grid/index.module.css +0 -0
  140. /package/{dist/esm → _dist}/icon/icons.d.ts +0 -0
  141. /package/{dist/esm → _dist}/icon/mui.d.ts +0 -0
  142. /package/{dist/esm → _dist}/icon/mui.js +0 -0
  143. /package/{dist/esm → _dist}/index.d.ts +0 -0
  144. /package/{dist/esm → _dist}/index.js +0 -0
  145. /package/{dist/esm → _dist}/menu/index.d.ts +0 -0
  146. /package/{dist/esm → _dist}/menu/index.module.css +0 -0
  147. /package/{dist/esm → _dist}/modal/index.d.ts +0 -0
  148. /package/{dist/esm → _dist}/modal/index.module.css +0 -0
  149. /package/{dist/esm → _dist}/popover/index.d.ts +0 -0
  150. /package/{dist/esm → _dist}/popover/index.module.css +0 -0
  151. /package/{dist/esm → _dist}/tooltip/index.d.ts +0 -0
@@ -0,0 +1,406 @@
1
+ import { Button, Input, PropsInput } from './index';
2
+ import { convertForSearch, convertLowerCase } from '../_lib/baseFunctions';
3
+ import { forwardRef, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from 'react';
4
+ import { onKeyboardSelection, setScrollListPosition } from '../_lib/listFunctions';
5
+
6
+ import { Icon } from '../icon';
7
+ import styles from './styles/SearchableInput.module.css';
8
+
9
+ type typeList = {
10
+ value?: string;
11
+ label?: string;
12
+ [key: string]: any;
13
+ };
14
+
15
+ type typeValue = string | number | undefined;
16
+
17
+ interface Props extends PropsInput {
18
+ autoCompleteList?: typeList[];
19
+ isDataFromApi: boolean;
20
+ value: typeValue;
21
+ valueKey?: string;
22
+ labelKey?: string;
23
+ itemComponent?: (option: typeList) => React.ReactNode;
24
+ parentInputValue?: typeValue; // Eğer bu input bir başka inputa bağlı ise, o inputun value'sunu gönderin. (örneğin; şehir - ilçe)
25
+ onChange?: (e: any) => void;
26
+ onText?: (text: string) => void; // Text değiştiğinde tetiklenir.
27
+ onSelect?: (item: any) => void; // Bir item seçildiğinde tetiklenir.
28
+ onLoad?: (value: typeValue) => void; // Component hazır olduğunda tetiklenir.
29
+ ilkSec?: boolean;
30
+ newCreate?: boolean; // Yeni bir item oluşturulabilir.
31
+ style?: React.CSSProperties;
32
+ disabled?: boolean;
33
+ listPositionRelative?: boolean; // Liste pozisyonu relative olacaksa true gönderin. (Varsayılan absolute)
34
+ loadingMessage?: string;
35
+ notFoundMessage?: string;
36
+ }
37
+
38
+ export interface SearchableInputRef {
39
+ setAutoCompleteList: (list: typeList[], value?: typeValue, callback?: () => void) => void;
40
+ clear: (openList?: boolean, focusInput?: boolean) => void;
41
+ open: () => void;
42
+ close: () => void;
43
+ checkByValue: (value: typeValue, openList?: boolean) => void;
44
+ setLoading: (loading: boolean) => void;
45
+ }
46
+
47
+ export const SearchableInput = forwardRef<SearchableInputRef, Props>(
48
+ (
49
+ {
50
+ autoCompleteList = [],
51
+ isDataFromApi,
52
+ name,
53
+ value,
54
+ parentInputValue,
55
+ disabled,
56
+ itemComponent,
57
+ valueKey = 'value',
58
+ labelKey = 'label',
59
+ onSelect,
60
+ onChange,
61
+ onText,
62
+ onLoad,
63
+ style,
64
+ listPositionRelative = false,
65
+ loadingMessage = 'Lütfen bekleyiniz...',
66
+ notFoundMessage = 'Kayıt bulunamadı...',
67
+ placeholder,
68
+ endAdornment,
69
+ ilkSec = false,
70
+ newCreate = false,
71
+ inputRef,
72
+ ...other
73
+ },
74
+ ref
75
+ ) => {
76
+ const refMain = useRef<HTMLDivElement>(null);
77
+ const refInput = useRef<HTMLInputElement>(null);
78
+ const refList = useRef<HTMLUListElement>(null);
79
+
80
+ const [data, setData] = useState<typeList[]>(autoCompleteList ?? []);
81
+ const [selectedValue, setSelectedValue] = useState<typeValue>(value ?? undefined);
82
+ const [parentValue, setParentValue] = useState<typeValue>(parentInputValue ?? undefined);
83
+ const [text, setText] = useState<string>(''); //Inputta görünen
84
+ const [filter, setFilter] = useState<string>(''); // Filtrelemeye tabi tutulan
85
+ const [newItemCreate, setNewItemCreate] = useState<typeList>({ created: false });
86
+ const [open, setOpen] = useState<boolean>(false);
87
+ const [loading, setLoading] = useState<boolean>(isDataFromApi && (!autoCompleteList || autoCompleteList?.length == 0));
88
+
89
+ useImperativeHandle(
90
+ ref,
91
+ () => ({
92
+ setAutoCompleteList: (list: typeList[], value: typeValue = undefined, callback?: () => void) => {
93
+ if (autoCompleteList && autoCompleteList?.length > 0) {
94
+ alert('AutoCompleteList zaten tanımlı olduğundan dışardan data seti değiştirilemez.');
95
+ return;
96
+ }
97
+ setData(list);
98
+ value && sendChange(value);
99
+ setLoading(false);
100
+ if (!Array.isArray(list) || list.length == 0) {
101
+ clear(false);
102
+ }
103
+ callback && callback();
104
+ // isDev && console.log("setAutoCompleteList =>", name, value, list);
105
+ },
106
+ clear: (openList: boolean = false, focusInput: boolean = false) => clear(openList, focusInput),
107
+ open: () => {
108
+ setOpen(true);
109
+ refInput.current && refInput.current.focus();
110
+ },
111
+ close: () => setOpen(false),
112
+ checkByValue: (value: typeValue, openList: boolean = false) => checkByValue(value, openList),
113
+ setLoading: (value) => setLoading(value)
114
+ }),
115
+ [autoCompleteList, data, value]
116
+ );
117
+
118
+ useEffect(() => {
119
+ if (inputRef) inputRef.current = refInput.current;
120
+ }, [refInput.current]);
121
+
122
+ useEffect(() => onLoad && onLoad(value), []);
123
+
124
+ useEffect(() => {
125
+ if (autoCompleteList && Array.isArray(autoCompleteList)) {
126
+ if (autoCompleteList.length > 0) {
127
+ // Sadece gerçekten farklıysa set et
128
+ if (JSON.stringify(autoCompleteList) !== JSON.stringify(data)) {
129
+ setData(autoCompleteList);
130
+ // isDev && console.log("autoCompleteList dolu =>", name, autoCompleteList);
131
+ }
132
+ } else {
133
+ // Boş array geldi VE data zaten boş değilse
134
+ if (data.length > 0) {
135
+ setData([]);
136
+ // isDev && console.log("autoCompleteList boşaltıldı =>", name);
137
+ }
138
+ }
139
+ }
140
+ }, [autoCompleteList]);
141
+
142
+ useEffect(() => {
143
+ // isDev && console.log('data =>', name, data, 'selectedValue =>', selectedValue, 'value =>', value);
144
+ if (!Array.isArray(data)) {
145
+ setData([]);
146
+ }
147
+ if (data.length > 0) {
148
+ setLoading(false);
149
+ checkByValue(selectedValue, open);
150
+ if (!value && ilkSec) {
151
+ checkByValue(data[0][valueKey], false);
152
+ }
153
+ } else {
154
+ !isDataFromApi && clear(false);
155
+ }
156
+ }, [data]);
157
+
158
+ // Seçim değişikliğinde parent'ı bilgilendir
159
+ useEffect(() => {
160
+ // isDev && console.log('selectedValue =>', name, selectedValue, 'value =>', value);
161
+ if (value?.toString() != selectedValue?.toString()) {
162
+ checkByValue(value, open);
163
+ // isDev && console.log('value Kontrol ediliyor', value, selectedValue);
164
+ }
165
+ }, [value]);
166
+
167
+ useEffect(() => {
168
+ if (parentInputValue !== parentValue) {
169
+ setParentValue(parentInputValue);
170
+ clear(false);
171
+ // isDev && console.log(name, "parentInputValueDeğişti =>", parentInputValue);
172
+ }
173
+ }, [parentInputValue]);
174
+
175
+ useEffect(() => {
176
+ const checkHideBackDrop = (e: any) => {
177
+ if (open && refMain.current && !refMain.current.contains(e.target)) {
178
+ checkByInput();
179
+ }
180
+ };
181
+ const checkESC = (e: any) => {
182
+ if (e.keyCode === 27 || e.key === 'Escape' || e.code === 'Escape') checkByInput();
183
+ };
184
+
185
+ window.addEventListener('mousedown', checkHideBackDrop);
186
+ if (refMain.current) refMain.current.addEventListener('keydown', checkESC);
187
+
188
+ if (open) {
189
+ setScrollListPosition(refList);
190
+ if (!listPositionRelative) {
191
+ window.addEventListener('scroll', handleUpdatePosition, true);
192
+ window.addEventListener('resize', handleUpdatePosition);
193
+ }
194
+ }
195
+
196
+ return () => {
197
+ window.removeEventListener('mousedown', checkHideBackDrop);
198
+ if (refMain.current) refMain.current.removeEventListener('keydown', checkESC);
199
+ window.removeEventListener('scroll', handleUpdatePosition, true);
200
+ window.removeEventListener('resize', handleUpdatePosition);
201
+ };
202
+ }, [open]);
203
+
204
+ useLayoutEffect(() => handleUpdatePosition(), [open]);
205
+
206
+ const setValue = useCallback(
207
+ (item: typeList | undefined, openList: boolean) => {
208
+ const newValue = item?.[valueKey] ?? '';
209
+ const newLabel = item?.[labelKey] ?? '';
210
+ setOpen(openList);
211
+ setText(newLabel);
212
+
213
+ // isDev && console.log(name, "setValue", newValue, "item", item, "value", value);
214
+ if (newValue === selectedValue) return;
215
+ setFilter('');
216
+ setSelectedValue(newValue);
217
+ onChange && sendChange(newValue);
218
+ onSelect && onSelect(item);
219
+ },
220
+ [onChange, onSelect, name, selectedValue, valueKey, labelKey]
221
+ );
222
+
223
+ const textInputOnChange = useCallback(
224
+ (e: any) => {
225
+ setSelectedValue(undefined);
226
+ setText(e.target.value);
227
+ setFilter(e.target.value.trim());
228
+ setOpen(true);
229
+ onText && onText(e.target.value);
230
+ },
231
+ [setValue, onText]
232
+ );
233
+
234
+ const checkByValue = useCallback(
235
+ (value: typeValue, openList: boolean = false, list: typeList[] = []) => {
236
+ const targetList = list.length > 0 ? list : data;
237
+ let find = Object.values(targetList).find((item: any) => convertLowerCase(item[valueKey]) === convertLowerCase(value));
238
+ if (!find && newCreate && newItemCreate.create) {
239
+ find = newItemCreate;
240
+ }
241
+ // isDev && console.log('find', find, 'value', value, data);
242
+ setValue(find, openList);
243
+ },
244
+ [data, valueKey, newCreate, newItemCreate, setValue]
245
+ );
246
+ const checkByInput = useCallback(() => {
247
+ const findByLabel: any = data.find((item: any) => convertLowerCase(item[labelKey]) === convertLowerCase(refInput.current?.value));
248
+ if (findByLabel && value == findByLabel[valueKey]) {
249
+ setOpen(false);
250
+ return;
251
+ }
252
+ setValue(findByLabel, false);
253
+ if (!findByLabel) setText('');
254
+
255
+ if (isDataFromApi && !findByLabel && data.length === 0) {
256
+ if (onText) onText('');
257
+ }
258
+ }, [data, labelKey, value, valueKey, isDataFromApi, onText, setValue, refInput.current]);
259
+
260
+ const clear = useCallback(
261
+ (openList: boolean = true, focusInput: boolean = false) => {
262
+ setFilter('');
263
+ setText('');
264
+ setValue(undefined, openList);
265
+ onText && onText('');
266
+ focusInput && refInput?.current?.focus();
267
+ },
268
+ [setValue, onText]
269
+ );
270
+ const sendChange = useCallback(
271
+ (value: typeValue) => {
272
+ // isDev && console.log(name, "sendChange", value, "selectedValue", selectedValue);
273
+ if (onChange && value !== selectedValue) {
274
+ onChange({ target: { name, value } });
275
+ }
276
+ },
277
+ [onChange, name]
278
+ );
279
+
280
+ const filteredData = useMemo(() => {
281
+ let list: any[];
282
+ if (filter.length > 0) {
283
+ list = data.filter((item: any) => convertForSearch(item[labelKey]).includes(convertForSearch(filter)) || item[labelKey] == filter);
284
+ } else {
285
+ list = data;
286
+ }
287
+
288
+ if (newCreate && text.length > 0) {
289
+ const filterText = data.find((item: any) => item[labelKey].toString().toLowerCase() === text.toString().toLowerCase());
290
+ if (!filterText) {
291
+ const newItem = { [labelKey]: text, [valueKey]: text, create: true };
292
+ list = [newItem, ...list];
293
+ setNewItemCreate(newItem);
294
+ } else {
295
+ if (newItemCreate.create) setNewItemCreate({ create: false });
296
+ }
297
+ }
298
+ return list;
299
+ }, [data, filter, newCreate, text, valueKey, labelKey]);
300
+
301
+ const handleUpdatePosition = () => {
302
+ if (open && !listPositionRelative && refMain) {
303
+ setFixedPosition(refMain);
304
+ }
305
+ };
306
+
307
+ const onKeyDown = (e: any) => {
308
+ if (!open || !refList.current) return null;
309
+ onKeyboardSelection({
310
+ e,
311
+ targetElement: refList,
312
+ checkByInput,
313
+ checkByValue,
314
+ clear,
315
+ itemClass: 'li.item',
316
+ selectedClass: 'selected'
317
+ });
318
+ };
319
+
320
+ return (
321
+ <div ref={refMain} className={styles.searchableInputComponent} onKeyDown={onKeyDown} style={style}>
322
+ <Input
323
+ {...other}
324
+ inputRef={refInput}
325
+ name={name}
326
+ value={text}
327
+ onFocus={() => !disabled && setOpen(true)}
328
+ onChange={textInputOnChange}
329
+ endAdornment={
330
+ !disabled && (
331
+ <div style={{ marginRight: 5 }} tabIndex={-1}>
332
+ <Button
333
+ title={'Temizle'}
334
+ tabIndex={-1}
335
+ hidden={!(text && text.length > 0)}
336
+ onClick={() => clear(true, true)}
337
+ onlyIcon={<Icon name={'close'} style={{ color: '#444' }} />}
338
+ />
339
+ {endAdornment}
340
+ <Button
341
+ tabIndex={-1}
342
+ hidden={!data || !(data.length > 0)}
343
+ onClick={() => !disabled && setOpen(!open)}
344
+ onlyIcon={<Icon name={open ? 'keyboard_arrow_up' : 'keyboard_arrow_down'} style={{ color: '#444' }} />}
345
+ />
346
+ </div>
347
+ )
348
+ }
349
+ placeholder={loading ? 'Lütfen bekleyiniz...' : placeholder}
350
+ loading={loading}
351
+ disabled={disabled}
352
+ propsInput={{
353
+ ...other?.propsInput,
354
+ autoComplete: 'off'
355
+ }}
356
+ />
357
+ {open && (
358
+ <div className={'listDiv'} data-relative={listPositionRelative}>
359
+ <ul ref={refList} className={`list ${open ? 'open' : ''}`}>
360
+ {(filteredData.length === 0 || loading) && <div className={`message ${loading ? 'loading' : ''}`}>{loading ? loadingMessage : notFoundMessage}</div>}
361
+ {filteredData.map((item: any, key: number) => {
362
+ const itemValue = item[valueKey];
363
+ const itemLabel = item[labelKey];
364
+ return (
365
+ <li key={key} className={`item ${itemValue === selectedValue ? 'active' : ''}`} data-value={itemValue} data-label={itemLabel} onClick={() => setValue(item, false)}>
366
+ {item.create && <span className={'newCreate'}>Yeni Oluştur: </span>}
367
+ {itemComponent ? itemComponent(item) : itemLabel}
368
+ </li>
369
+ );
370
+ })}
371
+ </ul>
372
+ </div>
373
+ )}
374
+ </div>
375
+ );
376
+ }
377
+ );
378
+
379
+ const setFixedPosition = (refMain: any) => {
380
+ if (!refMain.current) return;
381
+ const target = refMain.current;
382
+ const targetPosition = target.getBoundingClientRect();
383
+ const listDiv = target.querySelector('.listDiv');
384
+
385
+ if (listDiv) {
386
+ const listDivUL = target.querySelector('ul');
387
+ if (!listDiv) return;
388
+
389
+ const listHeight = listDivUL.getBoundingClientRect().height;
390
+
391
+ const style = [];
392
+ style.push(`position:fixed`);
393
+ style.push(`z-index:111111111111 !important`);
394
+ style.push(`width:${targetPosition.width}px`);
395
+
396
+ const spaceBelow = window.innerHeight - (targetPosition.top + targetPosition.height);
397
+ const spaceAbove = targetPosition.top;
398
+ if (spaceBelow < listHeight && spaceAbove > listHeight) {
399
+ style.push(`top:${targetPosition.top - listHeight}px`);
400
+ style.push(`margin-top:-1px`);
401
+ } else {
402
+ style.push(`top:${targetPosition.top + targetPosition.height}px`);
403
+ }
404
+ listDiv.setAttribute('style', style.join(';'));
405
+ }
406
+ };
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Copyright (c) 2024
3
+ * @author: izzetseydaoglu
4
+ * @last-modified: 11.06.2024 02:39
5
+ */
6
+
7
+ import React, { useEffect, useRef } from "react";
8
+
9
+ import { alert_add } from "../alert";
10
+
11
+ interface Props {
12
+ children?: React.ReactNode;
13
+ refUploadInput?: any;
14
+ className?: string;
15
+ required?: boolean;
16
+ multiple?: boolean;
17
+ ext_ok?: string[];
18
+ maxSize?: number;
19
+ maxFile?: number;
20
+ style?: React.CSSProperties;
21
+ onChange?: Function;
22
+ targetForm?: Function;
23
+ name?: string;
24
+ label?: string;
25
+ component?: any;
26
+ }
27
+
28
+ const upload_ext_ok = ["pdf", "doc", "docx", "xls", "xlsx", "jpg", "jpeg", "png", "bmp", "tiff", "tif", "udf", "txt", "rtf", "csv", "xml", "zip", "rar"];
29
+ const upload_maxsize = 30;
30
+ const upload_maxfile = 50;
31
+
32
+ export const UploadBase = ({
33
+ component = "div",
34
+ children,
35
+ targetForm,
36
+ onChange,
37
+ name = "file__",
38
+ required = true,
39
+ multiple = false,
40
+ maxSize = upload_maxsize,
41
+ maxFile = upload_maxfile,
42
+ ext_ok = upload_ext_ok,
43
+ style,
44
+ className,
45
+ refUploadInput = null,
46
+ label
47
+ }: Props) => {
48
+ const ref = useRef<HTMLInputElement | null>(null);
49
+ useEffect(() => {
50
+ if (refUploadInput) refUploadInput.current = ref.current;
51
+ }, [ref.current]);
52
+
53
+ const fileSelected = (e: any) => {
54
+ if (!(e.target.files.length > 0)) {
55
+ e.target.value = null;
56
+ return null;
57
+ }
58
+ if (e.target.files.length > maxFile) {
59
+ alert_add({ type: "error", message: "En fazla " + maxFile + " dosya seçebilirsiniz." });
60
+ e.target.value = null;
61
+ return null;
62
+ }
63
+
64
+ const fileList: any = [];
65
+ Object.values(e.target.files).map((file: any) => {
66
+ const size = file.size;
67
+ const ext = file.name.replace(/^.*\./, "").toLowerCase();
68
+
69
+ if (ext_ok.indexOf(ext) === -1) {
70
+ alert_add({ type: "error", message: "Yüklemeye çalıştığınız dosya türü desteklenmiyor. Desteklenen dosya türleri: " + ext_ok.join(", ") });
71
+ } else if (size > maxSize * 1000000) {
72
+ alert_add({ type: "error", message: "En fazla " + maxSize + "MB büyüklüğündeki dosyaları seçebilirsiniz." });
73
+ } else {
74
+ fileList.push(file);
75
+ }
76
+ });
77
+ if (onChange) onChange(fileList);
78
+
79
+ if (targetForm) {
80
+ const nameList: string[] = [];
81
+ let newform = {};
82
+ let uniqueID = new Date().getTime();
83
+ fileList.map((file: any) => {
84
+ uniqueID = uniqueID + 1;
85
+ newform = { ...newform, [name + uniqueID]: file };
86
+ nameList.push(file.name);
87
+ });
88
+ targetForm((prev: any) => ({
89
+ ...prev,
90
+ uploadBaseList: { ...newform },
91
+ uploadBaseListName: nameList.join(", ")
92
+ }));
93
+ }
94
+ };
95
+
96
+ const defaultStyle = {
97
+ position: "relative",
98
+ cursor: "pointer"
99
+ };
100
+ const Component = component.toLowerCase();
101
+ return (
102
+ <Component className={className} style={{ ...defaultStyle, ...style }} data-label={label ?? ""}>
103
+ {children}
104
+ <input
105
+ ref={ref}
106
+ type={"file"}
107
+ required={required}
108
+ onChange={fileSelected}
109
+ multiple={multiple}
110
+ accept={ext_ok.map((i: any) => "." + i).join(",")}
111
+ style={{
112
+ position: "absolute",
113
+ top: 0,
114
+ left: 0,
115
+ opacity: 0,
116
+ width: "100%",
117
+ height: "100%",
118
+ cursor: "pointer",
119
+ zIndex: 1
120
+ }}
121
+ />
122
+ </Component>
123
+ );
124
+ };
125
+
126
+ export const uploadBase_CreateForm = (formData: any) => {
127
+ let newform = { ...formData };
128
+ const list = formData["uploadBaseList"] ?? {};
129
+ Object.keys(list).map((fileKey: any) => (newform = { ...newform, [fileKey]: list[fileKey] }));
130
+ delete newform["uploadBaseList"];
131
+ delete newform["uploadBaseListName"];
132
+ return newform;
133
+ };
package/form/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from "./Button";
2
+ export * from "./Checkbox";
3
+ export * from "./Dialog";
4
+ export * from "./Form";
5
+ export * from "./FormOlustur";
6
+ export * from "./Input";
7
+ export * from "./Label";
8
+ export * from "./SearchableInput";
9
+ export * from "./UploadBase";
10
+
@@ -0,0 +1,145 @@
1
+ .button {
2
+ position: relative;
3
+ display: inline-flex;
4
+ align-items: center;
5
+ justify-content: center;
6
+ appearance: none;
7
+ user-select: none;
8
+ box-sizing: border-box;
9
+ overflow: hidden;
10
+ text-decoration: none;
11
+ letter-spacing: 0.03em;
12
+ text-transform: none;
13
+ border-radius: 6px;
14
+ color: rgba(0, 0, 0, 0.87);
15
+ font-family: inherit;
16
+ font-size: inherit;
17
+ font-weight: 500;
18
+ line-height: inherit;
19
+ box-shadow: 0 3px 1px -2px rgb(0 0 0 / 20%), 0 2px 2px 0 rgb(0 0 0 / 14%), 0px 1px 5px 0px rgb(0 0 0 / 12%);
20
+ background-color: #e0e0e0;
21
+ padding: 4px 10px;
22
+ outline: 0;
23
+ border: 0;
24
+ cursor: pointer;
25
+ white-space: nowrap;
26
+ }
27
+ .button.fullwidth {
28
+ width: 100%;
29
+ }
30
+ .button[data-button-size="small"] {
31
+ font-size: 0.875rem;
32
+ padding: 4px 10px;
33
+ min-width: 64px;
34
+ height: 32px;
35
+ }
36
+
37
+ .button[data-button-size="medium"] {
38
+ font-size: 1rem;
39
+ padding: 6px 12px;
40
+ min-width: 72px;
41
+ height: 36px;
42
+ }
43
+
44
+ .button[data-button-size="large"] {
45
+ font-size: 1.2rem;
46
+ padding: 8px 16px;
47
+ min-width: 80px;
48
+ height: 40px;
49
+ }
50
+
51
+ .button[hidden] {
52
+ display: none;
53
+ }
54
+
55
+ .button[disabled] {
56
+ opacity: 0.7;
57
+ box-shadow: inset 0 0 20px #000000ad;
58
+ cursor: not-allowed;
59
+ }
60
+ .button:focus,
61
+ .button:hover {
62
+ opacity: 0.9;
63
+ }
64
+
65
+ .button.primary {
66
+ color: #fff;
67
+ background-color: #3772c4;
68
+ border-color: #1877f2;
69
+ }
70
+
71
+ .button.secondary {
72
+ color: #fff;
73
+ background-color: #6c7573;
74
+ border-color: #6c757d;
75
+ }
76
+
77
+ .button.success {
78
+ color: #fff;
79
+ background-color: #198754;
80
+ border-color: #198754;
81
+ }
82
+
83
+ .button.danger {
84
+ color: #fff;
85
+ background-color: #dc3545;
86
+ border-color: #dc3545;
87
+ }
88
+
89
+ .button.warning {
90
+ color: #000;
91
+ background-color: #ffc107;
92
+ border-color: #ffc107;
93
+ }
94
+
95
+ .button.info {
96
+ color: #000;
97
+ background-color: #0dcaf0;
98
+ border-color: #0dcaf0;
99
+ }
100
+
101
+ .button.light {
102
+ color: #000;
103
+ background-color: #f8f9fa;
104
+ border-color: #f8f9fa;
105
+ }
106
+
107
+ .button.dark {
108
+ color: #fff;
109
+ background-color: #212529;
110
+ border-color: #212529;
111
+ }
112
+
113
+ .button.link {
114
+ box-shadow: none;
115
+ background-color: transparent;
116
+ color: inherit;
117
+ }
118
+
119
+ .iconbutton {
120
+ padding: 8px;
121
+ border-radius: 50%;
122
+ background-color: transparent;
123
+ box-shadow: none;
124
+ color: #707274;
125
+ /* overflow: unset; */
126
+ }
127
+ .iconbutton:focus,
128
+ .iconbutton:hover {
129
+ background-color: rgba(0, 0, 0, 0.04);
130
+ }
131
+
132
+ .ripple {
133
+ content: "";
134
+ position: absolute;
135
+ border-radius: 50%;
136
+ transform: scale(0);
137
+ animation: ripple 900ms linear;
138
+ background-color: rgba(255, 255, 255, 0.7);
139
+ }
140
+ @keyframes ripple {
141
+ to {
142
+ transform: scale(4);
143
+ opacity: 0;
144
+ }
145
+ }