@herca/rn-kit 0.1.64 → 0.1.65

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 (34) hide show
  1. package/README.md +8 -0
  2. package/lib/module/DatePicker/DatePicker.js +2 -2
  3. package/lib/module/DatePicker/DatePicker.js.map +1 -1
  4. package/lib/module/Input/InputDate.js +170 -0
  5. package/lib/module/Input/InputDate.js.map +1 -0
  6. package/lib/module/Input/README_INPUT_DATE.md +265 -0
  7. package/lib/module/Ui/README_VIEWINSETS.md +126 -0
  8. package/lib/module/Ui/ViewInsets.js +33 -0
  9. package/lib/module/Ui/ViewInsets.js.map +1 -0
  10. package/lib/module/function/README_DATE_FORMATTER.md +397 -0
  11. package/lib/module/function/dateFormatter.js +38 -0
  12. package/lib/module/function/dateFormatter.js.map +1 -0
  13. package/lib/module/index.js +3 -0
  14. package/lib/module/index.js.map +1 -1
  15. package/lib/typescript/src/Calendar/CalendarPropsType.d.ts +5 -0
  16. package/lib/typescript/src/Calendar/CalendarPropsType.d.ts.map +1 -1
  17. package/lib/typescript/src/Input/InputDate.d.ts +27 -0
  18. package/lib/typescript/src/Input/InputDate.d.ts.map +1 -0
  19. package/lib/typescript/src/Ui/ViewInsets.d.ts +13 -0
  20. package/lib/typescript/src/Ui/ViewInsets.d.ts.map +1 -0
  21. package/lib/typescript/src/function/dateFormatter.d.ts +14 -0
  22. package/lib/typescript/src/function/dateFormatter.d.ts.map +1 -0
  23. package/lib/typescript/src/index.d.ts +4 -1
  24. package/lib/typescript/src/index.d.ts.map +1 -1
  25. package/package.json +1 -1
  26. package/src/Calendar/CalendarPropsType.tsx +6 -0
  27. package/src/DatePicker/DatePicker.tsx +2 -2
  28. package/src/Input/InputDate.tsx +216 -0
  29. package/src/Input/README_INPUT_DATE.md +265 -0
  30. package/src/Ui/README_VIEWINSETS.md +126 -0
  31. package/src/Ui/ViewInsets.tsx +46 -0
  32. package/src/function/README_DATE_FORMATTER.md +397 -0
  33. package/src/function/dateFormatter.ts +54 -0
  34. package/src/index.tsx +8 -1
