@herca/rn-kit 0.1.6 → 0.1.8

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 (61) hide show
  1. package/README.md +29 -3
  2. package/lib/module/Accordion/README.md +1 -0
  3. package/lib/module/Alert/README.md +1 -0
  4. package/lib/module/Avatar/README_AVATAR.md +1 -1
  5. package/lib/module/Avatar/README_AVATARGROUP.md +3 -1
  6. package/lib/module/BottomSheet/README.md +1 -1
  7. package/lib/module/Button/README.md +3 -1
  8. package/lib/module/Calendar/README.md +1 -0
  9. package/lib/module/Chip/README.md +2 -1
  10. package/lib/module/Color/README.md +97 -46
  11. package/lib/module/DatePicker/{README.md → README_DATEPICKER.md} +1 -0
  12. package/lib/module/DatePicker/README_MONTHPICKER.md +90 -0
  13. package/lib/module/DatePicker/README_TIMEPICKER.md +83 -0
  14. package/lib/module/DatePicker/README_YEARPICKER.md +106 -0
  15. package/lib/module/DropDown/DropDown.js +49 -45
  16. package/lib/module/DropDown/DropDown.js.map +1 -1
  17. package/lib/module/DropDown/README.md +108 -0
  18. package/lib/module/Label/README.md +65 -0
  19. package/lib/module/Provider/Provider.js +2 -0
  20. package/lib/module/Provider/Provider.js.map +1 -1
  21. package/lib/module/RadioButton/README.md +2 -1
  22. package/lib/module/Timeline/Timeline.js +7 -1
  23. package/lib/module/Timeline/Timeline.js.map +1 -1
  24. package/lib/module/Timeline/TimelineItem.js +15 -5
  25. package/lib/module/Timeline/TimelineItem.js.map +1 -1
  26. package/lib/module/Ui/README_DEVIDER.md +62 -0
  27. package/lib/module/Ui/README_FOOTER.md +0 -0
  28. package/lib/typescript/src/DropDown/DropDown.d.ts.map +1 -1
  29. package/lib/typescript/src/DropDown/type.d.ts +1 -1
  30. package/lib/typescript/src/DropDown/type.d.ts.map +1 -1
  31. package/lib/typescript/src/Provider/Provider.d.ts +2 -2
  32. package/lib/typescript/src/Provider/Provider.d.ts.map +1 -1
  33. package/lib/typescript/src/Provider/type.d.ts +2 -2
  34. package/lib/typescript/src/Provider/type.d.ts.map +1 -1
  35. package/lib/typescript/src/Timeline/TimelineItem.d.ts +1 -1
  36. package/lib/typescript/src/Timeline/TimelineItem.d.ts.map +1 -1
  37. package/package.json +1 -1
  38. package/src/Accordion/README.md +1 -0
  39. package/src/Alert/README.md +1 -0
  40. package/src/Avatar/README_AVATAR.md +1 -1
  41. package/src/Avatar/README_AVATARGROUP.md +3 -1
  42. package/src/BottomSheet/README.md +1 -1
  43. package/src/Button/README.md +3 -1
  44. package/src/Calendar/README.md +1 -0
  45. package/src/Chip/README.md +2 -1
  46. package/src/Color/README.md +97 -46
  47. package/src/DatePicker/{README.md → README_DATEPICKER.md} +1 -0
  48. package/src/DatePicker/README_MONTHPICKER.md +90 -0
  49. package/src/DatePicker/README_TIMEPICKER.md +83 -0
  50. package/src/DatePicker/README_YEARPICKER.md +106 -0
  51. package/src/DropDown/DropDown.tsx +54 -58
  52. package/src/DropDown/README.md +108 -0
  53. package/src/DropDown/type.tsx +1 -1
  54. package/src/Label/README.md +65 -0
  55. package/src/Provider/Provider.tsx +4 -2
  56. package/src/Provider/type.tsx +2 -2
  57. package/src/RadioButton/README.md +2 -1
  58. package/src/Timeline/Timeline.tsx +8 -2
  59. package/src/Timeline/TimelineItem.tsx +16 -3
  60. package/src/Ui/README_DEVIDER.md +62 -0
  61. package/src/Ui/README_FOOTER.md +0 -0
@@ -1,7 +1,7 @@
1
1
  # 🧑‍🎨 Avatar Component
2
2
 
