@aurodesignsystem/auro-formkit 3.0.1 → 3.1.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 (59) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/components/checkbox/README.md +1 -1
  3. package/components/checkbox/demo/api.min.js +468 -25
  4. package/components/checkbox/demo/index.min.js +468 -25
  5. package/components/checkbox/demo/readme.md +1 -1
  6. package/components/checkbox/dist/index.js +468 -25
  7. package/components/checkbox/dist/registered.js +468 -25
  8. package/components/combobox/README.md +1 -1
  9. package/components/combobox/demo/api.min.js +1125 -74
  10. package/components/combobox/demo/index.min.js +1125 -74
  11. package/components/combobox/demo/readme.md +1 -1
  12. package/components/combobox/dist/auro-combobox.d.ts +30 -0
  13. package/components/combobox/dist/index.js +1125 -74
  14. package/components/combobox/dist/registered.js +1125 -74
  15. package/components/counter/README.md +1 -1
  16. package/components/counter/demo/api.min.js +570 -45
  17. package/components/counter/demo/index.min.js +570 -45
  18. package/components/counter/demo/readme.md +1 -1
  19. package/components/counter/dist/index.js +570 -45
  20. package/components/counter/dist/registered.js +570 -45
  21. package/components/datepicker/README.md +1 -1
  22. package/components/datepicker/demo/api.min.js +1073 -70
  23. package/components/datepicker/demo/index.min.js +1073 -70
  24. package/components/datepicker/demo/readme.md +1 -1
  25. package/components/datepicker/dist/index.js +1073 -70
  26. package/components/datepicker/dist/registered.js +1073 -70
  27. package/components/dropdown/README.md +1 -1
  28. package/components/dropdown/demo/api.md +8 -5
  29. package/components/dropdown/demo/api.min.js +104 -22
  30. package/components/dropdown/demo/index.min.js +104 -22
  31. package/components/dropdown/demo/readme.md +1 -1
  32. package/components/dropdown/dist/auro-dropdown.d.ts +29 -0
  33. package/components/dropdown/dist/index.js +104 -22
  34. package/components/dropdown/dist/registered.js +104 -22
  35. package/components/form/README.md +1 -1
  36. package/components/form/demo/readme.md +1 -1
  37. package/components/input/README.md +1 -1
  38. package/components/input/demo/api.md +4 -1
  39. package/components/input/demo/api.min.js +503 -25
  40. package/components/input/demo/index.min.js +503 -25
  41. package/components/input/demo/readme.md +1 -1
  42. package/components/input/dist/base-input.d.ts +24 -0
  43. package/components/input/dist/index.js +503 -25
  44. package/components/input/dist/registered.js +503 -25
  45. package/components/menu/README.md +1 -1
  46. package/components/menu/demo/readme.md +1 -1
  47. package/components/radio/README.md +1 -1
  48. package/components/radio/demo/api.min.js +468 -25
  49. package/components/radio/demo/index.min.js +468 -25
  50. package/components/radio/demo/readme.md +1 -1
  51. package/components/radio/dist/index.js +468 -25
  52. package/components/radio/dist/registered.js +468 -25
  53. package/components/select/README.md +1 -1
  54. package/components/select/demo/api.min.js +570 -45
  55. package/components/select/demo/index.min.js +570 -45
  56. package/components/select/demo/readme.md +1 -1
  57. package/components/select/dist/index.js +570 -45
  58. package/components/select/dist/registered.js +570 -45
  59. package/package.json +2 -2