@@ -0,0 +1,397 @@
1
+ # dateFormatter Function
2
+
3
+ Utility function untuk memformat objek Date ke berbagai format string dengan dukungan multi-bahasa dan kustomisasi tampilan.
4
+
5
+ ## Import
6
+
7
+ ```typescript
8
+ import { dateFormatter } from './function/dateFormatter';
9
+ ```
10
+
11
+ ## Signature
12
+
13
+ ```typescript
14
+ dateFormatter({ date, options }: DateFormatterProps): string
15
+ ```
16
+
17
+ ## Parameters
18
+
19
+ ### DateFormatterProps
20
+
21
+ | Parameter | Type | Required | Deskripsi |
22
+ | --------- | ------------------- | -------- | -------------------------------------------- |
23
+ | `date` | `Date \| DateProps` | ✅ Yes | Objek Date atau DateProps yang akan diformat |
24
+ | `options` | `Object` | ❌ No | Opsi konfigurasi untuk formatting |
25
+
26
+ ### Options Object
27
+
28
+ | Property | Type | Default | Deskripsi |
29
+ | ------------- | --------------------------------------------------------- | ----------- | -------------------------------------------------------------- |
30
+ | `useTime` | `boolean` | `false` | Menambahkan waktu (jam:menit:detik) ke output |
31
+ | `useWeekDay` | `boolean` | `false` | Menambahkan nama hari ke output (hanya untuk format localized) |
32
+ | `monthFormat` | `'numeric' \| '2-digit' \| 'long' \| 'short' \| 'narrow'` | `'long'` | Format tampilan bulan (hanya untuk format localized) |
33
+ | `language` | `'en' \| 'id'` | `'en'` | Bahasa untuk format localized |
34
+ | `format` | `'default' \| 'iso' \| 'localized'` | `'default'` | Tipe format output |
35
+
36
+ ## Format Types
37
+
38
+ ### 1. Default Format
39
+
40
+ Format: `YYYY-MM-DD`
41
+
42
+ ```typescript
43
+ dateFormatter({
44
+ date: new Date('2024-03-15'),
45
+ });
46
+ // Output: "2024-03-15"
47
+ ```
48
+
49
+ ### 2. ISO Format
50
+
51
+ Format: `YYYY-MM-DD` atau `YYYY-MM-DD HH:mm:ss` (jika useTime: true)
52
+
53
+ ```typescript
54
+ dateFormatter({
55
+ date: new Date('2024-03-15T14:30:45'),
56
+ options: { format: 'iso' },
57
+ });
58
+ // Output: "2024-03-15"
59
+
60
+ dateFormatter({
61
+ date: new Date('2024-03-15T14:30:45'),
62
+ options: { format: 'iso', useTime: true },
63
+ });
64
+ // Output: "2024-03-15 14:30:45"
65
+ ```
66
+
67
+ ### 3. Localized Format
68
+
69
+ Format berdasarkan locale dengan dukungan bahasa.
70
+
71
+ **Bahasa Indonesia:**
72
+
73
+ ```typescript
74
+ dateFormatter({
75
+ date: new Date('2024-03-15'),
76
+ options: { format: 'localized', language: 'id' },
77
+ });
78
+ // Output: "15 Maret 2024"
79
+ ```
80
+
81
+ **Bahasa Inggris:**
82
+
83
+ ```typescript
84
+ dateFormatter({
85
+ date: new Date('2024-03-15'),
86
+ options: { format: 'localized', language: 'en' },
87
+ });
88
+ // Output: "15 March 2024"
89
+ ```
90
+
91
+ ## Contoh Penggunaan
92
+
93
+ ### Basic Usage
94
+
95
+ ```typescript
96
+ // Format default
97
+ const formatted = dateFormatter({
98
+ date: new Date('2024-12-25'),
99
+ });
100
+ console.log(formatted); // "2024-12-25"
101
+ ```
102
+
103
+ ### Dengan Waktu
104
+
105
+ ```typescript
106
+ // ISO format dengan waktu
107
+ const withTime = dateFormatter({
108
+ date: new Date('2024-12-25T15:30:00'),
109
+ options: {
110
+ format: 'iso',
111
+ useTime: true,
112
+ },
113
+ });
114
+ console.log(withTime); // "2024-12-25 15:30:00"
115
+ ```
116
+
117
+ ### Format Localized Indonesia
118
+
119
+ ```typescript
120
+ // Tanggal lengkap bahasa Indonesia
121
+ const indonesian = dateFormatter({
122
+ date: new Date('2024-12-25'),
123
+ options: {
124
+ format: 'localized',
125
+ language: 'id',
126
+ },
127
+ });
128
+ console.log(indonesian); // "25 Desember 2024"
129
+ ```
130
+
131
+ ### Dengan Nama Hari
132
+
133
+ ```typescript
134
+ // Dengan nama hari (bahasa Indonesia)
135
+ const withWeekday = dateFormatter({
136
+ date: new Date('2024-12-25'),
137
+ options: {
138
+ format: 'localized',
139
+ language: 'id',
140
+ useWeekDay: true,
141
+ },
142
+ });
143
+ console.log(withWeekday); // "Rabu, 25 Desember 2024"
144
+
145
+ // Dengan nama hari (bahasa Inggris)
146
+ const withWeekdayEn = dateFormatter({
147
+ date: new Date('2024-12-25'),
148
+ options: {
149
+ format: 'localized',
150
+ language: 'en',
151
+ useWeekDay: true,
152
+ },
153
+ });
154
+ console.log(withWeekdayEn); // "Wednesday, 25 December 2024"
155
+ ```
156
+
157
+ ### Custom Month Format
158
+
159
+ ```typescript
160
+ // Bulan dalam format singkat
161
+ const shortMonth = dateFormatter({
162
+ date: new Date('2024-12-25'),
163
+ options: {
164
+ format: 'localized',
165
+ language: 'id',
166
+ monthFormat: 'short',
167
+ },
168
+ });
169
+ console.log(shortMonth); // "25 Des 2024"
170
+
171
+ // Bulan dalam format numerik
172
+ const numericMonth = dateFormatter({
173
+ date: new Date('2024-12-25'),
174
+ options: {
175
+ format: 'localized',
176
+ language: 'id',
177
+ monthFormat: 'numeric',
178
+ },
179
+ });
180
+ console.log(numericMonth); // "25/12/2024"
181
+ ```
182
+
183
+ ### Tanggal dan Waktu Lengkap
184
+
185
+ ```typescript
186
+ // Format lengkap dengan hari dan waktu
187
+ const fullDateTime = dateFormatter({
188
+ date: new Date('2024-12-25T15:30:00'),
189
+ options: {
190
+ format: 'localized',
191
+ language: 'id',
192
+ useWeekDay: true,
193
+ useTime: true,
194
+ },
195
+ });
196
+ console.log(fullDateTime); // "Rabu, 25 Desember 2024 - 15:30"
197
+ ```
198
+
199
+ ### Handling Invalid Dates
200
+
201
+ ```typescript
202
+ // Date tidak valid
203
+ const invalid1 = dateFormatter({ date: null });
204
+ console.log(invalid1); // ""
205
+
206
+ const invalid2 = dateFormatter({ date: new Date('invalid') });
207
+ console.log(invalid2); // ""
208
+
209
+ const invalid3 = dateFormatter({ date: undefined });
210
+ console.log(invalid3); // ""
211
+ ```
212
+
213
+ ## Use Cases
214
+
215
+ ### 1. Display Tanggal di UI
216
+
217
+ ```typescript
218
+ function DateDisplay({ date }: { date: Date }) {
219
+ const formattedDate = dateFormatter({
220
+ date,
221
+ options: {
222
+ format: 'localized',
223
+ language: 'id'
224
+ }
225
+ });
226
+
227
+ return <Text>{formattedDate}</Text>;
228
+ }
229
+ ```
230
+
231
+ ### 2. Format untuk API Request
232
+
233
+ ```typescript
234
+ function submitBooking(date: Date) {
235
+ const isoDate = dateFormatter({
236
+ date,
237
+ options: { format: 'iso' },
238
+ });
239
+
240
+ api.post('/bookings', { date: isoDate });
241
+ }
242
+ ```
243
+
244
+ ### 3. Log dengan Timestamp
245
+
246
+ ```typescript
247
+ function logEvent(message: string) {
248
+ const timestamp = dateFormatter({
249
+ date: new Date(),
250
+ options: {
251
+ format: 'iso',
252
+ useTime: true,
253
+ },
254
+ });
255
+
256
+ console.log(`[${timestamp}] ${message}`);
257
+ }
258
+ ```
259
+
260
+ ### 4. Multi-language Support
261
+
262
+ ```typescript
263
+ function DatePicker({ language }: { language: 'en' | 'id' }) {
264
+ const [selectedDate, setSelectedDate] = useState(new Date());
265
+
266
+ const displayDate = dateFormatter({
267
+ date: selectedDate,
268
+ options: {
269
+ format: 'localized',
270
+ language,
271
+ useWeekDay: true
272
+ }
273
+ });
274
+
275
+ return <Text>{displayDate}</Text>;
276
+ }
277
+ ```
278
+
279
+ ## Output Examples
280
+
281
+ ### Default Format
282
+
283
+ ```
284
+ 2024-03-15
285
+ ```
286
+
287
+ ### ISO Format
288
+
289
+ ```
290
+ 2024-03-15
291
+ 2024-03-15 14:30:45 (with time)
292
+ ```
293
+
294
+ ### Localized Format (Indonesian)
295
+
296
+ ```
297
+ 15 Maret 2024
298
+ Jumat, 15 Maret 2024 (with weekday)
299
+ 15 Maret 2024 - 14:30 (with time)
300
+ Jumat, 15 Maret 2024 - 14:30 (full)
301
+ ```
302
+
303
+ ### Localized Format (English)
304
+
305
+ ```
306
+ 15 March 2024
307
+ Friday, 15 March 2024 (with weekday)
308
+ 15 March 2024 - 14:30 (with time)
309
+ Friday, 15 March 2024 - 14:30 (full)
310
+ ```
311
+
312
+ ## Return Values
313
+
314
+ | Kondisi | Return Value |
315
+ | ---------------------------- | ------------------------------- |
316
+ | Date valid | String terformat sesuai options |
317
+ | Date `null` atau `undefined` | Empty string `""` |
318
+ | Date invalid | Empty string `""` |
319
+
320
+ ## Fitur
321
+
322
+ - ✅ Support multiple format types (default, ISO, localized)
323
+ - ✅ Multi-language support (English & Indonesian)
324
+ - ✅ Optional time inclusion
325
+ - ✅ Optional weekday display
326
+ - ✅ Customizable month format
327
+ - ✅ Graceful error handling untuk invalid dates
328
+ - ✅ TypeScript support dengan type definitions
329
+ - ✅ Zero-padded values untuk konsistensi
330
+ - ✅ 24-hour time format
331
+
332
+ ## Technical Details
333
+
334
+ ### Time Formatting
335
+
336
+ - Waktu menggunakan format 24-jam (HH:mm:ss untuk ISO, HH:mm untuk localized)
337
+ - Separator waktu: `:` untuk semua format
338
+ - Separator antara tanggal dan waktu (localized): `-`
339
+
340
+ ### Locale Mapping
341
+
342
+ - `language: 'id'` → `id-ID` locale
343
+ - `language: 'en'` → `en-GB` locale (British English format)
344
+
345
+ ### Month Format Options
346
+
347
+ Sesuai dengan `Intl.DateTimeFormatOptions['month']`:
348
+
349
+ - `'numeric'`: 3
350
+ - `'2-digit'`: 03
351
+ - `'long'`: March / Maret
352
+ - `'short'`: Mar / Mar
353
+ - `'narrow'`: M
354
+
355
+ ## Best Practices
356
+
357
+ 1. **Selalu handle empty/invalid dates** - Function mengembalikan empty string untuk input invalid
358
+ 2. **Gunakan format yang sesuai konteks**:
359
+ - `default` atau `iso` untuk data processing/API
360
+ - `localized` untuk user-facing display
361
+ 3. **Konsisten dengan language setting** aplikasi
362
+ 4. **Cache formatted values** jika digunakan berulang kali
363
+ 5. **Validate date objects** sebelum formatting jika memungkinkan
364
+
365
+ ## TypeScript
366
+
367
+ Function ini fully typed dengan interface:
368
+
369
+ ```typescript
370
+ interface DateFormatterProps {
371
+ date: Date | DateProps;
372
+ options?: {
373
+ useTime?: boolean;
374
+ useWeekDay?: boolean;
375
+ monthFormat?: Intl.DateTimeFormatOptions['month'];
376
+ language?: 'en' | 'id';
377
+ format?: 'default' | 'iso' | 'localized';
378
+ };
379
+ }
380
+ ```
381
+
382
+ ## Dependencies
383
+
384
+ - `Intl.DateTimeFormat` - Native JavaScript API untuk formatting tanggal
385
+ - Tidak memerlukan library eksternal
386
+
387
+ ## Browser/Platform Support
388
+
389
+ Function ini menggunakan `Intl.DateTimeFormat` yang didukung oleh:
390
+
391
+ - ✅ Semua browser modern
392
+ - ✅ React Native (dengan polyfill jika diperlukan)
393
+ - ✅ Node.js
394
+
395
+ ## License
396
+
397
+ MIT
@@ -0,0 +1,54 @@
1
+ import type { DateProps } from '../Calendar/CalendarPropsType';
2
+
3
+ interface DateFormatterProps {
4
+ date: Date | DateProps;
5
+ options?: {
6
+ useTime?: boolean;
7
+ useWeekDay?: boolean;
8
+ monthFormat?: Intl.DateTimeFormatOptions['month'];
9
+ language?: 'en' | 'id';
10
+ format?: 'default' | 'iso' | 'localized';
11
+ };
12
+ }
13
+
14
+ export const dateFormatter = ({ date, options }: DateFormatterProps) => {
15
+ if (!date) return '';
16
+
17
+ const dateObj = new Date(date);
18
+ if (isNaN(dateObj.getTime())) return '';
19
+
20
+ const year = dateObj.getFullYear();
21
+ const month = String(dateObj.getMonth() + 1).padStart(2, '0');
22
+ const day = String(dateObj.getDate()).padStart(2, '0');
23
+ const hours = String(dateObj.getHours()).padStart(2, '0');
24
+ const minutes = String(dateObj.getMinutes()).padStart(2, '0');
25
+ const seconds = String(dateObj.getSeconds()).padStart(2, '0');
26
+
27
+ if (options?.format === 'iso') {
28
+ return `${year}-${month}-${day}${options?.useTime ? ` ${hours}:${minutes}:${seconds}` : ''}`;
29
+ } else if (options?.format === 'localized') {
30
+ const datePart = new Intl.DateTimeFormat(
31
+ options?.language !== 'en' ? 'id-ID' : 'en-GB',
32
+ {
33
+ day: 'numeric',
34
+ month: options?.monthFormat ?? 'long',
35
+ year: 'numeric',
36
+ ...(options?.useWeekDay ? { weekday: 'long' } : {}),
37
+ }
38
+ ).format(dateObj);
39
+
40
+ if (!options?.useTime) return datePart;
41
+
42
+ const timePart = dateObj
43
+ .toLocaleTimeString(options?.language !== 'en' ? 'id-ID' : 'en-GB', {
44
+ hour: '2-digit',
45
+ minute: '2-digit',
46
+ hour12: false,
47
+ })
48
+ .replace('.', ':');
49
+
50
+ return `${datePart} - ${timePart}`;
51
+ } else {
52
+ return `${year}-${month}-${day}`;
53
+ }
54
+ };
package/src/index.tsx CHANGED
@@ -69,7 +69,11 @@ export { default as Provider } from './Provider/Provider';
69
69
  export { default as useFooter } from './Provider/Provider';
70
70
  export { default as Drawing } from './Drawing/Drawing';
71
71
  export { default as Calendar } from './Calendar/Calendar';
72
- export type { DateRangeProps } from './Calendar/CalendarPropsType';
72
+ export type {
73
+ DateRangeProps,
74
+ DateProps,
75
+ CalendarModeType,
76
+ } from './Calendar/CalendarPropsType';
73
77
  export { default as DatePicker } from './DatePicker/DatePicker';
74
78
  export { default as YearPicker } from './DatePicker/YearPicker';
75
79
  export { default as MonthPicker } from './DatePicker/MonthPicker';
@@ -90,3 +94,6 @@ export { default as BadgeIcon } from './BadgeIcon/BadgeIcon';
90
94
  export { default as PdfView } from './FileView/PdfView';
91
95
  export { default as InputSelect } from './Input/InputSelect';
92
96
  export type { ChipValue } from './Chip/type';
97
+ export { default as InputDate } from './Input/InputDate';
98
+ export { dateFormatter } from './function/dateFormatter';
99
+ export { default as ViewInsets } from './Ui/ViewInsets';