@khanacademy/wonder-blocks-birthday-picker 3.2.2 → 3.3.1

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,20 @@
1
1
  # @khanacademy/wonder-blocks-birthday-picker
2
2
 
3
+ ## 3.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [507cf2f]
8
+ - @khanacademy/wonder-blocks-tokens@5.1.0
9
+ - @khanacademy/wonder-blocks-dropdown@9.1.3
10
+ - @khanacademy/wonder-blocks-layout@3.1.3
11
+
12
+ ## 3.3.0
13
+
14
+ ### Minor Changes
15
+
16
+ - 3ef7032: Updated BirthdayPicker to use last day of month when monthYearOnly is true
17
+
3
18
  ## 3.2.2
4
19
 
5
20
  ### Patch Changes
@@ -36,9 +36,9 @@ type Props = {
36
36
  /**
37
37
  * Whether we want to hide the day field.
38
38
  *
39
- * **NOTE:** We will set the day to the _first_ day of the _selected_ month
39
+ * **NOTE:** We will set the day to the _last_ day of the _selected_ month
40
40
  * if the day field is hidden. Please make sure to modify the passed date
41
- * value to fit different needs (e.g. if you want to set the _first_ day of
41
+ * value to fit different needs (e.g. if you want to set the _last_ day of
42
42
  * the _following_ month instead).
43
43
  */
44
44
  monthYearOnly?: boolean;
package/dist/es/index.js CHANGED
@@ -54,11 +54,21 @@ class BirthdayPicker extends React.Component {
54
54
  day,
55
55
  year
56
56
  } = this.state;
57
- if (month === null || day === null || year === null) {
57
+ const {
58
+ monthYearOnly
59
+ } = this.props;
60
+ const dateFields = [year, month];
61
+ if (!monthYearOnly) {
62
+ dateFields.push(day);
63
+ }
64
+ if (dateFields.some(field => field === null)) {
58
65
  this.reportChange(null);
59
66
  return;
60
67
  }
61
- const date = moment([year, month, day]);
68
+ let date = moment(dateFields);
69
+ if (monthYearOnly) {
70
+ date = date.endOf("month");
71
+ }
62
72
  if (date.isAfter() || !date.isValid()) {
63
73
  this.setState({
64
74
  error: this.labels.errorMessage
@@ -102,8 +112,11 @@ class BirthdayPicker extends React.Component {
102
112
  };
103
113
  this.labels = _extends({}, defaultLabels, this.props.labels);
104
114
  if (defaultValue) {
105
- const date = moment(defaultValue);
115
+ let date = moment(defaultValue);
106
116
  if (date.isValid()) {
117
+ if (monthYearOnly) {
118
+ date = date.endOf("month");
119
+ }
107
120
  initialState.month = String(date.month());
108
121
  initialState.day = String(date.date());
109
122
  initialState.year = String(date.year());
package/dist/index.js CHANGED
@@ -81,11 +81,21 @@ class BirthdayPicker extends React__namespace.Component {
81
81
  day,
82
82
  year
83
83
  } = this.state;
84
- if (month === null || day === null || year === null) {
84
+ const {
85
+ monthYearOnly
86
+ } = this.props;
87
+ const dateFields = [year, month];
88
+ if (!monthYearOnly) {
89
+ dateFields.push(day);
90
+ }
91
+ if (dateFields.some(field => field === null)) {
85
92
  this.reportChange(null);
86
93
  return;
87
94
  }
88
- const date = moment__default["default"]([year, month, day]);
95
+ let date = moment__default["default"](dateFields);
96
+ if (monthYearOnly) {
97
+ date = date.endOf("month");
98
+ }
89
99
  if (date.isAfter() || !date.isValid()) {
90
100
  this.setState({
91
101
  error: this.labels.errorMessage
@@ -129,8 +139,11 @@ class BirthdayPicker extends React__namespace.Component {
129
139
  };
130
140
  this.labels = _extends__default["default"]({}, defaultLabels, this.props.labels);
131
141
  if (defaultValue) {
132
- const date = moment__default["default"](defaultValue);
142
+ let date = moment__default["default"](defaultValue);
133
143
  if (date.isValid()) {
144
+ if (monthYearOnly) {
145
+ date = date.endOf("month");
146
+ }
134
147
  initialState.month = String(date.month());
135
148
  initialState.day = String(date.date());
136
149
  initialState.year = String(date.year());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-birthday-picker",
3
- "version": "3.2.2",
3
+ "version": "3.3.1",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -12,10 +12,10 @@
12
12
  "dependencies": {
13
13
  "@babel/runtime": "^7.24.5",
14
14
  "@khanacademy/wonder-blocks-core": "12.2.0",
15
- "@khanacademy/wonder-blocks-dropdown": "9.1.2",
15
+ "@khanacademy/wonder-blocks-dropdown": "9.1.3",
16
16
  "@khanacademy/wonder-blocks-icon": "5.1.2",
17
- "@khanacademy/wonder-blocks-layout": "3.1.2",
18
- "@khanacademy/wonder-blocks-tokens": "5.0.0",
17
+ "@khanacademy/wonder-blocks-layout": "3.1.3",
18
+ "@khanacademy/wonder-blocks-tokens": "5.1.0",
19
19
  "@khanacademy/wonder-blocks-typography": "3.1.2"
20
20
  },
21
21
  "peerDependencies": {