@ttdk-design-system/library-react 0.0.0-stage → 1.0.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 (184) hide show
  1. package/AI_GUIDE.md +6518 -0
  2. package/llms.txt +6518 -0
  3. package/package.json +1098 -4
  4. package/src/core/index.ts +2 -0
  5. package/src/core/tailwind-preset.cjs +62 -0
  6. package/src/core/tailwind-preset.ts +85 -0
  7. package/src/core/theme/tokens.css +663 -0
  8. package/src/core/types.ts +836 -0
  9. package/src/index.ts +17 -0
  10. package/src/tailwind-preset.cjs +62 -0
  11. package/src/tailwind-preset.ts +85 -0
  12. package/src/types.ts +1 -0
  13. package/src/web/accordion/AI_GUIDE.md +149 -0
  14. package/src/web/accordion/accordion.css +1 -0
  15. package/src/web/accordion/accordion.tsx +430 -0
  16. package/src/web/accordion/index.ts +3 -0
  17. package/src/web/accordion/manifest.json +351 -0
  18. package/src/web/alert/AI_GUIDE.md +139 -0
  19. package/src/web/alert/alert.css +1 -0
  20. package/src/web/alert/alert.tsx +318 -0
  21. package/src/web/alert/index.ts +3 -0
  22. package/src/web/alert/manifest.json +240 -0
  23. package/src/web/avatar/AI_GUIDE.md +118 -0
  24. package/src/web/avatar/avatar.css +1 -0
  25. package/src/web/avatar/avatar.tsx +233 -0
  26. package/src/web/avatar/index.ts +3 -0
  27. package/src/web/avatar/manifest.json +195 -0
  28. package/src/web/badge/AI_GUIDE.md +94 -0
  29. package/src/web/badge/badge.css +1 -0
  30. package/src/web/badge/badge.tsx +140 -0
  31. package/src/web/badge/index.ts +2 -0
  32. package/src/web/badge/manifest.json +141 -0
  33. package/src/web/banner/AI_GUIDE.md +130 -0
  34. package/src/web/banner/banner.css +1 -0
  35. package/src/web/banner/banner.tsx +334 -0
  36. package/src/web/banner/index.ts +3 -0
  37. package/src/web/banner/manifest.json +240 -0
  38. package/src/web/breadcrumb/AI_GUIDE.md +120 -0
  39. package/src/web/breadcrumb/breadcrumb.css +1 -0
  40. package/src/web/breadcrumb/breadcrumb.tsx +306 -0
  41. package/src/web/breadcrumb/index.ts +3 -0
  42. package/src/web/breadcrumb/manifest.json +225 -0
  43. package/src/web/button/AI_GUIDE.md +121 -0
  44. package/src/web/button/button.css +1 -0
  45. package/src/web/button/button.tsx +287 -0
  46. package/src/web/button/index.ts +2 -0
  47. package/src/web/button/manifest.json +177 -0
  48. package/src/web/calendar/AI_GUIDE.md +151 -0
  49. package/src/web/calendar/calendar.css +1 -0
  50. package/src/web/calendar/calendar.tsx +1611 -0
  51. package/src/web/calendar/index.ts +3 -0
  52. package/src/web/calendar/manifest.json +470 -0
  53. package/src/web/card/AI_GUIDE.md +133 -0
  54. package/src/web/card/card.css +1 -0
  55. package/src/web/card/card.tsx +408 -0
  56. package/src/web/card/index.ts +4 -0
  57. package/src/web/card/manifest.json +357 -0
  58. package/src/web/checkbox/AI_GUIDE.md +146 -0
  59. package/src/web/checkbox/checkbox.css +1 -0
  60. package/src/web/checkbox/checkbox.tsx +307 -0
  61. package/src/web/checkbox/index.ts +2 -0
  62. package/src/web/checkbox/manifest.json +294 -0
  63. package/src/web/chip/AI_GUIDE.md +186 -0
  64. package/src/web/chip/chip.css +1 -0
  65. package/src/web/chip/chip.tsx +230 -0
  66. package/src/web/chip/index.ts +2 -0
  67. package/src/web/chip/manifest.json +186 -0
  68. package/src/web/dropdown/AI_GUIDE.md +167 -0
  69. package/src/web/dropdown/dropdown.css +1 -0
  70. package/src/web/dropdown/dropdown.tsx +1274 -0
  71. package/src/web/dropdown/index.ts +3 -0
  72. package/src/web/dropdown/manifest.json +576 -0
  73. package/src/web/flex/AI_GUIDE.md +113 -0
  74. package/src/web/flex/flex-item.tsx +97 -0
  75. package/src/web/flex/flex.css +1 -0
  76. package/src/web/flex/flex.tsx +108 -0
  77. package/src/web/flex/index.ts +5 -0
  78. package/src/web/flex/manifest.json +162 -0
  79. package/src/web/form/index.ts +7 -0
  80. package/src/web/grid/AI_GUIDE.md +112 -0
  81. package/src/web/grid/grid-item.tsx +112 -0
  82. package/src/web/grid/grid.css +1 -0
  83. package/src/web/grid/grid.tsx +99 -0
  84. package/src/web/grid/index.ts +5 -0
  85. package/src/web/grid/manifest.json +153 -0
  86. package/src/web/index.ts +86 -0
  87. package/src/web/input/AI_GUIDE.md +159 -0
  88. package/src/web/input/index.ts +3 -0
  89. package/src/web/input/input.css +1 -0
  90. package/src/web/input/input.tsx +537 -0
  91. package/src/web/input/manifest.json +465 -0
  92. package/src/web/input-number/AI_GUIDE.md +164 -0
  93. package/src/web/input-number/index.ts +3 -0
  94. package/src/web/input-number/input-number.css +1 -0
  95. package/src/web/input-number/input-number.tsx +1193 -0
  96. package/src/web/input-number/manifest.json +575 -0
  97. package/src/web/modal/AI_GUIDE.md +171 -0
  98. package/src/web/modal/index.ts +3 -0
  99. package/src/web/modal/manifest.json +375 -0
  100. package/src/web/modal/modal.css +1 -0
  101. package/src/web/modal/modal.tsx +571 -0
  102. package/src/web/pagination/AI_GUIDE.md +148 -0
  103. package/src/web/pagination/index.ts +21 -0
  104. package/src/web/pagination/manifest.json +432 -0
  105. package/src/web/pagination/pagination-content.tsx +45 -0
  106. package/src/web/pagination/pagination-ellipsis.tsx +54 -0
  107. package/src/web/pagination/pagination-first.tsx +155 -0
  108. package/src/web/pagination/pagination-item.tsx +45 -0
  109. package/src/web/pagination/pagination-last.tsx +155 -0
  110. package/src/web/pagination/pagination-link.tsx +121 -0
  111. package/src/web/pagination/pagination-next.tsx +158 -0
  112. package/src/web/pagination/pagination-previous.tsx +158 -0
  113. package/src/web/pagination/pagination.css +1 -0
  114. package/src/web/pagination/pagination.tsx +687 -0
  115. package/src/web/popover/AI_GUIDE.md +163 -0
  116. package/src/web/popover/index.ts +3 -0
  117. package/src/web/popover/manifest.json +396 -0
  118. package/src/web/popover/popover.css +1 -0
  119. package/src/web/popover/popover.tsx +702 -0
  120. package/src/web/radio/AI_GUIDE.md +155 -0
  121. package/src/web/radio/index.ts +2 -0
  122. package/src/web/radio/manifest.json +294 -0
  123. package/src/web/radio/radio.css +1 -0
  124. package/src/web/radio/radio.tsx +290 -0
  125. package/src/web/selectbox/AI_GUIDE.md +216 -0
  126. package/src/web/selectbox/index.ts +3 -0
  127. package/src/web/selectbox/manifest.json +477 -0
  128. package/src/web/selectbox/selectbox.css +1 -0
  129. package/src/web/selectbox/selectbox.tsx +1048 -0
  130. package/src/web/sonner/AI_GUIDE.md +98 -0
  131. package/src/web/sonner/index.ts +114 -0
  132. package/src/web/sonner/manifest.json +132 -0
  133. package/src/web/sonner/sonner.css +1 -0
  134. package/src/web/sonner/sonner.tsx +177 -0
  135. package/src/web/table/AI_GUIDE.md +145 -0
  136. package/src/web/table/index.ts +35 -0
  137. package/src/web/table/manifest.json +168 -0
  138. package/src/web/table/table-body.tsx +45 -0
  139. package/src/web/table/table-caption.tsx +45 -0
  140. package/src/web/table/table-cell.tsx +74 -0
  141. package/src/web/table/table-empty.tsx +108 -0
  142. package/src/web/table/table-footer.tsx +45 -0
  143. package/src/web/table/table-head.tsx +80 -0
  144. package/src/web/table/table-header.tsx +45 -0
  145. package/src/web/table/table-row.tsx +69 -0
  146. package/src/web/table/table.css +1 -0
  147. package/src/web/table/table.tsx +305 -0
  148. package/src/web/tabs/AI_GUIDE.md +150 -0
  149. package/src/web/tabs/index.ts +3 -0
  150. package/src/web/tabs/manifest.json +315 -0
  151. package/src/web/tabs/tabs.css +1 -0
  152. package/src/web/tabs/tabs.tsx +332 -0
  153. package/src/web/text/AI_GUIDE.md +129 -0
  154. package/src/web/text/index.ts +3 -0
  155. package/src/web/text/manifest.json +195 -0
  156. package/src/web/text/text.css +1 -0
  157. package/src/web/text/text.tsx +689 -0
  158. package/src/web/textarea/AI_GUIDE.md +141 -0
  159. package/src/web/textarea/index.ts +3 -0
  160. package/src/web/textarea/manifest.json +438 -0
  161. package/src/web/textarea/textarea.css +1 -0
  162. package/src/web/textarea/textarea.tsx +467 -0
  163. package/src/web/tooltip/AI_GUIDE.md +110 -0
  164. package/src/web/tooltip/index.ts +3 -0
  165. package/src/web/tooltip/manifest.json +222 -0
  166. package/src/web/tooltip/tooltip.css +1 -0
  167. package/src/web/tooltip/tooltip.tsx +423 -0
  168. package/src/webview/bottomsheet/AI_GUIDE.md +141 -0
  169. package/src/webview/bottomsheet/bottomsheet.css +1 -0
  170. package/src/webview/bottomsheet/bottomsheet.tsx +603 -0
  171. package/src/webview/bottomsheet/index.ts +4 -0
  172. package/src/webview/bottomsheet/manifest.json +377 -0
  173. package/src/webview/button/AI_GUIDE.md +79 -0
  174. package/src/webview/button/button-ios.css +1 -0
  175. package/src/webview/button/button-ios.tsx +138 -0
  176. package/src/webview/button/button-material.css +1 -0
  177. package/src/webview/button/button-material.tsx +138 -0
  178. package/src/webview/button/index.ts +7 -0
  179. package/src/webview/button/manifest.json +148 -0
  180. package/src/webview/index.ts +7 -0
  181. package/tailwind-preset.cjs +62 -0
  182. package/tailwind-preset.js +62 -0
  183. package/ttdk-manifest.json +10188 -0
  184. package/README.md +0 -3
