carbon-react 103.2.0 → 104.2.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 (77) hide show
  1. package/lib/__internal__/popover/popover.component.js +2 -6
  2. package/lib/__internal__/tooltip-provider/index.d.ts +1 -0
  3. package/lib/__internal__/tooltip-provider/index.js +6 -3
  4. package/lib/components/button/button.component.d.ts +21 -1
  5. package/lib/components/button/button.component.js +63 -52
  6. package/lib/components/date/__internal__/date-formats/index.d.ts +8 -0
  7. package/lib/components/date/__internal__/date-formats/index.js +47 -0
  8. package/lib/components/date/__internal__/date-picker/date-picker.component.d.ts +3 -0
  9. package/lib/components/date/__internal__/date-picker/date-picker.component.js +154 -0
  10. package/lib/components/date/__internal__/date-picker/date-picker.d.ts +25 -0
  11. package/lib/components/date/{day-picker.style.d.ts → __internal__/date-picker/day-picker.style.d.ts} +0 -0
  12. package/lib/components/date/{day-picker.style.js → __internal__/date-picker/day-picker.style.js} +5 -1
  13. package/lib/components/date/__internal__/date-picker/index.d.ts +1 -0
  14. package/lib/{__internal__/date → components/date/__internal__/date-picker}/index.js +2 -2
  15. package/lib/components/date/{navbar → __internal__/navbar}/button.style.d.ts +0 -0
  16. package/lib/components/date/{navbar → __internal__/navbar}/button.style.js +1 -1
  17. package/lib/components/date/{navbar → __internal__/navbar}/index.d.ts +0 -0
  18. package/lib/components/date/{navbar → __internal__/navbar}/index.js +0 -0
  19. package/lib/components/date/{navbar → __internal__/navbar}/navbar.component.d.ts +0 -0
  20. package/lib/components/date/{navbar → __internal__/navbar}/navbar.component.js +10 -12
  21. package/lib/components/date/__internal__/navbar/navbar.d.ts +8 -0
  22. package/lib/components/date/{navbar → __internal__/navbar}/navbar.style.d.ts +0 -0
  23. package/lib/components/date/{navbar → __internal__/navbar}/navbar.style.js +1 -1
  24. package/lib/components/date/__internal__/utils.d.ts +19 -0
  25. package/lib/components/date/__internal__/utils.js +182 -0
  26. package/lib/components/date/{weekday → __internal__/weekday}/abbr.style.d.ts +0 -0
  27. package/lib/components/date/{weekday → __internal__/weekday}/abbr.style.js +0 -0
  28. package/lib/components/date/{weekday → __internal__/weekday}/index.d.ts +0 -0
  29. package/lib/components/date/{weekday → __internal__/weekday}/index.js +0 -0
  30. package/lib/components/date/{weekday → __internal__/weekday}/weekday.component.d.ts +0 -0
  31. package/lib/components/date/{weekday → __internal__/weekday}/weekday.component.js +0 -0
  32. package/lib/components/date/__internal__/weekday/weekday.d.ts +13 -0
  33. package/lib/components/date/{weekday → __internal__/weekday}/weekday.style.d.ts +0 -0
  34. package/lib/components/date/{weekday → __internal__/weekday}/weekday.style.js +1 -1
  35. package/lib/components/date/date.component.d.ts +27 -55
  36. package/lib/components/date/date.component.js +291 -661
  37. package/lib/components/date/date.d.ts +28 -20
  38. package/lib/components/date/date.style.js +3 -2
  39. package/lib/components/date/index.js +2 -10
  40. package/lib/components/date-range/date-range-context.d.ts +17 -0
  41. package/lib/components/date-range/date-range.component.d.ts +3 -5
  42. package/lib/components/date-range/date-range.component.js +123 -119
  43. package/lib/components/date-range/date-range.context.d.ts +3 -0
  44. package/lib/components/date-range/date-range.context.js +14 -0
  45. package/lib/components/date-range/date-range.d.ts +5 -7
  46. package/lib/components/date-range/date-range.style.js +1 -0
  47. package/lib/components/date-range/index.d.ts +1 -0
  48. package/lib/components/i18n-provider/i18n-provider.component.d.ts +1 -4
  49. package/lib/components/i18n-provider/i18n-provider.component.js +1 -4
  50. package/lib/components/icon/icon.component.js +4 -2
  51. package/lib/components/icon-button/icon-button.component.js +11 -19
  52. package/lib/components/portal/portal.js +3 -6
  53. package/lib/components/step-sequence/step-sequence-item/step-sequence-item.style.js +13 -23
  54. package/lib/components/tooltip/tooltip.component.js +7 -7
  55. package/lib/components/tooltip/tooltip.d.ts +1 -0
  56. package/lib/locales/date-fns-locales/index.d.ts +1 -0
  57. package/lib/locales/date-fns-locales/index.js +18 -0
  58. package/lib/locales/en-gb.js +3 -4
  59. package/lib/locales/locale.d.ts +3 -4
  60. package/lib/locales/pl-pl.d.ts +1 -1
  61. package/lib/locales/pl-pl.js +5 -0
  62. package/lib/style/design-tokens/carbon-scoped-tokens-provider/carbon-scoped-tokens-provider.component.d.ts +7 -5
  63. package/lib/style/design-tokens/carbon-scoped-tokens-provider/carbon-scoped-tokens-provider.component.js +11 -36
  64. package/lib/style/themes/aegean/aegean-theme.config.d.ts +1 -0
  65. package/lib/style/themes/aegean/aegean-theme.config.js +2 -1
  66. package/lib/style/themes/base/base-theme.config.d.ts +162 -93
  67. package/lib/style/themes/mint/mint-theme.config.d.ts +1 -0
  68. package/lib/style/themes/mint/mint-theme.config.js +2 -1
  69. package/lib/style/themes/sage/index.d.ts +162 -93
  70. package/package.json +6 -5
  71. package/lib/__internal__/date/date.d.ts +0 -34
  72. package/lib/__internal__/date/date.js +0 -216
  73. package/lib/__internal__/date/index.d.ts +0 -1
  74. package/lib/__spec_helper__/mock-date-helper.d.ts +0 -1
  75. package/lib/__spec_helper__/mock-date-helper.js +0 -37
  76. package/lib/components/date/date-picker.component.d.ts +0 -22
  77. package/lib/components/date/date-picker.component.js +0 -218
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseDate = parseDate;
7
+ exports.formatToISO = formatToISO;
8
+ exports.formattedValue = formattedValue;
9
+ exports.isDateValid = isDateValid;
10
+ exports.additionalYears = additionalYears;
11
+ exports.findMatchedFormatAndValue = findMatchedFormatAndValue;
12
+ exports.parseISODate = parseISODate;
13
+ exports.getDisabledDays = getDisabledDays;
14
+ exports.checkISOFormatAndLength = checkISOFormatAndLength;
15
+ exports.getSeparator = void 0;
16
+
17
+ var _fp = require("date-fns/fp");
18
+
19
+ function parseDate(formatString, valueString) {
20
+ if (!valueString || !formatString) return "";
21
+ return (0, _fp.parse)(new Date(), formatString, valueString);
22
+ }
23
+
24
+ function formatToISO(formatString, valueString) {
25
+ const dateValue = parseDate(formatString, valueString);
26
+
27
+ if (!isDateValid(dateValue)) {
28
+ return null;
29
+ }
30
+
31
+ return (0, _fp.formatISO)(dateValue).split("T")[0];
32
+ }
33
+
34
+ function formattedValue(formatString, value) {
35
+ return (0, _fp.format)(formatString, value);
36
+ }
37
+
38
+ function isDateValid(date) {
39
+ return date && date.toString() !== "Invalid Date";
40
+ }
41
+
42
+ function hasMatchedFormat(formatString, valueString) {
43
+ return formatString.length === valueString.length && (0, _fp.isMatch)(formatString, valueString);
44
+ }
45
+
46
+ function additionalYears(formatString, value) {
47
+ if (formatString.split("y").length - 1 !== 2) {
48
+ return [formatString, value];
49
+ }
50
+
51
+ let year = value.substring(value.length - 2);
52
+ const dayAndMonth = value.substring(0, value.length - 2);
53
+ const yearAsNumber = Number(year);
54
+
55
+ if (yearAsNumber < 69) {
56
+ year = String(2000 + yearAsNumber);
57
+ } else {
58
+ year = String(1900 + yearAsNumber);
59
+ }
60
+
61
+ return [`${formatString.substring(0, formatString.length - 2)}yyyy`, `${dayAndMonth}${year}`];
62
+ }
63
+
64
+ function makeSeparatedValues(arr, str) {
65
+ return arr.map((_, i) => str.substring(arr[i], arr[i + 1]));
66
+ }
67
+
68
+ function checkForCompleteMatch(formatArray, valueArray) {
69
+ return formatArray.every((formatString, i) => hasMatchedFormat(formatString, valueArray[i]));
70
+ }
71
+
72
+ function findMatchWithNoSeparators(valueString, formatString) {
73
+ const indexArray = formatString.split("").reduce((arr, char, index) => {
74
+ if (index === 0 || char !== formatString[index - 1]) {
75
+ return [...arr, index];
76
+ }
77
+
78
+ return arr;
79
+ }, []);
80
+ const formatArray = makeSeparatedValues(indexArray, formatString);
81
+ const valueArray = makeSeparatedValues(indexArray, valueString);
82
+
83
+ if (checkForCompleteMatch(formatArray, valueArray)) {
84
+ return [formatArray.join("."), valueArray.join(".")];
85
+ }
86
+
87
+ return null;
88
+ }
89
+
90
+ function findMatchWithSeparators(valueString, formatString, separator) {
91
+ const formatArray = formatString.split(separator);
92
+ const valueArray = valueString.split(separator);
93
+
94
+ if (checkForCompleteMatch(formatArray, valueArray)) {
95
+ return [formatString, valueString];
96
+ }
97
+
98
+ return null;
99
+ }
100
+
101
+ const getSeparator = value => {
102
+ const separator = ["", ".", ",", "-", "/", " ", ":"].slice(1).find(char => value.includes(char));
103
+ return separator || "";
104
+ };
105
+
106
+ exports.getSeparator = getSeparator;
107
+
108
+ function findMatchedFormatAndValue(valueString, formats) {
109
+ if (!valueString) {
110
+ return ["", ""];
111
+ }
112
+
113
+ const valueSeparator = getSeparator(valueString);
114
+ const filteredFormats = formats.filter(formatString => formatString.length === valueString.length && getSeparator(formatString) === valueSeparator);
115
+ const matchedFormatAndValue = filteredFormats.reduce((acc, formatString) => {
116
+ const formatSeparator = getSeparator(formatString);
117
+
118
+ if (valueSeparator === "" && formatSeparator === "") {
119
+ // This check is added as there is a bug in date-fns https://github.com/date-fns/date-fns/issues/2785
120
+ // it incorrectly matches or fails to parse valid dates with no separators
121
+ const match = findMatchWithNoSeparators(valueString, formatString);
122
+
123
+ if (match) {
124
+ return match;
125
+ }
126
+ }
127
+
128
+ if (valueSeparator && formatSeparator && valueSeparator === formatSeparator) {
129
+ const match = findMatchWithSeparators(valueString, formatString, valueSeparator);
130
+
131
+ if (match) {
132
+ return match;
133
+ }
134
+ }
135
+
136
+ return acc;
137
+ }, []);
138
+ return matchedFormatAndValue;
139
+ }
140
+
141
+ function parseISODate(value) {
142
+ return (0, _fp.parseISO)(value);
143
+ }
144
+ /**
145
+ * Returns the disabled array of days specified by props maxDate and minDate
146
+ */
147
+
148
+
149
+ function getDisabledDays(minDate, maxDate) {
150
+ const days = [];
151
+
152
+ if (!minDate && !maxDate) {
153
+ return null;
154
+ }
155
+
156
+ if (checkISOFormatAndLength(minDate)) {
157
+ days.push({
158
+ before: parseISODate(minDate)
159
+ });
160
+ }
161
+
162
+ if (checkISOFormatAndLength(maxDate)) {
163
+ days.push({
164
+ after: parseISODate(maxDate)
165
+ });
166
+ }
167
+
168
+ return days;
169
+ }
170
+
171
+ function checkISOFormatAndLength(value) {
172
+ if (!value || value.length !== 10 || !isValidISODate(value)) {
173
+ return false;
174
+ }
175
+
176
+ const array = value.split("-");
177
+ return array.length === 3 && array[0].length === 4 && array[1].length === 2 && array[2].length === 2;
178
+ }
179
+
180
+ function isValidISODate(dateString) {
181
+ return parseISODate(dateString).toString() !== "Invalid Date";
182
+ }
@@ -0,0 +1,13 @@
1
+ import * as React from "react";
2
+
3
+ export interface WeekdayProps {
4
+ className?: string;
5
+ title?: string;
6
+ children?: React.ReactNode;
7
+ }
8
+
9
+ declare function Weekday(
10
+ props: WeekdayProps & React.RefAttributes<HTMLElement>
11
+ ): JSX.Element;
12
+
13
+ export default Weekday;
@@ -7,7 +7,7 @@ exports.default = void 0;
7
7
 
