@atlaskit/datetime-picker 13.0.10 → 13.0.12

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 (42) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/components/date-picker.js +30 -90
  3. package/dist/cjs/components/date-time-picker.js +14 -65
  4. package/dist/cjs/components/time-picker.js +11 -24
  5. package/dist/cjs/internal/date-time-picker-container.js +84 -0
  6. package/dist/cjs/internal/fixed-layer-menu.js +29 -0
  7. package/dist/cjs/internal/menu.js +57 -0
  8. package/dist/cjs/internal/parse-date.js +30 -0
  9. package/dist/es2019/components/date-picker.js +7 -67
  10. package/dist/es2019/components/date-time-picker.js +12 -63
  11. package/dist/es2019/components/time-picker.js +5 -16
  12. package/dist/es2019/internal/date-time-picker-container.js +77 -0
  13. package/dist/es2019/internal/fixed-layer-menu.js +20 -0
  14. package/dist/es2019/internal/menu.js +48 -0
  15. package/dist/es2019/internal/parse-date.js +22 -0
  16. package/dist/esm/components/date-picker.js +23 -83
  17. package/dist/esm/components/date-time-picker.js +12 -63
  18. package/dist/esm/components/time-picker.js +8 -21
  19. package/dist/esm/internal/date-time-picker-container.js +76 -0
  20. package/dist/esm/internal/fixed-layer-menu.js +23 -0
  21. package/dist/esm/internal/menu.js +49 -0
  22. package/dist/esm/internal/parse-date.js +22 -0
  23. package/dist/types/components/date-picker.d.ts +2 -3
  24. package/dist/types/components/date-time-picker.d.ts +2 -2
  25. package/dist/types/components/time-picker.d.ts +2 -2
  26. package/dist/types/internal/date-time-picker-container.d.ts +15 -0
  27. package/dist/types/internal/fixed-layer-menu.d.ts +7 -0
  28. package/dist/types/internal/menu.d.ts +7 -0
  29. package/dist/types/internal/parse-date.d.ts +11 -0
  30. package/dist/types-ts4.5/components/date-picker.d.ts +2 -3
  31. package/dist/types-ts4.5/components/date-time-picker.d.ts +2 -2
  32. package/dist/types-ts4.5/components/time-picker.d.ts +2 -2
  33. package/dist/types-ts4.5/internal/date-time-picker-container.d.ts +15 -0
  34. package/dist/types-ts4.5/internal/fixed-layer-menu.d.ts +7 -0
  35. package/dist/types-ts4.5/internal/menu.d.ts +7 -0
  36. package/dist/types-ts4.5/internal/parse-date.d.ts +11 -0
  37. package/package.json +2 -2
  38. /package/dist/cjs/{components/utils.js → internal/parse-tokens.js} +0 -0
  39. /package/dist/es2019/{components/utils.js → internal/parse-tokens.js} +0 -0
  40. /package/dist/esm/{components/utils.js → internal/parse-tokens.js} +0 -0
  41. /package/dist/types/{components/utils.d.ts → internal/parse-tokens.d.ts} +0 -0
  42. /package/dist/types-ts4.5/{components/utils.d.ts → internal/parse-tokens.d.ts} +0 -0
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getSafeCalendarValue = getSafeCalendarValue;
7
+ exports.getShortISOString = getShortISOString;
8
+ exports.getValidDate = getValidDate;
9
+ var _dateFns = require("date-fns");
10
+ var _parseTokens = require("./parse-tokens");
11
+ function getValidDate(iso) {
12
+ var date = (0, _dateFns.parseISO)(iso);
13
+ return (0, _dateFns.isValid)(date) ? {
14
+ day: date.getDate(),
15
+ month: date.getMonth() + 1,
16
+ year: date.getFullYear()
17
+ } : {};
18
+ }
19
+ function getShortISOString(date) {
20
+ return (0, _dateFns.format)(date, (0, _parseTokens.convertTokens)('YYYY-MM-DD'));
21
+ }
22
+ function getSafeCalendarValue(calendarValue) {
23
+ // If `calendarValue` has a year that is greater than 9999, default to
24
+ // today's date
25
+ var yearIsOverLimit = calendarValue.match(/^\d{5,}/);
26
+ if (yearIsOverLimit) {
27
+ return getShortISOString(new Date());
28
+ }
29
+ return calendarValue;
30
+ }
@@ -1,70 +1,22 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  /** @jsx jsx */
4
4
  import { Component } from 'react';
