@transferwise/components 0.0.0-experimental-e05dfa3 → 0.0.0-experimental-d0b76b1

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/build/index.esm.js +76 -150
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +76 -150
  4. package/build/index.js.map +1 -1
  5. package/build/main.css +1 -1
  6. package/build/styles/dateLookup/DateLookup.css +1 -1
  7. package/build/styles/header/Header.css +1 -1
  8. package/build/styles/main.css +1 -1
  9. package/build/types/dateInput/DateInput.d.ts +2 -0
  10. package/build/types/dateInput/DateInput.d.ts.map +1 -1
  11. package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
  12. package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts +1 -1
  13. package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts.map +1 -1
  14. package/build/types/dateLookup/tableLink/TableLink.d.ts +2 -16
  15. package/build/types/dateLookup/tableLink/TableLink.d.ts.map +1 -1
  16. package/build/types/dateLookup/tableLink/index.d.ts +1 -1
  17. package/build/types/dateLookup/tableLink/index.d.ts.map +1 -1
  18. package/build/types/dateLookup/yearCalendar/table/YearCalendarTable.d.ts.map +1 -1
  19. package/package.json +1 -1
  20. package/src/dateInput/DateInput.js +6 -0
  21. package/src/dateInput/DateInput.story.tsx +43 -1
  22. package/src/dateLookup/DateLookup.css +1 -1
  23. package/src/dateLookup/DateLookup.js +3 -16
  24. package/src/dateLookup/DateLookup.keyboardEvents.spec.js +0 -12
  25. package/src/dateLookup/DateLookup.less +49 -46
  26. package/src/dateLookup/DateLookup.story.js +7 -8
  27. package/src/dateLookup/dayCalendar/table/DayCalendarTable.js +1 -14
  28. package/src/dateLookup/dayCalendar/table/DayCalendarTable.spec.js +0 -25
  29. package/src/dateLookup/monthCalendar/table/MonthCalendarTable.js +20 -33
  30. package/src/dateLookup/monthCalendar/table/MonthCalendarTable.spec.js +0 -33
  31. package/src/dateLookup/tableLink/TableLink.js +70 -0
  32. package/src/dateLookup/yearCalendar/table/YearCalendarTable.js +11 -33
  33. package/src/dateLookup/yearCalendar/table/YearCalendarTable.spec.js +0 -26
  34. package/src/header/Header.css +1 -1
  35. package/src/header/Header.less +0 -5
  36. package/src/main.css +1 -1
  37. package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts +0 -2
  38. package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts.map +0 -1
  39. package/src/dateLookup/getFocusableTime/getFocusable.spec.js +0 -38
  40. package/src/dateLookup/getFocusableTime/getFocusableTime.tsx +0 -28
  41. package/src/dateLookup/tableLink/TableLink.tsx +0 -80
  42. /package/src/dateLookup/tableLink/{index.ts → index.js} +0 -0
@@ -0,0 +1,70 @@
1
+ import PropTypes from 'prop-types';
2
+ import { PureComponent } from 'react';
3
+ import { injectIntl } from 'react-intl';
4
+
5
+ import messages from '../DateLookup.messages';
6
+
7
+ class TableLink extends PureComponent {
8
+ onClick = (event) => {
9
+ event.preventDefault();
10
+ if (!this.props.disabled) {
11
+ this.props.onClick(this.props.item);
12
+ }
13
+ };
14
+
15
+ calculateAriaLabel = (longTitle, title, active, type, formatMessage) => {
16
+ if (active) {
17
+ return `${longTitle || title}, ${formatMessage(messages.selected)} ${formatMessage(
18
+ messages[type],
19
+ )}`;
20
+ }
21
+ return longTitle || title;
22
+ };
23
+
24
+ render() {
25
+ const {
26
+ item,
27
+ type,
28
+ title,
29
+ longTitle,
30
+ active,
31
+ disabled,
32
+ today,
33
+ intl: { formatMessage },
34
+ } = this.props;
35
+ return (
36
+ <>
37
+ <button
38
+ type="button"
39
+ className={`tw-date-lookup-${type}-option ${active ? 'active' : ''} ${
40
+ today ? 'today' : ''
41
+ } np-text-body-default-bold`}
42
+ disabled={disabled}
43
+ aria-label={this.calculateAriaLabel(longTitle, title, active, type, formatMessage)}
44
+ aria-pressed={active}
45
+ onClick={this.onClick}
46
+ >
47
+ {title || item}
48
+ </button>
49
+ </>
50
+ );
51
+ }
52
+ }
53
+
54
+ TableLink.propTypes = {
55
+ item: PropTypes.number.isRequired, // day (1-31), month (0-11) or year (2018 etc)
56
+ type: PropTypes.oneOf(['day', 'month', 'year']).isRequired,
57
+ title: PropTypes.string,
58
+ longTitle: PropTypes.string,
59
+ active: PropTypes.bool.isRequired,
60
+ disabled: PropTypes.bool.isRequired,
61
+ today: PropTypes.bool.isRequired,
62
+ onClick: PropTypes.func.isRequired,
63
+ };
64
+
65
+ TableLink.defaultProps = {
66
+ title: null,
67
+ longTitle: null,
68
+ };
69
+
70
+ export default injectIntl(TableLink);
@@ -2,7 +2,6 @@ import { formatDate } from '@transferwise/formatting';
2
2
  import PropTypes from 'prop-types';
