@aurodesignsystem-dev/auro-formkit 0.0.0-pr1483.2 → 0.0.0-pr1488.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/components/checkbox/demo/customize.min.js +436 -14
  2. package/components/checkbox/demo/getting-started.min.js +436 -14
  3. package/components/checkbox/demo/index.min.js +436 -14
  4. package/components/checkbox/dist/index.js +436 -14
  5. package/components/checkbox/dist/registered.js +436 -14
  6. package/components/combobox/demo/customize.min.js +1482 -6618
  7. package/components/combobox/demo/getting-started.min.js +1482 -6618
  8. package/components/combobox/demo/index.min.js +1482 -6618
  9. package/components/combobox/demo/keyboard-behavior.md +68 -8
  10. package/components/combobox/dist/index.js +1489 -6625
  11. package/components/combobox/dist/registered.js +1489 -6625
  12. package/components/counter/demo/customize.min.js +437 -15
  13. package/components/counter/demo/index.min.js +437 -15
  14. package/components/counter/dist/index.js +436 -14
  15. package/components/counter/dist/registered.js +436 -14
  16. package/components/datepicker/demo/api.md +3 -10
  17. package/components/datepicker/demo/customize.md +6 -6
  18. package/components/datepicker/demo/index.md +4 -4
  19. package/components/datepicker/demo/index.min.js +2319 -7650
  20. package/components/datepicker/dist/index.js +2319 -7650
  21. package/components/datepicker/dist/registered.js +2319 -7650
  22. package/components/datepicker/dist/src/auro-calendar.d.ts +0 -6
  23. package/components/datepicker/dist/src/auro-datepicker.d.ts +11 -24
  24. package/components/datepicker/dist/src/utilities.d.ts +40 -14
  25. package/components/datepicker/dist/src/utilitiesCalendar.d.ts +1 -1
  26. package/components/dropdown/demo/customize.min.js +1 -1
  27. package/components/dropdown/demo/getting-started.min.js +1 -1
  28. package/components/dropdown/demo/index.min.js +1 -1
  29. package/components/dropdown/dist/index.js +1 -1
  30. package/components/dropdown/dist/registered.js +1 -1
  31. package/components/form/demo/customize.min.js +44181 -58516
  32. package/components/form/demo/getting-started.min.js +44181 -58516
  33. package/components/form/demo/index.min.js +44181 -58516
  34. package/components/form/demo/registerDemoDeps.min.js +44181 -58516
  35. package/components/input/demo/api.md +51 -57
  36. package/components/input/demo/customize.md +0 -160
  37. package/components/input/demo/customize.min.js +1011 -6565
  38. package/components/input/demo/getting-started.md +0 -11
  39. package/components/input/demo/getting-started.min.js +1010 -6564
  40. package/components/input/demo/index.md +3 -28
  41. package/components/input/demo/index.min.js +1010 -6564
  42. package/components/input/dist/auro-input.d.ts +6 -25
  43. package/components/input/dist/base-input.d.ts +69 -82
  44. package/components/input/dist/index.d.ts +1 -2
  45. package/components/input/dist/index.js +1003 -6599
  46. package/components/input/dist/registered.js +1010 -6564
  47. package/components/input/dist/utilities.d.ts +9 -68
  48. package/components/radio/demo/index.min.js +436 -14
  49. package/components/radio/dist/index.js +436 -14
  50. package/components/radio/dist/registered.js +436 -14
  51. package/components/select/demo/customize.min.js +455 -31
  52. package/components/select/demo/getting-started.min.js +455 -31
  53. package/components/select/demo/index.min.js +455 -31
  54. package/components/select/demo/keyboard-behavior.md +54 -8
  55. package/components/select/dist/index.js +455 -31
  56. package/components/select/dist/registered.js +455 -31
  57. package/custom-elements.json +2117 -2625
  58. package/package.json +4 -4
  59. package/components/input/dist/auro-input-util.d.ts +0 -17
@@ -434,6 +434,415 @@ var styleCss$1 = css`:host{display:block;padding-bottom:var(--ds-size-150, 0.75r
434
434
 
435
435
  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]),:host([appearance=inverse]){--ds-auro-radio-group-label-color: var(--ds-basic-color-texticon-inverse, #ffffff)}:host([onDark][disabled]),:host([appearance=inverse][disabled]){--ds-auro-radio-group-label-color: var(--ds-basic-color-texticon-inverse-disabled, #7e8894)}`;
436
436
 
