@khanacademy/wonder-blocks-birthday-picker 2.0.85 → 2.0.87

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,18 @@
1
1
  # @khanacademy/wonder-blocks-birthday-picker
2
2
 
3
+ ## 2.0.87
4
+
5
+ ### Patch Changes
6
+
7
+ - a32b0779: Add responsive default to BirthdayPicker
8
+
9
+ ## 2.0.86
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [0b3a28a7]
14
+ - @khanacademy/wonder-blocks-dropdown@5.6.0
15
+
3
16
  ## 2.0.85
4
17
 
5
18
  ### Patch Changes
@@ -75,32 +75,6 @@ type State = {
75
75
  error: string | null;
76
76
  };
77
77
  export declare const defaultLabels: Labels;
78
- /**
79
- * Birthday Picker. Similar to a datepicker, but specifically for birthdates.
80
- * We don't want to show a calendar in this case as it can be quite tedious to
81
- * try and select a date that's many years old. Instead, we use a set of
82
- * dropdowns to achieve a similar effect.
83
- *
84
- * More information on this pattern:
85
- * https://medium.com/samsung-internet-dev/making-input-type-date-complicated-a544fd27c45a
86
- *
87
- * Arguably, this should probably even be 3 textfields, but that would be a
88
- * larger design change, more info:
89
- * https://designnotes.blog.gov.uk/2013/12/05/asking-for-a-date-of-birth/
90
- *
91
- * **NOTE:** This component is uncontrolled.
92
- *
93
- * ### Usage
94
- *
95
- * ```jsx
96
- * import {BirthdayPicker} from "@khanacademy/wonder-blocks-dates";
97
- *
98
- * <BirthdayPicker
99
- * defaultValue="2021-05-26"
100
- * onChange={(date) => {setDate(date)}}
101
- * />
102
- * ```
103
- */
104
78
  export default class BirthdayPicker extends React.Component<Props, State> {
105
79
  /**
106
80
  * Strings used for placeholders and error message. These are used this way
@@ -136,6 +110,7 @@ export default class BirthdayPicker extends React.Component<Props, State> {
136
110
  maybeRenderError(): React.ReactNode | null | undefined;
137
111
  renderMonth(): React.ReactNode;
138
112
  maybeRenderDay(): React.ReactNode | null | undefined;
113
+ getMonthYearWidth(monthYearOnly: boolean | undefined): number;
139
114
  renderYear(): React.ReactNode;
140
115
  render(): React.ReactNode;
141
116
  }
package/dist/es/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import _extends from '@babel/runtime/helpers/extends';
2
2
  import moment from 'moment';
3
3
  import * as React from 'react';
4
+ import { StyleSheet } from 'aphrodite';
4
5
  import { View } from '@khanacademy/wonder-blocks-core';
5
6
  import { Strut } from '@khanacademy/wonder-blocks-layout';
6
7
  import { spacing, color } from '@khanacademy/wonder-blocks-tokens';
@@ -18,6 +19,24 @@ const defaultLabels = Object.freeze({
18
19
  });
19
20
  const FIELD_MIN_WIDTH_FULL = 110;
20
21
  const FIELD_MIN_WIDTH_MONTH_YEAR = 167;
22
+ const FIELD_MIN_WIDTH_DAY = 100;
23
+ const xsMin = "520px";
24
+ const screenSizes = {
25
+ small: `@media (max-width: ${xsMin})`
26
+ };
27
+ const defaultStyles = StyleSheet.create({
28
+ wrapper: {
29
+ flexDirection: "row",
30
+ [screenSizes.small]: {
31
+ flexDirection: "column"
32
+ }
33
+ },
34
+ input: {
35
+ [screenSizes.small]: {
36
+ minWidth: "100%"
37
+ }
38
+ }
39
+ });
21
40
  class BirthdayPicker extends React.Component {
22
41
  constructor(props) {
23
42
  super(props);
@@ -132,7 +151,7 @@ class BirthdayPicker extends React.Component {
132
151
  const {
133
152
  month
134
153
  } = this.state;
135
- const minWidth = monthYearOnly ? FIELD_MIN_WIDTH_MONTH_YEAR : FIELD_MIN_WIDTH_FULL;
154
+ const minWidth = this.getMonthYearWidth(monthYearOnly);
136
155
  return React.createElement(SingleSelect, {
137
156
  "aria-invalid": !!this.state.error,
138
157
  error: !!this.state.error,
@@ -140,9 +159,9 @@ class BirthdayPicker extends React.Component {
140
159
  placeholder: this.labels.month,
141
160
  onChange: this.handleMonthChange,
142
161
  selectedValue: month,
143
- style: _extends({
162
+ style: [{
144
163
  minWidth
145
- }, dropdownStyle),
164
+ }, defaultStyles.input, dropdownStyle],
146
165
  testId: "birthday-picker-month"
147
166
  }, moment.monthsShort().map((month, i) => React.createElement(OptionItem, {
148
167
  key: month,
@@ -171,9 +190,9 @@ class BirthdayPicker extends React.Component {
171
190
  placeholder: this.labels.day,
172
191
  onChange: this.handleDayChange,
173
192
  selectedValue: day,
174
- style: _extends({
175
- minWidth: 100
176
- }, dropdownStyle),
193
+ style: [{
194
+ minWidth: FIELD_MIN_WIDTH_DAY
195
+ }, defaultStyles.input, dropdownStyle],
177
196
  testId: "birthday-picker-day"
178
197
  }, Array.from(Array(31)).map((_, day) => React.createElement(OptionItem, {
179
198
  key: String(day + 1),
@@ -181,6 +200,9 @@ class BirthdayPicker extends React.Component {
181
200
  value: String(day + 1)
182
201
  }))));
183
202
  }
203
+ getMonthYearWidth(monthYearOnly) {
204
+ return monthYearOnly ? FIELD_MIN_WIDTH_MONTH_YEAR : FIELD_MIN_WIDTH_FULL;
205
+ }
184
206
  renderYear() {
185
207
  const {
186
208
  disabled,
@@ -190,7 +212,7 @@ class BirthdayPicker extends React.Component {
190
212
  const {
191
213
  year
192
214
  } = this.state;
193
- const minWidth = monthYearOnly ? FIELD_MIN_WIDTH_MONTH_YEAR : FIELD_MIN_WIDTH_FULL;
215
+ const minWidth = this.getMonthYearWidth(monthYearOnly);
194
216
  return React.createElement(SingleSelect, {
195
217
  "aria-invalid": !!this.state.error,
196
218
  error: !!this.state.error,
@@ -198,9 +220,9 @@ class BirthdayPicker extends React.Component {
198
220
  placeholder: this.labels.year,
199
221
  onChange: this.handleYearChange,
200
222
  selectedValue: year,
201
- style: _extends({
223
+ style: [{
202
224
  minWidth
203
- }, dropdownStyle),
225
+ }, defaultStyles.input, dropdownStyle],
204
226
  dropdownStyle: {
205
227
  minWidth: 150
206
228
  },
@@ -217,9 +239,7 @@ class BirthdayPicker extends React.Component {
217
239
  } = this.props;
218
240
  return React.createElement(React.Fragment, null, React.createElement(View, {
219
241
  testId: "birthday-picker",
220
- style: _extends({
221
- flexDirection: "row"
222
- }, style)
242
+ style: [defaultStyles.wrapper, style]
223
243
  }, this.renderMonth(), this.maybeRenderDay(), React.createElement(Strut, {
224
244
  size: spacing.xSmall_8
225
245
  }), this.renderYear()), this.maybeRenderError());
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  var _extends = require('@babel/runtime/helpers/extends');
4
4
  var moment = require('moment');
5
5
  var React = require('react');
6
+ var aphrodite = require('aphrodite');
6
7
  var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
7
8
  var wonderBlocksLayout = require('@khanacademy/wonder-blocks-layout');
8
9
  var wonderBlocksTokens = require('@khanacademy/wonder-blocks-tokens');
@@ -45,6 +46,24 @@ const defaultLabels = Object.freeze({
45
46
  });
46
47
  const FIELD_MIN_WIDTH_FULL = 110;
47
48
  const FIELD_MIN_WIDTH_MONTH_YEAR = 167;
49
+ const FIELD_MIN_WIDTH_DAY = 100;
50
+ const xsMin = "520px";
51
+ const screenSizes = {
52
+ small: `@media (max-width: ${xsMin})`
53
+ };
54
+ const defaultStyles = aphrodite.StyleSheet.create({
55
+ wrapper: {
56
+ flexDirection: "row",
57
+ [screenSizes.small]: {
58
+ flexDirection: "column"
59
+ }
60
+ },
61
+ input: {
62
+ [screenSizes.small]: {
63
+ minWidth: "100%"
64
+ }
65
+ }
66
+ });
48
67
  class BirthdayPicker extends React__namespace.Component {
49
68
  constructor(props) {
50
69
  super(props);
@@ -159,7 +178,7 @@ class BirthdayPicker extends React__namespace.Component {
159
178
  const {
160
179
  month
161
180
  } = this.state;
162
- const minWidth = monthYearOnly ? FIELD_MIN_WIDTH_MONTH_YEAR : FIELD_MIN_WIDTH_FULL;
181
+ const minWidth = this.getMonthYearWidth(monthYearOnly);
163
182
  return React__namespace.createElement(wonderBlocksDropdown.SingleSelect, {
164
183
  "aria-invalid": !!this.state.error,
165
184
  error: !!this.state.error,
@@ -167,9 +186,9 @@ class BirthdayPicker extends React__namespace.Component {
167
186
  placeholder: this.labels.month,
168
187
  onChange: this.handleMonthChange,
169
188
  selectedValue: month,
170
- style: _extends__default["default"]({
189
+ style: [{
171
190
  minWidth
172
- }, dropdownStyle),
191
+ }, defaultStyles.input, dropdownStyle],
173
192
  testId: "birthday-picker-month"
174
193
  }, moment__default["default"].monthsShort().map((month, i) => React__namespace.createElement(wonderBlocksDropdown.OptionItem, {
175
194
  key: month,
@@ -198,9 +217,9 @@ class BirthdayPicker extends React__namespace.Component {
198
217
  placeholder: this.labels.day,
199
218
  onChange: this.handleDayChange,
200
219
  selectedValue: day,
201
- style: _extends__default["default"]({
202
- minWidth: 100
203
- }, dropdownStyle),
220
+ style: [{
221
+ minWidth: FIELD_MIN_WIDTH_DAY
222
+ }, defaultStyles.input, dropdownStyle],
204
223
  testId: "birthday-picker-day"
205
224
  }, Array.from(Array(31)).map((_, day) => React__namespace.createElement(wonderBlocksDropdown.OptionItem, {
206
225
  key: String(day + 1),
@@ -208,6 +227,9 @@ class BirthdayPicker extends React__namespace.Component {
208
227
  value: String(day + 1)
209
228
  }))));
210
229
  }
230
+ getMonthYearWidth(monthYearOnly) {
231
+ return monthYearOnly ? FIELD_MIN_WIDTH_MONTH_YEAR : FIELD_MIN_WIDTH_FULL;
232
+ }
211
233
  renderYear() {
212
234
  const {
213
235
  disabled,
@@ -217,7 +239,7 @@ class BirthdayPicker extends React__namespace.Component {
217
239
  const {
218
240
  year
219
241
  } = this.state;
220
- const minWidth = monthYearOnly ? FIELD_MIN_WIDTH_MONTH_YEAR : FIELD_MIN_WIDTH_FULL;
242
+ const minWidth = this.getMonthYearWidth(monthYearOnly);
221
243
  return React__namespace.createElement(wonderBlocksDropdown.SingleSelect, {
222
244
  "aria-invalid": !!this.state.error,
223
245
  error: !!this.state.error,
@@ -225,9 +247,9 @@ class BirthdayPicker extends React__namespace.Component {
225
247
  placeholder: this.labels.year,
226
248
  onChange: this.handleYearChange,
227
249
  selectedValue: year,
228
- style: _extends__default["default"]({
250
+ style: [{
229
251
  minWidth
230
- }, dropdownStyle),
252
+ }, defaultStyles.input, dropdownStyle],
231
253
  dropdownStyle: {
232
254
  minWidth: 150
233
255
  },
@@ -244,9 +266,7 @@ class BirthdayPicker extends React__namespace.Component {
244
266
  } = this.props;
245
267
  return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(wonderBlocksCore.View, {
246
268
  testId: "birthday-picker",
247
- style: _extends__default["default"]({
248
- flexDirection: "row"
249
- }, style)
269
+ style: [defaultStyles.wrapper, style]
250
270
  }, this.renderMonth(), this.maybeRenderDay(), React__namespace.createElement(wonderBlocksLayout.Strut, {
251
271
  size: wonderBlocksTokens.spacing.xSmall_8
252
272
  }), this.renderYear()), this.maybeRenderError());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-birthday-picker",
3
- "version": "2.0.85",
3
+ "version": "2.0.87",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,7 +15,7 @@
15
15
  "dependencies": {
16
16
  "@babel/runtime": "^7.18.6",
17
17
  "@khanacademy/wonder-blocks-core": "^7.0.1",
18
- "@khanacademy/wonder-blocks-dropdown": "^5.5.6",
18
+ "@khanacademy/wonder-blocks-dropdown": "^5.6.0",
19
19
  "@khanacademy/wonder-blocks-icon": "^4.1.5",
20
20
  "@khanacademy/wonder-blocks-layout": "^2.2.1",
21
21
  "@khanacademy/wonder-blocks-tokens": "^2.0.1",