3
3
  import { useIntl } from 'react-intl';
4
4
 
5
- import { getFocusableTime } from '../../getFocusableTime/getFocusableTime';
6
5
  import TableLink from '../../tableLink';
7
6
 
8
7
  const ROWS = 5;
@@ -12,38 +11,17 @@ const YEAR_ONLY_FORMAT = { year: 'numeric' };
12
11
  const YearCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onSelect }) => {
13
12
  const { locale } = useIntl();
14
13
  const startYear = viewYear - (viewYear % 20);
15
- const getLink = (year) => {
16
- return (
17
- <TableLink
18
- item={year}
19
- type="year"
20
- title={formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT)}
21
- active={!!(selectedDate && year === selectedDate.getFullYear())}
22
- disabled={isDisabled(year)}
23
- today={year === new Date().getFullYear()}
24
- autofocus={autofocusYear === year}
25
- onClick={onSelect}
26
- />
27
- );
28
- };
29
-
30
- const isSelected = (year) => {
31
- return selectedDate && year === selectedDate.getFullYear();
32
- };
33
-
34
- const isThisYear = (year) => {
35
- return year === new Date().getFullYear();
36
- };
37
-
38
- const isDisabled = (year) => {
39
- return !!((min && year < min.getFullYear()) || (max && year > max.getFullYear()));
40
- };
41
-
42
- const autofocusYear = (() => {
43
- const years = [...new Array(ROWS * COLS)].map((_, index) => startYear + index);
44
- return getFocusableTime(isSelected, isThisYear, isDisabled, years);
45
- })();
46
-
14
+ const getLink = (year) => (
15
+ <TableLink
16
+ item={year}
17
+ type="year"
18
+ title={formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT)}
19
+ active={!!(selectedDate && year === selectedDate.getFullYear())}
20
+ disabled={!!((min && year < min.getFullYear()) || (max && year > max.getFullYear()))}
21
+ today={year === new Date().getFullYear()}
22
+ onClick={onSelect}
23
+ />
24
+ );
47
25
  return (
48
26
  <table className="table table-condensed table-bordered tw-date-lookup-calendar m-b-0">
49
27
  <thead className="sr-only">
@@ -90,32 +90,6 @@ describe('YearCalendarTable', () => {
90
90
  expect(component.find('.sr-only').text()).toBe('Enter date..');
91
91
  });
92
92
 
93
- it('sets autofocus to true when 2002 is the selected year', () => {
94
- component.setProps({ selectedDate: new Date(2002, 5, 1) });
95
- expect(getTableLinkAt(2).prop('autofocus')).toBe(true);
96
- });
97
-
98
- it('sets autofocus to true when selected year is null and current year is visible', () => {
99
- const today = new Date();
100
- component.setProps({
101
- selectedDate: null,
102
- viewYear: today.getFullYear(),
103
- });
104
- expect(getTableLink().find({ today: true }).prop('autofocus')).toBe(true);
105
- });
106
-
107
- it('sets autofocus to true on the second year when the first year is disabled', () => {
108
- component.setProps({
109
- selectedDate: null,
110
- viewYear: 2000,
111
- min: new Date(2001, 1, 1),
112
- isDisabled: (month) => month === 0,
113
- });
114
-
115
- expect(getTableLinkAt(0).prop('autofocus')).toBe(false);
116
- expect(getTableLinkAt(1).prop('autofocus')).toBe(true);
117
- });
118
-
119
93
  const getTableLinkAt = (i) => component.find('[type="year"]').at(i);
120
94
  const getTableLink = () => component.find('[type="year"]');
121
95
  });
@@ -1 +1 @@
1
- .np-header{align-items:flex-end;border-bottom:1px solid #0000001a;border-bottom:1px solid var(--color-border-neutral);display:flex;justify-content:space-between;margin-bottom:8px;margin-bottom:var(--size-8);max-width:100%;padding:8px 0;padding:var(--size-8) 0}.np-header__title{color:#5d7079;color:var(--color-content-secondary)}.np-theme-personal .np-header{-moz-column-gap:24px;column-gap:24px;-moz-column-gap:var(--size-24);column-gap:var(--size-24)}.np-theme-personal .np-header__button{margin-inline:-16px;margin-inline:calc(var(--size-16)*-1);margin-bottom:-4px;margin-bottom:calc(var(--size-4)*-1)}.np-header legend{border-bottom:none;padding:0}
1
+ .np-header{align-items:flex-end;border-bottom:1px solid #0000001a;border-bottom:1px solid var(--color-border-neutral);display:flex;justify-content:space-between;margin-bottom:8px;margin-bottom:var(--size-8);max-width:100%;padding:8px 0;padding:var(--size-8) 0}.np-header__title{color:#5d7079;color:var(--color-content-secondary)}.np-theme-personal .np-header{-moz-column-gap:24px;column-gap:24px;-moz-column-gap:var(--size-24);column-gap:var(--size-24)}.np-theme-personal .np-header__button{margin-inline:-16px;margin-inline:calc(var(--size-16)*-1);margin-bottom:-4px;margin-bottom:calc(var(--size-4)*-1)}
@@ -19,9 +19,4 @@
19
19
  margin-bottom: calc(var(--size-4) * -1);
20
20
  }
21
21
  }
22
-
23
- legend {
24
- padding: 0;
25
- border-bottom: none;
26
- }
27
22
  }