@khanacademy/wonder-blocks-birthday-picker 3.3.9 → 4.0.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.
- package/CHANGELOG.md +16 -0
- package/dist/components/birthday-picker.d.ts +9 -0
- package/dist/es/index.js +54 -19
- package/dist/index.js +54 -20
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-birthday-picker
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 422505e: Removed moment.js and replaced it with Temporal polyfill
|
|
8
|
+
|
|
9
|
+
## 3.3.10
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [e63adea]
|
|
14
|
+
- Updated dependencies [e63adea]
|
|
15
|
+
- @khanacademy/wonder-blocks-tokens@8.0.0
|
|
16
|
+
- @khanacademy/wonder-blocks-dropdown@10.0.2
|
|
17
|
+
- @khanacademy/wonder-blocks-layout@3.1.8
|
|
18
|
+
|
|
3
19
|
## 3.3.9
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Temporal } from "temporal-polyfill";
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
import { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
4
|
export type Labels = {
|
|
@@ -89,6 +90,13 @@ export default class BirthdayPicker extends React.Component<Props, State> {
|
|
|
89
90
|
* Calculates the initial state values based on the default value.
|
|
90
91
|
*/
|
|
91
92
|
getStateFromDefault(): State;
|
|
93
|
+
/**
|
|
94
|
+
* Determines whether a given date is in the future.
|
|
95
|
+
*
|
|
96
|
+
* @param date - The Temporal.PlainDate to check.
|
|
97
|
+
* @returns True if the provided date comes after today's date, false otherwise.
|
|
98
|
+
*/
|
|
99
|
+
isFutureDate(date: Temporal.PlainDate): boolean;
|
|
92
100
|
lastChangeValue: string | null | undefined;
|
|
93
101
|
/**
|
|
94
102
|
* Report changes back to the calling component, but only if the value
|
|
@@ -108,6 +116,7 @@ export default class BirthdayPicker extends React.Component<Props, State> {
|
|
|
108
116
|
handleDayChange: (day: string) => void;
|
|
109
117
|
handleYearChange: (year: string) => void;
|
|
110
118
|
maybeRenderError(): React.ReactNode | null | undefined;
|
|
119
|
+
monthsShort(): string[];
|
|
111
120
|
renderMonth(): React.ReactNode;
|
|
112
121
|
maybeRenderDay(): React.ReactNode | null | undefined;
|
|
113
122
|
getMonthYearWidth(monthYearOnly: boolean | undefined): number;
|
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _extends from '@babel/runtime/helpers/extends';
|
|
2
|
-
import
|
|
2
|
+
import { Temporal } from 'temporal-polyfill';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { StyleSheet } from 'aphrodite';
|
|
5
5
|
import { View } from '@khanacademy/wonder-blocks-core';
|
|
@@ -65,11 +65,31 @@ class BirthdayPicker extends React.Component {
|
|
|
65
65
|
this.reportChange(null);
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
|
-
let date
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
let date;
|
|
69
|
+
try {
|
|
70
|
+
if (monthYearOnly) {
|
|
71
|
+
date = Temporal.PlainDate.from({
|
|
72
|
+
year: Number(year),
|
|
73
|
+
month: Number(month),
|
|
74
|
+
day: 31
|
|
75
|
+
});
|
|
76
|
+
} else {
|
|
77
|
+
date = Temporal.PlainDate.from({
|
|
78
|
+
year: Number(year),
|
|
79
|
+
month: Number(month),
|
|
80
|
+
day: Number(day)
|
|
81
|
+
}, {
|
|
82
|
+
overflow: "reject"
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
} catch (err) {
|
|
86
|
+
this.setState({
|
|
87
|
+
error: this.labels.errorMessage
|
|
88
|
+
});
|
|
89
|
+
this.reportChange(null);
|
|
90
|
+
return;
|
|
71
91
|
}
|
|
72
|
-
if (
|
|
92
|
+
if (this.isFutureDate(date)) {
|
|
73
93
|
this.setState({
|
|
74
94
|
error: this.labels.errorMessage
|
|
75
95
|
});
|
|
@@ -78,7 +98,7 @@ class BirthdayPicker extends React.Component {
|
|
|
78
98
|
this.setState({
|
|
79
99
|
error: null
|
|
80
100
|
});
|
|
81
|
-
this.reportChange(date.
|
|
101
|
+
this.reportChange(date.toString());
|
|
82
102
|
}
|
|
83
103
|
};
|
|
84
104
|
this.handleMonthChange = month => {
|
|
@@ -112,21 +132,30 @@ class BirthdayPicker extends React.Component {
|
|
|
112
132
|
};
|
|
113
133
|
this.labels = _extends({}, defaultLabels, this.props.labels);
|
|
114
134
|
if (defaultValue) {
|
|
115
|
-
let date =
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
initialState
|
|
121
|
-
|
|
122
|
-
|
|
135
|
+
let date = null;
|
|
136
|
+
try {
|
|
137
|
+
date = Temporal.PlainDate.from(defaultValue);
|
|
138
|
+
} catch (err) {
|
|
139
|
+
initialState.error = this.labels.errorMessage;
|
|
140
|
+
return initialState;
|
|
141
|
+
}
|
|
142
|
+
if (monthYearOnly) {
|
|
143
|
+
date = date.with({
|
|
144
|
+
day: date.daysInMonth
|
|
145
|
+
});
|
|
123
146
|
}
|
|
124
|
-
|
|
147
|
+
initialState.month = String(date.month);
|
|
148
|
+
initialState.day = String(date.day);
|
|
149
|
+
initialState.year = String(date.year);
|
|
150
|
+
if (this.isFutureDate(date)) {
|
|
125
151
|
initialState.error = this.labels.errorMessage;
|
|
126
152
|
}
|
|
127
153
|
}
|
|
128
154
|
return initialState;
|
|
129
155
|
}
|
|
156
|
+
isFutureDate(date) {
|
|
157
|
+
return Temporal.PlainDate.compare(date, Temporal.Now.plainDateISO()) === 1;
|
|
158
|
+
}
|
|
130
159
|
maybeRenderError() {
|
|
131
160
|
const {
|
|
132
161
|
error
|
|
@@ -155,6 +184,12 @@ class BirthdayPicker extends React.Component {
|
|
|
155
184
|
}
|
|
156
185
|
}, error)));
|
|
157
186
|
}
|
|
187
|
+
monthsShort() {
|
|
188
|
+
const format = new Intl.DateTimeFormat(navigator.language, {
|
|
189
|
+
month: "short"
|
|
190
|
+
}).format;
|
|
191
|
+
return [...Array(12).keys()].map(m => format(new Date(2021, m, 15)));
|
|
192
|
+
}
|
|
158
193
|
renderMonth() {
|
|
159
194
|
const {
|
|
160
195
|
disabled,
|
|
@@ -177,10 +212,10 @@ class BirthdayPicker extends React.Component {
|
|
|
177
212
|
minWidth
|
|
178
213
|
}, defaultStyles.input, dropdownStyle],
|
|
179
214
|
testId: "birthday-picker-month"
|
|
180
|
-
},
|
|
181
|
-
key:
|
|
182
|
-
label:
|
|
183
|
-
value: String(i)
|
|
215
|
+
}, this.monthsShort().map((monthShort, i) => React.createElement(OptionItem, {
|
|
216
|
+
key: monthShort,
|
|
217
|
+
label: monthShort,
|
|
218
|
+
value: String(i + 1)
|
|
184
219
|
})));
|
|
185
220
|
}
|
|
186
221
|
maybeRenderDay() {
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
4
|
-
var
|
|
4
|
+
var temporalPolyfill = require('temporal-polyfill');
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var aphrodite = require('aphrodite');
|
|
7
7
|
var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
|
|
@@ -33,7 +33,6 @@ function _interopNamespace(e) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
36
|
-
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
37
36
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
38
37
|
var infoIcon__default = /*#__PURE__*/_interopDefaultLegacy(infoIcon);
|
|
39
38
|
|
|
@@ -92,11 +91,31 @@ class BirthdayPicker extends React__namespace.Component {
|
|
|
92
91
|
this.reportChange(null);
|
|
93
92
|
return;
|
|
94
93
|
}
|
|
95
|
-
let date
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
let date;
|
|
95
|
+
try {
|
|
96
|
+
if (monthYearOnly) {
|
|
97
|
+
date = temporalPolyfill.Temporal.PlainDate.from({
|
|
98
|
+
year: Number(year),
|
|
99
|
+
month: Number(month),
|
|
100
|
+
day: 31
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
date = temporalPolyfill.Temporal.PlainDate.from({
|
|
104
|
+
year: Number(year),
|
|
105
|
+
month: Number(month),
|
|
106
|
+
day: Number(day)
|
|
107
|
+
}, {
|
|
108
|
+
overflow: "reject"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
} catch (err) {
|
|
112
|
+
this.setState({
|
|
113
|
+
error: this.labels.errorMessage
|
|
114
|
+
});
|
|
115
|
+
this.reportChange(null);
|
|
116
|
+
return;
|
|
98
117
|
}
|
|
99
|
-
if (
|
|
118
|
+
if (this.isFutureDate(date)) {
|
|
100
119
|
this.setState({
|
|
101
120
|
error: this.labels.errorMessage
|
|
102
121
|
});
|
|
@@ -105,7 +124,7 @@ class BirthdayPicker extends React__namespace.Component {
|
|
|
105
124
|
this.setState({
|
|
106
125
|
error: null
|
|
107
126
|
});
|
|
108
|
-
this.reportChange(date.
|
|
127
|
+
this.reportChange(date.toString());
|
|
109
128
|
}
|
|
110
129
|
};
|
|
111
130
|
this.handleMonthChange = month => {
|
|
@@ -139,21 +158,30 @@ class BirthdayPicker extends React__namespace.Component {
|
|
|
139
158
|
};
|
|
140
159
|
this.labels = _extends__default["default"]({}, defaultLabels, this.props.labels);
|
|
141
160
|
if (defaultValue) {
|
|
142
|
-
let date =
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
initialState
|
|
148
|
-
|
|
149
|
-
|
|
161
|
+
let date = null;
|
|
162
|
+
try {
|
|
163
|
+
date = temporalPolyfill.Temporal.PlainDate.from(defaultValue);
|
|
164
|
+
} catch (err) {
|
|
165
|
+
initialState.error = this.labels.errorMessage;
|
|
166
|
+
return initialState;
|
|
167
|
+
}
|
|
168
|
+
if (monthYearOnly) {
|
|
169
|
+
date = date.with({
|
|
170
|
+
day: date.daysInMonth
|
|
171
|
+
});
|
|
150
172
|
}
|
|
151
|
-
|
|
173
|
+
initialState.month = String(date.month);
|
|
174
|
+
initialState.day = String(date.day);
|
|
175
|
+
initialState.year = String(date.year);
|
|
176
|
+
if (this.isFutureDate(date)) {
|
|
152
177
|
initialState.error = this.labels.errorMessage;
|
|
153
178
|
}
|
|
154
179
|
}
|
|
155
180
|
return initialState;
|
|
156
181
|
}
|
|
182
|
+
isFutureDate(date) {
|
|
183
|
+
return temporalPolyfill.Temporal.PlainDate.compare(date, temporalPolyfill.Temporal.Now.plainDateISO()) === 1;
|
|
184
|
+
}
|
|
157
185
|
maybeRenderError() {
|
|
158
186
|
const {
|
|
159
187
|
error
|
|
@@ -182,6 +210,12 @@ class BirthdayPicker extends React__namespace.Component {
|
|
|
182
210
|
}
|
|
183
211
|
}, error)));
|
|
184
212
|
}
|
|
213
|
+
monthsShort() {
|
|
214
|
+
const format = new Intl.DateTimeFormat(navigator.language, {
|
|
215
|
+
month: "short"
|
|
216
|
+
}).format;
|
|
217
|
+
return [...Array(12).keys()].map(m => format(new Date(2021, m, 15)));
|
|
218
|
+
}
|
|
185
219
|
renderMonth() {
|
|
186
220
|
const {
|
|
187
221
|
disabled,
|
|
@@ -204,10 +238,10 @@ class BirthdayPicker extends React__namespace.Component {
|
|
|
204
238
|
minWidth
|
|
205
239
|
}, defaultStyles.input, dropdownStyle],
|
|
206
240
|
testId: "birthday-picker-month"
|
|
207
|
-
},
|
|
208
|
-
key:
|
|
209
|
-
label:
|
|
210
|
-
value: String(i)
|
|
241
|
+
}, this.monthsShort().map((monthShort, i) => React__namespace.createElement(wonderBlocksDropdown.OptionItem, {
|
|
242
|
+
key: monthShort,
|
|
243
|
+
label: monthShort,
|
|
244
|
+
value: String(i + 1)
|
|
211
245
|
})));
|
|
212
246
|
}
|
|
213
247
|
maybeRenderDay() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-birthday-picker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,16 +12,16 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@babel/runtime": "^7.24.5",
|
|
14
14
|
"@khanacademy/wonder-blocks-core": "12.2.1",
|
|
15
|
-
"@khanacademy/wonder-blocks-dropdown": "10.0.
|
|
15
|
+
"@khanacademy/wonder-blocks-dropdown": "10.0.2",
|
|
16
16
|
"@khanacademy/wonder-blocks-icon": "5.1.3",
|
|
17
|
-
"@khanacademy/wonder-blocks-layout": "3.1.
|
|
18
|
-
"@khanacademy/wonder-blocks-tokens": "
|
|
17
|
+
"@khanacademy/wonder-blocks-layout": "3.1.8",
|
|
18
|
+
"@khanacademy/wonder-blocks-tokens": "8.0.0",
|
|
19
19
|
"@khanacademy/wonder-blocks-typography": "3.1.3"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@phosphor-icons/core": "^2.0.2",
|
|
23
23
|
"aphrodite": "^1.2.5",
|
|
24
|
-
"
|
|
24
|
+
"temporal-polyfill": "^0.3.0",
|
|
25
25
|
"react": "18.2.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|