3
3
  Komponen `Avatar` digunakan untuk menampilkan foto pengguna atau inisial nama jika foto tidak tersedia.
4
- ![Deskripsi Alt](../../assets/doc/Avatar/Avatar.png)
4
+ <img src="../../assets/doc/Avatar/Avatar.png" width=200>
5
5
 
6
6
  ## ✨ Fitur
7
7
 
@@ -2,7 +2,9 @@
2
2
  # AvatarGroup Component (React Native)
3
3
 
4
4
  The `AvatarGroup` component displays a group of user avatars. It supports image avatars, initials-based avatars, and a fallback icon. If there are more avatars than the maximum visible count, it displays a "+X" bubble.
5
- ![Deskripsi Alt](../../assets/doc/Avatar/AvatarGroup.png)
5
+
6
+ <img src="../../assets/doc/Avatar/AvatarGroup.png" width=200>
7
+
6
8
  ---
7
9
 
8
10
  ## 📦 Props
@@ -1,8 +1,8 @@
1
1
  # ⬆️ BottomSheet Component
2
2
 
3
3
  Komponen `BottomSheet` adalah modal bawah (slide-up) untuk menampilkan konten dinamis, form, konfirmasi, dll, dengan berbagai fitur interaktif seperti gesture drag, keyboard-aware, dan customizable height.
4
- ![Deskripsi Alt](../../assets/doc/BottomSheet/BottomSheet.gif)
5
4
 
5
+ <img src="../../assets/doc/BottomSheet/BottomSheet.gif" width=200>
6
6
  ---
7
7
 
8
8
  ## 📦 Props
@@ -2,7 +2,9 @@
2
2
  # 🔘 Komponen Button (React Native)
3
3
 
4
4
  Komponen `Button` ini adalah tombol serbaguna untuk aplikasi React Native. Mendukung berbagai ukuran, varian, warna, dan status seperti `disabled` dan `loading`.
5
- ![Deskripsi Alt](../../assets/doc/Button/Button.png)
5
+
6
+
7
+ <img src="../../assets/doc/Button/Button.png" width=200>
6
8
 
7
9
  ---
8
10
 
@@ -1,6 +1,7 @@
1
1
  # 📆 Komponen Kalender Kustom (React Native)
2
2
 
3
3
  Komponen kalender ini dibuat menggunakan React Native dan memungkinkan pengguna untuk memilih tanggal tunggal maupun rentang tanggal, serta mendukung fitur penandaan dan pembatasan tanggal.
4
+ <img src="../../assets/doc/Calendar/Calendar.png" width=200>
4
5
 
5
6
  ---
6
7
 
@@ -1,7 +1,8 @@
1
1
  # 📦 Komponen `Chip` – React Native
2
2
 
3
3
  Komponen `Chip` digunakan untuk menampilkan daftar pilihan seperti tag, filter, atau kategori dalam bentuk tombol kecil (chip). Komponen ini mendukung pilihan tunggal maupun jamak, arah horizontal/vertikal, dan gaya warna yang dapat disesuaikan.
4
- ![Deskripsi Alt](../../assets/doc/Chip/Chip.png)
4
+
5
+ <img src="../../assets/doc/Chip/Chip.png" width=200>
5
6
 
6
7
  ---
7
8
 
