@khanacademy/wonder-blocks-birthday-picker 1.2.3 → 1.2.6

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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # @khanacademy/wonder-blocks-birthday-picker
2
2
 
3
+ ## 1.2.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [b3960766]
8
+ - @khanacademy/wonder-blocks-dropdown@2.7.0
9
+
10
+ ## 1.2.5
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [0b94d616]
15
+ - @khanacademy/wonder-blocks-dropdown@2.6.10
16
+
17
+ ## 1.2.4
18
+
19
+ ### Patch Changes
20
+
21
+ - @khanacademy/wonder-blocks-core@4.3.1
22
+ - @khanacademy/wonder-blocks-dropdown@2.6.9
23
+ - @khanacademy/wonder-blocks-icon@1.2.27
24
+ - @khanacademy/wonder-blocks-layout@1.4.9
25
+ - @khanacademy/wonder-blocks-typography@1.1.31
26
+
3
27
  ## 1.2.3
4
28
 
5
29
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -9,56 +9,16 @@ import Icon, { icons } from '@khanacademy/wonder-blocks-icon';
9
9
  import Color from '@khanacademy/wonder-blocks-color';
10
10
  import { SingleSelect, OptionItem } from '@khanacademy/wonder-blocks-dropdown';
11
11
 
12
- // Flow doesn't know about the getYear property on Date for some reason!
13
- // $FlowFixMe[prop-missing]
14
- const CUR_YEAR = new Date().getYear() + 1900; // Only exported internally for testing/documentation purposes.
15
-
12
+ const CUR_YEAR = new Date().getYear() + 1900;
16
13
  const defaultLabels = Object.freeze({
17
14
  errorMessage: "Please select a valid birthdate.",
18
15
  month: "Month",
19
16
  year: "Year",
20
17
  day: "Day"
21
- }); // Default minWidth value when we include the full DOB.
22
-
23
- const FIELD_MIN_WIDTH_FULL = 110; // Alternative minWidth value when we hide the day field.
24
- // See: https://www.figma.com/file/uJZi9ZvuEz5N8GJ3HqKFAa/(2021)-Account-records?node-id=20%3A398
25
-
18
+ });
19
+ const FIELD_MIN_WIDTH_FULL = 110;
26
20
  const FIELD_MIN_WIDTH_MONTH_YEAR = 167;
27
- /**
28
- * Birthday Picker. Similar to a datepicker, but specifically for birthdates.
29
- * We don't want to show a calendar in this case as it can be quite tedious to
30
- * try and select a date that's many years old. Instead, we use a set of
31
- * dropdowns to achieve a similar effect.
32
- *
33
- * More information on this pattern:
34
- * https://medium.com/samsung-internet-dev/making-input-type-date-complicated-a544fd27c45a
35
- *
36
- * Arguably, this should probably even be 3 textfields, but that would be a
37
- * larger design change, more info:
38
- * https://designnotes.blog.gov.uk/2013/12/05/asking-for-a-date-of-birth/
39
- *
40
- * **NOTE:** This component is uncontrolled.
41
- *
42
- * ### Usage
43
- *
44
- * ```jsx
45
- * import {BirthdayPicker} from "@khanacademy/wonder-blocks-dates";
46
- *
47
- * <BirthdayPicker
48
- * defaultValue="2021-05-26"
49
- * onChange={(date) => {setDate(date)}}
50
- * />
51
- * ```
52
- */
53
-
54
21
  class BirthdayPicker extends React.Component {
55
- /**
56
- * Strings used for placeholders and error message. These are used this way
57
- * to support i18n.
58
- * NOTE: This is a field rather than state to avoid re-rendering the entire
59
- * component. Also, we don't need to use state because these strings are
60
- * only needed on mount.
61
- */
62
22
  constructor(props) {
63
23
  super(props);
64
24
  this.lastChangeValue = null;
@@ -75,19 +35,14 @@ class BirthdayPicker extends React.Component {
75
35
  month,
76
36
  day,
77
37
  year
78
- } = this.state; // If any of the values haven't been set then our overall value is
79
- // equal to null
38
+ } = this.state;
80
39
 
81
40
  if (month === null || day === null || year === null) {
82
41
  this.reportChange(null);
83
42
  return;
84
- } // This is a legal call to Moment, but our Moment types don't
85
- // recognize it.
86
- // $FlowFixMe[incompatible-call]
87
-
43
+ }
88
44
 