@@ -333,11 +333,420 @@ var styleCss$1 = css`:host{display:block;padding-bottom:var(--ds-size-150, 0.75r
333
333
 
334
334
  var colorCss$1 = css`:host legend{color:var(--ds-auro-radio-group-label-color)}:host([disabled]){--ds-auro-radio-group-label-color: var(--ds-basic-color-texticon-disabled, #d0d0d0)}:host([onDark]){--ds-auro-radio-group-label-color: var(--ds-basic-color-texticon-inverse, #ffffff)}:host([onDark][disabled]){--ds-auro-radio-group-label-color: var(--ds-basic-color-texticon-inverse-disabled, #7e8894)}`;
335
335
 
336
+ class DateFormatter {
337
+
338
+ constructor() {
339
+
340
+ /**
341
+ * @description Parses a date string into its components.
342
+ * @param {string} dateStr - Date string to parse.
343
+ * @param {string} format - Date format to parse.
344
+ * @returns {Object<key["month" | "day" | "year"]: number>|undefined}
345
+ */
346
+ this.parseDate = (dateStr, format = 'mm/dd/yyyy') => {
347
+
348
+ // Guard Clause: Date string is defined
349
+ if (!dateStr) {
350
+ return undefined;
351
+ }
352
+
353
+ // Assume the separator is a "/" a defined in our code base
354
+ const separator = '/';
355
+
356
+ // Get the parts of the date and format
357
+ const valueParts = dateStr.split(separator);
358
+ const formatParts = format.split(separator);
359
+
360
+ // Check if the value and format have the correct number of parts
361
+ if (valueParts.length !== formatParts.length) {
362
+ throw new Error('AuroDatepickerUtilities | parseDate: Date string and format length do not match');
363
+ }
364
+
365
+ // Holds the result to be returned
366
+ const result = formatParts.reduce((acc, part, index) => {
367
+ const value = valueParts[index];
368
+
369
+ if ((/m/iu).test(part)) {
370
+ acc.month = value;
371
+ } else if ((/d/iu).test(part)) {
372
+ acc.day = value;
373
+ } else if ((/y/iu).test(part)) {
374
+ acc.year = value;
375
+ }
376
+
377
+ return acc;
378
+ }, {});
379
+
380
+ // If we found all the parts, return the result
381
+ if (result.month && result.year) {
382
+ return result;
383
+ }
384
+
385
+ // Throw an error to let the dev know we were unable to parse the date string
386
+ throw new Error('AuroDatepickerUtilities | parseDate: Unable to parse date string');
387
+ };
388
+
389
+ /**
390
+ * Convert a date object to string format.
391
+ * @param {Object} date - Date to convert to string.
392
+ * @returns {Object} Returns the date as a string.
393
+ */
394
+ this.getDateAsString = (date) => date.toLocaleDateString(undefined, {
395
+ year: "numeric",
396
+ month: "2-digit",
397
+ day: "2-digit",
398
+ });
399
+
400
+ /**
401
+ * Converts a date string to a North American date format.
402
+ * @param {String} dateStr - Date to validate.
403
+ * @param {String} format - Date format to validate against.
404
+ * @returns {Boolean}
405
+ */
406
+ this.toNorthAmericanFormat = (dateStr, format) => {
407
+
408
+ if (format === 'mm/dd/yyyy') {
409
+ return dateStr;
410
+ }
411
+
412
+ const parsedDate = this.parseDate(dateStr, format);
413
+
414
+ if (!parsedDate) {
415
+ throw new Error('AuroDatepickerUtilities | toNorthAmericanFormat: Unable to parse date string');
416
+ }
417
+
418
+ const { month, day, year } = parsedDate;
419
+
420
+ const dateParts = [];
421
+ if (month) {
422
+ dateParts.push(month);
423
+ }
424
+
425
+ if (day) {
426
+ dateParts.push(day);
427
+ }
428
+
429
+ if (year) {
430
+ dateParts.push(year);
431
+ }
432
+
433
+ return dateParts.join('/');
434
+ };
435
+ }
436
+ }
437
+ const dateFormatter = new DateFormatter();
438
+
439
+ // filepath: dateConstraints.mjs
440
+ const DATE_UTIL_CONSTRAINTS = {
441
+ maxDay: 31,
442
+ maxMonth: 12,
443
+ maxYear: 2400,
444
+ minDay: 1,
445
+ minMonth: 1,
446
+ minYear: 1900,
447
+ };
448
+
449
+ class AuroDateUtilitiesBase {
450
+
451
+ /**
452
+ * @description The maximum day value allowed by the various utilities in this class.
453
+ * @readonly
454
+ * @type {Number}
455
+ */
456
+ get maxDay() {
457
+ return DATE_UTIL_CONSTRAINTS.maxDay;
458
+ }
459
+
460
+ /**
461
+ * @description The maximum month value allowed by the various utilities in this class.
462
+ * @readonly
463
+ * @type {Number}
464
+ */
465
+ get maxMonth() {
466
+ return DATE_UTIL_CONSTRAINTS.maxMonth;
467
+ }
468
+
469
+ /**
470
+ * @description The maximum year value allowed by the various utilities in this class.
471
+ * @readonly
472
+ * @type {Number}
473
+ */
474
+ get maxYear() {
475
+ return DATE_UTIL_CONSTRAINTS.maxYear;
476
+ }
477
+
478
+ /**
479
+ * @description The minimum day value allowed by the various utilities in this class.
480
+ * @readonly
481
+ * @type {Number}
482
+ */
483
+ get minDay() {
484
+ return DATE_UTIL_CONSTRAINTS.minDay;
485
+ }
486
+
487
+ /**
488
+ * @description The minimum month value allowed by the various utilities in this class.
489
+ * @readonly
490
+ * @type {Number}
491
+ */
492
+ get minMonth() {
493
+ return DATE_UTIL_CONSTRAINTS.minMonth;
494
+ }
495
+
496
+ /**
497
+ * @description The minimum year value allowed by the various utilities in this class.
498
+ * @readonly
499
+ * @type {Number}
500
+ */
501
+ get minYear() {
502
+ return DATE_UTIL_CONSTRAINTS.minYear;
503
+ }
504
+ }
505
+
506
+ /* eslint-disable no-magic-numbers */
507
+
508
+ class AuroDateUtilities extends AuroDateUtilitiesBase {
509
+
510
+ /**
511
+ * Returns the current century.
512
+ * @returns {String} The current century.
513
+ */
514
+ getCentury () {
515
+ return String(new Date().getFullYear()).slice(0, 2);
516
+ }
517
+
518
+ /**
519
+ * Returns a four digit year.
520
+ * @param {String} year - The year to convert to four digits.
521
+ * @returns {String} The four digit year.
522
+ */
523
+ getFourDigitYear (year) {
524
+
525
+ const strYear = String(year).trim();
526
+ return strYear.length <= 2 ? this.getCentury() + strYear : strYear;
527
+ }
528
+
529
+ constructor() {
530
+
531
+ super();
532
+
533
+ /**
534
+ * Compares two dates to see if they match.
535
+ * @param {Object} date1 - First date to compare.
536
+ * @param {Object} date2 - Second date to compare.
537
+ * @returns {Boolean} Returns true if the dates match.
538
+ */
539
+ this.datesMatch = (date1, date2) => new Date(date1).getTime() === new Date(date2).getTime();
540
+
541
+ /**
542
+ * Returns true if value passed in is a valid date.
543
+ * @param {String} date - Date to validate.
544
+ * @param {String} format - Date format to validate against.
545
+ * @returns {Boolean}
546
+ */
547
+ this.validDateStr = (date, format) => {
548
+
549
+ // The length we expect the date string to be
550
+ const dateStrLength = format.length;
551
+
552
+ // Guard Clause: Date and format are defined
553
+ if (typeof date === "undefined" || typeof format === "undefined") {
554
+ throw new Error('AuroDatepickerUtilities | validateDateStr: Date and format are required');
555
+ }
556
+
557
+ // Guard Clause: Date should be of type string
558
+ if (typeof date !== "string") {
559
+ throw new Error('AuroDatepickerUtilities | validateDateStr: Date must be a string');
560
+ }
561
+
562
+ // Guard Clause: Format should be of type string
563
+ if (typeof format !== "string") {
564
+ throw new Error('AuroDatepickerUtilities | validateDateStr: Format must be a string');
565
+ }
566
+
567
+ // Guard Clause: Length is what we expect it to be
568
+ if (date.length !== dateStrLength) {
569
+ return false;
570
+ }
571
+ // Get a formatted date string and parse it
572
+ const dateParts = dateFormatter.parseDate(date, format);
573
+
574
+ // Guard Clause: Date parse succeeded
575
+ if (!dateParts) {
576
+ return false;
577
+ }
578
+
579
+ // Create the expected date string based on the date parts
580
+ const expectedDateStr = `${dateParts.month}/${dateParts.day || "01"}/${this.getFourDigitYear(dateParts.year)}`;
581
+
582
+ // Generate a date object that we will extract a string date from to compare to the passed in date string
583
+ const dateObj = new Date(this.getFourDigitYear(dateParts.year), dateParts.month - 1, dateParts.day || 1);
584
+
585
+ // Get the date string of the date object we created from the string date
586
+ const actualDateStr = dateFormatter.getDateAsString(dateObj);
587
+
588
+ // Guard Clause: Generated date matches date string input
589
+ if (expectedDateStr !== actualDateStr) {
590
+ return false;
591
+ }
592
+
593
+ // If we passed all other checks, we can assume the date is valid
594
+ return true;
595
+ };
596
+
597
+ /**
598
+ * Determines if a string date value matches the format provided.
599
+ * @param {string} value = The date string value.
600
+ * @param { string} format = The date format to match against.
601
+ * @returns {boolean}
602
+ */
603
+ this.dateAndFormatMatch = (value, format) => {
604
+
605
+ // Ensure we have both values we need to do the comparison
606
+ if (!value || !format) {
607
+ throw new Error('AuroFormValidation | dateFormatMatch: value and format are required');
608
+ }
609
+
610
+ // If the lengths are different, they cannot match
611
+ if (value.length !== format.length) {
612
+ return false;
613
+ }
614
+
615
+ // Get the parts of the date
616
+ const dateParts = dateFormatter.parseDate(value, format);
617
+
618
+ // Validator for day
619
+ const dayValueIsValid = (day) => {
620
+
621
+ // Guard clause: if there is no day in the dateParts, we can ignore this check.
622
+ if (!dateParts.day) {
623
+ return true;
624
+ }
625
+
626
+ // Guard clause: ensure day exists.
627
+ if (!day) {
628
+ return false;
629
+ }
630
+
631
+ // Convert day to number
632
+ const numDay = Number.parseInt(day, 10);
633
+
634
+ // Guard clause: ensure day is a valid integer
635
+ if (Number.isNaN(numDay)) {
636
+ throw new Error('AuroDatepickerUtilities | dayValueIsValid: Unable to parse day value integer');
637
+ }
638
+
639
+ // Guard clause: ensure day is within the valid range
640
+ if (numDay < this.minDay || numDay > this.maxDay) {
641
+ return false;
642
+ }
643
+
644
+ // Default return
645
+ return true;
646
+ };
647
+
648
+ // Validator for month
649
+ const monthValueIsValid = (month) => {
650
+
651
+ // Guard clause: ensure month exists.
652
+ if (!month) {
653
+ return false;
654
+ }
655
+
656
+ // Convert month to number
657
+ const numMonth = Number.parseInt(month, 10);
658
+
659
+ // Guard clause: ensure month is a valid integer
660
+ if (Number.isNaN(numMonth)) {
661
+ throw new Error('AuroDatepickerUtilities | monthValueIsValid: Unable to parse month value integer');
662
+ }
663
+
664
+ // Guard clause: ensure month is within the valid range
665
+ if (numMonth < this.minMonth || numMonth > this.maxMonth) {
666
+ return false;
667
+ }
668
+
669
+ // Default return
670
+ return true;
671
+ };
672
+
673
+ // Validator for year
674
+ const yearIsValid = (_year) => {
675
+
676
+ // Guard clause: ensure year exists.
677
+ if (!_year) {
678
+ return false;
679
+ }
680
+
681
+ // Get the full year
682
+ const year = this.getFourDigitYear(_year);
683
+
684
+ // Convert year to number
685
+ const numYear = Number.parseInt(year, 10);
686
+
687
+ // Guard clause: ensure year is a valid integer
688
+ if (Number.isNaN(numYear)) {
689
+ throw new Error('AuroDatepickerUtilities | yearValueIsValid: Unable to parse year value integer');
690
+ }
691
+
692
+ // Guard clause: ensure year is within the valid range
693
+ if (numYear < this.minYear || numYear > this.maxYear) {
694
+ return false;
695
+ }
696
+
697
+ // Default return
698
+ return true;
699
+ };
700
+
701
+ // Self-contained checks for month, day, and year
702
+ const checks = [
703
+ monthValueIsValid(dateParts.month),
704
+ dayValueIsValid(dateParts.day),
705
+ yearIsValid(dateParts.year)
706
+ ];
707
+
708
+ // If any of the checks failed, the date format does not match and the result is invalid
709
+ const isValid = checks.every((check) => check === true);
710
+
711
+ // If the check is invalid, return false
712
+ if (!isValid) {
713
+ return false;
714
+ }
715
+
716
+ // Default case
717
+ return true;
718
+ };
719
+ }
720
+ }
721
+
722
+ // Export a class instance
723
+ const dateUtilities = new AuroDateUtilities();
724
+
725
+ // Export the class instance methods individually
726
+ const {
727
+ datesMatch,
728
+ validDateStr,
729
+ dateAndFormatMatch,
730
+ minDay,
731
+ minMonth,
732
+ minYear,
733
+ maxDay,
734
+ maxMonth,
735
+ maxYear
736
+ } = dateUtilities;
737
+
738
+ const {
739
+ toNorthAmericanFormat,
740
+ parseDate,
741
+ getDateAsString
742
+ } = dateFormatter;
743
+
336
744
  // Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
337
745
  // See LICENSE in the project root for license information.
338
746
 
339
747
 
340
748
  class AuroFormValidation {
749
+
341
750
  constructor() {
342
751
  this.runtimeUtils = new AuroLibraryRuntimeUtils$1();
343
752
  }
@@ -429,17 +838,17 @@ class AuroFormValidation {
429
838
  ]
430
839
  }
431
840
  };
432
-
841
+
433
842
  let elementType;
434
843
  if (this.runtimeUtils.elementMatch(elem, 'auro-input')) {
435
844
  elementType = 'input';
436
845
  } else if (this.runtimeUtils.elementMatch(elem, 'auro-counter') || this.runtimeUtils.elementMatch(elem, 'auro-counter-group')) {
437
846
  elementType = 'counter';
438
847
  }
439
-
848
+
440
849
  if (elementType) {
441
850
  const rules = validationRules[elementType];
442
-
851
+
443
852
  if (rules) {
444
853
  Object.values(rules).flat().forEach(rule => {
445
854
  if (rule.check(elem)) {
@@ -465,48 +874,82 @@ class AuroFormValidation {
465
874
  if (!elem.value.match(emailRegex)) {
466
875
  elem.validity = 'patternMismatch';
467
876
  elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
877
+ return;
468
878
  }
469
879
  } else if (elem.type === 'credit-card') {
470
880
  if (elem.value.length > 0 && elem.value.length < elem.validationCCLength) {
471
881
  elem.validity = 'tooShort';
472
882
  elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
883
+ return;
473
884
  }
474
885
  } else if (elem.type === 'number') {
475
886
  if (elem.max !== undefined && Number(elem.max) < Number(elem.value)) {
476
887
  elem.validity = 'rangeOverflow';
477
888
  elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
889
+ return;
478
890
  }
479
891
 
480
892
  if (elem.min !== undefined && elem.value?.length > 0 && Number(elem.min) > Number(elem.value)) {
481
893
  elem.validity = 'rangeUnderflow';
482
894
  elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
895
+ return;
483
896
  }
484
- } else if (elem.type === 'date') {
485
- if (elem.value?.length > 0 && elem.value?.length < elem.lengthForType) {
897
+ } else if (elem.type === 'date' && elem.value?.length > 0) {
898
+
899
+ // Guard Clause: if the value is too short
900
+ if (elem.value.length < elem.lengthForType) {
901
+
486
902
  elem.validity = 'tooShort';
487
903
  elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
488
- } else if (elem.value?.length === elem.lengthForType && elem.util.toNorthAmericanFormat(elem.value, elem.format)) {
489
- const formattedValue = elem.util.toNorthAmericanFormat(elem.value, elem.format);
490
- const valueDate = new Date(formattedValue.dateForComparison);
491
-
492
- // validate max
493
- if (elem.max?.length === elem.lengthForType) {
494
- const maxDate = new Date(elem.util.toNorthAmericanFormat(elem.max, elem.format).dateForComparison);
495
-
496
- if (valueDate > maxDate) {
497
- elem.validity = 'rangeOverflow';
498
- elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
499
- }
904
+ return;
905
+ }
906
+
907
+ // Guard Clause: If the value is too long for the type
908
+ if (elem.value?.length > elem.lengthForType) {
909
+
910
+ elem.validity = 'tooLong';
911
+ elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
912
+ return;
913
+ }
914
+
915
+ // Validate that the date passed was the correct format
916
+ if (!dateAndFormatMatch(elem.value, elem.format)) {
917
+ elem.validity = 'patternMismatch';
918
+ elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || 'Invalid Date Format Entered';
919
+ return;
920
+ }
921
+
922
+ // Validate that the date passed was a valid date
923
+ if (!validDateStr(elem.value, elem.format)) {
924
+ elem.validity = 'invalidDate';
925
+ elem.errorMessage = elem.setCustomValidityInvalidDate || elem.setCustomValidity || 'Invalid Date Entered';
926
+ return;
927
+ }
928
+
929
+ // Perform the rest of the validation
930
+ const formattedValue = toNorthAmericanFormat(elem.value, elem.format);
931
+ const valueDate = new Date(formattedValue);
932
+
933
+ // // Validate max date
934
+ if (elem.max?.length === elem.lengthForType) {
935
+
936
+ const maxDate = new Date(toNorthAmericanFormat(elem.max, elem.format));
937
+
938
+ if (valueDate > maxDate) {
939
+ elem.validity = 'rangeOverflow';
940
+ elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
941
+ return;
500
942
  }
943
+ }
501
944
 
502
- // validate min
503
- if (elem.min?.length === elem.lengthForType) {
504
- const minDate = new Date(elem.util.toNorthAmericanFormat(elem.min, elem.format).dateForComparison);
945
+ // Validate min date
946
+ if (elem.min?.length === elem.lengthForType) {
947
+ const minDate = new Date(toNorthAmericanFormat(elem.min, elem.format));
505
948
 
506
- if (valueDate < minDate) {
507
- elem.validity = 'rangeUnderflow';
508
- elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
509
- }
949
+ if (valueDate < minDate) {
950
+ elem.validity = 'rangeUnderflow';
951
+ elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
952
+ return;
510
953
  }
511
954
  }
512
955
  }
@@ -625,7 +1068,7 @@ class AuroFormValidation {
625
1068
  if (input.validationMessage.length > 0) {
626
1069
  elem.errorMessage = input.validationMessage;
627
1070
  }
628
- } else if (this.inputElements?.length > 0 && elem.errorMessage === '') {
1071
+ } else if (this.inputElements?.length > 0 && elem.errorMessage === '') {
629
1072
  const firstInput = this.inputElements[0];
630
1073
 
631
1074
  if (firstInput.validationMessage.length > 0) {
@@ -111,7 +111,7 @@ The use of any Auro custom element has a dependency on the [Auro Design Tokens](
111
111
  In cases where the project is not able to process JS assets, there are pre-processed assets available for use. Legacy browsers such as IE11 are no longer supported.
112
112
 
113
113
  ```html
114
- <script type="module" src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit@3.0.0/auro-select/+esm"></script>
114
+ <script type="module" src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit@3.0.1/auro-select/+esm"></script>
115
115
  ```
116
116
  <!-- AURO-GENERATED-CONTENT:END -->
117
117