@@ -1,54 +1,105 @@
1
- # 📦 Konstanta: Color
2
- Konstanta Color berisi daftar token warna yang digunakan untuk styling antarmuka aplikasi menggunakan React Native. Warna-warna ini disusun berdasarkan tema dan gradasi, cocok digunakan bersama desain sistem seperti Design Token.
1
+ # Color Palette
2
+
3
+ Berikut adalah definisi warna yang digunakan di design system React Native Anda. Palette mencakup warna dasar (*base*), skala abu‐abu (*gray*), kategori semantik (*primary*, *success*, *danger*, *warning*, *info*, *orange*, *purple*), serta utilitas lain seperti `divider` dan `disabled`.
4
+
5
+ Warna tersimpan dalam objek `Color` dengan struktur hierarkis seperti contoh berikut:
6
+
7
+ ```ts
8
+ Color.primary[500] // -> "#4D46FF"
9
+ Color.gray[200] // -> "#EBEBEB"
10
+ ```
11
+
12
+ ---
13
+
14
+ ## Struktur Objek Color
15
+
16
+ ```ts
17
+ const Color = {
18
+ base: { ... },
19
+ gray: { ... },
20
+ primary: { ... },
21
+ warning: { ... },
22
+ danger: { ... },
23
+ success: { ... },
24
+ info: { ... },
25
+ orange: { ... },
26
+ purple: { ... },
27
+ divider: { ... },
28
+ disabled: { ... },
29
+ shadow: { ... },
30
+ };
31
+ ```
32
+
33
+ ### Skema Skala Warna
34
+
35
+ * **0–1000** (atau 0–950) – Semakin besar angka, semakin gelap warna.
36
+ * **50** – Latar paling terang (sering dipakai untuk *background* highlight).
37
+ * **500** – Warna utama (brand color dan teks link normal).
38
+ * **700/800/900** – Warna paling gelap untuk teks di atas latar berkait.
39
+
40
+ ---
41
+
42
+ ## Tabel Ringkasan
43
+
44
+ | Kategori | Contoh Penggunaan | Keterangan |
45
+ | ---------- | --------------------- | ------------------------------------------- |
46
+ | `base` | `Color.base.white100` | Warna putih/ hitam utama UI dasar. |
47
+ | `gray` | `Color.gray[700]` | Teks, ikon sekunder, border netral. |
48
+ | `primary` | `Color.primary[500]` | Aksi utama, tombol brand, ikon utama. |
49
+ | `success` | `Color.success[500]` | Status berhasil: label “Success”, badge OK. |
50
+ | `danger` | `Color.danger[500]` | Error, status gagal. |
51
+ | `warning` | `Color.warning[500]` | Peringatan. |
52
+ | `info` | `Color.info[500]` | Informasi tambahan. |
53
+ | `orange` | `Color.orange[500]` | Aksen/ badge khusus. |
54
+ | `purple` | `Color.purple[500]` | Aksen sekunder/ grafik. |
55
+ | `divider` | `Color.divider[25]` | Garis pemisah tipis. |
56
+ | `disabled` | `Color.disabled[25]` | Kontrol non‐aktif. |
57
+
58
+ > Anda bisa menambahkan `shadow` palette jika diperlukan gradasi drop shadow.
59
+
60
+ ---
61
+
62
+ ## TypeScript Helper
63
+
64
+ ```ts
65
+ export type ColorVariantType =
66
+ | 'default'
67
+ | 'success'
68
+ | 'danger'
69
+ | 'primary'
70
+ | 'warning'
71
+ | 'info'
72
+ | 'purple'
73
+ | 'orange';
74
+ ```
75
+
76
+ Tipe ini dipakai di komponen lain (mis. `Label`) untuk membatasi nama variant.
77
+
78
+ ---
79
+
80
+ ## Contoh Implementasi
3
81
 
4
- ## 🎨 Struktur Warna
5
- ✅ Base
6
- Warna dasar utama:
7
-
8
- white100: putih solid
9
-
10
- white60: putih transparan 60%
11
-
12
- black100: hitam solid
13
-
14
- black60: hitam transparan 60%
15
-
16
- ### ⚪ Gray (abu-abu)
17
- Gradasi abu-abu dari terang (gray.50) hingga gelap (gray.950), cocok untuk teks, latar, border, dsb.
18
-
19
- ### 🔵 Primary
20
- Gradasi warna utama (biru), digunakan untuk tombol, highlight, atau elemen penting lainnya.
21
-
22
- ### 🟠 Warning
23
- Warna peringatan, digunakan untuk menandai hal-hal seperti alert, notifikasi kuning, dll.
24
-
25
- ### 🔴 Danger
26
- Warna untuk kondisi berbahaya atau error (merah).
27
-
28
- ### 🟢 Success
29
- Digunakan untuk kondisi berhasil atau sukses (hijau).
30
-
31
- ### 🔷 Info
32
- Warna tambahan untuk informasi, notifikasi, atau status sekunder.
33
-
34
- ### 🟧 Orange
35
- Warna oranye, alternatif dari primary/warning.
82
+ ```tsx
83
+ import Color from '@/components/Color/Color';
36
84
 
37
- ### 🟣 Purple
38
- Warna ungu, bisa digunakan untuk status spesial atau branding.
85
+ const MyButton = () => (
86
+ <View style={{ backgroundColor: Color.primary[500], padding: 12 }}>
87
+ <Text style={{ color: Color.base.white100 }}>Click Me</Text>
88
+ </View>
89
+ );
90
+ ```
39
91
 
