@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
@@ -15,6 +15,8 @@ export interface DateInputPlaceholders {
15
15
  }
16
16
 
17
17
  export interface DateInputProps {
18
+ "aria-label"?: string;
19
+ "aria-labelledby"?: string;
18
20
  disabled?: boolean;
19
21
  size?: DateInputSize;
20
22
  value?: DateInputValue;
@@ -1 +1 @@
1
- {"version":3,"file":"DateInput.d.ts","sourceRoot":"","sources":["../../../src/dateInput/DateInput.js"],"names":[],"mappings":";AAeA;;;;;;;;;;;;;;;;;gCAsQC"}
1
+ {"version":3,"file":"DateInput.d.ts","sourceRoot":"","sources":["../../../src/dateInput/DateInput.js"],"names":[],"mappings":";AAeA;;;;;;;;;;;;;;;;;;;gCA0QC"}
@@ -1 +1 @@
1
- {"version":3,"file":"DateLookup.d.ts","sourceRoot":"","sources":["../../../src/dateLookup/DateLookup.js"],"names":[],"mappings":";AAqBA;IAoBE;;;;;;aAqBC;IApCD,wBAaC;IAjBD,wCAAsB;IAEtB,yCAAuB;IAIrB;;;;;;;;;;MAUC;IA0BH,6CAMC;IAFC,uCAAyE;IAI3E,6BAGC;IAED,iBAOE;IAEF,oBAME;IAEF,kBAME;IAEF,oCA2CE;IAEF,wEAmBE;IAEF,+DAOE;IAEF,gCAIE;IAEF,yBAA+C;IAE/C,2BAAmD;IAEnD,0BAAiD;IAEjD,sDAME;IAEF;;;eAEE;IAEF,+CA8BE;IAEF,wBAGE;IAEF,sCA0BC;CACF"}
1
+ {"version":3,"file":"DateLookup.d.ts","sourceRoot":"","sources":["../../../src/dateLookup/DateLookup.js"],"names":[],"mappings":";AAqBA;IAmBE;;;;;;aAqBC;IAnCD,wBAYC;IAhBD,wCAAsB;IAEtB,yCAAuB;IAIrB;;;;;;;;;MASC;IA0BH,6CAMC;IAFC,uCAAyE;IAI3E,6BAGC;IAED,iBAOE;IAEF,kBAME;IAEF,oCA0CE;IAEF,wEAgBE;IAEF,+DAOE;IAEF,gCAIE;IAEF,yBAA+C;IAE/C,2BAAmD;IAEnD,0BAAiD;IAEjD,sDAME;IAEF;;;eAEE;IAEF,+CA8BE;IAEF,wBAGE;IAEF,sCA0BC;CACF"}
@@ -1,5 +1,5 @@
1
1
  export default MonthCalendarTable;
2
- declare function MonthCalendarTable({ selectedDate, min, max, viewYear, placeholder, onSelect }: {
2
+ declare function MonthCalendarTable({ selectedDate: selected, min, max, viewYear, placeholder, onSelect, }: {
3
3
  selectedDate: any;
4
4
  min: any;
5
5
  max: any;
@@ -1 +1 @@
1
- {"version":3,"file":"MonthCalendarTable.d.ts","sourceRoot":"","sources":["../../../../../src/dateLookup/monthCalendar/table/MonthCalendarTable.js"],"names":[],"mappings":";AAWA;;;;;;;gCA4DC"}
1
+ {"version":3,"file":"MonthCalendarTable.d.ts","sourceRoot":"","sources":["../../../../../src/dateLookup/monthCalendar/table/MonthCalendarTable.js"],"names":[],"mappings":";AAUA;;;;;;;gCAgDC"}
@@ -1,19 +1,5 @@
1
- /// <reference types="react" />
2
- import { IntlShape } from 'react-intl';
3
- interface TableLinkProps {
4
- item: number;
5
- type: 'day' | 'month' | 'year';
6
- title?: string;
7
- longTitle?: string;
8
- active: boolean;
9
- disabled: boolean;
10
- today: boolean;
11
- autofocus?: boolean;
12
- onClick: (item: number) => void;
13
- intl: IntlShape;
14
- }
15
- declare const _default: import("react").FC<import("react-intl").WithIntlProps<TableLinkProps>> & {
16
- WrappedComponent: import("react").ComponentType<TableLinkProps>;
1
+ declare const _default: import("react").FC<import("react-intl").WithIntlProps<any>> & {
2
+ WrappedComponent: import("react").ComponentType<any>;
17
3
  };
18
4
  export default _default;
19
5
  //# sourceMappingURL=TableLink.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TableLink.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/tableLink/TableLink.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAc,SAAS,EAAE,MAAM,YAAY,CAAC;AAInD,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,IAAI,EAAE,SAAS,CAAC;CACjB;;;;AA8DD,wBAAqC"}
1
+ {"version":3,"file":"TableLink.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/tableLink/TableLink.js"],"names":[],"mappings":""}
@@ -1,2 +1,2 @@
1
- export { default } from './TableLink';
1
+ export { default } from "./TableLink";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/tableLink/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/tableLink/index.js"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"YearCalendarTable.d.ts","sourceRoot":"","sources":["../../../../../src/dateLookup/yearCalendar/table/YearCalendarTable.js"],"names":[],"mappings":";AAWA;;;;;;;gCAuDC"}
1
+ {"version":3,"file":"YearCalendarTable.d.ts","sourceRoot":"","sources":["../../../../../src/dateLookup/yearCalendar/table/YearCalendarTable.js"],"names":[],"mappings":";AAUA;;;;;;;gCAkCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "0.0.0-experimental-e05dfa3",
3
+ "version": "0.0.0-experimental-d0b76b1",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -14,6 +14,8 @@ const MonthBeforeDay = new Set(['en-US', 'ja-JP']);
14
14
  const INITIAL_DEFAULT_STATE = { year: null, month: null, day: null };
15
15
 
16
16
  const DateInput = ({
17
+ 'aria-labelledby': ariaLabelledBy,
18
+ 'aria-label': ariaLabel,
17
19
  disabled,
18
20
  size,
19
21
  value,
@@ -224,6 +226,8 @@ const DateInput = ({
224
226
  <div
225
227
  className="tw-date"
226
228
  id={id}
229
+ aria-labelledby={ariaLabelledBy}
230
+ aria-label={ariaLabel}
227
231
  onFocus={(event) =>
228
232
  shouldPropagateOnFocus(event) ? onFocus && onFocus() : event.stopPropagation()
229
233
  }
@@ -300,6 +304,8 @@ function shouldPropagateOnBlur({ target, relatedTarget }) {
300
304
  }
301
305
 
302
306
  DateInput.propTypes = {
307
+ 'aria-label': PropTypes.string,
308
+ 'aria-labelledby': PropTypes.string,
303
309
  disabled: PropTypes.bool,
304
310
  size: PropTypes.oneOf(['sm', 'md', 'lg']),
305
311
  value: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
@@ -1,6 +1,6 @@
1
1
  import { Meta, StoryObj } from '@storybook/react';
2
2
 
3
- import { DateInput, InlineAlert } from '..';
3
+ import { DateInput, Info, InlineAlert, Title, Typography } from '..';
4
4
  import { lorem10, storyConfig } from '../test-utils';
5
5
 
6
6
  export default {
@@ -25,6 +25,48 @@ type Story = StoryObj<typeof DateInput>;
25
25
 
26
26
  export const Basic: Story = {};
27
27
 
28
+ export const WithLabel: Story = {
29
+ render: (args) => {
30
+ const id1 = 'date-input-group-label-1';
31
+ const label = 'Date of Birth';
32
+ return (
33
+ <>
34
+ <Title type={Typography.TITLE_SUBSECTION}>
35
+ label (as <code>div</code> element) is linked with <code>DateInput</code> via{' '}
36
+ <code>aria-labelledby</code> prop
37
+ </Title>
38
+ <div className="control-label" id={id1}>
39
+ Date of Delivery
40
+ </div>
41
+ <DateInput {...args} aria-labelledby={id1} />
42
+
43
+ <br />
44
+
45
+ <Title type={Typography.TITLE_SUBSECTION}>
46
+ label (as <code>div</code> element) is detached but <code>DateInput</code> has same label
47
+ via <code>aria-label</code> attribute
48
+ </Title>
49
+ <div className="control-label">
50
+ {label}{' '}
51
+ <Info aria-label="Fast transfer hint" title="Fast transfer hint" content={lorem10} />
52
+ </div>
53
+ <DateInput {...args} aria-label={label} />
54
+
55
+ <br />
56
+
57
+ <Title type={Typography.TITLE_SUBSECTION}>
58
+ <code>DateInput</code> wrapped in <code>fieldset</code> + using <code>legend</code> as
59
+ label (rare use case)
60
+ </Title>
61
+ <fieldset>
62
+ <legend className="control-label">Expiry Date</legend>
63
+ <DateInput {...args} />
64
+ </fieldset>
65
+ </>
66
+ );
67
+ },
68
+ };
69
+
28
70
  export const BasicMobile: Story = storyConfig(Basic, { variants: ['mobile'] });
29
71
 
30
72
  export const InputError: Story = {
@@ -1 +1 @@
1
- .tw-date-lookup-menu{width:400px}.tw-date-lookup-calendar{background-color:inherit;min-width:300px;table-layout:fixed;text-align:center}.tw-date-lookup-calendar>tbody>tr>td:nth-child(7n+6) button,.tw-date-lookup-calendar>tbody>tr>td:nth-child(7n+7) button,.tw-date-lookup-calendar>thead>tr>th:nth-child(7n+6),.tw-date-lookup-calendar>thead>tr>th:nth-child(7n+7){color:#5d7079;color:var(--color-content-secondary);font-weight:400;font-weight:var(--font-weight-regular)}.tw-date-lookup-calendar>tbody>tr>td{padding:4px;padding:var(--size-4)}@media (max-width:320px){.tw-date-lookup-calendar>tbody>tr>td{padding:0}}.tw-date-lookup-calendar>tbody>tr>td:has(.tw-date-lookup-day-option){padding:1px}.tw-date-lookup-calendar>tbody>tr>td button{background-color:transparent;border:transparent;border-radius:10px;border-radius:var(--radius-small);color:#0097c7;color:var(--color-content-accent);color:#37517e;color:var(--color-content-primary);font-weight:600;font-weight:var(--font-weight-semi-bold);padding:4px 0;padding:var(--size-4) 0;width:100%}@media (max-width:320px){.tw-date-lookup-calendar>tbody>tr>td button{padding:0}}.tw-date-lookup-calendar>tbody>tr>td button.tw-date-lookup-day-option{align-items:center;border-radius:50%;display:inline-flex;height:40px;height:var(--size-40);justify-content:center;line-height:40px;line-height:var(--size-40);padding:0;width:40px;width:var(--size-40)}.tw-date-lookup-calendar>tbody>tr>td button.tw-date-lookup-day-option.today{text-decoration:underline;text-decoration-thickness:2px;text-underline-offset:4px}.tw-date-lookup-calendar>tbody>tr>td:hover button:not(.disabled,:disabled),.tw-date-lookup-calendar>tbody>tr>td:not(.disabled,:disabled) button.show-focus{background-color:var(--color-background-screen-hover)}.tw-date-lookup-calendar>tbody>tr>td:not(.disabled,:disabled) button.active{background-color:var(--color-interactive-primary);color:#00a2dd;color:var(--color-interactive-accent)}.tw-date-lookup-calendar abbr{text-decoration:none}.tw-date-lookup-header-current-container{display:inline}.tw-date-lookup-header-current{font-weight:800;font-weight:var(--font-weight-bold)}.np-theme-personal .tw-date-lookup-menu .table-bordered,.np-theme-personal.tw-date-lookup-menu .table-bordered{border:none}.np-theme-personal .tw-date-lookup-menu thead,.np-theme-personal.tw-date-lookup-menu thead{background-color:unset}.np-theme-personal .tw-date-lookup-menu td,.np-theme-personal.tw-date-lookup-menu td{border:none}.np-theme-personal .tw-date-lookup-menu .tw-date-lookup-header-current,.np-theme-personal.tw-date-lookup-menu .tw-date-lookup-header-current{color:#37517e;color:var(--color-content-primary)}
1
+ .tw-date-lookup-menu{width:400px}.tw-date-lookup-calendar{min-width:300px;table-layout:fixed;text-align:center}.tw-date-lookup-calendar>tbody>tr>td{padding:4px;padding:var(--size-4)}@media (max-width:320px){.tw-date-lookup-calendar>tbody>tr>td{padding:0}}.tw-date-lookup-calendar>tbody>tr>td button{background-color:transparent;border:transparent;border-radius:10px;border-radius:var(--radius-small);color:#0097c7;color:var(--color-content-accent);font-weight:600;font-weight:var(--font-weight-semi-bold);padding:4px 0;padding:var(--size-4) 0;width:100%}@media (max-width:320px){.tw-date-lookup-calendar>tbody>tr>td button{padding:0}}.tw-date-lookup-calendar>tbody>tr>td button:not(.disabled,:disabled).active{background-color:#0081ba;background-color:var(--color-interactive-accent-active);color:#fff}.tw-date-lookup-calendar>tbody>tr>td button:not(.disabled,:disabled):hover{background-color:#008fc9;background-color:var(--color-interactive-accent-hover);color:#fff}.np-theme-personal .tw-date-lookup-calendar>tbody>tr>td button{color:#37517e;color:var(--color-content-primary)}.np-theme-personal .tw-date-lookup-calendar>tbody>tr>td button:not(.disabled,:disabled).active,.np-theme-personal .tw-date-lookup-calendar>tbody>tr>td button:not(.disabled,:disabled):hover{color:var(--color-interactive-control)}.np-theme-personal .tw-date-lookup-calendar>tbody>tr>td:nth-child(7n+6) button,.np-theme-personal .tw-date-lookup-calendar>tbody>tr>td:nth-child(7n+7) button,.np-theme-personal .tw-date-lookup-calendar>thead>tr>th:nth-child(7n+6),.np-theme-personal .tw-date-lookup-calendar>thead>tr>th:nth-child(7n+7){color:#5d7079;color:var(--color-content-secondary);font-weight:400;font-weight:var(--font-weight-regular)}.tw-date-lookup-calendar abbr{text-decoration:none}.np-theme-personal .tw-date-lookup-calendar{background-color:inherit}.np-theme-personal .tw-date-lookup-menu .table-bordered,.np-theme-personal.tw-date-lookup-menu .table-bordered{border:none}.np-theme-personal .tw-date-lookup-menu thead,.np-theme-personal.tw-date-lookup-menu thead{background-color:unset}.np-theme-personal .tw-date-lookup-menu td,.np-theme-personal.tw-date-lookup-menu td{border:none}.np-theme-personal .tw-date-lookup-menu .tw-date-lookup-header-current-container,.np-theme-personal.tw-date-lookup-menu .tw-date-lookup-header-current-container{display:inline-block}.np-theme-personal .tw-date-lookup-menu .tw-date-lookup-header-current-container .tw-date-lookup-header-current,.np-theme-personal.tw-date-lookup-menu .tw-date-lookup-header-current-container .tw-date-lookup-header-current{color:#37517e;color:var(--color-content-primary)}.np-theme-personal .tw-date-lookup-menu .tw-date-lookup-day-option,.np-theme-personal.tw-date-lookup-menu .tw-date-lookup-day-option{align-items:center;color:#37517e;color:var(--color-content-primary);display:inline-flex;height:32px;height:var(--size-32);justify-content:center;line-height:32px;line-height:var(--size-32)}.np-theme-personal .tw-date-lookup-menu .tw-date-lookup-day-option.active,.np-theme-personal.tw-date-lookup-menu .tw-date-lookup-day-option.active{background-color:#00a2dd;background-color:var(--color-interactive-accent);color:var(--color-interactive-primary)}
@@ -28,7 +28,6 @@ class DateLookup extends PureComponent {
28
28
  super(props);
29
29
  this.state = {
30
30
  selectedDate: getStartOfDay(props.value),
31
- originalDate: null,
32
31
  min: getStartOfDay(props.min),
33
32
  max: getStartOfDay(props.max),
34
33
  viewMonth: (props.value || new Date()).getMonth(),
@@ -84,14 +83,6 @@ class DateLookup extends PureComponent {
84
83
  }
85
84
  };
86
85
 
87
- discard = () => {
88
- const { originalDate } = this.state;
89
- if (originalDate !== null) {
90
- this.props.onChange(originalDate);
91
- }
92
- this.close();
93
- };
94
-
95
86
  close = () => {
96
87
  const { onBlur } = this.props;
97
88
  this.setState({ open: false });
@@ -101,7 +92,7 @@ class DateLookup extends PureComponent {
101
92
  };
102
93
 
103
94
  handleKeyDown = (event) => {
104
- const { open, originalDate } = this.state;
95
+ const { open } = this.state;
105
96
  switch (event.keyCode) {
106
97
  case KeyCodes.LEFT:
107
98
  if (open) {
@@ -136,7 +127,6 @@ class DateLookup extends PureComponent {
136
127
  event.preventDefault();
137
128
  break;
138
129
  case KeyCodes.ESCAPE:
139
- originalDate && this.props.onChange(originalDate);
140
130
  this.close();
141
131
  event.preventDefault();
142
132
  break;
@@ -146,10 +136,7 @@ class DateLookup extends PureComponent {
146
136
  };
147
137
 
148
138
  adjustDate = (daysToAdd, monthsToAdd, yearsToAdd) => {
149
- const { selectedDate, min, max, mode, originalDate } = this.state;
150
- if (originalDate === null) {
151
- this.setState({ originalDate: selectedDate });
152
- }
139
+ const { selectedDate, min, max, mode } = this.state;
153
140
  let date;
154
141
  if (selectedDate) {
155
142
  date = new Date(
@@ -256,7 +243,7 @@ class DateLookup extends PureComponent {
256
243
  open={open}
257
244
  className="tw-date-lookup-menu"
258
245
  position={Position.BOTTOM}
259
- onClose={this.discard}
246
+ onClose={this.close}
260
247
  >
261
248
  {this.getCalendar()}
262
249
  </ResponsivePanel>
@@ -80,18 +80,6 @@ describe('DateLookup (keyboard events)', () => {
80
80
  pressKey(KEY_CODES.DOWN);
81
81
  onChangeCalledWith(new Date(2019, 0, 3));
82
82
  });
83
-
84
- it('resets to original date when escape key is pressed', () => {
85
- pressKey(KEY_CODES.LEFT);
86
- pressKey(KEY_CODES.ESCAPE);
87
- onChangeCalledWith(date);
88
- });
89
-
90
- it('resets to original date when clicking outside modal', () => {
91
- pressKey(KEY_CODES.LEFT);
92
- component.find('.dimmer').simulate('click');
93
- onChangeCalledWith(date);
94
- });
95
83
  });
96
84
 
97
85
  describe('when open and in month mode', () => {
@@ -9,24 +9,12 @@
9
9
  text-align: center;
10
10
  table-layout: fixed;
11
11
 
12
- > thead > tr > th:nth-child(7n+6),
13
- > thead > tr > th:nth-child(7n+7),
14
- > tbody > tr > td:nth-child(7n+6) button,
15
- > tbody > tr > td:nth-child(7n+7) button {
16
- color: var(--color-content-secondary);
17
- font-weight: var(--font-weight-regular);
18
- }
19
-
20
12
  > tbody > tr > td {
21
13
  padding: var(--size-4);
22
14
  @media (--screen-400-zoom) {
23
15
  padding: 0;
24
16
  }
25
17
 
26
- &:has(.tw-date-lookup-day-option) {
27
- padding: 1px;
28
- }
29
-
30
18
  button {
31
19
  width: 100%;
32
20
  padding: var(--size-4) 0;
@@ -38,34 +26,37 @@
38
26
  border-radius: var(--radius-small);
39
27
  background-color: transparent;
40
28
  font-weight: var(--font-weight-semi-bold);
41
- color: var(--color-content-primary);
42
29
 
43
- &.tw-date-lookup-day-option {
44
- height: var(--size-40);
45
- border-radius: 50%;
46
- line-height: var(--size-40);
47
- width: var(--size-40);
48
- padding: 0;
49
- display: inline-flex;
50
- align-items: center;
51
- justify-content: center;
52
-
53
- &.today {
54
- text-decoration: underline;
55
- text-decoration-thickness: 2px;
56
- text-underline-offset: 4px;
57
- }
30
+ &:not(.disabled, :disabled).active {
31
+ color: #fff;
32
+ background-color: var(--color-interactive-accent-active);
58
33
  }
59
- }
60
34
 
61
- &:not(.disabled, :disabled) button.show-focus,
62
- &:hover button:not(.disabled, :disabled) {
63
- background-color: var(--color-background-screen-hover);
64
- }
35
+ &:not(.disabled, :disabled):hover {
36
+ color: #fff;
37
+ background-color: var(--color-interactive-accent-hover);
38
+ }
65
39
 
66
- &:not(.disabled, :disabled) button.active {
67
- background-color: var(--color-interactive-primary);
68
- color: var(--color-interactive-accent);
40
+ .np-theme-personal & {
41
+ color: var(--color-content-primary);
42
+
43
+ &:not(.disabled, :disabled).active {
44
+ color: var(--color-interactive-control);
45
+ }
46
+
47
+ &:not(.disabled, :disabled):hover {
48
+ color: var(--color-interactive-control);
49
+ }
50
+ }
51
+ }
52
+ }
53
+ > thead > tr > th:nth-child(7n+6),
54
+ > thead > tr > th:nth-child(7n+7),
55
+ > tbody > tr > td:nth-child(7n+6) button,
56
+ > tbody > tr > td:nth-child(7n+7) button {
57
+ .np-theme-personal & {
58
+ color: var(--color-content-secondary);
59
+ font-weight: var(--font-weight-regular);
69
60
  }
70
61
  }
71
62
 
@@ -73,15 +64,9 @@
73
64
  text-decoration: none;
74
65
  }
75
66
 
76
- background-color: inherit;
77
- }
78
-
79
- .tw-date-lookup-header-current-container {
80
- display: inline;
81
- }
82
-
83
- .tw-date-lookup-header-current {
84
- font-weight: var(--font-weight-bold);
67
+ .np-theme-personal & {
68
+ background-color: inherit;
69
+ }
85
70
  }
86
71
 
87
72
  .np-theme-personal {
@@ -98,9 +83,27 @@
98
83
  td {
99
84
  border: none;
100
85
  }
86
+
87
+ .tw-date-lookup-header-current-container {
88
+ display: inline-block;
101
89
 
102
- .tw-date-lookup-header-current {
90
+ .tw-date-lookup-header-current {
91
+ color: var(--color-content-primary);
92
+ }
93
+ }
94
+
95
+ .tw-date-lookup-day-option {
96
+ height: var(--size-32);
97
+ line-height: var(--size-32);
98
+ display: inline-flex;
99
+ align-items: center;
100
+ justify-content: center;
103
101
  color: var(--color-content-primary);
104
102
  }
103
+
104
+ .tw-date-lookup-day-option.active {
105
+ background-color: var(--color-interactive-accent);
106
+ color: var(--color-interactive-primary);
107
+ }
105
108
  }
106
109
  }
@@ -13,8 +13,6 @@ export default {
13
13
 
14
14
  let theFuture = new Date();
15
15
  theFuture.setDate(theFuture.getDate() + 10);
16
- let thePast = new Date();
17
- thePast.setDate(thePast.getDate() - 10);
18
16
 
19
17
  export const Basic = () => {
20
18
  const [value, setValue] = useState(null);
@@ -24,13 +22,16 @@ export const Basic = () => {
24
22
  const placeholder = text('placeholder', 'placeholder');
25
23
  const size = select('size', Object.values(Size), Size.MEDIUM);
26
24
 
25
+ const minvalue = date('minvalue', new Date());
26
+ const maxvalue = date('maxvalue', theFuture);
27
27
  const clearable = boolean('clearable', false);
28
28
 
29
29
  return (
30
30
  <DateLookup
31
31
  disabled={disabled}
32
32
  label={label}
33
- min={thePast}
33
+ max={new Date(maxvalue)}
34
+ min={new Date(minvalue)}
34
35
  monthFormat={monthFormat}
35
36
  placeholder={placeholder}
36
37
  size={size}
@@ -41,11 +42,9 @@ export const Basic = () => {
41
42
  );
42
43
  };
43
44
 
44
- Basic.play = async ({ canvasElement }) => {
45
- // testing focus state on keyboard nav
45
+ Basic.play = ({ canvasElement }) => {
46
46
  const canvas = within(canvasElement);
47
- userEvent.tab(canvas.getByRole('button'));
48
- userEvent.keyboard('{space}');
47
+ userEvent.click(canvas.getByRole('button'));
49
48
  };
50
49
 
51
50
  export const Basic400Zoom = storyConfig(
@@ -61,7 +60,7 @@ export const RightAligned = () => {
61
60
  const placeholder = text('placeholder', 'placeholder');
62
61
  const size = select('size', Object.values(Size), Size.MEDIUM);
63
62
 
64
- const minvalue = date('minvalue', thePast);
63
+ const minvalue = date('minvalue', new Date());
65
64
  const maxvalue = date('maxvalue', theFuture);
66
65
  const clearable = boolean('clearable', false);
67
66
 
@@ -4,7 +4,6 @@ import { PureComponent } from 'react';
4
4
  import { injectIntl } from 'react-intl';
5
5
 
6
6
  import { getDayNames, isWithinRange } from '../../../common/dateUtils';
7
- import { getFocusableTime } from '../../getFocusableTime/getFocusableTime';
8
7
  import { getStartOfDay } from '../../getStartOfDay';
9
8
  import TableLink from '../../tableLink';
10
9
 
@@ -66,16 +65,6 @@ class DayCalendarTable extends PureComponent {
66
65
  return !!(selectedDate && +new Date(viewYear, viewMonth, day) === +selectedDate);
67
66
  };
68
67
 
69
- isToday = (day) => {
70
- const { viewMonth, viewYear } = this.props;
71
- return +getStartOfDay(new Date()) === +new Date(viewYear, viewMonth, day);
72
- };
73
-
74
- getAutofocusDay = (weeks) => {
75
- const days = weeks.flatMap((week) => week);
76
- return getFocusableTime(this.isActive, this.isToday, this.isDisabled, days);
77
- };
78
-
79
68
  render() {
80
69
  const {
81
70
  viewMonth,
@@ -83,7 +72,6 @@ class DayCalendarTable extends PureComponent {
83
72
  intl: { locale },
84
73
  } = this.props;
85
74
  const weeks = this.getTableStructure();
86
- let autoFocusDay = this.getAutofocusDay(weeks, viewMonth, viewYear);
87
75
  return (
88
76
  <table className="table table-condensed table-bordered tw-date-lookup-calendar m-b-0">
89
77
  <thead>
@@ -115,11 +103,10 @@ class DayCalendarTable extends PureComponent {
115
103
  locale,
116
104
  SHORT_DAY_FORMAT,
117
105
  )}
118
- autofocus={day === autoFocusDay}
119
106
  longTitle={formatDate(new Date(viewYear, viewMonth, day), locale)}
120
107
  active={this.isActive(day)}
121
108
  disabled={this.isDisabled(day)}
122
- today={this.isToday(day)}
109
+ today={+getStartOfDay(new Date()) === +new Date(viewYear, viewMonth, day)}
123
110
  onClick={this.selectDay}
124
111
  />
125
112
  )}
@@ -117,31 +117,6 @@ describe('DayCalendarTable', () => {
117
117
  expect(props.onSelect).toHaveBeenCalledWith(new Date(2018, 11, 1));
118
118
  });
119
119
 
120
- it('sets autofocus to true when 5 is the selected day', () => {
121
- component.setProps({ selectedDate: new Date(2018, 11, 5) });
122
- expect(getTableLinkAt(4).prop('autofocus')).toBe(true);
123
- });
124
-
125
- it('does not set autofocus to true when 5 is the selected day but not the right month', () => {
126
- component.setProps({ selectedDate: new Date(2018, 10, 5) });
127
- expect(getTableLinkAt(4).prop('autofocus')).toBe(false);
128
- });
129
-
130
- it('does not set autofocus to true when 5 is the selected day but not the right year', () => {
131
- component.setProps({ selectedDate: new Date(2017, 11, 5) });
132
- expect(getTableLinkAt(4).prop('autofocus')).toBe(false);
133
- });
134
-
135
- it('sets autofocus to true when selected date is null and current day is visible', () => {
136
- const today = new Date();
137
- component.setProps({
138
- selectedDate: today,
139
- viewMonth: today.getMonth(),
140
- viewYear: today.getFullYear(),
141
- });
142
- expect(component.find(TableLink).find({ today: true }).prop('autofocus')).toBe(true);
143
- });
144
-
145
120
  const getTableLinkAt = (i) => component.find(TableLink).at(i);
146
121
  const getTableDataAt = (i) => component.find('tbody td').at(i);
147
122
  });
@@ -2,40 +2,33 @@ 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 = 3;
9
8
  const COLS = 4;
10
- const MONTH_ONLY_FORMAT = { month: 'short' };
9
+ const MONTH_ONLY_FORMAY = { month: 'short' };
11
10
 
12
- const MonthCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onSelect }) => {
11
+ const MonthCalendarTable = ({
12
+ selectedDate: selected,
13
+ min,
14
+ max,
15
+ viewYear,
16
+ placeholder,
17
+ onSelect,
18
+ }) => {
13
19
  const { locale } = useIntl();
14
- const getLink = (month) => {
15
- return (
16
- <TableLink
17
- item={month}
18
- type="month"
19
- title={formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAT)}
20
- active={isSelected(month)}
21
- disabled={isDisabled(month)}
22
- today={viewYear === new Date().getFullYear() && month === new Date().getMonth()}
23
- autofocus={autofocusMonth === month}
24
- onClick={onSelect}
25
- />
26
- );
27
- };
28
-
29
- const isSelected = (month) => {
30
- return (
31
- selectedDate && month === selectedDate.getMonth() && viewYear === selectedDate.getFullYear()
32
- );
33
- };
34
-
35
- const isThisMonth = (month) => {
36
- return viewYear === new Date().getFullYear() && month === new Date().getMonth();
37
- };
38
20
 
21
+ const getLink = (month) => (
22
+ <TableLink
23
+ item={month}
24
+ type="month"
25
+ title={formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAY)}
26
+ active={!!(selected && month === selected.getMonth() && viewYear === selected.getFullYear())}
27
+ disabled={isDisabled(month)}
28
+ today={viewYear === new Date().getFullYear() && month === new Date().getMonth()}
29
+ onClick={onSelect}
30
+ />
31
+ );
39
32
  const isDisabled = (month) => {
40
33
  const date = new Date(viewYear, month);
41
34
  return !!(
@@ -43,12 +36,6 @@ const MonthCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onS
43
36
  (max && date > new Date(max.getFullYear(), max.getMonth()))
44
37
  );
45
38
  };
46
-
47
- const autofocusMonth = (() => {
48
- const months = [...new Array(ROWS * COLS)].map((_, index) => index);
49
- return getFocusableTime(isSelected, isThisMonth, isDisabled, months);
50
- })();
51
-
52
39
  return (
53
40
  <table className="table table-condensed table-bordered tw-date-lookup-calendar np-text-body-default-bold m-b-0">
54
41
  <thead className="sr-only">
@@ -82,39 +82,6 @@ describe('MonthCalendarTable', () => {
82
82
  expect(component.find('.sr-only').text()).toBe('Enter date..');
83
83
  });
84
84
 
85
- it('sets autofocus to true when June is the selected month', () => {
86
- component.setProps({ selectedDate: new Date(2018, 5, 1) });
87
- expect(getTableLinkAt(5).prop('autofocus')).toBe(true);
88
- });
89
-
90
- it('does not set autofocus to true when June is the selected month but not the right year', () => {
91
- component.setProps({ selectedDate: new Date(2017, 5, 1) });
92
- expect(getTableLinkAt(5).prop('autofocus')).toBe(false);
93
- });
94
-
95
- it('sets autofocus to true when selected date is null and current month is visible', () => {
96
- const today = new Date();
97
- component.setProps({
98
- selectedDate: null,
99
- viewYear: today.getFullYear(),
100
- viewMonth: today.getMonth(),
101
- });
102
- expect(getTableLink().find({ today: true }).prop('autofocus')).toBe(true);
103
- });
104
-
105
- it('sets autofocus to true on the second month when the first month is disabled', () => {
106
- component.setProps({
107
- selectedDate: null,
108
- viewYear: 2022,
109
- min: new Date(2022, 1, 28),
110
- viewMonth: 0,
111
- isDisabled: (month) => month === 0,
112
- });
113
-
114
- expect(getTableLinkAt(0).prop('autofocus')).toBe(false);
115
- expect(getTableLinkAt(1).prop('autofocus')).toBe(true);
116
- });
117
-
118
85
  const getTableLinkAt = (i) => component.find('[title="MonthName"]').at(i);
119
86
  const getTableLink = () => component.find('[title="MonthName"]');
120
87
  });