@idds/react 1.6.13 → 1.6.15

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 (2) hide show
  1. package/README.md +61 -281
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -24,7 +24,7 @@ Import the styles in your application entry point:
24
24
 
25
25
  ```jsx
26
26
  // src/main.jsx or src/index.jsx
27
- import '@idds/react/style.css';
27
+ import '@idds/react/index.css';
28
28
  ```
29
29
 
30
30
  ### 2. Import and Use Components
@@ -114,26 +114,6 @@ Or use minified versions for production:
114
114
  @import '@idds/styles/tailwind/css/bgn.min.css';
115
115
  ```
116
116
 
117
- Then you can use Tailwind utility classes with INA Digital colors:
118
-
119
- ```jsx
120
- <div className="bg-blue-500 text-white p-4">
121
- <p className="text-guide-500">This text uses guide-500 color</p>
122
- <p className="text-neutral-500">This text uses neutral-500 color</p>
123
- </div>
124
- ```
125
-
126
- **Available brand theme files:**
127
-
128
- - `@idds/styles/tailwind/css/idds.css` - Default theme
129
- - `@idds/styles/tailwind/css/inagov.css` - INAGov brand
130
- - `@idds/styles/tailwind/css/inaku.css` - INAKu brand
131
- - `@idds/styles/tailwind/css/inapas.css` - INAPas brand
132
- - `@idds/styles/tailwind/css/bgn.css` - BGN brand
133
- - `@idds/styles/tailwind/css/bkn.css` - BKN brand
134
- - `@idds/styles/tailwind/css/lan.css` - LAN brand
135
- - `@idds/styles/tailwind/css/panrb.css` - panrb brand
136
-
137
117
  ## Available Components
138
118
 
139
119
  ### Form Components
@@ -225,79 +205,31 @@ setBrandTheme('bgn'); // or 'inagov', 'inaku', 'inapas', 'bkn', 'lan', 'panrb'
225
205
 
226
206
  // Use default theme
227
207
  setBrandTheme('default');
228
-
229
- // Remove brand theme (use default)
230
- setBrandTheme(null);
231
208
  ```
232
209
 
233
- ### Available Brand Themes
234
-
235
- - `'default'` - Default INA Digital theme
236
- - `'inagov'` - INAGov brand theme
237
- - `'inaku'` - INAKu brand theme
238
- - `'inapas'` - INAPas brand theme
239
- - `'bgn'` - BGN brand theme
240
- - `'bkn'` - BKN brand theme
241
- - `'lan'` - LAN brand theme
242
- - `'panrb'` - panrb brand theme
243
-
244
- ### Custom Theme
245
-
246
- You can also set a custom theme:
247
-
248
- ```jsx
249
- import { setCustomTheme } from '@idds/react';
250
-
251
- setCustomTheme({
252
- name: 'custom',
253
- colors: {
254
- primary500: '#0968f6',
255
- primary600: '#0754c4',
256
- // ... other color tokens
257
- },
258
- });
259
- ```
210
+ ### Theme Mode (Light/Dark)
260
211
 
261
- ### Theme Utilities
212
+ You can globally set or toggle the theme mode between light and dark:
262
213
 
263
214
  ```jsx
264
- import {
265
- getCurrentTheme,
266
- getAvailableBrands,
267
- resetTheme,
268
- isValidBrand,
269
- } from '@idds/react';
215
+ import { setThemeMode, toggleThemeMode, getThemeMode } from '@idds/react';
270
216
 
271
- // Get current active theme
272
- const currentTheme = getCurrentTheme();
217
+ // Set specific mode
218
+ setThemeMode('dark'); // or 'light'
273
219
 
274
- // Get available brand names
275
- const brands = getAvailableBrands();
220
+ // Toggle current mode
221
+ toggleThemeMode();
276
222
 
277
- // Reset to default theme
278
- resetTheme();
279
-
280
- // Validate brand name
281
- if (isValidBrand('bgn')) {
282
- setBrandTheme('bgn');
283
- }
223
+ // Get current mode
224
+ const currentMode = getThemeMode();
284
225
  ```
285
226
 
286
227
  ## Utilities
287
228
 
288
- ### Form Utilities
289
-
290
- ```jsx
291
- import { useForm, FormProvider, FormField } from '@idds/react';
292
-
293
- // Form handling with validation
294
- const { handleSubmit, register, errors } = useForm();
295
- ```
296
-
297
229
  ### Confirmation Dialog
298
230
 