40
- 🧱 Divider
41
- divider.25: Warna pembatas antar elemen UI.
92
+ ---
42
93
 
43
- 📴 Disabled
44
- disabled.25: Warna untuk elemen non-aktif.
94
+ ## Tips Penggunaan
45
95
 
46
- ## Cara menggunakan
96
+ * Gunakan warna **50** untuk latar lembut (highlight, badge background).
97
+ * Gunakan warna **500** untuk elemen interaktif utama.
98
+ * Gunakan warna **700+** untuk teks di atas warna **50–300**.
99
+ * Gunakan `rgba(..., 0.x)` jika memerlukan translusi.
47
100
 
48
- ```tsx
49
- import Color from '@herca/rn-kit';
101
+ ---
50
102
 
51
- <View style={{ backgroundColor: Color.primary[500] }} />
52
- <Text style={{ color: Color.gray[900] }}>Teks</Text>
103
+ ## Lisensi
53
104
 
54
- ```
105
+ Bagian dari library internal Anda; ikuti lisensi proyek.
@@ -4,6 +4,7 @@ Komponen `DatePicker` adalah antarmuka pemilih tanggal yang dibungkus dalam sebu
4
4
 
5
5
  Komponen ini extend dari Calendar, jadi kalian bisa menggunakan semua props yang ada di Calendar [Calendar](../Calendar/README.md)
6
6
 
7
+ <img src="../../assets/doc/Datepicker/Datepicker.gif" width=200>
7
8
  ---
8
9
 
9
10
  ## ✨ Fitur