89
- const date = moment([year, month, day]); // If the date is in the future or is invalid then we want to show
90
- // an error to the user and return a null value.
45
+ const date = moment([year, month, day]);
91
46
 
92
47
  if (date.isAfter() || !date.isValid()) {
93
48
  this.setState({
@@ -97,9 +52,7 @@ class BirthdayPicker extends React.Component {
97
52
  } else {
98
53
  this.setState({
99
54
  error: null
100
- }); // If the date picker is in a non-English language, we still
101
- // want to generate an English date.
102
-
55
+ });
103
56
  this.reportChange(date.locale("en").format("YYYY-MM-DD"));
104
57
  }
105
58
  };
@@ -125,10 +78,6 @@ class BirthdayPicker extends React.Component {
125
78
  this.lastChangeValue = props.defaultValue || null;
126
79
  this.state = this.getStateFromDefault();
127
80
  }
128
- /**
129
- * Calculates the initial state values based on the default value.
130
- */
131
-
132
81
 
133
82
  getStateFromDefault() {
134
83
  const {
@@ -140,10 +89,8 @@ class BirthdayPicker extends React.Component {
140
89
  day: monthYearOnly ? "1" : null,
141
90
  year: null,
142
91
  error: null
143
- }; // merge custom labels with the default ones
144
-
145
- this.labels = _extends({}, defaultLabels, this.props.labels); // If a default value was provided then we use moment to convert it
146
- // into a date that we can use to populate the
92
+ };
93
+ this.labels = _extends({}, defaultLabels, this.props.labels);
147
94
 
148
95
  if (defaultValue) {
149
96
  const date = moment(defaultValue);
@@ -152,9 +99,7 @@ class BirthdayPicker extends React.Component {
152
99
  initialState.month = String(date.month());
153
100
  initialState.day = String(date.date());
154
101
  initialState.year = String(date.year());
155
- } // If the date is in the future or is invalid then we want to show
156
- // an error to the user.
157
-
102
+ }
158
103
 
159
104
  if (date.isAfter() || !date.isValid()) {
160
105
  initialState.error = this.labels.errorMessage;
@@ -173,14 +118,14 @@ class BirthdayPicker extends React.Component {
173
118
  return null;
174
119
  }
175
120
 
176
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Strut, {
121
+ return React.createElement(React.Fragment, null, React.createElement(Strut, {
177
122
  size: Spacing.xxxSmall_4
178
- }), /*#__PURE__*/React.createElement(View, {
123
+ }), React.createElement(View, {
179
124
  style: {
180
125
  flexDirection: "row"
181
126
  },
182
127
  role: "alert"
183
- }, /*#__PURE__*/React.createElement(Icon, {
128
+ }, React.createElement(Icon, {
184
129
  size: "small",
185
130
  icon: icons.info,
186
131
  color: Color.red,
@@ -188,9 +133,9 @@ class BirthdayPicker extends React.Component {
188
133
  marginTop: 3
189
134
  },
190
135
  "aria-hidden": "true"
191
- }), /*#__PURE__*/React.createElement(Strut, {
136
+ }), React.createElement(Strut, {
192
137
  size: Spacing.xxxSmall_4
193
- }), /*#__PURE__*/React.createElement(Body, {
138
+ }), React.createElement(Body, {
194
139
  style: {
195
140
  color: Color.red
196
141
  }
@@ -206,7 +151,7 @@ class BirthdayPicker extends React.Component {
206
151
  month
207
152
  } = this.state;
208
153
  const minWidth = monthYearOnly ? FIELD_MIN_WIDTH_MONTH_YEAR : FIELD_MIN_WIDTH_FULL;
209
- return /*#__PURE__*/React.createElement(SingleSelect, {
154
+ return React.createElement(SingleSelect, {
210
155
  disabled: disabled,
211
156
  placeholder: this.labels.month,
212
157
  onChange: this.handleMonthChange,
@@ -215,7 +160,7 @@ class BirthdayPicker extends React.Component {
215
160
  minWidth
216
161
  },
217
162
  testId: "birthday-picker-month"
218
- }, moment.monthsShort().map((month, i) => /*#__PURE__*/React.createElement(OptionItem, {
163
+ }, moment.monthsShort().map((month, i) => React.createElement(OptionItem, {
219
164
  key: month,
220
165
  label: month,
221
166
  value: String(i)
@@ -229,15 +174,15 @@ class BirthdayPicker extends React.Component {
229
174
  } = this.props;
230
175
  const {
231
176
  day
232
- } = this.state; // Hide the day field if the month/year only mode is enabled.
177
+ } = this.state;
233
178
 
234
179
  if (monthYearOnly) {
235
180
  return null;
236
181
  }
237
182
 
238
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Strut, {
183
+ return React.createElement(React.Fragment, null, React.createElement(Strut, {
239
184
  size: Spacing.xSmall_8
240
- }), /*#__PURE__*/React.createElement(SingleSelect, {
185
+ }), React.createElement(SingleSelect, {
241
186
  disabled: disabled,
242
187
  placeholder: this.labels.day,
243
188
  onChange: this.handleDayChange,
@@ -246,7 +191,7 @@ class BirthdayPicker extends React.Component {
246
191
  minWidth: 100
247
192
  },
248
193
  testId: "birthday-picker-day"
249
- }, Array.from(Array(31)).map((_, day) => /*#__PURE__*/React.createElement(OptionItem, {
194
+ }, Array.from(Array(31)).map((_, day) => React.createElement(OptionItem, {
250
195
  key: String(day + 1),
251
196
  label: String(day + 1),
252
197
  value: String(day + 1)
@@ -262,7 +207,7 @@ class BirthdayPicker extends React.Component {
262
207
  year
263
208
  } = this.state;
264
209
  const minWidth = monthYearOnly ? FIELD_MIN_WIDTH_MONTH_YEAR : FIELD_MIN_WIDTH_FULL;
265
- return /*#__PURE__*/React.createElement(SingleSelect, {
210
+ return React.createElement(SingleSelect, {
266
211
  disabled: disabled,
267
212
  placeholder: this.labels.year,
268
213
  onChange: this.handleYearChange,
@@ -271,7 +216,7 @@ class BirthdayPicker extends React.Component {
271
216
  minWidth
272
217
  },
273
218
  testId: "birthday-picker-year"
274
- }, Array.from(Array(120)).map((_, yearOffset) => /*#__PURE__*/React.createElement(OptionItem, {
219
+ }, Array.from(Array(120)).map((_, yearOffset) => React.createElement(OptionItem, {
275
220
  key: String(CUR_YEAR - yearOffset),
276
221
  label: String(CUR_YEAR - yearOffset),
277
222
  value: String(CUR_YEAR - yearOffset)
@@ -279,12 +224,12 @@ class BirthdayPicker extends React.Component {
279
224
  }
280
225
 
281
226
  render() {
282
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(View, {
227
+ return React.createElement(React.Fragment, null, React.createElement(View, {
283
228
  testId: "birthday-picker",
284
229
  style: {
285
230
  flexDirection: "row"
286
231
  }
287
- }, this.renderMonth(), this.maybeRenderDay(), /*#__PURE__*/React.createElement(Strut, {
232
+ }, this.renderMonth(), this.maybeRenderDay(), React.createElement(Strut, {
288
233
  size: Spacing.xSmall_8
289
234
  }), this.renderYear()), this.maybeRenderError());
290
235
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-birthday-picker",
3
- "version": "1.2.3",
3
+ "version": "1.2.6",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,12 +15,12 @@
15
15
  "dependencies": {
16
16
  "@babel/runtime": "^7.16.3",
17
17
  "@khanacademy/wonder-blocks-color": "^1.1.20",
18
- "@khanacademy/wonder-blocks-core": "^4.3.0",
19
- "@khanacademy/wonder-blocks-dropdown": "^2.6.8",
20
- "@khanacademy/wonder-blocks-icon": "^1.2.26",
21
- "@khanacademy/wonder-blocks-layout": "^1.4.8",
18
+ "@khanacademy/wonder-blocks-core": "^4.3.1",
19
+ "@khanacademy/wonder-blocks-dropdown": "^2.7.0",
20
+ "@khanacademy/wonder-blocks-icon": "^1.2.27",
21
+ "@khanacademy/wonder-blocks-layout": "^1.4.9",
22
22
  "@khanacademy/wonder-blocks-spacing": "^3.0.5",
23
- "@khanacademy/wonder-blocks-typography": "^1.1.30"
23
+ "@khanacademy/wonder-blocks-typography": "^1.1.31"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "aphrodite": "^1.2.5",
@@ -28,7 +28,7 @@
28
28
  "react": "16.14.0"
29
29
  },
30
30
  "devDependencies": {
31
- "wb-dev-build-settings": "^0.3.0"
31
+ "wb-dev-build-settings": "^0.4.0"
32
32
  },
33
33
  "author": "",
34
34
  "license": "MIT"