299
231
  ```jsx
300
- import { ConfirmationProvider, useConfirmation } from '@idds/react';
232
+ import { ConfirmationProvider, useConfirmation, Button } from '@idds/react';
301
233
 
302
234
  // Wrap your app
303
235
  <ConfirmationProvider>
@@ -305,24 +237,31 @@ import { ConfirmationProvider, useConfirmation } from '@idds/react';
305
237
  </ConfirmationProvider>;
306
238
 
307
239
  // Use in components
308
- const confirm = useConfirmation();
309
-
310
- const handleDelete = async () => {
311
- const result = await confirm({
312
- title: 'Delete Item',
313
- message: 'Are you sure you want to delete this item?',
314
- });
315
-
316
- if (result) {
317
- // User confirmed
318
- }
319
- };
240
+ export default function DeleteItem() {
241
+ const { confirm } = useConfirmation();
242
+
243
+ const handleDelete = async () => {
244
+ const isConfirmed = await confirm({
245
+ title: 'Hapus Data?',
246
+ message: 'Apakah Anda yakin ingin menghapus data ini? Tindakan ini tidak dapat dibatalkan.',
247
+ confirmText: 'Hapus',
248
+ cancelText: 'Batal',
249
+ confirmClassName: 'bg-red-600 hover:bg-red-700 text-white', // Custom class for confirm button
250
+ });
251
+
252
+ if (isConfirmed) {
253
+ console.log('User confirmed deletion');
254
+ }
255
+ };
256
+
257
+ return <Button onClick={handleDelete} className="bg-red-600 hover:bg-red-700 text-white border-none">Hapus Item</Button>;
258
+ }
320
259
  ```
321
260
 
322
261
  ### Toast Notifications
323
262
 
324
263
  ```jsx
325
- import { ToastProvider, useToast } from '@idds/react';
264
+ import { ToastProvider, useToast, Button } from '@idds/react';
326
265
 
327
266
  // Wrap your app
328
267
  <ToastProvider>
@@ -330,12 +269,20 @@ import { ToastProvider, useToast } from '@idds/react';
330
269
  </ToastProvider>;
331
270
 
332
271
  // Use in components
333
- const toast = useToast();
334
-
335
- toast.success('Operation completed successfully!');
336
- toast.error('An error occurred');
337
- toast.info('Information message');
338
- toast.warning('Warning message');
272
+ export default function MyComponent() {
273
+ const { toast } = useToast();
274
+
275
+ const handleShowToast = () => {
276
+ toast({
277
+ state: 'positive',
278
+ title: 'Berhasil',
279
+ description: 'Data berhasil disimpan',
280
+ duration: 3000,
281
+ });
282
+ };
283
+
284
+ return <Button onClick={handleShowToast}>Show Toast</Button>;
285
+ }
339
286
  ```
340
287
 
341
288
  ### Security Utilities
@@ -346,6 +293,8 @@ import {
346
293
  validateInput,
347
294
  encodeHtmlEntities,
348
295
  decodeHtmlEntities,
296
+ sanitizeFileName,
297
+ containsDangerousPatterns,
349
298
  } from '@idds/react';
350
299
 
351
300
  // Sanitize user input