5
- import { css, jsx } from '@emotion/react';
5
+ import { jsx } from '@emotion/react';
6
6
  import { format, isValid, lastDayOfMonth, parseISO } from 'date-fns';
7
7
  import pick from 'lodash/pick';
8
8
  import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
9
- import Calendar from '@atlaskit/calendar';
10
9
  import CalendarIcon from '@atlaskit/icon/glyph/calendar';
11
- import { UNSAFE_LAYERING } from '@atlaskit/layering';
12
10
  import { createLocalizationProvider } from '@atlaskit/locale';
13
11
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
14
12
  import Select, { mergeStyles } from '@atlaskit/select';
15
- import { N0, N50A, N60A } from '@atlaskit/theme/colors';
16
- import { layers } from '@atlaskit/theme/constants';
17
13
  import { defaultDateFormat, EmptyComponent, padToTwo, placeholderDatetime } from '../internal';
18
- import FixedLayer from '../internal/fixed-layer';
14
+ import { Menu } from '../internal/menu';
15
+ import { getSafeCalendarValue, getShortISOString } from '../internal/parse-date';
16
+ import { convertTokens } from '../internal/parse-tokens';
19
17
  import { makeSingleValue } from '../internal/single-value';
20
- import { convertTokens } from './utils';
21
18
  const packageName = "@atlaskit/datetime-picker";
22
- const packageVersion = "13.0.10";
23
- function getValidDate(iso) {
24
- const date = parseISO(iso);
25
- return isValid(date) ? {
26
- day: date.getDate(),
27
- month: date.getMonth() + 1,
28
- year: date.getFullYear()
29
- } : {};
30
- }
31
- function getShortISOString(date) {
32
- return format(date, convertTokens('YYYY-MM-DD'));
33
- }
34
- const menuStyles = css({
35
- zIndex: layers.dialog(),
36
- backgroundColor: `var(--ds-surface-overlay, ${N0})`,
37
- borderRadius: "var(--ds-border-radius, 3px)",
38
- boxShadow: `var(--ds-shadow-overlay, ${`0 4px 8px -2px ${N50A}, 0 0 1px ${N60A}`})`,
39
- overflow: 'hidden'
40
- });
41
- const Menu = ({
42
- selectProps,
43
- innerProps
44
- }) => jsx(UNSAFE_LAYERING, {
45
- isDisabled: getBooleanFF('platform.design-system-team.layering_qmiw3') ? false : true
46
- }, jsx(FixedLayer, {
47
- inputValue: selectProps.inputValue,
48
- containerRef: selectProps.calendarContainerRef,
49
- content: jsx("div", _extends({
50
- css: menuStyles
51
- }, innerProps), jsx(Calendar, _extends({}, getValidDate(selectProps.calendarValue), getValidDate(selectProps.calendarView), {
52
- disabled: selectProps.calendarDisabled,
53
- disabledDateFilter: selectProps.calendarDisabledDateFilter,
54
- minDate: selectProps.calendarMinDate,
55
- maxDate: selectProps.calendarMaxDate,
56
- nextMonthLabel: selectProps.nextMonthLabel,
57
- onChange: selectProps.onCalendarChange,
58
- onSelect: selectProps.onCalendarSelect,
59
- previousMonthLabel: selectProps.previousMonthLabel,
60
- calendarRef: selectProps.calendarRef,
61
- selected: [selectProps.calendarValue],
62
- locale: selectProps.calendarLocale,
63
- testId: selectProps.testId && `${selectProps.testId}--calendar`,
64
- weekStartDay: selectProps.calendarWeekStartDay
65
- }))),
66
- testId: selectProps.testId
67
- }));
19
+ const packageVersion = "13.0.12";
68
20
  const datePickerDefaultProps = {
69
21
  appearance: 'default',
70
22
  autoFocus: false,
@@ -210,15 +162,6 @@ class DatePicker extends Component {
210
162
  isOpen: true
211
163
  });
212
164
  });