@@ -0,0 +1,90 @@
1
+ # MonthPicker
2
+
3
+ Komponen **MonthPicker** adalah komponen pemilih bulan berbasis **React Native** yang dapat menampilkan pilihan bulan dalam tiga mode berbeda: **single**, **range**, dan **multiple**. Komponen ini dirancang untuk dipakai di dalam komponen **BottomSheet** dengan tampilan yang konsisten terhadap desain sistem.
4
+
5
+
6
+
7
+ ---
8
+
9
+ ## API Reference
10
+
11
+ | Prop | Tipe | Default | Deskripsi |
12
+ | ---------- | ------------------------------------------------------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------- |
13
+ | `isOpen` | `boolean` | `false` | Menentukan apakah **BottomSheet** terbuka atau tertutup. |
14
+ | `onClose` | `() => void` | `undefined` | Callback yang dipanggil saat pengguna menekan tombol **Batal** atau menutup **BottomSheet**. |
15
+ | `onChange` | `(value: number[] \| { startDate: number \| null; endDate: number \| null }) => void` | `undefined` | Callback yang dipanggil ketika pengguna menekan tombol **Pilih**. Parameter yang dikirim tergantung pada `mode`. |
16
+ | `mode` | `'single' \| 'range' \| 'multiple'` | `'single'` | Menentukan cara pemilihan bulan. |
17
+
18
+ ### Bentuk *value* yang Dikirim oleh `onChange`
19
+
20
+ | `mode` | Bentuk *value* |
21
+ | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
22
+ | `single` | `number[]` – array yang berisi satu elemen bulan terpilih. Contoh: `[5]` untuk Mei. |
23
+ | `range` | `{ startDate: number \| null; endDate: number \| null }` – objek berisi bulan mulai & akhir. Contoh: `{ startDate: 1, endDate: 3 }` untuk Jan–Mar. |
24
+ | `multiple` | `number[]` – array berisi daftar bulan terpilih. Contoh: `[2, 4, 8]` untuk Feb, Apr, Agt. |
25
+
26
+ ---
27
+
28
+ ## Contoh Penggunaan
29
+
30
+ ```tsx
31
+ import { useState } from 'react';
32
+ import { View, Button } from 'react-native';
33
+ import MonthPicker from '@/components/MonthPicker/MonthPicker';
34
+
35
+ export default function Example() {
36
+ const [open, setOpen] = useState(false);
37
+ const [months, setMonths] = useState<number[]>([]);
38
+
39
+ return (
40
+ <View style={{ flex: 1 }}>
41
+ <Button title="Pilih Bulan" onPress={() => setOpen(true)} />
42
+
43
+ <MonthPicker
44
+ isOpen={open}
45
+ mode="multiple"
46
+ onClose={() => setOpen(false)}
47
+ onChange={(value) => {
48
+ if (Array.isArray(value)) {
49
+ setMonths(value);
50
+ }
51
+ setOpen(false);
52
+ }}
53
+ />
54
+ </View>
55
+ );
56
+ }
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Detail
62
+
63
+ 1. **Single Mode**
64
+
65
+ * Klik satu bulan untuk menandai pilihan.
66
+ * Menekan **Pilih** mengirimkan array dengan satu elemen.
67
+ 2. **Range Mode**
68
+
69
+ * Klik bulan pertama untuk menentukan `startDate`.
70
+ * Klik bulan kedua untuk menentukan `endDate`.
71
+ * Jika `startDate` sudah terisi dan `endDate` belum, tetapi pengguna memilih bulan yang lebih kecil dari `startDate`, maka komponen otomatis menukar posisi dan mengisi `endDate` dengan nilai awal `startDate`.
72
+ 3. **Multiple Mode**
73
+
74
+ * Klik untuk toggle seleksi pada tiap bulan. Bulan yang dipilih disimpan dalam array `multipleValue`.
75
+
76
+ ---
77
+
78
+ ## Kustomisasi Tampilan
79
+
80
+ * **Warna**: Warna latar dan border untuk opsi terpilih mengikuti `Color.primary` pada design system. Anda dapat menyesuaikannya dengan mengubah style `optionSelected` di dalam `MonthPicker`.
81
+ * **Jumlah Kolom**: Saat ini komponen menampilkan `numColumns={3}` pada `FlatList`. Ubah nilai ini untuk menyesuaikan grid.
82
+
83
+ ---
84
+
85
+ ## Tips
86
+
87
+ * Pastikan memanggil `onClose` setelah memproses hasil `onChange` agar **BottomSheet** tertutup.
88
+ * Komponen ini tidak menangani validasi kombinasi bulan secara otomatis (mis. range satu tahun penuh). Tambahkan logika tambahan di tempat Anda memakainya apabila diperlukan.
89
+
90
+ ---
@@ -0,0 +1,83 @@
1
+ # TimePickerWheel
2
+
3
+ **TimePickerWheel** adalah komponen pemilih waktu berbentuk *wheel* (picker bergulir) untuk **React Native**. Komponen ini menampilkan dua kolom (jam & menit) yang dapat digulir secara vertikal, dibungkus di dalam komponen **BottomSheet**.
4
+
5
+ ---
6
+
7
+ ## API Reference
8
+
9
+ | Prop | Tipe | Default | Deskripsi |
10
+ | ---------- | --------------------------------------------------- | ------- | --------------------------------------------------------------------------------------------- |
11
+ | `isOpen` | `boolean` | `false` | Menentukan apakah **BottomSheet** terbuka. |
12
+ | `onClose` | `() => void` | `-` | Callback saat pengguna menutup **BottomSheet** atau menekan tombol **Batal**. |
13
+ | `onChange` | `(value: { hour: number; minute: number }) => void` | `-` | Callback saat pengguna menekan tombol **Pilih**. Objek yang dikirim berisi `hour` & `minute`. |
14
+
15
+ ### Bentuk *value* `onChange`
16
+
17
+ ```ts
18
+ {
19
+ hour: number; // 0–23
20
+ minute: number; // 0–59
21
+ }
22
+ ```
23
+
24
+ ---
25
+
26
+ ## Cara Kerja Singkat
27
+
28
+ 1. **Wheel Padding** – Komponen menambahkan elemen *dummy* di atas & bawah daftar agar item tengah selalu berada di posisi highlight.
29
+ 2. **Highlight** – Baris tengah diberi `backgroundColor` khusus (`Color.primary[50]`) untuk menonjolkan pilihan aktif.
30
+ 3. **Snapping** – Properti `snapToInterval={ITEM_HEIGHT}` memastikan scroll *wheel* berhenti tepat di setiap item.
31
+ 4. **Sync & Loop** – Setelah scroll selesai, komponen menghitung indeks nyata (0‑23 untuk jam, 0‑59 untuk menit) agar wheel terasa tak terbatas.
32
+
33
+ ---
34
+
35
+ ## Contoh Penggunaan
36
+
37
+ ```tsx
38
+ import { useState } from 'react';
39
+ import { View, Button } from 'react-native';
40
+ import TimePickerWheel from '@/components/TimePickerWheel/TimePickerWheel';
41
+
42
+ export default function Example() {
43
+ const [open, setOpen] = useState(false);
44
+ const [time, setTime] = useState<{ hour: number; minute: number } | null>(
45
+ null
46
+ );
47
+
48
+ const formatted = time ? `${time.hour.toString().padStart(2, '0')}:${time.minute.toString().padStart(2, '0')}` : '—';
49
+
50
+ return (
51
+ <View style={{ flex: 1 }}>
52
+ <Button title={`Pilih Waktu (${formatted})`} onPress={() => setOpen(true)} />
53
+
54
+ <TimePickerWheel
55
+ isOpen={open}
56
+ onClose={() => setOpen(false)}
57
+ onChange={(value) => {
58
+ setTime(value);
59
+ setOpen(false);
60
+ }}
61
+ />
62
+ </View>
63
+ );
64
+ }
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Kustomisasi Tampilan
70
+
71
+ * **Jumlah Items Terlihat** (`VISIBLE_ITEMS`): Default 5. Ubah nilai konstanta untuk menambah/kurangi tinggi wheel.
72
+ * **Tinggi Item** (`ITEM_HEIGHT`): Default 40. Pengaturan ini mempengaruhi `snapToInterval`.
73
+ * **Warna & Tipografi**: Edit style `selectedItemText`, `itemText`, dan `highlight` untuk menyesuaikan brand guideline.
74
+
75
+ ---
76
+
77
+ ## Tips Implementasi
78
+
79
+ * Selalu panggil `onClose` setelah menangani hasil `onChange` agar **BottomSheet** menutup.
80
+ * Jika Anda ingin menetapkan waktu awal sebelum picker dibuka, setel `selectedHour` & `selectedMinute` memakai `useState` lalu buka picker.
81
+ * Komponen ini tidak membatasi kombinasi jam‑menit (mis. langkah 5 menit). Tambahkan logika tambahan jika diperlukan.
82
+
83
+ ---
@@ -0,0 +1,106 @@
1
+ # YearPicker
2
+
3
+ **YearPicker** adalah komponen pemilih tahun berbasis **React Native**. Dibandingkan dengan *MonthPicker*, komponen ini mendukung navigasi halaman (pagination) untuk deretan tahun dan dapat digunakan dalam tiga mode:
4
+
5
+ * **single** – memilih satu tahun.
6
+ * **range** – memilih rentang tahun.
7
+ * **multiple** – memilih beberapa tahun sekaligus.
8
+
9
+ Semua outputnya dibungkus dalam komponen **BottomSheet** untuk konsistensi UI.
10
+
11
+ ---
12
+
13
+ ## API Reference
14
+
15
+ | Prop | Tipe | Default | Deskripsi |
16
+ | ---------- | ------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------ |
17
+ | `isOpen` | `boolean` | `false` | Menentukan apakah **BottomSheet** terbuka. |
18
+ | `onClose` | `() => void` | `-` | Dipanggil saat pengguna menutup picker atau menekan **Batal**. |
19
+ | `onChange` | `(value: number[] \| { startDate: number \| null; endDate: number \| null }) => void` | `-` | Dipanggil setelah pengguna menekan **Pilih**. Bentuk *value* bergantung pada `mode`. |
20
+ | `mode` | `'single' \| 'range' \| 'multiple'` | `'single'` | Menentukan mode pemilihan. |
21
+
22
+ ### Bentuk *value* `onChange`
23
+
24
+ | `mode` | *value* |
25
+ | ---------- | ---------------------------------------------------------------------------------------------------------------------- |
26
+ | `single` | `number[]` – satu elemen, contoh `[2023]`. |
27
+ | `range` | `{ startDate: number \| null; endDate: number \| null }` – objek rentang, contoh `{ startDate: 2010, endDate: 2015 }`. |
28
+ | `multiple` | `number[]` – daftar tahun, contoh `[2018, 2020, 2022]`. |
29
+
30
+ ---
31
+
32
+ ## Cara Kerja Singkat
33
+
34
+ 1. **Daftar Tahun**
35
+
36
+ * Komponen membuat rentang tahun ±60 tahun ke belakang & depan dari tahun saat ini (total 121 tahun).
37
+ 2. **Pagination**
38
+
39
+ * `pageSize` default 9 (3 kolom × 3 baris). Tombol panah mengubah `pageIndex` untuk melihat kelompok tahun selanjutnya atau sebelumnya.
40
+ 3. **Seleksi & Highlight**
41
+
42
+ * Tahun yang dipilih diberi latar `Color.primary[50]` dan border `Color.primary[300]`.
43
+ 4. **Logika Mode**
44
+
45
+ * *Single*: klik satu tahun.
46
+ * *Range*: klik awal & akhir; otomatis menukar jika urutan terbalik.
47
+ * *Multiple*: toggle checklist per tahun.
48
+
49
+ ---
50
+
51
+ ## Contoh Penggunaan
52
+
53
+ ```tsx
54
+ import { useState } from 'react';
55
+ import { View, Button } from 'react-native';
56
+ import YearPicker from '@/components/YearPicker/YearPicker';
57
+
58
+ export default function YearPickerExample() {
59
+ const [open, setOpen] = useState(false);
60
+ const [yearRange, setYearRange] = useState<{ startDate: number | null; endDate: number | null }>({ startDate: null, endDate: null });
61
+
62
+ const label = yearRange.startDate && yearRange.endDate ? `${yearRange.startDate}–${yearRange.endDate}` : '—';
63
+
64
+ return (
65
+ <View style={{ flex: 1 }}>
66
+ <Button title={`Pilih Rentang Tahun (${label})`} onPress={() => setOpen(true)} />
67
+
68
+ <YearPicker
69
+ isOpen={open}
70
+ mode="range"
71
+ onClose={() => setOpen(false)}
72
+ onChange={(value) => {
73
+ if (!Array.isArray(value)) {
74
+ setYearRange(value);
75
+ }
76
+ setOpen(false);
77
+ }}
78
+ />
79
+ </View>
80
+ );
81
+ }
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Kustomisasi Tampilan & Perilaku
87
+
88
+ | Konstanta / Style | Fungsi | Cara Ubah |
89
+ | ----------------- | ------------------------------------------------ | ---------------------------------------- |
90
+ | `pageSize` | Jumlah tahun ditampilkan per halaman (grid 3×N). | Sesuaikan untuk menambah baris. |
91
+ | `buttonNav` | Style tombol panah. | Edit warna & radius pada file `styles`. |
92
+ | `optionSelected` | Warna highlight. | Ganti `backgroundColor` & `borderColor`. |
93
+
94
+ ---
95
+
96
+ ## Tips Implementasi
97
+
98
+ * Ingin memulai dengan tahun tertentu? Setel `singleValue`, `rangeValue`, atau `multipleValue` melalui `useState` sebelum `isOpen` di-set `true`.
99
+ * Anda dapat memfilter rentang tahun dengan memodifikasi konstanta `total` & `start` di dalam `useMemo(years)`.
100
+ * Pastikan memanggil `onClose` setelah `onChange` untuk menutup picker.
101
+
102
+ ---
103
+
104
+ ## Lisensi
105
+
106
+ Bagian dari library internal Anda; ikuti lisensi proyek.
@@ -3,11 +3,13 @@ import {
3
3
  View,
4
4
  Text,
5
5
  TouchableOpacity,
6
+ Pressable,
6
7
  StyleSheet,
7
8
  ScrollView,
8
9
  useWindowDimensions,
9
10
  findNodeHandle,
10
11
  UIManager,
12
+ Modal,
11
13
  } from 'react-native';
12
14
  import Color from '../Color/Color';
13
15
  import type { DropDownProps } from './type';
@@ -21,9 +23,13 @@ const Dropdown = ({
21
23
  }: DropDownProps) => {
22
24
  const [isOpen, setIsOpen] = useState(false);
23
25
  const [selected, setSelected] = useState<string | number>();
24
- const [dropdownPosition, setDropdownPosition] = useState<'left' | 'right'>(
25
- 'left'
26
- );
26
+ const [align, setAlign] = useState<'left' | 'right'>('left');
27
+ const [buttonLayout, setButtonLayout] = useState({
28
+ x: 0,
29
+ y: 0,
30
+ width: 0,
31
+ height: 0,
32
+ });
27
33
 
28
34
  const buttonRef = useRef<View>(null);
29
35
  const windowWidth = useWindowDimensions().width;
@@ -32,9 +38,10 @@ const Dropdown = ({
32
38
  if (!isOpen) {
33
39
  const handle = findNodeHandle(buttonRef.current);
34
40
  if (handle) {
35
- UIManager.measureInWindow(handle, (x, _y, width, _height) => {
41
+ UIManager.measureInWindow(handle, (x, y, width, height) => {
36
42
  const middle = windowWidth / 2;
37
- setDropdownPosition(x + width / 2 > middle ? 'right' : 'left');
43
+ setAlign(x + width / 2 > middle ? 'right' : 'left');
44
+ setButtonLayout({ x, y, width, height });
38
45
  setIsOpen(true);
39
46
  });
40
47
  }
@@ -50,70 +57,65 @@ const Dropdown = ({
50
57
  };
51
58
 
52
59
  return (
53
- <View style={styles.container}>
54
- <TouchableOpacity
55
- ref={buttonRef}
56
- style={styles.dropdownButton}
57
- onPress={handleToggle}
58
- >
59
- {renderButton ? (
60
- renderButton
61
- ) : (
62
- <Text>{selected || 'Select an option'}</Text>
63
- )}
60
+ <>
61
+ <TouchableOpacity ref={buttonRef} onPress={handleToggle}>
62
+ {renderButton}
64
63
  </TouchableOpacity>
65
-
66
64
  {isOpen && (
67
- <View
68
- style={[
69
- styles.dropdownList,
70
- dropdownPosition === 'left' ? styles.left : styles.right,
71
- ]}
72
- >
73
- <ScrollView nestedScrollEnabled style={{ maxHeight }}>
74
- {options.map((item, index) => (
75
- <TouchableOpacity
76
- key={index}
77
- onPress={() => handlePressOption(item)}
78
- style={[
79
- styles.option,
80
- selected === item.value ? styles.optionSelected : null,
81
- ]}
82
- >
83
- <Text>{item.label}</Text>
84
- </TouchableOpacity>
85
- ))}
86
- </ScrollView>
87
- </View>
65
+ <Modal transparent animationType="none" visible>
66
+ <Pressable
67
+ style={StyleSheet.absoluteFillObject}
68
+ onPress={() => setIsOpen(false)}
69
+ />
70
+
71
+ <View
72
+ style={[
73
+ styles.dropdownList,
74
+ {
75
+ top: buttonLayout.y + buttonLayout.height,
76
+ left: align === 'left' ? buttonLayout.x : undefined,
77
+ right:
78
+ align === 'right'
79
+ ? windowWidth - (buttonLayout.x + buttonLayout.width)
80
+ : undefined,
81
+ },
82
+ ]}
83
+ >
84
+ <ScrollView nestedScrollEnabled style={{ maxHeight }}>
85
+ {options.map((item, idx) => (
86
+ <TouchableOpacity
87
+ key={idx}
88
+ onPress={() => handlePressOption(item)}
89
+ style={[
90
+ styles.option,
91
+ selected === item.value && styles.optionSelected,
92
+ ]}
93
+ >
94
+ <Text>{item.label}</Text>
95
+ </TouchableOpacity>
96
+ ))}
97
+ </ScrollView>
98
+ </View>
99
+ </Modal>
88
100
  )}
89
- </View>
101
+ </>
90
102
  );
91
103
  };
92
104
 
93
105
  export default Dropdown;
94
106
 
95
107
  const styles = StyleSheet.create({
96
- container: {
97
- // width: 200, // or flexible
98
- },
99
- dropdownButton: {
100
- // borderWidth: 1,
101
- // borderColor: '#ccc',
102
- // padding: 12,
103
- // borderRadius: 6,
104
- // backgroundColor: '#fff',
105
- },
108
+ button: {},
106
109
  dropdownList: {
107
110
  position: 'absolute',
108
- marginTop: 18,
109
111
  padding: 8,
110
- zIndex: 9999,
112
+ zIndex: 10,
111
113
  gap: 4,
112
114
  borderWidth: 1,
113
115
  borderColor: Color.gray[50],
114
116
  borderRadius: 8,
115
117
  backgroundColor: Color.base.white100,
116
- width: 100,
118
+ width: 120,
117
119
  },
118
120
  option: {
119
121
  gap: 8,
@@ -127,10 +129,4 @@ const styles = StyleSheet.create({
127
129
  backgroundColor: Color.primary[50],
128
130
  borderColor: Color.primary[300],
129
131
  },
130
- left: {
131
- left: 0,
132
- },
133
- right: {
134
- right: 0,
135
- },
136
132
  });