@@ -361,7 +310,11 @@ if (!validation.isValid) {
361
310
  ### File Validation
362
311
 
363
312
  ```jsx
364
- import { validateFile, validateMagicNumber, formatFileSize } from '@idds/react';
313
+ import {
314
+ validateFile,
315
+ validateFileMagicNumber,
316
+ formatFileSize,
317
+ } from '@idds/react';
365
318
 
366
319
  // Validate file
367
320
  const result = validateFile(file, {
@@ -369,199 +322,26 @@ const result = validateFile(file, {
369
322
  maxSize: 5 * 1024 * 1024, // 5MB
370
323
  });
371
324
 
372
- // Validate magic number (file signature)
373
- const magicResult = await validateMagicNumber(file, 'image/png');
374
-
375
325
  // Format file size
376
326
  const formatted = formatFileSize(1024 * 1024); // "1 MB"
377
327
  ```
378
328
 
379
- ### Formatting Utilities
380
-
381
- ```jsx
382
- import {
383
- formattingThousand,
384
- onlyAlphanumeric,
385
- onlyNumericValue,
386
- onlyDecimalNumber,
387
- } from '@idds/react';
388
-
389
- formattingThousand(1000000); // "1,000,000"
390
- onlyAlphanumeric('abc123!@#'); // "abc123"
391
- onlyNumericValue('123abc'); // "123"
392
- onlyDecimalNumber('123.45'); // "123.45"
393
- ```
394
-
395
- ## Component Examples
396
-
397
- ### TextField
398
-
399
- ```jsx
400
- import { TextField } from '@idds/react';
401
-
402
- <TextField
403
- label="Email"
404
- placeholder="Enter your email"
405
- value={email}
406
- onChange={setEmail}
407
- type="email"
408
- required
409
- showClearButton
410
- maxLength={100}
411
- showCharCount
412
- />;
413
- ```
414
-
415
- ### Button
416
-
417
- ```jsx
418
- import { Button } from '@idds/react';
419
-
420
- <Button variant="primary" size="md" onClick={handleClick}>
421
- Submit
422
- </Button>;
423
- ```
424
-
425
- ### SelectDropdown
426
-
427
- ```jsx
428
- import { SelectDropdown } from '@idds/react';
429
-
430
- const options = [
431
- { value: '1', label: 'Option 1' },
432
- { value: '2', label: 'Option 2' },
433
- ];
434
-
435
- <SelectDropdown
436
- label="Select Option"
437
- options={options}
438
- value={selected}
439
- onChange={setSelected}
440
- searchable
441
- clearable
442
- />;
443
- ```
444
-
445
- ### DatePicker
446
-
447
- ```jsx
448
- import { DatePicker } from '@idds/react';
449
-
450
- <DatePicker
451
- label="Select Date"
452
- value={date}
453
- onChange={setDate}
454
- mode="single"
455
- dateFormat="DD/MM/YYYY"
456
- showIcon
457
- showClearButton
458
- />;
459
- ```
460
-
461
- ### Table
462
-
463
- ```jsx
464
- import { Table } from '@idds/react';
465
-
466
- const columns = [
467
- { key: 'name', label: 'Name' },
468
- { key: 'email', label: 'Email' },
469
- ];
470
-
471
- const data = [
472
- { id: 1, name: 'John', email: 'john@example.com' },
473
- { id: 2, name: 'Jane', email: 'jane@example.com' },
474
- ];
475
-
476
- <Table columns={columns} data={data} />;
477
- ```
478
-
479
- ## Styling
480
-
481
- ### CSS Classes
482
-
483
- Components use BEM-like naming conventions:
484
-
485
- - `ina-button` - Base button class
486
- - `ina-button--primary` - Primary variant
487
- - `ina-button--disabled` - Disabled state
488
- - `ina-text-field` - Text field component
489
- - `ina-text-field__input` - Input element
490
- - `ina-text-field__label` - Label element
491
-
492
- ### Custom Styling
493
-
494
- You can override component styles using CSS:
495
-
496
- ```css
497
- .ina-button--primary {
498
- background-color: your-custom-color;
499
- }
500
- ```
501
-
502
- ### Using with Tailwind CSS (Optional)
503
-
504
- If you want to use Tailwind CSS utility classes alongside the design system:
505
-
506
- 1. Install Tailwind CSS in your project
507
- 2. Import color tokens:
508
-
509
- ```js
510
- // tailwind.config.js
511
- import iddsColorTokens from '@idds/react';
512
-
513
- export default {
514
- theme: {
515
- extend: {
516
- colors: iddsColorTokens,
517
- },
518
- },
519
- };
520
- ```
521
-
522
- 3. Use Tailwind classes for custom styling:
523
-
524
- ```jsx
525
- <div className="bg-blue-500 text-white p-4">
526
- <Button>Click me</Button>
527
- </div>
528
- ```
329
+ ### Styling
529
330
 
530
- > **Note:** Tailwind CSS is **optional**. The design system works perfectly without it. Components are fully styled and functional using only the included CSS.
331
+ Components use BEM-like naming conventions (e.g., `ina-button`, `ina-button--primary`). The `@idds/styles` package serves all necessary core styles. Tailwind integration is completely **optional**.
531
332
 
532
333
  ## TypeScript Support
533
334
 
534
- All components are fully typed with TypeScript:
335
+ All components are fully typed and expose their prop types along with their sub-types (e.g. sizes, variants).
535
336
 
536
337
  ```tsx
537
- import { TextField, type TextFieldProps } from '@idds/react';
538
-
539
- const props: TextFieldProps = {
540
- label: 'Email',
541
- value: email,
542
- onChange: setEmail,
543
- };
544
- ```
545
-
546
- ## Development
547
-
548
- ```bash
549
- # Install dependencies
550
- npm install
551
-
552
- # Start development server
553
- npm run dev
554
-
555
- # Build for production
556
- npm run build
557
-
558
- # Type checking
559
- npm run type-check
560
-
561
- # Linting
562
- npm run lint
338
+ import {
339
+ TextField,
340
+ type TextFieldProps,
341
+ type TextFieldSize,
342
+ } from '@idds/react';
563
343
  ```
564
344
 
565
345
  ## License
566
346
 
567
- INA Digital © [Umar Faruq]
347
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idds/react",
3
- "version": "1.6.13",
3
+ "version": "1.6.15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -51,7 +51,7 @@
51
51
  "./*": "./dist/*"
52
52
  },
53
53
  "dependencies": {
54
- "@idds/styles": "^1.6.13",
54
+ "@idds/styles": "^1.6.15",
55
55
  "clsx": "^2.1.1",
56
56
  "react-hook-form": "^7.60.0"
57
57
  },