8
8
  var _styledComponents = _interopRequireDefault(require("styled-components"));
9
9
 
10
- var _base = _interopRequireDefault(require("../../../style/themes/base"));
10
+ var _base = _interopRequireDefault(require("../../../../style/themes/base"));
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
@@ -1,57 +1,29 @@
1
1
  export default DateInput;
2
- export const defaultDateFormat: "DD/MM/YYYY";
3
- export class BaseDateInput extends React.Component<any, any, any> {
4
- constructor(props: Readonly<any>);
5
- constructor(props: any, context?: any);
6
- localeData: {
7
- locale: any;
8
- formats: any;
9
- format: any;
10
- };
11
- isBlurBlocked: boolean;
12
- isOpening: boolean;
13
- inputHasFocus: any;
14
- isControlled: boolean;
15
- initialVisibleValue: any;
16
- inputFocusedViaPicker: boolean;
17
- hasMounted: boolean;
18
- inputPresentationRef: React.RefObject<any>;
19
- isAutoFocused: boolean | undefined;
20
- hasValueChanged: (prevProps: any) => any;
21
- assignInput: (input: any) => void;
22
- input: any;
23
- shouldAllowBlur: () => any;
24
- shouldBlockBlur: () => boolean;
25
- handleBlur: () => void;
26
- handleFocus: (ev: any) => void;
27
- handleKeyDown: (ev: any) => void;
28
- openDatePicker: (openedOnMount: any) => void;
29
- updateValidEventValues: (value: any) => void;
30
- reformatVisibleDate: () => void;
31
- closeDatePicker: () => void;
32
- handleClick: (event: any) => void;
33
- handleDateSelect: (selectedDate: any) => void;
34
- updateVisibleValue: (date: any) => void;
35
- focusInput: () => void;
36
- handleVisibleInputChange: (ev: any) => void;
37
- updateSelectedDate: (newValue: any) => void;
38
- getDateObject: (newValue: any) => any;
39
- emitOnChangeCallback: (ev: any, isoFormattedValue: any) => void;
40
- canBeEmptyValues: (value: any) => any;
41
- buildCustomEvent: (ev: any, isoFormattedValue: any) => any;
42
- renderDatePicker: (dateRangeProps: any) => JSX.Element | null;
43
- markCurrentDatepicker: () => void;
44
- hiddenValue: () => any;
45
- renderHiddenInput: () => JSX.Element;
2
+ declare function DateInput({ adaptiveLabelBreakpoint, allowEmptyValue, autoFocus, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, disabled, disablePortal, helpAriaLabel, labelInline, minDate, maxDate, onBlur, onChange, onClick, onFocus, onKeyDown, pickerProps, readOnly, size, tooltipPosition, value, ...rest }: {
3
+ [x: string]: any;
4
+ adaptiveLabelBreakpoint: any;
5
+ allowEmptyValue: any;
6
+ autoFocus: any;
7
+ "data-component": any;
8
+ "data-element": any;
9
+ "data-role": any;
10
+ disabled: any;
11
+ disablePortal?: boolean | undefined;
12
+ helpAriaLabel: any;
13
+ labelInline: any;
14
+ minDate: any;
15
+ maxDate: any;
16
+ onBlur: any;
17
+ onChange: any;
18
+ onClick: any;
19
+ onFocus: any;
20
+ onKeyDown: any;
21
+ pickerProps?: {} | undefined;
22
+ readOnly: any;
23
+ size?: string | undefined;
24
+ tooltipPosition: any;
25
+ value: any;
26
+ }): JSX.Element;
27
+ declare namespace DateInput {
28
+ const propTypes: any;
46
29
  }
47
- export namespace BaseDateInput {
48
- export { LocaleContext as contextType };
49
- export const propTypes: any;
50
- export const defaultProps: {
51
- disablePortal: boolean;
52
- "data-component": string;
53
- };
54
- }
55
- declare const DateInput: JSX.Element;
56
- import React from "react";
57
- import LocaleContext from "../../__internal__/i18n-context";