213
- _defineProperty(this, "getSafeCalendarValue", calendarValue => {
214
- // If `calendarValue` has a year that is greater than 9999, default to
215
- // today's date
216
- const yearIsOverLimit = calendarValue.match(/^\d{5,}/);
217
- if (yearIsOverLimit) {
218
- return getShortISOString(new Date());
219
- }
220
- return calendarValue;
221
- });
222
165
  _defineProperty(this, "onInputKeyDown", event => {
223
166
  var _this$containerRef3;
224
167
  const {
@@ -262,12 +205,9 @@ class DatePicker extends Component {
262
205
  // for more details.
263
206
  event.preventDefault();
264
207
  if (!this.isDateDisabled(calendarValue)) {
265
- const {
266
- value
267
- } = this.getSafeState();
268
208
  // Get a safe `calendarValue` in case the value exceeds the maximum
269
209
  // allowed by ISO 8601
270
- const safeCalendarValue = this.getSafeCalendarValue(calendarValue);
210
+ const safeCalendarValue = getSafeCalendarValue(calendarValue);
271
211
  const valueChanged = safeCalendarValue !== value;
272
212
  this.setState({
273
213
  selectInputValue: '',
@@ -7,68 +7,15 @@ import { format, isValid, parseISO } from 'date-fns';
7
7
  import pick from 'lodash/pick';
8
8
  import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
9
9
  import SelectClearIcon from '@atlaskit/icon/glyph/select-clear';
10
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
11
10
  import { mergeStyles } from '@atlaskit/select';
12
- import { B100, N0, N100, N20, N30, N500, N70, R400 } from '@atlaskit/theme/colors';
11
+ import { N500, N70 } from '@atlaskit/theme/colors';
13
12
  import { defaultTimes, formatDateTimeZoneIntoIso } from '../internal';
13
+ import { DateTimePickerContainer } from '../internal/date-time-picker-container';
14
+ import { convertTokens } from '../internal/parse-tokens';
14
15
  import DatePicker from './date-picker';
15
16
  import TimePicker from './time-picker';
16
- import { convertTokens } from './utils';
17
17
  const packageName = "@atlaskit/datetime-picker";
18
- const packageVersion = "13.0.10";
19
- const isInvalidBorderStyles = css({
20
- borderColor: `var(--ds-border-danger, ${R400})`
21
- });
22
- const isFocusedBorderStyles = css({
23
- borderColor: `var(--ds-border-focused, ${B100})`
24
- });
25
- const isFocusedStyles = css({
26
- backgroundColor: `var(--ds-background-input-pressed, ${N0})`
27
- });
28
- const subtleBgStyles = css({
29
- backgroundColor: 'transparent',
30
- borderColor: 'transparent'
31
- });
32
- const subtleFocusedBgStyles = css({
33
- backgroundColor: "var(--ds-background-input-pressed, transparent)",
34
- borderColor: 'transparent'
35
- });
36
- const noBgStyles = css({
37
- backgroundColor: 'transparent',
38
- borderColor: 'transparent',
39
- '&:hover': {
40
- backgroundColor: 'transparent',
41
- borderColor: 'transparent'
42
- }
43
- });
44
- const hoverStyles = css({
45
- '&:hover': {
46
- backgroundColor: `var(--ds-background-input-hovered, ${N30})`,
47
- borderColor: `var(--ds-border-input, ${getBooleanFF('platform.design-system-team.border-checkbox_nyoiu') ? N100 : N30})`
48
- }
49
- });
50
- const isInvalidHoverStyles = css({
51
- '&:hover': {
52
- backgroundColor: `var(--ds-background-input-hovered, ${N0})`,
53
- borderColor: `var(--ds-border-danger, ${R400})`
54
- }
55
- });
56
- const isDisabledStyles = css({
57
- '&:hover': {
58
- cursor: 'default'
59
- }
60
- });
61
- const baseContainerStyles = css({
62
- display: 'flex',
63
- backgroundColor: `var(--ds-background-input, ${N20})`,
64
- border: getBooleanFF('platform.design-system-team.update-input-border-wdith_5abwv') ? `${"var(--ds-border-width, 1px)"} solid ${`var(--ds-border-input, ${N100})`}` : `2px solid ${`var(--ds-border-input, ${N20})`}`,
65
- borderRadius: "var(--ds-border-radius, 3px)",
66
- transition: 'background-color 200ms ease-in-out, border-color 200ms ease-in-out',
67
- '&:hover': {
68
- cursor: 'pointer'
69
- }
70
- });
71
-
18
+ const packageVersion = "13.0.12";
72
19
  // Make DatePicker 50% the width of DateTimePicker
73
20
  // If rendering an icon container, shrink the TimePicker
74
21
  const datePickerContainerStyles = css({
@@ -290,12 +237,14 @@ class DateTimePicker extends React.Component {
290
237
  // Render DateTimePicker's IconContainer when a value has been filled
291
238
  // Don't use Date or TimePicker's because they can't be customised
292
239
  const isClearable = Boolean(dateValue || timeValue);
293
- const notFocusedOrIsDisabled = !(isFocused || isDisabled);
294
- return jsx("div", _extends({
295
- css: [baseContainerStyles, isDisabled && isDisabledStyles, isFocused && isFocusedStyles, bothProps.appearance === 'subtle' && (isFocused ? subtleFocusedBgStyles : subtleBgStyles), isFocused && isFocusedBorderStyles, bothProps.isInvalid && isInvalidBorderStyles, notFocusedOrIsDisabled && (bothProps.isInvalid ? isInvalidHoverStyles : hoverStyles), bothProps.appearance === 'none' && noBgStyles]
296
- }, innerProps, {
297
- "data-testid": testId
298
- }), jsx("input", {
240
+ return jsx(DateTimePickerContainer, {
241
+ appearance: bothProps.appearance,
242
+ isDisabled: isDisabled,
243
+ isFocused: isFocused,
244
+ isInvalid: bothProps.isInvalid,
245
+ testId: testId,
246
+ innerProps: innerProps
247
+ }, jsx("input", {
299
248
  name: name,
300
249
  type: "hidden",
301
250
  value: value,
@@ -1,5 +1,5 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  import React from 'react';
4
4
 
5
5
  // eslint-disable-next-line no-restricted-imports
@@ -7,16 +7,16 @@ import { format, isValid } from 'date-fns';
7
7
  import pick from 'lodash/pick';
8
8
  import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
9
9
  import { createLocalizationProvider } from '@atlaskit/locale';
10
- import Select, { components, CreatableSelect, mergeStyles } from '@atlaskit/select';
10
+ import Select, { CreatableSelect, mergeStyles } from '@atlaskit/select';
11
11
  // eslint-disable-next-line @atlaskit/design-system/no-deprecated-imports
12
12
  import { gridSize } from '@atlaskit/theme/constants';
13
13
  import { defaultTimeFormat, defaultTimes, EmptyComponent, placeholderDatetime } from '../internal';
14
- import FixedLayer from '../internal/fixed-layer';
14
+ import { FixedLayerMenu } from '../internal/fixed-layer-menu';
15
15
  import parseTime from '../internal/parse-time';
16
+ import { convertTokens } from '../internal/parse-tokens';
16
17
  import { makeSingleValue } from '../internal/single-value';
17
- import { convertTokens } from './utils';
18
18
  const packageName = "@atlaskit/datetime-picker";
19
- const packageVersion = "13.0.10";
19
+ const packageVersion = "13.0.12";
20
20
  const menuStyles = {
21
21
  /* Need to remove default absolute positioning as that causes issues with position fixed */
22
22
  position: 'static',
@@ -25,17 +25,6 @@ const menuStyles = {
25
25
  /* React-Popper has already offset the menu so we need to reset the margin, otherwise the offset value is doubled */
26
26
  margin: 0
27
27
  };
28
- const FixedLayerMenu = ({
29
- selectProps,
30
- ...rest
31
- }) => /*#__PURE__*/React.createElement(FixedLayer, {
32
- inputValue: selectProps.inputValue,
33
- containerRef: selectProps.fixedLayerRef,
34
- content: /*#__PURE__*/React.createElement(components.Menu, _extends({}, rest, {
35
- menuShouldScrollIntoView: false
36
- })),
37
- testId: selectProps.testId
38
- });
39
28
  const timePickerDefaultProps = {
40
29
  appearance: 'default',
41
30
  autoFocus: false,
@@ -0,0 +1,77 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ /** @jsx jsx */
3
+ import { css, jsx } from '@emotion/react';
4
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
+ import { B100, N0, N100, N20, N30, R400 } from '@atlaskit/theme/colors';
6
+ const isInvalidBorderStyles = css({
7
+ borderColor: `var(--ds-border-danger, ${R400})`
8
+ });
9
+ const isFocusedBorderStyles = css({
10
+ borderColor: `var(--ds-border-focused, ${B100})`
11
+ });
12
+ const isFocusedStyles = css({
13
+ backgroundColor: `var(--ds-background-input-pressed, ${N0})`
14
+ });
15
+ const subtleBgStyles = css({
16
+ backgroundColor: 'transparent',
17
+ borderColor: 'transparent'
18
+ });
19
+ const subtleFocusedBgStyles = css({
20
+ backgroundColor: "var(--ds-background-input-pressed, transparent)",
21
+ borderColor: 'transparent'
22
+ });
23
+ const noBgStyles = css({
24
+ backgroundColor: 'transparent',
25
+ borderColor: 'transparent',
26
+ '&:hover': {
27
+ backgroundColor: 'transparent',
28
+ borderColor: 'transparent'
29
+ }
30
+ });
31
+ const hoverStyles = css({
32
+ '&:hover': {
33
+ backgroundColor: `var(--ds-background-input-hovered, ${N30})`,
34
+ borderColor: `var(--ds-border-input, ${getBooleanFF('platform.design-system-team.border-checkbox_nyoiu') ? N100 : N30})`
35
+ }
36
+ });
37
+ const isInvalidHoverStyles = css({
38
+ '&:hover': {
39
+ backgroundColor: `var(--ds-background-input-hovered, ${N0})`,
40
+ borderColor: `var(--ds-border-danger, ${R400})`
41
+ }
42
+ });
43
+ const isDisabledStyles = css({
44
+ '&:hover': {
45
+ cursor: 'default'
46
+ }
47
+ });
48
+ const baseContainerStyles = css({
49
+ display: 'flex',
50
+ backgroundColor: `var(--ds-background-input, ${N20})`,
51
+ border: getBooleanFF('platform.design-system-team.update-input-border-wdith_5abwv') ? `${"var(--ds-border-width, 1px)"} solid ${`var(--ds-border-input, ${N100})`}` : `2px solid ${`var(--ds-border-input, ${N20})`}`,
52
+ borderRadius: "var(--ds-border-radius, 3px)",
53
+ transition: 'background-color 200ms ease-in-out, border-color 200ms ease-in-out',
54
+ '&:hover': {
55
+ cursor: 'pointer'
56
+ }
57
+ });
58
+
59
+ /**
60
+ * This is the container for the datetime picker component.
61
+ */
62
+ export const DateTimePickerContainer = ({
63
+ isDisabled,
64
+ isFocused,
65
+ appearance,
66
+ isInvalid,
67
+ innerProps,
68
+ testId,
69
+ children
70
+ }) => {
71
+ const notFocusedOrIsDisabled = !(isFocused || isDisabled);
72
+ return jsx("div", _extends({
73
+ css: [baseContainerStyles, isDisabled && isDisabledStyles, isFocused && isFocusedStyles, appearance === 'subtle' && (isFocused ? subtleFocusedBgStyles : subtleBgStyles), isFocused && isFocusedBorderStyles, isInvalid && isInvalidBorderStyles, notFocusedOrIsDisabled && (isInvalid ? isInvalidHoverStyles : hoverStyles), appearance === 'none' && noBgStyles]
74
+ }, innerProps, {
75
+ "data-testid": testId
76
+ }), children);
77
+ };
@@ -0,0 +1,20 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ /** @jsx jsx */
3
+ import { jsx } from '@emotion/react';
4
+ import { components } from '@atlaskit/select';
5
+ import FixedLayer from '../internal/fixed-layer';
6
+
7
+ /**
8
+ * This is the fixed layer menu used in the time picker.
9
+ */
10
+ export const FixedLayerMenu = ({
11
+ selectProps,
12
+ ...rest
13
+ }) => jsx(FixedLayer, {
14
+ inputValue: selectProps.inputValue,
15
+ containerRef: selectProps.fixedLayerRef,
16
+ content: jsx(components.Menu, _extends({}, rest, {
17
+ menuShouldScrollIntoView: false
18
+ })),
19
+ testId: selectProps.testId
20
+ });
@@ -0,0 +1,48 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ /** @jsx jsx */
3
+ import { css, jsx } from '@emotion/react';
4
+ import Calendar from '@atlaskit/calendar';
5
+ import { UNSAFE_LAYERING } from '@atlaskit/layering';
6
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
+ import { N0, N50A, N60A } from '@atlaskit/theme/colors';
8
+ import { layers } from '@atlaskit/theme/constants';
9
+ import FixedLayer from '../internal/fixed-layer';
10
+ import { getValidDate } from './parse-date';
11
+ const menuStyles = css({
12
+ zIndex: layers.dialog(),
13
+ backgroundColor: `var(--ds-surface-overlay, ${N0})`,
14
+ borderRadius: "var(--ds-border-radius, 3px)",
15
+ boxShadow: `var(--ds-shadow-overlay, ${`0 4px 8px -2px ${N50A}, 0 0 1px ${N60A}`})`,
16
+ overflow: 'hidden'
17
+ });
18
+
19
+ /**
20
+ * This is the menu used in the select of the date picker.
21
+ */
22
+ export const Menu = ({
23
+ selectProps,
24
+ innerProps
25
+ }) => jsx(UNSAFE_LAYERING, {
26
+ isDisabled: getBooleanFF('platform.design-system-team.layering_qmiw3') ? false : true
27
+ }, jsx(FixedLayer, {
28
+ inputValue: selectProps.inputValue,
29
+ containerRef: selectProps.calendarContainerRef,
30
+ content: jsx("div", _extends({
31
+ css: menuStyles
32
+ }, innerProps), jsx(Calendar, _extends({}, getValidDate(selectProps.calendarValue), getValidDate(selectProps.calendarView), {
33
+ disabled: selectProps.calendarDisabled,
34
+ disabledDateFilter: selectProps.calendarDisabledDateFilter,
35
+ minDate: selectProps.calendarMinDate,
36
+ maxDate: selectProps.calendarMaxDate,
37
+ nextMonthLabel: selectProps.nextMonthLabel,
38
+ onChange: selectProps.onCalendarChange,
39
+ onSelect: selectProps.onCalendarSelect,
40
+ previousMonthLabel: selectProps.previousMonthLabel,
41
+ calendarRef: selectProps.calendarRef,
42
+ selected: [selectProps.calendarValue],
43
+ locale: selectProps.calendarLocale,
44
+ testId: selectProps.testId && `${selectProps.testId}--calendar`,
45
+ weekStartDay: selectProps.calendarWeekStartDay
46
+ }))),
47
+ testId: selectProps.testId
48
+ }));
@@ -0,0 +1,22 @@
1
+ import { format, isValid, parseISO } from 'date-fns';
2
+ import { convertTokens } from './parse-tokens';
3
+ export function getValidDate(iso) {
4
+ const date = parseISO(iso);
5
+ return isValid(date) ? {
6
+ day: date.getDate(),
7
+ month: date.getMonth() + 1,
8
+ year: date.getFullYear()
9
+ } : {};
10
+ }
11
+ export function getShortISOString(date) {
12
+ return format(date, convertTokens('YYYY-MM-DD'));
13
+ }
14
+ export function getSafeCalendarValue(calendarValue) {
15
+ // If `calendarValue` has a year that is greater than 9999, default to
16
+ // today's date
17
+ const yearIsOverLimit = calendarValue.match(/^\d{5,}/);
18
+ if (yearIsOverLimit) {
19
+ return getShortISOString(new Date());
20
+ }
21
+ return calendarValue;
22
+ }
@@ -1,3 +1,4 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
1
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
3
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
4
  import _createClass from "@babel/runtime/helpers/createClass";
@@ -6,77 +7,27 @@ import _inherits from "@babel/runtime/helpers/inherits";
6
7
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
8
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8
9
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
- import _extends from "@babel/runtime/helpers/extends";
10
10
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
11
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
12
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
13
13
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
14
14
  /** @jsx jsx */
15
15
  import { Component } from 'react';
16
- import { css, jsx } from '@emotion/react';
16
+ import { jsx } from '@emotion/react';
17
17
  import { format, isValid, lastDayOfMonth, parseISO } from 'date-fns';
18
18
  import pick from 'lodash/pick';
19
19
  import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
20
- import Calendar from '@atlaskit/calendar';
21
20
  import CalendarIcon from '@atlaskit/icon/glyph/calendar';
22
- import { UNSAFE_LAYERING } from '@atlaskit/layering';
23
21
  import { createLocalizationProvider } from '@atlaskit/locale';
24
22
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
25
23
  import Select, { mergeStyles } from '@atlaskit/select';
26
- import { N0, N50A, N60A } from '@atlaskit/theme/colors';
27
- import { layers } from '@atlaskit/theme/constants';
28
24
  import { defaultDateFormat, EmptyComponent, padToTwo, placeholderDatetime } from '../internal';
29
- import FixedLayer from '../internal/fixed-layer';
25
+ import { Menu } from '../internal/menu';
26
+ import { getSafeCalendarValue, getShortISOString } from '../internal/parse-date';
27
+ import { convertTokens } from '../internal/parse-tokens';
30
28
  import { makeSingleValue } from '../internal/single-value';
31
- import { convertTokens } from './utils';
32
29
  var packageName = "@atlaskit/datetime-picker";
33
- var packageVersion = "13.0.10";
34
- function getValidDate(iso) {
35
- var date = parseISO(iso);
36
- return isValid(date) ? {
37
- day: date.getDate(),
38
- month: date.getMonth() + 1,
39
- year: date.getFullYear()
40
- } : {};
41
- }
42
- function getShortISOString(date) {
43
- return format(date, convertTokens('YYYY-MM-DD'));
44
- }
45
- var menuStyles = css({
46
- zIndex: layers.dialog(),
47
- backgroundColor: "var(--ds-surface-overlay, ".concat(N0, ")"),
48
- borderRadius: "var(--ds-border-radius, 3px)",
49
- boxShadow: "var(--ds-shadow-overlay, ".concat("0 4px 8px -2px ".concat(N50A, ", 0 0 1px ").concat(N60A), ")"),
50
- overflow: 'hidden'
51
- });
52
- var Menu = function Menu(_ref) {
53
- var selectProps = _ref.selectProps,
54
- innerProps = _ref.innerProps;
55
- return jsx(UNSAFE_LAYERING, {
56
- isDisabled: getBooleanFF('platform.design-system-team.layering_qmiw3') ? false : true
57
- }, jsx(FixedLayer, {
58
- inputValue: selectProps.inputValue,
59
- containerRef: selectProps.calendarContainerRef,
60
- content: jsx("div", _extends({
61
- css: menuStyles
62
- }, innerProps), jsx(Calendar, _extends({}, getValidDate(selectProps.calendarValue), getValidDate(selectProps.calendarView), {
63
- disabled: selectProps.calendarDisabled,
64
- disabledDateFilter: selectProps.calendarDisabledDateFilter,
65
- minDate: selectProps.calendarMinDate,
66
- maxDate: selectProps.calendarMaxDate,
67
- nextMonthLabel: selectProps.nextMonthLabel,
68
- onChange: selectProps.onCalendarChange,
69
- onSelect: selectProps.onCalendarSelect,
70
- previousMonthLabel: selectProps.previousMonthLabel,
71
- calendarRef: selectProps.calendarRef,
72
- selected: [selectProps.calendarValue],
73
- locale: selectProps.calendarLocale,
74
- testId: selectProps.testId && "".concat(selectProps.testId, "--calendar"),
75
- weekStartDay: selectProps.calendarWeekStartDay
76
- }))),
77
- testId: selectProps.testId
78
- }));
79
- };
30
+ var packageVersion = "13.0.12";
80
31
  var datePickerDefaultProps = {
81
32
  appearance: 'default',
82
33
  autoFocus: false,
@@ -123,8 +74,8 @@ var DatePicker = /*#__PURE__*/function (_Component) {
123
74
  _defineProperty(_assertThisInitialized(_this), "isDateDisabled", function (date) {
124
75
  return _this.props.disabled.indexOf(date) > -1;
125
76
  });
126
- _defineProperty(_assertThisInitialized(_this), "onCalendarChange", function (_ref2) {
127
- var iso = _ref2.iso;
77
+ _defineProperty(_assertThisInitialized(_this), "onCalendarChange", function (_ref) {
78
+ var iso = _ref.iso;
128
79
  var _iso$split = iso.split('-'),
129
80
  _iso$split2 = _slicedToArray(_iso$split, 3),
130
81
  year = _iso$split2[0],
@@ -145,8 +96,8 @@ var DatePicker = /*#__PURE__*/function (_Component) {
145
96
  calendarValue: newIso
146
97
  });
147
98
  });
148
- _defineProperty(_assertThisInitialized(_this), "onCalendarSelect", function (_ref3) {
149
- var iso = _ref3.iso;
99
+ _defineProperty(_assertThisInitialized(_this), "onCalendarSelect", function (_ref2) {
100
+ var iso = _ref2.iso;
150
101
  _this.setState({
151
102
  selectInputValue: '',
152
103
  isOpen: false,
@@ -224,15 +175,6 @@ var DatePicker = /*#__PURE__*/function (_Component) {
224
175
  isOpen: true
225
176
  });
226
177
  });
227
- _defineProperty(_assertThisInitialized(_this), "getSafeCalendarValue", function (calendarValue) {
228
- // If `calendarValue` has a year that is greater than 9999, default to
229
- // today's date
230
- var yearIsOverLimit = calendarValue.match(/^\d{5,}/);
231
- if (yearIsOverLimit) {
232
- return getShortISOString(new Date());
233
- }
234
- return calendarValue;
235
- });
236
178
  _defineProperty(_assertThisInitialized(_this), "onInputKeyDown", function (event) {
237
179
  var _this$containerRef3;
238
180
  var _this$getSafeState2 = _this.getSafeState(),
@@ -275,12 +217,10 @@ var DatePicker = /*#__PURE__*/function (_Component) {
275
217
  // for more details.
276
218
  event.preventDefault();
277
219
  if (!_this.isDateDisabled(calendarValue)) {
278
- var _this$getSafeState3 = _this.getSafeState(),
279
- _value2 = _this$getSafeState3.value;
280
220
  // Get a safe `calendarValue` in case the value exceeds the maximum
281
221
  // allowed by ISO 8601
282
- var safeCalendarValue = _this.getSafeCalendarValue(calendarValue);
283
- var valueChanged = safeCalendarValue !== _value2;
222
+ var safeCalendarValue = getSafeCalendarValue(calendarValue);
223
+ var valueChanged = safeCalendarValue !== value;
284
224
  _this.setState({
285
225
  selectInputValue: '',
286
226
  isOpen: false,
@@ -350,8 +290,8 @@ var DatePicker = /*#__PURE__*/function (_Component) {
350
290
  if (parseInputValue) {
351
291
  return parseInputValue(date, dateFormat || defaultDateFormat);
352
292
  }
353
- var _this$getSafeState4 = _this.getSafeState(),
354
- l10n = _this$getSafeState4.l10n;
293
+ var _this$getSafeState3 = _this.getSafeState(),
294
+ l10n = _this$getSafeState3.l10n;
355
295
  return l10n.parseDate(date);
356
296
  });
357
297
  /**
@@ -365,8 +305,8 @@ var DatePicker = /*#__PURE__*/function (_Component) {
365
305
  var _this$props2 = _this.props,
366
306
  formatDisplayLabel = _this$props2.formatDisplayLabel,
367
307
  dateFormat = _this$props2.dateFormat;
368
- var _this$getSafeState5 = _this.getSafeState(),
369
- l10n = _this$getSafeState5.l10n;
308
+ var _this$getSafeState4 = _this.getSafeState(),
309
+ l10n = _this$getSafeState4.l10n;
370
310
  if (formatDisplayLabel) {
371
311
  return formatDisplayLabel(value, dateFormat || defaultDateFormat);
372
312
  }
@@ -378,8 +318,8 @@ var DatePicker = /*#__PURE__*/function (_Component) {
378
318
  if (placeholder) {
379
319
  return placeholder;
380
320
  }
381
- var _this$getSafeState6 = _this.getSafeState(),
382
- l10n = _this$getSafeState6.l10n;
321
+ var _this$getSafeState5 = _this.getSafeState(),
322
+ l10n = _this$getSafeState5.l10n;
383
323
  return l10n.formatDate(placeholderDatetime);
384
324
  });
385
325
  _this.state = {
@@ -418,11 +358,11 @@ var DatePicker = /*#__PURE__*/function (_Component) {
418
358
  locale = _this$props3.locale,
419
359
  testId = _this$props3.testId,
420
360
  weekStartDay = _this$props3.weekStartDay;
421
- var _this$getSafeState7 = this.getSafeState(),
422
- value = _this$getSafeState7.value,
423
- calendarValue = _this$getSafeState7.calendarValue,
424
- isOpen = _this$getSafeState7.isOpen,
425
- selectInputValue = _this$getSafeState7.selectInputValue;
361
+ var _this$getSafeState6 = this.getSafeState(),
362
+ value = _this$getSafeState6.value,
363
+ calendarValue = _this$getSafeState6.calendarValue,
364
+ isOpen = _this$getSafeState6.isOpen,
365
+ selectInputValue = _this$getSafeState6.selectInputValue;
426
366
  var actualSelectInputValue;
427
367
  if (getBooleanFF('platform.design-system-team.date-picker-input-a11y-fix_cbbxs')) {
428
368
  actualSelectInputValue = selectInputValue || (value ? this.formatDate(value) : undefined);