437
+ class DateFormatter {
438
+
439
+ constructor() {
440
+
441
+ /**
442
+ * @description Parses a date string into its components.
443
+ * @param {string} dateStr - Date string to parse.
444
+ * @param {string} format - Date format to parse.
445
+ * @returns {Object<key["month" | "day" | "year"]: number>|undefined}
446
+ */
447
+ this.parseDate = (dateStr, format = 'mm/dd/yyyy') => {
448
+
449
+ // Guard Clause: Date string is defined
450
+ if (!dateStr) {
451
+ return undefined;
452
+ }
453
+
454
+ // Assume the separator is a "/" a defined in our code base
455
+ const separator = '/';
456
+
457
+ // Get the parts of the date and format
458
+ const valueParts = dateStr.split(separator);
459
+ const formatParts = format.split(separator);
460
+
461
+ // Check if the value and format have the correct number of parts
462
+ if (valueParts.length !== formatParts.length) {
463
+ throw new Error('AuroDatepickerUtilities | parseDate: Date string and format length do not match');
464
+ }
465
+
466
+ // Holds the result to be returned
467
+ const result = formatParts.reduce((acc, part, index) => {
468
+ const value = valueParts[index];
469
+
470
+ if ((/m/iu).test(part)) {
471
+ acc.month = value;
472
+ } else if ((/d/iu).test(part)) {
473
+ acc.day = value;
474
+ } else if ((/y/iu).test(part)) {
475
+ acc.year = value;
476
+ }
477
+
478
+ return acc;
479
+ }, {});
480
+
481
+ // If we found all the parts, return the result
482
+ if (result.month && result.year) {
483
+ return result;
484
+ }
485
+
486
+ // Throw an error to let the dev know we were unable to parse the date string
487
+ throw new Error('AuroDatepickerUtilities | parseDate: Unable to parse date string');
488
+ };
489
+
490
+ /**
491
+ * Convert a date object to string format.
492
+ * @param {Object} date - Date to convert to string.
493
+ * @param {String} locale - Optional locale to use for the date string. Defaults to user's locale.
494
+ * @returns {String} Returns the date as a string.
495
+ */
496
+ this.getDateAsString = (date, locale = undefined) => date.toLocaleDateString(locale, {
497
+ year: "numeric",
498
+ month: "2-digit",
499
+ day: "2-digit",
500
+ });
501
+
502
+ /**
503
+ * Converts a date string to a North American date format.
504
+ * @param {String} dateStr - Date to validate.
505
+ * @param {String} format - Date format to validate against.
506
+ * @returns {Boolean}
507
+ */
508
+ this.toNorthAmericanFormat = (dateStr, format) => {
509
+
510
+ if (format === 'mm/dd/yyyy') {
511
+ return dateStr;
512
+ }
513
+
514
+ const parsedDate = this.parseDate(dateStr, format);
515
+
516
+ if (!parsedDate) {
517
+ throw new Error('AuroDatepickerUtilities | toNorthAmericanFormat: Unable to parse date string');
518
+ }
519
+
520
+ const { month, day, year } = parsedDate;
521
+
522
+ const dateParts = [];
523
+ if (month) {
524
+ dateParts.push(month);
525
+ }
526
+
527
+ if (day) {
528
+ dateParts.push(day);
529
+ }
530
+
531
+ if (year) {
532
+ dateParts.push(year);
533
+ }
534
+
535
+ return dateParts.join('/');
536
+ };
537
+ }
538
+ }
539
+ const dateFormatter = new DateFormatter();
540
+
541
+ // filepath: dateConstraints.mjs
542
+ const DATE_UTIL_CONSTRAINTS = {
543
+ maxDay: 31,
544
+ maxMonth: 12,
545
+ maxYear: 2400,
546
+ minDay: 1,
547
+ minMonth: 1,
548
+ minYear: 1900,
549
+ };
550
+
551
+ class AuroDateUtilitiesBase {
552
+
553
+ /**
554
+ * @description The maximum day value allowed by the various utilities in this class.
555
+ * @readonly
556
+ * @type {Number}
557
+ */
558
+ get maxDay() {
559
+ return DATE_UTIL_CONSTRAINTS.maxDay;
560
+ }
561
+
562
+ /**
563
+ * @description The maximum month value allowed by the various utilities in this class.
564
+ * @readonly
565
+ * @type {Number}
566
+ */
567
+ get maxMonth() {
568
+ return DATE_UTIL_CONSTRAINTS.maxMonth;
569
+ }
570
+
571
+ /**
572
+ * @description The maximum year value allowed by the various utilities in this class.
573
+ * @readonly
574
+ * @type {Number}
575
+ */
576
+ get maxYear() {
577
+ return DATE_UTIL_CONSTRAINTS.maxYear;
578
+ }
579
+
580
+ /**
581
+ * @description The minimum day value allowed by the various utilities in this class.
582
+ * @readonly
583
+ * @type {Number}
584
+ */
585
+ get minDay() {
586
+ return DATE_UTIL_CONSTRAINTS.minDay;
587
+ }
588
+
589
+ /**
590
+ * @description The minimum month value allowed by the various utilities in this class.
591
+ * @readonly
592
+ * @type {Number}
593
+ */
594
+ get minMonth() {
595
+ return DATE_UTIL_CONSTRAINTS.minMonth;
596
+ }
597
+
598
+ /**
599
+ * @description The minimum year value allowed by the various utilities in this class.
600
+ * @readonly
601
+ * @type {Number}
602
+ */
603
+ get minYear() {
604
+ return DATE_UTIL_CONSTRAINTS.minYear;
605
+ }
606
+ }
607
+
608
+ /* eslint-disable no-magic-numbers */
609
+
610
+ class AuroDateUtilities extends AuroDateUtilitiesBase {
611
+
612
+ /**
613
+ * Returns the current century.
614
+ * @returns {String} The current century.
615
+ */
616
+ getCentury () {
617
+ return String(new Date().getFullYear()).slice(0, 2);
618
+ }
619
+
620
+ /**
621
+ * Returns a four digit year.
622
+ * @param {String} year - The year to convert to four digits.
623
+ * @returns {String} The four digit year.
624
+ */
625
+ getFourDigitYear (year) {
626
+
627
+ const strYear = String(year).trim();
628
+ return strYear.length <= 2 ? this.getCentury() + strYear : strYear;
629
+ }
630
+
631
+ constructor() {
632
+
633
+ super();
634
+
635
+ /**
636
+ * Compares two dates to see if they match.
637
+ * @param {Object} date1 - First date to compare.
638
+ * @param {Object} date2 - Second date to compare.
639
+ * @returns {Boolean} Returns true if the dates match.
640
+ */
641
+ this.datesMatch = (date1, date2) => new Date(date1).getTime() === new Date(date2).getTime();
642
+
643
+ /**
644
+ * Returns true if value passed in is a valid date.
645
+ * @param {String} date - Date to validate.
646
+ * @param {String} format - Date format to validate against.
647
+ * @returns {Boolean}
648
+ */
649
+ this.validDateStr = (date, format) => {
650
+
651
+ // The length we expect the date string to be
652
+ const dateStrLength = format.length;
653
+
654
+ // Guard Clause: Date and format are defined
655
+ if (typeof date === "undefined" || typeof format === "undefined") {
656
+ throw new Error('AuroDatepickerUtilities | validateDateStr: Date and format are required');
657
+ }
658
+
659
+ // Guard Clause: Date should be of type string
660
+ if (typeof date !== "string") {
661
+ throw new Error('AuroDatepickerUtilities | validateDateStr: Date must be a string');
662
+ }
663
+
664
+ // Guard Clause: Format should be of type string
665
+ if (typeof format !== "string") {
666
+ throw new Error('AuroDatepickerUtilities | validateDateStr: Format must be a string');
667
+ }
668
+
669
+ // Guard Clause: Length is what we expect it to be
670
+ if (date.length !== dateStrLength) {
671
+ return false;
672
+ }
673
+ // Get a formatted date string and parse it
674
+ const dateParts = dateFormatter.parseDate(date, format);
675
+
676
+ // Guard Clause: Date parse succeeded
677
+ if (!dateParts) {
678
+ return false;
679
+ }
680
+
681
+ // Create the expected date string based on the date parts
682
+ const expectedDateStr = `${dateParts.month}/${dateParts.day || "01"}/${this.getFourDigitYear(dateParts.year)}`;
683
+
684
+ // Generate a date object that we will extract a string date from to compare to the passed in date string
685
+ const dateObj = new Date(this.getFourDigitYear(dateParts.year), dateParts.month - 1, dateParts.day || 1);
686
+
687
+ // Get the date string of the date object we created from the string date
688
+ const actualDateStr = dateFormatter.getDateAsString(dateObj, "en-US");
689
+
690
+ // Guard Clause: Generated date matches date string input
691
+ if (expectedDateStr !== actualDateStr) {
692
+ return false;
693
+ }
694
+
695
+ // If we passed all other checks, we can assume the date is valid
696
+ return true;
697
+ };
698
+
699
+ /**
700
+ * Determines if a string date value matches the format provided.
701
+ * @param {string} value = The date string value.
702
+ * @param { string} format = The date format to match against.
703
+ * @returns {boolean}
704
+ */
705
+ this.dateAndFormatMatch = (value, format) => {
706
+
707
+ // Ensure we have both values we need to do the comparison
708
+ if (!value || !format) {
709
+ throw new Error('AuroFormValidation | dateFormatMatch: value and format are required');
710
+ }
711
+
712
+ // If the lengths are different, they cannot match
713
+ if (value.length !== format.length) {
714
+ return false;
715
+ }
716
+
717
+ // Get the parts of the date
718
+ const dateParts = dateFormatter.parseDate(value, format);
719
+
720
+ // Validator for day
721
+ const dayValueIsValid = (day) => {
722
+
723
+ // Guard clause: if there is no day in the dateParts, we can ignore this check.
724
+ if (!dateParts.day) {
725
+ return true;
726
+ }
727
+
728
+ // Guard clause: ensure day exists.
729
+ if (!day) {
730
+ return false;
731
+ }
732
+
733
+ // Convert day to number
734
+ const numDay = Number.parseInt(day, 10);
735
+
736
+ // Guard clause: ensure day is a valid integer
737
+ if (Number.isNaN(numDay)) {
738
+ throw new Error('AuroDatepickerUtilities | dayValueIsValid: Unable to parse day value integer');
739
+ }
740
+
741
+ // Guard clause: ensure day is within the valid range
742
+ if (numDay < this.minDay || numDay > this.maxDay) {
743
+ return false;
744
+ }
745
+
746
+ // Default return
747
+ return true;
748
+ };
749
+
750
+ // Validator for month
751
+ const monthValueIsValid = (month) => {
752
+
753
+ // Guard clause: ensure month exists.
754
+ if (!month) {
755
+ return false;
756
+ }
757
+
758
+ // Convert month to number
759
+ const numMonth = Number.parseInt(month, 10);
760
+
761
+ // Guard clause: ensure month is a valid integer
762
+ if (Number.isNaN(numMonth)) {
763
+ throw new Error('AuroDatepickerUtilities | monthValueIsValid: Unable to parse month value integer');
764
+ }
765
+
766
+ // Guard clause: ensure month is within the valid range
767
+ if (numMonth < this.minMonth || numMonth > this.maxMonth) {
768
+ return false;
769
+ }
770
+
771
+ // Default return
772
+ return true;
773
+ };
774
+
775
+ // Validator for year
776
+ const yearIsValid = (_year) => {
777
+
778
+ // Guard clause: ensure year exists.
779
+ if (!_year) {
780
+ return false;
781
+ }
782
+
783
+ // Get the full year
784
+ const year = this.getFourDigitYear(_year);
785
+
786
+ // Convert year to number
787
+ const numYear = Number.parseInt(year, 10);
788
+
789
+ // Guard clause: ensure year is a valid integer
790
+ if (Number.isNaN(numYear)) {
791
+ throw new Error('AuroDatepickerUtilities | yearValueIsValid: Unable to parse year value integer');
792
+ }
793
+
794
+ // Guard clause: ensure year is within the valid range
795
+ if (numYear < this.minYear || numYear > this.maxYear) {
796
+ return false;
797
+ }
798
+
799
+ // Default return
800
+ return true;
801
+ };
802
+
803
+ // Self-contained checks for month, day, and year
804
+ const checks = [
805
+ monthValueIsValid(dateParts.month),
806
+ dayValueIsValid(dateParts.day),
807
+ yearIsValid(dateParts.year)
808
+ ];
809
+
810
+ // If any of the checks failed, the date format does not match and the result is invalid
811
+ const isValid = checks.every((check) => check === true);
812
+
813
+ // If the check is invalid, return false
814
+ if (!isValid) {
815
+ return false;
816
+ }
817
+
818
+ // Default case
819
+ return true;
820
+ };
821
+ }
822
+ }
823
+
824
+ // Export a class instance
825
+ const dateUtilities = new AuroDateUtilities();
826
+
827
+ // Export the class instance methods individually
828
+ const {
829
+ datesMatch,
830
+ validDateStr,
831
+ dateAndFormatMatch,
832
+ minDay,
833
+ minMonth,
834
+ minYear,
835
+ maxDay,
836
+ maxMonth,
837
+ maxYear
838
+ } = dateUtilities;
839
+
840
+ const {
841
+ toNorthAmericanFormat,
842
+ parseDate,
843
+ getDateAsString
844
+ } = dateFormatter;
845
+
437
846
  // Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
