carbon-react 95.1.2 → 95.1.3

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.
@@ -78,7 +78,7 @@ const FilterableSelect = /*#__PURE__*/_react.default.forwardRef(({
78
78
  const [textboxRef, setTextboxRef] = (0, _react.useState)();
79
79
  const [isOpen, setOpen] = (0, _react.useState)(false);
80
80
  const [textValue, setTextValue] = (0, _react.useState)("");
81
- const [selectedValue, setSelectedValue] = (0, _react.useState)("");
81
+ const [selectedValue, setSelectedValue] = (0, _react.useState)(value || defaultValue || "");
82
82
  const [highlightedValue, setHighlightedValue] = (0, _react.useState)("");
83
83
  const [filterText, setFilterText] = (0, _react.useState)("");
84
84
  const createCustomEvent = (0, _react.useCallback)(newValue => {
@@ -187,21 +187,33 @@ const FilterableSelect = /*#__PURE__*/_react.default.forwardRef(({
187
187
  }
188
188
  }, [setMatchingText, selectedValue]);
189
189
  (0, _react.useEffect)(() => {
190
- const newValue = value || defaultValue;
191
190
  const modeSwitchedMessage = "Input elements should not switch from uncontrolled to controlled (or vice versa). " + "Decide between using a controlled or uncontrolled input element for the lifetime of the component";
192
191
  const onChangeMissingMessage = "onChange prop required when using a controlled input element";
193
192
  (0, _invariant.default)(isControlled.current === (value !== undefined), modeSwitchedMessage);
194
193
  (0, _invariant.default)(!isControlled.current || isControlled.current && onChange, onChangeMissingMessage);
195
- setSelectedValue(prevValue => {
196
- if (value && isControlled.current && prevValue !== newValue) {
197
- setMatchingText(newValue);
194
+
195
+ if (isControlled.current) {
196
+ setSelectedValue(prevValue => {
197
+ if (value && prevValue !== value) {
198
+ setMatchingText(value);
199
+ }
200
+
201
+ return value;
202
+ });
203
+ setHighlightedValue(value);
204
+ } else {
205
+ if (textValue !== selectedValue) {
206
+ setMatchingText(selectedValue);
198
207
  }
199
208
 
200
- return newValue;
201
- });
202
- setHighlightedValue(newValue); // prevent value update on filter change
209
+ if (highlightedValue !== selectedValue) {
210
+ setHighlightedValue(selectedValue);
211
+ }
212
+ } // prevent value update on filter change
213
+ // selectedValue and highlightedValue omitted from deps, only want uncontrolled change if onChange/children update
203
214
  // eslint-disable-next-line react-hooks/exhaustive-deps
204
- }, [value, defaultValue, onChange, children]);
215
+
216
+ }, [value, onChange, children]);
205
217
  (0, _react.useEffect)(() => {
206
218
  if (!isOpen) {
207
219
  setFilterText("");
@@ -215,8 +227,11 @@ const FilterableSelect = /*#__PURE__*/_react.default.forwardRef(({
215
227
  (0, _invariant.default)(!hasListActionButton || hasListActionButton && onListAction, onListActionMissingMessage);
216
228
  }, [listActionButton, onListAction]);
217
229
  (0, _react.useEffect)(() => {
218
- setMatchingText(value || defaultValue); // update text value only when children are changing
230
+ if (isControlled.current) {
231
+ setMatchingText(value);
232
+ } // update text value only when children are changing
219
233
  // eslint-disable-next-line react-hooks/exhaustive-deps
234
+
220
235
  }, [value, children]);
221
236
  (0, _react.useEffect)(() => {
222
237
  if (onFilterChange) {
@@ -82,7 +82,7 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
82
82
  const [textboxRef, setTextboxRef] = (0, _react.useState)();
83
83
  const [isOpen, setOpenState] = (0, _react.useState)(false);
84
84
  const [textValue, setTextValue] = (0, _react.useState)("");
85
- const [selectedValue, setSelectedValue] = (0, _react.useState)([]);
85
+ const [selectedValue, setSelectedValue] = (0, _react.useState)(value || defaultValue || []);
86
86
  const [highlightedValue, setHighlightedValue] = (0, _react.useState)("");
87
87
  const [filterText, setFilterText] = (0, _react.useState)("");
88
88
  const [placeholderOverride, setPlaceholderOverride] = (0, _react.useState)();
@@ -124,7 +124,7 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
124
124
  setSelectedValue(previousValue => {
125
125
  isClickTriggeredBySelect.current = true;
126
126
 
127
- if (previousValue.length === 0) {
127
+ if (!previousValue.length) {
128
128
  return previousValue;
129
129
  }
130
130
 
@@ -185,7 +185,7 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
185
185
  const mapValuesToPills = (0, _react.useCallback)(() => {
186
186
  const canDelete = !disabled && !readOnly;
187
187
 
188
- if (selectedValue.length === 0) {
188
+ if (!selectedValue.length) {
189
189
  return "";
190
190
  }
191
191
 
@@ -205,31 +205,28 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
205
205
  const {
206
206
  title
207
207
  } = pillProps;
208
+ const key = title + ((matchingOption === null || matchingOption === void 0 ? void 0 : matchingOption.props.value) || index);
208
209
  return /*#__PURE__*/_react.default.createElement(_multiSelect.StyledSelectPillContainer, {
209
- key: title
210
+ key: key
210
211
  }, /*#__PURE__*/_react.default.createElement(_pill.default, _extends({
211
212
  onDelete: canDelete ? () => removeSelectedValue(index) : undefined
212
213
  }, pillProps), title));
213
214
  }); // eslint-disable-next-line react-hooks/exhaustive-deps
214
215
  }, [children, disabled, readOnly, selectedValue]);
215
216
  (0, _react.useEffect)(() => {
216
- const newValue = value || defaultValue;
217
217
  const modeSwitchedMessage = "Input elements should not switch from uncontrolled to controlled (or vice versa). " + "Decide between using a controlled or uncontrolled input element for the lifetime of the component";
218
- const onChageMissingMessage = "onChange prop required when using a controlled input element";
218
+ const onChangeMissingMessage = "onChange prop required when using a controlled input element";
219
219
  (0, _invariant.default)(isControlled.current === (value !== undefined), modeSwitchedMessage);
220
- (0, _invariant.default)(!isControlled.current || isControlled.current && onChange, onChageMissingMessage);
221
- setSelectedValue(previousValue => {
222
- if (!newValue && previousValue.length === 0) {
223
- return previousValue;
224
- }
220
+ (0, _invariant.default)(!isControlled.current || isControlled.current && onChange, onChangeMissingMessage);
225
221
 
226
- return newValue;
227
- });
228
- }, [value, defaultValue, onChange]); // removes placeholder when a value is present
222
+ if (isControlled.current) {
223
+ setSelectedValue(value);
224
+ }
225
+ }, [value, onChange]); // removes placeholder when a value is present
229
226
 
230
227
  (0, _react.useEffect)(() => {
231
- const hasValue = value && value.length > 0;
232
- const hasSelectedValue = selectedValue && selectedValue.length > 0;
228
+ const hasValue = value === null || value === void 0 ? void 0 : value.length;
229
+ const hasSelectedValue = selectedValue === null || selectedValue === void 0 ? void 0 : selectedValue.length;
233
230
 
234
231
  if (hasValue || hasSelectedValue) {
235
232
  setPlaceholderOverride(" ");
@@ -77,7 +77,7 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
77
77
  const [textboxRef, setTextboxRef] = (0, _react.useState)();
78
78
  const [isOpen, setOpenState] = (0, _react.useState)(false);
79
79
  const [textValue, setTextValue] = (0, _react.useState)("");
80
- const [selectedValue, setSelectedValue] = (0, _react.useState)("");
80
+ const [selectedValue, setSelectedValue] = (0, _react.useState)(value || defaultValue || "");
81
81
  const childOptions = (0, _react.useMemo)(() => _react.default.Children.toArray(children), [children]);
82
82
  const createCustomEvent = (0, _react.useCallback)(newValue => {
83
83
  const customEvent = {
@@ -176,13 +176,15 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
176
176
  isClickTriggeredBySelect.current = false;
177
177
  }, []);
178
178
  (0, _react.useEffect)(() => {
179
- const newValue = value || defaultValue;
180
179
  const modeSwitchedMessage = "Input elements should not switch from uncontrolled to controlled (or vice versa). " + "Decide between using a controlled or uncontrolled input element for the lifetime of the component";
181
180
  const onChangeMissingMessage = "onChange prop required when using a controlled input element";
182
181
  (0, _invariant.default)(isControlled.current === (value !== undefined), modeSwitchedMessage);
183
182
  (0, _invariant.default)(!isControlled.current || isControlled.current && onChange, onChangeMissingMessage);
184
- setSelectedValue(newValue);
185
- }, [value, defaultValue, onChange]);
183
+
184
+ if (isControlled.current) {
185
+ setSelectedValue(value);
186
+ }
187
+ }, [value, onChange]);
186
188
  (0, _react.useEffect)(() => {
187
189
  const matchingOption = childOptions.find(child => (0, _isExpectedOption.default)(child, selectedValue));
188
190
  let newText = "";
@@ -55,7 +55,7 @@ export interface SimpleSelectProps
55
55
  | "left-start"
56
56
  | "left-end";
57
57
  /** Use the opposite list placement if the set placement does not fit */
58
- flipEnabled?: bool;
58
+ flipEnabled?: boolean;
59
59
  }
60
60
 
61
61
  declare function SimpleSelect(
@@ -22,5 +22,13 @@ function isExpectedOption(element, expectedValue) {
22
22
  return false;
23
23
  }
24
24
 
25
+ const {
26
+ length
27
+ } = typeof expectedValue === "string" ? expectedValue : Object.keys(expectedValue);
28
+
29
+ if (!length) {
30
+ return false;
31
+ }
32
+
25
33
  return (0, _isExpectedValue.default)(element.props.value, expectedValue);
26
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "95.1.2",
3
+ "version": "95.1.3",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "engineStrict": true,
6
6
  "engines": {
@@ -8,10 +8,12 @@
8
8
  "node": ">=14.16.0"
9
9
  },
10
10
  "files": [
11
- "lib"
11
+ "lib",
12
+ "scripts/check_carbon_version.js",
13
+ "scripts/check_rfcs.js"
12
14
  ],
13
15
  "scripts": {
14
- "start": "node ./check_version.js && start-storybook -p 9001 -s .assets -c .storybook",
16
+ "start": "node ./scripts/check_node_version.js && start-storybook -p 9001 -s .assets -c .storybook",
15
17
  "start:debug-theme": "cross-env STORYBOOK_DEBUG_THEME=true npm run start",
16
18
  "test": "jest --config=./jest.conf.json",
17
19
  "test-update": "jest --config=./jest.conf.json --updateSnapshot",
@@ -22,6 +24,7 @@
22
24
  "lint": "eslint ./src",
23
25
  "precompile": "npm run clean-lib && npm run copy-files && npm run babel",
24
26
  "prepublishOnly": "npm run precompile",
27
+ "postinstall": "node ./scripts/check_carbon_version.js && node ./scripts/check_rfcs.js",
25
28
  "watch": "npm run clean-lib && npm run copy-files -- --watch & npm run babel -- --watch",
26
29
  "build-storybook": "build-storybook -c .storybook -s .assets",
27
30
  "start:static": "npx http-server -p 9001 ./storybook-static",
@@ -132,16 +135,19 @@
132
135
  "typescript": "^3.9.5"
133
136
  },
134
137
  "dependencies": {
138
+ "@octokit/rest": "^18.12.0",
135
139
  "@popperjs/core": "^2.9.0",
136
140
  "@sage/design-tokens": "^1.73.0",
137
141
  "@styled-system/prop-types": "^5.1.5",
138
142
  "@tippyjs/react": "^4.2.5",
139
143
  "classnames": "~2.2.6",
140
144
  "crypto-js": "~3.3.0",
145
+ "dotenv": "^10.0.0",
141
146
  "immutable": "~3.8.2",
142
147
  "invariant": "^2.2.4",
143
148
  "lodash": "^4.17.20",
144
149
  "moment": "~2.20.1",
150
+ "node-fetch": "^2.6.1",
145
151
  "polished": "^4.0.5",
146
152
  "prop-types": "^15.7.2",
147
153
  "react-day-picker": "~6.1.1",
@@ -0,0 +1,30 @@
1
+ /* eslint-disable no-console */
2
+ const fetch = require("node-fetch");
3
+ const dotenv = require("dotenv");
4
+ const chalk = require("chalk");
5
+ const { version } = require("../package.json");
6
+
7
+ dotenv.config();
8
+ const majorVersion = version.split(".")[0];
9
+
10
+ const checkCarbonVersion = () => {
11
+ fetch("https://registry.npmjs.com/carbon-react")
12
+ .then((res) => res.json())
13
+ .then((data) => {
14
+ const { latest } = data["dist-tags"];
15
+ const latestMajor = latest.split(".")[0];
16
+
17
+ const diff = Number(latestMajor) - Number(majorVersion);
18
+
19
+ if (diff > 1) {
20
+ console.log(
21
+ `carbon-react version installed is currently ${chalk.yellow(
22
+ diff
23
+ )} major versions behind the latest.`
24
+ );
25
+ }
26
+ })
27
+ .catch((err) => console.log(err));
28
+ };
29
+
30
+ if (!process.env.CARBON_INSTALL) checkCarbonVersion();
@@ -0,0 +1,49 @@
1
+ /* eslint-disable no-console */
2
+ const { Octokit } = require("@octokit/rest");
3
+ const dotenv = require("dotenv");
4
+ const chalk = require("chalk");
5
+
6
+ dotenv.config();
7
+ const octokit = new Octokit({
8
+ baseUrl: "https://api.github.com",
9
+ });
10
+
11
+ const method = "GET";
12
+ const owner = "sage";
13
+ const path = "pulls";
14
+ const repo = "carbon";
15
+ const url = "/repos/{owner}/{repo}/{path}";
16
+
17
+ const getOpenRfcs = async () => {
18
+ const { data } = await octokit.request({
19
+ owner,
20
+ repo,
21
+ url,
22
+ method,
23
+ path,
24
+ });
25
+
26
+ return data.filter((item) => {
27
+ const labels = item.labels.filter((label) => label.name === "RFC");
28
+
29
+ return labels.length > 0;
30
+ });
31
+ };
32
+
33
+ const getRfcTitle = (rfc) => rfc.title.split(": ")[1];
34
+
35
+ const checkRfcs = async () => {
36
+ const openRfcs = await getOpenRfcs();
37
+
38
+ if (openRfcs.length > 0) {
39
+ console.log("\ncarbon-react currently has open RFCs:");
40
+
41
+ openRfcs.forEach((item) => {
42
+ const title = getRfcTitle(item);
43
+ console.log(`- ${title}: ${chalk.cyan(item.html_url)}`);
44
+ });
45
+ console.log("\n");
46
+ }
47
+ };
48
+
49
+ if (!process.env.CARBON_INSTALL) checkRfcs();