@@ -0,0 +1,1274 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ import { useState, useRef, useEffect } from "react";
4
+
5
+ export interface DropdownOption {
6
+ /**
7
+ * Teks label tampilan pilihan dropdown menu.
8
+ */
9
+ label: string;
10
+
11
+ /**
12
+ * Nilai unik (value) dari item dropdown.
13
+ */
14
+ value: string | number;
15
+
16
+ /**
17
+ * Status apakah opsi ini dinonaktifkan dari pemilihan.
18
+ * @default false
19
+ */
20
+ disabled?: boolean;
21
+
22
+ /**
23
+ * Ikon kustom di samping label item pilihan.
24
+ */
25
+ icon?: any;
26
+
27
+ /**
28
+ * Deskripsi atau teks bantuan kecil di bawah label item pilihan.
29
+ */
30
+ description?: string;
31
+
32
+ /**
33
+ * Menandai item sebagai aksi berbahaya/destruktif (misal: "Hapus"), ditampilkan dengan warna aksen merah.
34
+ * @default false
35
+ */
36
+ danger?: boolean;
37
+
38
+ /**
39
+ * Menampilkan garis pemisah horizontal (divider) di atas item ini.
40
+ * @default false
41
+ */
42
+ divider?: boolean;
43
+
44
+ /**
45
+ * Callback event saat item ini diklik.
46
+ */
47
+ onClick?: (option?: DropdownOption) => void;
48
+ }
49
+ export type DropdownMenuItem = DropdownOption;
50
+ export type DropdownUiProps = UiProps;
51
+ export interface DropdownProps {
52
+ /**
53
+ * Teks label judul field yang ditampilkan di atas dropdown (14px Semibold, #141313).
54
+ */
55
+ label?: string;
56
+
57
+ /**
58
+ * Menandai field sebagai opsi opsional dengan menambahkan teks '(Opsional)' (12px Regular, #9698A2).
59
+ * @default false
60
+ */
61
+ optional?: boolean;
62
+
63
+ /**
64
+ * Kustomisasi teks keterangan opsional.
65
+ * @default '(Opsional)'
66
+ */
67
+ optionalText?: string;
68
+
69
+ /**
70
+ * Teks petunjuk saat belum ada opsi yang dipilih.
71
+ * @default 'Pilih dropdown menu'
72
+ */
73
+ placeholder?: string;
74
+
75
+ /**
76
+ * Nilai terpilih saat ini (single string/number atau array nilai untuk mode multiple).
77
+ */
78
+ value?: any;
79
+
80
+ /**
81
+ * Nilai awal tidak terkontrol (uncontrolled initial value).
82
+ */
83
+ defaultValue?: any;
84
+
85
+ /**
86
+ * Daftar pilihan opsi dropdown menu. Dapat berupa array of object `{ label, value }` atau array of string.
87
+ */
88
+ options?: Array<DropdownOption | string>;
89
+
90
+ /**
91
+ * Mode pemilihan jamak (multi-select) dengan tampilan chips/tag dan daftar checkbox.
92
+ * @default false
93
+ */
94
+ multiple?: boolean;
95
+
96
+ /**
97
+ * Mengaktifkan kotak pencarian (search input) di dalam menu dropdown.
98
+ * @default false
99
+ */
100
+ searchable?: boolean;
101
+
102
+ /**
103
+ * Placeholder pada kotak pencarian di dalam dropdown.
104
+ * @default 'Cari'
105
+ */
106
+ searchPlaceholder?: string;
107
+
108
+ /**
109
+ * Teks tombol terapkan pada footer multi-select.
110
+ * @default 'Terapkan'
111
+ */
112
+ applyText?: string;
113
+
114
+ /**
115
+ * Teks tombol reset pada footer multi-select.
116
+ * @default 'Reset'
117
+ */
118
+ resetText?: string;
119
+
120
+ /**
121
+ * Nama form field HTML.
122
+ */
123
+ name?: string;
124
+
125
+ /**
126
+ * Identifier unik elemen dropdown.
127
+ */
128
+ id?: string;
129
+
130
+ /**
131
+ * Status apakah dropdown sedang dalam kondisi error / tidak valid.
132
+ * @default false
133
+ */
134
+ error?: boolean;
135
+
136
+ /**
137
+ * Pesan teks penjelasan kesalahan validasi di bawah field.
138
+ */
139
+ errorMessage?: string;
140
+
141
+ /**
142
+ * Teks petunjuk atau keterangan bantuan di bawah field (12px Regular, #3C4245).
143
+ */
144
+ helperText?: string;
145
+
146
+ /**
147
+ * Posisi teks helper
148
+ */
149
+ helperTextPosition?: "top" | "bottom";
150
+
151
+ /**
152
+ * Skala ukuran dropdown.
153
+ * - `'sm'`: 36px
154
+ * - `'md'`: 48px (standar desain)
155
+ * - `'lg'`: 56px
156
+ * @default 'md'
157
+ */
158
+ size?: "sm" | "md" | "lg";
159
+
160
+ /**
161
+ * Bentuk sudut kelengkungan dropdown.
162
+ * - `'none'`: 0px
163
+ * - `'sm'`: 4px
164
+ * - `'md'`: 8px (standar desain)
165
+ * - `'lg'`: 12px
166
+ * - `'full'`: 9999px (kapsul)
167
+ * @default 'md'
168
+ */
169
+ rounded?: "none" | "sm" | "md" | "lg" | "full";
170
+
171
+ /**
172
+ * Posisi penempatan panel menu dropdown popover terhadap elemen trigger.
173
+ * @default 'bottom-start'
174
+ */
175
+ placement?:
176
+ | "bottom-start"
177
+ | "bottom-end"
178
+ | "bottom"
179
+ | "top-start"
180
+ | "top-end"
181
+ | "top";
182
+
183
+ /**
184
+ * Menampilkan panah chevron indikator buka/tutup pada trigger.
185
+ * @default true
186
+ */
187
+ arrow?: boolean;
188
+
189
+ /**
190
+ * Ikon kustom di awal teks trigger (leading icon).
191
+ */
192
+ icon?: any;
193
+
194
+ /**
195
+ * Otomatis menutup menu popover setelah pengguna memilih opsi (pada single select).
196
+ * @default true
197
+ */
198
+ closeOnSelect?: boolean;
199
+
200
+ /**
201
+ * Menjadikan lebar field dropdown memenuhi kontainer penuh (full-width 100%).
202
+ * @default false
203
+ */
204
+ block?: boolean;
205
+
206
+ /**
207
+ * Status apakah dropdown dinonaktifkan (disabled).
208
+ * @default false
209
+ */
210
+ disabled?: boolean;
211
+
212
+ /**
213
+ * Menandai field sebagai input wajib diisi (menampilkan tanda bintang merah *).
214
+ * @default false
215
+ */
216
+ required?: boolean;
217
+
218
+ /**
219
+ * Ref instance elemen control dropdown untuk akses DOM langsung.
220
+ */
221
+ inputRef?: any;
222
+
223
+ /**
224
+ * Menampilkan tombol × untuk menghapus pilihan yang sudah dipilih.
225
+ * @default false
226
+ */
227
+ clearable?: boolean;
228
+
229
+ /**
230
+ * Menampilkan spinner loading dan menonaktifkan interaksi dropdown.
231
+ * @default false
232
+ */
233
+ loading?: boolean;
234
+
235
+ /**
236
+ * Menjadikan dropdown hanya-baca (tidak bisa dibuka/diubah).
237
+ * @default false
238
+ */
239
+ readOnly?: boolean;
240
+
241
+ /**
242
+ * Kustomisasi visual granular wrapper utama (UiProps).
243
+ */
244
+ ui?: DropdownUiProps;
245
+
246
+ /**
247
+ * Style inline native untuk wrapper luar.
248
+ */
249
+ style?: React.CSSProperties;
250
+
251
+ /**
252
+ * Style kustom untuk elemen label (UiProps).
253
+ */
254
+ labelStyle?: UiProps;
255
+
256
+ /**
257
+ * Class CSS kustom untuk elemen label (Tailwind / class kustom).
258
+ */
259
+ labelClass?: string;
260
+
261
+ /**
262
+ * Style kustom untuk elemen kotak pemicu (control trigger) (UiProps).
263
+ */
264
+ controlStyle?: UiProps;
265
+
266
+ /**
267
+ * Class CSS kustom untuk elemen kotak pemicu (control trigger) (Tailwind / class kustom).
268
+ */
269
+ controlClass?: string;
270
+
271
+ /**
272
+ * Style kustom untuk panel popover / menu list opsi (UiProps).
273
+ */
274
+ listStyle?: UiProps;
275
+
276
+ /**
277
+ * Class CSS kustom untuk panel popover / menu list opsi (Tailwind / class kustom).
278
+ */
279
+ listClass?: string;
280
+
281
+ /**
282
+ * Style kustom untuk pesan teks error validasi (UiProps).
283
+ */
284
+ errorMessageStyle?: UiProps;
285
+
286
+ /**
287
+ * Class CSS kustom untuk pesan teks error validasi (Tailwind / class kustom).
288
+ */
289
+ errorMessageClass?: string;
290
+
291
+ /**
292
+ * Style kustom untuk teks petunjuk bantuan (UiProps).
293
+ */
294
+ helperTextStyle?: UiProps;
295
+
296
+ /**
297
+ * Class CSS kustom untuk teks petunjuk bantuan (Tailwind / class kustom).
298
+ */
299
+ helperTextClass?: string;
300
+
301
+ /**
302
+ * Callback event saat nilai pilihan berubah.
303
+ */
304
+ onChange?: (value: any) => void;
305
+
306
+ /**
307
+ * Callback event saat sebuah opsi dipilih dari menu.
308
+ */
309
+ onSelect?: (option: DropdownOption) => void;
310
+
311
+ /**
312
+ * Callback event saat pengguna mengetik di kolom pencarian.
313
+ */
314
+ onSearch?: (query: string) => void;
315
+
316
+ /**
317
+ * Callback event saat menu dropdown terbuka.
318
+ */
319
+ onOpen?: () => void;
320
+
321
+ /**
322
+ * Callback event saat menu dropdown ditutup.
323
+ */
324
+ onClose?: () => void;
325
+
326
+ /**
327
+ * Menonaktifkan middleware `shift` pada floating-ui sehingga posisi list popover
328
+ * tidak bergeser secara horizontal mengikuti tepi layar.
329
+ * Berguna saat ingin list tetap berada di tengah atau posisi placement yang ditentukan.
330
+ * @default false
331
+ */
332
+ disableShift?: boolean;
333
+
334
+ /**
335
+ * Class CSS kustom wrapper luar.
336
+ */
337
+ className?: string;
338
+
339
+ /**
340
+ * Elemen pemicu (trigger) kustom, tombol, ikon, atau komponen anak lainnya.
341
+ */
342
+ children?: any;
343
+
344
+ /**
345
+ * Konten kustom yang ditampilkan di dalam panel popover menggantikan list opsi standar.
346
+ * Berguna untuk menampilkan komponen seperti Calendar, Color Picker, dsb. di dalam Dropdown.
347
+ * Ketika prop ini di-set, `options` tidak akan dirender.
348
+ * Menerima ReactNode atau render function `({ close }) => ReactNode`.
349
+ */
350
+ panelContent?: any;
351
+
352
+ /**
353
+ * Label atau teks kustom untuk ditampilkan pada trigger dropdown.
354
+ * Sangat berguna saat menggunakan `panelContent` seperti Date Picker di mana nilai trigger diformat secara kustom.
355
+ */
356
+ displayValue?: string;
357
+
358
+ /**
359
+ * Strategi positioning Floating UI ('fixed' atau 'absolute').
360
+ * Default 'fixed' agar dropdown tidak terpotong (clipped) oleh kontainer parent yang memiliki `overflow: hidden`.
361
+ * @default 'fixed'
362
+ */
363
+ // strategy?: 'fixed' | 'absolute';
364
+ }
365
+ export type DropdownMenuProps = DropdownProps;
366
+
367
+ /**
368
+ * Komponen Dropdown Menu TTDK sesuai spesifikasi Desain:
369
+ * - Selaras UI & Props dengan Selectbox: Label, Helper/Error text, Search bar, Floating popover
370
+ * - Mode Single Select / Menu Actions dengan Active Teal Checkmark (#00A3A6)
371
+ * - Mode Multi-Select dengan Checkbox list, Chip tags (Label ✕), dan Action footer (Reset & Terapkan)
372
+ * - Varian trigger fleksibel: 'select' (standar form), 'action' / 'primary' (tombol aksi), 'outline', 'ghost'
373
+ * - Dukungan Trigger Kustom melalui Slot / Children (misal: tombol kustom)
374
+ * - Dukungan item kaya: Icon, Deskripsi, Divider pemisah seksi, dan Danger item
375
+ */
376
+
377
+ import {
378
+ computePosition,
379
+ autoUpdate,
380
+ flip,
381
+ shift,
382
+ offset,
383
+ size as floatingSize,
384
+ } from "@floating-ui/dom";
385
+ import { buildUiVars, UiProps } from "../../core/types";
386
+
387
+ function Dropdown(props: DropdownProps) {
388
+ const rootRef = useRef<HTMLDivElement>(null);
389
+ const controlRef = useRef<HTMLDivElement>(null);
390
+ const dropdownRef = useRef<HTMLDivElement>(null);
391
+ const [isOpen, setIsOpen] = useState(() => false);
392
+
393
+ const [searchQuery, setSearchQuery] = useState(() => "");
394
+
395
+ const [currentValue, setCurrentValue] = useState(() =>
396
+ props.value !== undefined
397
+ ? props.value
398
+ : props.defaultValue !== undefined
399
+ ? props.defaultValue
400
+ : props.multiple
401
+ ? []
402
+ : ""
403
+ );
404
+
405
+ const [tempMultiValue, setTempMultiValue] = useState<any[]>(() => []);
406
+
407
+ const cleanupAutoUpdateRef = useRef<any>(null);
408
+
409
+ function updatePosition() {
410
+ if (!controlRef.current || !dropdownRef.current) return;
411
+ dropdownRef.current.style.maxHeight = "";
412
+ computePosition(controlRef.current, dropdownRef.current, {
413
+ placement: props.placement || "bottom-start",
414
+ strategy: "absolute",
415
+ middleware: [
416
+ offset(4),
417
+ flip({
418
+ fallbackPlacements: [
419
+ "top-start",
420
+ "top-end",
421
+ "bottom-start",
422
+ "bottom-end",
423
+ ],
424
+ padding: {
425
+ top: 16,
426
+ bottom: 16,
427
+ left: 16,
428
+ right: 16,
429
+ },
430
+ }),
431
+ ...(props.disableShift
432
+ ? []
433
+ : [
434
+ shift({
435
+ padding: {
436
+ top: 16,
437
+ bottom: 16,
438
+ left: 16,
439
+ right: 16,
440
+ },
441
+ }),
442
+ ]),
443
+ floatingSize({
444
+ apply({ rects, elements, availableHeight }) {
445
+ const isPanel = Boolean(props.panelContent);
446
+ const customWidth =
447
+ props.listStyle?.width !== undefined &&
448
+ props.listStyle?.width !== null &&
449
+ props.listStyle?.width !== ""
450
+ ? typeof props.listStyle.width === "number" ||
451
+ /^\d+(\.\d+)?$/.test(String(props.listStyle.width).trim())
452
+ ? `${String(props.listStyle.width).trim()}px`
453
+ : String(props.listStyle.width)
454
+ : undefined;
455
+ const customMaxHeight =
456
+ props.listStyle?.maxHeight !== undefined &&
457
+ props.listStyle?.maxHeight !== null &&
458
+ props.listStyle?.maxHeight !== ""
459
+ ? props.listStyle.maxHeight === "none"
460
+ ? "none"
461
+ : typeof props.listStyle.maxHeight === "number" ||
462
+ /^\d+(\.\d+)?$/.test(
463
+ String(props.listStyle.maxHeight).trim()
464
+ )
465
+ ? `${String(props.listStyle.maxHeight).trim()}px`
466
+ : String(props.listStyle.maxHeight)
467
+ : undefined;
468
+ Object.assign(elements.floating.style, {
469
+ width:
470
+ customWidth ||
471
+ (isPanel ? "auto" : `${rects.reference.width}px`),
472
+ minWidth: customWidth
473
+ ? customWidth
474
+ : isPanel
475
+ ? "auto"
476
+ : undefined,
477
+ maxHeight:
478
+ customMaxHeight !== undefined
479
+ ? customMaxHeight
480
+ : isPanel
481
+ ? "none"
482
+ : `${Math.max(180, Math.min(availableHeight, 360))}px`,
483
+ });
484
+ },
485
+ padding: {
486
+ top: 16,
487
+ bottom: 16,
488
+ left: 16,
489
+ right: 16,
490
+ },
491
+ }),
492
+ ],
493
+ }).then(({ x, y, placement }: any) => {
494
+ if (!dropdownRef.current) return;
495
+ dropdownRef.current.style.position = "absolute";
496
+ dropdownRef.current.style.left = `${x}px`;
497
+ dropdownRef.current.style.top = `${y}px`;
498
+ dropdownRef.current.setAttribute("data-placement", placement);
499
+ });
500
+ }
501
+
502
+ function startFloating() {
503
+ stopFloating();
504
+ if (controlRef.current && dropdownRef.current) {
505
+ cleanupAutoUpdateRef.current = autoUpdate(
506
+ controlRef.current,
507
+ dropdownRef.current,
508
+ () => {
509
+ updatePosition();
510
+ }
511
+ );
512
+ }
513
+ }
514
+
515
+ function stopFloating() {
516
+ if (typeof cleanupAutoUpdateRef.current === "function") {
517
+ cleanupAutoUpdateRef.current();
518
+ cleanupAutoUpdateRef.current = null;
519
+ }
520
+ }
521
+
522
+ function handleClickOutside(event: any) {
523
+ if (!dropdownRef.current) return;
524
+ const target = event.target;
525
+ if (
526
+ rootRef.current &&
527
+ !rootRef.current.contains(target) &&
528
+ dropdownRef.current &&
529
+ !dropdownRef.current.contains(target)
530
+ ) {
531
+ closeDropdown();
532
+ }
533
+ }
534
+
535
+ function onPointerDown(event: any) {
536
+ handleClickOutside(event);
537
+ }
538
+
539
+ function toggleDropdown() {
540
+ if (props.disabled || props.readOnly || props.loading) return;
541
+ const nextOpen = !isOpen;
542
+ setIsOpen(nextOpen);
543
+ if (nextOpen) {
544
+ if (props.multiple) {
545
+ setTempMultiValue(Array.isArray(currentValue) ? [...currentValue] : []);
546
+ }
547
+ if (props.onOpen) props.onOpen();
548
+ } else {
549
+ setSearchQuery("");
550
+ if (props.onClose) props.onClose();
551
+ }
552
+ }
553
+
554
+ function closeDropdown() {
555
+ stopFloating();
556
+ setIsOpen(false);
557
+ setSearchQuery("");
558
+ if (props.onClose) props.onClose();
559
+ }
560
+
561
+ function normalizedOptions() {
562
+ const raw = props.options;
563
+ if (!raw || !Array.isArray(raw)) return [];
564
+ return raw.map((opt: any) => {
565
+ if (typeof opt === "object" && opt !== null) {
566
+ return {
567
+ label: String(opt.label ?? opt.value ?? ""),
568
+ value: opt.value ?? opt.label ?? "",
569
+ disabled: Boolean(opt.disabled),
570
+ icon: opt.icon,
571
+ description: opt.description,
572
+ danger: Boolean(opt.danger),
573
+ divider: Boolean(opt.divider),
574
+ onClick: opt.onClick,
575
+ };
576
+ }
577
+ return {
578
+ label: String(opt),
579
+ value: opt,
580
+ disabled: false,
581
+ icon: undefined,
582
+ description: undefined,
583
+ danger: false,
584
+ divider: false,
585
+ onClick: undefined,
586
+ };
587
+ });
588
+ }
589
+
590
+ function filteredOptions() {
591
+ const opts = normalizedOptions();
592
+ if (!searchQuery || !searchQuery.trim()) return opts;
593
+ const q = searchQuery.toLowerCase().trim();
594
+ return opts.filter((opt: any) => {
595
+ const matchLabel = opt.label && opt.label.toLowerCase().includes(q);
596
+ const matchDesc =
597
+ opt.description && opt.description.toLowerCase().includes(q);
598
+ return matchLabel || matchDesc;
599
+ });
600
+ }
601
+
602
+ function isOptionSelected(optValue: any) {
603
+ if (props.multiple) {
604
+ const list = isOpen
605
+ ? tempMultiValue
606
+ : Array.isArray(currentValue)
607
+ ? currentValue
608
+ : [];
609
+ return list.some((v: any) => String(v) === String(optValue));
610
+ }
611
+ return String(currentValue) === String(optValue);
612
+ }
613
+
614
+ function handleSingleSelect(opt: any) {
615
+ if (opt.disabled || props.disabled) return;
616
+ if (opt.onClick) {
617
+ opt.onClick(opt);
618
+ }
619
+ setCurrentValue(opt.value);
620
+ if (props.onSelect) {
621
+ props.onSelect(opt);
622
+ }
623
+ if (props.onChange) {
624
+ props.onChange(opt.value);
625
+ }
626
+ if (props.closeOnSelect !== false) {
627
+ closeDropdown();
628
+ }
629
+ }
630
+
631
+ function handleMultiToggle(opt: any) {
632
+ if (opt.disabled || props.disabled) return;
633
+ if (opt.onClick) {
634
+ opt.onClick(opt);
635
+ }
636
+ const index = tempMultiValue.findIndex(
637
+ (v: any) => String(v) === String(opt.value)
638
+ );
639
+ if (index > -1) {
640
+ const next = [...tempMultiValue];
641
+ next.splice(index, 1);
642
+ setTempMultiValue(next);
643
+ } else {
644
+ setTempMultiValue([...tempMultiValue, opt.value]);
645
+ }
646
+ }
647
+
648
+ function handleRemoveTag(val: any, event: any) {
649
+ if (event && event.stopPropagation) event.stopPropagation();
650
+ if (props.disabled) return;
651
+ if (Array.isArray(currentValue)) {
652
+ const next = currentValue.filter((v: any) => String(v) !== String(val));
653
+ setCurrentValue(next);
654
+ setTempMultiValue([...next]);
655
+ if (props.onChange) {
656
+ props.onChange(next);
657
+ }
658
+ }
659
+ }
660
+
661
+ function handleApply() {
662
+ setCurrentValue([...tempMultiValue]);
663
+ if (props.onChange) {
664
+ props.onChange([...tempMultiValue]);
665
+ }
666
+ closeDropdown();
667
+ }
668
+
669
+ function handleReset() {
670
+ setTempMultiValue([]);
671
+ setCurrentValue([]);
672
+ if (props.onChange) {
673
+ props.onChange([]);
674
+ }
675
+ }
676
+
677
+ function handleSearchInput(e: any) {
678
+ setSearchQuery(e.target.value);
679
+ if (props.onSearch) {
680
+ props.onSearch(e.target.value);
681
+ }
682
+ }
683
+
684
+ function getSingleSelectedLabel() {
685
+ if (
686
+ props.displayValue !== undefined &&
687
+ props.displayValue !== null &&
688
+ props.displayValue !== ""
689
+ ) {
690
+ return props.displayValue;
691
+ }
692
+ const opts = normalizedOptions();
693
+ const match = opts.find(
694
+ (opt: any) => String(opt.value) === String(currentValue)
695
+ );
696
+ if (match) {
697
+ return match.label;
698
+ }
699
+ if (
700
+ currentValue !== undefined &&
701
+ currentValue !== null &&
702
+ currentValue !== ""
703
+ ) {
704
+ return String(currentValue);
705
+ }
706
+ return "";
707
+ }
708
+
709
+ function getMultiSelectedChips() {
710
+ const list = Array.isArray(currentValue) ? currentValue : [];
711
+ const opts = normalizedOptions();
712
+ return list.map((val: any) => {
713
+ const match = opts.find((o: any) => String(o.value) === String(val));
714
+ return {
715
+ value: val,
716
+ label: match ? match.label : String(val),
717
+ };
718
+ });
719
+ }
720
+
721
+ function hasValue() {
722
+ if (
723
+ props.displayValue !== undefined &&
724
+ props.displayValue !== null &&
725
+ props.displayValue !== ""
726
+ ) {
727
+ return true;
728
+ }
729
+ if (props.multiple) {
730
+ return Array.isArray(currentValue) && currentValue.length > 0;
731
+ }
732
+ return (
733
+ currentValue !== undefined && currentValue !== "" && currentValue !== null
734
+ );
735
+ }
736
+
737
+ function handleClear(event: any) {
738
+ if (event && event.stopPropagation) event.stopPropagation();
739
+ if (props.disabled || props.readOnly) return;
740
+ const emptyVal = props.multiple ? [] : "";
741
+ setCurrentValue(emptyVal);
742
+ setTempMultiValue([]);
743
+ if (props.onChange) {
744
+ props.onChange(emptyVal);
745
+ }
746
+ }
747
+
748
+ useEffect(() => {
749
+ if (props.value !== undefined) {
750
+ setCurrentValue(props.value);
751
+ }
752
+ }, [props.value]);
753
+
754
+ useEffect(() => {
755
+ if (isOpen) {
756
+ startFloating();
757
+
758
+ const handlePointerDown = (event: any) => {
759
+ const target = event.target;
760
+ if (
761
+ rootRef.current &&
762
+ !rootRef.current.contains(target) &&
763
+ dropdownRef.current &&
764
+ !dropdownRef.current.contains(target)
765
+ ) {
766
+ closeDropdown();
767
+ }
768
+ };
769
+
770
+ document.addEventListener("pointerdown", handlePointerDown, true);
771
+
772
+ return () => {
773
+ stopFloating();
774
+ document.removeEventListener("pointerdown", handlePointerDown, true);
775
+ };
776
+ } else {
777
+ stopFloating();
778
+ }
779
+ }, [isOpen]);
780
+
781
+ return (
782
+ <div
783
+ ref={rootRef}
784
+ className={`ttdk-dropdown-wrapper ${props.className || ""}`.trim()}
785
+ data-disabled={props.disabled}
786
+ data-error={Boolean(props.error || props.errorMessage)}
787
+ data-size={props.size || "md"}
788
+ data-block={props.block ? "true" : undefined}
789
+ style={{
790
+ ...buildUiVars(props.ui),
791
+ ...((props.ui as any) || {}),
792
+ ...((props as any)["style"] || {}),
793
+ ...props.style,
794
+ }}
795
+ >
796
+ {props.label ? (
797
+ <label
798
+ className={`ttdk-dropdown-label ${props.labelClass || ""}`.trim()}
799
+ htmlFor={props.id}
800
+ style={{
801
+ ...buildUiVars(props.labelStyle),
802
+ }}
803
+ >
804
+ <span>{props.label}</span>
805
+ {props.required ? (
806
+ <span className="ttdk-dropdown-required" aria-hidden="true">
807
+ *
808
+ </span>
809
+ ) : null}
810
+ {props.optional ? (
811
+ <span className="ttdk-dropdown-optional">
812
+ {props.optionalText || "(Opsional)"}
813
+ </span>
814
+ ) : null}
815
+ </label>
816
+ ) : null}
817
+ {props.helperText && props.helperTextPosition === "top" ? (
818
+ <div
819
+ className={`ttdk-dropdown-helper-text ${
820
+ props.helperTextClass || ""
821
+ }`.trim()}
822
+ style={{
823
+ ...buildUiVars(props.helperTextStyle),
824
+ }}
825
+ >
826
+ {props.helperText}
827
+ </div>
828
+ ) : null}
829
+ <div
830
+ role="button"
831
+ aria-haspopup="menu"
832
+ ref={controlRef}
833
+ className={`ttdk-dropdown-control ${props.controlClass || ""}`.trim()}
834
+ id={props.id}
835
+ tabIndex={props.disabled ? -1 : 0}
836
+ aria-expanded={isOpen}
837
+ aria-disabled={props.disabled}
838
+ aria-invalid={Boolean(props.error || props.errorMessage)}
839
+ data-open={isOpen ? "true" : "false"}
840
+ data-filled={hasValue() ? "true" : "false"}
841
+ data-error={Boolean(props.error || props.errorMessage)}
842
+ data-disabled={Boolean(props.disabled)}
843
+ data-size={props.size || "md"}
844
+ data-rounded={props.rounded || "md"}
845
+ data-custom-trigger={props.children ? "true" : undefined}
846
+ style={{
847
+ ...buildUiVars(props.controlStyle),
848
+ }}
849
+ onClick={(event) => toggleDropdown()}
850
+ onKeyDown={(e) => {
851
+ if (e.key === "Enter" || e.key === " ") {
852
+ e.preventDefault();
853
+ toggleDropdown();
854
+ } else if (e.key === "Escape") {
855
+ closeDropdown();
856
+ }
857
+ }}
858
+ >
859
+ {props.children ? <>{props.children}</> : null}
860
+ {!props.children ? (
861
+ <>
862
+ <div className="ttdk-dropdown-display">
863
+ {props.icon ? (
864
+ <span className="ttdk-dropdown-leading-icon" aria-hidden="true">
865
+ {props.icon}
866
+ </span>
867
+ ) : null}
868
+ {props.multiple && hasValue() ? (
869
+ <div className="ttdk-dropdown-chips">
870
+ {getMultiSelectedChips()?.map((chip) => (
871
+ <span className="ttdk-dropdown-chip" key={chip.value}>
872
+ <span className="ttdk-dropdown-chip-text">
873
+ {chip.label}
874
+ </span>
875
+ <button
876
+ type="button"
877
+ className="ttdk-dropdown-chip-remove"
878
+ aria-label={`Hapus ${chip.label}`}
879
+ onClick={(e) => handleRemoveTag(chip.value, e)}
880
+ >
881
+ <svg
882
+ className="ttdk-dropdown-chip-remove-icon"
883
+ viewBox="0 0 24 24"
884
+ fill="none"
885
+ >
886
+ <line x1="18" y1="6" x2="6" y2="18" />
887
+ <line x1="6" y1="6" x2="18" y2="18" />
888
+ </svg>
889
+ </button>
890
+ </span>
891
+ ))}
892
+ </div>
893
+ ) : null}
894
+ {!props.multiple && hasValue() ? (
895
+ <span className="ttdk-dropdown-value">
896
+ {getSingleSelectedLabel()}
897
+ </span>
898
+ ) : null}
899
+ {!hasValue() ? (
900
+ <span className="ttdk-dropdown-placeholder">
901
+ {props.placeholder || "Pilih dropdown menu"}
902
+ </span>
903
+ ) : null}
904
+ </div>
905
+ {props.clearable &&
906
+ hasValue() &&
907
+ !props.disabled &&
908
+ !props.readOnly &&
909
+ !props.loading ? (
910
+ <button
911
+ type="button"
912
+ className="ttdk-dropdown-clear"
913
+ aria-label="Hapus pilihan"
914
+ onClick={(e) => handleClear(e)}
915
+ >
916
+ <svg
917
+ className="ttdk-dropdown-clear-icon"
918
+ viewBox="0 0 24 24"
919
+ fill="none"
920
+ >
921
+ <line x1="18" y1="6" x2="6" y2="18" />
922
+ <line x1="6" y1="6" x2="18" y2="18" />
923
+ </svg>
924
+ </button>
925
+ ) : null}
926
+ {props.loading ? (
927
+ <span className="ttdk-dropdown-spinner" aria-hidden="true">
928
+ <svg
929
+ className="ttdk-dropdown-spinner-icon"
930
+ viewBox="0 0 24 24"
931
+ fill="none"
932
+ >
933
+ <line
934
+ x1="12"
935
+ y1="2.5"
936
+ x2="12"
937
+ y2="6.5"
938
+ opacity="0.175"
939
+ transform="rotate(0 12 12)"
940
+ />
941
+ <line
942
+ x1="12"
943
+ y1="2.5"
944
+ x2="12"
945
+ y2="6.5"
946
+ opacity="0.25"
947
+ transform="rotate(30 12 12)"
948
+ />
949
+ <line
950
+ x1="12"
951
+ y1="2.5"
952
+ x2="12"
953
+ y2="6.5"
954
+ opacity="0.325"
955
+ transform="rotate(60 12 12)"
956
+ />
957
+ <line
958
+ x1="12"
959
+ y1="2.5"
960
+ x2="12"
961
+ y2="6.5"
962
+ opacity="0.4"
963
+ transform="rotate(90 12 12)"
964
+ />
965
+ <line
966
+ x1="12"
967
+ y1="2.5"
968
+ x2="12"
969
+ y2="6.5"
970
+ opacity="0.475"
971
+ transform="rotate(120 12 12)"
972
+ />
973
+ <line
974
+ x1="12"
975
+ y1="2.5"
976
+ x2="12"
977
+ y2="6.5"
978
+ opacity="0.55"
979
+ transform="rotate(150 12 12)"
980
+ />
981
+ <line
982
+ x1="12"
983
+ y1="2.5"
984
+ x2="12"
985
+ y2="6.5"
986
+ opacity="0.625"
987
+ transform="rotate(180 12 12)"
988
+ />
989
+ <line
990
+ x1="12"
991
+ y1="2.5"
992
+ x2="12"
993
+ y2="6.5"
994
+ opacity="0.7"
995
+ transform="rotate(210 12 12)"
996
+ />
997
+ <line
998
+ x1="12"
999
+ y1="2.5"
1000
+ x2="12"
1001
+ y2="6.5"
1002
+ opacity="0.775"
1003
+ transform="rotate(240 12 12)"
1004
+ />
1005
+ <line
1006
+ x1="12"
1007
+ y1="2.5"
1008
+ x2="12"
1009
+ y2="6.5"
1010
+ opacity="0.85"
1011
+ transform="rotate(270 12 12)"
1012
+ />
1013
+ <line
1014
+ x1="12"
1015
+ y1="2.5"
1016
+ x2="12"
1017
+ y2="6.5"
1018
+ opacity="0.925"
1019
+ transform="rotate(300 12 12)"
1020
+ />
1021
+ <line
1022
+ x1="12"
1023
+ y1="2.5"
1024
+ x2="12"
1025
+ y2="6.5"
1026
+ opacity="1"
1027
+ transform="rotate(330 12 12)"
1028
+ />
1029
+ </svg>
1030
+ </span>
1031
+ ) : null}
1032
+ {!props.loading && props.arrow !== false ? (
1033
+ <span
1034
+ className="ttdk-dropdown-arrow"
1035
+ data-open={isOpen ? "true" : "false"}
1036
+ >
1037
+ <svg
1038
+ className="ttdk-dropdown-arrow-icon"
1039
+ viewBox="0 0 24 24"
1040
+ fill="none"
1041
+ >
1042
+ <polyline points="6 9 12 15 18 9" />
1043
+ </svg>
1044
+ </span>
1045
+ ) : null}
1046
+ </>
1047
+ ) : null}
1048
+ </div>
1049
+ {isOpen && !props.disabled ? (
1050
+ <div
1051
+ className="ttdk-dropdown-menu"
1052
+ role="menu"
1053
+ ref={dropdownRef}
1054
+ style={{
1055
+ ...buildUiVars(props.listStyle),
1056
+ ...(props.listStyle?.width !== undefined &&
1057
+ props.listStyle?.width !== null &&
1058
+ props.listStyle?.width !== ""
1059
+ ? {
1060
+ width:
1061
+ typeof props.listStyle.width === "number" ||
1062
+ /^\d+(\.\d+)?$/.test(String(props.listStyle.width).trim())
1063
+ ? `${String(props.listStyle.width).trim()}px`
1064
+ : String(props.listStyle.width),
1065
+ minWidth:
1066
+ typeof props.listStyle.width === "number" ||
1067
+ /^\d+(\.\d+)?$/.test(String(props.listStyle.width).trim())
1068
+ ? `${String(props.listStyle.width).trim()}px`
1069
+ : String(props.listStyle.width),
1070
+ }
1071
+ : {}),
1072
+ }}
1073
+ >
1074
+ {props.searchable ? (
1075
+ <div
1076
+ className="ttdk-dropdown-search"
1077
+ onClick={(e) => e.stopPropagation()}
1078
+ >
1079
+ <input
1080
+ type="text"
1081
+ className="ttdk-dropdown-search-input"
1082
+ placeholder={props.searchPlaceholder || "Cari"}
1083
+ value={searchQuery}
1084
+ onInput={(e) => handleSearchInput(e)}
1085
+ autoFocus
1086
+ />
1087
+ <span className="ttdk-dropdown-search-icon" aria-hidden="true">
1088
+ <svg
1089
+ className="ttdk-dropdown-search-svg"
1090
+ viewBox="0 0 24 24"
1091
+ fill="none"
1092
+ >
1093
+ <circle cx="11" cy="11" r="8" />
1094
+ <line x1="21" y1="21" x2="16.65" y2="16.65" />
1095
+ </svg>
1096
+ </span>
1097
+ </div>
1098
+ ) : null}
1099
+ {props.panelContent ? (
1100
+ <div
1101
+ className="ttdk-dropdown-panel-content"
1102
+ onClick={(e) => e.stopPropagation()}
1103
+ >
1104
+ {typeof props.panelContent === "function" ? (
1105
+ <>
1106
+ {props.panelContent({
1107
+ close: () => closeDropdown(),
1108
+ })}
1109
+ </>
1110
+ ) : (
1111
+ <>{props.panelContent}</>
1112
+ )}
1113
+ </div>
1114
+ ) : null}
1115
+ {!props.panelContent ? (
1116
+ <div className="ttdk-dropdown-options-list" role="presentation">
1117
+ {filteredOptions()?.map((opt) => (
1118
+ <div key={opt.value}>
1119
+ {opt.divider ? (
1120
+ <div className="ttdk-dropdown-divider" role="separator" />
1121
+ ) : null}
1122
+ <div
1123
+ className={`ttdk-dropdown-option ${
1124
+ props.listClass || ""
1125
+ }`.trim()}
1126
+ role={props.multiple ? "menuitemcheckbox" : "menuitem"}
1127
+ aria-selected={isOptionSelected(opt.value)}
1128
+ aria-disabled={opt.disabled}
1129
+ data-selected={
1130
+ isOptionSelected(opt.value) ? "true" : "false"
1131
+ }
1132
+ data-disabled={opt.disabled ? "true" : "false"}
1133
+ data-danger={opt.danger ? "true" : undefined}
1134
+ onClick={(e) => {
1135
+ e.stopPropagation();
1136
+ if (props.multiple) {
1137
+ handleMultiToggle(opt);
1138
+ } else {
1139
+ handleSingleSelect(opt);
1140
+ }
1141
+ }}
1142
+ >
1143
+ {props.multiple ? (
1144
+ <span
1145
+ className="ttdk-dropdown-checkbox"
1146
+ data-checked={
1147
+ isOptionSelected(opt.value) ? "true" : "false"
1148
+ }
1149
+ >
1150
+ {isOptionSelected(opt.value) ? (
1151
+ <svg
1152
+ className="ttdk-dropdown-checkbox-icon"
1153
+ viewBox="0 0 24 24"
1154
+ fill="none"
1155
+ >
1156
+ <polyline points="20 6 9 17 4 12" />
1157
+ </svg>
1158
+ ) : null}
1159
+ </span>
1160
+ ) : null}
1161
+ {opt.icon ? (
1162
+ <span
1163
+ className="ttdk-dropdown-option-icon"
1164
+ aria-hidden="true"
1165
+ >
1166
+ {opt.icon}
1167
+ </span>
1168
+ ) : null}
1169
+ <div className="ttdk-dropdown-option-content">
1170
+ <span className="ttdk-dropdown-option-label">
1171
+ {opt.label}
1172
+ </span>
1173
+ {opt.description ? (
1174
+ <span className="ttdk-dropdown-option-desc">
1175
+ {opt.description}
1176
+ </span>
1177
+ ) : null}
1178
+ </div>
1179
+ {!props.multiple && isOptionSelected(opt.value) ? (
1180
+ <span
1181
+ className="ttdk-dropdown-check-icon"
1182
+ aria-hidden="true"
1183
+ >
1184
+ <svg
1185
+ className="ttdk-dropdown-check-svg"
1186
+ viewBox="0 0 24 24"
1187
+ fill="none"
1188
+ >
1189
+ <polyline points="20 6 9 17 4 12" />
1190
+ </svg>
1191
+ </span>
1192
+ ) : null}
1193
+ </div>
1194
+ </div>
1195
+ ))}
1196
+ {filteredOptions().length === 0 ? (
1197
+ <div className="ttdk-dropdown-empty">
1198
+ Tidak ada pilihan ditemukan
1199
+ </div>
1200
+ ) : null}
1201
+ </div>
1202
+ ) : null}
1203
+ {props.multiple ? (
1204
+ <div
1205
+ className="ttdk-dropdown-actions"
1206
+ onClick={(e) => e.stopPropagation()}
1207
+ >
1208
+ <button
1209
+ type="button"
1210
+ className="ttdk-dropdown-btn-reset"
1211
+ onClick={(event) => handleReset()}
1212
+ >
1213
+ <svg
1214
+ className="ttdk-dropdown-btn-reset-icon"
1215
+ viewBox="0 0 24 24"
1216
+ fill="none"
1217
+ >
1218
+ <path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" />
1219
+ <path d="M3 3v5h5" />
1220
+ </svg>
1221
+ <span>{props.resetText || "Reset"}</span>
1222
+ </button>
1223
+ <button
1224
+ type="button"
1225
+ className="ttdk-dropdown-btn-apply"
1226
+ onClick={(event) => handleApply()}
1227
+ >
1228
+ <span>{props.applyText || "Terapkan"}</span>
1229
+ <svg
1230
+ className="ttdk-dropdown-btn-apply-icon"
1231
+ viewBox="0 0 24 24"
1232
+ fill="none"
1233
+ >
1234
+ <polyline points="20 6 9 17 4 12" />
1235
+ </svg>
1236
+ </button>
1237
+ </div>
1238
+ ) : null}
1239
+ </div>
1240
+ ) : null}
1241
+ {props.helperText && props.helperTextPosition !== "top" ? (
1242
+ <div
1243
+ className={`ttdk-dropdown-helper-text ${
1244
+ props.helperTextClass || ""
1245
+ }`.trim()}
1246
+ style={{
1247
+ ...buildUiVars(props.helperTextStyle),
1248
+ }}
1249
+ >
1250
+ {props.helperText}
1251
+ </div>
1252
+ ) : null}
1253
+ {props.errorMessage ||
1254
+ (typeof props.error === "string" && props.error) ? (
1255
+ <div
1256
+ role="alert"
1257
+ className={`ttdk-dropdown-error-text ${
1258
+ props.errorMessageClass || ""
1259
+ }`.trim()}
1260
+ style={{
1261
+ ...buildUiVars(props.errorMessageStyle),
1262
+ }}
1263
+ >
1264
+ {props.errorMessage ||
1265
+ (typeof props.error === "string" ? props.error : "")}
1266
+ </div>
1267
+ ) : null}
1268
+ </div>
1269
+ );
1270
+ }
1271
+
1272
+ export default Dropdown;
1273
+
1274
+ export { Dropdown };