438
847
  // See LICENSE in the project root for license information.
439
848
 
@@ -575,7 +984,7 @@ class AuroFormValidation {
575
984
  validity: 'valueMissing',
576
985
  message: e => e.getAttribute('setCustomValidityValueMissingFilter') || e.setCustomValidity || ''
577
986
  }
578
- ]
987
+ ]
579
988
  }
580
989
  };
581
990
 
@@ -640,12 +1049,12 @@ class AuroFormValidation {
640
1049
 
641
1050
  // Guard Clause: if the value is too short
642
1051
  if (elem.value?.length < elem.lengthForType) {
643
-
1052
+
644
1053
  elem.validity = 'tooShort';
645
1054
  elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
646
1055
  return;
647
- }
648
-
1056
+ }
1057
+
649
1058
  // Guard Clause: If the value is too long for the type
650
1059
  if (elem.value?.length > elem.lengthForType) {
651
1060
 
@@ -653,20 +1062,31 @@ class AuroFormValidation {
653
1062
  elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
654
1063
  return;
655
1064
  }
656
-
657
- // Validate that the date passed was the correct format and is a valid date
658
- if (elem.value && !elem.valueObject) {
1065
+
1066
+ // Validate that the date passed was the correct format
1067
+ if (!dateAndFormatMatch(elem.value, elem.format)) {
659
1068
  elem.validity = 'patternMismatch';
660
- elem.errorMessage = elem.setCustomValidityPatternMismatch || elem.setCustomValidity || 'Invalid Date Format Entered';
1069
+ elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || 'Invalid Date Format Entered';
1070
+ return;
1071
+ }
1072
+
1073
+ // Validate that the date passed was a valid date
1074
+ if (!validDateStr(elem.value, elem.format)) {
1075
+ elem.validity = 'invalidDate';
1076
+ elem.errorMessage = elem.setCustomValidityInvalidDate || elem.setCustomValidity || 'Invalid Date Entered';
661
1077
  return;
662
1078
  }
663
1079
 
664
1080
  // Perform the rest of the validation
1081
+ const formattedValue = toNorthAmericanFormat(elem.value, elem.format);
1082
+ const valueDate = new Date(formattedValue);
665
1083
 
666
1084
  // // Validate max date
667
1085
  if (elem.max?.length === elem.lengthForType) {
668
1086
 
669
- if (elem.valueObject > elem.maxObject) {
1087
+ const maxDate = new Date(toNorthAmericanFormat(elem.max, elem.format));
1088
+
1089
+ if (valueDate > maxDate) {
670
1090
  elem.validity = 'rangeOverflow';
671
1091
  elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
672
1092
  return;
@@ -675,7 +1095,9 @@ class AuroFormValidation {
675
1095
 
676
1096
  // Validate min date
677
1097
  if (elem.min?.length === elem.lengthForType) {
678
- if (elem.valueObject < elem.minObject) {
1098
+ const minDate = new Date(toNorthAmericanFormat(elem.min, elem.format));
1099
+
1100
+ if (valueDate < minDate) {
679
1101
  elem.validity = 'rangeUnderflow';
680
1102
  elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
681
1103
  return;
@@ -735,7 +1157,7 @@ class AuroFormValidation {
735
1157
  if (typeof elem.value === "string") {
736
1158
  hasValue = elem.value && elem.value.length > 0;
737
1159
  }
738
-
1160
+
739
1161
  if (typeof elem.value === "boolean") {
740
1162
  hasValue = elem.value || elem.value === false;
741
1163
  }
@@ -760,7 +1182,7 @@ class AuroFormValidation {
760
1182
  }
761
1183
 
762
1184
  const isCombobox = this.runtimeUtils.elementMatch(elem, 'auro-combobox');
763
-
1185
+
764
1186
  if (isCombobox) {
765
1187
 
766
1188
  if (!elem.persistInput || elem.behavior === "filter") {
@@ -800,7 +1222,7 @@ class AuroFormValidation {
800
1222
  }
801
1223
 
802
1224
  // multiple input in one components (datepicker)
803
- // combobox has 2 inputs but no need to check validity on the 2nd one which is in fullscreen bib.
1225
+ // combobox has 2 inputs but no need to check validity on the 2nd one which is in fullscreen bib.
804
1226
  if (elem.validity === 'valid' && this.auroInputElements.length > 1 && !isCombobox) {
805
1227
  elem.validity = this.auroInputElements[1].validity;
806
1228
  elem.errorMessage = this.auroInputElements[1].errorMessage;
@@ -1151,7 +1573,7 @@ class AuroHelpText extends LitElement {
1151
1573
  }
1152
1574
  }
1153
1575
 
1154
- var formkitVersion = '202605271836';
1576
+ var formkitVersion = '202605292307';
1155
1577
 
1156
1578
  // Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
1157
1579
  // See LICENSE in the project root for license information.